void _UpdateCmpTrig() { JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; if (null == nameMgr.AllCmpTrigNames() || 0 == nameMgr.AllCmpTrigNames().Length) //系统中不存在已命名的AI通道 { ShowTips("系统配置中不存在已命名的CmpTrig通道!"); btAdd.Enabled = false; } else { btAdd.Enabled = true; } string[] cmpTrigNames = _station.CmpTrigNames; if (null == cmpTrigNames || 0 == cmpTrigNames.Length) { btDel.Enabled = false; return; } else//if(null != chnNames) { btDel.Enabled = true; foreach (string cmpTrigName in cmpTrigNames) { DataGridViewRow row = new DataGridViewRow(); DataGridViewTextBoxCell cellName = new DataGridViewTextBoxCell(); cellName.Value = cmpTrigName; DataGridViewTextBoxCell cellInfo = new DataGridViewTextBoxCell(); JFDevCellInfo devInfo = nameMgr.GetCmpTrigCellInfo(cmpTrigName); if (null == devInfo) { cellName.Style.ForeColor = Color.Red; cellInfo.Value = "无效的通道名称,在配置中不存在!"; cellInfo.Style.ForeColor = Color.Red; } else { cellInfo.Value = string.Format("控制器:{0} - 模块:{1} - 通道:{2}", devInfo.DeviceID, devInfo.ModuleIndex, devInfo.ChannelIndex); } row.Cells.Add(cellName); row.Cells.Add(cellInfo); dgvNameInfos.Rows.Add(row); } } }
void _AddCmpTrigNames() { string[] allChnNames = null; //系统中所有已命名的通道 string[] existChnNames = null; //已存在的通道名称 JFDevCellNameManeger nameMgr = JFHubCenter.Instance.MDCellNameMgr; allChnNames = nameMgr.AllCmpTrigNames(); //系统名称表中所有可用的DI通道名称 existChnNames = _station.CmpTrigNames; //工站中已有的DI通道名称 if (null == allChnNames || 0 == allChnNames.Length) { MessageBox.Show("不存在" + _chnType.ToString() + "命名通道"); return; } List <string> lstAddNames = new List <string>(); //可供添加的DI通道名称 if (null == existChnNames || 0 == existChnNames.Length) { lstAddNames.AddRange(allChnNames); } else { foreach (string chnName in allChnNames) { if (!existChnNames.Contains(chnName)) { lstAddNames.Add(chnName); } } } if (lstAddNames.Count == 0) { MessageBox.Show("没有可供添加的" + _chnType.ToString() + "命名通道"); return; } List <string> lstAddInfos = new List <string>(); foreach (string addName in lstAddNames) { JFDevCellInfo chnInfo = nameMgr.GetCmpTrigCellInfo(addName); lstAddInfos.Add(string.Format("控制器:{0} - 模块:{1} - 通道:{2}", chnInfo.DeviceID, chnInfo.ModuleIndex, chnInfo.ChannelIndex)); } FormAddNames frm = new FormAddNames(); frm.Text = "为工站:" + _station.Name + " 添加CmpTrig命名通道"; frm.SetAvailedNames(lstAddNames.ToArray(), lstAddInfos.ToArray()); if (DialogResult.OK == frm.ShowDialog()) { string[] chnNamesWillAdd = null; string[] chnInfosWillAdd = null; frm.GetSelectNameInfos(out chnNamesWillAdd, out chnInfosWillAdd); for (int i = 0; i < chnNamesWillAdd.Length; i++) { string chnName = chnNamesWillAdd[i]; _station.AddCmpTrig(chnName); } _station.SaveCfg(); UpdateStation2UI(); } }