using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.IO; using System.Windows.Forms; using CoreFS.CA06; using PrintSolution.LabelPrinter; using INI; using Infragistics.Win.UltraWinGrid; using System.Reflection; namespace Core.LZMes.Client.UIM.UIM02 { public partial class UIM020060 : FrmBase { private ZebraPrinter printer = new ZebraPrinter(); private Hashtable pkgHt = new Hashtable(); private int hasPackaged = 0; public UIM020060() { InitializeComponent(); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": this.DoQuery(); break; case "Save": this.DoSave(); break; case "Export": this.DoExport(); break; case "Print": this.DoPrint(); break; case "Exit": this.Close(); break; } } /// /// 查询原料库库存数据 /// private void DoQuery() { try { this.dataSet1.Tables[0].Clear(); string ordNo = this.textBox1.Text.Trim();// string ordSeq = this.textBox2.Text.Trim();// string coilNo = this.textBox3.Text.Trim();// hasPackaged = int.Parse(this.ultraComboEditor2.Value.ToString()); string diiver = this.textBox4.Text.Trim(); string startTime = ""; string endTime = ""; if (this.ultraCheckEditor1.Checked) { startTime = ""; startTime = ""; } else { startTime = this.ultraDateTimeEditor3.Value != null ? ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd") : "";//开始时间 endTime = this.ultraDateTimeEditor2.Value != null ? ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//结束时间 } string prog = this.ultraComboEditor3.Value.ToString(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM02.UIM020060"; ccp.MethodName = "queryPkgCoil"; ccp.ServerParams = new object[] { ordNo, ordSeq, coilNo, hasPackaged, diiver, startTime, endTime, prog }; ccp.SourceDataTable = this.dataSet1.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); //打印标签后颜色区分 20130314 DataRowCollection drs = dataSet1.Tables[0].Rows; string ord_pak, pak, ordfl; for (int i = 0; i < drs.Count; i++) { if (drs[i]["PRINT_TP"].ToString().Equals("Y")) { if (!drs[i]["ORG_ORD_NO"].ToString().Equals(drs[i]["ORD_NO"].ToString()) &&!drs[i]["ORG_ORD_SEQ"].ToString().Equals(drs[i]["ORD_SEQ"].ToString())) ultraGrid1.Rows[i].Appearance.BackColor = Color.FromArgb(192, 255, 192); } //订单包装要求跟实际包装不一致变红色 ord_pak = drs[i]["PAKMTH_TP"].ToString().Trim(); pak = drs[i]["PACKAGE_LEVEL"].ToString().Trim(); ordfl = drs[i]["ORD_FL"].ToString().Trim(); if (ord_pak != pak && "订单材".Equals(ordfl)) { ultraGrid1.Rows[i].Appearance.BackColor = Color.SandyBrown; } } //打印标签后颜色区分 20130314 } catch (Exception EX) { MessageBox.Show(EX.ToString()); } } private void DoSave() { ultraGrid1.Update(); if (this.ultraDateTimeEditor1.Value == null) { MessageBox.Show("请选择包装日期!"); this.ultraDateTimeEditor1.Focus(); return; } ArrayList list = new ArrayList(); ArrayList coilLables = new ArrayList(); Infragistics.Win.UltraWinGrid.RowsCollection rs = this.ultraGrid1.Rows; for (int i = 0; i < rs.Count; i++) { if ("TRUE".Equals(rs[i].Cells["CHK"].Text.ToUpperInvariant())) { string packageLevel = rs[i].Cells["PACKAGE_LEVEL"].Text; if (packageLevel.Equals("")) { MessageBox.Show("第" + (i + 1) + "行包装等级为空,请核对后再点击保存!"); return; } string[] packageArray = new string[2]; packageArray[0] = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString(); packageArray[1] = pkgHt[rs[i].Cells["PACKAGE_LEVEL"].Text].ToString(); list.Add(packageArray); //ColdCoilLable coilLabel = new ColdCoilLable(); //coilLabel.rollNo = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString().Substring(0,9); //coilLabel.specification = rs[i].Cells["SPEC_ABBSYM"].Value.ToString(); //coilLabel.steelGrade = rs[i].Cells["SPEC_STL_GRD"].Value.ToString(); //coilLabel.dimension = rs[i].Cells["PRINT_SIZE"].Value.ToString(); //coilLabel.coilNo = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString(); //coilLabel.weight = rs[i].Cells["ACT_WGT"].Value.ToString(); //coilLabel.heatNo = rs[i].Cells["CHARGE_NO"].Value.ToString(); //coilLabel.prodDate = rs[i].Cells["MILL_DTIME"].Value.ToString(); //coilLabel.contractNo = rs[i].Cells["ORD_NO"].Value.ToString() + "-" + rs[i].Cells["ORD_SEQ"].Value.ToString(); //coilLabel.licenseNo = string.Empty; //coilLabel.licenseMark = string.Empty; //coilLabel.checker = string.Empty; //coilLabel.barcode = coilLabel.coilNo; //coilLables.Add(coilLabel); } } string pkgReg = this.UserInfo.GetUserID(); string pkgShift = this.UserInfo.GetUserOrder(); string pkgGroup = this.UserInfo.GetUserGroup(); string pkgDtime = this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd"); if (list.Count > 0) { CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM02.UIM020060"; ccp.MethodName = "savePkgCoil"; ccp.ServerParams = new object[] { list, pkgShift, pkgGroup, pkgReg, pkgDtime, hasPackaged }; this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); //if (hasPackaged == 0) //{ //print //PrintLabel(coilLables); //PrintLabel(coilLables); //} this.DoQuery(); } } private void DoExport() { try { if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK) { string fileName = this.saveFileDialog1.FileName; ultraGridExcelExporter1.Export(ultraGrid1, fileName); System.Diagnostics.Process.Start(fileName); } } catch (Exception EX) { MessageBox.Show(EX.ToString()); } } private void DoPrint() { ultraGrid1.UpdateData(); //************************** Hashtable param = new Hashtable(); string line = string.Empty; ArrayList coilLables = new ArrayList(); Infragistics.Win.UltraWinGrid.RowsCollection rs = this.ultraGrid1.Rows; for (int i = 0; i < rs.Count; i++) { if (Convert.ToBoolean(rs[i].Cells["CHK"].Value)) { ColdCoilLable coilLabel = new ColdCoilLable(); //coilLabel.rollNo = textBox9.Text.Trim().Substring(0, 9);//批号 //coilLabel.specification = textBox8.Text.Trim();//标准号 //coilLabel.steelGrade = textBox5.Text.Trim();//牌号 //coilLabel.dimension = textBox15.Text.Trim() + "*" + textBox14.Text.Trim();//厚度、宽度 //coilLabel.heatNo = textBox13.Text.Trim();//炉号 coilLabel.rollNo = string.Empty; //批号 coilLabel.specification = string.Empty; //标准号 coilLabel.steelGrade = string.Empty; //牌号 coilLabel.dimension = string.Empty; //厚度、宽度 coilLabel.heatNo = string.Empty;//炉号 coilLabel.coilNo = textBox9.Text.Trim();//卷号 coilLabel.weight = textBox10.Text.Trim();//重量 string millTime = textBox12.Text.Trim();//生产时间 if (millTime != null && millTime != "") { coilLabel.prodDate = millTime.Replace(" ", "");//生产日期 } else { coilLabel.prodDate = string.Empty; } if (checkBoxORD.Checked)//合同号 { coilLabel.contractNo = textBox11.Text.Trim() + "-" + textBox7.Text.Trim();//合同号,订单号 } else { coilLabel.contractNo = string.Empty; } if (this.checkBox3.Checked)//许可证号 { coilLabel.licenseNo = this.textBoxLicenseNo.Text.Trim(); } else { coilLabel.licenseNo = string.Empty; } if (this.checkBox4.Checked)//许可证标识 { coilLabel.licenseMark = textBoxlicenseMark.Text;//string.Empty; } else { coilLabel.licenseMark = string.Empty; } coilLabel.checker = string.Empty; coilLabel.barcode = coilLabel.coilNo; coilLables.Add(coilLabel); line = rs[i].Cells["LINE_TP"].Text.ToString(); } } //print try { PrintLabel(coilLables); PrintLabel(coilLables); PrintLabel(coilLables);//一次打印三张 20151231 WL PrintLabel(coilLables);//一次打印4张 20160805 WL //20130314添加标签打印标识 string coilNo1 = this.textBox9.Text.Trim(); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM02.UIM020060"; ccp.MethodName = "updateColor"; ccp.ServerParams = new object[] { coilNo1 }; ccp.SourceDataTable = this.dataSet1.Tables[0]; this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal); //20140304 param.Add("i1", line); param.Add("i2", coilNo1); param.Add("i3", this.UserInfo.GetUserID()); param.Add("i4", "标签打印"); param.Add("i5", "UIM020060"); param.Add("i6", "打印后"); param.Add("o7", ""); CoreClientParam ccp4 = new CoreClientParam(); ccp4.ServerName = "UIB.COM.ComDBProcedure"; ccp4.MethodName = "doXmlProcedure"; ccp4.ServerParams = new Object[] { "UIL010020_02_CALL.CALL", param }; this.ExecuteNonQuery(ccp4, CoreInvokeType.Internal); //提示 ArrayList all = ccp4.ReturnObject as ArrayList; if (all[0].ToString() != "YY")//确认是否存在问题 { MessageBox.Show(all[0].ToString(), "提示"); return; } DoQuery(); } catch (Exception ex) { MessageBox.Show("连接打印机失败,请点击\"打印\"按钮重新打印!"); } } private void PrintLabel(ArrayList list) { foreach (ColdCoilLable coilLabel in list) { printer.printLable(coilLabel); } } private void UIM020060_Load(object sender, EventArgs e) { try { string Current = Directory.GetCurrentDirectory();//获取当前根目录 Ini ini = new Ini(Current + "/CoreFS.ini"); // 读取ini string labPrinterAddr = ini.ReadValue("LABPRINTERADDR", "4"); printer.Addr = labPrinterAddr; /*string labPrinterAddr = "10.10.76.140"; printer.Addr = labPrinterAddr;*/ //string version = ini.ReadValue("LABPRINTERADDR", "Version"); string version = "4"; printer.LableVersion = int.Parse(version); CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIM.UIM02.UIM020060"; ccp.MethodName = "queryPkgType"; ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal); ArrayList list = (ArrayList)ccp.ReturnObject; if (list != null) { this.ultraGrid1.DisplayLayout.ValueLists.Add("List1"); int listSize = list.Count; for (int i = 0; i < listSize; i++) { Infragistics.Win.ValueListItem item = new Infragistics.Win.ValueListItem(); Hashtable ht = (Hashtable)list[i]; string smCd = ht["SM_CD"].ToString(); string cmCfnm = ""; object obj = ht["SM_CFNM"]; if (obj != null) { cmCfnm = ht["SM_CFNM"].ToString(); } pkgHt.Add(cmCfnm, smCd); this.ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(smCd, cmCfnm); } this.ultraGrid1.DisplayLayout.ValueLists["List1"].DisplayStyle = Infragistics.Win.ValueListDisplayStyle.DisplayText; this.ultraGrid1.DisplayLayout.Bands[0].Columns["PACKAGE_LEVEL"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; this.ultraGrid1.DisplayLayout.Bands[0].Columns["PACKAGE_LEVEL"].ValueList = this.ultraGrid1.DisplayLayout.ValueLists["List1"]; this.ultraComboEditor2.SelectedIndex = 0; this.ultraComboEditor3.SelectedIndex = 0; } } catch (Exception ej) { System.Diagnostics.Debug.WriteLine(ej.ToString()); } } private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e) { try { if (e.Cell.Column.Key == "CHK") { string coilNo = string.Empty; string weight = string.Empty; string ordNo = string.Empty; string ordSeq = string.Empty; string ordThk = string.Empty; string ordWth = string.Empty; string heatNo = string.Empty; string steelCode = string.Empty; string standardNo = string.Empty; string millTime = string.Empty; string custspecstl = string.Empty; if (!Convert.ToBoolean(e.Cell.Value)) { for (int i = 0; i < ultraGrid1.Rows.Count; i++) { ultraGrid1.Rows[i].Cells["CHK"].Value = false; } coilNo = e.Cell.Row.Cells["OLD_SAMPL_NO"].Text; weight = e.Cell.Row.Cells["ACT_WGT"].Text; ordNo = e.Cell.Row.Cells["ORD_NO"].Text; ordSeq = e.Cell.Row.Cells["ORD_SEQ"].Text; ordThk = e.Cell.Row.Cells["INSTR_COIL_THK"].Text; ordWth = e.Cell.Row.Cells["INSTR_COIL_WTH"].Text; heatNo = e.Cell.Row.Cells["CHARGE_NO"].Text; steelCode = e.Cell.Row.Cells["SPEC_STL_GRD"].Text; standardNo = e.Cell.Row.Cells["SPEC_ABBSYM"].Text; millTime = e.Cell.Row.Cells["MILL_DTIME"].Text; custspecstl = e.Cell.Row.Cells["DDC_STL_GRD"].Text; } SetControlValue(coilNo, weight, ordNo, ordSeq, ordThk, ordWth, heatNo, steelCode, standardNo, millTime,custspecstl); e.Cell.Value = !Convert.ToBoolean(e.Cell.Value); } } catch (Exception ej) { System.Diagnostics.Debug.WriteLine(ej.ToString()); } } private void SetControlValue(string coilNo, string weight, string ordNo, string ordSeq, string ordThk, string ordWth, string heatNo, string steelCode, string standardNo, string millTime, string custspecstl) { textBox9.Text = coilNo; textBox10.Text = weight; textBox12.Text = millTime; textBox11.Text = ordNo; textBox7.Text = ordSeq; textBox15.Text = ordThk; textBox14.Text = ordWth; textBox5.Text = steelCode; textBox8.Text = standardNo; textBox13.Text = heatNo; textBox6.Text = custspecstl; } private void button1_Click(object sender, EventArgs e) { try { string directoryPath = "C:\\Temp\\ZBS\\"; int indexFlag = 0; foreach (UltraGridRow ugr in this.ultraGrid1.Rows) { if (Convert.ToBoolean(ugr.Cells["CHK"].Text) ) { indexFlag++; CoreClientParam ccp = new CoreClientParam(); ccp.ServerName = "UIB.UIB03.TestPrint"; ccp.MethodName = "print"; ccp.ServerParams = new object[] { "G00001" ,ugr.Cells["OLD_SAMPL_NO"].Text }; CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); byte[] byData = (byte[])cx.ReturnObject; System.DateTime dt = System.DateTime.Now; string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt); string sFile = directoryPath + "ABC" + ".xls"; FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write); fs.Write(byData, 0, byData.Length); fs.Close(); Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook workbook = app.Application.Workbooks.Add(sFile); Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)workbook.Worksheets[1]; ws.PrintOut(1, 1, 1, false, Missing.Value, false, false, Missing.Value);//"HP LaserJet P1505" workbook.Saved = true; workbook.Close(Missing.Value, Missing.Value, Missing.Value); app.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject(ws); System.Runtime.InteropServices.Marshal.ReleaseComObject(app); app = null; GC.Collect(); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void checkBoxORD_Click(object sender, EventArgs e) { try { this.textBox11.Enabled = this.checkBoxORD.Checked; this.textBox7.Enabled = this.checkBoxORD.Checked; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void checkBox3_Click(object sender, EventArgs e) { try { this.textBoxLicenseNo.Enabled = this.checkBox3.Checked; this.textBoxLicenseNo.Enabled = this.checkBox3.Checked; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void checkBox4_Click(object sender, EventArgs e) { try { this.textBoxlicenseMark.Enabled = this.checkBox4.Checked; this.textBoxlicenseMark.Enabled = this.checkBox4.Checked; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e) { if (this.ultraCheckEditor1.Checked) { this.ultraDateTimeEditor2.Enabled = false; this.ultraDateTimeEditor3.Enabled = false; //this.ultraCheckAll.Checked = false; } if (!this.ultraCheckEditor1.Checked) { this.ultraDateTimeEditor2.Enabled = true; this.ultraDateTimeEditor3.Enabled = true; } } } }