private void btnCalcTagRemove_Click(object sender, EventArgs e) { string strCalcTagName; cls_CalcTag tmp = new cls_CalcTag(); if (lvCalcTagList.SelectedItems.Count == 0) { MessageBox.Show("Please select the calculation tag first!", "Error"); return; } if (MessageBox.Show("Are you sure to delete the calculation tag?", "Confirm Message", MessageBoxButtons.OKCancel) != DialogResult.OK) { lvTagList.Focus(); return; } strCalcTagName = lvCalcTagList.SelectedItems[0].Text; if (!calc_taglist_data.TryRemove(strCalcTagName, out tmp)) { MessageBox.Show("Calculation Tag Remove failed", "Error"); return; } RefreshDeviceCalcTagList(); }
//Delegate function to check duplicated Tag/CalcTag ID from frmEditTag form bool CheckDuplicateTag(string tag_name, string type) { if (type == "TAG") { if (tag_list.Count > 0) { cls_Tag tag = tag_list.Where(p => p.TagName == tag_name).FirstOrDefault(); if (tag != null) { MessageBox.Show("Duplicate Tag Name!", "Error"); return(false); } } } else if (type == "CALC_TAG") { if (calc_tag_list.Count > 0) { cls_CalcTag calc_tag = calc_tag_list.Where(p => p.TagName == tag_name).FirstOrDefault(); if (calc_tag != null) { MessageBox.Show("Duplicate Calculation Tag Name!", "Error"); return(false); } } } else { MessageBox.Show("Wrong type string to check duplicated tag name!", "Error"); return(false); } return(true); }
//Delegate function to recieve calculation tag data from frmEditCalcTag form void SetCalcTagInformation(cls_CalcTag calc_tag, bool edit) { if (edit) { cls_CalcTag tmp = new cls_CalcTag(); if (calc_taglist_data.TryGetValue(calc_tag.TagName, out tmp)) { if (!calc_taglist_data.TryUpdate(calc_tag.TagName, calc_tag, tmp)) { MessageBox.Show("Calculation Tag Update failed!", "Error"); return; } } } else { if (!calc_taglist_data.TryAdd(calc_tag.TagName, calc_tag)) { MessageBox.Show("Calculation Tag Add failed!", "Error"); return; } } //RefreshDeviceCalcTagList(); }
//Constructor to Edit Calculation Tag public frmEditCalcTag(SetCalcTag set_calc_tag, ConcurrentDictionary <string, cls_Tag> tag_list, cls_CalcTag calc_tag) { InitializeComponent(); this.isEdit = true; this.calc_tag_data = calc_tag; this.delgSetCalcTag = set_calc_tag; this.tag_list_data = tag_list; }
//Delegate function to receive tag set data from frmEditTag form void SetCalcTagInformation(cls_CalcTag calc_tag, bool edit) { if (edit) { this.calc_tag_list[calc_tag_index] = calc_tag; return; } else { this.calc_tag_list.Add(calc_tag); return; } }
private void lvCalcTagList_DoubleClick(object sender, EventArgs e) { string strCalcTagName; ConcurrentDictionary <string, cls_Tag> dictTag = new ConcurrentDictionary <string, cls_Tag>(); cls_CalcTag calc_tag = new cls_CalcTag(); if (lvCalcTagList.SelectedItems.Count == 0) { MessageBox.Show("Please select the calculation tag first!", "Error"); return; } foreach (cls_Tag tag in this.tag_list) { dictTag.TryAdd(tag.TagName, tag); } strCalcTagName = lvCalcTagList.SelectedItems[0].Text; int i = 0; foreach (cls_CalcTag t in this.calc_tag_list) { if (t.TagName == strCalcTagName) { calc_tag = t; break; } i++; } this.calc_tag_index = i; frmEditCalcTag frm = new frmEditCalcTag(SetCalcTagInformation, dictTag, calc_tag); frm.Owner = this; frm.ShowDialog(); DisplayCalcTagList(); }
private void lvCalcTagList_DoubleClick(object sender, EventArgs e) { string strCalcTagName; cls_CalcTag calc_tag = new cls_CalcTag(); if (lvCalcTagList.SelectedItems.Count == 0) { MessageBox.Show("Please select the calculation tag first!", "Error"); return; } strCalcTagName = lvCalcTagList.SelectedItems[0].Text; if (!calc_taglist_data.TryGetValue(strCalcTagName, out calc_tag)) { MessageBox.Show("Get tag[" + strCalcTagName + "] information error", "Error"); return; } frmEditCalcTag frm = new frmEditCalcTag(SetCalcTagInformation, this.taglist_data, calc_tag); frm.Owner = this; frm.ShowDialog(); RefreshDeviceCalcTagList(); }
private void btnCalcTagSave_Click(object sender, EventArgs e) { cls_CalcTag tmpCalcTag = new cls_CalcTag(); frmCalcExpression frmCalc; Dictionary <string, string> tag_name_list = new Dictionary <string, string>(); if (txtCalcTagName.Text == "") { MessageBox.Show("Please enter Calculation Tag Name!", "Error"); return; } else { if (!this.isEdit) //Check duplicated id { if (!delgCheckDuplicateCalc(txtCalcTagName.Text.Trim(), "CALC_TAG")) { return; } } } tmpCalcTag.TagName = txtCalcTagName.Text.Trim(); tmpCalcTag.Description = txtDescription.Text.Trim(); if (pnlCalcExpression.Controls.Count > 0) { frmCalc = (frmCalcExpression)pnlCalcExpression.Controls[0]; if (frmCalc.GetExpression() == "") { MessageBox.Show("Calculation Expressiom must not be empty!", "Error"); return; } tmpCalcTag.Expression = frmCalc.GetExpression(); tag_name_list = frmCalc.GetTagNameList(); if (tag_name_list.Count > 0) { foreach (KeyValuePair <string, string> kvp in tag_name_list) { switch (kvp.Key) { case "A": tmpCalcTag.ParamA = kvp.Value; break; case "B": tmpCalcTag.ParamB = kvp.Value; break; case "C": tmpCalcTag.ParamC = kvp.Value; break; case "D": tmpCalcTag.ParamD = kvp.Value; break; case "E": tmpCalcTag.ParamE = kvp.Value; break; case "F": tmpCalcTag.ParamF = kvp.Value; break; case "G": tmpCalcTag.ParamG = kvp.Value; break; case "H": tmpCalcTag.ParamH = kvp.Value; break; default: break; } } } } tmpCalcTag.LastUpdateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); delgSetCalcTag(tmpCalcTag, this.isEdit); this.Close(); }
private void btnSaveEDCXml_Click(object sender, EventArgs e) { cls_EDC_Info tmpEDC = new cls_EDC_Info(); List <Tuple <string, string> > tmp_tag_info = new List <Tuple <string, string> >(); List <Tuple <string, string> > tmp_calc_tag_info = new List <Tuple <string, string> >(); if (txtSerial.Text.Trim() == "") { MessageBox.Show("Please input the serial id!", "Error"); return; } if (cmbGateway.Text.Trim() == "") { MessageBox.Show("Please select the gateway id!", "Error"); return; } if (cmbDevice.Text.Trim() == "") { MessageBox.Show("Please select the device id!", "Error"); return; } if (cmbReportType.Text.Trim() == "") { MessageBox.Show("Please select the report type!", "Error"); return; } if (cmbReportType.Text.Trim() == "interval") { if (txtReportInterval.Text.Trim() == "") { MessageBox.Show("Please input the report interval!", "Error"); return; } else { int value; if (!int.TryParse(txtReportInterval.Text.Trim(), out value)) { MessageBox.Show("Report Interval is number only!", "Error"); return; } tmpEDC.report_interval = int.Parse(txtReportInterval.Text.Trim()); if (chkAVG.Checked) { tmpEDC.interval_function.Add("AVG"); } if (chkMAX.Checked) { tmpEDC.interval_function.Add("MAX"); } if (chkMIN.Checked) { tmpEDC.interval_function.Add("MIN"); } if (tmpEDC.interval_function.Count == 0) { MessageBox.Show("Please checked at lease one interval function!", "Error"); return; } } } if (txtReportPath.Text.Trim() == "") { MessageBox.Show("Please input the report path!", "Error"); return; } if (!this.isEdit) { if (cmbEDCHeaderSet.Text.Trim() == "") { MessageBox.Show("Please select the EDC Header set first!", "Error"); return; } } tmpEDC.serial_id = txtSerial.Text.Trim(); tmpEDC.gateway_id = cmbGateway.Text.Trim(); tmpEDC.device_id = cmbDevice.Text.Trim(); tmpEDC.report_tpye = cmbReportType.Text.Trim(); tmpEDC.ReportEDCPath = txtReportPath.Text.Trim(); if (chkEnable.Checked) { tmpEDC.enable = true; } else { tmpEDC.enable = false; } if (this.isEdit) { tmpEDC.edchead_info = this.edc_data.edchead_info; } else { foreach (cls_EDC_Header h in this.edc_header_list.head_set_list) { if (h.set_name == cmbEDCHeaderSet.Text.Trim()) { tmpEDC.edchead_info = h.head_set; } } } foreach (ListViewItem item in lvTagList.Items) { cls_Tag t = this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()]; if (t != null) { if (item.Checked) { this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()].report_flag = "Y"; } else { this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()].report_flag = "N"; } } } foreach (KeyValuePair <string, cls_Tag> tag in this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info) { if (tag.Value.report_flag == "Y") { tmp_tag_info.Add(Tuple.Create(tag.Key, tag.Key)); } } foreach (ListViewItem item in lvCalcTagList.Items) { if (item.Checked) { cls_CalcTag ct = this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].calc_tag_info[item.Text.Trim()]; if (ct != null) { tmp_calc_tag_info.Add(Tuple.Create(ct.TagName, ct.TagName)); } } } tmpEDC.tag_info = tmp_tag_info; tmpEDC.calc_tag_info = tmp_calc_tag_info; if (!this.isEdit) { delgSetSerial(this.serial_index); } if (this.isCopy) { delgSetEDCXmlInfo(tmpEDC, false); } else { delgSetEDCXmlInfo(tmpEDC, this.isEdit); } if (!this.gateway_mgr.gateway_list[this.gateway_index].function_list.Contains("EDC")) { this.gateway_mgr.gateway_list[this.gateway_index].function_list.Add("EDC"); } this.Close(); }
private void btnSaveDBConfig_Click(object sender, EventArgs e) { cls_DB_Info tmpDB = new cls_DB_Info(); List <Tuple <string, string> > tmp_tag_info = new List <Tuple <string, string> >(); List <Tuple <string, string> > tmp_calc_tag_info = new List <Tuple <string, string> >(); if (cmbGateway.Text.Trim() == "") { MessageBox.Show("Please select the gateway id!", "Error"); return; } if (cmbDevice.Text.Trim() == "") { MessageBox.Show("Please select the device id!", "Error"); return; } if (!this.isEdit) { if (!delgCheckDuplicate(cmbGateway.Text.Trim(), cmbDevice.Text.Trim())) { MessageBox.Show("Gateway ID + Device ID should be an unique key!", "Error"); return; } } if (cmbDBType.Text.Trim() == "") { MessageBox.Show("Please select the DB type!", "Error"); return; } if (txtDataSource.Text.Trim() == "") { MessageBox.Show("Please input the data source!", "Error"); return; } if (txtPortID.Text.Trim() == "") { MessageBox.Show("Please input the port id!", "Error"); return; } if (txtConnectDB.Text.Trim() == "") { MessageBox.Show("Please input the database name!", "Error"); return; } if (txtDataSource.Text.Trim() == "") { MessageBox.Show("Please input the data source!", "Error"); return; } if (txtUserName.Text.Trim() == "") { MessageBox.Show("Please input the user name!", "Error"); return; } if (txtPassword.Text.Trim() == "") { MessageBox.Show("Please input the password!", "Error"); return; } tmpDB.serial_id = txtSerial.Text.Trim(); tmpDB.gateway_id = cmbGateway.Text.Trim(); tmpDB.device_id = cmbDevice.Text.Trim(); tmpDB.db_type = cmbDBType.Text.Trim(); tmpDB.data_source = txtDataSource.Text.Trim(); tmpDB.port_id = txtPortID.Text.Trim(); tmpDB.db_name = txtConnectDB.Text.Trim(); tmpDB.user_name = txtUserName.Text.Trim(); //tmpDB.password = EncryptionHelper.Encrypt(txtPassword.Text.Trim()); tmpDB.password = txtPassword.Text.Trim(); if (generate_connection_string(cmbDBType.Text.Trim()) == null) { MessageBox.Show("DB type not supported yet", "Error"); return; } else { tmpDB.connection_string = generate_connection_string(cmbDBType.Text.Trim()); } if (get_provider_name(cmbDBType.Text.Trim()) == null) { MessageBox.Show("DB type not supported yet", "Error"); return; } else { tmpDB.provider_name = get_provider_name(cmbDBType.Text.Trim()); } if (chkEnable.Checked) { tmpDB.enable = true; } else { tmpDB.enable = false; } foreach (ListViewItem item in lvTagList.Items) { cls_Tag t = this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()]; if (t != null) { if (item.Checked) { this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()].db_report_flag = "Y"; } else { this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info[item.Text.Trim()].db_report_flag = "N"; } } } foreach (KeyValuePair <string, cls_Tag> tag in this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].tag_info) { if (tag.Value.db_report_flag == "Y") { tmp_tag_info.Add(Tuple.Create(tag.Key, tag.Key)); } } foreach (ListViewItem item in lvCalcTagList.Items) { if (item.Checked) { cls_CalcTag ct = this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].calc_tag_info[item.Text.Trim()]; if (ct != null) { tmp_calc_tag_info.Add(Tuple.Create(ct.TagName, ct.TagName)); } } } /* * foreach (KeyValuePair<string, cls_CalcTag> calc_tag in this.gateway_mgr.gateway_list[gateway_index].device_info[device_index].calc_tag_info) * { * tmp_calc_tag_info.Add(Tuple.Create(calc_tag.Key, calc_tag.Key)); * } */ tmpDB.tag_info = tmp_tag_info; tmpDB.calc_tag_info = tmp_calc_tag_info; if (!this.isEdit) { delgSetDBSerial(this.serial_index); } if (this.isCopy) { delgSetDBInfo(tmpDB, false); } else { delgSetDBInfo(tmpDB, this.isEdit); } if (!this.gateway_mgr.gateway_list[this.gateway_index].function_list.Contains("DB")) { this.gateway_mgr.gateway_list[this.gateway_index].function_list.Add("DB"); } this.Close(); }
public frmCalcExpression(cls_CalcTag calc_tag) { InitializeComponent(); this.calc_tag_data = calc_tag; this.isEdit = true; }