public static TrayList.Tray GetTrayInfo(string sn) { //with temp_table as //(select ROW_NUMBER() OVER(PARTITION BY serial_cd ORDER BY faci_seq desc),* //--faci_seq,updated_at,process_at,proc_uuid,work_cd,machine_cd,serial_cd,lot_cd,mo_cd,tag_id,datatype_id,partsserial_cd,partslot_cd,cavity_no //from t_faci_kk13 //where datatype_id = 'OVEN_TRAY_ID') //select* from temp_table // where row_number = 1 StringBuilder sql = new StringBuilder(); sql.AppendFormat( @"SELECT process_at,datatype_id,partsserial_cd FROM t_faci_{0} WHERE datatype_id = 'OVEN_TRAY_ID' AND serial_cd='{1}' ORDER BY faci_seq DESC" , Pqm.type.ToLower(), sn); System.Data.DataTable dt = new System.Data.DataTable(); new DBFactory().ExecuteDataTable(sql.ToString(), ref dt); TrayList.Tray tray = new TrayList.Tray() { sn = sn }; if (dt.Rows.Count > 0) { tray.process_at = dt.Rows[0]["process_at"].ToString(); tray.datatype_id = dt.Rows[0]["datatype_id"].ToString(); tray.partsserial_cd = dt.Rows[0]["partsserial_cd"].ToString(); if (Info.TrayList.trayList.Count == 0) { tray.result = "0"; } else { tray.result = Info.TrayList.trayList[0].partsserial_cd == tray.partsserial_cd ? "0" : "1"; } return(tray); } else { tray.result = "1"; return(tray); } }
public static void WriteCSV(Info.TrayList.Tray trayInfo)//(string SN,DateTime checkTime) { DateTime dt = DateTime.Now; string fileName = type + factory + building + line + process + dt.ToString("_yyyyMMddHHmmss_") + trayInfo.sn; string path = Document.pathList[1] + fileName + ".csv"; using (StreamWriter file = new StreamWriter(path, true)) { string[] csvStr = new string[] { type, factory, building, line, process, trayInfo.sn, "", "", "", dt.ToString("yy,MM,dd,HH,mm,ss"), "1", inspect, upperLimit, lowerLimit, Info.Oven.roastTime.ToString(), Info.Oven.result, trayInfo.result, "0" }; string str = String.Join(",", csvStr); file.WriteLine(str);// 直接追加文件末尾,换行 } }
void Action(string sn) { txtDisplaySN.Text = sn; txtDetail.ForeColor = Color.Black; txtSN.Text = ""; txtSN.SelectAll(); Application.DoEvents(); //填满之后,清空 object sender = new object { }; if (sequence == NTRS4Oven.Layout.sum) { BtnClear_Click(sender, new EventArgs()); } if (!sn.Contains("ERROR")) { sn = sn.Substring(0, 17); } #region SN检查:是否重复 foreach (Info.TrayList.Tray var in Info.TrayList.trayList) { if (sn == var.sn && sn != "ERROR") { txtResult.Text = "FAIL"; txtDetail.Text = "Duplicate SN"; txtDetail.ForeColor = Color.Red; txtDetail.BackColor = txtDetail.BackColor; return; } } #endregion if (Info.TrayList.trayList.Count == 0) { #region oven检查 Info.Oven.initializeOven(); //是否存在于log(最近2个月) if (Info.Oven.ovenLogExist(sn)) { //烤的时间在上下限内 if (!Info.Oven.inLimit()) { txtResult.Text = "FAIL"; txtDetail.Text = "Oven Info:\r\nBaking time is out of range"; txtDetail.ForeColor = Color.Red; txtDetail.BackColor = txtDetail.BackColor; return; } } else { txtResult.Text = "FAIL"; txtDetail.Text = "Oven Info:\r\nNo data in oven log"; txtDetail.ForeColor = Color.Red; txtDetail.BackColor = txtDetail.BackColor; return; } #endregion } #region 第一个tray检查 Info.TrayList.Tray tray = Info.DB.GetTrayInfo(sn); if (Info.TrayList.trayList.Count == 0 && tray.partsserial_cd == null) { txtResult.Text = "FAIL"; txtDetail.Text = "Tray Info:\r\nNo tray data in database"; txtDetail.ForeColor = Color.Red; txtDetail.BackColor = txtDetail.BackColor; return; } Info.TrayList.trayList.Add(tray); #endregion #region 方块布局显示 int[] location = Array.ConvertAll(Regedit.Trajectory[sequence].Split(','), int.Parse); try { TlpLayout.Controls.Add(NTRS4Oven.Layout.paint(Info.TrayList.trayList[Info.TrayList.trayList.Count - 1]), location[0] - 1, location[1] - 1); } catch (Exception ex) { MessageBox.Show(ex.Message); } #endregion #region 数据显示 txtResult.Text = Info.TrayList.trayList[Info.TrayList.trayList.Count - 1].result == "0" ? "PASS":"******"; txtDetail.Text = string.Format("Oven Info:\r\n{0}sec\r\n{1}\r\n{2}", Info.Oven.roastTime, Info.Oven.start, Info.Oven.end); if (Info.TrayList.trayList[Info.TrayList.trayList.Count - 1].partsserial_cd == null) { txtDetail.Text += "\r\n\r\nTray Info:\r\nNo tray data in database"; txtDetail.ForeColor = Color.Red; txtDetail.BackColor = txtDetail.BackColor; } else { txtDetail.Text += string.Format("\r\n\r\nTray Info:\r\n{0}\r\n{1}\r\n{2}", Info.TrayList.trayList[Info.TrayList.trayList.Count - 1].process_at, Info.TrayList.trayList[Info.TrayList.trayList.Count - 1].datatype_id, Info.TrayList.trayList[Info.TrayList.trayList.Count - 1].partsserial_cd); } #endregion //写log Log.WriteLog(txtDisplaySN.Text, txtDetail.Text, txtResult.Text); //非"MISS"写csv if (txtResult.Text != "MISS") { Pqm.WriteCSV(Info.TrayList.trayList[Info.TrayList.trayList.Count - 1]); } sequence++; return; //Judge.judge(sn); //txtSN.Text = string.Empty; ////方块布局显示 //int[] location = Array.ConvertAll(Regedit.Trajectory[sequence].Split(','), int.Parse); //try //{ // TlpLayout.Controls.Add(NTRS4Oven.Layout.paint(AllInfo.SNlist[AllInfo.SNlist.Count - 1]), // location[0] - 1, location[1] - 1); //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message); //} ////数据显示 //txtDisplaySN.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].SN; //txtDetail.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].detail; //txtResult.Text = AllInfo.SNlist[AllInfo.SNlist.Count - 1].result; ////写log //Log.WriteLog(txtDisplaySN.Text, txtDetail.Text, txtResult.Text); ////非"MISS"写csv //if (txtResult.Text != "MISS") //{ // Pqm.WriteCSV(AllInfo.SNlist[AllInfo.SNlist.Count - 1]); //} //sequence++; }
//public static Panel paint(AllInfo.SNinfo snInfo) //{ // Color panelColor = new Color(); // Color strColor = new Color(); // switch (snInfo.result) // { // case "PASS": // //panelColor = ColorTranslator.FromHtml("#008000"); // panelColor = Color.Green; // strColor = Color.Black; // break; // case "MISS": // panelColor = Color.Yellow; // strColor = Color.Black; // break; // case "FAIL": // panelColor = Color.Red; // strColor = Color.Black; // break; // default: // panelColor = Color.Red; // strColor = Color.Black; // break; // } // Panel panel = new Panel(); // panel.Dock = DockStyle.Fill; // panel.BackColor = panelColor; // //panel.AutoSize = true; // Label l1 = new Label(); // l1.Text = snInfo.result; // //l1.Font = new Font("微软雅黑", 12, FontStyle.Bold); // l1.Font = new Font("微软雅黑",l1.Font.Size,FontStyle.Bold); // Label l2 = new Label(); // //绝对位置change动态位置 // l2.Location = new Point(0, 50); // l2.Text = Regedit.Trajectory[AllInfo.SNlist.Count-1]; // Label l3 = new Label(); // l3.BringToFront(); // //l3.AutoSize = true; // l3.Width = (Main.TlpLayout_Width / Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["col"])) - 10; // l3.Height = 24;//可以显示2行字 // l3.Location = new Point(0, 20); // //l3.Text = snInfo.detail=="PASS"?"Tray OK":"Tray NG"; // l3.Text = snInfo.tips; // panel.Controls.Add(l3); // l1.ForeColor = l2.ForeColor = l3.ForeColor = strColor; // panel.Controls.Add(l1); // panel.Controls.Add(l2); // return panel; //} public static Panel paint(Info.TrayList.Tray trayInfo) { Color panelColor = new Color(); Color strColor = new Color(); switch (trayInfo.result) { //case "PASS": case "0": //panelColor = ColorTranslator.FromHtml("#008000"); panelColor = Color.Green; strColor = Color.Black; break; //case "MISS": // panelColor = Color.Yellow; // strColor = Color.Black; // break; //case "FAIL": case "1": panelColor = Color.Red; strColor = Color.Black; break; default: panelColor = Color.Red; strColor = Color.Black; break; } Panel panel = new Panel(); panel.Dock = DockStyle.Fill; panel.BackColor = panelColor; //panel.AutoSize = true; Label l1 = new Label(); l1.Text = trayInfo.result == "0" ? "PASS" : "FAIL"; //l1.Font = new Font("微软雅黑", 12, FontStyle.Bold); l1.Font = new Font("微软雅黑", l1.Font.Size, FontStyle.Bold); l1.ForeColor = strColor; Label l2 = new Label(); //绝对位置change动态位置 l2.Location = new Point(0, 50); l2.Text = Regedit.Trajectory[Info.TrayList.trayList.Count - 1]; l2.ForeColor = strColor; if (trayInfo.result == "1") { Label l3 = new Label(); l3.BringToFront(); //l3.AutoSize = true; l3.Width = (Main.TlpLayout_Width / Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["col"])) - 10; l3.Height = 24;//可以显示2行字 l3.Location = new Point(0, 20); l3.ForeColor = strColor; panel.Controls.Add(l3); l3.Text = trayInfo.partsserial_cd == null ? "No tray data" : "Different tray"; } panel.Controls.Add(l1); panel.Controls.Add(l2); return(panel); }