ed3fb8cb7e762d4cb94e0972263d219f27cdaa26.svn-base 34 KB

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