using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using gregn6Lib; using MESClassLibrary.BLL.Log; using MESClassLibrary.BLL.Mistake247; using MESClassLibrary.Model; namespace PurchingMistakeNew { public partial class Form4 : Form { public Form4() { InitializeComponent(); } private void textBox1_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (textBox1.Text.Trim() != "") { textBox2.Enabled = true; textBox2.Focus(); } else { MessageBox.Show("请扫描设备配置码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); textBox1.Focus(); return; } } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void Form4_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; textBox1.Enabled = true; textBox2.Enabled = false; panel1.Visible = false; initData(); } private void textBox2_KeyDown(object sender, KeyEventArgs e) { try { string partNo = "", deviceNo = "", partsub = "",order=""; int BoxCount = 0, type = 0, orderCount = 0, ActualCount = 0; RecordBLL rbll = new RecordBLL(); MistakeBLL bll = new MistakeBLL(); AssemblyBLL abll = new AssemblyBLL(); Plan247BLL pbll = new Plan247BLL(); AssemblyModel md = new AssemblyModel(); RecordModel rmd = new RecordModel(); GridppReport report = new GridppReport(); string batchNo = "", newbatchNo = ""; if (e.KeyCode == Keys.Enter) { #region 是否扫描单号 if (textBox4.Text.Trim() == "") { MessageBox.Show("请扫描计划单!", "提示", MessageBoxButtons.OK); textBox4.Focus(); return; } #endregion if (textBox2.Text.Trim().Length < 10) { MessageBox.Show("半成品条码有误,请重新扫描!", "提示", MessageBoxButtons.OK); textBox2.Focus(); return; } if (VerifyHelper.ScanSjBarCodeFormat(textBox2.Text.Trim()) == false) { MessageBox.Show($"扫描条码[{textBox2.Text.Trim()}]格式错误!", "提示", MessageBoxButtons.OK); textBox2.Text = ""; textBox2.Focus(); return; } #region 判断计划单里是否有此产品的生产计划并且是未完成 DataTable hdt = pbll.IsHavePlan(textBox2.Text.Trim().Substring(0, 10), textBox4.Text.Trim()); if (hdt != null && hdt.Rows.Count > 0) { order = hdt.Rows[0]["OrderNo"].ToString(); orderCount = Convert.ToInt32(hdt.Rows[0]["OrderCount"].ToString()); } else { MessageBox.Show("该零件已生产完成!", "提示", MessageBoxButtons.OK); textBox2.Focus(); return; } #endregion DataTable recorddt = rbll.SearchByPartNo1(textBox2.Text.Trim()); if (recorddt != null && recorddt.Rows.Count > 0) { MessageBox.Show("此半成品已装配过!", "提示", MessageBoxButtons.OK); textBox2.Focus(); return; } else { deviceNo = textBox1.Text.Trim(); partNo = textBox2.Text.Substring(0, 10); #region 判断半成品和设备码是否匹配 DataTable dt = bll.IsMath(deviceNo, partNo); if (dt != null && dt.Rows.Count > 0) { #region 根据半成品查找总成零件号 DataTable dt2 = bll.SearchByNo(partNo, deviceNo); if (dt2 != null && dt2.Rows.Count > 0) { partsub = dt2.Rows[0]["PartNo2"].ToString(); LogHelper.WriteLog("PartSub:" + partsub); #region 判断总成零件当前批次是否存在 newbatchNo = DateTime.Now.ToString("yyyy-MM-dd").Substring(2, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(5, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(8, 2); LogHelper.WriteLog("NewBatch:" + newbatchNo); try { DataTable partdt = abll.searchPartNo(partsub + "." + newbatchNo); if (partdt != null && partdt.Rows.Count > 0) { string tmpPartNo = partdt.Rows[0]["PartNo"].ToString(); md.PartNo = tmpPartNo.Substring(0, tmpPartNo.Length - 6) +(Convert.ToInt32(tmpPartNo.Substring(tmpPartNo.Length - 6, 6)) + 1).ToString().PadLeft(6, '0'); LogHelper.WriteLog("有记录:"+md.PartNo); } else { md.PartNo = partsub + "." + newbatchNo + "." + "000001"; LogHelper.WriteLog("无记录:" + md.PartNo); } } catch (Exception ex) { LogHelper.WriteLog("报catch"); LogHelper.WriteLogManager(ex); //LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod()); MessageBox.Show("连接数据库失败!"); return; } #endregion md.PartName = dt2.Rows[0]["PartName2"].ToString(); #region 保存总成条码 md.ID = Guid.NewGuid().ToString(); md.BatchNo = DateTime.Now.ToString("yyyy-MM-dd").Substring(2, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(5, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(8, 2); #region 根据半成品零件号判断总成类型、总成条码模板、打印机 #region 注释 //if (partNo == "1230002601" || partNo == "1230003122") //{ // md.PartType = "X247 左侧前门板"; // type = 1; // report.LoadFromFile(@"D:\X247 左侧前门板.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); //} //if (partNo == "1230002604" || partNo == "1230003130") //{ // md.PartType = "X247 左侧后门板"; // type = 1; // report.LoadFromFile(@"D:\X247 左侧后门板.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); //} //if (partNo == "1230002602" || partNo == "1230003126") //{ // md.PartType = "X247 右侧前门板"; // type = 2; // report.LoadFromFile(@"D:\X247 右侧前门板.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); //} //if (partNo == "1230002605" || partNo == "1230003134") //{ // md.PartType = "X247 右侧后门板"; // type = 2; // report.LoadFromFile(@"D:\X247 右侧后门板.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); //} #endregion #region 轮眉 if (partNo == "1230002609") { md.PartType = "X247 前部左侧轮眉"; type = 3; report.LoadFromFile(@"D:\X247 前部左侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (partNo == "1230002615") { md.PartType = "X247 后部左侧轮眉"; type = 3; report.LoadFromFile(@"D:\X247 后部左侧后轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (partNo == "1230002612") { md.PartType = "X247 前部右侧轮眉"; type = 4; report.LoadFromFile(@"D:\X247 前部右侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); } if (partNo == "1230002617") { md.PartType = "X247 右侧后部后轮眉"; type = 4; report.LoadFromFile(@"D:\X247 右侧后部后轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); } if (partNo == "1230002619") { md.PartType = "X247 后部左侧前轮眉"; type = 5; report.LoadFromFile(@"D:\X247 后部左侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (partNo == "1230002621") { md.PartType = "X247 后部右侧前轮眉"; type = 5; report.LoadFromFile(@"D:\X247 后部右侧前轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } #endregion #region 注释 //if (partNo == "1230002627") //{ // md.PartType = "X247 后部左侧扰流板"; // type = 6; // report.LoadFromFile(@"D:\X247 后部左侧扰流板眉.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); //} //if (partNo == "1230002600") //{ // md.PartType = "X247 后部右侧扰流板"; // type = 7; // report.LoadFromFile(@"D:\X247 后部右侧扰流板.grf"); // report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); //} #endregion #endregion md.Color = "通用"; md.ColorNo = ""; md.TapeBatchNo = md.BatchNo; md.Validity = "3个月"; md.ValidityDate = "从" + DateTime.Now.ToString("yyyy-MM-dd") + "到" + DateTime.Now.AddMonths(3).ToString("yyyy-MM-dd"); md.Flag = 0; abll.AddInfo(md); #endregion #region 打印总成条码 report.Register(""); report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString(); report.Print(false); abll.UpdateInfo(md); #endregion #region 更新订单完成数 pbll.UpdateCount(partsub, order); #endregion #region 保存记录 rmd.ID = Guid.NewGuid().ToString(); rmd.PartNo1 = textBox2.Text.Trim(); rmd.PartNo2 = md.PartNo; rmd.Type = type; rbll.AddInfo(rmd); #endregion textBox1.Focus(); textBox2.Enabled = false; textBox1.Text = ""; textBox2.Text = ""; initData(); } #endregion } else { MessageBox.Show("匹配失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion } } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); MessageBox.Show("数据库连接失败!", "提示", MessageBoxButtons.OK); } } public void initData() { string[] part = { "A2478850022", "A2478850222", "A2478850122", "A2478850322" }; string[] sum = new string[4]; DataTable dt = null; RecordBLL bll = new RecordBLL(); string batch = DateTime.Now.ToString("yyyy-MM-dd").Substring(2, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(5, 2) + DateTime.Now.ToString("yyyy-MM-dd").Substring(8, 2); //string batch = "191111"; try { for (int i = 0; i < 4; i++) { dt = bll.GetCount(part[i], batch); if (dt != null && dt.Rows.Count > 0) { sum[i] = dt.Rows[0]["sum"].ToString(); } else { sum[i] = ""; } } #region uc1.PartInfo = "A2478850022 前部左侧轮眉总成"; uc2.PartInfo = "A2478850222 后部左侧后轮眉总成"; uc3.PartInfo = "A2478850122 前部右侧轮眉总成"; uc4.PartInfo = "A2478850322 后部右侧后轮眉总成"; uc1.Sum = sum[0]; uc2.Sum = sum[1]; uc3.Sum = sum[2]; uc4.Sum = sum[3]; #endregion } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void button1_Click(object sender, EventArgs e) { panel1.Visible = true; } private void button2_Click(object sender, EventArgs e) { try { AssemblyBLL bll = new AssemblyBLL(); AssemblyModel md = new AssemblyModel(); string part = ""; GridppReport report = new GridppReport(); if (textBox3.Text.Trim() == "") { MessageBox.Show("总成条码不能为空!", "提示", MessageBoxButtons.OK); textBox3.Focus(); return; } DataTable dt = bll.searchPartNo(textBox3.Text.Trim()); if (dt != null && dt.Rows.Count > 0) { #region 补打 md.ID = Guid.NewGuid().ToString(); md.PartNo = textBox3.Text.Trim(); md.PartName = dt.Rows[0]["PartName"].ToString(); md.BatchNo = dt.Rows[0]["BatchNo"].ToString(); md.Color = dt.Rows[0]["Color"].ToString(); md.ColorNo = dt.Rows[0]["ColorNo"].ToString(); md.PartType = dt.Rows[0]["PartType"].ToString(); md.TapeBatchNo = dt.Rows[0]["TapeBatchNo"].ToString(); md.Validity = dt.Rows[0]["Validity"].ToString(); md.ValidityDate = dt.Rows[0]["ValidityDate"].ToString(); md.Des = dt.Rows[0]["Des"].ToString(); md.Flag = 1; bll.AddInfo(md); part = textBox3.Text.Trim().Substring(0, textBox3.Text.Trim().IndexOf(".")); #region 轮眉 if (part == "A2478850022") { md.PartType = "X247 前部左侧轮眉"; report.LoadFromFile(@"D:\X247 前部左侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (part == "A2478850222") { md.PartType = "X247 后部左侧后轮眉"; report.LoadFromFile(@"D:\X247 后部左侧后轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (part == "A2478850122") { md.PartType = "X247 前部右侧轮眉"; report.LoadFromFile(@"D:\X247 前部右侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); } if (part == "A2478850322") { md.PartType = "X247 右侧后部后轮眉"; report.LoadFromFile(@"D:\X247 右侧后部后轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); } if (part == "A2477309400") { md.PartType = "X247 后部左侧前轮眉"; report.LoadFromFile(@"D:\X247 后部左侧轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer1"].ToString(); } if (part == "A2477309600") { md.PartType = "X247 后部右侧前轮眉"; report.LoadFromFile(@"D:\X247 后部右侧前轮眉.grf"); report.Printer.PrinterName = ConfigurationManager.AppSettings["Printer2"].ToString(); } #endregion #endregion report.Register(""); report.ConnectionString = ConfigurationManager.ConnectionStrings["report"].ToString(); report.Print(false); bll.UpdateInfo(md); } else { MessageBox.Show("总成条码不存在!", "提示", MessageBoxButtons.OK); textBox3.Focus(); return; } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private void button3_Click(object sender, EventArgs e) { panel1.Visible = false; } private void textBox4_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { if (textBox4.Text.Trim().Length != 12) { MessageBox.Show("订单号有误,请重新扫描!", "提示", MessageBoxButtons.OK); textBox4.Focus(); return; } #region 判断订单号是否存在 if (initList()) return; #endregion } } catch (Exception ex) { LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod()); } } private bool initList() { Plan247BLL bll = new Plan247BLL(); int a = 0; this.listView1.Items.Clear(); DataTable dt = bll.SearhByOrderNo(textBox4.Text.Trim()); if (dt != null && dt.Rows.Count > 0) { #region 判断订单是否生产完成 for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToInt32(dt.Rows[i]["IsFinish"].ToString()) == 1) { a += 1; if (a == dt.Rows.Count) { MessageBox.Show("订单已完成,请扫描其他订单!", "提示", MessageBoxButtons.OK); textBox4.Focus(); return true; } } else { ListViewItem lvi = new ListViewItem(dt.Rows[i]["OrderNo"].ToString()); lvi.SubItems.Add(dt.Rows[i]["PartNo"].ToString()); //后面添加的Item都为SubItems ,即为子项 lvi.SubItems.Add(dt.Rows[i]["PartName2"].ToString()); lvi.SubItems.Add(dt.Rows[i]["OrderCount"].ToString()); lvi.SubItems.Add(dt.Rows[i]["CompleteCount"].ToString()); listView1.Items.Add(lvi); } } #endregion } else { MessageBox.Show("订单号不存在,请重新扫描!", "提示", MessageBoxButtons.OK); textBox4.Focus(); return true; } return false; } } }