using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using Mesnac.Compressor.Data; using Mesnac.Action.Default.Purview; using SocketProcess; using System.Threading; using Mesnac.Compressor.Entity; using Mesnac.Log; using KeyBord; namespace DisassemblyTable { public partial class Disassembly : Form { SerialEquip Com; SocketServer socket; string Port= System.Configuration.ConfigurationManager.AppSettings["para"]; string connType= System.Configuration.ConfigurationManager.AppSettings["Type"]; public delegate void Transit(string data); public string NGStationID = ""; //private ScanerHook_V2 listener; public Disassembly() { InitializeComponent(); InitPort(); //initCombox(); //USB扫码枪 //initUsbScanBarCode(); //listener.Start(); InitializeInputLanguage("en-US"); } public void initUsbScanBarCode() { try { //listener = new ScanerHook_V2(); //listener.ScanerEvent += Listener_ScanerEvent; } catch (Exception ex) { } } //函数内容: 函数方法,设置系统输入法 //函数版本: 0.0.0.0 //修改时间: 2023.07.12 //修改人:gyc //============================================================================================ //注意事项: //1.语言项,如zh-CN,en-US //2. //============================================================================================ private void InitializeInputLanguage(string cultureType) { //获取系统中已经安装的文字输入法 InputLanguageCollection MyInputs = InputLanguage.InstalledInputLanguages; //遍历获取英文输入法索引值 for (int i = 0; i < MyInputs.Count; i++) { if (MyInputs[i].Culture.IetfLanguageTag == cultureType) { //获取英文输入法 InputLanguage enInput = InputLanguage.InstalledInputLanguages[i]; //设置为当前输入法 InputLanguage.CurrentInputLanguage = enInput; break; } } } private void Listener_ScanerEvent(ScanerHook_V2.ScanerCodes codes) { try { this.textBox1.Text = ""; this.textBox1.Text = codes.Result; } catch (Exception ex) { } } public void InitPort() { if (connType.ToLower() == "socket") { socket = new SocketServer(); ThreadPool.QueueUserWorkItem(new WaitCallback(Thread), Port); socket.ReciveEvent += socketRecieve; } else if (connType.ToLower() == "com") { // string Port = "COM3"; Com = new SerialEquip(connType+Port); Com.OpenCom(null); Com.SerialData += Receive; } else { MessageBox.Show("未找到通信类型:"+ connType); } } public void Thread(object o) { int port=Convert.ToInt32(o); socket.StartService(port); } public void socketRecieve(string barcode, object o) { Receive(barcode); } public void Receive(string Data) { if (this.InvokeRequired) { this.Invoke(new Transit(Receive), Data); return; } try { Console.WriteLine("扫描数据" + Data + "数据完成"); ClearAllControl(); if (!Data.Trim().Contains("E") && Data.Length < 10) { return; } textBox1.Text = Data.Trim(); //判断条码内容为什么组件(动静盘,前盖,壳体) if (Data.Trim().Contains("M")) { DbHandler db = new DbHandler(); DataSet ds = db.Select(Data.Trim()); DataTable dt1 = ds.Tables[0]; if (dt1 != null && dt1.Rows.Count > 0) { DataRow dr = dt1.Rows[0]; string NGstation = dr["StationName"].ToString(); this.tb_ngstation.Text = NGstation; NGStationID = dr["OrderID"].ToString(); //BindReStartStationInfo(); } else { //MessageBox.Show("未查询到当前条码生产NG信息"); this.tb_ngstation.Text = "未查询到当前条码生产NG信息"; //DataTable dt = GetNewDatatable(); //dataGridView1.DataSource = dt; NGStationID = ""; //BindReStartStationInfo(); return; } if (ds.Tables.Count > 1) { dataGridView1.DataSource = ds.Tables[1]; } //解绑 //通过条码查询是什么组件 //DbHandler dbHandler = new DbHandler(); //string remark = ""; //if (radioButton1.Checked) //{ // remark = radioButton1.Text; //} //else if (radioButton2.Checked) //{ // remark = radioButton2.Text; //} //else if (radioButton3.Checked) //{ // remark = radioButton3.Text; //} //else if (radioButton4.Checked) //{ // remark = radioButton4.Text; //} //else if (radioButton5.Checked) //{ // remark = radioButton5.Text; //} //dbHandler.InsertRepairInfo("", Data, "2", remark); //LogService.Instance.Error("》》》重投成功,产品码:" + textBox1.Text.Trim() + ",重投工位:2"); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } } private void ClearAllControl() { this.textBox1.Text = ""; dataGridView1.DataSource = null; this.tb_ngstation.Text = ""; } private void Disassembly_FormClosing(object sender, FormClosingEventArgs e) { try { // listener.Stop(); if (connType.ToLower() == "socket") { //socket.StopService(); socket.ReciveEvent -= socketRecieve; } else if (connType.ToLower() == "com") { if(Com != null) Com.Close(); } } catch (Exception ex) { } } private DataTable GetNewDatatable() { DataTable dt = new DataTable(); dt.Columns.Add("NG工位",typeof(string)); dt.Columns.Add("记录时间", typeof(string)); dt.Columns.Add("漏率显示", typeof(string)); dt.Columns.Add("漏率显示最小值", typeof(string)); dt.Columns.Add("漏率显示最大值", typeof(string)); dt.Columns.Add("漏率显示状态", typeof(string)); dt.Columns.Add("漏率显示幂值", typeof(string)); dt.Columns.Add("漏率显示幂值最小值", typeof(string)); dt.Columns.Add("漏率显示幂值最大值", typeof(string)); dt.Columns.Add("漏率显示幂值状态", typeof(string)); dt.Columns.Add("真空压力", typeof(string)); dt.Columns.Add("真空压力最小值", typeof(string)); dt.Columns.Add("真空压力最大值", typeof(string)); dt.Columns.Add("真空压力状态", typeof(string)); DataRow dataRow = dt.NewRow(); dataRow["NG工位"] = "140氦气检漏"; dataRow["记录时间"] = DateTime.Now.ToString("yyyy/MM/dd"); dataRow["漏率显示"] = "0.0000"; dataRow["漏率显示最小值"] = "0.0000"; dataRow["漏率显示最大值"] = "0.0000"; dataRow["漏率显示状态"] = "不合格"; dataRow["漏率显示幂值"] = "0.0000"; dataRow["漏率显示幂值最小值"] = "0.0000"; dataRow["漏率显示幂值最大值"] = "0.0000"; dataRow["漏率显示幂值状态"] = "不合格"; dataRow["真空压力"] = "0.0000"; dataRow["真空压力最小值"] = "0.0000"; dataRow["真空压力最大值"] = "0.0000"; dataRow["真空压力状态"] = "不合格"; dt.Rows.Add(dataRow); return dt; } private void button1_Click(object sender, EventArgs e) { string Data = ""; //ClearAllControl(); Data=textBox1.Text.Trim(); //Data = "SJ1811020005"; Console.WriteLine("扫描数据"+ Data); DbHandler db = new DbHandler(); DataSet ds = db.Select(Data); if (ds==null||ds.Tables.Count < 1) { //MessageBox.Show("未查询到当前条码生产NG信息"); //this.tb_ngstation.Text = "140氦气检漏"; DataTable dt = GetNewDatatable(); //dataGridView1.DataSource = dt; return; } DataTable dt1 = ds.Tables[0]; if (dt1 != null && dt1.Rows.Count > 0) { DataRow dr = dt1.Rows[0]; string NGstation = dr["StationName"].ToString(); //this.tb_ngstation.Text = NGstation; } else { //MessageBox.Show("未查询到当前条码生产NG信息"); //this.tb_ngstation.Text = "140氦气检漏"; DataTable dt = GetNewDatatable(); //dataGridView1.DataSource = dt; return; } if (ds.Tables.Count > 1) { //dataGridView1.DataSource = ds.Tables[1]; } //for (int i = 0; i < dataGridView1.Columns.Count; i++) //{ // dataGridView1.Columns[i].Frozen = false; //} } private void BindReStartStationInfo() { try { if (string.IsNullOrEmpty(NGStationID)) { NGStationID = "20"; } DbHandler db = new DbHandler(); cbReStartStation.DisplayMember = "StationName"; cbReStartStation.ValueMember = "StationID"; cbReStartStation.DataSource = db.GetReStartStationList(NGStationID); } catch (Exception ex) { MessageBox.Show("工位绑定失败"); } } private void button2_Click(object sender, EventArgs e) { try { if (textBox1.Text.Trim() == "") { MessageBox.Show("条码为空!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string REMARK = ""; string RestarStation = "11"; if (!radioButton1.Checked && !radioButton2.Checked) { MessageBox.Show("请选择拆解类型!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (radioButton1.Checked) { REMARK = radioButton1.Text; RestarStation = "11"; } else if (radioButton2.Checked) { REMARK = radioButton2.Text; RestarStation = "24"; } DbHandler dbHandler = new DbHandler(); dbHandler.InsertRepairInfo(textBox1.Text, textBox1.Text.Trim(), RestarStation, REMARK); LogService.Instance.Error("》》》返修成功,产品码:" + textBox1.Text.Trim()); //清空返修后的数据 bool iflag = dbHandler.UpdateTraceReStartStation("1", RestarStation, textBox1.Text.Trim()); if (iflag) { //根据NG工位删除之后的数据 SelectStationData(textBox1.Text.Trim()); } bool iflag1 = dbHandler.DeletePrintInfo(textBox1.Text.Trim()); if (iflag1) { LogService.Instance.Error("》》》打印记录清除成功,产品码:" + textBox1.Text.Trim()); } //修改重投状态T_RP_SemiProInfo textBox1.Text = ""; radioButton1.Checked = false; radioButton2.Checked = false; MessageBox.Show("返修记录成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { LogService.Instance.Error("异常:" + ex.Message); } } private void SelectStationData(string Barcode) { try { DbHandler dbHandler = new DbHandler(); string cbReStartStation = ""; if (radioButton1.Checked) { cbReStartStation = "22"; } else { cbReStartStation = "25"; } DataTable dt1 = dbHandler.GetDeleteReStartStationList(cbReStartStation); if (dt1 != null && dt1.Rows.Count > 0) { foreach (DataRow VARIABLE in dt1.Rows) { //删除工位数据 DeleteStationData(VARIABLE["TableName"].ToString(), Barcode); } } } catch (Exception ex) { LogService.Instance.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } } private void DeleteStationData(string TableName,string BarCode) { try { DbHandler dbHandler = new DbHandler(); dbHandler.DeleteStationData(TableName, BarCode); } catch (Exception ex) { LogService.Instance.Error("空间名:" + ex.Source + ";" + '\n' + "方法名:" + ex.TargetSite + '\n' + "故障点:" + ex.StackTrace.Substring(ex.StackTrace.LastIndexOf("\\") + 1, ex.StackTrace.Length - ex.StackTrace.LastIndexOf("\\") - 1) + '\n' + "错误提示:" + ex.Message); } } private void Disassembly_Load(object sender, EventArgs e) { //BindReStartStationInfo(); //dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; } private void button3_Click(object sender, EventArgs e) { try { //修改数据 //查询条码 DbHandler db = new DbHandler(); DataTable dt = db.Test1(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { //这里如果要判断最后一工位与倒数第二个工位互锁,取ID=16 string s = dt.Rows[i]["SemiBarcode_A"].ToString(); LogService.Instance.Debug("A码:" + s); //按照A码查询产品码 string proBarcode = db.GetProductionInfo(s); LogService.Instance.Debug("产品码:" + proBarcode); //执行update语句 db.UpdateCPM(proBarcode, s); LogService.Instance.Debug((i + 1) + "行,更新成功!"); } } } catch (Exception ex) { LogService.Instance.Error("异常:" + ex.Message); } } } }