d6fd629424d34cd100f1661f6a15719004fb3c31.svn-base 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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.Reflection;
  11. using Excel1 = Microsoft.Office.Interop.Excel;
  12. using Infragistics.Win.UltraWinGrid;
  13. using System.Runtime.InteropServices;
  14. using System.Collections;
  15. namespace Core.LZMes.Client.UIM
  16. {
  17. public partial class UIM010233 : FrmBase
  18. {
  19. public UIM010233()
  20. {
  21. InitializeComponent();
  22. }
  23. public override void ToolBar_Click(object sender, string ToolbarKey)
  24. {
  25. switch (ToolbarKey)
  26. {
  27. case "query":
  28. this.DoQuery();
  29. break;
  30. case "queryRZ":
  31. this.DoQueryRZ();
  32. break;
  33. case "export":
  34. //this.DataTabletoExcelkk(this.dataSet2.Tables[0]);
  35. this.DataTabletoExcelULTRA(ultraGrid2, "网上销售(" + this.textBox_RZ.Text + ")产品信息");
  36. this.DataTabletoExcelULTRA(ultraGrid1, "网上销售(" + this.textBox_RZ.Text + ")质量信息");
  37. saveWGCoil(); //导出网购卷同时保存钢卷到网购卷记录表中
  38. break;
  39. case "Exit":
  40. this.Close();
  41. break;
  42. }
  43. }
  44. /// <summary>
  45. /// 查询冷轧成品库库存数据
  46. /// </summary>
  47. private void DoQuery()
  48. {
  49. try
  50. {
  51. this.dataSet2.Tables[0].Clear();
  52. this.dataSet1.Tables[0].Clear();
  53. this.textBox_RZ.Text = "冷轧"; //导出冷轧数据标识
  54. string startTime = this.ultraDateTimeEditor1.Value != null ? ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd") : "";//入库开始时间
  55. string endTime = this.ultraDateTimeEditor2.Value != null ? ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//入库结束时间
  56. string specStlGrd = this.textBox3.Text;//牌号
  57. string coilNo = this.textBox9.Text;//钢卷号
  58. string wanggou_yn = this.ultraComboEditor1_YN.Value.ToString();
  59. string[] queryParams = new string[] { startTime, endTime, specStlGrd, coilNo, wanggou_yn };
  60. List<string[]> list = new List<String[]>();
  61. list.Add(queryParams);
  62. CoreClientParam ccp = new CoreClientParam();
  63. ccp.ServerName = "UIM.UIM010233";
  64. ccp.MethodName = "queryerjiYardList";
  65. ccp.ServerParams = new object[] { list };
  66. ccp.SourceDataTable = this.dataSet2.Tables[0];
  67. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  68. string[] queryParams1 = new string[] { startTime, endTime, specStlGrd, coilNo, wanggou_yn };
  69. List<string[]> list1 = new List<String[]>();
  70. list1.Add(queryParams1);
  71. CoreClientParam ccp1 = new CoreClientParam();
  72. ccp1.ServerName = "UIM.UIM010233";
  73. ccp1.MethodName = "queryerjizhiliang";
  74. ccp1.ServerParams = new object[] { list1 };
  75. ccp1.SourceDataTable = this.dataSet1.Tables[0];
  76. this.ExecuteQueryToDataTable(ccp1, CoreInvokeType.Internal);
  77. //设置已经网购卷的颜色
  78. Color color = Color.PaleGoldenrod;
  79. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid2.Rows)
  80. {
  81. string status = ugr.Cells["WANGGOU_YN"].Text;
  82. if ("是".Equals(status))
  83. {
  84. color = Color.White;
  85. }
  86. else
  87. {
  88. color = Color.PaleGoldenrod;
  89. }
  90. ugr.Appearance.BackColor = color;
  91. }
  92. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid1.Rows)
  93. {
  94. string status = ugr.Cells["WANGGOU_YN"].Text;
  95. if ("是".Equals(status))
  96. {
  97. color = Color.White;
  98. }
  99. else
  100. {
  101. color = Color.PaleGoldenrod;
  102. }
  103. ugr.Appearance.BackColor = color;
  104. }
  105. ////统计钢卷数量,钢卷总重量
  106. //int coilCount = (int)dataSet2.Tables[0].Compute("count(OLD_SAMPL_NO)", "");
  107. //double coilWgtSum = 0;
  108. //foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid2.Rows)
  109. //{
  110. // double actWgt = 0;
  111. // try
  112. // {
  113. // Color color = Color.PaleGoldenrod;
  114. // string status = ugr.Cells["TOT_DEC_GRD"].Value.ToString().Trim();
  115. // if ("合格".Equals(status))
  116. // {
  117. // color = Color.White;
  118. // }
  119. // else if ("不合格".Equals(status))
  120. // {
  121. // color = Color.FromArgb(255, 128, 128);
  122. // }
  123. // ugr.Appearance.BackColor = color;
  124. // actWgt = double.Parse(ugr.Cells["ACT_WGT"].Value.ToString().Trim());
  125. // }
  126. // catch (Exception e)
  127. // {
  128. // }
  129. // coilWgtSum += actWgt;
  130. //}
  131. }
  132. catch (Exception EX)
  133. {
  134. MessageBox.Show(EX.ToString());
  135. }
  136. }
  137. /// <summary>
  138. /// 查询热轧成品库库存数据
  139. /// </summary>
  140. private void DoQueryRZ()
  141. {
  142. try
  143. {
  144. this.dataSet2.Tables[0].Clear();
  145. this.dataSet1.Tables[0].Clear();
  146. this.textBox_RZ.Text = "热轧"; //导出热轧数据标识
  147. string startTime = this.ultraDateTimeEditor1.Value != null ? ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd") : "";//入库开始时间
  148. string endTime = this.ultraDateTimeEditor2.Value != null ? ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd") : "";//入库结束时间
  149. string specStlGrd = this.textBox3.Text;//牌号
  150. string coilNo = this.textBox9.Text;//钢卷号
  151. string wanggou_yn = this.ultraComboEditor1_YN.Value.ToString();
  152. string[] queryParams = new string[] { startTime, endTime, specStlGrd, coilNo, wanggou_yn };
  153. List<string[]> list = new List<String[]>();
  154. list.Add(queryParams);
  155. CoreClientParam ccp = new CoreClientParam();
  156. ccp.ServerName = "UIM.UIM010233";
  157. ccp.MethodName = "queryerjiYardListRZ";
  158. ccp.ServerParams = new object[] { list };
  159. ccp.SourceDataTable = this.dataSet2.Tables[0];
  160. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  161. string[] queryParams1 = new string[] { startTime, endTime, specStlGrd, coilNo, wanggou_yn };
  162. List<string[]> list1 = new List<String[]>();
  163. list1.Add(queryParams1);
  164. CoreClientParam ccp1 = new CoreClientParam();
  165. ccp1.ServerName = "UIM.UIM010233";
  166. ccp1.MethodName = "queryerjizhiliangRZ";
  167. ccp1.ServerParams = new object[] { list1 };
  168. ccp1.SourceDataTable = this.dataSet1.Tables[0];
  169. this.ExecuteQueryToDataTable(ccp1, CoreInvokeType.Internal);
  170. //设置已经网购卷的颜色
  171. Color color = Color.PaleGoldenrod;
  172. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid2.Rows)
  173. {
  174. string status = ugr.Cells["WANGGOU_YN"].Text;
  175. if ("是".Equals(status))
  176. {
  177. color = Color.White;
  178. }
  179. else {
  180. color = Color.PaleGoldenrod;
  181. }
  182. ugr.Appearance.BackColor = color;
  183. }
  184. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid1.Rows)
  185. {
  186. string status = ugr.Cells["WANGGOU_YN"].Text;
  187. if ("是".Equals(status))
  188. {
  189. color = Color.White;
  190. }
  191. else
  192. {
  193. color = Color.PaleGoldenrod;
  194. }
  195. ugr.Appearance.BackColor = color;
  196. }
  197. ////统计钢卷数量,钢卷总重量
  198. //int coilCount = (int)dataSet2.Tables[0].Compute("count(OLD_SAMPL_NO)", "");
  199. //double coilWgtSum = 0;
  200. //foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in ultraGrid2.Rows)
  201. //{
  202. // double actWgt = 0;
  203. // try
  204. // {
  205. // Color color = Color.PaleGoldenrod;
  206. // string status = ugr.Cells["TOT_DEC_GRD"].Value.ToString().Trim();
  207. // if ("合格".Equals(status))
  208. // {
  209. // color = Color.White;
  210. // }
  211. // else if ("不合格".Equals(status))
  212. // {
  213. // color = Color.FromArgb(255, 128, 128);
  214. // }
  215. // ugr.Appearance.BackColor = color;
  216. // actWgt = double.Parse(ugr.Cells["ACT_WGT"].Value.ToString().Trim());
  217. // }
  218. // catch (Exception e)
  219. // {
  220. // }
  221. // coilWgtSum += actWgt;
  222. //}
  223. }
  224. catch (Exception EX)
  225. {
  226. MessageBox.Show(EX.ToString());
  227. }
  228. }
  229. private void UIM010233_Load(object sender, EventArgs e)
  230. {
  231. this.ultraDateTimeEditor1.Value = "";
  232. this.ultraDateTimeEditor2.Value = "";
  233. }
  234. private void DoExport()
  235. {
  236. try
  237. {
  238. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  239. {
  240. string fileName = this.saveFileDialog1.FileName;
  241. // this.ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  242. // string a = this.ultraGrid2.DisplayLayout.Appearance.Key;
  243. this.ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  244. System.Diagnostics.Process.Start(fileName);
  245. //Infragistics.Excel.Workbook work = new Infragistics.Excel.Workbook();
  246. //Infragistics.Excel.Worksheet sheet1 = work.Worksheets.Add("网上销售(" + this.textBox_RZ.Text + ")产品信息");
  247. //Infragistics.Excel.Worksheet sheet2 = work.Worksheets.Add("网上销售(" + this.textBox_RZ.Text + ")质量信息");
  248. //this.ultraGridExcelExporter1.Export(this.ultraGrid1, sheet1,1,0);
  249. //this.ultraGridExcelExporter1.Export(this.ultraGrid1, sheet2, 1, 0);
  250. //Infragistics.Excel.BIFF8Writer.WriteWorkbookToFile(work, fileName);
  251. }
  252. }
  253. catch (Exception ex)
  254. {
  255. MessageBox.Show(ex.ToString());
  256. }
  257. }
  258. public void DataTabletoExcelkk(System.Data.DataTable tmpDataTable)
  259. {
  260. string fileName = saveFileDialog1.FileName;
  261. string FileName;
  262. saveFileDialog1.FileName = "网上销售(" + this.textBox_RZ.Text + ")产品信息";
  263. saveFileDialog1.DefaultExt = ".xls";
  264. saveFileDialog1.Filter = "excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
  265. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  266. {
  267. fileName = saveFileDialog1.FileName;
  268. FileName = fileName;
  269. }
  270. else
  271. {
  272. return;
  273. }
  274. string FilePath = saveFileDialog1.FileName;
  275. if (tmpDataTable == null)
  276. return;
  277. int rowNum = tmpDataTable.Rows.Count;
  278. int columnNum = tmpDataTable.Columns.Count;
  279. int rowIndex = 1;
  280. int columnIndex = 0;
  281. Excel1.Application xlApp = new Excel1.ApplicationClass();
  282. //Microsoft.Office.Interop.Excel.Application xlApp;
  283. //xlApp = new Microsoft.Office.Interop.Excel.Application();
  284. xlApp.DefaultFilePath = "";
  285. xlApp.DisplayAlerts = false;
  286. xlApp.SheetsInNewWorkbook = 1;
  287. Excel1._Workbook xlBook = (Excel1._Workbook)(xlApp.Workbooks.Add(Missing.Value));//添加新工作簿
  288. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[1];
  289. int colnum = tmpDataTable.Columns.Count;
  290. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(colnum) + "1");
  291. // Excel1.Range r = ws.get_Range("A1", "AA1");
  292. object[] objHeader = new object[colnum];
  293. //将DataTable的列名导入Excel表第一行
  294. foreach (DataColumn dc in tmpDataTable.Columns)
  295. {
  296. objHeader[columnIndex] = dc.Caption;
  297. columnIndex++;
  298. }
  299. r.Value2 = objHeader;
  300. //将DataTable中的数据导入Excel中
  301. for (int i = 0; i < rowNum; i++)
  302. {
  303. rowIndex++;
  304. columnIndex = 0;
  305. for (int j = 0; j < columnNum; j++)
  306. {
  307. objHeader[columnIndex] = tmpDataTable.Rows[i][j].ToString();
  308. columnIndex++;
  309. }
  310. r = ws.get_Range("A" + (i + 2), NumToExeclRowStr(colnum) + (i + 2));
  311. r.Value2 = objHeader;
  312. }
  313. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  314. Excel1.Range RMXNEW;
  315. string Inf0 = "";
  316. Inf0 = "V1:" + "V2";
  317. RMXNEW = ws.get_Range(Inf0, Type.Missing);
  318. RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  319. RMXNEW.EntireColumn.NumberFormat = "0";
  320. Excel1.Range RMXNEW1;
  321. string Inf1 = "";
  322. Inf1 = "W1:" + "W2";
  323. RMXNEW1 = ws.get_Range(Inf1, Type.Missing);
  324. RMXNEW1.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  325. RMXNEW1.EntireColumn.NumberFormat = "0";
  326. ////导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  327. //Excel1.Range RMX1;
  328. //string Inf1 = "";
  329. //Inf1 = "A1:" + "W1";
  330. //RMX1 = ws.get_Range(Inf1, Type.Missing);
  331. //RMX1.EntireColumn.Delete(0);
  332. r.EntireColumn.AutoFit();
  333. xlBook.SaveCopyAs(FilePath);
  334. this.KillSpecialExcel(xlApp);
  335. MessageBox.Show("数据成功导出到:" + saveFileDialog1.FileName.ToString(),
  336. "导出完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
  337. //System.Diagnostics.Process.Start(fileName);
  338. }
  339. private string NumTochr(int Num)
  340. {
  341. int n = 64 + Num;
  342. return "" + (Char)n;
  343. }
  344. private string NumToExeclRowStr(int Num)
  345. {
  346. int X, Y;
  347. if (Num < 27)
  348. {
  349. return NumTochr(Num);
  350. }
  351. X = Num / 26;
  352. Y = Num - X * 26;
  353. //if (Y == 0) Y = 1;
  354. return NumTochr(X) + NumTochr(Y);
  355. }
  356. //单独作为一个excel表导出
  357. public void DataTabletoExcelULTRA(UltraGrid tmpDataTable,string rFileName)
  358. {
  359. string fileName = saveFileDialog1.FileName;
  360. string FileName;
  361. saveFileDialog1.FileName = rFileName;
  362. saveFileDialog1.DefaultExt = ".xls";
  363. saveFileDialog1.Filter = "excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
  364. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  365. {
  366. fileName = saveFileDialog1.FileName;
  367. FileName = fileName;
  368. }
  369. else
  370. {
  371. return;
  372. }
  373. string FilePath = saveFileDialog1.FileName;
  374. if (tmpDataTable == null)
  375. return;
  376. int rowNum = tmpDataTable.Rows.Count;
  377. int columnNum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count - 1;
  378. int rowIndex = 1;
  379. int columnIndex = 0;
  380. Excel1.Application xlApp = new Excel1.ApplicationClass();
  381. //Microsoft.Office.Interop.Excel.Application xlApp;
  382. //xlApp = new Microsoft.Office.Interop.Excel.Application();
  383. xlApp.DefaultFilePath = "";
  384. xlApp.DisplayAlerts = false;
  385. xlApp.SheetsInNewWorkbook = 1; //设置导出表格工作簿sheet数量
  386. Excel1._Workbook xlBook = (Excel1._Workbook)(xlApp.Workbooks.Add(Missing.Value));//添加新工作簿
  387. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[1];
  388. ws.Name = rFileName;
  389. //int colnum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count;
  390. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(columnNum - 1) + "1");
  391. // Excel1.Range r = ws.get_Range("A1", "AA1");
  392. object[] objHeader = new object[columnNum];
  393. //将DataTable的列名导入Excel表第一行
  394. foreach (UltraGridColumn dc in tmpDataTable.DisplayLayout.Bands[0].Columns)
  395. {
  396. if (columnIndex < columnNum - 1)
  397. {
  398. objHeader[columnIndex] = dc.Header.Caption;
  399. columnIndex++;
  400. }
  401. }
  402. r.Value2 = objHeader;
  403. //将DataTable中的数据导入Excel中
  404. int h = 0;
  405. for (int i = 0; i < rowNum; i++)
  406. {
  407. if (tmpDataTable.Rows[i].Cells[columnNum].Text.ToString() == "True")
  408. {
  409. rowIndex++;
  410. columnIndex = 0;
  411. for (int j = 0; j < columnNum - 1; j++)
  412. {
  413. objHeader[columnIndex] = tmpDataTable.Rows[h].Cells[j].Text.ToString();
  414. columnIndex++;
  415. }
  416. r = ws.get_Range("A" + (h + 2), NumToExeclRowStr(columnNum) + (h + 2));
  417. r.Value2 = objHeader;
  418. h++;
  419. }
  420. }
  421. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  422. Excel1.Range RMXNEW;
  423. string Inf0 = "";
  424. Inf0 = "V1:" + "V2";
  425. RMXNEW = ws.get_Range(Inf0, Type.Missing);
  426. RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  427. RMXNEW.EntireColumn.NumberFormat = "0";
  428. Excel1.Range RMXNEW1;
  429. string Inf1 = "";
  430. Inf1 = "W1:" + "W2";
  431. RMXNEW1 = ws.get_Range(Inf1, Type.Missing);
  432. RMXNEW1.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  433. RMXNEW1.EntireColumn.NumberFormat = "0";
  434. ////导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  435. //Excel1.Range RMX1;
  436. //string Inf1 = "";
  437. //Inf1 = "A1:" + "W1";
  438. //RMX1 = ws.get_Range(Inf1, Type.Missing);
  439. //RMX1.EntireColumn.Delete(0);
  440. r.EntireColumn.AutoFit();
  441. xlBook.SaveCopyAs(FilePath);
  442. this.KillSpecialExcel(xlApp);
  443. MessageBox.Show("数据成功导出到:" + saveFileDialog1.FileName.ToString(),
  444. "导出完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
  445. //System.Diagnostics.Process.Start(fileName);
  446. }
  447. //将两个表的数据作为sheet导出到一个excel中
  448. public void DataTabletoExcelULTRA2(UltraGrid tmpDataTable)
  449. {
  450. string fileName = saveFileDialog1.FileName;
  451. string FileName;
  452. saveFileDialog1.FileName = "网上销售(" + this.textBox_RZ.Text + ")产品信息";
  453. saveFileDialog1.DefaultExt = ".xls";
  454. saveFileDialog1.Filter = "excel文件(*.xls)|*.xls|所有文件(*.*)|*.*";
  455. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  456. {
  457. fileName = saveFileDialog1.FileName;
  458. FileName = fileName;
  459. }
  460. else
  461. {
  462. return;
  463. }
  464. string FilePath = saveFileDialog1.FileName;
  465. if (tmpDataTable == null)
  466. return;
  467. int rowNum = tmpDataTable.Rows.Count;
  468. int columnNum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count-1;
  469. int rowIndex = 1;
  470. int columnIndex = 0;
  471. Excel1.Application xlApp = new Excel1.ApplicationClass();
  472. //Microsoft.Office.Interop.Excel.Application xlApp;
  473. //xlApp = new Microsoft.Office.Interop.Excel.Application();
  474. xlApp.DefaultFilePath = "";
  475. xlApp.DisplayAlerts = false;
  476. xlApp.SheetsInNewWorkbook = 2; //设置导出表格工作簿sheet数量
  477. Excel1._Workbook xlBook = (Excel1._Workbook)(xlApp.Workbooks.Add(Missing.Value));//添加新工作簿
  478. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[1];
  479. ws.Name = "网上销售(" + this.textBox_RZ.Text + ")产品信息";
  480. //int colnum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count;
  481. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(columnNum - 1) + "1");
  482. // Excel1.Range r = ws.get_Range("A1", "AA1");
  483. object[] objHeader = new object[columnNum];
  484. //将DataTable的列名导入Excel表第一行
  485. foreach (UltraGridColumn dc in tmpDataTable.DisplayLayout.Bands[0].Columns)
  486. {
  487. if (columnIndex < columnNum - 1)
  488. {
  489. objHeader[columnIndex] = dc.Header.Caption;
  490. columnIndex++;
  491. }
  492. }
  493. r.Value2 = objHeader;
  494. //将DataTable中的数据导入Excel中
  495. int h = 0;
  496. for (int i = 0; i < rowNum; i++)
  497. {
  498. if (tmpDataTable.Rows[i].Cells[columnNum].Text.ToString() == "True")
  499. {
  500. rowIndex++;
  501. columnIndex = 0;
  502. for (int j = 0; j < columnNum-1; j++)
  503. {
  504. objHeader[columnIndex] = tmpDataTable.Rows[h].Cells[j].Text.ToString();
  505. columnIndex++;
  506. }
  507. r = ws.get_Range("A" + (h + 2), NumToExeclRowStr(columnNum) + (h + 2));
  508. r.Value2 = objHeader;
  509. h++;
  510. }
  511. }
  512. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  513. Excel1.Range RMXNEW;
  514. string Inf0 = "";
  515. Inf0 = "V1:" + "V2";
  516. RMXNEW = ws.get_Range(Inf0, Type.Missing);
  517. RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  518. RMXNEW.EntireColumn.NumberFormat = "0";
  519. Excel1.Range RMXNEW1;
  520. string Inf1 = "";
  521. Inf1 = "W1:" + "W2";
  522. RMXNEW1 = ws.get_Range(Inf1, Type.Missing);
  523. RMXNEW1.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  524. RMXNEW1.EntireColumn.NumberFormat = "0";
  525. ////导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  526. //Excel1.Range RMX1;
  527. //string Inf1 = "";
  528. //Inf1 = "A1:" + "W1";
  529. //RMX1 = ws.get_Range(Inf1, Type.Missing);
  530. //RMX1.EntireColumn.Delete(0);
  531. r.EntireColumn.AutoFit();
  532. xlBook = xlBookAddSheet2(ultraGrid1, xlBook); //获得第2个sheet的质量数据
  533. xlBook.SaveCopyAs(FilePath);
  534. this.KillSpecialExcel(xlApp);
  535. MessageBox.Show("数据成功导出到:" + saveFileDialog1.FileName.ToString(),
  536. "导出完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
  537. saveWGCoil(); //导出网购卷同时保存钢卷到网购卷记录表中
  538. //System.Diagnostics.Process.Start(fileName);
  539. }
  540. //在同一个excel表中添加质量信息工作表sheet
  541. public Excel1._Workbook xlBookAddSheet2(UltraGrid tmpDataTable, Excel1._Workbook xlBook)
  542. {
  543. if (tmpDataTable == null)
  544. return xlBook;
  545. int rowNum = tmpDataTable.Rows.Count;
  546. int columnNum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count-1;
  547. int rowIndex = 1;
  548. int columnIndex = 0;
  549. Excel1.Worksheet ws = (Excel1.Worksheet)xlBook.Worksheets[2];
  550. ws.Name = "质量信息";
  551. //int colnum = tmpDataTable.DisplayLayout.Bands[0].Columns.Count;
  552. Excel1.Range r = ws.get_Range("A1", NumToExeclRowStr(columnNum-1) + "1");
  553. // Excel1.Range r = ws.get_Range("A1", "AA1");
  554. object[] objHeader = new object[columnNum];
  555. //将DataTable的列名导入Excel表第一行
  556. foreach (UltraGridColumn dc in tmpDataTable.DisplayLayout.Bands[0].Columns)
  557. {
  558. if (columnIndex < columnNum - 1)
  559. {
  560. objHeader[columnIndex] = dc.Header.Caption;
  561. columnIndex++;
  562. }
  563. }
  564. r.Value2 = objHeader;
  565. //将DataTable中的数据导入Excel中
  566. int h = 0;
  567. for (int i = 0; i < rowNum; i++)
  568. {
  569. if (tmpDataTable.Rows[i].Cells[columnNum].Text.ToString() == "True")
  570. {
  571. rowIndex++;
  572. columnIndex = 0;
  573. for (int j = 0; j < columnNum-1; j++)
  574. {
  575. objHeader[columnIndex] = tmpDataTable.Rows[h].Cells[j].Text.ToString();
  576. columnIndex++;
  577. }
  578. r = ws.get_Range("A" + (h + 2), NumToExeclRowStr(columnNum-1) + (h + 2));
  579. r.Value2 = objHeader;
  580. h++;
  581. }
  582. }
  583. //将合同号的数据转换为excel中的数字格式,否则为科学计数法格式
  584. Excel1.Range RMXNEW;
  585. string Inf0 = "";
  586. Inf0 = "V1:" + "V2";
  587. RMXNEW = ws.get_Range(Inf0, Type.Missing);
  588. RMXNEW.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  589. RMXNEW.EntireColumn.NumberFormat = "0";
  590. Excel1.Range RMXNEW1;
  591. string Inf1 = "";
  592. Inf1 = "W1:" + "W2";
  593. RMXNEW1 = ws.get_Range(Inf1, Type.Missing);
  594. RMXNEW1.EntireColumn.HorizontalAlignment = Excel1.XlHAlign.xlHAlignCenter;
  595. RMXNEW1.EntireColumn.NumberFormat = "0";
  596. ////导出到EXCEL中 只需要某些列,下面删除多余的列(已经在datatable中按字段排好序)
  597. //Excel1.Range RMX1;
  598. //string Inf1 = "";
  599. //Inf1 = "A1:" + "W1";
  600. //RMX1 = ws.get_Range(Inf1, Type.Missing);
  601. //RMX1.EntireColumn.Delete(0);
  602. r.EntireColumn.AutoFit();
  603. return xlBook;
  604. }
  605. #region 结束EXCEL.EXE进程的方法
  606. /// <summary>
  607. /// 结束EXCEL.EXE进程的方法
  608. /// </summary>
  609. /// <param name="m_objExcel">EXCEL对象</param>
  610. [DllImport("user32.dll", SetLastError = true)]
  611. static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);
  612. public void KillSpecialExcel(Microsoft.Office.Interop.Excel.Application m_objExcel)
  613. {
  614. try
  615. {
  616. if (m_objExcel != null)
  617. {
  618. int lpdwProcessId;
  619. GetWindowThreadProcessId(new IntPtr(m_objExcel.Hwnd), out lpdwProcessId);
  620. System.Diagnostics.Process.GetProcessById(lpdwProcessId).Kill();
  621. }
  622. }
  623. catch (Exception ex)
  624. {
  625. MessageBox.Show(ex.Message);
  626. }
  627. }
  628. #endregion
  629. private void button1_Click(object sender, EventArgs e)
  630. {
  631. this.DoExport();
  632. }
  633. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  634. {
  635. try
  636. {
  637. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  638. {
  639. ugr.Cells["CHK"].Value = this.checkBox1.Checked;
  640. foreach (UltraGridRow ugr2 in this.ultraGrid2.Rows)
  641. {
  642. ugr2.Cells["CHK"].Value = this.checkBox1.Checked;
  643. }
  644. this.ultraGrid2.UpdateData();
  645. }
  646. this.ultraGrid1.UpdateData();
  647. }
  648. catch (Exception ex)
  649. {
  650. System.Diagnostics.Debug.WriteLine(ex.ToString());
  651. }
  652. }
  653. //把已经导出到网购的钢卷保存到网购钢卷记录表中TBC01_WSXS_COIL_COM
  654. private void saveWGCoil()
  655. {
  656. try
  657. {
  658. ArrayList list = new ArrayList();
  659. ArrayList al = null;
  660. string lineName = "C";
  661. if (this.textBox_RZ.Text == "热轧") {
  662. lineName = "H";
  663. }
  664. foreach (UltraGridRow ugr in this.ultraGrid2.Rows)
  665. {
  666. if (Convert.ToBoolean(ugr.Cells["CHK"].Text))
  667. {
  668. al = new ArrayList();
  669. string coil_no = ugr.Cells["OLD_SAMPL_NO"].Text.ToString();
  670. DataTable dttb = new DataTable();
  671. CoreClientParam ccp = new CoreClientParam();
  672. ccp.ServerName = "UIB.COM.ComDBQuery";
  673. ccp.MethodName = "doSimpleQuery";
  674. ArrayList paramArray = new ArrayList();
  675. paramArray.Add("UIM010232_WSXS.SELECT");
  676. paramArray.Add(coil_no);
  677. ccp.ServerParams = new object[] { paramArray };
  678. ccp.SourceDataTable = dttb;
  679. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  680. //判定是否存在该钢卷
  681. if (dttb.Rows.Count == 0)
  682. {
  683. al.Add("UIM010232_WSXS.INSERT");
  684. al.Add(coil_no);
  685. al.Add("Y");
  686. al.Add(lineName);
  687. al.Add("");
  688. al.Add(ugr.Cells["TESHUSHUOMING"].Text.ToString());
  689. al.Add("UIM010233.saveWGCoil");
  690. al.Add(this.UserInfo.GetUserName().ToString());
  691. list.Add(al);
  692. }
  693. //else
  694. //{
  695. // al.Add("UIM010232_WSXS.UPDATE");
  696. // al.Add("Y");
  697. // al.Add(ugr.Cells["TESHUSHUOMING"].Text.ToString());
  698. // al.Add("UIM010233.saveWGCoil");
  699. // al.Add(this.UserInfo.GetUserName().ToString());
  700. // al.Add(coil_no);
  701. //}
  702. }
  703. }
  704. if (list.Count > 0)
  705. {
  706. CoreClientParam ccp = new CoreClientParam();
  707. ccp.ServerName = "UIB.COM.ComDBSave";
  708. ccp.MethodName = "doXmlSave";
  709. ccp.ServerParams = new object[] { list };
  710. ccp.SourceDataTable = this.dataSet2.Tables[0];
  711. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  712. }
  713. if (this.textBox_RZ.Text == "热轧")
  714. {
  715. this.DoQueryRZ();
  716. }
  717. else
  718. {
  719. this.DoQuery();
  720. }
  721. this.checkBox1.Checked = false;
  722. }
  723. catch (Exception ex)
  724. {
  725. System.Diagnostics.Debug.WriteLine(ex.ToString());
  726. }
  727. }
  728. //private void ultraGrid2_DoubleClickRow(object sender, DoubleClickRowEventArgs e)
  729. //{
  730. // try
  731. // {
  732. // if (this.ultraGrid2.ActiveRow == null) return;
  733. // string clickColumnID = this.ultraGrid2.ActiveCell.Column.Key;
  734. // string OLD_SAMPL_NO = this.ultraGrid2.ActiveRow.Cells["OLD_SAMPL_NO"].Value.ToString();
  735. // string CHK_VAL = this.ultraGrid2.ActiveRow.Cells["CHK"].Value.ToString();
  736. // if (CHK_VAL == "True")
  737. // {
  738. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "False";
  739. // }
  740. // else
  741. // {
  742. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "True";
  743. // }
  744. // foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  745. // {
  746. // if (OLD_SAMPL_NO.Equals(ugr.Cells["OLD_SAMPL_NO"].Text.ToString()))
  747. // {
  748. // if (CHK_VAL == "True")
  749. // {
  750. // ugr.Cells["CHK"].Value = "False";
  751. // }
  752. // else
  753. // {
  754. // ugr.Cells["CHK"].Value = "True";
  755. // }
  756. // }
  757. // }
  758. // }
  759. // catch (Exception ex)
  760. // {
  761. // System.Diagnostics.Debug.WriteLine(ex.ToString());
  762. // }
  763. //}
  764. private void ultraGrid2_CellChange(object sender, CellEventArgs e)
  765. {
  766. try
  767. {
  768. if (this.ultraGrid2.ActiveRow == null) return;
  769. string clickColumnID = this.ultraGrid2.ActiveCell.Column.Key;
  770. if (clickColumnID.Equals("CHK"))
  771. {
  772. string OLD_SAMPL_NO = this.ultraGrid2.ActiveRow.Cells["OLD_SAMPL_NO"].Value.ToString();
  773. string CHK_VAL = this.ultraGrid2.ActiveRow.Cells["CHK"].Text.ToString();
  774. //if (CHK_VAL == "True")
  775. //{
  776. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "False";
  777. //}
  778. //else
  779. //{
  780. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "True";
  781. //}
  782. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  783. {
  784. if (OLD_SAMPL_NO.Equals(ugr.Cells["OLD_SAMPL_NO"].Text.ToString()))
  785. {
  786. if (CHK_VAL == "True")
  787. {
  788. ugr.Cells["CHK"].Value = "True";
  789. }
  790. else
  791. {
  792. ugr.Cells["CHK"].Value = "False";
  793. }
  794. }
  795. }
  796. }
  797. }
  798. catch (Exception ex)
  799. {
  800. System.Diagnostics.Debug.WriteLine(ex.ToString());
  801. }
  802. }
  803. private void ultraGrid1_CellChange(object sender, CellEventArgs e)
  804. {
  805. try
  806. {
  807. if (this.ultraGrid1.ActiveRow == null) return;
  808. string clickColumnID = this.ultraGrid1.ActiveCell.Column.Key;
  809. if (clickColumnID.Equals("CHK"))
  810. {
  811. string OLD_SAMPL_NO = this.ultraGrid1.ActiveRow.Cells["OLD_SAMPL_NO"].Value.ToString();
  812. string CHK_VAL = this.ultraGrid1.ActiveRow.Cells["CHK"].Text.ToString();
  813. //if (CHK_VAL == "True")
  814. //{
  815. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "False";
  816. //}
  817. //else
  818. //{
  819. // this.ultraGrid2.ActiveRow.Cells["CHK"].Value = "True";
  820. //}
  821. foreach (UltraGridRow ugr in this.ultraGrid2.Rows)
  822. {
  823. if (OLD_SAMPL_NO.Equals(ugr.Cells["OLD_SAMPL_NO"].Text.ToString()))
  824. {
  825. if (CHK_VAL == "True")
  826. {
  827. ugr.Cells["CHK"].Value = "True";
  828. }
  829. else
  830. {
  831. ugr.Cells["CHK"].Value = "False";
  832. }
  833. }
  834. }
  835. }
  836. }
  837. catch (Exception ex)
  838. {
  839. System.Diagnostics.Debug.WriteLine(ex.ToString());
  840. }
  841. }
  842. }
  843. }