private void cbCmdTableType_SelectedIndexChanged(object sender, EventArgs e) { // изменение типа таблицы данных команды if (modbusCmd != null) { modbusCmd.TableType = cbCmdTableType.SelectedIndex == 0 ? TableTypes.Coils : TableTypes.HoldingRegisters; modbusCmd.UpdateFuncCode(); ShowFuncCode(modbusCmd); ShowByteOrder(modbusCmd); // установка типа элементов команды по умолчанию cbCmdElemType.SelectedIndex = (int)modbusCmd.DefElemType; // ограничение макс. количества элементов в команде int maxElemCnt = DataUnit.GetMaxElemCnt(modbusCmd.TableType); if (numCmdElemCnt.Value > maxElemCnt) { numCmdElemCnt.Value = maxElemCnt; } numCmdElemCnt.Maximum = maxElemCnt; OnObjectChanged(TreeUpdateTypes.CurrentNode); } }
/// <summary> /// Отобразить свойства группы элементов /// </summary> private void ShowElemGroupProps(ElemGroup elemGroup) { numGrAddress.Value = 1; numGrAddress.Minimum = AddrShift; numGrAddress.Maximum = ushort.MaxValue + AddrShift; numGrAddress.Hexadecimal = !DecAddr; ShowFuncCode(elemGroup); if (elemGroup == null) { chkGrActive.Checked = false; txtGrName.Text = ""; cbGrTableType.SelectedIndex = 0; numGrAddress.Value = AddrShift; lblGrAddressHint.Text = ""; numGrElemCnt.Value = 1; gbElemGroup.Enabled = false; } else { chkGrActive.Checked = elemGroup.Active; txtGrName.Text = elemGroup.Name; cbGrTableType.SelectedIndex = (int)elemGroup.TableType; numGrAddress.Value = elemGroup.Address + AddrShift; lblGrAddressHint.Text = string.Format(KpPhrases.AddressHint, AddrNotation, AddrShift); numGrElemCnt.Value = 1; numGrElemCnt.Maximum = DataUnit.GetMaxElemCnt(elemGroup.TableType); numGrElemCnt.Value = elemGroup.Elems.Count; gbElemGroup.Enabled = true; } }
private void cbGrTableType_SelectedIndexChanged(object sender, EventArgs e) { // изменение типа таблицы данных группы элементов if (elemGroup != null) { TableTypes tableType = (TableTypes)cbGrTableType.SelectedIndex; int maxElemCnt = DataUnit.GetMaxElemCnt(tableType); bool cancel = elemGroup.Elems.Count > maxElemCnt && MessageBox.Show(string.Format(KpPhrases.ElemRemoveWarning, maxElemCnt), CommonPhrases.QuestionCaption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) != DialogResult.Yes; if (cancel) { cbGrTableType.SelectedIndexChanged -= cbGrTableType_SelectedIndexChanged; cbGrTableType.SelectedIndex = (int)elemGroup.TableType; cbGrTableType.SelectedIndexChanged += cbGrTableType_SelectedIndexChanged; } else { // ограничение макс. количества элементов в группе if (numGrElemCnt.Value > maxElemCnt) { numGrElemCnt.Value = maxElemCnt; } numGrElemCnt.Maximum = maxElemCnt; // установка типа таблицы данных elemGroup.TableType = tableType; elemGroup.UpdateFuncCode(); ShowFuncCode(elemGroup); // установка типа элементов группы по умолчанию ElemTypes elemType = elemGroup.DefElemType; foreach (Elem elem in elemGroup.Elems) { elem.ElemType = elemType; } OnObjectChanged(TreeUpdateTypes.CurrentNode | TreeUpdateTypes.ChildNodes); } } }
/// <summary> /// Отобразить свойства команды /// </summary> private void ShowCmdProps(ModbusCmd modbusCmd) { numCmdAddress.Value = 1; numCmdAddress.Minimum = AddrShift; numCmdAddress.Maximum = ushort.MaxValue + AddrShift; numCmdAddress.Hexadecimal = !DecAddr; ShowFuncCode(modbusCmd); ShowByteOrder(modbusCmd); if (modbusCmd == null) { txtCmdName.Text = ""; cbCmdTableType.SelectedIndex = 0; numCmdAddress.Value = AddrShift; lblCmdAddressHint.Text = ""; cbCmdElemType.SelectedIndex = 0; numCmdElemCnt.Value = 1; txtCmdByteOrder.Text = ""; numCmdNum.Value = 1; gbCmd.Enabled = false; } else { txtCmdName.Text = modbusCmd.Name; cbCmdTableType.SelectedIndex = modbusCmd.TableType == TableTypes.Coils ? 0 : 1; chkCmdMultiple.Checked = modbusCmd.Multiple; numCmdAddress.Value = modbusCmd.Address + AddrShift; lblCmdAddressHint.Text = string.Format(KpPhrases.AddressHint, AddrNotation, AddrShift); cbCmdElemType.SelectedIndex = (int)modbusCmd.ElemType; numCmdElemCnt.Value = 1; numCmdElemCnt.Maximum = DataUnit.GetMaxElemCnt(modbusCmd.TableType); numCmdElemCnt.Value = modbusCmd.ElemCnt; cbCmdElemType.Enabled = modbusCmd.ElemTypeEnabled; numCmdElemCnt.Enabled = modbusCmd.Multiple; numCmdNum.Value = modbusCmd.CmdNum; gbCmd.Enabled = true; } }
private void btnAddElem_Click(object sender, EventArgs e) { // создание элемента и добавление в шаблон устройства ElemGroup elemGroup = selElemGroup == null ? selElemInfo.ElemGroup : selElemGroup; int maxElemCnt = DataUnit.GetMaxElemCnt(elemGroup.TableType); if (elemGroup.Elems.Count >= maxElemCnt) { MessageBox.Show(string.Format(KpPhrases.ElemCntExceeded, maxElemCnt), CommonPhrases.WarningCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } ElemInfo elemInfo = new ElemInfo(); elemInfo.Elem = new Elem() { ElemType = elemGroup.DefElemType }; elemInfo.ElemGroup = elemGroup; elemInfo.Settings = template.Sett; int ind = selNode.Tag is ElemInfo ? selNode.Index + 1 : elemGroup.Elems.Count; elemGroup.Elems.Insert(ind, elemInfo.Elem); // создание узла дерева элемента TreeNode elemNode = NewElemNode(elemInfo); TreeNode grNode = selNode.Tag is ElemInfo ? selNode.Parent : selNode; grNode.Nodes.Insert(ind, elemNode); UpdateElemNodes(grNode); UpdateSignals(grNode); treeView.SelectedNode = elemNode; ctrlElem.SetFocus(); // установка признака изменения Modified = true; }