private void btnLoginSave_Click(object sender, EventArgs e) { bool isUserValid = false; int user_id = 0; string userName = ToolBoxWrite.TextBoxRead(tbLoginUserName); string userPassword = ToolBoxWrite.TextBoxRead(tbLoginPassword); if (serverProtocol.AuthenticateUser(userName, userPassword)) { isUserValid = true; } else { LoginAttemptsCount++; ToolBoxWrite.TextBoxWrite(tbLoginUserName, string.Empty); ToolBoxWrite.TextBoxWrite(tbLoginPassword, string.Empty); if (LoginAttemptsCount == GlobalVar.MATS_SERVER_LOGIN_ATTEMPTS) { MessageBox.Show("Invalid Login Attempts For " + GlobalVar.MATS_SERVER_LOGIN_ATTEMPTS.ToString() + "Times. Please Restart The Program."); this.Close(); } else { MessageBox.Show("Login Details are Incorrect.", "!Warning"); } return; } if (isUserValid) { this.Visible = false; GlobalVar.USER_NAME = tbLoginUserName.Text; ToolBox.ToolBoxWrite.IS_FORM_LOADED = false; FrmMechBench frm = new FrmMechBench(serverProtocol); DialogResult dr = frm.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Abort) { this.Close(); } else if (GlobalVar.isUserLogOut) { LoginAttemptsCount = 0; GlobalVar.isUserLogOut = false; this.Visible = true; ToolBoxWrite.TextBoxWrite(tbLoginUserName, string.Empty); ToolBoxWrite.TextBoxWrite(tbLoginPassword, string.Empty); } else { this.Close(); } } }
public bool SendReport(string data, bool isManual, bool result) { Console.WriteLine("Report Data: " + data); string[] receivedData = data.Split(' '); string benchName = receivedData[0]; string msgType = receivedData[1]; string channelName = receivedData[2]; string measuredVal = receivedData[3]; if (GlobalVar.SELECTED_STRUCT_TEST.ChannelName.Contains(channelName)) { //if (!Utility.ValidateNumber(measuredVal, true, true)) //{ // string errorMsg = "Loose Connection(Data Corrupt). Please Try Again"; // ToolBoxWrite.LabelWrite(mainForm.lblServerResponse, errorMsg, Color.Red); // return false; //} //else { string unit = receivedData[4]; if (unit == "\n") { unit = string.Empty; } GlobalVar.STRUCT_REPORT = new STRUCT_REPORT(); GlobalVar.STRUCT_REPORT.ChannelName = channelName; GlobalVar.STRUCT_REPORT.ComponentNum = GlobalVar.COMPONENT_NUMBER; GlobalVar.STRUCT_REPORT.MeasuredVal = measuredVal.Replace("$#", " "); GlobalVar.STRUCT_REPORT.TestId = GlobalVar.SELECTED_STRUCT_TEST.TestId; GlobalVar.STRUCT_REPORT.TestResult = result;//TestCheck(GlobalVar.STRUCT_REPORT.MeasuredVal); GlobalVar.STRUCT_REPORT.UnitName = unit; GlobalVar.STRUCT_REPORT.IsManualEntry = isManual; List <string> ChannelNameList = new List <string>(); ChannelNameList.Add(GlobalVar.STRUCT_REPORT.ChannelName); List <string> UnitNameList = new List <string>(); UnitNameList.Add(GlobalVar.STRUCT_REPORT.UnitName); List <string> MeasuredValueList = new List <string>(); MeasuredValueList.Add(GlobalVar.STRUCT_REPORT.MeasuredVal); serverProtocol.SendReport(ChannelNameList, MeasuredValueList, UnitNameList, GlobalVar.STRUCT_REPORT); mainForm.UpdateReportDetails(GlobalVar.STRUCT_REPORT); bool retVal = GlobalVar.STRUCT_REPORT.TestResult; string sendData = string.Empty; //if (retVal) //{ // sendData = "pwm 1 50 30 1" + transmitTerminator; // serial.Write(sendData); // Thread.Sleep(200); // sendData = "pwm 16 50 20 1" + transmitTerminator; // serial.Write(sendData); //} //else //{ // sendData = "pwm 2 50 30 3" + transmitTerminator; // serial.Write(sendData); // Thread.Sleep(200); // sendData = "pwm 16 50 20 3" + transmitTerminator; // serial.Write(sendData); //} } } else { string errorMsg = "The used instrument/channel is incorrect." + " Channel:" + channelName; ToolBoxWrite.LabelWrite(mainForm.lblServerResponse, errorMsg, Color.Red); return(false); } return(true); }
public bool GetBenchDetails() { serial.AsyncRead(BenchReceivedData, false); serial.Write(configEnd + transmitTerminator); string data = serial.ReadLine(4); serial.Write(configStart + transmitTerminator); data = serial.ReadLine(4); if (data == null || !data.Contains("Started")) { return(false); } serial.Write(configIdentify + transmitTerminator); //while (!data.Contains("prod.ch2:")) { data = serial.ReadLine(4); if (data == null) { serial.Write(configEnd + transmitTerminator); return(false); } data = data.Replace("\n", string.Empty); Console.WriteLine("Received Client Data: " + data); string[] instrumentMsg = data.Split(';'); for (int i = 0; i < instrumentMsg.Length; i++) { if (instrumentMsg[i].Length > 2) { string[] instrumentMsgfields = instrumentMsg[i].Split(' '); switch (instrumentMsgfields[0]) { case "prod.name:": ToolBoxWrite.TextBoxWrite(mainForm.tbBenchName, instrumentMsgfields[1]); // frm.tbBenchName.Text = instrumentMsgfields[1]; bench.setBenchName(instrumentMsgfields[1]); break; case "prod.swver:": break; case "prod.hwver:": break; case "prod.type:": bench.setType(instrumentMsgfields[1]); break; case "prod.class:": bench.setClass(instrumentMsgfields[1]); break; case "prod.num:": instrumentMsgfields[1] = instrumentMsgfields[1].Replace("\0\n", ""); bench.setNum(instrumentMsgfields[1]); break; case "prod.interface:": bench.setInterface(instrumentMsgfields[1]); break; case "prod.channelcount:": bench.setChCount(instrumentMsgfields[1]); break; case "prod.ch1:": ToolBoxWrite.ComboBoxWrite(mainForm.cbChannel1, instrumentMsgfields[1]); bench.setChan1(instrumentMsgfields[1]); break; case "prod.ch2:": ToolBoxWrite.ComboBoxWrite(mainForm.cbChannel2, instrumentMsgfields[1]); bench.setChan2(instrumentMsgfields[1]); break; case "prod.ch3:": ToolBoxWrite.ComboBoxWrite(mainForm.cbChannel3, instrumentMsgfields[1]); bench.setChan3(instrumentMsgfields[1]); break; //case "prod.ch4:": // ToolBoxWrite.ComboBoxWrite(mainForm.cbChannel4, instrumentMsgfields[1]); // bench.setChan4(instrumentMsgfields[1]); // break; } // switch (instrumentMsgfields[0]) if(sentCommand[0] == "identify\r") } } } serial.Write(configEnd + transmitTerminator); data = serial.ReadLine(4); if (!data.Contains("Ended")) { return(false); } return(true); }