//using AutoMapper;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
///
/// 端口-编辑
///
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;
///
/// 端口
///
//public Dropdown port;
public InputField port;
///
/// 编号
///
public InputField portCode;
///
/// 名称
///
public InputField portName;
///
/// 线缆组名称
///
public Dropdown cableGroupName;
/////
///// 所属设备
/////
//public InputField deviceId;
///
/// 型号
///
//public InputField portModel;
///
/// 状态
///
//public Dropdown status;
///
/// 线路类型
///
public Dropdown portType;
///
/// 起始端口机柜
///
public Dropdown startCabinet;
///
/// 对联机柜
///
public Dropdown conCabinet;
///
/// 对联设备【(对联)所属设备】
///
//public Dropdown conDevice;
public Text conDeviceName;
///
/// 对联端口
///
//public Dropdown conPort;
public Text conPort;
///
/// 对联端口编号
///
//public Text conPortCode;
public InputField conPortCode;
///
/// 对联端口名
///
//public Text conPortName;
public InputField conPortName;
public InputField cableName;
///
/// 起始端口所属设备
///
public Text deviceName;
///
/// 本设备ID和名字关联字典
///
public Dictionary deviceName_dic = new Dictionary();
///
/// 对联设备ID和名字关联字典
///
public Dictionary conDevice_dic = new Dictionary();
public string conDevice_dic_id;
public Button close_bt;
private void Awake()
{
Inst = this;
content_ret = content.GetComponent();
content_grid = content.GetComponent();
save_bt_img = save_bt.GetComponent();
//addconCabinet();
//conCabinet.captionText.text = null;
//findIndex(conCabinet, "");
gameObject.SetActive(false);
}
///
/// 添加跳转机柜下拉菜单内容
///
public void addconCabinet()
{
conCabinet.options.Clear();
startCabinet.options.Clear();
var startCabinet_Content = startCabinet.template.GetComponent().content.transform;
var conCabinet_Content = conCabinet.template.GetComponent().content.transform;
List conCabinetname = new List();
int index = 1;
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
DeviceQuery cabinetItem = GameManager.Inst.Cabinets_go[i].GetComponent();
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 conCabinet_text = conCabinet_Content.GetChild(index).GetChild(1).GetComponent();
//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();
}
///
/// 寻找下拉菜单选项
///
///
///
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;
}
///
/// 寻找对联机柜
///
public string findconCabinet()
{
GameObject _go = null;
List gos = new List();
gos.AddRange(GameManager.Inst.Racks_go);
gos.AddRange(GameManager.Inst.TmsCards_go);
for (int i = 0; i < gos.Count; i++)
{
if (gos[i].GetComponent().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 "";
}
///
/// 将点击的端口信息同步到UI
/// true:PortList1 false:PortList2
///
///
///
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();
// 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().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().portList.deviceId == p.portList.conDevice &&
x.GetComponent().portList.port == p.portList.conPort &&
x.GetComponent().portList.deviceName == p.portList.conDeviceName));
var c2 = GameManager.Inst.FindParent(conPort_game, GameManager.Inst.IsDesiredParent);
findIndex(conCabinet, c2 == null ? "" : c2.GetComponent().deviceList.deviceName);//(对联)机柜
//对联端口所属设备
var part_game1 = GameManager.Inst.FindParent(conPort_game, GameManager.Inst.IsFindRacks_goORMachineSlots_goORTmsCards_go);
if (part_game1)
{
var d_ = part_game1.GetComponent();
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();
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();
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().deviceList.deviceName);
/**********************************************/
mybody.conDevice = p.portList.deviceId;
mybody.conDeviceName = conDeviceName.text;
mybody.conPort = p.portList.port;
}
}
///
/// 封装同步P1数据
///
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();
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().deviceList.deviceName);
add_portType_options();// 线路类型
if (!string.IsNullOrEmpty(p.portList.conDevice) && findIndex(portType, p.portList.portType) == null)
findIndex(portType, "");
}
///
/// 同步信息
///
public void syncInfo(string nowDeviceID)
{
mybody = new Body();
//config = new MapperConfiguration(cfg =>
//{
// cfg.CreateMap();
// cfg.CreateMap();
//});
//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(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);
}
}
///
/// 同步信息
///
public void syncInfo()
{
//config = new MapperConfiguration(cfg =>
//{
// cfg.CreateMap();
// cfg.CreateMap();
//});
//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(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);
}
}
///
/// 获取端口的对联设备和对联端口选项
///
public void init()
{
#region old
//List conDevice_list = new List();//对联设备
//List conPort_list = new List();// 对联端口
//conPort_list.Add("");
////加载所有对联设备和对联端口选项
//Dictionary conDevice_list_dict = new Dictionary();
//Dictionary conPort_list_dict = new Dictionary();
//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 portType_list = new List();
//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();
}
}
///
/// 清除UI显示
///
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;
}
///
/// 添加线缆组下拉菜单选项
///
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);
}
///
/// 添加线路类型下拉菜单选项
///
public void add_portType_options()
{
List portType_list = new List();
foreach (var item in PatternChoose.Inst.xianlan.lineCode_dic.Keys)
{
portType_list.Add(item);
}
portType_list.Add("");
portType.options.Clear();
portType.AddOptions(portType_list);
}
///
/// 获取端口的对联设备和对联端口选项
///
/// 对联机柜
public void init(string conCabinet_name)
{
#region old
//List conDevice_list = new List();//对联设备
//List conPort_list = new List();// 对联端口
//conPort_list.Add("");
////加载所有对联设备和对联端口选项
//Dictionary conDevice_list_dict = new Dictionary();
//Dictionary conPort_list_dict = new Dictionary();
//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();
// break;
// }
//}
//foreach (var item in d.gameObject.GetComponentsInChildren())
//{
// 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 portType_list = new List();
//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);
}
});
}
///
/// 跳转机柜
///
///
public void gotoCabinet(GameObject Cabinet)
{
if (!Cabinet)
return;
Cabinet.GetComponent().Change_hide(Cabinet, true, true);
}
///
/// 添加监听
///
public void add_onValueChanged()
{
toggle.onValueChanged.AddListener(delegate
{
OnToggleChanged(toggle);
});
con_toggle.onValueChanged.AddListener(delegate
{
OnToggleChanged(con_toggle);
});
}
///
/// 移除监听
///
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();
}
}));
}
///
/// 刷新
///
public void refurbish()
{
Array.ForEach(GameManager.Inst.pop_ups.ToArray(), (itme) =>
{
itme.gameObject.SetActive(false);
});
}
public IEnumerator Succeed(Action 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));
}
///
/// 当 端口 值发生改变时(根据端口添加该端口下信息)
///
///
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;
// }
//}
}
///
/// 当 对联设备 值发生改变时(根据对联设备--添加该设备下所有端口)
///
///
public void OnDropdownValueChanged_conDevice(int index)
{
#region old
//List> orderedList = conDevice_dic.ToList();
//try
//{
// KeyValuePair element = orderedList.ElementAt(index);
// conDevice_dic_id = element.Key;
//}
//catch (Exception)
//{
// conDevice_dic_id = null;
//}
////if (index == 0) return;
//List conPort_list = new List();//对联端口
//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 conDevice_list = new List();//对联设备
//conDevice_list.Add("");
//Dictionary conDevice_list_dict = new Dictionary();
//conDevice_list_dict.Add("", "");
//if (index != conCabinet.options.Count - 1)
//{
// var _s = GameManager.Inst.Cabinets_go[index].GetComponentsInChildren();
// 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().content.transform;
for (int i = 0; i < content.childCount; i++)
{
var text = content.GetChild(i).GetComponentInChildren();
text.SetTextWithEllipsis(text.text);
}
conCabinet.captionText.SetTextWithEllipsis(conCabinet.captionText.text);
}
if (startCabinet.transform.Find("Dropdown List"))
{
var content = startCabinet.transform.Find("Dropdown List").GetComponent().content.transform;
for (int i = 0; i < content.childCount; i++)
{
var text = content.GetChild(i).GetComponentInChildren();
string s = text.text;
text.SetTextWithEllipsis(s);
}
startCabinet.captionText.SetTextWithEllipsis(startCabinet.captionText.text);
}
GameManager.Inst.AdaptiveHight(content.gameObject, content, content_ret, content_grid);
}
///
/// 端口-编辑保存
///
///
public IEnumerator saveJson(Action 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(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
{
///
/// id
///
public string id;
///
/// 端口
///
public string port;
///
/// 编号
///
public string portCode;
///
/// 名称
///
public string portName;
///
/// 类型
///
public string portType;
///
/// 端口位置
///
public string portPosition;
///
/// 所属设备(ID)
///
public string deviceId;
///
/// 型号
///
public string portModel;
///
/// 是否启用:1-正常;0-禁用
///
public string status;
///
/// 对联设备(ID)
///
public string conDevice;
///
/// 对联端口
///
public string conPort;
///
/// 线缆名
///
[Tooltip("线缆名")] public string cableName;
///
/// 线缆组名
///
[Tooltip("线缆组名")] public string cableGroupName;
///
/// 备注
///
public string remark;
///
/// 所属设备名称
///
public string deviceName;
///
/// 对联设备名称
///
public string conDeviceName;
///
///
///
public string createTime;
///
///
///
public string createName;
///
/// 要改的(对联)-端口ID【自己需要的】
///
public string conId;
///
/// 要改的(对联)-端口编号【自己需要的】
///
public string conPortCode;
///
/// 要改的(对联)-端口名【自己需要的】
///
public string conPortName;
}
[System.Serializable]
public class Root
{
///
///
///
public string code;
///
/// 反馈结果
///
public string message;
///
/// 返回内容
///
public string data;
///
///
///
public string serverTime;
}
#endregion
}