UIL010020.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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.UIL.UIL01
  17. {
  18. public partial class UIL010020 : FrmBase
  19. {
  20. private ZebraPrinter printer = new ZebraPrinter();
  21. public UIL010020()
  22. {
  23. InitializeComponent();
  24. }
  25. public override void ToolBar_Click(object sender, string ToolbarKey)
  26. {
  27. switch (ToolbarKey)
  28. {
  29. case "Query":
  30. this.DoQuery();
  31. break;
  32. case "Export":
  33. this.DoExport();
  34. break;
  35. case "Print":
  36. this.DoPrint();
  37. break;
  38. case "Save":
  39. this.DoSave();
  40. break;
  41. case "Exit":
  42. this.Close();
  43. break;
  44. }
  45. }
  46. /// <summary>
  47. /// 查询原料库库存数据
  48. /// </summary>
  49. private void DoQuery()
  50. {
  51. try
  52. {
  53. switch (CustomInfo)
  54. {
  55. case "1":
  56. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CHK_Y"].Hidden = true;
  57. break;
  58. case "2":
  59. break;
  60. case "3":
  61. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CHK_Y"].Hidden = true;
  62. break;
  63. }
  64. this.dataSet1.Tables[0].Clear();
  65. string startTime = this.ultraDateTimeEditor1.Value != null ? this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd") : "";//生产开始时间
  66. string endTime = this.ultraDateTimeEditor2.Value != null ? this.ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//生产结束时间
  67. string coilWthMin = this.textBox4.Text;//宽度最小值
  68. string coilWthMax = this.textBox5.Text;//宽度最大值
  69. string coilThkMin = this.textBox6.Text;//厚度最小值
  70. string coilThkMax = this.textBox7.Text;//厚度最大值
  71. string coilNo = this.textBox9.Text;//钢卷号
  72. string ordNo = this.textBox11.Text;//合同号
  73. string ordSeq = this.textBox3.Text;//订单号
  74. ArrayList list = new ArrayList();
  75. list.Add(startTime);
  76. list.Add(endTime);
  77. list.Add(coilThkMin);
  78. list.Add(coilThkMax);
  79. list.Add(coilWthMin);
  80. list.Add(coilWthMax);
  81. list.Add(ordNo);
  82. list.Add(ordSeq);
  83. list.Add(coilNo);
  84. list.Add(CustomInfo);
  85. CoreClientParam ccp = new CoreClientParam();
  86. ccp.ServerName = "UIL.UIL01.UIL010020";
  87. ccp.MethodName = "queryCoilList";
  88. ccp.ServerParams = new object[] { list };
  89. ccp.SourceDataTable = this.dataSet1.Tables[0];
  90. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  91. //打印标签后颜色区分 20131017
  92. //DataRowCollection drs = dataSet1.Tables[0].Rows; 存在漏洞不是每行都能选中!!!!!!
  93. Infragistics.Win.UltraWinGrid.RowsCollection drs = this.ultraGrid1.Rows;
  94. for (int i = 0; i < drs.Count; i++)
  95. {
  96. if (drs[i].Cells["PRINT_TP"].Value.ToString().Trim().Equals("Y".ToString()))
  97. {
  98. ultraGrid1.Rows[i].Appearance.BackColor = Color.FromArgb(192, 255, 192);
  99. }
  100. }
  101. //打印标签后颜色区分 20131017
  102. }
  103. catch (Exception EX)
  104. {
  105. MessageBox.Show(EX.ToString());
  106. }
  107. }
  108. private void DoSave() {
  109. try {
  110. string coilNo = string.Empty;
  111. string prog = string.Empty;
  112. switch (CustomInfo)
  113. {
  114. case "2":
  115. Hashtable paramHsmp = new Hashtable();
  116. this.ultraGrid1.UpdateData();
  117. string regID = this.UserInfo.GetUserID();
  118. if (regID == "")
  119. {
  120. System.Windows.Forms.MessageBox.Show("!");
  121. return;
  122. }
  123. Infragistics.Win.UltraWinGrid.RowsCollection rs = this.ultraGrid1.Rows;
  124. if (rs.Count > 0)
  125. {
  126. for (int i = 0; i < rs.Count; i++)
  127. {
  128. if (rs[i].Cells["CHK_Y"].Text.Trim() == "FALSE")
  129. {
  130. continue;
  131. }
  132. //else if (rs[i].Cells["CUR_PROG_CD"].Text.Trim() != "")
  133. //{
  134. // continue;
  135. //}
  136. else
  137. {
  138. paramHsmp = new Hashtable();
  139. coilNo = rs[i].Cells["COIL_NO"].Text.Trim();
  140. if (rs[i].Cells["CUR_PROG_CD"].Text.Trim().Equals("综合判定待机")) {
  141. prog="DED";
  142. }
  143. else if (rs[i].Cells["CUR_PROG_CD"].Text.Trim().Equals("重卷指示待机"))
  144. {
  145. prog = "DBA";
  146. }
  147. paramHsmp.Add("i1", coilNo);
  148. paramHsmp.Add("i2", prog);
  149. paramHsmp.Add("i3", regID);
  150. paramHsmp.Add("o4", "");
  151. CoreClientParam ccp = new CoreClientParam();
  152. ccp.ServerName = "UIB.COM.ComDBProcedure";
  153. ccp.MethodName = "doXmlProcedure";
  154. ccp.ServerParams = new Object[] { "UIL010020_01_CALL.CALL", paramHsmp };
  155. this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  156. //提示
  157. ArrayList all = ccp.ReturnObject as ArrayList;
  158. if (all[0].ToString() != "YY")//确认是否存在问题
  159. {
  160. MessageBox.Show(all[0].ToString(), "提示");
  161. return;
  162. }
  163. }
  164. }
  165. }
  166. this.DoQuery();
  167. break;
  168. }
  169. }
  170. catch (Exception Ey)
  171. {
  172. MessageBox.Show(Ey.ToString());
  173. }
  174. }
  175. private void DoExport()
  176. {
  177. try
  178. {
  179. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  180. {
  181. string fileName = this.saveFileDialog1.FileName;
  182. ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  183. System.Diagnostics.Process.Start(fileName);
  184. }
  185. }
  186. catch (Exception EX)
  187. {
  188. MessageBox.Show(EX.ToString());
  189. }
  190. }
  191. private void DoPrint()
  192. {
  193. try
  194. {
  195. ultraGrid1.UpdateData();
  196. //----20131018
  197. Hashtable param= new Hashtable();
  198. string line = string.Empty;
  199. string printid = this.UserInfo.GetUserID();
  200. string flag = string.Empty;
  201. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ultraGrid1.Rows)
  202. {
  203. if (Convert.ToBoolean(row.Cells["CHK"].Value))
  204. {
  205. //----20131018
  206. param = new Hashtable();
  207. ColdCoilLable coilLabel = new ColdCoilLable();
  208. coilLabel.rollNo = string.Empty;
  209. coilLabel.specification = row.Cells["SPEC_ABBSYM"].Value.ToString();
  210. coilLabel.steelGrade = string.Empty;
  211. //if(Convert.ToBoolean(row.Cells["CHK_SIZE"].Value)){
  212. //coilLabel.dimension = row.Cells["COIL_SIZE"].Value.ToString();
  213. //}else{
  214. //coilLabel.dimension = row.Cells["ORD_SIZE"].Value.ToString();
  215. //}
  216. coilLabel.dimension = string.Empty;
  217. coilLabel.coilNo = row.Cells["COIL_NO"].Value.ToString();
  218. coilLabel.weight = row.Cells["ACT_WGT"].Value.ToString();
  219. coilLabel.heatNo = row.Cells["HEAT_NO"].Value.ToString();
  220. coilLabel.prodDate = row.Cells["MILL_DTIME"].Value.ToString();
  221. coilLabel.contractNo = string.Empty;
  222. coilLabel.licenseNo = string.Empty;
  223. coilLabel.licenseMark = string.Empty;
  224. coilLabel.checker = string.Empty;
  225. coilLabel.barcode = coilLabel.coilNo;
  226. if (row.Cells["PRINT_TP"].Text=="Y")
  227. {
  228. if (MessageBox.Show( row.Cells["COIL_NO"].Value.ToString()+"已打印,需要再次打印?",
  229. "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
  230. {
  231. switch (CustomInfo)
  232. {
  233. case "1":
  234. if (Convert.ToBoolean(row.Cells["CHK_SIZE"].Value))
  235. {
  236. coilLabel.dimension = row.Cells["COIL_SIZE"].Value.ToString();
  237. }
  238. else
  239. {
  240. coilLabel.dimension = row.Cells["ORD_SIZE"].Value.ToString();
  241. }
  242. coilLabel.steelGrade = row.Cells["SPEC_STL_GRD"].Value.ToString();
  243. //coilLabel.contractNo = row.Cells["ORD_NO"].Value.ToString() + "-" + row.Cells["ORD_SEQ"].Value.ToString();
  244. // coilLabel.contractNo = string.Empty;
  245. line = "S";
  246. flag = "A";
  247. break;
  248. case "2":
  249. //printer.printLable(coilLabel);
  250. line = "L";
  251. flag = "B";
  252. break;
  253. case "3":
  254. //coilLabel.dimension = string.Empty;
  255. line = "C";
  256. flag = "D";
  257. break;
  258. }
  259. string coilno = row.Cells["COIL_NO"].Value.ToString();
  260. printer.printLable(coilLabel);
  261. UpdateColor(coilno,flag);
  262. //----20131018
  263. param.Add("i1", line);
  264. param.Add("i2", coilno);
  265. param.Add("i3", printid);
  266. param.Add("i4", "标签打印");
  267. param.Add("i5", "UIL010020");
  268. param.Add("i6", "打印后");
  269. param.Add("o7", "");
  270. PrintHistory(param);
  271. }
  272. }
  273. else if (row.Cells["PRINT_TP"].Text == "N")
  274. {
  275. switch (CustomInfo)
  276. {
  277. case "1":
  278. if (Convert.ToBoolean(row.Cells["CHK_SIZE"].Value))
  279. {
  280. coilLabel.dimension = row.Cells["COIL_SIZE"].Value.ToString();
  281. }
  282. else
  283. {
  284. coilLabel.dimension = row.Cells["ORD_SIZE"].Value.ToString();
  285. }
  286. coilLabel.steelGrade = row.Cells["SPEC_STL_GRD"].Value.ToString();
  287. //coilLabel.contractNo = row.Cells["ORD_NO"].Value.ToString() + "-" + row.Cells["ORD_SEQ"].Value.ToString();
  288. //coilLabel.contractNo = string.Empty;
  289. line = "S";
  290. flag = "A";
  291. break;
  292. case "2":
  293. //printer.printLable(coilLabel);
  294. line = "L";
  295. flag = "B";
  296. break;
  297. case "3":
  298. // coilLabel.dimension = string.Empty;
  299. line = "C";
  300. flag = "D";
  301. break;
  302. }
  303. string coilno = row.Cells["COIL_NO"].Value.ToString();
  304. printer.printLable(coilLabel);
  305. UpdateColor(coilno, flag);
  306. //----20131018
  307. param.Add("i1", line);
  308. param.Add("i2", coilno);
  309. param.Add("i3", printid);
  310. param.Add("i4", "标签打印");
  311. param.Add("i5", "UIL010020");
  312. param.Add("i6", "打印后");
  313. param.Add("o7", "");
  314. PrintHistory(param);
  315. }
  316. }
  317. }
  318. this.DoQuery();
  319. }
  320. catch (Exception EX)
  321. {
  322. MessageBox.Show("打印异常:连接打印机失败,请点击\"打印\"按钮重新打印!");
  323. }
  324. }
  325. private void UpdateColor(string coilno,string flag) {
  326. CoreClientParam ccp1 = new CoreClientParam();
  327. ccp1.ServerName = "UIL.UIL01.UIL010020";
  328. ccp1.MethodName = "dateColor";
  329. ccp1.ServerParams = new object[] { coilno ,flag};
  330. ccp1.SourceDataTable = this.dataSet1.Tables[0];
  331. this.ExecuteQueryToDataTable(ccp1, CoreInvokeType.Internal);
  332. }
  333. //标签打印记录增加
  334. private void PrintHistory(Hashtable param)
  335. {
  336. CoreClientParam ccp4 = new CoreClientParam();
  337. ccp4.ServerName = "UIB.COM.ComDBProcedure";
  338. ccp4.MethodName = "doXmlProcedure";
  339. ccp4.ServerParams = new Object[] { "UIL010020_02_CALL.CALL", param };
  340. this.ExecuteNonQuery(ccp4, CoreInvokeType.Internal);
  341. //提示
  342. ArrayList all = ccp4.ReturnObject as ArrayList;
  343. if (all[0].ToString() != "YY")//确认是否存在问题
  344. {
  345. MessageBox.Show(all[0].ToString(), "提示");
  346. return;
  347. }
  348. }
  349. private void UIL010020_Load(object sender, EventArgs e)
  350. {
  351. try
  352. {
  353. string Current = Directory.GetCurrentDirectory();//获取当前根目录
  354. Ini ini = new Ini(Current + "/CoreFS.ini");
  355. // 读取ini
  356. string labPrinterAddr = ini.ReadValue("LABPRINTERADDR", CustomInfo);
  357. printer.Addr = labPrinterAddr;
  358. string version = ini.ReadValue("LABPRINTERADDR", "Version");
  359. printer.LableVersion = int.Parse(version);
  360. //MessageBox.Show(labPrinterAddr);
  361. }
  362. catch (Exception ej) {
  363. System.Diagnostics.Debug.WriteLine(ej.ToString());
  364. }
  365. }
  366. private void ultraButton1_Click(object sender, EventArgs e)
  367. {
  368. try
  369. {
  370. string directoryPath = "C:\\Temp\\ZBS\\";
  371. int indexFlag = 0;
  372. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  373. {
  374. if (Convert.ToBoolean(ugr.Cells["CHK"].Text))
  375. {
  376. indexFlag++;
  377. CoreClientParam ccp = new CoreClientParam();
  378. ccp.ServerName = "UIB.UIB03.TestPrint";
  379. ccp.MethodName = "print";
  380. ccp.ServerParams = new object[] { "G00001", ugr.Cells["COIL_NO"].Text };
  381. CoreClientParam cx = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  382. byte[] byData = (byte[])cx.ReturnObject;
  383. System.DateTime dt = System.DateTime.Now;
  384. string TimeNow = string.Format("{0:yyyyMMddHHmmssffff}", dt);
  385. string sFile = directoryPath + "ABC" + ".xls";
  386. FileStream fs = new FileStream(sFile, FileMode.OpenOrCreate, FileAccess.Write);
  387. fs.Write(byData, 0, byData.Length);
  388. fs.Close();
  389. Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
  390. Microsoft.Office.Interop.Excel.Workbook workbook = app.Application.Workbooks.Add(sFile);
  391. Microsoft.Office.Interop.Excel._Worksheet ws = (Microsoft.Office.Interop.Excel._Worksheet)workbook.Worksheets[1];
  392. ws.PrintOut(1, 1, 1, false, Missing.Value, false, false, Missing.Value);//"HP LaserJet P1505"
  393. workbook.Saved = true;
  394. workbook.Close(Missing.Value, Missing.Value, Missing.Value);
  395. app.Quit();
  396. System.Runtime.InteropServices.Marshal.ReleaseComObject(ws);
  397. System.Runtime.InteropServices.Marshal.ReleaseComObject(app);
  398. app = null;
  399. GC.Collect();
  400. }
  401. }
  402. }
  403. catch (Exception ex)
  404. {
  405. System.Diagnostics.Debug.WriteLine(ex.ToString());
  406. }
  407. }
  408. //酸轧标签打印第三个版本,纸张纵向,数据横向
  409. private void ultraButton_print3_Click(object sender, EventArgs e)
  410. {
  411. printer.LableVersion = 3;
  412. DoPrint();
  413. }
  414. }
  415. }