//public int GetInsertIndexOfList(ListItemType listItemType) // { // } //public void Add(RegisterItem register) // { // } public void AddOutputStatus(StatusRegister status) { ListViewItem listItem = null; if (_nMaxCoilIndex < 0 || _nSubIndexOfOutputStatus > 7) { listItem = new ListViewItem(); _nSubIndexOfOutputStatus = 0; listItem.UseItemStyleForSubItems = false; if ((_nMaxCoilIndex >= 0 && this.Items.Count > (_nMaxCoilIndex + 1))) { this.Items.Insert(_nMaxCoilIndex + 1, listItem); } else if (_nMaxCoilIndex < 0 && this.Items.Count > 0) { this.Items.Insert(0, listItem); } else { this.Items.Add(listItem); } IncMaxCoilIndex(); } else { listItem = this.Items[_nMaxCoilIndex]; } for (int nIndex = 0; nIndex < status._lsLoName.Count; nIndex++) { if (_nSubIndexOfOutputStatus == 0) { listItem.SubItems[0].BackColor = aItemsHeadColor[(int)ListItemType.Coils]; listItem.SubItems[0].Text = string.Format("{0:X4}", status._nStartAddr); listItem.SubItems.Add(status._lsLoName[nIndex]); } else { listItem.SubItems.Add(string.Format("{0:X4}", status._nStartAddr)); listItem.SubItems.Add(status._lsLoName[nIndex]); } _nSubIndexOfOutputStatus += 2; } }
public void AddCoil(int nAddr, string strHiName, string strLoName) { StatusRegister coil = new StatusRegister(); coil._nStartAddr = nAddr; coil._lsHiName.Add(strHiName); coil._lsLoName.Add(strLoName); coil._lsCurStatus.Add(false); if (_dicCoils == null) { _dicCoils = new SerializableDictionary <Int32, StatusRegister>(); } lock (_dicCoils) { _dicCoils.Add(nAddr, coil); } _bModified = true; }
public void AddInputStatus(int nAddr, bool bMultiBits, string[] aStrHiName, string[] aStrLoName) { StatusRegister intputStatus = new StatusRegister(); intputStatus._nStartAddr = nAddr; intputStatus._bMultiBits = bMultiBits; for (int nIndex = 0; nIndex < aStrHiName.Length; nIndex++) { intputStatus._lsHiName.Add(aStrHiName[nIndex]); intputStatus._lsLoName.Add(aStrLoName[nIndex]); intputStatus._lsCurStatus.Add(false); } if (_dicInputStatus == null) { _dicInputStatus = new SerializableDictionary <Int32, StatusRegister>(); } _dicInputStatus.Add(nAddr, intputStatus); _bModified = true; }
public void DblClickOnCoilItem(int nIndexOfList, int nSubIndex) { uint uiAddr = 0; int nAddrIndex = 0; int nIndexOfStatus = 0; bool bMultiBits = listView1.Items[nIndexOfList].SubItems[nAddrIndex].Text.Contains("-"); if (bMultiBits) { string strAddrText = listView1.Items[nIndexOfList].SubItems[0].Text; strAddrText = strAddrText.Substring(0, strAddrText.IndexOf("-")); frm8BitsSetting.HexToUint(strAddrText, ref uiAddr); nIndexOfStatus = listView1.Items[nIndexOfList].SubItems[nAddrIndex].Text.Contains("-L8") ? (nSubIndex - 1) : (nSubIndex + 8 - 1); } else { frm8BitsSetting.HexToUint(listView1.Items[nIndexOfList].SubItems[((int)(nSubIndex / 2)) * 2].Text, ref uiAddr); nIndexOfStatus = 0; } if ((nSubIndex == 0) || ((nSubIndex % 2) == 0 && !bMultiBits))//弹出设置对话框进行修改 { if (bMultiBits) { ShowSetMultiOutputDlg((int)uiAddr); } else { ShowSetOutputDlg((int)uiAddr); } } else //双击在子项上,设置高低状态 { if (_device._dicCoils.ContainsKey((int)uiAddr)) { StatusRegister coil = _device._dicCoils[(Int32)uiAddr]; bool bHiStatus = (listView1.Items[nIndexOfList].SubItems[nSubIndex].Text == coil._lsHiName[nIndexOfStatus]); if (bHiStatus) { coil._lsCurStatus[nIndexOfStatus] = false; listView1.Items[nIndexOfList].SubItems[nSubIndex].Text = coil._lsLoName[nIndexOfStatus]; listView1.Items[nIndexOfList].SubItems[nSubIndex].BackColor = Color.White; } else { coil._lsCurStatus[nIndexOfStatus] = true; listView1.Items[nIndexOfList].SubItems[nSubIndex].Text = coil._lsHiName[nIndexOfStatus]; listView1.Items[nIndexOfList].SubItems[nSubIndex].BackColor = Color.Red; } if (listView1.Items[nIndexOfList].SubItems[nSubIndex] == listView1._selectedSubItem) { listView1._colorBak = bHiStatus ? Color.White : Color.Red; } //_statusBar1.Panels[0].Text = string.Format("设置\"{0}\"", listView1.Items[nIndexOfList].SubItems[nSubIndex].Text); //ThreadStart thStart = new ThreadStart(ThreadSetOutput); Thread thSetOutput = new Thread(new ParameterizedThreadStart(ThreadSetOutput)); object[] param = new object[3]; param[0] = uiAddr; param[1] = _device; param[2] = listView1.Items[nIndexOfList].SubItems[nSubIndex].Text; thSetOutput.Start(param); } } }