GQ_Communicate/GQ_VR/Assets/script/接口/修改/RedactPort.cs

1467 lines
50 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//using AutoMapper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 端口-编辑
/// </summary>
public class RedactPort : MonoBehaviour
{
public static RedactPort Inst;
public Body mybody = new Body();
public Root URlreturn = new Root();
public Transform content;
RectTransform content_ret;
GridLayoutGroup content_grid;
//public PortQuery.Root root;
public Button save_bt;
Image save_bt_img;
PortQuery.PortList portlist = null;
[Header("记录的端口")]
public GameObject PortList1_game;
public GameObject PortList2_game;
public PortQuery.PortList PortList1;
public PortQuery.PortList PortList2;
[Header("当前端口选择")]
public Toggle toggle;
public Toggle con_toggle;
[Header("机柜跳转")]
public Button cabinet1;
public Button cabinet2;
/// <summary>
/// 端口
/// </summary>
//public Dropdown port;
public InputField port;
/// <summary>
/// 编号
/// </summary>
public InputField portCode;
/// <summary>
/// 名称
/// </summary>
public InputField portName;
/// <summary>
/// 线缆组名称
/// </summary>
public Dropdown cableGroupName;
///// <summary>
///// 所属设备
///// </summary>
//public InputField deviceId;
/// <summary>
/// 型号
/// </summary>
//public InputField portModel;
/// <summary>
/// 状态
/// </summary>
//public Dropdown status;
/// <summary>
/// 线路类型
/// </summary>
public Dropdown portType;
/// <summary>
/// 起始端口机柜
/// </summary>
public Dropdown startCabinet;
/// <summary>
/// 对联机柜
/// </summary>
public Dropdown conCabinet;
/// <summary>
/// 对联设备【(对联)所属设备】
/// </summary>
//public Dropdown conDevice;
public Text conDeviceName;
/// <summary>
/// 对联端口
/// </summary>
//public Dropdown conPort;
public Text conPort;
/// <summary>
/// 对联端口编号
/// </summary>
//public Text conPortCode;
public InputField conPortCode;
/// <summary>
/// 对联端口名
/// </summary>
//public Text conPortName;
public InputField conPortName;
public InputField cableName;
/// <summary>
/// 起始端口所属设备
/// </summary>
public Text deviceName;
/// <summary>
/// 本设备ID和名字关联字典
/// </summary>
public Dictionary<string?, string?> deviceName_dic = new Dictionary<string?, string?>();
/// <summary>
/// 对联设备ID和名字关联字典
/// </summary>
public Dictionary<string, string> conDevice_dic = new Dictionary<string, string>();
public string conDevice_dic_id;
public Button close_bt;
private void Awake()
{
Inst = this;
content_ret = content.GetComponent<RectTransform>();
content_grid = content.GetComponent<GridLayoutGroup>();
save_bt_img = save_bt.GetComponent<Image>();
//addconCabinet();
//conCabinet.captionText.text = null;
//findIndex(conCabinet, "");
gameObject.SetActive(false);
}
/// <summary>
/// 添加跳转机柜下拉菜单内容
/// </summary>
public void addconCabinet()
{
conCabinet.options.Clear();
startCabinet.options.Clear();
var startCabinet_Content = startCabinet.template.GetComponent<ScrollRect>().content.transform;
var conCabinet_Content = conCabinet.template.GetComponent<ScrollRect>().content.transform;
List<string> conCabinetname = new List<string>();
int index = 1;
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
DeviceQuery cabinetItem = GameManager.Inst.Cabinets_go[i].GetComponent<DeviceQuery>();
if (cabinetItem && cabinetItem.deviceList.rackType == "1")
{
conCabinetname.Add(cabinetItem.deviceList.deviceName);
//startCabinet.options.Add(new Dropdown.OptionData(string.Empty));
//conCabinet.options.Add(new Dropdown.OptionData(string.Empty));
//var dsa = startCabinet_Content.transform.childCount;
////var gfh = dsa.transform.childCount;
//Text startCabinet_text = startCabinet_Content.GetChild(index).GetChild(1).GetComponent<Text>();
//Text conCabinet_text = conCabinet_Content.GetChild(index).GetChild(1).GetComponent<Text>();
//startCabinet_text.SetTextWithEllipsis(cabinetItem.deviceList.deviceName);
//string startCabinet_txt = startCabinet_text.text;
//conCabinet_text.SetTextWithEllipsis(cabinetItem.deviceList.deviceName);
//string conCabinet_txt = conCabinet_text.text;
////startCabinet.options.Add(new Dropdown.OptionData(startCabinet_txt));
////conCabinet.options.Add(new Dropdown.OptionData(conCabinet_txt));
//index++;
}
}
conCabinetname.Add("");
conCabinet.AddOptions(conCabinetname);
startCabinet.AddOptions(conCabinetname);
}
//MapperConfiguration config;
//IMapper mapper;
private void OnEnable()
{
#region old
//mybody = new Body();
//conDevice_dic.Clear();
//if (conCabinet.options.Count == 0)
//{
// addconCabinet();
//}
//syncInfo();
//string conCabinet_name = findconCabinet();
//if (string.IsNullOrEmpty(conCabinet_name))
// init();
//else
// init(conCabinet_name);
//port.text = mybody.port;
//portCode.text = mybody.portCode;
//portName.text = mybody.portName;
////cableGroupName.captionText.text = mybody.cableGroupName;
//findIndex(conCabinet, conCabinet_name);
//findIndex(cableGroupName, mybody.cableGroupName);
//cableName.text = mybody.cableName;
////deviceId.text = mybody.deviceId;
////portModel.text = mybody.portModel;
//portType.captionText.text = mybody.portType;
////portType.value = portType.options.FindIndex(option => option.text == portType.captionText.text);
//int _portType = portType.options.FindIndex(option => option.text == mybody.portType);
//if (_portType != -1)
//{
// portType.captionText.text = mybody.portType;
// portType.value = _portType;
//}
//else
//{
// Debug.LogError("端口类型不存在于下拉菜单选项中!");
//}
////conDevice.captionText.text = mybody.conDevice;
////conDevice.captionText.text = mybody.conDeviceName;
//findIndex(conDevice, mybody.conDeviceName);
//conDevice_dic_id = mybody.conDevice;
////status.value = string.IsNullOrEmpty(mybody.status) ? 2 : Convert.ToInt32(mybody.status);
//if (!string.IsNullOrEmpty(mybody.conDevice) && !string.IsNullOrEmpty(conCabinet_name))
////if (!string.IsNullOrEmpty(mybody.conDevice))
//{
// //自动识别对联设备
// for (int i = 0; i < conDevice.options.Count; i++)
// {
// //if (conDevice.options[i].text == mybody.conDevice)
// if (conDevice.options[i].text == mybody.conDeviceName && !string.IsNullOrEmpty(mybody.conDeviceName))
// {
// conDevice.value = conDevice.options.Count;
// conDevice.value = i;
// conDevice.captionText.text = mybody.conDeviceName;
// var _conPort = conPort.options.FindIndex(option => option.text == mybody.conPort);
// if (_conPort != -1)
// {
// conPort.captionText.text = mybody.conPort;
// conPort.value = _conPort;
// }
// break;
// }
// }
//}
//else
//{
// conDevice.captionText.text = null;
// conPort.captionText.text = null;
// cableName.text = null;
// cableGroupName.captionText.text = null;
//}
//if (!string.IsNullOrEmpty(mybody.deviceName))
// deviceName.text = mybody.deviceName;
//else
// deviceName.text = null;
////int _conDevice = conDevice.options.FindIndex(option => option.text == mybody.conDevice);
////if (_conDevice != -1)
////{
//// conDevice.captionText.text = mybody.cableGroupName;
//// conDevice.value = _conDevice;
////}
//findIndex(conDevice, mybody.conDevice);
////Debug.Log("版本号 1.1.1");
#endregion
OnToggleChanged(toggle);
init();
}
/// <summary>
/// 寻找下拉菜单选项
/// </summary>
/// <param name="_dro"></param>
/// <param name="_name"></param>
public string findIndex(Dropdown _dro, string _name)
{
if (string.IsNullOrEmpty(_name) && cableGroupName == _dro)
{
_name = LineGroupManager.Instance.selected_group_name;
}
int index = _dro.options.FindIndex(x => x.text == _name);
if (index != -1)
{
_dro.captionText.text = _dro.options[index].text;
_dro.value = index;
return index.ToString();
}
return null;
}
/// <summary>
/// 寻找对联机柜
/// </summary>
public string findconCabinet()
{
GameObject _go = null;
List<GameObject> gos = new List<GameObject>();
gos.AddRange(GameManager.Inst.Racks_go);
gos.AddRange(GameManager.Inst.TmsCards_go);
for (int i = 0; i < gos.Count; i++)
{
if (gos[i].GetComponent<DeviceQuery>().deviceList.id == mybody.conDevice && !string.IsNullOrEmpty(mybody.conDevice))
{
_go = gos[i];
break;
}
}
GameObject go = null;
if (_go != null)
{
go = GameManager.Inst.FindParent(_go, GameManager.Inst.IsDesiredParent);
if (go != null)
{
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
if (GameManager.Inst.Cabinets_go[i].name == go.name)
{
conCabinet.value = i;
conCabinet.captionText.text = go.name;
return go.name;
//break;
}
}
//conCabinet.captionText.text = go.name;
}
else
{
conCabinet.captionText.text = "";
conCabinet.value = int.MaxValue;
}
}
else
{
conCabinet.captionText.text = "";
conCabinet.value = int.MaxValue;
}
return "";
}
/// <summary>
/// 将点击的端口信息同步到UI
/// true:PortList1 false:PortList2
/// </summary>
/// <param name="p"></param>
/// <param name="isPortList1"></param>
public void AutoShowInfo(PortQuery p, bool isPortList1)
{
if (isPortList1)
{
PortList1 = p.portList;
PortList1_game = p.gameObject;
}
else
{
PortList2 = p.portList;
PortList2_game = p.gameObject;
}
// 是P1 并且 P2是空【自动获取P2】
if (isPortList1 && (PortList2 == null || string.IsNullOrEmpty(PortList2.id)))
{
#region P1
//deviceName_dic.Clear();
//mybody.id = p.portList.id;
//mybody.port = p.portList.port;
//mybody.portCode = p.portList.portCode;
//mybody.portName = p.portList.portName;
//mybody.portType = p.portList.portType;
//mybody.portPosition = p.portList.portPosition;
//mybody.deviceId = p.portList.deviceId;
//mybody.deviceName = p.portList.deviceName;
//mybody.portModel = p.portList.portModel;
//mybody.status = p.portList.status;
//mybody.cableName = p.portList.cableName;
//mybody.cableGroupName = p.portList.cableGroupName;
//mybody.remark = p.portList.remark;
//mybody.createTime = p.portList.createTime;
//mybody.createName = p.portList.createName;
//var part_game = GameManager.Inst.FindParent(PortList1_game, GameManager.Inst.IsFindRacks_goORMachineSlots_goORTmsCards_go);
//if (part_game)
//{
// var dp = part_game.GetComponent<DeviceQuery>();
// if (dp != null)
// {
// deviceName.text = dp.deviceList.deviceName;//① 所属设备
// if (!string.IsNullOrEmpty(dp.deviceList.deviceName))
// deviceName_dic.Add(dp.deviceList.deviceName, dp.deviceList.id);
// else
// {
// if (!deviceName_dic.Keys.Contains(""))
// deviceName_dic.Add("", string.Empty);
// }
// }
//}
//portCode.text = p.portList.portCode;//② 编号
//portName.text = p.portList.portName;//③ 名称
//port.text = p.portList.port;//④ 端口
//cableName.text = p.portList.cableName;
//add_cableGroupName_options();
//if (findIndex(cableGroupName, p.portList.cableGroupName) == null)
// findIndex(cableGroupName, "");
//addconCabinet();
//var c = GameManager.Inst.FindParent(PortList1_game, GameManager.Inst.IsDesiredParent);
//if (c)
// //findIndex(startCabinet, c.name);
// findIndex(startCabinet, c.GetComponent<DeviceQuery>().deviceList.deviceName);
//add_portType_options();
//if (findIndex(portType, p.portList.portType) == null)
// findIndex(cableGroupName, "");
#endregion
PackageInfo_P1(p);
/**********************************************/
mybody.conDevice = p.portList.conDevice;
mybody.conDeviceName = p.portList.conDeviceName;
mybody.conPort = p.portList.conPort;
conPort.text = p.portList.conPort;//④(对联)端口
conDeviceName.text = "";//①(对联)所属设备
//对联端口
var conPort_game = (GameManager.Inst.TmsPorts_go).FirstOrDefault(x =>
(x.GetComponent<PortQuery>().portList.deviceId == p.portList.conDevice &&
x.GetComponent<PortQuery>().portList.port == p.portList.conPort &&
x.GetComponent<PortQuery>().portList.deviceName == p.portList.conDeviceName));
var c2 = GameManager.Inst.FindParent(conPort_game, GameManager.Inst.IsDesiredParent);
findIndex(conCabinet, c2 == null ? "" : c2.GetComponent<DeviceQuery>().deviceList.deviceName);//(对联)机柜
//对联端口所属设备
var part_game1 = GameManager.Inst.FindParent(conPort_game, GameManager.Inst.IsFindRacks_goORMachineSlots_goORTmsCards_go);
if (part_game1)
{
var d_ = part_game1.GetComponent<DeviceQuery>();
var d_name = d_.deviceList.deviceName;
if (!string.IsNullOrEmpty(d_name))
{
conDeviceName.text = d_name;
conDevice_dic.Clear();
conDevice_dic.Add(d_name, d_.deviceList.id);
}
}
if (conPort_game != null)
{
var con = conPort_game.GetComponent<PortQuery>();
conPortCode.text = con.portList.portCode;//②(对联)编号
conPortName.text = con.portList.portName;//③(对联)名称
}
else
{
conPortCode.text = null;//②(对联)编号
conPortName.text = null;//③(对联)名称
}
}
// 是P1 并且 P2不空【只修改P1】
else if (isPortList1 && PortList2 != null && !string.IsNullOrEmpty(PortList2.id))
{
PackageInfo_P1(p);
}
// 是P2
else if (!isPortList1)//对联端口的
{
conDevice_dic.Clear();
conDeviceName.text = "";
var part_game2 = GameManager.Inst.FindParent(PortList2_game, GameManager.Inst.IsFindRacks_goORMachineSlots_goORTmsCards_go);
if (part_game2)
{
var dp = part_game2.GetComponent<DeviceQuery>();
if (dp != null)
{
conDeviceName.text = dp.deviceList.deviceName;//①(对联)所属设备
conDevice_dic.Add(conDeviceName.text, dp.deviceList.id);
}
}
conPortCode.text = p.portList.portCode;//②(对联)编号
conPortName.text = p.portList.portName;//③(对联)名称
conPort.text = p.portList.port;//④(对联)端口
addconCabinet();
var c = GameManager.Inst.FindParent(PortList2_game, GameManager.Inst.IsDesiredParent);
if (c)
//findIndex(conCabinet, c.name);
findIndex(conCabinet, c.GetComponent<DeviceQuery>().deviceList.deviceName);
/**********************************************/
mybody.conDevice = p.portList.deviceId;
mybody.conDeviceName = conDeviceName.text;
mybody.conPort = p.portList.port;
}
}
/// <summary>
/// 封装同步P1数据
/// </summary>
public void PackageInfo_P1(PortQuery p)
{
deviceName_dic.Clear();
mybody.id = p.portList.id;
mybody.port = p.portList.port;
mybody.portCode = p.portList.portCode;
mybody.portName = p.portList.portName;
mybody.portType = p.portList.portType;
mybody.portPosition = p.portList.portPosition;
mybody.deviceId = p.portList.deviceId;
mybody.deviceName = p.portList.deviceName;
mybody.portModel = p.portList.portModel;
mybody.status = p.portList.status;
mybody.cableName = p.portList.cableName;
mybody.cableGroupName = p.portList.cableGroupName;
mybody.remark = p.portList.remark;
mybody.createTime = p.portList.createTime;
mybody.createName = p.portList.createName;
var part_game = GameManager.Inst.FindParent(PortList1_game, GameManager.Inst.IsFindRacks_goORMachineSlots_goORTmsCards_go);
if (part_game)
{
var dp = part_game.GetComponent<DeviceQuery>();
if (dp != null)
{
deviceName.text = dp.deviceList.deviceName;//① 所属设备
if (!string.IsNullOrEmpty(dp.deviceList.deviceName))
deviceName_dic.Add(dp.deviceList.deviceName, dp.deviceList.id);
else
{
if (!deviceName_dic.Keys.Contains(""))
deviceName_dic.Add("", string.Empty);
}
}
}
portCode.text = p.portList.portCode;//② 编号
portName.text = p.portList.portName;//③ 名称
port.text = p.portList.port;//④ 端口
if (!string.IsNullOrEmpty(p.portList.conDevice))// 线缆名
cableName.text = p.portList.cableName;
add_cableGroupName_options();// 线缆组名
if (!string.IsNullOrEmpty(p.portList.conDevice) && findIndex(cableGroupName, p.portList.cableGroupName) == null)
findIndex(cableGroupName, "");
addconCabinet();
var c = GameManager.Inst.FindParent(PortList1_game, GameManager.Inst.IsDesiredParent);
if (c)
//findIndex(startCabinet, c.name);
findIndex(startCabinet, c.GetComponent<DeviceQuery>().deviceList.deviceName);
add_portType_options();// 线路类型
if (!string.IsNullOrEmpty(p.portList.conDevice) && findIndex(portType, p.portList.portType) == null)
findIndex(portType, "");
}
/// <summary>
/// 同步信息
/// </summary>
public void syncInfo(string nowDeviceID)
{
mybody = new Body();
//config = new MapperConfiguration(cfg =>
//{
// cfg.CreateMap<RedactPort.Body, PortQuery.PortList>();
// cfg.CreateMap<PortQuery.PortList, RedactPort.Body>();
//});
//mapper = config.CreateMapper();
try
{
if (!string.IsNullOrEmpty(GameManager.Inst.nowDeviceID))
{
for (int i = 0; i < GameManager.Inst.TmsPorts.Count; i++)
{
if (GameManager.Inst.TmsPorts[i].id == GameManager.Inst.nowDeviceID)
{
portlist = GameManager.Inst.TmsPorts[i];
break;
}
}
//mybody = mapper.Map<RedactPort.Body>(portlist);
if (portlist != null)
{
mybody.id = portlist.id;
mybody.port = portlist.port;
mybody.portCode = portlist.portCode;
mybody.portName = portlist.portName;
mybody.portType = portlist.portType;
mybody.portPosition = portlist.portPosition;
mybody.deviceId = portlist.deviceId;
mybody.deviceName = portlist.deviceName;
mybody.portModel = portlist.portModel;
mybody.status = portlist.status;
mybody.conDevice = portlist.conDevice;
mybody.conDeviceName = portlist.conDeviceName;
mybody.conPort = portlist.conPort;
mybody.cableName = portlist.cableName;
mybody.cableGroupName = portlist.cableGroupName;
mybody.remark = portlist.remark;
mybody.createTime = portlist.createTime;
mybody.createName = portlist.createName;
}
}
}
catch (Exception e)
{
Debug.Log(e.StackTrace + "**********" + e.Message);
}
}
/// <summary>
/// 同步信息
/// </summary>
public void syncInfo()
{
//config = new MapperConfiguration(cfg =>
//{
// cfg.CreateMap<RedactPort.Body, PortQuery.PortList>();
// cfg.CreateMap<PortQuery.PortList, RedactPort.Body>();
//});
//mapper = config.CreateMapper();
try
{
if (!string.IsNullOrEmpty(GameManager.Inst.nowDeviceID))
{
for (int i = 0; i < GameManager.Inst.TmsPorts.Count; i++)
{
if (GameManager.Inst.TmsPorts[i].id == GameManager.Inst.nowDeviceID)
{
portlist = GameManager.Inst.TmsPorts[i];
break;
}
}
//mybody = mapper.Map<RedactPort.Body>(portlist);
if (portlist != null)
{
mybody.id = portlist.id;
mybody.port = portlist.port;
mybody.portCode = portlist.portCode;
mybody.portName = portlist.portName;
mybody.portType = portlist.portType;
mybody.deviceId = portlist.deviceId;
mybody.deviceName = portlist.deviceName;
mybody.portModel = portlist.portModel;
mybody.status = portlist.status;
mybody.conDevice = portlist.conDevice;
mybody.conDeviceName = portlist.conDeviceName;
mybody.conPort = portlist.conPort;
mybody.cableName = portlist.cableName;
mybody.cableGroupName = portlist.cableGroupName;
mybody.remark = portlist.remark;
mybody.createTime = portlist.createTime;
mybody.createName = portlist.createName;
}
}
}
catch (Exception e)
{
Debug.Log(e.StackTrace + "**********" + e.Message);
}
}
/// <summary>
/// 获取端口的对联设备和对联端口选项
/// </summary>
public void init()
{
#region old
//List<string> conDevice_list = new List<string>();//对联设备
//List<string> conPort_list = new List<string>();// 对联端口
//conPort_list.Add("");
////加载所有对联设备和对联端口选项
//Dictionary<string, string> conDevice_list_dict = new Dictionary<string, string>();
//Dictionary<string, string> conPort_list_dict = new Dictionary<string, string>();
//if (GameManager.Inst.TmsPorts == null)
// return;
//foreach (var item in GameManager.Inst.TmsPorts)
//{
// if (!conDevice_list_dict.ContainsKey(item.deviceId) && !string.IsNullOrEmpty(item.deviceId))
// {
// conDevice_list_dict.Add(item.deviceId, item.deviceName);
// //conDevice_list.Add(item.deviceId);
// conDevice_list.Add(item.deviceName);
// }
// if (!conPort_list_dict.ContainsKey(item.port) && !string.IsNullOrEmpty(item.port))
// {
// conPort_list_dict.Add(item.port, "");
// conPort_list.Add(item.port);
// }
//}
//conDevice.options.Clear();
//conDevice_list.Add("");
//conDevice.AddOptions(conDevice_list);
//conDevice_dic.Clear();
//conDevice_dic = conDevice_list_dict;
//conPort.options.Clear();
//conPort.AddOptions(conPort_list);
//cableGroupName.options.Clear();
//foreach (var item in LineQuery.Inst.keyValues.Keys)
//{
// Dropdown.OptionData optionData = new Dropdown.OptionData(item);
// cableGroupName.options.Add(optionData);
//}
//Dropdown.OptionData optionData1 = new Dropdown.OptionData("");
//cableGroupName.options.Add(optionData1);
//cableGroupName.captionText.text = "";
//List<string> portType_list = new List<string>();
//foreach (var item in PatternChoose.Inst.xianlan.lineCode_dic.Keys)
//{
// portType_list.Add(item);
//}
//portType_list.Add("");
//portType.options.Clear();
//portType.AddOptions(portType_list);
//portType.captionText.text = "";
#endregion
if (!PortList1_game)
{
add_cableGroupName_options();
addconCabinet();
add_portType_options();
clearUI();
}
}
/// <summary>
/// 清除UI显示
/// </summary>
public void clearUI()
{
cableName.text = string.Empty;
findIndex(cableGroupName, "");
findIndex(portType, "");
findIndex(startCabinet, "");
deviceName.text = string.Empty;
portCode.text = string.Empty;
portName.text = string.Empty;
port.text = string.Empty;
findIndex(conCabinet, "");
conDeviceName.text = string.Empty;
conPortCode.text = string.Empty;
conPortName.text = string.Empty;
conPort.text = string.Empty;
}
/// <summary>
/// 添加线缆组下拉菜单选项
/// </summary>
public void add_cableGroupName_options()
{
cableGroupName.options.Clear();
foreach (var item in LineQuery.Inst.keyValues.Keys)
{
Dropdown.OptionData optionData = new Dropdown.OptionData(item);
cableGroupName.options.Add(optionData);
}
Dropdown.OptionData optionData1 = new Dropdown.OptionData("");
cableGroupName.options.Add(optionData1);
}
/// <summary>
/// 添加线路类型下拉菜单选项
/// </summary>
public void add_portType_options()
{
List<string> portType_list = new List<string>();
foreach (var item in PatternChoose.Inst.xianlan.lineCode_dic.Keys)
{
portType_list.Add(item);
}
portType_list.Add("");
portType.options.Clear();
portType.AddOptions(portType_list);
}
/// <summary>
/// 获取端口的对联设备和对联端口选项
/// </summary>
/// <param name="conCabinet_name">对联机柜</param>
public void init(string conCabinet_name)
{
#region old
//List<string> conDevice_list = new List<string>();//对联设备
//List<string> conPort_list = new List<string>();// 对联端口
//conPort_list.Add("");
////加载所有对联设备和对联端口选项
//Dictionary<string, string> conDevice_list_dict = new Dictionary<string, string>();
//Dictionary<string, string> conPort_list_dict = new Dictionary<string, string>();
//DeviceQuery d = null;
//for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
//{
// if (GameManager.Inst.Cabinets_go[i].name == conCabinet_name)
// {
// d = GameManager.Inst.Cabinets_go[i].GetComponent<DeviceQuery>();
// break;
// }
//}
//foreach (var item in d.gameObject.GetComponentsInChildren<PortQuery>())
//{
// if (!conDevice_list_dict.ContainsKey(item.portList.deviceId) && !string.IsNullOrEmpty(item.portList.deviceId) && !string.IsNullOrEmpty(item.portList.id))
// {
// conDevice_list_dict.Add(item.portList.deviceId, item.portList.deviceName);
// //conDevice_list.Add(item.deviceId);
// conDevice_list.Add(item.portList.deviceName);
// }
// if (!conPort_list_dict.ContainsKey(item.portList.port) && !string.IsNullOrEmpty(item.portList.port) && !string.IsNullOrEmpty(item.portList.id))
// {
// conPort_list_dict.Add(item.portList.port, "");
// conPort_list.Add(item.portList.port);
// }
//}
//conDevice.options.Clear();
//conDevice_list.Add("");
//conDevice.AddOptions(conDevice_list);
//conDevice_dic.Clear();
//conDevice_dic = conDevice_list_dict;
//conPort.options.Clear();
//conPort.AddOptions(conPort_list);
//cableGroupName.options.Clear();
//foreach (var item in LineQuery.Inst.keyValues.Keys)
//{
// Dropdown.OptionData optionData = new Dropdown.OptionData(item);
// cableGroupName.options.Add(optionData);
//}
//Dropdown.OptionData optionData1 = new Dropdown.OptionData("");
//cableGroupName.options.Add(optionData1);
//cableGroupName.captionText.text = "";
//List<string> portType_list = new List<string>();
//foreach (var item in PatternChoose.Inst.xianlan.lineCode_dic.Keys)
//{
// portType_list.Add(item);
//}
//portType_list.Add("");
//portType.options.Clear();
//portType.AddOptions(portType_list);
//portType.captionText.text = "";
#endregion
}
private void Start()
{
save_bt.onClick.AddListener(() =>
{
GameManager.Inst.editorMenu.gameObject.SetActive(false);
StartCoroutine(SaveJsonCoroutine());
});
//conDevice.onValueChanged.AddListener(OnDropdownValueChanged_conDevice);
//port.onValueChanged.AddListener(OnDropdownValueChanged_port);
conCabinet.onValueChanged.AddListener(OnDropdownValueChanged_conCabinet);
close_bt.onClick.AddListener(() =>
{
ExtendedFlycam.Inst.QieHuan(Menu.M_数字机房_线缆连接_配置);
LineGroupManager.Instance.ShowPanel();
SecondConfirmPanel.Instance.panel_object.SetActive(false);
});
add_onValueChanged();
cabinet1.onClick.AddListener(() =>
{
OnToggleChanged(toggle);
var name_ = startCabinet.options[startCabinet.value].text; //startCabinet.value.text.Split("/");
//if (!string.IsNullOrEmpty(findIndex(startCabinet, startCabinet.captionText.text)))
if (!string.IsNullOrEmpty(findIndex(startCabinet, name_)))
{
//var name_ = startCabinet.captionText.text.Split("/");
var v = GameManager.Inst.Cabinets_go.FirstOrDefault((x) => name_.Contains(x.name));
gotoCabinet(v);
}
});
cabinet2.onClick.AddListener(() =>
{
OnToggleChanged(con_toggle);
var name_ = conCabinet.options[conCabinet.value].text;
//if (!string.IsNullOrEmpty(findIndex(conCabinet, conCabinet.captionText.text)))
if (!string.IsNullOrEmpty(findIndex(conCabinet, name_)))
{
//var name_ = conCabinet.captionText.text.Split("/");
var v = GameManager.Inst.Cabinets_go.FirstOrDefault((x) => name_.Contains(x.name));
gotoCabinet(v);
}
});
}
/// <summary>
/// 跳转机柜
/// </summary>
/// <param name="Cabinet"></param>
public void gotoCabinet(GameObject Cabinet)
{
if (!Cabinet)
return;
Cabinet.GetComponent<ClickEvent>().Change_hide(Cabinet, true, true);
}
/// <summary>
/// 添加监听
/// </summary>
public void add_onValueChanged()
{
toggle.onValueChanged.AddListener(delegate
{
OnToggleChanged(toggle);
});
con_toggle.onValueChanged.AddListener(delegate
{
OnToggleChanged(con_toggle);
});
}
/// <summary>
/// 移除监听
/// </summary>
public void remove_onValueChanged()
{
toggle.onValueChanged.RemoveAllListeners();
con_toggle.onValueChanged.RemoveAllListeners();
}
private IEnumerator SaveJsonCoroutine()
{
Debug.Log("@@1");
yield return StartCoroutine(saveJson((x) =>
{
//Debug.Log("@@8");
if (x != null && URlreturn != null && URlreturn.message == "操作成功")
{
StartCoroutine(Succeed((x) =>
{
if (x)
{
refurbish();
}
else
{
SecondConfirmPanel.DeleteConform(null, "更新场景失败");
Debug.Log("接口获取数据失败(编辑端口-初始化失败)");
}
}));
}
else
{
Debug.Log("编辑端口失败: " + URlreturn.message);
SecondConfirmPanel.DeleteConform(null, (URlreturn != null) ? URlreturn.message : "编辑端口失败");
if (x != "isNull")
refurbish();
}
}));
}
/// <summary>
/// 刷新
/// </summary>
public void refurbish()
{
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
{
itme.gameObject.SetActive(false);
});
}
public IEnumerator Succeed(Action<bool> callback)
{
GameManager.Inst.isLoading = false;
//TransparentGlowManage.Inst.addScript();
//yield return StartCoroutine(GameManager.Inst.init_Device());
//yield return StartCoroutine(GameManager.Inst.init_Port());
//yield return StartCoroutine(LineQuery.Inst.getJsonCoroutine());
//GameManager.Inst.LoadScene();
//callback.Invoke(true);
yield return null;
StartCoroutine(GameManager.Inst.Initialize((x) =>
{
if (!string.IsNullOrEmpty(x))
callback.Invoke(true);
else
callback.Invoke(false);
}, true));
}
/// <summary>
/// 当 端口 值发生改变时(根据端口添加该端口下信息)
/// </summary>
/// <param name="index"></param>
private void OnDropdownValueChanged_port(int index)
{
if (index == 0) return;
//port.options[index]
//for (int i = 0; i < port.options.Count; i++)
//{
// if (i == port.value)
// {
// port.value = 0;
// port.value = i;
// }
//}
}
/// <summary>
/// 当 对联设备 值发生改变时(根据对联设备--添加该设备下所有端口)
/// </summary>
/// <param name="index"></param>
public void OnDropdownValueChanged_conDevice(int index)
{
#region old
//List<KeyValuePair<string, string>> orderedList = conDevice_dic.ToList();
//try
//{
// KeyValuePair<string, string> element = orderedList.ElementAt(index);
// conDevice_dic_id = element.Key;
//}
//catch (Exception)
//{
// conDevice_dic_id = null;
//}
////if (index == 0) return;
//List<string> conPort_list = new List<string>();//对联端口
//conPort_list.Add("");
//foreach (var item in GameManager.Inst.root_AllPort.data)
//{
// if (string.IsNullOrEmpty(conDevice_dic_id))
// {
// if (item.deviceName == conDevice.options[index].text && !string.IsNullOrEmpty(item.deviceName) && !string.IsNullOrEmpty(item.port))//conDevice.options[index]//对联设备名
// //if (item.deviceId == conDevice.options[index].text)//conDevice.options[index]//对联设备ID
// {
// conPort_list.Add(item.port);
// }
// }
// else
// {
// if (item.deviceId == conDevice_dic_id && !string.IsNullOrEmpty(item.port))
// {
// conPort_list.Add(item.port);
// }
// }
//}
//conPort.options.Clear();
//conPort.AddOptions(conPort_list);
//if (string.IsNullOrEmpty(mybody.conPort)) return;
////自动识别端口
//for (int i = 0; i < conPort.options.Count; i++)
//{
// if (conPort.options[i].text == mybody.conPort)
// {
// conPort.value = i;
// conPort.captionText.text = conPort.options[i].text;
// break;
// }
//}
#endregion
}
public void OnDropdownValueChanged_conCabinet(int index)
{
#region old
//List<string> conDevice_list = new List<string>();//对联设备
//conDevice_list.Add("");
//Dictionary<string, string> conDevice_list_dict = new Dictionary<string, string>();
//conDevice_list_dict.Add("", "");
//if (index != conCabinet.options.Count - 1)
//{
// var _s = GameManager.Inst.Cabinets_go[index].GetComponentsInChildren<DeviceQuery>();
// Array.ForEach(_s, (item) =>
// {
// if (!conDevice_list_dict.ContainsKey(item.deviceList.id) && !string.IsNullOrEmpty(item.deviceList.id) && item.deviceList.type != "1")
// {
// conDevice_list_dict.Add(item.deviceList.id, item.deviceList.deviceName);
// // conDevice_list.Add(item.deviceList.id);
// conDevice_list.Add(item.deviceList.deviceName);
// }
// });
// //conDevice_list.Add("");
// conDevice.options.Clear();
// conDevice.AddOptions(conDevice_list);
// conDevice_dic.Clear();
// conDevice_dic = conDevice_list_dict;
//}
//else
//{
// conDevice_dic.Clear();
// conDevice.options.Clear();
// conDevice.captionText.text = "";
//}
#endregion
}
private void Update()
{
//if ((cableGroupName.transform.Find("Dropdown List") && cableGroupName.transform.Find("Dropdown List").gameObject.activeSelf) ||
// (portType.transform.Find("Dropdown List") && portType.transform.Find("Dropdown List").gameObject.activeSelf))
//{
// // 下拉菜单处于展开状态。
// //Color color = save_bt_img.color;
// //color.a = 0;
// //save_bt_img.color = color;
// save_bt.gameObject.SetActive(false);
//}
//else
//{
// // 下拉菜单未展开。
// //Color color = save_bt_img.color;
// //color.a = 1;
// //save_bt_img.color = color;
// save_bt.gameObject.SetActive(true);
//}
if (conCabinet.transform.Find("Dropdown List"))
{
var content = conCabinet.transform.Find("Dropdown List").GetComponent<ScrollRect>().content.transform;
for (int i = 0; i < content.childCount; i++)
{
var text = content.GetChild(i).GetComponentInChildren<Text>();
text.SetTextWithEllipsis(text.text);
}
conCabinet.captionText.SetTextWithEllipsis(conCabinet.captionText.text);
}
if (startCabinet.transform.Find("Dropdown List"))
{
var content = startCabinet.transform.Find("Dropdown List").GetComponent<ScrollRect>().content.transform;
for (int i = 0; i < content.childCount; i++)
{
var text = content.GetChild(i).GetComponentInChildren<Text>();
string s = text.text;
text.SetTextWithEllipsis(s);
}
startCabinet.captionText.SetTextWithEllipsis(startCabinet.captionText.text);
}
GameManager.Inst.AdaptiveHight(content.gameObject, content, content_ret, content_grid);
}
/// <summary>
/// 端口-编辑保存
/// </summary>
/// <param name="token"></param>
public IEnumerator saveJson(Action<string> callback)
{
#region old
//if (string.IsNullOrEmpty(mybody.id))
// yield break;
//try
//{
// mybody.port = port.text;
// mybody.portCode = portCode.text;
// mybody.portName = portName.text;
// if (!string.IsNullOrEmpty(conDevice.captionText.text) && !string.IsNullOrEmpty(conPort.captionText.text))
// mybody.cableGroupName = cableGroupName.captionText.text;
// //mybody.deviceId = deviceId.text;
// //mybody.portModel = portModel.text;
// //mybody.status = status.value.ToString();
// //mybody.conDevice = conDevice.captionText.text;
// mybody.conDevice = conDevice_dic_id;
// mybody.conPort = conPort.captionText.text;
// mybody.cableName = cableName.text;
// mybody.portType = portType.captionText.text;
//}
//catch (Exception e)
//{
// Debug.Log("修改端口错误:" + e.Message);
// //gameObject.SetActive(false);
// callback.Invoke(null);
// yield break;
//}
#endregion
try
{
mybody.portType = string.IsNullOrEmpty(portType.captionText.text) ? null : portType.captionText.text;
mybody.deviceId = deviceName_dic.ContainsKey(deviceName.text) ? deviceName_dic[deviceName.text] : null;
mybody.portCode = portCode.text;
mybody.portName = portName.text;
mybody.port = port.text;
mybody.conDevice = conDevice_dic.ContainsKey(conDeviceName.text) ? conDevice_dic[conDeviceName.text] : null;
mybody.conPort = conPort.text;
//mybody.conId = PortList2.id;
mybody.conPortCode = conPortCode.text;
mybody.conPortName = conPortName.text;
// 回调传参 isNull 则编辑弹窗不关闭
bool isNull = string.IsNullOrEmpty(mybody.conDevice);
if (LineQuery.Inst.keyValues.ContainsKey(cableGroupName.captionText.text))
mybody.cableGroupName = LineQuery.Inst.keyValues[cableGroupName.captionText.text];
else
mybody.cableGroupName = null;
// 检测
if (isNull)
{
mybody.cableName = null;
mybody.cableGroupName = null;
}
else
{
// 起始端口未选择
if (string.IsNullOrEmpty(mybody.id))
{
URlreturn.message = "请选择端口";
callback?.Invoke("isNull");
yield break;
}
// 本地回环
if (PortList1.id == PortList2.id)
{
URlreturn.message = "该线路为本地回环,请重新选择连接线路";
callback?.Invoke("isNull");
yield break;
}
// 检测线缆名
if (CheckString(cableName.text))
{
mybody.cableName = cableName.text;
}
else
{
URlreturn.message = "请填写线缆名";
callback?.Invoke("isNull");
yield break;
}
// 检测线缆组名
if (CheckString(mybody.cableGroupName)) { }
else
{
URlreturn.message = "请填写线缆所属组名";
callback?.Invoke("isNull");
yield break;
}
}
mybody.conId = PortList2?.id;
}
catch (Exception e)
{
Debug.LogError(e.Message + "\n" + e.StackTrace);
callback.Invoke(null);
yield break;
}
string newData = JsonConvert.SerializeObject(mybody);
//Debug.Log(json);
yield return StartCoroutine(
CombineJSON.UpdateJson_POST(GameManager.Inst.Jk_URL.dk_bj, GameManager.Inst.arguments.token, newData, (jsonResult) =>
{
//Debug.Log("@@5");
try
{
URlreturn = JsonConvert.DeserializeObject<Root>(jsonResult);
callback?.Invoke(jsonResult);
//Debug.Log("@@6");
}
catch (Exception e)
{
Debug.Log("修改端口接口错误:" + e.Message);
callback.Invoke(null);
}
}
));
}
public void OnToggleChanged(Toggle _toggle)
{
if (_toggle == toggle)
{
remove_onValueChanged();
_toggle.isOn = true;
con_toggle.isOn = false;
add_onValueChanged();
}
else if (_toggle == con_toggle)
{
remove_onValueChanged();
_toggle.isOn = true;
toggle.isOn = false;
add_onValueChanged();
}
}
bool CheckString(string input)
{
if (string.IsNullOrWhiteSpace(input))
{
return false;
}
return true; // 如果没有空字符串或者只包含空格则返回true
}
public void OnDisable()
{
PortList2 = null;
deviceName_dic.Clear();
conDevice_dic.Clear();
}
#region JSON
[System.Serializable]
public class Body
{
/// <summary>
/// id
/// </summary>
public string id;
/// <summary>
/// 端口
/// </summary>
public string port;
/// <summary>
/// 编号
/// </summary>
public string portCode;
/// <summary>
/// 名称
/// </summary>
public string portName;
/// <summary>
/// 类型
/// </summary>
public string portType;
/// <summary>
/// 端口位置
/// </summary>
public string portPosition;
/// <summary>
/// 所属设备ID
/// </summary>
public string deviceId;
/// <summary>
/// 型号
/// </summary>
public string portModel;
/// <summary>
/// 是否启用1-正常0-禁用
/// </summary>
public string status;
/// <summary>
/// 对联设备ID
/// </summary>
public string conDevice;
/// <summary>
/// 对联端口
/// </summary>
public string conPort;
/// <summary>
/// 线缆名
/// </summary>
[Tooltip("线缆名")] public string cableName;
/// <summary>
/// 线缆组名
/// </summary>
[Tooltip("线缆组名")] public string cableGroupName;
/// <summary>
/// 备注
/// </summary>
public string remark;
/// <summary>
/// 所属设备名称
/// </summary>
public string deviceName;
/// <summary>
/// 对联设备名称
/// </summary>
public string conDeviceName;
/// <summary>
///
/// </summary>
public string createTime;
/// <summary>
///
/// </summary>
public string createName;
/// <summary>
/// 要改的(对联)-端口ID【自己需要的】
/// </summary>
public string conId;
/// <summary>
/// 要改的(对联)-端口编号【自己需要的】
/// </summary>
public string conPortCode;
/// <summary>
/// 要改的(对联)-端口名【自己需要的】
/// </summary>
public string conPortName;
}
[System.Serializable]
public class Root
{
/// <summary>
///
/// </summary>
public string code;
/// <summary>
/// 反馈结果
/// </summary>
public string message;
/// <summary>
/// 返回内容
/// </summary>
public string data;
/// <summary>
///
/// </summary>
public string serverTime;
}
#endregion
}