UIM020070.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  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 System.Collections;
  10. using CoreFS.CA06;
  11. using PrintSolution;
  12. //using Excel=Microsoft.Office.Interop.Excel;
  13. //using Microsoft.Office.Interop.Excel;
  14. using System.Reflection;
  15. using Excel1 = Microsoft.Office.Interop.Excel;
  16. //using Excel;
  17. namespace Core.LZMes.Client.UIM.UIM02
  18. {
  19. public partial class UIM020070 : FrmBase
  20. {
  21. private int coil_no_index = -1;//冷轧卷在轧制计划的下标位置
  22. public UIM020070()
  23. {
  24. InitializeComponent();
  25. }
  26. public override void ToolBar_Click(object sender, string ToolbarKey)
  27. {
  28. switch (ToolbarKey)
  29. {
  30. case "Query":
  31. this.DoQuery();
  32. break;
  33. case "Export":
  34. // this.DataTabletoExcelkk(this.dataSet1.Tables[0]);
  35. this.DoExport1();
  36. break;
  37. case "Print":
  38. this.DoPrint();
  39. break;
  40. case "Exit":
  41. this.Close();
  42. break;
  43. }
  44. }
  45. private void UIM020040_Load(object sender, EventArgs e)
  46. {
  47. }
  48. private void DoExport1()
  49. {
  50. try
  51. {
  52. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  53. {
  54. string fileName = this.saveFileDialog1.FileName;
  55. ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  56. System.Diagnostics.Process.Start(fileName);
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. MessageBox.Show(ex.ToString());
  62. }
  63. }
  64. /// <summary>
  65. /// 查询重卷计划
  66. /// </summary>
  67. private void DoQuery()
  68. {
  69. bool flag = false;
  70. //string trnfGroup = this.ultraComboEditor3.Text.Trim();
  71. //string trnfShift = this.ultraComboEditor2.Text.Trim();
  72. string trnfShift = -1 == this.ultraComboEditor2.SelectedIndex ? "" : this.ultraComboEditor2.Value.ToString();//班次
  73. string trnfGroup = -1 == this.ultraComboEditor3.SelectedIndex ? "" : this.ultraComboEditor3.Value.ToString();//班组
  74. string pFromDate = null == this.ultraDateTimeEditor1.Value ? "" : this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd");
  75. string pToDate = null == this.ultraDateTimeEditor2.Value ? "" : this.ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd");
  76. string mFromDate = null == this.ultraDateTimeEditor3.Value ? "" : this.ultraDateTimeEditor3.DateTime.ToString("yyyyMMdd");
  77. string mToDate = null == this.ultraDateTimeEditor4.Value ? "" : this.ultraDateTimeEditor4.DateTime.ToString("yyyyMMdd");
  78. string ordNo = textBox3.Text.Trim();
  79. string ordSeq = textBox1.Text.Trim();
  80. string coilNo = textBox2.Text.Trim();
  81. if ("".Equals(ordNo) && coilNo.Equals(""))
  82. {
  83. if ("".Equals(mFromDate) || "".Equals(mToDate) || (ultraDateTimeEditor4.DateTime - ultraDateTimeEditor3.DateTime).Days > 30)
  84. {
  85. if ("".Equals(pFromDate) || "".Equals(pToDate) || (ultraDateTimeEditor2.DateTime - ultraDateTimeEditor1.DateTime).Days > 30)
  86. {
  87. MessageBox.Show("请选择合适的查询条件后再进行查询操作,否则导致数据量过大!");
  88. return;
  89. }
  90. }
  91. }
  92. this.dataSet1.Tables[0].Clear();
  93. CoreClientParam ccp = new CoreClientParam();
  94. ccp.ServerName = "UIM.UIM02.UIM020070";
  95. ccp.MethodName = "queryReelPlan";
  96. ccp.ServerParams = new Object[] { pFromDate, pToDate, mFromDate, mToDate, ordNo, ordSeq, coilNo, trnfShift, trnfGroup};
  97. ccp.SourceDataTable = this.dataSet1.Tables[0];
  98. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  99. coil_no_index = -1;
  100. DataRowCollection drs = dataSet1.Tables[0].Rows;
  101. for (int i = 0; i < drs.Count; i++)
  102. {
  103. Color color = Color.FromArgb(255, 255, 255);
  104. string status = drs[i]["STATUS_CD"].ToString().Trim();
  105. double coilWth = double.Parse(drs[i]["C_COIL_WTH"].ToString().Trim());
  106. double ordWth = double.Parse(drs[i]["C_COIL_THK"].ToString().Trim());
  107. string ingDecGrd = drs[i]["INGR_DEC_GRD"].ToString().Trim();
  108. if ("轧制吊销".Equals(status))
  109. {
  110. color = Color.FromArgb(255, 128, 128);
  111. }
  112. else if ("轧制进行".Equals(status))
  113. {
  114. color = Color.FromArgb(0, 192, 0);
  115. if (coilWth < ordWth)
  116. {
  117. color = Color.SandyBrown;
  118. }
  119. }
  120. else if ("轧制完成".Equals(status))
  121. {
  122. color = Color.FromArgb(192, 255, 192);
  123. }
  124. else if ("上料完成".Equals(status))
  125. {
  126. color = Color.FromArgb(192, 192, 255);
  127. }
  128. else if ("轧废".Equals(status))
  129. {
  130. color = Color.FromArgb(192, 192, 192);
  131. }
  132. else
  133. {
  134. if (!"合格".Equals(ingDecGrd))
  135. {
  136. color = Color.FromArgb(255, 204, 0);
  137. }
  138. else if (coilWth < ordWth)
  139. {
  140. color = Color.SandyBrown;
  141. }
  142. }
  143. ultraGrid1.Rows[i].Appearance.BackColor = color;
  144. }
  145. try
  146. {
  147. getRectange();
  148. }catch(Exception EX)
  149. {
  150. MessageBox.Show(EX.ToString());
  151. }
  152. }
  153. #region "Rectange"
  154. //基料卷展示的宽度
  155. private int width = 9;
  156. //
  157. private int locy = 10;
  158. //宽度X坐标(第一个基料卷)
  159. private int locx1 = 0;
  160. //厚度X坐标(第一个基料卷)
  161. private int locx2 = 0;
  162. //轧制单元X坐标(第一个单元)
  163. private int locx_roll = 0;
  164. //轧制单元Y坐标
  165. private int locy_roll = 81;
  166. //轧制单元高度
  167. private int roll_height = 22;
  168. //Coil Tip
  169. System.Windows.Forms.ToolTip Coil_Tip = new ToolTip();
  170. //背景颜色配色
  171. Infragistics.Win.Appearance appearance = new Infragistics.Win.Appearance();
  172. private void getRectange()
  173. {
  174. try
  175. {
  176. locx1 = locx2 = locx_roll = 0;
  177. System.Int16 wth; //宽度
  178. double thk; //厚度
  179. //string coilNO;
  180. string rollNO = "";
  181. int rollCoilCnt = 0;
  182. int totalCnt = 0;
  183. this.panel5.Controls.Clear();
  184. Coil_Tip.RemoveAll();
  185. foreach (DataRow row in this.dataSet1.Tables[0].Rows)
  186. {
  187. wth = Convert.ToInt16(row["C_COIL_WTH"]);
  188. thk = Convert.ToDouble(row["C_COIL_THK"]);
  189. //coilNO = Convert.ToString(row["C_COIL_NO"]);
  190. //string tempRollNO = Convert.ToString(row["ROLL_MANA_NO"]);
  191. //if (rollNO != null) //&& rollNO != tempRollNO
  192. //{
  193. // getRollRectange(totalCnt, rollCoilCnt, rollNO);
  194. //rollCoilCnt = 1;
  195. //}
  196. //else
  197. //{
  198. rollCoilCnt = rollCoilCnt + 1;
  199. totalCnt = totalCnt + 1;
  200. //}
  201. //rollNO = tempRollNO;
  202. getWidthRectange(row);
  203. getThkRectange(row);
  204. }
  205. getRollRectange(totalCnt, rollCoilCnt, rollNO);
  206. }
  207. catch (System.Exception ex)
  208. {
  209. System.Diagnostics.Debug.WriteLine(ex.ToString());
  210. }
  211. }
  212. private void getRollRectange(int totalCnt, int rollCnt, string rollNO)
  213. {
  214. System.Windows.Forms.Label lab_roll = new Label();
  215. lab_roll.AutoSize = false;
  216. lab_roll.TextAlign = ContentAlignment.MiddleCenter;
  217. lab_roll.BackColor = System.Drawing.Color.White;
  218. lab_roll.BorderStyle = BorderStyle.FixedSingle;
  219. this.panel5.Controls.Add(lab_roll);
  220. lab_roll.Location = new System.Drawing.Point(locx_roll, locy_roll);
  221. lab_roll.Name = rollNO;
  222. lab_roll.Size = new System.Drawing.Size(rollCnt * width, roll_height);
  223. lab_roll.TabIndex = 1;
  224. lab_roll.Text = rollNO;
  225. //lab_roll.DoubleClick += new EventHandler(lab_roll_DoubleClick);
  226. this.locx_roll = this.locx_roll + rollCnt * width;
  227. }
  228. private void getWidthRectange(System.Data.DataRow row)
  229. {
  230. try
  231. {
  232. System.Decimal height = Common.FixDBManager.CheckNullDecimal(row["C_COIL_WTH"]);
  233. string Status_CD = Common.FixDBManager.CheckNullStr(row["STATUS_CD"]);
  234. string Coil_NO = Common.FixDBManager.CheckNullStr(row["C_COIL_NO"]);
  235. string tip_str = getTipStr(row);
  236. int lab_locy = 0;
  237. int lab_height = 0;
  238. if (height <= 800)
  239. {
  240. lab_height = Convert.ToInt16((height / 800) * 26);
  241. lab_locy = 90 - lab_height;
  242. }
  243. else if (height > 800 & height <= 1100)
  244. {
  245. lab_height = Convert.ToInt16(((height - 800) / 300) * 26) + 26;
  246. lab_locy = 90 - lab_height;
  247. }
  248. else if (height > 1100 & height <= 1400)
  249. {
  250. lab_height = Convert.ToInt16(((height - 1100) / 300) * 26) + 26 + 26;
  251. lab_locy = 90 - lab_height;
  252. }
  253. else
  254. {
  255. lab_height = 90;
  256. lab_locy = 0;
  257. }
  258. System.Windows.Forms.Label lab_width = new Label();
  259. lab_width.AutoSize = false;
  260. lab_width.BorderStyle = BorderStyle.FixedSingle;
  261. lab_width.Text = "";
  262. if (Status_CD == "轧制作业待机")
  263. {
  264. lab_width.BackColor = this.label14.BackColor;
  265. }
  266. else if (Status_CD == "轧制吊销")
  267. {
  268. lab_width.BackColor = this.label7.BackColor;
  269. }
  270. else if (Status_CD == "上料完成")
  271. {
  272. lab_width.BackColor = this.label16.BackColor;
  273. }
  274. else if (Status_CD == "轧制进行")
  275. {
  276. lab_width.BackColor = this.label11.BackColor;
  277. }
  278. else if (Status_CD == "轧制完成")
  279. {
  280. lab_width.BackColor = this.label9.BackColor;
  281. }
  282. else if (Status_CD == "轧废")
  283. {
  284. lab_width.BackColor = this.label17.BackColor;
  285. }
  286. this.panel5.Controls.Add(lab_width);
  287. lab_width.Location = new System.Drawing.Point(locx1, lab_locy);
  288. lab_width.Name = Coil_NO;
  289. lab_width.Tag = Coil_NO;
  290. lab_width.Size = new System.Drawing.Size(width, lab_height);
  291. Coil_Tip.SetToolTip(lab_width, tip_str);
  292. this.locx1 = this.locx1 + this.width;
  293. lab_width.DoubleClick += new EventHandler(lab_width_DoubleClick);
  294. }
  295. catch (System.Exception ex)
  296. {
  297. System.Diagnostics.Debug.WriteLine(ex.ToString());
  298. }
  299. }
  300. private void getThkRectange(System.Data.DataRow row)
  301. {
  302. try
  303. {
  304. int lab_locy = locy_roll + roll_height;
  305. System.Double height = Convert.ToDouble(row["C_COIL_THK"]);
  306. string Status_CD = Common.FixDBManager.CheckNullStr(row["STATUS_CD"]);
  307. string Coil_NO = Common.FixDBManager.CheckNullStr(row["C_COIL_NO"]);
  308. string tip_str = getTipStr(row);
  309. int lab_height = 0;
  310. if (height <= 0.6)
  311. {
  312. lab_height = Convert.ToInt16((height / 0.6) * 26);
  313. }
  314. else if (height > 0.6 & height <= 1.2)
  315. {
  316. lab_height = Convert.ToInt16(((height - 0.6) / 0.8) * 26) + 26;
  317. }
  318. else if (height > 1.2 & height <= 1.8)
  319. {
  320. lab_height = Convert.ToInt16(((height - 1.2) / 0.6) * 26) + 26 + 26;
  321. }
  322. else
  323. {
  324. lab_height = 81;
  325. }
  326. System.Windows.Forms.Label Clab_height = new Label();
  327. Clab_height.AutoSize = false;
  328. Clab_height.BorderStyle = BorderStyle.FixedSingle;
  329. Clab_height.Text = "";
  330. if (Status_CD == "轧制作业待机")
  331. {
  332. Clab_height.BackColor = this.label14.BackColor;
  333. }
  334. else if (Status_CD == "轧制吊销")
  335. {
  336. Clab_height.BackColor = this.label7.BackColor;
  337. }
  338. else if (Status_CD == "上料完成")
  339. {
  340. Clab_height.BackColor = this.label16.BackColor;
  341. }
  342. else if (Status_CD == "轧制进行")
  343. {
  344. Clab_height.BackColor = this.label11.BackColor;
  345. }
  346. else if (Status_CD == "轧制完成")
  347. {
  348. Clab_height.BackColor = this.label9.BackColor;
  349. }
  350. else if (Status_CD == "轧废")
  351. {
  352. Clab_height.BackColor = this.label17.BackColor;
  353. }
  354. this.panel5.Controls.Add(Clab_height);
  355. Clab_height.Location = new System.Drawing.Point(locx2, lab_locy);
  356. Clab_height.Name = "H" + Coil_NO;
  357. Clab_height.Tag = Coil_NO;
  358. Clab_height.Size = new System.Drawing.Size(width, lab_height);
  359. Coil_Tip.SetToolTip(Clab_height, tip_str);
  360. this.locx2 = this.locx2 + this.width;
  361. Clab_height.DoubleClick += new EventHandler(Clab_height_DoubleClick);
  362. }
  363. catch (System.Exception ex)
  364. {
  365. System.Diagnostics.Debug.WriteLine(ex.ToString());
  366. }
  367. }
  368. private string getTipStr(System.Data.DataRow row)
  369. {
  370. try
  371. {
  372. string tip_str = "连退卷号:" + Common.FixDBManager.CheckNullStr(row["C_COIL_NO"]) + "\n";
  373. tip_str = tip_str + "原料内径:" + Common.FixDBManager.CheckNullStr(row["C_COIL_INDIA"]) + "\n";
  374. tip_str = tip_str + "原料外径:" + Common.FixDBManager.CheckNullStr(row["C_OUTDIA"]) + "\n";
  375. tip_str = tip_str + "原料厚度:" + Common.FixDBManager.CheckNullStr(row["C_COIL_THK"]) + "\n";
  376. tip_str = tip_str + "原料宽度:" + Common.FixDBManager.CheckNullStr(row["C_COIL_WTH"]);
  377. return tip_str;
  378. }
  379. catch (System.Exception ex)
  380. {
  381. System.Diagnostics.Debug.WriteLine(ex.ToString());
  382. return "";
  383. }
  384. }
  385. #endregion
  386. #region "Label Event"
  387. //轧辊单元双击事件
  388. //void lab_roll_DoubleClick(object sender, EventArgs e)
  389. //{
  390. // try
  391. // {
  392. // this.ultraGrid1.Selected.Rows.Clear();
  393. // string RollNO = (sender as System.Windows.Forms.Label).Name;
  394. // for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
  395. // {
  396. // if (Common.FixDBManager.CheckNullStr(this.ultraGrid1.Rows[i].Cells["ROLL_MANA_NO"].Value) == RollNO)
  397. // {
  398. // this.ultraGrid1.Selected.Rows.Add(this.ultraGrid1.Rows[i]);
  399. // }
  400. // }
  401. // this.ultraGrid1.Selected.Rows[0].Activated = true;
  402. // }
  403. // catch (System.Exception ex)
  404. // {
  405. // System.Diagnostics.Debug.WriteLine(ex.ToString());
  406. // }
  407. //}
  408. void lab_width_DoubleClick(object sender, EventArgs e)
  409. {
  410. try
  411. {
  412. this.ultraGrid1.Selected.Rows.Clear();
  413. string CoilNO = (sender as System.Windows.Forms.Label).Tag.ToString();//L5-053562-10A0000
  414. //string CoilNO = "L5-053562-10A0000";
  415. for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
  416. {
  417. if (Common.FixDBManager.CheckNullStr(this.ultraGrid1.Rows[i].Cells["C_COIL_NO"].Value) == CoilNO)
  418. {
  419. //string a = "12";
  420. this.ultraGrid1.Selected.Rows.Add(this.ultraGrid1.Rows[i]);
  421. }
  422. }
  423. this.ultraGrid1.Selected.Rows[0].Activated = true;
  424. }
  425. catch (System.Exception ex)
  426. {
  427. System.Diagnostics.Debug.WriteLine(ex.ToString());
  428. }
  429. }
  430. void Clab_height_DoubleClick(object sender, EventArgs e)
  431. {
  432. try
  433. {
  434. this.ultraGrid1.Selected.Rows.Clear();
  435. string CoilNO = (sender as System.Windows.Forms.Label).Tag.ToString();
  436. for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
  437. {
  438. if (Common.FixDBManager.CheckNullStr(this.ultraGrid1.Rows[i].Cells["C_COIL_NO"].Value) == CoilNO)
  439. {
  440. this.ultraGrid1.Selected.Rows.Add(this.ultraGrid1.Rows[i]);
  441. }
  442. }
  443. this.ultraGrid1.Selected.Rows[0].Activated = true;
  444. }
  445. catch (System.Exception ex)
  446. {
  447. System.Diagnostics.Debug.WriteLine(ex.ToString());
  448. }
  449. }
  450. #endregion
  451. #region "Button Event"
  452. //private void btn_Add_Click(object sender, EventArgs e)
  453. //{
  454. // try
  455. // {
  456. // this.ultraGrid1.Selected.Rows.Clear();
  457. // // string CoilNO = txt_CoilNO.Text.Trim().ToUpper();
  458. // for (int i = 0; i < this.ultraGrid1.Rows.Count; i++)
  459. // {
  460. // if ((Common.FixDBManager.CheckNullStr(this.ultraGrid1.Rows[i].Cells["C_COIL_NO"].Value).IndexOf(CoilNO) > -1) ||
  461. // (Common.FixDBManager.CheckNullStr(this.ultraGrid1.Rows[i].Cells["R_COIL_NO"].Value).IndexOf(CoilNO) > -1))
  462. // {
  463. // this.ultraGrid1.Selected.Rows.Add(this.ultraGrid1.Rows[i]);
  464. // }
  465. // }
  466. // if (ultraGrid1.Selected.Rows.Count > 0)
  467. // this.ultraGrid1.Selected.Rows[0].Activated = true;
  468. // }
  469. // catch (System.Exception ex)
  470. // {
  471. // System.Diagnostics.Debug.WriteLine(ex.ToString());
  472. // }
  473. //}
  474. #endregion
  475. private void DoExport()
  476. {
  477. try
  478. {
  479. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  480. {
  481. string fileName = this.saveFileDialog1.FileName;
  482. this.ultraGrid1.DisplayLayout.Bands[0].Columns["STATUS_CD"].Hidden = true;
  483. this.ultraGrid1.DisplayLayout.Bands[0].Columns["C_EXTSHAPE_REQ"].Hidden = true;
  484. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ACID_PROD_PATH"].Hidden = true;
  485. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BZ"].Hidden = true;
  486. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORDCUST_CD"].Hidden = true;
  487. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INGR_DEC_GRD"].Hidden = true;
  488. this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.None;
  489. ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  490. System.Diagnostics.Process.Start(fileName);
  491. this.ultraGrid1.BeginUpdate();
  492. this.ultraGrid1.DisplayLayout.Bands[0].Columns["STATUS_CD"].Hidden = true;
  493. this.ultraGrid1.DisplayLayout.Bands[0].Columns["C_EXTSHAPE_REQ"].Hidden = true;
  494. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ACID_PROD_PATH"].Hidden = true;
  495. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BZ"].Hidden = true;
  496. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORDCUST_CD"].Hidden = true;
  497. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INGR_DEC_GRD"].Hidden = true;
  498. this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ExtendLastColumn;
  499. this.ultraGrid1.EndUpdate();
  500. }
  501. }
  502. catch (Exception ex)
  503. {
  504. MessageBox.Show(ex.ToString());
  505. }
  506. }
  507. private string NumTochr(int Num)
  508. {
  509. int n = 64 + Num;
  510. return "" + (Char)n;
  511. }
  512. private string NumToExeclRowStr(int Num)
  513. {
  514. int X, Y;
  515. if (Num < 27)
  516. {
  517. return NumTochr(Num);
  518. }
  519. X = Num / 26;
  520. Y = Num - X * 26;
  521. return NumTochr(X) + NumTochr(Y);
  522. }
  523. /// <summary>
  524. /// 将DataTable中的列名及数据导出到Excel表中
  525. /// </summary>
  526. /// <param name="tmpDataTable">要导出的DataTable</param>
  527. /// <param name="strFileName">Excel的保存路径及名称</param>
  528. public void DataTabletoExcelkk(System.Data.DataTable tmpDataTable)
  529. {
  530. string fileName = saveFileDialog1.FileName;
  531. string FileName;
  532. saveFileDialog1.FileName = "重卷计划查询报表";
  533. saveFileDialog1.DefaultExt = ".xls";
  534. saveFileDialog1.Filter = "excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
  535. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  536. {
  537. fileName = saveFileDialog1.FileName;
  538. FileName = fileName;
  539. }
  540. string FilePath = saveFileDialog1.FileName;
  541. if (tmpDataTable == null)
  542. return;
  543. int rowNum = tmpDataTable.Rows.Count;
  544. int columnNum = tmpDataTable.Columns.Count;
  545. int rowIndex = 1;
  546. int columnIndex = 0;
  547. Excel1.Application xlApp = new Excel1.ApplicationClass();
  548. //Microsoft.Office.Interop.Excel.Application xlApp;
  549. //xlApp = new Microsoft.Office.Interop.Excel.Application();
  550. xlApp.DefaultFilePath = "";
  551. xlApp.DisplayAlerts = false;
  552. xlApp.SheetsInNewWorkbook = 1;
  553. Excel1._Workbook xlBook = (Excel1._Workbook)(xlApp.Workbooks.Add(Missing.Value));//添加新工作簿
  554. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[1];
  555. int colnum = tmpDataTable.Columns.Count;
  556. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(colnum) + "1");
  557. object[] objHeader = new object[colnum];
  558. //将DataTable的列名导入Excel表第一行
  559. foreach (DataColumn dc in tmpDataTable.Columns)
  560. {
  561. objHeader[columnIndex] = dc.Caption;
  562. columnIndex++;
  563. }
  564. r.Value2 = objHeader;
  565. //将DataTable中的数据导入Excel中
  566. for (int i = 0; i < rowNum; i++)
  567. {
  568. rowIndex++;
  569. columnIndex = 0;
  570. for (int j = 0; j < columnNum; j++)
  571. {
  572. objHeader[columnIndex] = tmpDataTable.Rows[i][j].ToString();
  573. columnIndex++;
  574. }
  575. r = ws.get_Range("A" + (i + 2), NumToExeclRowStr(colnum) + (i + 2));
  576. r.Value2 = objHeader;
  577. }
  578. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  579. Excel1.Range RMXNEW;
  580. string Inf0 = "";
  581. Inf0 = "AD1:" + "AD2";
  582. RMXNEW = ws.get_Range(Inf0, Type.Missing);
  583. RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter; 
  584. RMXNEW.EntireColumn.NumberFormat = "0";
  585. //填充要合并的数值到两个List
  586. ArrayList al = new ArrayList();
  587. ArrayList al1 = new ArrayList();
  588. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ultraGrid1.Rows)
  589. {
  590. string yaoqiuType = row.Cells["JISHUYAOQIU"].Text;
  591. al.Add(yaoqiuType);
  592. string beizhuType = row.Cells["ORD_RMK"].Text;
  593. al1.Add(beizhuType);
  594. }
  595. //合并特殊要求
  596. if (al.Count > 0)
  597. {
  598. int XXCount = al.Count;
  599. string LastName = "";
  600. int LastPosInf = -1;
  601. for (int i = 0; i < XXCount; i++)
  602. {
  603. if (LastName == "")
  604. {
  605. LastName = (string)al[i];
  606. LastPosInf = i;
  607. }
  608. else
  609. {
  610. if (LastName == (string)al[i])
  611. {
  612. if (i == XXCount - 1)
  613. {
  614. if (LastPosInf != i)
  615. {
  616. Excel1.Range RMX;
  617. string Inf = "";
  618. Inf = "AS" + (LastPosInf + 2).ToString() + ":" + "AS" + (i + 2).ToString();
  619. RMX = ws.get_Range(Inf, Type.Missing);
  620. RMX.MergeCells = true;
  621. RMX.Merge(0);
  622. }
  623. }
  624. }
  625. else
  626. {
  627. if (LastPosInf != i - 1)
  628. {
  629. Excel1.Range RMX;
  630. string Inf = "";
  631. Inf = "AS" + (LastPosInf + 2).ToString() + ":" + "AS" + (i + 1).ToString();
  632. RMX = ws.get_Range(Inf, Type.Missing);
  633. RMX.MergeCells = true;
  634. RMX.Merge(0);
  635. }
  636. LastName = (string)al[i];
  637. LastPosInf = i;
  638. }
  639. }
  640. }
  641. }
  642. al.Clear();
  643. //合并备注列
  644. if (al1.Count > 0)
  645. {
  646. int XXCount = al1.Count;
  647. string LastName = "";
  648. int LastPosInf = -1;
  649. for (int i = 0; i < XXCount; i++)
  650. {
  651. if (LastName == "")
  652. {
  653. LastName = (string)al1[i];
  654. LastPosInf = i;
  655. }
  656. else
  657. {
  658. if (LastName == (string)al1[i])
  659. {
  660. if (i == XXCount - 1)
  661. {
  662. if (LastPosInf != i)
  663. {
  664. Excel1.Range RMX;
  665. string Inf = "";
  666. Inf = "AT" + (LastPosInf + 2).ToString() + ":" + "AT" + (i + 2).ToString();
  667. RMX = ws.get_Range(Inf, Type.Missing);
  668. RMX.MergeCells = true;
  669. RMX.Merge(0);
  670. }
  671. }
  672. }
  673. else
  674. {
  675. if (LastPosInf != i - 1)
  676. {
  677. Excel1.Range RMX;
  678. string Inf = "";
  679. Inf = "AT" + (LastPosInf + 2).ToString() + ":" + "AT" + (i + 1).ToString();
  680. RMX = ws.get_Range(Inf, Type.Missing);
  681. RMX.MergeCells = true;
  682. RMX.Merge(0);
  683. }
  684. LastName = (string)al1[i];
  685. LastPosInf = i;
  686. }
  687. }
  688. }
  689. }
  690. al1.Clear();
  691. //导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  692. Excel1.Range RMX1;
  693. string Inf1 = "";
  694. Inf1 = "A1:" + "W1";
  695. RMX1 = ws.get_Range(Inf1, Type.Missing);
  696. RMX1.EntireColumn.Delete(0);
  697. r.EntireColumn.AutoFit();
  698. xlBook.SaveCopyAs(FilePath);
  699. }
  700. private void DoPrint()
  701. {
  702. if (MessageBox.Show("您确认流程卡打印信息?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
  703. {
  704. if (coil_no_index >= 0)
  705. {
  706. Infragistics.Win.UltraWinGrid.UltraGridRow uRow = ultraGrid1.Rows[coil_no_index];
  707. ArrayList param = new ArrayList();
  708. param.Add(uRow.Cells["C_COIL_NO"].Value.ToString().Trim().Substring(0, 9));
  709. param.Add(uRow.Cells["STL_GRD"].Value.ToString().Trim());
  710. param.Add(uRow.Cells["H_COIL_NO"].Value.ToString().Trim());
  711. param.Add(uRow.Cells["H_SIZE"].Value.ToString().Trim());
  712. param.Add(uRow.Cells["H_WEIGHT"].Value.ToString().Trim());
  713. param.Add(uRow.Cells["SPEC_STL_GRD"].Value.ToString().Trim());
  714. param.Add(uRow.Cells["C_COIL_NO"].Value.ToString().Trim().Substring(0,12));
  715. param.Add(uRow.Cells["C_SIZE"].Value.ToString().Trim());
  716. string prodLine = uRow.Cells["PROD_LINE"].Value.ToString().Trim();
  717. if (prodLine == "L")
  718. {
  719. param.Add("否");
  720. param.Add(uRow.Cells["C_TOT_DEC_GRD"].Value.ToString().Trim());
  721. param.Add(uRow.Cells["C_CAUSE"].Value.ToString().Trim());
  722. param.Add(uRow.Cells["C_WEIGHT"].Value.ToString().Trim());
  723. param.Add(uRow.Cells["C_YARD"].Value.ToString().Trim());
  724. param.Add("连退");
  725. param.Add("是");
  726. }
  727. else
  728. {
  729. param.Add("是");
  730. param.Add(uRow.Cells["C_TOT_DEC_GRD"].Value.ToString().Trim());
  731. param.Add(uRow.Cells["C_CAUSE"].Value.ToString().Trim());
  732. param.Add(uRow.Cells["C_WEIGHT"].Value.ToString().Trim());
  733. param.Add(uRow.Cells["C_YARD"].Value.ToString().Trim());
  734. param.Add("酸轧成品");
  735. param.Add("否");
  736. }
  737. param.Add(uRow.Cells["C_COIL_NO"].Value.ToString().Trim());
  738. param.Add(ultraGrid1.Rows[coil_no_index].Cells["C_COIL_THK"].Value.ToString().Trim() + "*" + ultraGrid1.Rows[coil_no_index].Cells["C_COIL_WTH"].Value.ToString().Trim());
  739. param.Add(uRow.Cells["L_TOT_DEC_GRD"].Value.ToString().Trim());
  740. param.Add(uRow.Cells["L_CAUSE"].Value.ToString().Trim());
  741. param.Add(uRow.Cells["C_ACT_WGT"].Value.ToString().Trim());
  742. param.Add(uRow.Cells["C_CUR_LOAD_LOC"].Value.ToString().Trim());
  743. try
  744. {
  745. ExcelPrinter ePrinter = new ExcelPrinter("FlowCard3.xml", param);
  746. ePrinter.PageSetup.IsCustom = true;
  747. ePrinter.PageSetup.TopMargin = 40;
  748. ePrinter.PageSetup.BottomMargin = 1;
  749. ePrinter.PageSetup.LeftMargin = 1;
  750. ePrinter.PageSetup.RightMargin = 0.5;
  751. ePrinter.Orientation = 1;//横向打印
  752. ePrinter.printExcel();
  753. }
  754. catch (Exception ex)
  755. {
  756. MessageBox.Show("打印失败,请关闭程序后重新操作!");
  757. return;
  758. }
  759. }
  760. else
  761. {
  762. MessageBox.Show("请选择打印钢卷!");
  763. return;
  764. }
  765. }
  766. }
  767. private void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  768. {
  769. ultraGrid1.UpdateData();
  770. if (e.Cell.Column.Key.Equals("CHK"))
  771. {
  772. if (Convert.ToBoolean(e.Cell.Value))
  773. {
  774. string C_COILNO = e.Cell.Row.Cells["C_COIL_NO"].Text.Trim();
  775. if (coil_no_index != -1)
  776. {
  777. ultraGrid1.Rows[coil_no_index].Cells["CHK"].Value = false;
  778. }
  779. coil_no_index = e.Cell.Row.Index;
  780. }
  781. else
  782. {
  783. coil_no_index = -1;
  784. }
  785. }
  786. }
  787. private void UIM020070_Load(object sender, EventArgs e)
  788. {
  789. try
  790. {
  791. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn col in this.ultraGrid1.DisplayLayout.Bands[0].Columns)
  792. {
  793. //Common.FixDBManager.SetCellActivation(col.Key.ToString(), "L_TBF03_SPEC_REEL", this.ultraGrid1, "ACTIVATEONLY");
  794. }
  795. }
  796. catch (System.Exception ex)
  797. {
  798. System.Diagnostics.Debug.WriteLine(ex.ToString());
  799. }
  800. }
  801. }
  802. }