private void timer_Main_Tick(object sender, EventArgs e) { String str_actualTrayIconText = this.TrayIcon.Text; this.TrayIcon.Text = "Working. Be patient."; foreach (FileInfo actFI in this.SearchDirectory.GetFiles()) { if (actFI.Extension.ToLower() != ".txt") { continue; } StreamReader sr = new StreamReader(actFI.OpenRead()); SpeaReport[] SpeaFileReports = { }; while (!sr.EndOfStream) { String[] ar_LineElements = sr.ReadLine().Split(';'); if (ar_LineElements[0] != "START") { continue; } SpeaReport actSpeaReport = new SpeaReport(); if (sr.EndOfStream) { continue; } /* * String[] ar_NextLE = sr.ReadLine().Split(';'); * if (ar_NextLE[0] != "SN") * { * * } */ actSpeaReport.ReportHeader.ProductID = ar_LineElements[1]; actSpeaReport.ReportHeader.OperatorID = ar_LineElements[5]; DateTime startTime; try { startTime = new DateTime( Convert.ToInt32(ar_LineElements[6].Substring(6, 4)), Convert.ToInt32(ar_LineElements[6].Substring(0, 2)), Convert.ToInt32(ar_LineElements[6].Substring(3, 2)), Convert.ToInt32(ar_LineElements[7].Substring(0, 2)), Convert.ToInt32(ar_LineElements[7].Substring(3, 2)), Convert.ToInt32(ar_LineElements[7].Substring(6, 2))); } catch { startTime = new DateTime( Convert.ToInt32(ar_LineElements[6].Substring(6, 4)), Convert.ToInt32(ar_LineElements[6].Substring(3, 2)), Convert.ToInt32(ar_LineElements[6].Substring(0, 2)), Convert.ToInt32(ar_LineElements[7].Substring(0, 2)), Convert.ToInt32(ar_LineElements[7].Substring(3, 2)), Convert.ToInt32(ar_LineElements[7].Substring(6, 2))); } if (startTime < new DateTime(2017, 4, 6, 4, 0, 0)) { continue; // only new reports are allowed to process } actSpeaReport.ReportHeader.StartTime = startTime.ToString(); ar_LineElements = sr.ReadLine().Split(';'); if (ar_LineElements[0] == "SN") { actSpeaReport.ReportHeader.SerialNumber = ar_LineElements[1]; ar_LineElements = sr.ReadLine().Split(';'); } else { actSpeaReport.ReportHeader.SerialNumber = "0000000000000"; } if (actSpeaReport.ReportHeader.SerialNumber.Length != 13) { continue; } if (DoubleResultCheck.IsWritten(actSpeaReport.ReportHeader.SerialNumber, startTime)) { actSpeaReport.Dispose(); continue; } while (!(ar_LineElements[0] == "BOARDRESULT")) { TestRunSpea actTRS = ParserFunctions.FormatLine(ar_LineElements); Array.Resize(ref actSpeaReport.ReportBody.TestRuns, actSpeaReport.ReportBody.TestRuns.Length + 1); actSpeaReport.ReportBody.TestRuns.SetValue(actTRS, actSpeaReport.ReportBody.TestRuns.Length - 1); ar_LineElements = sr.ReadLine().Split(';'); } actSpeaReport.ReportHeader.Grade = ar_LineElements[1]; ar_LineElements = sr.ReadLine().Split(';'); DateTime endTime = new DateTime( Convert.ToInt32(ar_LineElements[2].Substring(6, 4)), Convert.ToInt32(ar_LineElements[2].Substring(0, 2)), Convert.ToInt32(ar_LineElements[2].Substring(3, 2)), Convert.ToInt32(ar_LineElements[3].Substring(0, 2)), Convert.ToInt32(ar_LineElements[3].Substring(3, 2)), Convert.ToInt32(ar_LineElements[3].Substring(6, 2))); actSpeaReport.ReportHeader.EndTime = endTime.ToString(); Array.Resize(ref SpeaFileReports, SpeaFileReports.Length + 1); SpeaFileReports.SetValue(actSpeaReport, SpeaFileReports.Length - 1); } SpeaReport[] SpeaReportsToProcess = { }; if (SpeaFileReports.Length == 0) { continue; } for (Int32 i = 0; i < SpeaFileReports.Length; i++) { if ((SpeaFileReports[i].ReportHeader.SerialNumber == "0000000000000") && (SpeaReportsToProcess.Length == 0)) { continue; } if ((SpeaFileReports[i].ReportHeader.Grade == "PASS") && (SpeaFileReports[i].ReportHeader.SerialNumber != "0000000000000")) { Array.Resize(ref SpeaReportsToProcess, SpeaReportsToProcess.Length + 1); SpeaReportsToProcess.SetValue(SpeaFileReports[i], SpeaReportsToProcess.Length - 1); continue; } if (i < SpeaFileReports.Length - 1) { if (SpeaFileReports[i + 1].ReportHeader.SerialNumber == "0000000000000") { if (SpeaFileReports[i + 1].ReportHeader.Grade == "PASS") { SpeaFileReports[i].ReportHeader.Grade = "PASS"; } for (Int32 j = 0; j < SpeaFileReports[i].ReportBody.TestRuns.Length; j++) { if (SpeaFileReports[i].ReportBody.TestRuns[j].TestGrade == "FAIL") { for (Int32 k = 0; k < SpeaFileReports[i + 1].ReportBody.TestRuns.Length; k++) { if (SpeaFileReports[i].ReportBody.TestRuns[j].TestName == SpeaFileReports[i + 1].ReportBody.TestRuns[k].TestName) { SpeaFileReports[i].ReportBody.TestRuns[j] = SpeaFileReports[i + 1].ReportBody.TestRuns[k]; k = SpeaFileReports[i + 1].ReportBody.TestRuns.Length; } } } } } Array.Resize(ref SpeaReportsToProcess, SpeaReportsToProcess.Length + 1); SpeaReportsToProcess.SetValue(SpeaFileReports[i], SpeaReportsToProcess.Length - 1); continue; } } foreach (SpeaReport actSRTP in SpeaReportsToProcess) { UnitReport UR = new UnitReport(); UR.starttime = Convert.ToDateTime(actSRTP.ReportHeader.StartTime); UR.endtime = Convert.ToDateTime(actSRTP.ReportHeader.EndTime); UR.Operator = new _Operator(ConfigFile.GetOperatorPersonalNumber(actSRTP.ReportHeader.OperatorID)); UR.Cathegory.Product.SerialNo = actSRTP.ReportHeader.SerialNumber; UR.Cathegory.Product.PartNo = actSRTP.ReportHeader.ProductID; UR.AddProperty("Work Order", UR.Cathegory.Product.SerialNo.Substring(0, 8)); UR.TestRun.name = "ICT"; foreach (TestRunSpea actTRS in actSRTP.ReportBody.TestRuns) { UR.TestRun.AddTestRunChild(actTRS.TestName, Convert.ToDateTime(actSRTP.ReportHeader.StartTime), Convert.ToDateTime(actSRTP.ReportHeader.EndTime), actTRS.TestGrade, actTRS.MeasUnit, actTRS.MeasValue, actTRS.LowLimit, actTRS.HighLimit); } UR.Cathegory.name = "Default"; UR.mode = "P"; UR.TestNumberPrefix = false; Array actReport = UR.GetXMLReport(); String str_actReport = ""; foreach (String actLine in actReport) { str_actReport = String.Concat(str_actReport, actLine); } DoubleResultCheck.WriteResult(UR.Cathegory.Product.SerialNo, UR.starttime); if (!this.BelMesObj.EmployeeVerification(UR.Operator.ToString())) { ErrorHandling.Create("Neznamy operator.", false, false); } else { if (this.BelMesObj.BelMESAuthorization(UR.Cathegory.Product.SerialNo, "ICT", UR.Cathegory.Product.PartNo, "")) { Thread.Sleep(500); if (this.BelMesObj.SetActualResult(UR.Cathegory.Product.SerialNo, "ICT", UR.TestRun.grade, str_actReport)) { //DoubleResultCheck.WriteResult(UR.Cathegory.Product.SerialNo, UR.starttime); } } } } this.TrayIcon.Text = str_actualTrayIconText; } }
private Boolean GenerateReport(String SerialNumber, DateTime StartTime) { try { DateTime starttime = StartTime; DateTime endtime = StartTime.AddSeconds(5); UnitReport myReport = new UnitReport(starttime, endtime, "D", "", false); myReport.Operator.name = this.str_OperatorNr; myReport.Cathegory = new _Cathegory("Default"); myReport.Cathegory.Product = new _Product("", SerialNumber); //mozno pridam stlpec s PartNumberom, ktory vrati autorizacia belmesu myReport.TestRun.name = this.cb_TestTypes.Text; myReport.starttime = starttime; myReport.endtime = endtime; myReport.AddProperty("Work Order", SerialNumber.Substring(0, 8)); String URMode = myStationConfig.GetMode(); if (URMode == "") { URMode = "D"; } else { myReport.mode = URMode; } XmlNode assembliesNode = ProductsConfig.XmlFile.LastChild.SelectSingleNode("./Assemblies"); foreach (XmlNode actAssNode in assembliesNode.ChildNodes) { if (actAssNode.SelectSingleNode("./Name").InnerText == myReport.Cathegory.Product.PartNo) { XmlNode propertiesNode = actAssNode.SelectSingleNode("./Properties"); if (propertiesNode != null) { foreach (XmlNode actPropNode in propertiesNode) { myReport.AddProperty(actPropNode.Name, actPropNode.InnerText); } } } } XmlNode familyProperties = ProductsConfig.XmlFile.LastChild.SelectSingleNode("./Families"); foreach (XmlNode actFamilyNode in familyProperties.ChildNodes) { if (actFamilyNode.SelectSingleNode("./Name").InnerText == myReport.Cathegory.Product.PartNo) { XmlNode propertiesNode = actFamilyNode.SelectSingleNode("./Properties"); if (propertiesNode != null) { foreach (XmlNode actPropNode in propertiesNode) { myReport.AddProperty(actPropNode.Name, actPropNode.InnerText); } } } } Array commonProperties = myStationConfig.GetProperties(); for (int i = 0; i < commonProperties.GetLength(0); i++) { String actNameNode = commonProperties.GetValue(i, 0).ToString().Trim().Replace('_', ' '); myReport.AddProperty(actNameNode, commonProperties.GetValue(i, 1).ToString().Trim()); } StationConfig.StationInfos actSI = myStationConfig.GetStationInfosForTest(this.cb_TestTypes.Text); foreach (StationConfig.StationInfos.StationProperty actProp in actSI.StationProperties) { String actNameNode = actProp.Name.Replace('_', ' '); myReport.AddProperty(actNameNode, actProp.Value); } String StationName = actSI.Name; String StationGUID = actSI.GUID; myReport.TestRun.grade = "PASS"; myReport.Station = new _Station(StationGUID, StationName); if (this.act_SNS != null) { if (myReport.Cathegory.Product.SerialNo == this.act_SNS.SerialNumber) { foreach (StepInfo actFSI in this.act_SNS.Steps) { if (actFSI.Name.Trim() == "CustomerSerialNumber") { myReport.AddProperty("CustomerSN", actFSI.ResultValue); myReport.TestRun.AddTestRunChild(actFSI.Name, myReport.starttime, myReport.endtime, actFSI.Grade, actFSI.ResultValue, "*$*", actFSI.ResultValue); } else { myReport.TestRun.AddTestRunChild(actFSI.Name, myReport.starttime, myReport.endtime, actFSI.Grade, actFSI.ResultValue, "", "*$*"); } if (actFSI.Grade == "FAIL") { myReport.TestRun.grade = "FAIL"; } } } if (myReport.TestRun.grade == "FAIL") { myReport.AddProperty("To Repair", "Yes"); } } this.act_SNS = null; String strReportPath = this.myStationConfig.GetReportPathDirectory(); Array XmlReportLines; String XmlReportContent = ""; try { XmlReportLines = myReport.GetXMLReport(strReportPath, true); if (myReport.TestRun.grade == "") { MessageBox.Show("Problem pri vytvarani reportu. Zavolajte prosim technika."); this.Close(); } foreach (String ActLine in XmlReportLines) { XmlReportContent = String.Concat(XmlReportContent, ActLine); } } catch (Exception ex) { MessageBox.Show(ex.Message); } // if (this.objBelMes.Activated) { try { String testKind = this.cb_TestTypes.Text; if (testKind == "Adjustement") { testKind = "Adjustment"; } if (myReport.TestRun.grade.ToUpper().Trim() == "PASS") { myReport.TestRun.grade = "Pass"; } if (myReport.TestRun.grade.ToUpper().Trim() == "FAIL") { myReport.TestRun.grade = "Fail"; } if (this.objBelMes.SetActualResult(myReport.Cathegory.Product.SerialNo, testKind, String.Concat(myReport.TestRun.grade, "ed"), XmlReportContent)) { if (this.objBelMes.Authorization.intReturnCode == 0) { this.lbl_Info.ForeColor = System.Drawing.Color.Green; } else { if (this.objBelMes.Authorization.blnMustTraced) { this.lbl_Info.ForeColor = System.Drawing.Color.Red; } else { this.lbl_Info.ForeColor = System.Drawing.Color.FromArgb(255, 150, 0); } } //this.Authorization.TryAuthorization(myReport.Cathegory.Product.SerialNo, testKind, String.Concat(myReport.TestRun.grade, "ED"), this.Env, false, false, XmlReportContent); } else { return(false); } this.lbl_Info.Text = this.objBelMes.Authorization.strResult; } catch { return(false); } } return(true); } catch { return(false); } }