private void btnImportKP_Click(object sender, EventArgs e) { if (lastLine != null) { // приём таблиц базы конфигурации при необходимости string errMsg; if (!baseTablesReceived && !ReceiveBaseTables(out errMsg)) { errLog.WriteAction(errMsg); ScadaUtils.ShowError(errMsg); } if (baseTablesReceived) { FrmImport frmImport; if (FrmImport.Import(tblKP, lastLine.Number, errLog, out frmImport) == DialogResult.OK) { // импорт КП try { lvReqSequence.BeginUpdate(); int newIndex = lastLine.ReqSequence.IndexOf(lastKP); newIndex = newIndex < 0 ? lastLine.ReqSequence.Count : newIndex + 1; bool insert = newIndex < lastLine.ReqSequence.Count; ListViewItem newItem = null; int kpIndex = newIndex; foreach (TreeNode nodeKP in frmImport.TreeView.Nodes) { if (nodeKP.Checked) { DataRowView rowKP = (DataRowView)nodeKP.Tag; Settings.KP newKP = new Settings.KP(); newKP.Number = (int)rowKP["KPNum"]; DefineKPProps(newKP, rowKP, true); newItem = NewKPItem(newKP, kpIndex); if (insert) { lastLine.ReqSequence.Insert(kpIndex, newKP); lvReqSequence.Items.Insert(kpIndex, newItem); } else { lastLine.ReqSequence.Add(newKP); lvReqSequence.Items.Add(newItem); } kpIndex++; } } // обновление порядковых номеров КП if (insert && kpIndex > newIndex) { for (int i = kpIndex + 1; i < lvReqSequence.Items.Count; i++) lvReqSequence.Items[i].Text = (i + 1).ToString(); } // выбор последнего добавленного элемента if (newItem != null) newItem.Selected = true; } catch (Exception ex) { errMsg = AppPhrases.ImportKpError + ":\r\n" + ex.Message; errLog.WriteAction(errMsg); ScadaUtils.ShowError(errMsg); } finally { SetModified(); lvReqSequence.EndUpdate(); } } } } lvReqSequence.Focus(); }
private void btnCopyKP_Click(object sender, EventArgs e) { if (lastLine != null && lastKP != null && lastKpItem != null) { copiedKP = lastKP; btnPasteKP.Enabled = true; } lvReqSequence.Focus(); }
private void btnAddKP_Click(object sender, EventArgs e) { if (lastLine != null) { int newIndex = lastLine.ReqSequence.IndexOf(lastKP); newIndex = newIndex < 0 ? lastLine.ReqSequence.Count : newIndex + 1; Settings.KP newKP = new Settings.KP(); ListViewItem newItem = NewKPItem(newKP, newIndex); if (newIndex < lastLine.ReqSequence.Count) { lastLine.ReqSequence.Insert(newIndex, newKP); lvReqSequence.Items.Insert(newIndex, newItem); for (int i = newIndex + 1; i < lvReqSequence.Items.Count; i++) lvReqSequence.Items[i].Text = (i + 1).ToString(); } else { lastLine.ReqSequence.Add(newKP); lvReqSequence.Items.Add(newItem); } newItem.Selected = true; SetModified(); } numKpNumber.Focus(); }
private void lvReqSequence_SelectedIndexChanged(object sender, EventArgs e) { changing = true; if (lvReqSequence.SelectedItems.Count > 0) { lastKpItem = lvReqSequence.SelectedItems[0]; lastKP = lastKpItem.Tag as Settings.KP; if (lastKP == null) { lastKpItem = null; } else { chkKpActive.Checked = lastKP.Active; chkKpBind.Checked = lastKP.Bind; numKpNumber.SetNumericValue(lastKP.Number); txtKpName.Text = lastKP.Name; cbKpDll.Text = lastKP.Dll; numKpAddress.SetNumericValue(lastKP.Address); txtCallNum.Text = lastKP.CallNum; numKpTimeout.SetNumericValue(lastKP.Timeout); numKpDelay.SetNumericValue(lastKP.Delay); timeKpTime.Value = new DateTime(timeKpTime.MinDate.Year, timeKpTime.MinDate.Month, timeKpTime.MinDate.Day, lastKP.Time.Hour, lastKP.Time.Minute, lastKP.Time.Second); timeKpPeriod.Value = new DateTime(timeKpPeriod.MinDate.Year, timeKpPeriod.MinDate.Month, timeKpPeriod.MinDate.Day, lastKP.Period.Hours, lastKP.Period.Minutes, lastKP.Period.Seconds); txtCmdLine.Text = lastKP.CmdLine; gbSelectedKP.Enabled = true; } } else { lastKP = null; lastKpItem = null; chkKpActive.Checked = false; chkKpBind.Checked = false; numKpNumber.Value = 0; txtKpName.Text = ""; cbKpDll.Text = ""; numKpAddress.Value = 0; txtCallNum.Text = ""; numKpTimeout.Value = 0; numKpDelay.Value = 0; timeKpTime.Value = timeKpTime.MinDate; timeKpPeriod.Value = timeKpPeriod.MinDate; txtCmdLine.Text = ""; gbSelectedKP.Enabled = false; } // установка доступности кнопок для действий с КП bool itemSelected = lastKpItem != null; btnMoveUpKP.Enabled = itemSelected && lastKpItem.Index > 0; btnMoveDownKP.Enabled = itemSelected && lastKpItem.Index < lvReqSequence.Items.Count - 1; btnDelKP.Enabled = itemSelected; btnCopyKP.Enabled = itemSelected; btnCutKP.Enabled = itemSelected; changing = false; }
private bool fullLoad2; // загружать 2-й журнал полностью /// <summary> /// Конструктор /// </summary> public FrmMain() { Application.EnableVisualStyles(); InitializeComponent(); // установка формата времени опроса КП timeKpTime.CustomFormat = Localization.Culture.DateTimeFormat.LongTimePattern; // установка имён столбцов списков для перевода формы colParamName.Name = "colParamName"; colParamValue.Name = "colParamValue"; colKpOrder.Name = "colKpOrder"; colKpActive.Name = "colKpActive"; colKpBind.Name = "colKpBind"; colKpNumber.Name = "colKpNumber"; colKpName.Name = "colKpName"; colKpDll.Name = "colKpDll"; colKpAddress.Name = "colKpAddress"; colCallNum.Name = "colCallNum"; colKpTimeout.Name = "colKpTimeout"; colKpDelay.Name = "colKpDelay"; colKpTime.Name = "colKpTime"; colKpPeriod.Name = "colKpPeriod"; colKpCmdLine.Name = "colKpCmdLine"; // инициализация полей appDirs = new AppDirs(); errLog = new Log(Log.Formats.Simple); errLog.Encoding = Encoding.UTF8; mutex = null; icoStart = Icon.FromHandle((ilMain.Images["star_on.ico"] as Bitmap).GetHicon()); icoStop = Icon.FromHandle((ilMain.Images["star_off.ico"] as Bitmap).GetHicon()); svcContr = null; prevSvcStatus = ServiceControllerStatus.Stopped; nodeCommonParams = treeView.Nodes["nodeCommonParams"]; nodeKpDlls = treeView.Nodes["nodeKpDlls"]; nodeLines = treeView.Nodes["nodeLines"]; nodeStats = treeView.Nodes["nodeStats"]; origSettings = new Settings(); modSettings = null; lastNode = null; lastLine = null; lastParam = null; lastParamItem = null; lastKP = null; lastKpItem = null; copiedKP = null; changing = false; serverComm = null; baseTablesReceived = false; tblCommLine = new DataTable(); tblKP = new DataTable(); tblKPType = new DataTable(); kpDllInfoList = new SortedList<string, KpDllInfo>(); commCnlParamsBuf = new Dictionary<string, SortedList<string, string>>(); lbLog1 = null; lbLog2 = null; logFileName1 = ""; logFileName2 = ""; logFileAge1 = DateTime.MinValue; logFileAge2 = DateTime.MinValue; fullLoad1 = false; fullLoad2 = false; Application.ThreadException += Application_ThreadException; }
private void miImportLines_Click(object sender, EventArgs e) { // приём таблиц базы конфигурации при необходимости string errMsg; if (!baseTablesReceived && !ReceiveBaseTables(out errMsg)) { errLog.WriteAction(errMsg); ScadaUtils.ShowError(errMsg); } if (baseTablesReceived) { FrmImport frmImport; if (FrmImport.Import(tblCommLine, tblKP, errLog, out frmImport) == DialogResult.OK) { // импорт линий связи и КП try { treeView.BeginUpdate(); TreeNode selNode = treeView.SelectedNode; if (selNode != null) { int lineIndex = selNode == nodeLines ? selNode.Nodes.Count : selNode.Index + 1; TreeNode newLineNode = selNode; foreach (TreeNode nodeLine in frmImport.TreeView.Nodes) { if (nodeLine.Checked) { // импорт линии связи DataRowView rowLine = (DataRowView)nodeLine.Tag; Settings.CommLine newLine = new Settings.CommLine(); newLine.Number = (int)rowLine["CommLineNum"]; newLine.Name = Convert.ToString(rowLine["Name"]); newLineNode = NewLineNode(newLine); nodeLines.Nodes.Insert(lineIndex, newLineNode); modSettings.CommLines.Insert(lineIndex, newLine); lineIndex++; // импорт КП int kpIndex = 0; foreach (TreeNode nodeKP in nodeLine.Nodes) { if (nodeKP.Checked) { DataRowView rowKP = (DataRowView)nodeKP.Tag; Settings.KP newKP = new Settings.KP(); newKP.Number = (int)rowKP["KPNum"]; DefineKPProps(newKP, rowKP, true); newLine.ReqSequence.Add(newKP); kpIndex++; } } } } treeView.SelectedNode = newLineNode; } } catch (Exception ex) { errMsg = AppPhrases.ImportLinesAndKpError + ":\r\n" + ex.Message; errLog.WriteAction(errMsg); ScadaUtils.ShowError(errMsg); } finally { SetModified(); treeView.EndUpdate(); } } } }
private void treeView_AfterSelect(object sender, TreeViewEventArgs e) { TreeNode node = e.Node; NodeTag nodeTag = node == null ? null : node.Tag as NodeTag; if (nodeTag != null && node != lastNode) { Text = AppPhrases.MainFormTitle + " - " + node.Text; lastNode = node; lastLine = nodeTag.Obj as Settings.CommLine; lastKP = nodeTag.Obj as Settings.KP; if (lastKP != null) lastLine = ((NodeTag)node.Parent.Tag).Obj as Settings.CommLine; // отображение ассоциированных с узлом дерева страниц tabControl.TabPages.Clear(); foreach (TabPage tabPage in nodeTag.TabPages) { tabControl.TabPages.Add(tabPage); if (tabPage == pageCommonParams) CommonParamsToPage(); else if (tabPage == pageLineParams) LineParamsToPage(); else if (tabPage == pageCustomParams) CustomParamsToPage(); else if (tabPage == pageReqSequence) ReqSequenceToPage(); else if (tabPage == pageLineLog) chkLineLogPause.Checked = false; else if (tabPage == pageKpCmd) txtCmdPwd.Text = ""; } // определение отображаемых на странице журналов tabControl_SelectedIndexChanged(null, null); if (!treeView.Focused) treeView.Focus(); } }