void ShowMessage(object sender, EntityData ed, string MSG, bool b) { RichTextBox rtb = (RichTextBox)sender; UserControl1 u = new UserControl1(); string strmes = ""; if (ed == null) { strmes = DateTime.Now.ToString("yyyy-MM-dd hh:mm ") + MSG; sqlhelp.GetDataSetWithSQLString(string.Format(sqlhelp.InsertAuto, u.ResourceName, u.OrBitUserName,strmes, ""), u.DatabaseServer, u.DatabaseName, u.DatabasePassword, u.DatabaseUser); } else { strmes = DateTime.Now.ToString("yyyy-MM-dd hh:mm ") + "随工单号" + ed.lotsn + ":" + MSG ; sqlhelp.GetDataSetWithSQLString(string.Format(sqlhelp.InsertAuto, u.ResourceName, u.OrBitUserName,strmes, ed.lotsn), u.DatabaseServer, u.DatabaseName, u.DatabasePassword, u.DatabaseUser); } if (b) rtb.AppendText(strmes+"\n"); else { rtb.AppendText(strmes+"\n"); rtb.ForeColor = System.Drawing.Color.Red; } rtb.Select(rtb.TextLength, 0); rtb.ScrollToCaret(); }
void DelegateSetDGVValue(object[] sender, EntityData ed) { if (ed == null) return; DataGridView dgv = (DataGridView)sender[0]; RichTextBox rtb = (RichTextBox)sender[1]; if (dgv.Columns["落料数"] == null) return; dgv.Rows[0].Cells["落料数"].Value = ed.PunchPCS; dgv.Rows[0].Cells["盒数"].Value = ed.BoxNum; if (dgv.Rows[0].Cells["标箱数量"].Value.ToString() != ed.box_pcs.ToString()) { ShowMessage(rtb, ed, dgv.Rows[0].Cells["随工单号"].Value.ToString() + "的标箱数量由" + dgv.Rows[0].Cells["标箱数量"].Value.ToString() + "个更改为" + ed.box_pcs.ToString() + "个\n", true); } dgv.Rows[0].Cells["标箱数量"].Value = ed.box_pcs; }
/// <summary> /// 修改提示界面 /// </summary> /// <param name="sender"></param> /// <param name="ed"></param> /// <param name="MSG"></param> void DelegateSetValue(object[] sender, EntityData ed, string MSG, bool b) { ShowMessage(sender[0], ed, MSG, b); }
/// <summary> /// 修改随工单信息UI /// </summary> /// <param name="sender"></param> /// <param name="ed"></param> public void SetUIControlValue(object[] sender, EntityData ed) { if (ed == null) return; DataGridView dgv = (DataGridView)sender[0]; RichTextBox rtb = (RichTextBox)sender[1]; if (dgv.InvokeRequired) { DelegateSetDataGridView dsdgv = new DelegateSetDataGridView(DelegateSetDGVValue); dgv.Invoke(dsdgv, new Object[] { new object[] { dgv, rtb }, ed }); } else { if (dgv.Columns["落料数"] == null) return; dgv.Rows[0].Cells["落料数"].Value = ed.PunchPCS; dgv.Rows[0].Cells["盒数"].Value = ed.BoxNum; if (dgv.Rows[0].Cells["标箱数量"].Value.ToString() != ed.box_pcs.ToString()) { ShowMessage(rtb, ed, dgv.Rows[0].Cells["随工单号"].Value.ToString() + "的标箱数量由" + dgv.Rows[0].Cells["标箱数量"].Value.ToString() + "个更改为" + ed.box_pcs.ToString() + "个\n", true); } dgv.Rows[0].Cells["标箱数量"].Value = ed.box_pcs; } }
public void SetUIControlValue(object sender, EntityData ed, string msg, bool b) { RichTextBox rtb = (RichTextBox)sender; //if (ed == null) // return; if (rtb.InvokeRequired) { DelegateSetRichTextBox dsrtb = new DelegateSetRichTextBox(DelegateSetValue); rtb.Invoke(dsrtb, new Object[] { new object[] { rtb }, ed, msg, b }); } else { ShowMessage(rtb, ed, msg, b); } }
/// <summary> /// 线程打印标识单 /// </summary> //private void StartThread(object obj) //{ // MyObject mobj = (MyObject)obj; // if (mobj.ed != null) // { // GetLotsnPCSBoxNum(ref mobj.ed); // int pcs = mobj.ed.PunchPCS - (mobj.ed.box_pcs * mobj.ed.BoxNum); // if (pcs >= mobj.ed.box_pcs) // { // md.SetUIControlValue(richTextBox1, mobj.ed, "即将生产" + pcs / mobj.ed.box_pcs + "个标识单", true); // DataSet ds = GetDataSetWithSQLString(string.Format(sqlhelp.PrintBSD, mobj.dgv.Rows[0].Cells["IdentityDocumentsId"].Value.ToString(), // OrBitUserId, // pcName, pcs / mobj.ed.box_pcs)); // if (ds == null) // return; // if (ds.Tables[ds.Tables.Count - 1].Rows[0]["Return Value"].ToString() == "-1") // { // md.SetUIControlValue(richTextBox1, mobj.ed, ds.Tables[ds.Tables.Count - 1].Rows[0]["@I_ReturnMessage"].ToString(), false); // } // else // { // string FTPid = ds.Tables[0].Rows[0][0].ToString(); // string FtpDirectory = ds.Tables[0].Rows[0][1].ToString(); // ds.Tables.RemoveAt(0); // ds.Tables.Remove(ds.Tables[ds.Tables.Count - 1]); // if (pMRZ.DownloadFtp(mobj.ed.Filepath, FTPid + mobj.i, FTP.ftpDIR + "/" + FtpDirectory + "/" + FTPid, FTP.ftpip, FTP.ftpUNM, FTP.ftpPWD) == -2) // md.SetUIControlValue(richTextBox1, mobj.ed, "标签文件下载失败", true); // else // md.SetUIControlValue(richTextBox1, mobj.ed, pMRZ.printStimulsoftReports(FTPid + mobj.i, ds, false), true); // GetIPSN(DGVLotSN1); // } // } // md.SetUIControlValue(new object[] { mobj.dgv, richTextBox1 }, mobj.ed); // } //} private void StartThread(object obj) { List<MyObject> mobj = (List<MyObject>)obj; int pcs = 0; foreach (var item in mobj) { GetLotSn(); if (_EDlotsn1 != null && item.ed.lotsn == _EDlotsn1.lotsn) { item.ed = _EDlotsn1; } if (_EDlotsn2 != null && item.ed.lotsn == _EDlotsn2.lotsn) { item.ed = _EDlotsn2; } if (DGVLotSN1.Columns["随工单号"] != null && item.dgv.Rows[0].Cells["随工单号"].Value.ToString() == DGVLotSN1.Rows[0].Cells["随工单号"].Value.ToString()) { item.dgv = DGVLotSN1; } if (dgvLotSN2.Columns["随工单号"] != null && item.dgv.Rows[0].Cells["随工单号"].Value.ToString() == dgvLotSN2.Rows[0].Cells["随工单号"].Value.ToString()) { item.dgv = dgvLotSN2; } if (item.ed == null) continue; pcs = item.ed.PunchPCS - (item.ed.box_pcs * item.ed.BoxNum); if (item.ed.isover && pcs > 0) { int printBoxNum = 0; string _msg = ""; if (item.ed.box_pcs <= 0) continue; if (pcs % item.ed.box_pcs > 0) { printBoxNum = pcs / item.ed.box_pcs + 1; _msg = "即将生产" + printBoxNum + "个标识单,包含零头箱"; } else { printBoxNum = pcs / item.ed.box_pcs; _msg = "即将生产" + printBoxNum + "个标识单"; } printBSD(item, printBoxNum, _msg); } if (pcs >= item.ed.box_pcs && !item.ed.isover) { int printBoxNum = 0; string _msg = ""; if (item.ed.box_pcs <= 0) continue; printBoxNum = pcs / item.ed.box_pcs; _msg = "即将生产" + printBoxNum + "个标识单"; printBSD(item, printBoxNum, _msg); #region 根据随工单打印 //DataSet ds = GetDataSetWithSQLString(string.Format(sqlhelp.PrintBSD, item.dgv.Rows[0].Cells["IdentityDocumentsId"].Value.ToString(), // OrBitUserId, // pcName, printBoxNum)); //md.SetUIControlValue(richTextBox1, item.ed, _msg, true); //if (ds == null) // return; //if (ds.Tables[ds.Tables.Count - 1].Rows[0]["Return Value"].ToString() == "-1") //{ // md.SetUIControlValue(richTextBox1, item.ed, ds.Tables[ds.Tables.Count - 1].Rows[0]["@I_ReturnMessage"].ToString(), false); //} //else //{ // string FTPid = ds.Tables[0].Rows[0][0].ToString(); // string FtpDirectory = ds.Tables[0].Rows[0][1].ToString(); // ds.Tables.RemoveAt(0); // ds.Tables.Remove(ds.Tables[ds.Tables.Count - 1]); // if (pMRZ.DownloadFtp(item.ed.Filepath, FTPid + item.i, FTP.ftpDIR + "/" + FtpDirectory + "/" + FTPid, FTP.ftpip, FTP.ftpUNM, FTP.ftpPWD) == -2) // md.SetUIControlValue(richTextBox1, item.ed, "标签文件下载失败", true); // else // { // md.SetUIControlValue(richTextBox1, item.ed, pMRZ.printStimulsoftReports(FTPid + item.i, ds, false), true); // item.ed.BoxNum += printBoxNum; // } //} #endregion } // 打印 if (_EDlotsn1 != null && item.ed.lotsn == _EDlotsn1.lotsn && _EDlotsn1.isover) { md.SetUIControlValue(new object[] { item.dgv, richTextBox1 }, _EDlotsn1); _EDlotsn1 = new EntityData(); } if (_EDlotsn2 != null && item.ed.lotsn == _EDlotsn2.lotsn && _EDlotsn2.isover) { _EDlotsn2 = new EntityData(); } md.SetUIControlValue(new object[] { item.dgv, richTextBox1 }, item.ed); // GetLotSn(); GetIPSN(DGVLotSN1); } }
EntityData SeveEntityData(DataTable dt) { EntityData edt = new EntityData(); if (dt == null || dt.Rows.Count <= 0) { return edt; } edt.lotsn = dt.Rows[0]["随工单号"].ToString();//随工单 if (dt.Rows[0]["盒数"].ToString() == "") edt.BoxNum = 0; else edt.BoxNum = int.Parse(dt.Rows[0]["盒数"].ToString());//盒子数量 if (dt.Rows[0]["落料数"].ToString() == "") { edt.PunchPCS = 0; } else edt.PunchPCS = int.Parse(dt.Rows[0]["落料数"].ToString());//落料数 if (dt.Rows[0]["标箱数量"].ToString() == "") { edt.box_pcs = 0; md.SetUIControlValue(richTextBox1, null, "请维护随工单[" + dt.Rows[0]["随工单号"].ToString() + "]对应料号的标箱数量!", false); } else edt.box_pcs = int.Parse(dt.Rows[0]["标箱数量"].ToString());//获取标箱数量 return edt; }
/// <summary> /// 获取上一个工单的落料情况 /// </summary> /// <param name="ed"></param> DataSet GetOLDLotSNInfo(EntityData ed) { if (ed == null) return null; if (ed.lotsn == "") return null; string sql = string.Format(sqlhelp.GetoldLotsn, ed.lotsn); return GetDataSetWithSQLString(sql); }
/// <summary> /// 获取对应随工单的落料数与标识单个数 /// </summary> /// <param name="ed"></param> void GetLotsnPCSBoxNum(ref EntityData ed) { string sql = string.Format(sqlhelp.GetLotSNPunchPCSBoxNum, ed.lotsn); DataSet ds = GetDataSetWithSQLString(sql); if (ds.Tables[0].Rows[0]["BoxNum"].ToString() == "") ed.BoxNum = 0; else ed.BoxNum = int.Parse(ds.Tables[0].Rows[0]["BoxNum"].ToString()); if (ds.Tables[0].Rows[0]["PunchPCS"].ToString() == "") ed.PunchPCS = 0; else ed.PunchPCS = int.Parse(ds.Tables[0].Rows[0]["PunchPCS"].ToString()); if (ds.Tables[0].Rows[0]["Box_pcs"].ToString() == "") ed.box_pcs = 0; else ed.box_pcs = int.Parse(ds.Tables[0].Rows[0]["Box_pcs"].ToString()); }
/// <summary> /// 获取机台当前的随工单 /// </summary> void GetLotSn() { pcName = "012-098";// Dns.GetHostName();//获取机台名称 string sql = string.Format(sqlhelp.GetLotSN, pcName); DataSet ds = GetDataSetWithSQLString(sql); if (ds.Tables[ds.Tables.Count - 1].Rows[0]["Return Value"].ToString() == "-1") { md.SetUIControlValue(richTextBox1, null, ds.Tables[ds.Tables.Count - 1].Rows[0]["@I_ReturnMessage"].ToString(), false); return; } else { //DGVLotSN1.DataSource = ds.Tables[0]; if (ds.Tables[0].Rows[0][1].ToString() != "-2") { md.SetDGVUIClic(new object[] { DGVLotSN1 }, ds.Tables[0], ""); if (_EDlotsn1 == null) _EDlotsn1 = new EntityData(); if (_EDlotsn1.lotsn != "" && _EDlotsn1.lotsn != ds.Tables[0].Rows[0]["随工单号"].ToString()) { DataSet ds1 = GetOLDLotSNInfo(_EDlotsn1); _EDlotsn1 = SeveEntityData(ds1.Tables[0]); _EDlotsn1.isover = true; md.SetDGVIsyc(new object[] { DGVLotSN1, label2 }, ds1.Tables[0], true, ""); }//换随工单后查询一次原随工单的落料数 else { _EDlotsn1 = SeveEntityData(ds.Tables[0]); _EDlotsn1.isover = false; md.SetDGVIsyc(new object[] { DGVLotSN1, label2 }, ds.Tables[0], true, ""); } } if (ds.Tables.Count > 2) { //判断随工单在哪里 if (ds.Tables[1].Rows[0][1].ToString() != "-2") { if (_EDlotsn2 == null) _EDlotsn2 = new EntityData(); if (_EDlotsn2.lotsn != "" && _EDlotsn2.lotsn != ds.Tables[1].Rows[0]["随工单号"].ToString()) { DataSet ds1 = GetOLDLotSNInfo(_EDlotsn2); _EDlotsn2 = SeveEntityData(ds1.Tables[0]); _EDlotsn2.isover = true; md.SetDGVIsyc(new object[] { dgvLotSN2, label2 }, ds1.Tables[0], true, ""); } else { _EDlotsn2 = SeveEntityData(ds.Tables[1]); _EDlotsn2.isover = false; md.SetDGVIsyc(new object[] { dgvLotSN2, label2 }, ds.Tables[1], true, ""); } } } else { //label1.Text = "随工单信息"; //label2.Visible = false; //dgvLotSN2.Visible = false; md.SetDGVIsyc(new object[] { dgvLotSN2, label2 }, null, false, ""); } } }