using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Stone.Common; using Stone.Entity; using Stone.WinBiz.JISAdmin; using System.IO; using System.Threading; using Gm_WMS.DataAccess.DataService; using Stone.WinBiz.SystemData; namespace Stone.WinModule.AssembleAdmin { public partial class frmEdiPrintAssembleScan : Stone.WinModule.frmBase { #region 正常订单 private string PackageGroupName = ""; private int PackageQty = 0; private DataSet dsData = null; private bool isLoad = false; private LocalDBService dbnew = new LocalDBService(); public frmEdiPrintAssembleScan() { InitializeComponent(); } private void frmEdiPrintAssembleScan_Load(object sender, EventArgs e) { try { MyGridViewStyle.SetDataGridMenuCommon(this.dgGrid); MyGridViewStyle.SetDataGridMenuCommon(this.dgReOrder); PackageGroupName = MyAppconfig.ReadValue("JIS扫描打印类型"); PackageQty = Convert.ToInt32(MyAppconfig.ReadValue("JIS扫描打印装箱数")); this.lblPackageGroupName.Text = PackageGroupName + " (" + PackageQty + ")"; ReOrderUpdateGrid(); InsertUpdateGrid(); timer2.Enabled = true; UpdateGrid(); isLoad = true; } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); } } private void txtBillNo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (this.txtBillNo.Text.Trim() != "") { this.txtOrderNo.Focus(); this.txtOrderNo.SelectAll(); } } } private void txtOrderNo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (this.txtBillNo.Text.Trim().ToUpper() != this.txtOrderNo.Text.Trim()) { MyMessageBox.ShowMessagePop("转配单条码和序列标签条码不一样"); this.txtOrderNo.Focus(); this.txtOrderNo.SelectAll(); return; } this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); } } private void txtBarCode_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { if (this.txtBillNo.Text.Trim() == "") { MyMessageBox.ShowMessagePop("请扫描装配单"); this.txtBillNo.Focus(); this.txtBillNo.SelectAll(); return; } if (this.txtOrderNo.Text.Trim() == "") { MyMessageBox.ShowMessagePop("请扫描序列标签"); this.txtOrderNo.Focus(); this.txtOrderNo.SelectAll(); return; } if (this.txtBarCode.Text.Trim() == "") { MyMessageBox.ShowMessagePop("请扫描油漆件标签"); this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); return; } string BillNo = this.txtBillNo.Text.Trim().ToUpper(); string OrderNumber = this.txtOrderNo.Text.Trim().ToUpper(); string BarCode = this.txtBarCode.Text.Trim().ToUpper(); if (BillNo != OrderNumber) { MyMessageBox.ShowMessagePop("转配单条码和序列标签条码不一样"); this.txtBillNo.Focus(); this.txtBillNo.SelectAll(); return; } if (BarCode.Length < 10) { MyMessageBox.ShowMessagePop("油漆件条码不正确"); this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); return; } OrderNumber = OrderNumber + "1"; BarCode = BarCode.Substring(0, BarCode.Length - 10); BarCode = F_FIFO.GetModel(BarCode); if (BarCode.Length > 7) { BarCode = BarCode.Substring(0, 7); } //BarCode = BarCode.Substring(0, 7); ScanOrderNumber(OrderNumber, BarCode); } catch (Exception ex) { MyLogger.Write(ex.Message); MyMessageBox.ShowMessagePop(ex.Message); this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); } } } private void btnUpdate_Click(object sender, EventArgs e) { try { UpdateGrid(); } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); } } private void btnPrint_Click(object sender, EventArgs e) { try { if (this.dgGrid.SelectedRows.Count == 0) throw new Exception("请选择一行要打印的数据"); string OrderNumber = this.dgGrid.SelectedRows[0].Cells["OrderNumber"].Value.ToString(); Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); DataSet dsNow = t_JIS_Seq5000.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc"); if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在"); if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == true) throw new Exception(OrderNumber + " 已经打印过了"); t_JIS_Seq5000.Edit("[IsPrintAssemble]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString()); dsNow.Tables[0].TableName = "BillHead"; F_JIS5000_Print.PrintAssembly(dsNow); F_JIS5000_Print.PrintAssemblyLabel(dsNow); UpdateGrid(); } catch (Exception ex) { MyLogger.Write(ex.Message); MyMessageBox.ShowMessagePop(ex.Message); } } private void AddPrintAssemble(string OrderNumber, Gm_WMS.DataAccess.DataService.LocalDBService db, int IsReOrder) { Entity_t_JIS_PrintAssemble t_JIS_PrintAssemble = new Entity_t_JIS_PrintAssemble(db); DataRow drNew = null; drNew = t_JIS_PrintAssemble.Table.NewRow(); drNew["OrderNumber"] = OrderNumber; drNew["PackageGroupName"] = PackageGroupName; drNew["SuperMarket"] = "SMA"; drNew["IsReOrder"] = IsReOrder; t_JIS_PrintAssemble.Add(drNew); drNew = t_JIS_PrintAssemble.Table.NewRow(); drNew["OrderNumber"] = OrderNumber; drNew["PackageGroupName"] = PackageGroupName; drNew["SuperMarket"] = "SMB"; drNew["IsReOrder"] = IsReOrder; t_JIS_PrintAssemble.Add(drNew); } private void ScanOrderNumber(string OrderNumber, string BarCode) { try { Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); DataSet dsNow = t_JIS_Seq5000.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc"); if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在"); if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsTransport"]) == true) throw new Exception(OrderNumber + " 已经扫描过了"); if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == false) throw new Exception(OrderNumber + " 未打印,不能扫描"); string PartNumber = dsNow.Tables[0].Rows[0]["PartNumber"].ToString(); if (BarCode != PartNumber.Split('-')[0].Trim()) { MyMessageBox.ShowMessagePop("油漆件条码扫描不正确"); this.txtBarCode.Focus(); this.txtBarCode.SelectAll(); return; } UpdateGrid(); t_JIS_Seq5000.Edit("[IsTransport]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString()); AddPrintAssemble(dsNow.Tables[0].Rows[0]["OrderNumber"].ToString(), dbnew, 0); try { string filename = WriteMES(dsNow, false); FtpMES(filename); } catch (Exception ex) { MyMessageBox.ShowErrorMessage(ex.Message); } for (int i = 0; i < this.dgGrid.Rows.Count; i++) { if (OrderNumber == this.dgGrid.Rows[i].Cells["OrderNumber"].Value.ToString()) { if (this.dgGrid.Rows.Count >= (i + 2)) //找到下一个订单 { string OrderNumberNew = this.dgGrid.Rows[i + 1].Cells["OrderNumber"].Value.ToString(); DataSet dsNext = t_JIS_Seq5000.GetData("[OrderNumber]='" + OrderNumberNew + "' and [PackageGroupName]='" + PackageGroupName + "' "); if (dsNext.Tables[0].Rows.Count > 0) { t_JIS_Seq5000.Edit("[IsPrintAssemble]=1", "[ID]=" + dsNext.Tables[0].Rows[0]["ID"].ToString()); dsNext.Tables[0].TableName = "BillHead"; F_JIS5000_Print.PrintAssembly(dsNext); F_JIS5000_Print.PrintAssemblyLabel(dsNext); } } else //未找到下一个订单 { if (this.dgGrid.Rows.Count >= PackageQty) //已经满,生成装箱单 { string BillNo = F_JIS5000_Print.GetPackingListNumber(dbnew, PackageGroupName); string PagerNumber = F_JIS5000_Print.GetNumber(dbnew, PackageGroupName, 2); string ids = ""; for (int j = 0; j < dsData.Tables[0].Rows.Count; j++) { ids += dsData.Tables[0].Rows[j]["ID"].ToString() + ","; } if (ids != "") { ids = ids.Substring(0, ids.Length - 1); t_JIS_Seq5000.Edit("[IsPrintPackingList]=1, [PackingListNumber]='" + BillNo + "', [PagerNumber]='" + PagerNumber + "'", "[ID] in(" + ids + ")"); } } } break; } } UpdateGrid(); this.txtBillNo.Text = ""; this.txtOrderNo.Text = ""; this.txtBarCode.Text = ""; this.txtBillNo.Focus(); this.txtBillNo.SelectAll(); } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); this.txtBillNo.Focus(); this.txtBillNo.SelectAll(); } } private void UpdateGrid() { Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); dsData = t_JIS_Seq5000.GetData("top " + PackageQty + " ID, SequenceNumber, CheckSequence, OrderNumber, partNumber, PartName, SwetTime, IsPrintAssemble, IsTransport, PartsFamily, supplyGroup", "[IsFix]=1 and (SwetTime is not null) and IsPrintPackingList=0 and PackageGroupName='" + PackageGroupName + "'", "[SequenceNumber] asc"); this.dgGrid.DataSource = dsData.Tables[0]; this.dgGrid.Columns["ID"].Visible = false; this.dgGrid.Columns["CheckSequence"].Width = 80; this.dgGrid.Columns["CheckSequence"].HeaderText = "序号"; this.dgGrid.Columns["SequenceNumber"].Visible = false; this.dgGrid.Columns["OrderNumber"].HeaderText = "订单号"; this.dgGrid.Columns["OrderNumber"].Width = 80; this.dgGrid.Columns["partNumber"].HeaderText = "零件号"; this.dgGrid.Columns["partNumber"].Width = 100; this.dgGrid.Columns["PartName"].HeaderText = "描述"; this.dgGrid.Columns["PartName"].Width = 240; this.dgGrid.Columns["SwetTime"].HeaderText = "时间"; this.dgGrid.Columns["SwetTime"].Width = 140; this.dgGrid.Columns["IsPrintAssemble"].HeaderText = "打印"; this.dgGrid.Columns["IsPrintAssemble"].Width = 50; this.dgGrid.Columns["IsTransport"].HeaderText = "扫描"; this.dgGrid.Columns["IsTransport"].Width = 50; this.dgGrid.Columns["PartsFamily"].Visible = false; this.dgGrid.Columns["supplyGroup"].Visible = false; MyGridViewStyle.SetDataGridRowNumber(this.dgGrid); for (int i = 0; i < this.dgGrid.Columns.Count; i++) { this.dgGrid.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } this.dgGrid.Sort(this.dgGrid.Columns["SequenceNumber"], ListSortDirection.Descending); if (isLoad) { if (dsData.Tables[0].Rows.Count > 0) //如果第一行未打印,则自动打印第一行 { if (Convert.ToBoolean(this.dgGrid.Rows[0].Cells["IsPrintAssemble"].Value) == false) { DataSet dsNext = t_JIS_Seq5000.GetData("[ID]=" + this.dgGrid.Rows[0].Cells["ID"].Value.ToString()); if (dsNext.Tables[0].Rows.Count > 0) { t_JIS_Seq5000.Edit("[IsPrintAssemble]=1", "[ID]=" + dsNext.Tables[0].Rows[0]["ID"].ToString()); dsNext.Tables[0].TableName = "BillHead"; F_JIS5000_Print.PrintAssembly(dsNext); F_JIS5000_Print.PrintAssemblyLabel(dsNext); UpdateGrid(); } } } } } #endregion #region ftp_mes private static string WriteMES(DataSet dsData, bool isReOrder) { if (MyAppconfig.ReadValue("MES_AutoSend").Trim() != "是") { return ""; } string ID = dsData.Tables[0].Rows[0]["ID"].ToString(); string OrderNumber = dsData.Tables[0].Rows[0]["OrderNumber"].ToString(); DateTime SwetTime = Convert.ToDateTime(dsData.Tables[0].Rows[0]["SwetTime"]); string CheckSequence = dsData.Tables[0].Rows[0]["CheckSequence"].ToString(); string SequenceNumber = dsData.Tables[0].Rows[0]["SequenceNumber"].ToString(); EntityBase v_JIS_Tod = new Entity_v_JIS_Tod(); if (isReOrder) v_JIS_Tod = new Entity_v_JIS_Tod_ReOrder(); DataSet dsTod = v_JIS_Tod.GetData("", "[SeqID]=" + dsData.Tables[0].Rows[0]["ID"].ToString(), "JisMajor desc, seqnum asc"); StreamWriter sw = null; string filename = ""; string name = ""; try { filename = MyIO.GetAppPath() + "\\MES_BAK\\"; if (!Directory.Exists(filename)) { Directory.CreateDirectory(filename); } OrderNumber = OrderNumber.Substring(0, OrderNumber.Length - 1); name = DateTime.Now.ToString("yyMMddHHmmss") + "-" + OrderNumber + ".csv"; filename += name; string PrintTime = MyDateTime.Format(MyDateTimeType.DateTime); sw = new StreamWriter(filename, false, Encoding.Default); foreach (DataRow drData in dsTod.Tables[0].Rows) { string partNumber = drData["partNumber"].ToString().Trim(); string line = ID + ","; line += OrderNumber + ","; line += MyDateTime.Format(SwetTime, MyDateTimeType.Date) + ","; line += MyDateTime.Format(SwetTime, MyDateTimeType.Time3) + ","; line += "\"" + drData["PartsFamily"].ToString() + "\","; line += "\"" + drData["SupplyGroup"].ToString() + "\","; line += drData["Variant1"].ToString() + ","; line += partNumber + ","; line += drData["description"].ToString() + ","; line += drData["ColorName"].ToString() + "(" + drData["ColorCode"].ToString() + ")" + ","; line += drData["quantity"].ToString() + ","; line += CheckSequence + ","; line += (partNumber.Length > 2 ? partNumber.Substring(partNumber.Length - 2, 2) : "") + ","; line += "AAB" + ","; line += drData["Variant"].ToString() + ","; line += PrintTime; sw.WriteLine(line); } } catch (Exception ex) { MyLogger.Write(ex.Message); } finally { if (sw != null) sw.Close(); } return name; } private static void FtpMES(string filename) { return ; string MES_AutoSend = MyAppconfig.ReadValue("MES_AutoSend").Trim(); string MES_Path = MyAppconfig.ReadValue("MES_Path").Trim(); if (MES_AutoSend == "是") { string path = MyIO.GetAppPath() + "\\MES_BAK"; File.Copy(path + "\\" + filename.ToString(), MES_Path + "\\" + filename.ToString()); } } #endregion #region 处理ReOrder订单 private void timer2_Tick(object sender, EventArgs e) { try { ReOrderUpdateGrid(); InsertUpdateGrid(); } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); } } private void ReOrderUpdateGrid() { Entity_t_JIS_Seq5000_ReOrder t_JIS_Seq5000_ReOrder = new Entity_t_JIS_Seq5000_ReOrder(); DataSet dsReOrder = t_JIS_Seq5000_ReOrder.GetData("ID, OrderNumber, partNumber, PartName, SwetTime", "IsPrintAssemble=0 and PackageGroupName='" + PackageGroupName + "'", "[SwetTime] asc"); this.dgReOrder.DataSource = dsReOrder.Tables[0]; this.dgReOrder.Columns["ID"].Visible = false; this.dgReOrder.Columns["OrderNumber"].HeaderText = "订单号"; this.dgReOrder.Columns["partNumber"].HeaderText = "零件号"; this.dgReOrder.Columns["PartName"].HeaderText = "描述"; this.dgReOrder.Columns["PartName"].Width = 260; this.dgReOrder.Columns["SwetTime"].HeaderText = "时间"; this.dgReOrder.Columns["SwetTime"].Width = 180; MyGridViewStyle.SetDataGridRowNumber(this.dgReOrder); for (int i = 0; i < this.dgReOrder.Columns.Count; i++) { this.dgReOrder.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } } private void btnReOrder_Click(object sender, EventArgs e) { Gm_WMS.DataAccess.DataService.LocalDBService db = null; try { if (this.dgReOrder.SelectedRows.Count == 0) throw new Exception("请选择一条ReOrder订单"); string OrderNumber = this.dgReOrder.SelectedRows[0].Cells["OrderNumber"].Value.ToString(); db = new Gm_WMS.DataAccess.DataService.LocalDBService(); db.BeginTrans(); Entity_t_JIS_Seq5000_ReOrder t_JIS_Seq5000_ReOrder = new Entity_t_JIS_Seq5000_ReOrder(db); DataSet dsNow = t_JIS_Seq5000_ReOrder.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' and [IsPrintAssemble]=0 ", "[ID] asc"); if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在"); //if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == true) throw new Exception(OrderNumber + " 已经打印了"); t_JIS_Seq5000_ReOrder.Edit("[IsPrintAssemble]=1,[IsTransport]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString()); dsNow.Tables[0].TableName = "BillHead"; F_JIS5000_Print_ReOrder.PrintAssembly(dsNow.Copy()); F_JIS5000_Print_ReOrder.PrintAssemblyLabel(dsNow.Copy()); if (IsDeploy(dsNow)) { AddPrintAssemble(dsNow.Tables[0].Rows[0]["OrderNumber"].ToString(), db, 1); string filename = WriteMES(dsNow, true); FtpMES(filename); } db.Commit(); ReOrderUpdateGrid(); } catch (Exception ex) { if (db != null) db.Rollback(); MyMessageBox.ShowMessagePop(ex.Message); } finally { if (db != null) db.EndTrans(); } } //是否装配 private bool IsDeploy(DataSet dsNow) { bool ret = true; Entity_t_Product t_Product = new Entity_t_Product(); DataTable dtProduct = t_Product.GetData("[Code]='" + dsNow.Tables[0].Rows[0]["partNumber"].ToString() + "'").Tables[0]; if (dtProduct.Rows.Count > 0) { if (dtProduct.Rows[0]["Deploy"].ToString().Trim().ToUpper() == "F35" || dtProduct.Rows[0]["Deploy"].ToString().Trim().ToUpper() == "F30") { ret = false; } } return ret; } private void btnReOrderUpdate_Click(object sender, EventArgs e) { try { ReOrderUpdateGrid(); } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); } } #endregion #region 插单 private void btnInsertUpdate_Click(object sender, EventArgs e) { try { InsertUpdateGrid(); } catch (Exception ex) { MyMessageBox.ShowMessagePop(ex.Message); } } private void btnInsertPrint_Click(object sender, EventArgs e) { Gm_WMS.DataAccess.DataService.LocalDBService db = null; try { if (this.dgInsert.SelectedRows.Count == 0) throw new Exception("请选择一条插单订单"); string OrderNumber = this.dgInsert.SelectedRows[0].Cells["OrderNumber"].Value.ToString(); db = new Gm_WMS.DataAccess.DataService.LocalDBService(); db.BeginTrans(); Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(db); DataSet dsNow = t_JIS_Seq5000.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc"); if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在"); if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == true) throw new Exception(OrderNumber + " 已经打印了"); t_JIS_Seq5000.Edit("[IsPrintAssemble]=1,[IsTransport]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString()); AddPrintAssemble(dsNow.Tables[0].Rows[0]["OrderNumber"].ToString(), db, 0); dsNow.Tables[0].TableName = "BillHead"; F_JIS5000_Print.PrintAssembly(dsNow); F_JIS5000_Print.PrintAssemblyLabel(dsNow); string filename = WriteMES(dsNow, false); FtpMES(filename); db.Commit(); InsertUpdateGrid(); } catch (Exception ex) { if (db != null) db.Rollback(); MyMessageBox.ShowMessagePop(ex.Message); } finally { if (db != null) db.EndTrans(); } } private void InsertUpdateGrid() { Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(); DataSet dsInsert = t_JIS_Seq5000.GetData("ID, OrderNumber, partNumber, PartName, SwetTime", "IsPrintAssemble=0 and [IsInsert]=1 and PackageGroupName='" + PackageGroupName + "'", "[SwetTime] asc"); this.dgInsert.DataSource = dsInsert.Tables[0]; this.dgInsert.Columns["ID"].Visible = false; this.dgInsert.Columns["OrderNumber"].HeaderText = "订单号"; this.dgInsert.Columns["partNumber"].HeaderText = "零件号"; this.dgInsert.Columns["PartName"].HeaderText = "描述"; this.dgInsert.Columns["PartName"].Width = 260; this.dgInsert.Columns["SwetTime"].HeaderText = "时间"; this.dgInsert.Columns["SwetTime"].Width = 180; MyGridViewStyle.SetDataGridRowNumber(this.dgInsert); for (int i = 0; i < this.dgInsert.Columns.Count; i++) { this.dgInsert.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; } } #endregion private void timer1_Tick(object sender, EventArgs e) { this.txtBillNo.Focus(); this.timer1.Enabled = false; } } }