private void btnSOCKET_Click(object sender, EventArgs e) { DialogResult result1 = MessageBox.Show("Save change ?", "Important Question", MessageBoxButtons.YesNo); if (result1 == DialogResult.Yes) { station existedStationsSetting = new station_repository().get_info(); if (existedStationsSetting == null) { } else { if (isOpen(existedStationsSetting.socket_port)) { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.OFF_switch_96x25; //close socket try { if (Application.OpenForms.OfType <Form1>().Count() == 1) { Application.OpenForms.OfType <Form1>().First().Close(); btnShow.Enabled = false; } } catch (Exception ex) { MessageBox.Show("Error ! Cant close this socket.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.ON_switch_96x25; //open socket Int32 port = existedStationsSetting.socket_port; IPAddress localAddr = IPAddress.Parse(frmConfiguration.GetLocalIPAddress()); try { //frmNewMain.tcpListener = new TcpListener(localAddr, port); //frmNewMain.tcpListener.Start(); if (Application.OpenForms.OfType <Form1>().Count() == 1) { Application.OpenForms.OfType <Form1>().First().Close(); } protocol = new Form1(newMain); //protocol = new Form1(this.SAMPPort); protocol.Show(); btnShow.Enabled = true; } catch (Exception ex) { MessageBox.Show("Error ! Cant open this socket.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
private void btnSave_Click(object sender, EventArgs e) { module_repository modules = new module_repository(); IEnumerable <module> moduleConfigList = modules.get_all(); MODULE_CONFIG_LIST = moduleConfigList.Select(x => x.item_name).ToArray(); // saving to db station objStationSetting = new station_repository().get_info(); if (isOpen(objStationSetting.socket_port) && (!txtSocketPort.Text.Equals(objStationSetting.socket_port.ToString()))) { //this.btnSOCKET.Image = global::DataLogger.Properties.Resources.OFF_switch_96x25; //close socket try { //frmNewMain.tcpListener.Stop(); if (Application.OpenForms.OfType <Form1>().Count() == 1) { Application.OpenForms.OfType <Form1>().First().Close(); btnShow.Enabled = false; } } catch (Exception ex) { MessageBox.Show("Error ! Cant close this socket.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } try { objStationSetting.station_name = txtStationName.Text; objStationSetting.station_id = txtStationID.Text; objStationSetting.socket_port = Convert.ToInt32(txtSocketPort.Text.Trim()); //MessageBox.Show("1"); objStationSetting.module_comport = cbModule.Text; //MessageBox.Show("2"); } catch (Exception ex) { MessageBox.Show("Cant SAVE !"); this.Close(); return; } try { //MessageBox.Show("3"); if (new station_repository().update(ref objStationSetting) > 0) { // ok } else { // fail } foreach (string itemModule in MODULE_CONFIG_LIST) { module obj = _modules.get_info_by_name(itemModule); if (obj.type_value == 1) { string currentvar = obj.item_name; //TextBox value = null; string currentmodule = currentvar + "Module"; string currentmoduleText = null; GetTextBoxStrings(this, currentmodule, ref currentmoduleText); string currentchannel = currentvar + "Channel"; string currentchannelText = null; GetTextBoxStrings(this, currentchannel, ref currentchannelText); string currentinputmin = currentvar + "InputMin"; string currentinputminText = null; GetTextBoxStrings(this, currentinputmin, ref currentinputminText); string currentinputmax = currentvar + "InputMax"; string currentinputmaxText = null; GetTextBoxStrings(this, currentinputmax, ref currentinputmaxText); string currentoutputmin = currentvar + "OutputMin"; string currentoutputminText = null; GetTextBoxStrings(this, currentoutputmin, ref currentoutputminText); string currentoutputmax = currentvar + "OutputMax"; string currentoutputmaxText = null; GetTextBoxStrings(this, currentoutputmax, ref currentoutputmaxText); string currentoffset = currentvar + "Offset"; string currentoffsetText = null; GetTextBoxStrings(this, currentoffset, ref currentoffsetText); string currentunit = currentvar + "Unit"; string currentunitText = null; GetTextBoxStrings(this, currentunit, ref currentunitText); string currentvaluecolumn = currentvar + "ValueColumn"; string currentvaluecolumnText = null; GetTextBoxStrings(this, currentvaluecolumn, ref currentvaluecolumnText); string currentstatuscolumn = currentvar + "StatusColumn"; string currentstatuscolumnText = null; GetTextBoxStrings(this, currentstatuscolumn, ref currentstatuscolumnText); string currenttype = currentvar + "Type"; string currenttypeText = null; GetTextBoxStrings(this, currenttype, ref currenttypeText); string currentdisplayname = currentvar + "DisplayName"; string currentdisplaynameText = null; GetTextBoxStrings(this, currentdisplayname, ref currentdisplaynameText); obj.module_id = Convert.ToInt32(currentmoduleText); obj.channel_number = Convert.ToInt32(currentchannelText); obj.input_min = Convert.ToInt32(currentinputminText); obj.input_max = Convert.ToInt32(currentinputmaxText); obj.output_min = Convert.ToInt32(currentoutputminText); obj.output_max = Convert.ToInt32(currentoutputmaxText); obj.off_set = Convert.ToDouble(currentoffsetText); obj.unit = currentunitText; obj.value_column = currentvaluecolumnText; obj.status_column = currentstatuscolumnText; obj.type_value = Convert.ToInt32(currenttypeText); obj.display_name = currentdisplaynameText; if (_modules.update(ref obj) > 0) { // ok } else { // fail } } else if (obj.type_value == 2) { } } MessageBox.Show("Success", "", MessageBoxButtons.OK, MessageBoxIcon.None); } catch (Exception ex) { MessageBox.Show("Error", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void refreshDataForControl() { // get all comport name from computer. string[] availableComportList; availableComportList = SerialPort.GetPortNames(); if (availableComportList.Length <= 0) { //MessageBox.Show(lang.getText("available_port_null")); //this.Close(); //return; } // check station info setting station existedStationsSetting = new station_repository().get_info(); if (existedStationsSetting == null) { existedStationsSetting = new station(); if (new station_repository().add(ref existedStationsSetting) > 0) { // insert ok to database } else { MessageBox.Show(lang.getText("system_error")); return; } } else { // set data to control from existed station setting txtStationName.Text = existedStationsSetting.station_name; txtStationID.Text = existedStationsSetting.station_id; txtSocketPort.Text = existedStationsSetting.socket_port.ToString(); if (isOpen(existedStationsSetting.socket_port)) { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.ON_switch_96x25; } else { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.OFF_switch_96x25; } var sortComportList = availableComportList.OrderBy(port => Convert.ToInt32(port.Replace("COM", string.Empty))); cbModulePH.Items.Clear(); cbModuleOrp.Items.Clear(); cbModuleTemp.Items.Clear(); cbModuleDO.Items.Clear(); cbModuleTurb.Items.Clear(); cbModuleCond.Items.Clear(); } foreach (string itemModuleID in MODULE_ID_LIST) { cbModulePH.Items.Add(itemModuleID); cbModuleOrp.Items.Add(itemModuleID); cbModuleTemp.Items.Add(itemModuleID); cbModuleDO.Items.Add(itemModuleID); cbModuleTurb.Items.Add(itemModuleID); cbModuleCond.Items.Add(itemModuleID); } IEnumerable <module> moduleConfigurationList = checkAndInsertModuleConfiguration(); foreach (module itemModuleSetting in moduleConfigurationList) { displayModuleSetting(itemModuleSetting); } }
private void refreshDataForControl() { // get all comport name from computer. string[] availableComportList; availableComportList = SerialPort.GetPortNames(); module_repository modules = new module_repository(); IEnumerable <module> moduleConfigList = modules.get_all(); MODULE_CONFIG_LIST = moduleConfigList.Select(x => x.item_name).ToArray(); if (availableComportList.Length <= 0) { MessageBox.Show(lang.getText("available_port_null")); //this.Close(); //return; } // check station info setting station existedStationsSetting = new station_repository().get_info(); if (existedStationsSetting == null) { existedStationsSetting = new station(); if (new station_repository().add(ref existedStationsSetting) > 0) { // insert ok to database } else { MessageBox.Show(lang.getText("system_error")); return; } } else { // set data to control from existed station setting txtStationName.Text = existedStationsSetting.station_name; txtStationID.Text = existedStationsSetting.station_id; txtSocketPort.Text = existedStationsSetting.socket_port.ToString(); if (isOpen(existedStationsSetting.socket_port)) { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.ON_switch_96x25; btnShow.Enabled = true; } else { this.btnSOCKET.Image = global::DataLogger.Properties.Resources.OFF_switch_96x25; btnShow.Enabled = false; } var sortComportList = availableComportList.OrderBy(port => Convert.ToInt32(port.Replace("COM", string.Empty))); int selectedIndex = 0; cbModule.Items.Clear(); var1Module.Items.Clear(); var2Module.Items.Clear(); var3Module.Items.Clear(); var4Module.Items.Clear(); var5Module.Items.Clear(); var6Module.Items.Clear(); foreach (string itemAvailableComportName in sortComportList) { cbModule.Items.Add(itemAvailableComportName); if (existedStationsSetting.module_comport == itemAvailableComportName) { cbModule.SelectedIndex = selectedIndex; } selectedIndex = selectedIndex + 1; } } foreach (string itemModuleID in MODULE_ID_LIST) { var1Module.Items.Add(itemModuleID); var2Module.Items.Add(itemModuleID); var3Module.Items.Add(itemModuleID); var4Module.Items.Add(itemModuleID); var5Module.Items.Add(itemModuleID); var6Module.Items.Add(itemModuleID); var7Module.Items.Add(itemModuleID); var8Module.Items.Add(itemModuleID); var9Module.Items.Add(itemModuleID); var10Module.Items.Add(itemModuleID); var11Module.Items.Add(itemModuleID); var12Module.Items.Add(itemModuleID); var13Module.Items.Add(itemModuleID); var14Module.Items.Add(itemModuleID); var15Module.Items.Add(itemModuleID); var16Module.Items.Add(itemModuleID); var17Module.Items.Add(itemModuleID); var18Module.Items.Add(itemModuleID); } IEnumerable <module> moduleConfigurationList = checkAndInsertModuleConfiguration(); foreach (module itemModuleSetting in moduleConfigurationList) { displayModuleSetting(itemModuleSetting); } }
private void btnSave_Click(object sender, EventArgs e) { // saving to db station objStationSetting = new station_repository().get_info(); if (isOpen(objStationSetting.socket_port) && (!txtSocketPort.Text.Equals(objStationSetting.socket_port.ToString()))) { //close socket try { frmNewMain.tcpListener.Stop(); } catch (Exception ex) { MessageBox.Show("Error ! Cant close this socket.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } try { objStationSetting.station_name = txtStationName.Text; objStationSetting.station_id = txtStationID.Text; objStationSetting.socket_port = Convert.ToInt32(txtSocketPort.Text.Trim()); } catch (Exception ex) { MessageBox.Show("Cant SAVE !"); this.Close(); return; } try { if (new station_repository().update(ref objStationSetting) > 0) { // ok } else { // fail } foreach (string itemModule in MODULE_CONFIG_LIST) { switch (itemModule.ToLower()) { //PH ORP TEMP DO TURB COND case "var1": module objpH = _modules.get_info_by_name(itemModule); objpH.display_name = txtName1.Text; objpH.unit = txtUnit1.Text; objpH.module_id = cbModulePH.SelectedIndex + 1; objpH.channel_number = Convert.ToInt32(txtpHChannel.Text); objpH.input_min = Convert.ToInt32(txtpHInputMin.Text); objpH.input_max = Convert.ToInt32(txtpHInputMax.Text); objpH.output_min = Convert.ToInt32(txtpHOutputMin.Text); objpH.output_max = Convert.ToInt32(txtpHOutputMax.Text); objpH.off_set = Convert.ToInt32(txtpHOffset.Text); objpH.sensorId = txtpHSensorId.Text; if (_modules.update(ref objpH) > 0) { // ok } else { // fail } break; case "var2": module objOrp = _modules.get_info_by_name(itemModule); objOrp.display_name = txtName2.Text; objOrp.unit = txtUnit2.Text; objOrp.module_id = cbModuleOrp.SelectedIndex + 1; objOrp.channel_number = Convert.ToInt32(txtOrpChannel.Text); objOrp.input_min = Convert.ToInt32(txtOrpInputMin.Text); objOrp.input_max = Convert.ToInt32(txtOrpInputMax.Text); objOrp.output_min = Convert.ToInt32(txtOrpOutputMin.Text); objOrp.output_max = Convert.ToInt32(txtOrpOutputMax.Text); objOrp.off_set = Convert.ToInt32(txtOrpOffset.Text); objOrp.sensorId = txtOrpSensorId.Text; if (_modules.update(ref objOrp) > 0) { // ok } else { // fail } break; case "var3": module objTemp = _modules.get_info_by_name(itemModule); objTemp.display_name = txtName3.Text; objTemp.module_id = cbModuleTemp.SelectedIndex + 1; objTemp.unit = txtUnit3.Text; objTemp.channel_number = Convert.ToInt32(txtTempChannel.Text); objTemp.input_min = Convert.ToInt32(txtTempInputMin.Text); objTemp.input_max = Convert.ToInt32(txtTempInputMax.Text); objTemp.output_min = Convert.ToInt32(txtTempOutputMin.Text); objTemp.output_max = Convert.ToInt32(txtTempOutputMax.Text); objTemp.off_set = Convert.ToInt32(txtTempOffset.Text); objTemp.sensorId = txtTempSensorId.Text; if (_modules.update(ref objTemp) > 0) { // ok } else { // fail } break; case "var4": module objDO = _modules.get_info_by_name(itemModule); objDO.display_name = txtName4.Text; objDO.unit = txtUnit4.Text; objDO.module_id = cbModuleDO.SelectedIndex + 1; objDO.channel_number = Convert.ToInt32(txtDOChannel.Text); objDO.input_min = Convert.ToInt32(txtDOInputMin.Text); objDO.input_max = Convert.ToInt32(txtDOInputMax.Text); objDO.output_min = Convert.ToInt32(txtDOOutputMin.Text); objDO.output_max = Convert.ToInt32(txtDOOutputMax.Text); objDO.off_set = Convert.ToInt32(txtDOOffset.Text); objDO.sensorId = txtDOSensorId.Text; if (_modules.update(ref objDO) > 0) { // ok } else { // fail } break; case "var5": module objTurb = _modules.get_info_by_name(itemModule); objTurb.display_name = txtName5.Text; objTurb.unit = txtUnit5.Text; objTurb.module_id = cbModuleTurb.SelectedIndex + 1; objTurb.channel_number = Convert.ToInt32(txtTurbChannel.Text); objTurb.input_min = Convert.ToInt32(txtTurbInputMin.Text); objTurb.input_max = Convert.ToInt32(txtTurbInputMax.Text); objTurb.output_min = Convert.ToInt32(txtTurbOutputMin.Text); objTurb.output_max = Convert.ToInt32(txtTurbOutputMax.Text); objTurb.off_set = Convert.ToInt32(txtTurbOffset.Text); objTurb.sensorId = txtTurbSensorId.Text; if (_modules.update(ref objTurb) > 0) { // ok } else { // fail } break; case "var6": module objCond = _modules.get_info_by_name(itemModule); objCond.display_name = txtName6.Text; objCond.unit = txtUnit6.Text; objCond.module_id = cbModuleCond.SelectedIndex + 1; objCond.channel_number = Convert.ToInt32(txtCondChannel.Text); objCond.input_min = Convert.ToInt32(txtCondInputMin.Text); objCond.input_max = Convert.ToInt32(txtCondInputMax.Text); objCond.output_min = Convert.ToInt32(txtCondOutputMin.Text); objCond.output_max = Convert.ToInt32(txtCondOutputMax.Text); objCond.off_set = Convert.ToInt32(txtCondOffset.Text); objCond.sensorId = txtCondSensorId.Text; if (_modules.update(ref objCond) > 0) { // ok } else { // fail } break; default: break; } } MessageBox.Show("Success", "", MessageBoxButtons.OK, MessageBoxIcon.None); } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }