1c37e04e183e831d4658151982faa9aabbb5ef9a.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using CoreFS.CA06;
  10. using System.Collections;
  11. using System.Reflection;
  12. using Excel1 = Microsoft.Office.Interop.Excel;
  13. using Infragistics.Win.UltraWinGrid;
  14. using System.Runtime.InteropServices;
  15. namespace Core.LZMes.Client.UIK
  16. {
  17. public partial class StorageStandby : FrmBase
  18. {
  19. //记录前一次入库垛位
  20. internal string before_yard = "1-01A-01";
  21. public StorageStandby()
  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. }
  36. }
  37. private void DoQuery()
  38. {
  39. try
  40. {
  41. string starttiem = this.ultraCalendarSTRATTIME.Text.ToString();
  42. string endtime = this.ultraCalendarENDTIME.Text.ToString();
  43. // string starttiem = this.ultraDateTimeEditor1.Value != null ? this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd") : "";//出库时间
  44. // string endtime = this.ultraDateTimeEditor1.Value != null ? this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd") : "";//出库时间
  45. bool flag = false;
  46. if (this.ultraCheckEditor2.Checked == true)
  47. {
  48. flag = true;
  49. this.dataSet1.Tables[0].Clear();
  50. starttiem = this.ultraDateTimeEditor2.Value != null ? this.ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//出库时间
  51. endtime = this.ultraDateTimeEditor3.Value != null ? this.ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd") : "";//出库时间
  52. CoreClientParam ccp = new CoreClientParam();
  53. ccp.ServerName = "UIB.COM.ComDBQuery";
  54. ccp.MethodName = "doSimpleQuery";
  55. ArrayList paramArray = new ArrayList();
  56. paramArray.Add("UIK050010_04.SELECT");
  57. paramArray.Add(starttiem);
  58. paramArray.Add(endtime);
  59. ccp.ServerParams = new object[] { paramArray };
  60. ccp.SourceDataTable = this.dataSet1.Tables[0];
  61. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  62. System.Diagnostics.Debug.WriteLine(this.dataSet1.Tables[0].ToString());
  63. }
  64. else
  65. {
  66. if (this.ultraCheckEditor1.Checked == true)
  67. {
  68. this.dataSet1.Tables[0].Clear();
  69. CoreClientParam ccp = new CoreClientParam();
  70. ccp.ServerName = "UIK.UIK05.StorageStandby";
  71. ccp.MethodName = "Query_Coil_State";
  72. ccp.ServerParams = new object[] { starttiem, endtime, flag };
  73. ccp.SourceDataTable = this.dataSet1.Tables[0];
  74. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  75. //设置生产规范标准不合格行的颜色
  76. Color color = Color.FromArgb(255, 255, 255);
  77. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid1.Rows)
  78. {
  79. string status = ugr.Cells["TECH_DCS_CD"].Text;
  80. //string fm_avg = ugr.Cells["FM_EXT_STRIP_TEMP_AVG"].Text;
  81. //if (null == fm_avg || fm_avg.Equals(""))
  82. //{
  83. // ugr.Cells["FM_EXT_STRIP_TEMP_AVG"].Value = "0";
  84. //}
  85. //string dc_avg = ugr.Cells["DC_TEMP_AVG"].Text;
  86. //if (null == dc_avg || dc_avg.Equals(""))
  87. //{
  88. // ugr.Cells["DC_TEMP_AVG"].Value = "0";
  89. //}
  90. if (null != status && "不合格".Equals(status))
  91. {
  92. color = Color.FromArgb(255, 128, 128);
  93. }
  94. else
  95. {
  96. color = Color.FromArgb(255, 255, 255);
  97. }
  98. ugr.Appearance.BackColor = color;
  99. }
  100. DataRowCollection drs1 = dataSet1.Tables[0].Rows;
  101. if (drs1.Count <= 0)
  102. {
  103. MessageBox.Show("该时间内没有入库待机钢卷");
  104. }
  105. }
  106. else
  107. {
  108. flag = true;
  109. this.dataSet1.Tables[0].Clear();
  110. CoreClientParam ccp2 = new CoreClientParam();
  111. ccp2.ServerName = "UIK.UIK05.StorageStandby";
  112. ccp2.MethodName = "Query_Coil_State";
  113. ccp2.ServerParams = new object[] { starttiem, endtime, flag };
  114. ccp2.SourceDataTable = this.dataSet1.Tables[0];
  115. this.ExecuteQueryToDataTable(ccp2, CoreInvokeType.Internal);
  116. //设置生产规范标准不合格行的颜色
  117. Color color = Color.FromArgb(255, 255, 255);
  118. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid1.Rows)
  119. {
  120. string status = ugr.Cells["TECH_DCS_CD"].Text;
  121. if (null != status && "不合格".Equals(status))
  122. {
  123. color = Color.FromArgb(255, 128, 128);
  124. }
  125. else
  126. {
  127. color = Color.FromArgb(255, 255, 255);
  128. }
  129. ugr.Appearance.BackColor = color;
  130. }
  131. DataRowCollection drs2 = dataSet1.Tables[0].Rows;
  132. if (drs2.Count <= 0)
  133. {
  134. MessageBox.Show("该时间内没有入库待机钢卷");
  135. }
  136. }
  137. }
  138. }
  139. catch (Exception EX)
  140. {
  141. MessageBox.Show(EX.ToString());
  142. }
  143. }
  144. /// <summary>
  145. /// 导出
  146. /// </summary>
  147. private void DoExport()
  148. {
  149. try
  150. {
  151. //if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  152. //{
  153. // string fileName = this.saveFileDialog1.FileName;
  154. // ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  155. // System.Diagnostics.Process.Start(fileName);
  156. //}
  157. this.DataTabletoExcelULTRA(ultraGrid1);
  158. }
  159. catch (Exception ex)
  160. {
  161. MessageBox.Show(ex.ToString());
  162. }
  163. }
  164. private void StorageStandby_Load(object sender, EventArgs e)
  165. {
  166. this.ultraCheckEditor1.Checked = true;
  167. this.ultraCheckEditor1.Checked = false ;
  168. }
  169. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  170. {
  171. if (this.ultraCheckEditor1.Checked == true)
  172. {
  173. this.ultraCalendarSTRATTIME.Enabled = false;
  174. this.ultraCalendarENDTIME.Enabled = false;
  175. }
  176. if (this.ultraCheckEditor1.Checked == false)
  177. {
  178. this.ultraCalendarENDTIME.Enabled = true;
  179. this.ultraCalendarSTRATTIME.Enabled = true;
  180. }
  181. }
  182. private void ultraGrid1_DoubleClickRow(object sender, Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs e)
  183. {
  184. Infragistics.Win.UltraWinGrid.UltraGridRow uRow = ultraGrid1.ActiveRow;
  185. String coilNo = uRow.Cells["OLD_SAMPL_NO"].Value.ToString();
  186. String curProgCd = "PCA";
  187. this.textBox1.Text = coilNo;
  188. string entryShift = this.UserInfo.GetUserOrder();//入库班次
  189. string entryGroup = this.UserInfo.GetUserGroup();//入库班组
  190. string entryDtime = this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMddHHmmss");//入库时间
  191. string reg_id = this.UserInfo.GetUserID();//操作人
  192. //StorageStandby_Sub dlg = new StorageStandby_Sub(this, 1);
  193. //if (DialogResult.OK == dlg.ShowDialog(this))
  194. //{
  195. string yardAddr = this.textBox3.Text.ToString().Trim();//垛位
  196. if (yardAddr == "" && yardAddr.Length != 13)
  197. {
  198. MessageBox.Show("垛位输入有误!");
  199. return;
  200. }
  201. string[] tmpArray = yardAddr.Split('-');
  202. try
  203. {
  204. if (tmpArray[1].Length < 3)
  205. {
  206. tmpArray[1] = "0" + tmpArray[1];
  207. }
  208. if (tmpArray[2].Length < 2)
  209. {
  210. tmpArray[2] = "0" + tmpArray[2];
  211. }
  212. if (Convert.ToInt32(tmpArray[0]) != 1)
  213. {
  214. MessageBox.Show("垛位输入有误,请重新输入!");
  215. return;
  216. }
  217. //if (tmpArray[1] > "17A")
  218. //{
  219. // MessageBox.Show("垛位输入有误,请重新输入!");
  220. // return;
  221. //}
  222. if (Convert.ToInt32(tmpArray[2]) > 69)
  223. {
  224. MessageBox.Show("垛位行数不能超过69,请重新输入!");
  225. return;
  226. }
  227. if (Convert.ToInt32(tmpArray[1].Substring(0, 2)) > 17)
  228. {
  229. MessageBox.Show("垛位列数不能超过17,请重新输入!");
  230. return;
  231. }
  232. if ((tmpArray[1].Substring(2, 1)) != "A")
  233. {
  234. MessageBox.Show("垛位格式不对,请重新输入!");
  235. return;
  236. }
  237. yardAddr = tmpArray[0] + "-" + tmpArray[1] + "-" + tmpArray[2];
  238. }
  239. catch (Exception ex)
  240. {
  241. MessageBox.Show("垛位信息错误!");
  242. return;
  243. }
  244. DataTable dt = new DataTable();
  245. CoreClientParam ccpx = new CoreClientParam();
  246. ccpx.ServerName = "UIM.UIM010040";
  247. ccpx.MethodName = "SelectCoilYard";
  248. ccpx.ServerParams = new object[] { yardAddr };
  249. ccpx.SourceDataTable = dt;
  250. this.ExecuteQueryToDataTable(ccpx, CoreInvokeType.Internal);
  251. if (dt.Rows.Count <= 0)
  252. {
  253. CoreClientParam ccp = new CoreClientParam();
  254. ccp.ServerName = "UIM.UIM010040";
  255. ccp.MethodName = "saveCoilYard";
  256. ccp.ServerParams = new object[] { coilNo, yardAddr, entryShift, entryGroup, entryDtime, reg_id, curProgCd };
  257. ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  258. if (ccp.ReturnCode != 0)
  259. {
  260. return;
  261. }
  262. else
  263. {
  264. MessageBox.Show("入库成功!");
  265. }
  266. this.DoQuery();
  267. }
  268. else
  269. {
  270. MessageBox.Show("该位置上已经有了钢卷,请重新输入!");
  271. return;
  272. }
  273. //}
  274. //else
  275. //{
  276. // return;
  277. //}
  278. }
  279. /// <summary>
  280. /// 查询区域中一行的垛位信息
  281. /// </summary>
  282. /// <param name="areayType"></param>
  283. /// <param name="areayNo"></param>
  284. /// <param name="yardCol"></param>
  285. internal void queryYardRows(int areaType, int areaNo, string yardCol)
  286. {
  287. this.dataSet3.Tables[0].Clear();
  288. CoreClientParam ccp = new CoreClientParam();
  289. ccp.ServerName = "UIM.UIM010070";
  290. ccp.MethodName = "queryYardRows";
  291. ccp.ServerParams = new object[] { areaType, areaNo, yardCol };
  292. ccp.SourceDataTable = this.dataSet3.Tables[0];
  293. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  294. }
  295. /// <summary>
  296. /// 查询区域中一行的垛位中钢卷信息
  297. /// </summary>
  298. /// <param name="areayType"></param>
  299. /// <param name="areayNo"></param>
  300. /// <param name="yardCol"></param>
  301. internal void queryYardRowCoils(int areaType, int areaNo, string yardCol)
  302. {
  303. this.dataSet2.Tables[0].Clear();
  304. CoreClientParam ccp = new CoreClientParam();
  305. ccp.ServerName = "UIM.UIM010070";
  306. ccp.MethodName = "queryYardRowCoils";
  307. ccp.ServerParams = new object[] { areaType, areaNo, yardCol };
  308. ccp.SourceDataTable = this.dataSet2.Tables[0];
  309. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  310. }
  311. internal int queryMinYardRow(int areaType, int areaNo, string yardCol)
  312. {
  313. int minRow = 1;
  314. CoreClientParam ccp = new CoreClientParam();
  315. ccp.ServerName = "UIM.UIM010070";
  316. ccp.MethodName = "queryMinYardRow";
  317. ccp.ServerParams = new object[] { areaType, areaNo, yardCol };
  318. ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
  319. if (ccp.ReturnObject != null)
  320. {
  321. minRow = int.Parse(ccp.ReturnObject.ToString());
  322. }
  323. return minRow;
  324. }
  325. /// <summary>
  326. /// 查询库存区域
  327. /// </summary>
  328. /// <param name="areaType"></param>
  329. /// <returns></returns>
  330. internal ArrayList queryYardAreas(int areaType)
  331. {
  332. CoreClientParam ccp = new CoreClientParam();
  333. ccp.ServerName = "UIM.UIM010040";
  334. ccp.MethodName = "queryYardAreas";
  335. ccp.ServerParams = new object[] { areaType };
  336. ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
  337. ArrayList retList = (ArrayList)ccp.ReturnObject;
  338. return retList;
  339. }
  340. /// <summary>
  341. /// 查询库存区分
  342. /// </summary>
  343. /// <param name="areaNo"></param>
  344. /// <returns></returns>
  345. internal ArrayList queryYardColsByArea(int areaNo)
  346. {
  347. CoreClientParam ccp = new CoreClientParam();
  348. ccp.ServerName = "UIM.UIM010040";
  349. ccp.MethodName = "queryYardColsByArea";
  350. ccp.ServerParams = new object[] { areaNo };
  351. ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
  352. ArrayList retList = (ArrayList)ccp.ReturnObject;
  353. return retList;
  354. }
  355. public void DataTabletoExcelULTRA(UltraGrid tmpDataTable)
  356. {
  357. string fileName = saveFileDialog1.FileName;
  358. string FileName;
  359. saveFileDialog1.FileName = "入库待机钢卷";
  360. saveFileDialog1.DefaultExt = ".xls";
  361. saveFileDialog1.Filter = "excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
  362. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  363. {
  364. fileName = saveFileDialog1.FileName;
  365. FileName = fileName;
  366. }
  367. else
  368. {
  369. return;
  370. }
  371. string FilePath = saveFileDialog1.FileName;
  372. int rowNum = tmpDataTable.Rows.Count;
  373. //页面显示的列数
  374. int columnNum = tmpDataTable.DisplayLayout.Bands[0].Columns.BoundColumnsCount;
  375. int rowIndex = 1;
  376. int columnIndex = 0;
  377. Excel1.Application xlApp = new Excel1.ApplicationClass();
  378. //Microsoft.Office.Interop.Excel.Application xlApp;
  379. //xlApp = new Microsoft.Office.Interop.Excel.Application();
  380. xlApp.DefaultFilePath = "";
  381. xlApp.DisplayAlerts = false;
  382. xlApp.SheetsInNewWorkbook = 1;
  383. Excel1._Workbook xlBook = (Excel1._Workbook)(xlApp.Workbooks.Add(Missing.Value));//添加新工作簿
  384. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[1];
  385. //int colnum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count;
  386. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(columnNum) + "1");
  387. // Excel1.Range r = ws.get_Range("A1", "AA1");
  388. object[] objHeader = new object[columnNum];
  389. //将DataTable的列名导入Excel表第一行
  390. foreach (UltraGridColumn dc in tmpDataTable.DisplayLayout.Bands[0].Columns)
  391. {
  392. objHeader[columnIndex] = dc.Header.Caption;
  393. columnIndex++;
  394. if (columnIndex == columnNum) break;
  395. }
  396. r.Value2 = objHeader;
  397. //设置第一行表头格式
  398. //r = xlApp.get_Range(xlApp.Cells[1, 1], xlApp.Cells[1, columnNum]);
  399. //设置 域 Range 的颜色
  400. r.Interior.ColorIndex = 17;
  401. r.Font.Size = 9;
  402. // r.get_Characters(0, s1.Length).Font.Size = 20;
  403. r.RowHeight = 30;
  404. r.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  405. //r.Font.Name = "隶书";
  406. //r.Font.Color = clBlue;
  407. //r.Font.Bold = true;
  408. r.Borders.LineStyle = Excel1.XlLineStyle.xlContinuous;
  409. //r.Font.UnderLine = True;
  410. //将DataTable中的数据导入Excel中
  411. for (int i = 0; i < rowNum; i++)
  412. {
  413. rowIndex++;
  414. columnIndex = 0;
  415. for (int j = 0; j < columnNum; j++)
  416. {
  417. //若为订单号 加个单引号转换数据为文本格式
  418. if (columnIndex == 3 || columnIndex == 4)
  419. {
  420. objHeader[columnIndex] = "'" + tmpDataTable.Rows[i].Cells[j].Text.ToString();
  421. }
  422. else
  423. {
  424. objHeader[columnIndex] = tmpDataTable.Rows[i].Cells[j].Text.ToString();
  425. }
  426. columnIndex++;
  427. }
  428. r = ws.get_Range("A" + (i + 2), NumToExeclRowStr(columnNum) + (i + 2));
  429. r.Value2 = objHeader;
  430. r.Borders.LineStyle = Excel1.XlLineStyle.xlContinuous;
  431. r.Font.Size = 9;
  432. }
  433. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  434. //Excel1.Range RMXNEW;
  435. //string Inf0 = "";
  436. //Inf0 = "Z1:" + "Z2";
  437. //RMXNEW = ws.get_Range(Inf0, Type.Missing);
  438. //RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  439. ////格式化表格数据0为纯数字,@为文本 "yyyy-mm-dd" General
  440. //RMXNEW.EntireColumn.NumberFormat = "@";
  441. //Excel1.Range RMXNEW1;
  442. //string Inf1 = "";
  443. //Inf1 = "Y1:" + "Y2";
  444. //RMXNEW1 = ws.get_Range(Inf1, Type.Missing);
  445. //RMXNEW1.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  446. //RMXNEW1.EntireColumn.NumberFormat = "yyyy-mm-dd";
  447. ////导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  448. //Excel1.Range RMX1;
  449. //string Inf1 = "";
  450. //Inf1 = "A1:" + "W1";
  451. //RMX1 = ws.get_Range(Inf1, Type.Missing);
  452. //RMX1.EntireColumn.Delete(0);
  453. r.EntireColumn.AutoFit(); //自适应宽度
  454. //Excel1.Borders pborders = r.Borders;
  455. //设置边框
  456. //r.BorderAround(XlLineStyle.xlContinuous, XlBorderWeight.xlMedium, XlColorIndex.xlColorIndexAutomatic, System.Drawing.Color.Black.ToArgb());
  457. //r.Borders.get_Item(XlBordersIndex.xlEdgeBottom).Weight = XlBorderWeight.xlMedium;
  458. //r.WrapText = true;
  459. xlBook.SaveCopyAs(FilePath);
  460. this.KillSpecialExcel(xlApp);
  461. MessageBox.Show("数据已经成功导出到:" + saveFileDialog1.FileName.ToString(),
  462. "导出完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
  463. System.Diagnostics.Process.Start(fileName);
  464. }
  465. private string NumTochr(int Num)
  466. {
  467. int n = 64 + Num;
  468. return "" + (Char)n;
  469. }
  470. private string NumToExeclRowStr(int Num)
  471. {
  472. int X, Y;
  473. if (Num < 27)
  474. {
  475. return NumTochr(Num);
  476. }
  477. X = Num / 26;
  478. Y = Num - X * 26;
  479. return NumTochr(X) + NumTochr(Y);
  480. }
  481. #region 结束EXCEL.EXE进程的方法
  482. /// <summary>
  483. /// 结束EXCEL.EXE进程的方法
  484. /// </summary>
  485. /// <param name="m_objExcel">EXCEL对象</param>
  486. [DllImport("user32.dll", SetLastError = true)]
  487. static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
  488. public void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel)
  489. {
  490. try
  491. {
  492. if (m_objExcel != null)
  493. {
  494. int lpdwProcessId;
  495. GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId);
  496. System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
  497. }
  498. }
  499. catch (Exception ex)
  500. {
  501. MessageBox.Show(ex.Message);
  502. }
  503. }
  504. #endregion
  505. }
  506. }