UIM010061.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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.Windows.Forms;
  10. using CoreFS.CA06;
  11. namespace Core.LZMes.Client.UIM
  12. {
  13. public partial class UIM010061 : FrmBase
  14. {
  15. int queryType = 0;
  16. string queryDate = "";
  17. public UIM010061()
  18. {
  19. InitializeComponent();
  20. }
  21. private void UIM010061_Load(object sender, EventArgs e)
  22. {
  23. //默认查询入库记录
  24. this.ultraComboEditor1.Value = 0;
  25. this.QueryCustomers();//查询并显示收货单位
  26. }
  27. public override void ToolBar_Click(object sender, string ToolbarKey)
  28. {
  29. switch (ToolbarKey)
  30. {
  31. case "Query":
  32. this.DoQuery();
  33. break;
  34. case "Export":
  35. this.DoExport();
  36. break;
  37. case "Exit":
  38. this.Close();
  39. break;
  40. }
  41. }
  42. /// <summary>
  43. /// 查询原料库钢卷出入库记录
  44. /// </summary>
  45. private void DoQuery()
  46. {
  47. try
  48. {
  49. this.dataSet1.Tables[0].Clear();
  50. string startTime = this.ultraDateTimeEditor1.DateTime.ToString("yyyyMMdd");//开始时间
  51. queryDate = this.ultraDateTimeEditor1.DateTime.ToString("yyyy/MM/dd");
  52. string endTime = this.ultraDateTimeEditor2.DateTime.ToString("yyyyMMdd");//结束时间
  53. queryType = int.Parse(this.ultraComboEditor1.Value.ToString());//查询类型 0 入库记录 1 出库记录
  54. string specStlGrd = this.textBox3.Text.Trim();//牌号
  55. string coilWthMin = this.textBox4.Text.Trim();//宽度最小值
  56. string coilWthMax = this.textBox5.Text.Trim();//宽度最大值
  57. string coilThkMin = this.textBox6.Text.Trim();//厚度最小值
  58. string coilThkMax = this.textBox7.Text.Trim();//厚度最大值
  59. string curLoadLoc = this.textBox8.Text.Trim();//垛位
  60. string coilNo = this.textBox9.Text.Trim();//轧批号
  61. string coilNo1 = this.textBox13.Text.Trim();//轧批号
  62. string coilNo2 = this.textBox14.Text.Trim();//钢卷号
  63. string shift = -1 == this.ultraComboEditor2.SelectedIndex ? "" : this.ultraComboEditor2.Value.ToString();//班次
  64. string group = -1 == this.ultraComboEditor3.SelectedIndex ? "" : this.ultraComboEditor3.Value.ToString();//班组
  65. string regId = this.textBox10.Text.Trim();//作业人
  66. string custCd = -1 == this.ultraComboEditor4.SelectedIndex ? "" : this.ultraComboEditor4.Value.ToString();//客户编号
  67. string ordNo = this.textBox11.Text.Trim();//订单号
  68. string ordSeq = this.textBox12.Text.Trim();//合同号
  69. string ordFl = -1 == this.ultraComboEditor5.SelectedIndex ? "" : this.ultraComboEditor5.Value.ToString();//订单区分
  70. string prodnmCd = -1 == this.ultraComboEditor6.SelectedIndex ? "" : this.ultraComboEditor6.Value.ToString();//产品类型
  71. string outType = -1 == this.ultraComboEditor7.SelectedIndex ? "" : this.ultraComboEditor7.Value.ToString();//出库类型
  72. string[] queryParams = new string[] { startTime, endTime, specStlGrd, coilWthMin, coilWthMax,
  73. coilThkMin, coilThkMax, curLoadLoc, coilNo,coilNo1, shift, group, regId, custCd, ordNo, ordSeq,
  74. ordFl, prodnmCd,outType,coilNo2 };
  75. List<string[]> list = new List<String[]>();
  76. list.Add(queryParams);
  77. CoreClientParam ccp = new CoreClientParam();
  78. ccp.ServerName = "UIM.UIM010060";
  79. ccp.MethodName = "queryYardList";
  80. ccp.ServerParams = new object[] { queryType, list };
  81. ccp.SourceDataTable = this.dataSet1.Tables[0];
  82. this.ExecuteQueryToDataTable(ccp, CoreInvokeType.Internal);
  83. DataRowCollection drs = this.dataSet1.Tables[0].Rows;
  84. int coilCount = 0;
  85. double wgtCount = 0;
  86. int drsSize = drs.Count;
  87. coilCount = drsSize;
  88. for (int i = 0; i < drsSize; i++)
  89. {
  90. //wgtCount += double.Parse(drs[i]["ACT_WGT"].ToString());
  91. // double actWgt = 0;
  92. try
  93. {
  94. // actWgt = double.Parse(drs[i]["ACT_WGT"].ToString());
  95. wgtCount += double.Parse(drs[i]["ACT_WGT"].ToString());
  96. }
  97. catch (Exception e)
  98. {
  99. }
  100. // wgtCount += actWgt;
  101. }
  102. this.textBox1.Text = coilCount.ToString();
  103. this.textBox2.Text = (wgtCount/1000).ToString();
  104. }
  105. catch (Exception EX)
  106. {
  107. MessageBox.Show(EX.ToString());
  108. }
  109. }
  110. /// <summary>
  111. /// 查询并显示收货单位
  112. /// </summary>
  113. private void QueryCustomers()
  114. {
  115. CoreClientParam ccp = new CoreClientParam();
  116. ccp.ServerName = "UIM.UIM010060";
  117. ccp.MethodName = "queryCustomers";
  118. ccp = this.ExecuteQuery(ccp, CoreInvokeType.Internal);
  119. ArrayList custList = (ArrayList)ccp.ReturnObject;
  120. int listSize = custList.Count;
  121. Infragistics.Win.ValueListItem[] valueListItems = new Infragistics.Win.ValueListItem[listSize];
  122. for (int i = 0; i < listSize; i++)
  123. {
  124. Infragistics.Win.ValueListItem item = new Infragistics.Win.ValueListItem();
  125. Hashtable ht = (Hashtable)custList[i];
  126. item.DataValue = ht["VALUE"].ToString();
  127. object obj = ht["LABEL"];
  128. if (obj != null)
  129. {
  130. item.DisplayText = ht["LABEL"].ToString();
  131. }
  132. else
  133. {
  134. item.DisplayText = "";
  135. }
  136. valueListItems[i] = item;
  137. }
  138. this.ultraComboEditor4.Items.AddRange(valueListItems);
  139. }
  140. /// <summary>
  141. /// 导出出入库记录
  142. /// </summary>
  143. private void DoExport()
  144. {
  145. try
  146. {
  147. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  148. {
  149. //改字体
  150. this.ultraGrid1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  151. // 重量改为t
  152. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ultraGrid1.Rows)
  153. {
  154. double tempWGT;
  155. double.TryParse(row.Cells["ACT_WGT"].Value.ToString(), out tempWGT);
  156. tempWGT = tempWGT * 0.001;
  157. row.Cells["ACT_WGT"].Value = tempWGT.ToString();
  158. }
  159. ultraGrid1.UpdateData();
  160. string fileName = this.saveFileDialog1.FileName;
  161. string exportName = "原料";
  162. string operation = queryDate;
  163. operation += " ";
  164. operation += tools.UserInfoExt.Get_UserOrder(UserInfo) + "/" + tools.UserInfoExt.Get_UserGroup(UserInfo);
  165. operation += " 制表人:";
  166. operation += UserInfo.GetUserName();
  167. this.ultraGrid1.DisplayLayout.Bands[0].Columns["YARD_ENTRY_DTIME"].Hidden = true;
  168. this.ultraGrid1.DisplayLayout.Bands[0].Columns["PRODNM_CD"].Hidden = true;
  169. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CZSJ"].Hidden = true;
  170. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SHIFT"].Hidden = true;
  171. this.ultraGrid1.DisplayLayout.Bands[0].Columns["WKGROUP"].Hidden = true;
  172. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CZR"].Hidden = true;
  173. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INGR_DEC_GRD"].Hidden = true;
  174. this.ultraGrid1.DisplayLayout.Bands[0].Columns["MATLQLTY_DEC_GRD"].Hidden = true;
  175. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SIZE_DEC_RST"].Hidden = true;
  176. this.ultraGrid1.DisplayLayout.Bands[0].Columns["EXTSHAPE_DEC_GRD"].Hidden = true;
  177. this.ultraGrid1.DisplayLayout.Bands[0].Columns["WGT_DEC_RST"].Hidden = true;
  178. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORD_NO"].Hidden = true;
  179. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORD_SEQ"].Hidden = true;
  180. this.ultraGrid1.DisplayLayout.Bands[0].Columns["DLIV_TP"].Hidden = true;
  181. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORDCUST_CD"].Hidden = true;
  182. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CHARGE_NO"].Hidden = true;
  183. this.ultraGrid1.DisplayLayout.Bands[0].Columns["TRNF_DTIME"].Hidden = true;
  184. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_LEN"].Hidden = true;
  185. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_INDIA"].Hidden = true;
  186. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_OUTDIA"].Hidden = true;
  187. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_WGT"].Hidden = true;
  188. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_LEN"].Hidden = true;
  189. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_INDIA"].Hidden = true;
  190. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_OUTDIA"].Hidden = true;
  191. if (queryType == 0)
  192. {
  193. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ZPH"].Hidden = true;
  194. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["OLD_SAMPL_NO"].Hidden = true;
  195. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["SPEC_STL_GRD"].Hidden = true;
  196. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ACT_WGT"].Hidden = true;
  197. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["CUR_LOAD_LOC"].Hidden = true;
  198. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["TOT_DEC_GRD"].Hidden = true;
  199. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["IN_YARD_KIND"].Hidden = true;
  200. this.ultraGrid1.DisplayLayout.Bands[0].Columns["OUT_YARD_KIND"].Hidden = true;
  201. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["HOUKUAN"].Hidden = true;
  202. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["NHOUKUAN"].Hidden = true;
  203. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ROWNUM"].Hidden = true;
  204. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["BEF_STL_GRD"].Hidden = true;
  205. exportName += "入库单";
  206. }
  207. else
  208. {
  209. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ZPH"].Hidden = true;
  210. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["OLD_SAMPL_NO"].Hidden = true;
  211. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["SPEC_STL_GRD"].Hidden = true;
  212. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ACT_WGT"].Hidden = true;
  213. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CUR_LOAD_LOC"].Hidden = true;
  214. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["TOT_DEC_GRD"].Hidden = true;
  215. this.ultraGrid1.DisplayLayout.Bands[0].Columns["IN_YARD_KIND"].Hidden = true;
  216. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["OUT_YARD_KIND"].Hidden = true;
  217. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["HOUKUAN"].Hidden = true;
  218. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["NHOUKUAN"].Hidden = true;
  219. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ROWNUM"].Hidden = true;
  220. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["SPEC_STL_GRD"].Hidden = true;
  221. exportName += "出库单";
  222. }
  223. this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.None;
  224. ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  225. if (isExcelInstalled())
  226. {
  227. Microsoft.Office.Interop.Excel.Application excel;
  228. Microsoft.Office.Interop.Excel._Workbook objBook;
  229. Microsoft.Office.Interop.Excel.Workbooks objBooks;//接口 workbooks
  230. Microsoft.Office.Interop.Excel.Sheets objSheets;// 接口 sheets
  231. Microsoft.Office.Interop.Excel.Worksheet objSheet;//接口 worksheet
  232. Microsoft.Office.Interop.Excel.Range range = null;
  233. try
  234. {
  235. excel = new Microsoft.Office.Interop.Excel.Application();
  236. objBooks = excel.Workbooks;
  237. //Object miss = System.Reflection.Missing.Value;
  238. objBook = objBooks.Add(fileName);
  239. objSheets = objBook.Sheets;
  240. objSheet = (Microsoft.Office.Interop.Excel.Worksheet)objSheets[1];
  241. excel.Visible = false; //让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写
  242. Microsoft.Office.Interop.Excel.Range tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[1, System.Reflection.Missing.Value];
  243. tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  244. tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  245. objSheet.get_Range("A1", "I1").Merge(objSheet.get_Range("A1", "I1").MergeCells);
  246. objSheet.get_Range("A2", "I2").Merge(objSheet.get_Range("A2", "I2").MergeCells);
  247. objSheet.get_Range("A1", "I1").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
  248. objSheet.get_Range("A2", "I2").VerticalAlignment = Microsoft.Office.Interop.Excel.XlVAlign.xlVAlignCenter;
  249. objSheet.get_Range("A1", "I1").HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
  250. objSheet.get_Range("A2", "I2").HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignLeft;
  251. ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Font.Size = 24;
  252. ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).RowHeight = 45;
  253. ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Font.Bold = true;
  254. ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[1, 1]).Interior.Color = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
  255. ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[2, 1]).Interior.Color = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
  256. excel.Cells[1, 1] = exportName;
  257. excel.Cells[2, 1] = operation;
  258. int iRowCnt = objSheet.UsedRange.Cells.Rows.Count;
  259. int iBgnRow = (objSheet.UsedRange.Cells.Row > 3 ? objSheet.UsedRange.Cells.Row : objSheet.UsedRange.Cells.Row + 1) + 1;
  260. int insertIdx = iRowCnt - 1,insertIdx1 = iRowCnt-1;
  261. string befStlStr = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 4 : 5]).Text.ToString();
  262. string befThkStr = GetThickBySize(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 5 : 6]).Text.ToString());
  263. string curStlStr = string.Empty, curThkStr = string.Empty;
  264. int coilCount = 0,coilCount1 = 0;
  265. double weightSum = 0,weightSum1 = 0;
  266. for (int i = iRowCnt - 2; i >= iBgnRow; i--)
  267. {
  268. curStlStr = ((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 4 : 5]).Text.ToString();
  269. curThkStr = GetThickBySize(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 5 : 6]).Text.ToString());
  270. if (!befStlStr.Equals(curStlStr) || !befThkStr.Equals(curThkStr))
  271. {
  272. if (!befStlStr.Equals(curStlStr))
  273. {
  274. tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[insertIdx1, System.Reflection.Missing.Value];
  275. tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  276. excel.Cells[insertIdx1, queryType == 0 ? 3 : 4] = coilCount1.ToString();
  277. excel.Cells[insertIdx1, queryType == 0 ? 8 : 9] = weightSum1.ToString();
  278. coilCount1 = 0;
  279. weightSum1 = 0;
  280. insertIdx1 = i;
  281. }
  282. tmpRange = (Microsoft.Office.Interop.Excel.Range)objSheet.Rows[insertIdx, System.Reflection.Missing.Value];
  283. tmpRange.Insert(Microsoft.Office.Interop.Excel.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  284. excel.Cells[insertIdx, queryType == 0 ? 3 : 4] = coilCount.ToString();
  285. excel.Cells[insertIdx, queryType == 0 ? 8 : 9] = weightSum.ToString();
  286. coilCount = 0;
  287. weightSum = 0;
  288. insertIdx = i + 1;
  289. insertIdx1++;
  290. }
  291. if (i > iBgnRow)
  292. {
  293. coilCount++;
  294. weightSum += Convert.ToDouble(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 8 : 9]).Text);
  295. coilCount1++;
  296. weightSum1 += Convert.ToDouble(((Microsoft.Office.Interop.Excel.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 8 : 9]).Text);
  297. }
  298. befStlStr = curStlStr;
  299. befThkStr = curThkStr;
  300. }
  301. objBook.SaveCopyAs(fileName);
  302. //设置禁止弹出保存和覆盖的询问提示框
  303. excel.DisplayAlerts = false;
  304. excel.AlertBeforeOverwriting = false;
  305. //确保Excel进程关闭
  306. objBooks.Close();
  307. excel.Workbooks.Close();
  308. excel.Quit();
  309. System.Runtime.InteropServices.Marshal.ReleaseComObject(objBook);
  310. System.Runtime.InteropServices.Marshal.ReleaseComObject(objBooks);
  311. System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
  312. GC.Collect();
  313. System.GC.WaitForPendingFinalizers();
  314. //MessageBox.Show("数据导出完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  315. if (System.IO.File.Exists(fileName))
  316. System.Diagnostics.Process.Start(fileName); //保存成功后打开此文件
  317. }
  318. catch (Exception ex)
  319. {
  320. MessageBox.Show(ex.Message, "错误提示");
  321. }
  322. }
  323. else
  324. {
  325. ET.Application excel;
  326. ET._Workbook objBook;
  327. ET.Workbooks objBooks;//接口 workbooks
  328. ET.Sheets objSheets;// 接口 sheets
  329. ET.Worksheet objSheet;//接口 worksheet
  330. ET.Range range = null;
  331. try
  332. {
  333. excel = new ET.Application();
  334. objBooks = excel.Workbooks;
  335. //Object miss = System.Reflection.Missing.Value;
  336. objBook = objBooks.Add(fileName);
  337. objSheets = objBook.Sheets;
  338. objSheet = (ET.Worksheet)objSheets[1];
  339. excel.Visible = false; //让后台执行设置为不可见,为true的话会看到打开一个Excel,然后数据在往里写
  340. ET.Range tmpRange = (ET.Range)objSheet.Rows[1, System.Reflection.Missing.Value];
  341. tmpRange.Insert(ET.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  342. tmpRange.Insert(ET.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  343. objSheet.get_Range("A1", "I1").Merge(true);
  344. objSheet.get_Range("A2", "I2").Merge(true);
  345. objSheet.get_Range("A1", "I1").VerticalAlignment = ET.ETVAlign.etVAlignCenter;
  346. objSheet.get_Range("A2", "I2").VerticalAlignment = ET.ETVAlign.etVAlignCenter;
  347. objSheet.get_Range("A1", "I1").HorizontalAlignment = ET.ETHAlign.etHAlignCenter;
  348. objSheet.get_Range("A2", "I2").HorizontalAlignment = ET.ETHAlign.etHAlignLeft;
  349. ((ET.Range)objSheet.UsedRange.Cells[1, 1]).Font.Size = 24;
  350. ((ET.Range)objSheet.UsedRange.Cells[1, 1]).RowHeight = 45;
  351. ((ET.Range)objSheet.UsedRange.Cells[1, 1]).Font.Bold = true;
  352. ((ET.Range)objSheet.UsedRange.Cells[1, 1]).Interior.Color = ((ET.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
  353. ((ET.Range)objSheet.UsedRange.Cells[2, 1]).Interior.Color = ((ET.Range)objSheet.UsedRange.Cells[4, 1]).Interior.Color;
  354. excel.Cells[1, 1] = exportName;
  355. excel.Cells[2, 1] = operation;
  356. int iRowCnt = objSheet.UsedRange.Cells.Rows.Count;
  357. int iBgnRow = (objSheet.UsedRange.Cells.Row > 3 ? objSheet.UsedRange.Cells.Row : objSheet.UsedRange.Cells.Row + 1) + 1;
  358. int insertIdx = iRowCnt - 1;
  359. string befStlStr = ((ET.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 4 : 5]).Text.ToString();
  360. string befThkStr = GetThickBySize(((ET.Range)objSheet.UsedRange.Cells[insertIdx - 1, queryType == 0 ? 5 : 6]).Text.ToString());
  361. string curStlStr = string.Empty, curThkStr = string.Empty;
  362. int coilCount = 0;
  363. double weightSum = 0;
  364. for (int i = iRowCnt - 2; i >= iBgnRow; i--)
  365. {
  366. curStlStr = ((ET.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 4 : 5]).Text.ToString();
  367. curThkStr = GetThickBySize(((ET.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 5 : 6]).Text.ToString());
  368. if (befStlStr.Equals(curStlStr) && befThkStr.Equals(curThkStr))
  369. {
  370. //coilCount++;
  371. //weightSum += Convert.ToDouble(((ET.Range)objSheet.UsedRange.Cells[i, 7]).Text);
  372. }
  373. else
  374. {
  375. tmpRange = (ET.Range)objSheet.Rows[insertIdx, System.Reflection.Missing.Value];
  376. tmpRange.Insert(ET.XlInsertShiftDirection.xlShiftDown, System.Reflection.Missing.Value);
  377. excel.Cells[insertIdx, queryType == 0 ? 3 : 4] = coilCount.ToString();
  378. excel.Cells[insertIdx, queryType == 0 ? 8 : 9] = weightSum.ToString();
  379. coilCount = 0;
  380. weightSum = 0;
  381. insertIdx = i + 1;
  382. }
  383. if (i > iBgnRow)
  384. {
  385. coilCount++;
  386. weightSum += Convert.ToDouble(((ET.Range)objSheet.UsedRange.Cells[i, queryType == 0 ? 8 :9]).Text);
  387. }
  388. befStlStr = curStlStr;
  389. befThkStr = curThkStr;
  390. }
  391. System.Reflection.Missing miss = System.Reflection.Missing.Value;
  392. objBook.SaveAs(fileName, miss, miss, miss, miss, miss, ET.ETSaveAsAccessMode.etNoChange, miss, miss, miss, miss);
  393. //objBook.SaveCopyAs(fileName);
  394. //设置禁止弹出保存和覆盖的询问提示框
  395. excel.DisplayAlerts = false;
  396. //excel.AlertBeforeOverwriting = false;
  397. //确保Excel进程关闭
  398. objBooks.Close(false);
  399. excel.Workbooks.Close(false);
  400. excel.Quit();
  401. System.Runtime.InteropServices.Marshal.ReleaseComObject(objBook);
  402. System.Runtime.InteropServices.Marshal.ReleaseComObject(objBooks);
  403. System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
  404. GC.Collect();
  405. System.GC.WaitForPendingFinalizers();
  406. //MessageBox.Show("数据导出完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  407. if (System.IO.File.Exists(fileName))
  408. System.Diagnostics.Process.Start(fileName); //保存成功后打开此文件
  409. }
  410. catch (Exception ex)
  411. {
  412. MessageBox.Show(ex.Message, "错误提示");
  413. }
  414. }
  415. this.ultraGrid1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  416. foreach (Infragistics.Win.UltraWinGrid.UltraGridRow row in ultraGrid1.Rows)
  417. {
  418. double tempWGT;
  419. double.TryParse(row.Cells["ACT_WGT"].Value.ToString(), out tempWGT);
  420. tempWGT = tempWGT * 1000;
  421. row.Cells["ACT_WGT"].Value = tempWGT.ToString();
  422. }
  423. ultraGrid1.UpdateData();
  424. this.ShowColumns();
  425. }
  426. }
  427. catch (Exception ex)
  428. {
  429. MessageBox.Show(ex.ToString());
  430. }
  431. }
  432. private bool isExcelInstalled()
  433. {
  434. Type type = Type.GetTypeFromProgID("Excel.Application");
  435. return type != null;
  436. }
  437. private string GetThickBySize(string coilSize)
  438. {
  439. string thick = string.Empty;
  440. if (!string.IsNullOrEmpty(coilSize) && coilSize.Contains("*"))
  441. {
  442. thick = coilSize.Substring(0, coilSize.IndexOf("*"));
  443. }
  444. return thick;
  445. }
  446. private void ShowColumns()
  447. {
  448. this.ultraGrid1.BeginUpdate();
  449. this.ultraGrid1.DisplayLayout.Bands[0].Columns["YARD_ENTRY_DTIME"].Hidden = false;
  450. this.ultraGrid1.DisplayLayout.Bands[0].Columns["PRODNM_CD"].Hidden = false;
  451. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CZSJ"].Hidden = false;
  452. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SHIFT"].Hidden = false;
  453. this.ultraGrid1.DisplayLayout.Bands[0].Columns["WKGROUP"].Hidden = false;
  454. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CZR"].Hidden = false;
  455. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ZPH"].Hidden = false;
  456. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["OLD_SAMPL_NO"].Hidden = true;
  457. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["SPEC_STL_GRD"].Hidden = true;
  458. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ACT_WGT"].Hidden = true;
  459. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CUR_LOAD_LOC"].Hidden = false;
  460. this.ultraGrid1.DisplayLayout.Bands[0].Columns["TOT_DEC_GRD"].Hidden = false;
  461. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INGR_DEC_GRD"].Hidden = false;
  462. this.ultraGrid1.DisplayLayout.Bands[0].Columns["MATLQLTY_DEC_GRD"].Hidden = false;
  463. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SIZE_DEC_RST"].Hidden = false;
  464. this.ultraGrid1.DisplayLayout.Bands[0].Columns["EXTSHAPE_DEC_GRD"].Hidden = false;
  465. this.ultraGrid1.DisplayLayout.Bands[0].Columns["WGT_DEC_RST"].Hidden = false;
  466. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORD_NO"].Hidden = false;
  467. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORD_SEQ"].Hidden = false;
  468. this.ultraGrid1.DisplayLayout.Bands[0].Columns["DLIV_TP"].Hidden = false;
  469. this.ultraGrid1.DisplayLayout.Bands[0].Columns["ORDCUST_CD"].Hidden = false;
  470. this.ultraGrid1.DisplayLayout.Bands[0].Columns["CHARGE_NO"].Hidden = false;
  471. this.ultraGrid1.DisplayLayout.Bands[0].Columns["TRNF_DTIME"].Hidden = false;
  472. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_LEN"].Hidden = false;
  473. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_INDIA"].Hidden = false;
  474. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_OUTDIA"].Hidden = false;
  475. this.ultraGrid1.DisplayLayout.Bands[0].Columns["INSTR_COIL_WGT"].Hidden = false;
  476. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_LEN"].Hidden = false;
  477. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_INDIA"].Hidden = false;
  478. this.ultraGrid1.DisplayLayout.Bands[0].Columns["COIL_OUTDIA"].Hidden = false;
  479. this.ultraGrid1.DisplayLayout.Bands[0].Columns["IN_YARD_KIND"].Hidden = false;
  480. this.ultraGrid1.DisplayLayout.Bands[0].Columns["OUT_YARD_KIND"].Hidden = false;
  481. this.ultraGrid1.DisplayLayout.Bands[0].Columns["HOUKUAN"].Hidden = false;
  482. this.ultraGrid1.DisplayLayout.Bands[0].Columns["NHOUKUAN"].Hidden = false;
  483. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BEF_STL_GRD"].Hidden = false;
  484. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SPEC_STL_GRD"].Hidden = false;
  485. //this.ultraGrid1.DisplayLayout.Bands[0].Columns["ROWNUM"].Hidden = false;
  486. this.ultraGrid1.DisplayLayout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ExtendLastColumn;
  487. this.ultraGrid1.EndUpdate();
  488. }
  489. private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  490. {
  491. }
  492. private void button1_Click(object sender, EventArgs e)
  493. {
  494. try
  495. {
  496. if (this.saveFileDialog1.ShowDialog(this) == DialogResult.OK)
  497. {
  498. string fileName = this.saveFileDialog1.FileName;
  499. this.ultraGridExcelExporter1.Export(ultraGrid1, fileName);
  500. System.Diagnostics.Process.Start(fileName);
  501. }
  502. }
  503. catch (Exception ex)
  504. {
  505. MessageBox.Show(ex.ToString());
  506. }
  507. }
  508. }
  509. }