UIM020060.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.IO;
  10. using System.Windows.Forms;
  11. using CoreFS.CA06;
  12. using PrintSolution.LabelPrinter;
  13. using INI;
  14. using Infragistics.Win.UltraWinGrid;
  15. using System.Reflection;
  16. namespace Core.LZMes.Client.UIM.UIM02
  17. {
  18. public partial class UIM020060 : FrmBase
  19. {
  20. private ZebraPrinter printer = new ZebraPrinter();
  21. private Hashtable pkgHt = new Hashtable();
  22. private int hasPackaged = 0;
  23. public UIM020060()
  24. {
  25. InitializeComponent();
  26. }
  27. public override void ToolBar_Click(object sender, string ToolbarKey)
  28. {
  29. switch (ToolbarKey)
  30. {
  31. case "Query":
  32. this.DoQuery();
  33. break;
  34. case "Save":
  35. this.DoSave();
  36. break;
  37. case "Export":
  38. this.DoExport();
  39. break;
  40. case "Print":
  41. this.DoPrint();
  42. break;
  43. case "Exit":
  44. this.Close();
  45. break;
  46. }
  47. }
  48. /// <summary>
  49. /// 查询原料库库存数据
  50. /// </summary>
  51. private void DoQuery()
  52. {
  53. try
  54. {
  55. this.dataSet1.Tables[0].Clear();
  56. string ordNo = this.textBox1.Text.Trim();//
  57. string ordSeq = this.textBox2.Text.Trim();//
  58. string coilNo = this.textBox3.Text.Trim();//
  59. hasPackaged = int.Parse(this.ultraComboEditor2.Value.ToString());
  60. string diiver = this.textBox4.Text.Trim();
  61. string startTime = "";
  62. string endTime = "";
  63. if (this.ultraCheckEditor1.Checked)
  64. {
  65. startTime = "";
  66. startTime = "";
  67. }
  68. else
  69. {
  70. startTime = this.ultraDateTimeEditor3.Value != null ? ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd") : "";//开始时间
  71. endTime = this.ultraDateTimeEditor2.Value != null ? ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//结束时间
  72. }
  73. string prog = this.ultraComboEditor3.Value.ToString();
  74. CoreClientParam ccp = new CoreClientParam();
  75. ccp.ServerName = "UIM.UIM02.UIM020060";
  76. ccp.MethodName = "queryPkgCoil";
  77. ccp.ServerParams = new object[] { ordNo, ordSeq, coilNo, hasPackaged, diiver, startTime, endTime, prog };
  78. ccp.SourceDataTable = this.dataSet1.Tables[0];
  79. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  80. //打印标签后颜色区分 20130314
  81. DataRowCollection drs = dataSet1.Tables[0].Rows;
  82. string ord_pak, pak, ordfl;
  83. for (int i = 0; i < drs.Count; i++)
  84. {
  85. if (drs[i]["PRINT_TP"].ToString().Equals("Y"))
  86. {
  87. if (!drs[i]["ORG_ORD_NO"].ToString().Equals(drs[i]["ORD_NO"].ToString())
  88. &&!drs[i]["ORG_ORD_SEQ"].ToString().Equals(drs[i]["ORD_SEQ"].ToString()))
  89. ultraGrid1.Rows[i].Appearance.BackColor = Color.FromArgb(192, 255, 192);
  90. }
  91. //订单包装要求跟实际包装不一致变红色
  92. ord_pak = drs[i]["PAKMTH_TP"].ToString().Trim();
  93. pak = drs[i]["PACKAGE_LEVEL"].ToString().Trim();
  94. ordfl = drs[i]["ORD_FL"].ToString().Trim();
  95. if (ord_pak != pak && "订单材".Equals(ordfl)) {
  96. ultraGrid1.Rows[i].Appearance.BackColor = Color.SandyBrown;
  97. }
  98. }
  99. //打印标签后颜色区分 20130314
  100. }
  101. catch (Exception EX)
  102. {
  103. MessageBox.Show(EX.ToString());
  104. }
  105. }
  106. private void DoSave()
  107. {
  108. ultraGrid1.Update();
  109. if (this.ultraDateTimeEditor1.Value == null)
  110. {
  111. MessageBox.Show("请选择包装日期!");
  112. this.ultraDateTimeEditor1.Focus();
  113. return;
  114. }
  115. ArrayList list = new ArrayList();
  116. ArrayList coilLables = new ArrayList();
  117. Infragistics.Win.UltraWinGrid.RowsCollection rs = this.ultraGrid1.Rows;
  118. for (int i = 0; i < rs.Count; i++)
  119. {
  120. if ("TRUE".Equals(rs[i].Cells["CHK"].Text.ToUpperInvariant()))
  121. {
  122. string packageLevel = rs[i].Cells["PACKAGE_LEVEL"].Text;
  123. if (packageLevel.Equals(""))
  124. {
  125. MessageBox.Show("第" + (i + 1) + "行包装等级为空,请核对后再点击保存!");
  126. return;
  127. }
  128. string[] packageArray = new string[2];
  129. packageArray[0] = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString();
  130. packageArray[1] = pkgHt[rs[i].Cells["PACKAGE_LEVEL"].Text].ToString();
  131. list.Add(packageArray);
  132. //ColdCoilLable coilLabel = new ColdCoilLable();
  133. //coilLabel.rollNo = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString().Substring(0,9);
  134. //coilLabel.specification = rs[i].Cells["SPEC_ABBSYM"].Value.ToString();
  135. //coilLabel.steelGrade = rs[i].Cells["SPEC_STL_GRD"].Value.ToString();
  136. //coilLabel.dimension = rs[i].Cells["PRINT_SIZE"].Value.ToString();
  137. //coilLabel.coilNo = rs[i].Cells["OLD_SAMPL_NO"].Value.ToString();
  138. //coilLabel.weight = rs[i].Cells["ACT_WGT"].Value.ToString();
  139. //coilLabel.heatNo = rs[i].Cells["CHARGE_NO"].Value.ToString();
  140. //coilLabel.prodDate = rs[i].Cells["MILL_DTIME"].Value.ToString();
  141. //coilLabel.contractNo = rs[i].Cells["ORD_NO"].Value.ToString() + "-" + rs[i].Cells["ORD_SEQ"].Value.ToString();
  142. //coilLabel.licenseNo = string.Empty;
  143. //coilLabel.licenseMark = string.Empty;
  144. //coilLabel.checker = string.Empty;
  145. //coilLabel.barcode = coilLabel.coilNo;
  146. //coilLables.Add(coilLabel);
  147. }
  148. }
  149. string pkgReg = this.UserInfo.GetUserID();
  150. string pkgShift = this.UserInfo.GetUserOrder();
  151. string pkgGroup = this.UserInfo.GetUserGroup();
  152. string pkgDtime = this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd");
  153. if (list.Count > 0)
  154. {
  155. CoreClientParam ccp = new CoreClientParam();
  156. ccp.ServerName = "UIM.UIM02.UIM020060";
  157. ccp.MethodName = "savePkgCoil";
  158. ccp.ServerParams = new object[] { list, pkgShift, pkgGroup, pkgReg, pkgDtime, hasPackaged };
  159. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  160. //if (hasPackaged == 0)
  161. //{
  162. //print
  163. //PrintLabel(coilLables);
  164. //PrintLabel(coilLables);
  165. //}
  166. this.DoQuery();
  167. }
  168. }
  169. private void DoExport()
  170. {
  171. try
  172. {
  173. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  174. {
  175. string fileName = this.saveFileDialog1.FileName;
  176. ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  177. System.Diagnostics.Process.Start(fileName);
  178. }
  179. }
  180. catch (Exception EX)
  181. {
  182. MessageBox.Show(EX.ToString());
  183. }
  184. }
  185. private void DoPrint()
  186. {
  187. ultraGrid1.UpdateData();
  188. //**************************
  189. Hashtable param = new Hashtable();
  190. string line = string.Empty;
  191. ArrayList coilLables = new ArrayList();
  192. Infragistics.Win.UltraWinGrid.RowsCollection rs = this.ultraGrid1.Rows;
  193. for (int i = 0; i < rs.Count; i++)
  194. {
  195. if (Convert.ToBoolean(rs[i].Cells["CHK"].Value))
  196. {
  197. ColdCoilLable coilLabel = new ColdCoilLable();
  198. //coilLabel.rollNo = textBox9.Text.Trim().Substring(0, 9);//批号
  199. //coilLabel.specification = textBox8.Text.Trim();//标准号
  200. //coilLabel.steelGrade = textBox5.Text.Trim();//牌号
  201. //coilLabel.dimension = textBox15.Text.Trim() + "*" + textBox14.Text.Trim();//厚度、宽度
  202. //coilLabel.heatNo = textBox13.Text.Trim();//炉号
  203. coilLabel.rollNo = string.Empty; //批号
  204. coilLabel.specification = string.Empty; //标准号
  205. coilLabel.steelGrade = string.Empty; //牌号
  206. coilLabel.dimension = string.Empty; //厚度、宽度
  207. coilLabel.heatNo = string.Empty;//炉号
  208. coilLabel.coilNo = textBox9.Text.Trim();//卷号
  209. coilLabel.weight = textBox10.Text.Trim();//重量
  210. string millTime = textBox12.Text.Trim();//生产时间
  211. if (millTime != null && millTime != "")
  212. {
  213. coilLabel.prodDate = millTime.Replace(" ", "");//生产日期
  214. }
  215. else
  216. {
  217. coilLabel.prodDate = string.Empty;
  218. }
  219. if (checkBoxORD.Checked)//合同号
  220. {
  221. coilLabel.contractNo = textBox11.Text.Trim() + "-" + textBox7.Text.Trim();//合同号,订单号
  222. }
  223. else
  224. {
  225. coilLabel.contractNo = string.Empty;
  226. }
  227. if (this.checkBox3.Checked)//许可证号
  228. {
  229. coilLabel.licenseNo = this.textBoxLicenseNo.Text.Trim();
  230. }
  231. else
  232. {
  233. coilLabel.licenseNo = string.Empty;
  234. }
  235. if (this.checkBox4.Checked)//许可证标识
  236. {
  237. coilLabel.licenseMark = textBoxlicenseMark.Text;//string.Empty;
  238. }
  239. else
  240. {
  241. coilLabel.licenseMark = string.Empty;
  242. }
  243. coilLabel.checker = string.Empty;
  244. coilLabel.barcode = coilLabel.coilNo;
  245. coilLables.Add(coilLabel);
  246. line = rs[i].Cells["LINE_TP"].Text.ToString();
  247. }
  248. }
  249. //print
  250. try
  251. {
  252. PrintLabel(coilLables);
  253. PrintLabel(coilLables);
  254. PrintLabel(coilLables);//一次打印三张 20151231 WL
  255. PrintLabel(coilLables);//一次打印4张 20160805 WL
  256. //20130314添加标签打印标识
  257. string coilNo1 = this.textBox9.Text.Trim();
  258. CoreClientParam ccp = new CoreClientParam();
  259. ccp.ServerName = "UIM.UIM02.UIM020060";
  260. ccp.MethodName = "updateColor";
  261. ccp.ServerParams = new object[] { coilNo1 };
  262. ccp.SourceDataTable = this.dataSet1.Tables[0];
  263. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  264. //20140304
  265. param.Add("i1", line);
  266. param.Add("i2", coilNo1);
  267. param.Add("i3", this.UserInfo.GetUserID());
  268. param.Add("i4", "标签打印");
  269. param.Add("i5", "UIM020060");
  270. param.Add("i6", "打印后");
  271. param.Add("o7", "");
  272. CoreClientParam ccp4 = new CoreClientParam();
  273. ccp4.ServerName = "UIB.COM.ComDBProcedure";
  274. ccp4.MethodName = "doXmlProcedure";
  275. ccp4.ServerParams = new Object[] { "UIL010020_02_CALL.CALL", param };
  276. this.ExecuteNonQuery(ccp4, CoreInvokeType.Internal);
  277. //提示
  278. ArrayList all = ccp4.ReturnObject as ArrayList;
  279. if (all[0].ToString() != "YY")//确认是否存在问题
  280. {
  281. MessageBox.Show(all[0].ToString(), "提示");
  282. return;
  283. }
  284. DoQuery();
  285. }
  286. catch (Exception ex)
  287. {
  288. MessageBox.Show("连接打印机失败,请点击\"打印\"按钮重新打印!");
  289. }
  290. }
  291. private void PrintLabel(ArrayList list)
  292. {
  293. foreach (ColdCoilLable coilLabel in list)
  294. {
  295. printer.printLable(coilLabel);
  296. }
  297. }
  298. private void UIM020060_Load(object sender, EventArgs e)
  299. {
  300. try {
  301. string Current = Directory.GetCurrentDirectory();//获取当前根目录
  302. Ini ini = new Ini(Current + "/CoreFS.ini");
  303. // 读取ini
  304. string labPrinterAddr = ini.ReadValue("LABPRINTERADDR", "4");
  305. printer.Addr = labPrinterAddr;
  306. /*string labPrinterAddr = "10.10.76.140";
  307. printer.Addr = labPrinterAddr;*/
  308. //string version = ini.ReadValue("LABPRINTERADDR", "Version");
  309. string version = "4";
  310. printer.LableVersion = int.Parse(version);
  311. CoreClientParam ccp = new CoreClientParam();
  312. ccp.ServerName = "UIM.UIM02.UIM020060";
  313. ccp.MethodName = "queryPkgType";
  314. ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
  315. ArrayList list = (ArrayList)ccp.ReturnObject;
  316. if (list != null)
  317. {
  318. this.ultraGrid1.DisplayLayout.ValueLists.Add("List1");
  319. int listSize = list.Count;
  320. for (int i = 0; i < listSize; i++)
  321. {
  322. Infragistics.Win.ValueListItem item = new Infragistics.Win.ValueListItem();
  323. Hashtable ht = (Hashtable)list[i];
  324. string smCd = ht["SM_CD"].ToString();
  325. string cmCfnm = "";
  326. object obj = ht["SM_CFNM"];
  327. if (obj != null)
  328. {
  329. cmCfnm = ht["SM_CFNM"].ToString();
  330. }
  331. pkgHt.Add(cmCfnm, smCd);
  332. this.ultraGrid1.DisplayLayout.ValueLists["List1"].ValueListItems.Add(smCd, cmCfnm);
  333. }
  334. this.ultraGrid1.DisplayLayout.ValueLists["List1"].DisplayStyle = Infragistics.Win.ValueListDisplayStyle.DisplayText;
  335. this.ultraGrid1.DisplayLayout.Bands[0].Columns["PACKAGE_LEVEL"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
  336. this.ultraGrid1.DisplayLayout.Bands[0].Columns["PACKAGE_LEVEL"].ValueList = this.ultraGrid1.DisplayLayout.ValueLists["List1"];
  337. this.ultraComboEditor2.SelectedIndex = 0;
  338. this.ultraComboEditor3.SelectedIndex = 0;
  339. }
  340. }
  341. catch (Exception ej)
  342. { System.Diagnostics.Debug.WriteLine(ej.ToString()); }
  343. }
  344. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  345. {
  346. try
  347. {
  348. if (e.Cell.Column.Key == "CHK")
  349. {
  350. string coilNo = string.Empty;
  351. string weight = string.Empty;
  352. string ordNo = string.Empty;
  353. string ordSeq = string.Empty;
  354. string ordThk = string.Empty;
  355. string ordWth = string.Empty;
  356. string heatNo = string.Empty;
  357. string steelCode = string.Empty;
  358. string standardNo = string.Empty;
  359. string millTime = string.Empty;
  360. string custspecstl = string.Empty;
  361. if (!Convert.ToBoolean(e.Cell.Value))
  362. {
  363. for (int i = 0; i < ultraGrid1.Rows.Count; i++)
  364. {
  365. ultraGrid1.Rows[i].Cells["CHK"].Value = false;
  366. }
  367. coilNo = e.Cell.Row.Cells["OLD_SAMPL_NO"].Text;
  368. weight = e.Cell.Row.Cells["ACT_WGT"].Text;
  369. ordNo = e.Cell.Row.Cells["ORD_NO"].Text;
  370. ordSeq = e.Cell.Row.Cells["ORD_SEQ"].Text;
  371. ordThk = e.Cell.Row.Cells["INSTR_COIL_THK"].Text;
  372. ordWth = e.Cell.Row.Cells["INSTR_COIL_WTH"].Text;
  373. heatNo = e.Cell.Row.Cells["CHARGE_NO"].Text;
  374. steelCode = e.Cell.Row.Cells["SPEC_STL_GRD"].Text;
  375. standardNo = e.Cell.Row.Cells["SPEC_ABBSYM"].Text;
  376. millTime = e.Cell.Row.Cells["MILL_DTIME"].Text;
  377. custspecstl = e.Cell.Row.Cells["DDC_STL_GRD"].Text;
  378. }
  379. SetControlValue(coilNo, weight, ordNo, ordSeq, ordThk, ordWth, heatNo, steelCode, standardNo, millTime,custspecstl);
  380. e.Cell.Value = !Convert.ToBoolean(e.Cell.Value);
  381. }
  382. }
  383. catch (Exception ej)
  384. { System.Diagnostics.Debug.WriteLine(ej.ToString()); }
  385. }
  386. 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)
  387. {
  388. textBox9.Text = coilNo;
  389. textBox10.Text = weight;
  390. textBox12.Text = millTime;
  391. textBox11.Text = ordNo;
  392. textBox7.Text = ordSeq;
  393. textBox15.Text = ordThk;
  394. textBox14.Text = ordWth;
  395. textBox5.Text = steelCode;
  396. textBox8.Text = standardNo;
  397. textBox13.Text = heatNo;
  398. textBox6.Text = custspecstl;
  399. }
  400. private void button1_Click(object sender, EventArgs e)
  401. {
  402. try
  403. {
  404. string directoryPath = "C:\\Temp\\ZBS\\";
  405. int indexFlag = 0;
  406. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  407. {
  408. if (Convert.ToBoolean(ugr.Cells["CHK"].Text) )
  409. {
  410. indexFlag++;
  411. CoreClientParam ccp = new CoreClientParam();
  412. ccp.ServerName = "UIB.UIB03.TestPrint";
  413. ccp.MethodName = "print";
  414. ccp.ServerParams = new object[] { "G00001"
  415. ,ugr.Cells["OLD_SAMPL_NO"].Text
  416. };
  417. CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  418. byte[] byData = (byte[])cx.ReturnObject;
  419. System.DateTime dt = System.DateTime.Now;
  420. string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
  421. string sFile = directoryPath + "ABC" + ".xls";
  422. FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
  423. fs.Write(byData, 0, byData.Length);
  424. fs.Close();
  425. Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
  426. Microsoft.Office.Interop.Excel.Workbook workbook = app.Application.Workbooks.Add(sFile);
  427. Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)workbook.Worksheets[1];
  428. ws.PrintOut(1, 1, 1, false, Missing.Value, false, false, Missing.Value);//"HP LaserJet P1505"
  429. workbook.Saved = true;
  430. workbook.Close(Missing.Value, Missing.Value, Missing.Value);
  431. app.Quit();
  432. System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
  433. System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
  434. app = null;
  435. GC.Collect();
  436. }
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. System.Diagnostics.Debug.WriteLine(ex.ToString());
  442. }
  443. }
  444. private void checkBoxORD_Click(object sender, EventArgs e)
  445. {
  446. try
  447. {
  448. this.textBox11.Enabled = this.checkBoxORD.Checked;
  449. this.textBox7.Enabled = this.checkBoxORD.Checked;
  450. }
  451. catch (Exception ex)
  452. {
  453. System.Diagnostics.Debug.WriteLine(ex.ToString());
  454. }
  455. }
  456. private void checkBox3_Click(object sender, EventArgs e)
  457. {
  458. try
  459. {
  460. this.textBoxLicenseNo.Enabled = this.checkBox3.Checked;
  461. this.textBoxLicenseNo.Enabled = this.checkBox3.Checked;
  462. }
  463. catch (Exception ex)
  464. {
  465. System.Diagnostics.Debug.WriteLine(ex.ToString());
  466. }
  467. }
  468. private void checkBox4_Click(object sender, EventArgs e)
  469. {
  470. try
  471. {
  472. this.textBoxlicenseMark.Enabled = this.checkBox4.Checked;
  473. this.textBoxlicenseMark.Enabled = this.checkBox4.Checked;
  474. }
  475. catch (Exception ex)
  476. {
  477. System.Diagnostics.Debug.WriteLine(ex.ToString());
  478. }
  479. }
  480. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  481. {
  482. if (this.ultraCheckEditor1.Checked)
  483. {
  484. this.ultraDateTimeEditor2.Enabled = false;
  485. this.ultraDateTimeEditor3.Enabled = false;
  486. //this.ultraCheckAll.Checked = false;
  487. }
  488. if (!this.ultraCheckEditor1.Checked)
  489. {
  490. this.ultraDateTimeEditor2.Enabled = true;
  491. this.ultraDateTimeEditor3.Enabled = true;
  492. }
  493. }
  494. }
  495. }