FrmMaterialInoutBOF.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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 Core.Mes.Client.Common;
  10. using Infragistics.Win.UltraWinGrid;
  11. using Infragistics.Win.UltraWinGrid.ExcelExport;
  12. using Infragistics.Win;
  13. using System.Collections;
  14. using CoreFS.CA06;
  15. using System.Diagnostics;
  16. using System.IO;
  17. using Core.LgMes.Client.Report;
  18. namespace Core.LgMes.Client.lgIntegrationQuery
  19. {
  20. public partial class FrmMaterialInoutBOF : frmStyleBase
  21. {
  22. private bool bAddNow, bEditNow, bDelNow;
  23. private UltraGridRow currRow = null;
  24. public FrmMaterialInoutBOF()
  25. {
  26. InitializeComponent();
  27. }
  28. private void FrmMaterialInoutBOF_Load(object sender, EventArgs e)
  29. {
  30. ultraDateTimeEditor1.DateTime = DateTime.Today;
  31. ultraDateTimeEditor2.DateTime = DateTime.Today;
  32. ValueList vl = new ValueList();
  33. vl.ValueListItems.Add("CAS", "CAS");
  34. vl.ValueListItems.Add("炉前", "炉前");
  35. vl.ValueListItems.Add("KR", "KR");
  36. this.ultraGrid1.DisplayLayout.Bands[0].Columns["STATIONCODE"].ValueList = vl;
  37. proc_SetToolbarButtons();
  38. }
  39. public override void ToolBar_Click(object sender, string ToolbarKey)
  40. {
  41. switch (ToolbarKey)
  42. {
  43. case "Query":
  44. {
  45. if (bAddNow || bEditNow || bDelNow)
  46. return;
  47. proc_Query();
  48. proc_SetToolbarButtons();
  49. break;
  50. }
  51. case "Add":
  52. {
  53. if (bAddNow || bEditNow || bDelNow)
  54. return;
  55. currRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  56. this.proc_setCellReadOnly(currRow, false);
  57. bAddNow = true;
  58. this.proc_SetToolbarButtons();
  59. break;
  60. }
  61. case "Edit":
  62. {
  63. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  64. return;
  65. currRow = ultraGrid1.ActiveRow;
  66. this.proc_setCellReadOnly(currRow, false);
  67. bEditNow = true;
  68. this.proc_SetToolbarButtons();
  69. break;
  70. }
  71. case "Save":
  72. {
  73. if (bAddNow)
  74. {
  75. proc_Add("Add");
  76. }
  77. else if (bEditNow)
  78. {
  79. proc_Add("Edit");
  80. }
  81. proc_Query();
  82. break;
  83. }
  84. case "Delete":
  85. {
  86. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  87. return;
  88. bDelNow = true;
  89. this.proc_SetToolbarButtons();
  90. proc_Delete();
  91. bDelNow = false;
  92. proc_Query();
  93. this.proc_SetToolbarButtons();
  94. break;
  95. }
  96. case "Export":
  97. {
  98. try
  99. {
  100. if (ultraGrid1.Rows.Count == 0) return;
  101. string strFileName = "炼二作业区物料申报记录" + DateTime.Now.ToString("yyyyMMdd");
  102. SaveFileDialog dlg = new SaveFileDialog();
  103. dlg.Title = "保存";
  104. dlg.OverwritePrompt = true;
  105. dlg.Filter = "Excel文件(*.xls)|*.xls";
  106. dlg.AddExtension = true;
  107. dlg.FileName = strFileName;
  108. if (dlg.ShowDialog() == DialogResult.OK)
  109. {
  110. strFileName = dlg.FileName;
  111. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  112. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  113. {
  114. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  115. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  116. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  117. Process.Start(p);
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. MessageBox.Show(ex.Message);
  124. }
  125. break;
  126. }
  127. case "Cancel":
  128. {
  129. if (!(bAddNow || bEditNow)) return;
  130. string strOpt = " [" + (bAddNow ? "新增" : (bEditNow ? "修改" : "")) + "]";
  131. if (MessageBox.Show("确定要取消" + strOpt + "操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  132. return;
  133. if (bAddNow)
  134. {
  135. currRow.Delete(false);
  136. currRow = null;
  137. if (ultraGrid1.Rows.Count > 0)
  138. {
  139. ultraGrid1.ActiveCell = ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"];
  140. ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"].Selected = false;
  141. }
  142. bAddNow = false;
  143. }
  144. else if (bEditNow)
  145. {
  146. this.proc_setCellReadOnly(currRow, true);
  147. currRow = null;
  148. bEditNow = false;
  149. }
  150. this.proc_SetToolbarButtons();
  151. break;
  152. }
  153. case "Close":
  154. {
  155. this.Close();
  156. break;
  157. }
  158. }
  159. }
  160. public void proc_Query()
  161. {
  162. Cursor oldCursor = this.Cursor;
  163. this.Cursor = Cursors.WaitCursor;
  164. try
  165. {
  166. this.dataTable1.Clear();
  167. string sqlStr = @"SELECT * FROM DEV_MATERIAL_ZLREPORT WHERE
  168. OPTDATE BETWEEN TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('{1}','YYYY-MM-DD HH24:MI:SS')";
  169. if (ultraDateTimeEditor2.DateTime.Date.Subtract(ultraDateTimeEditor1.DateTime.Date).Days > 90)
  170. {
  171. MessageBox.Show("查询时间不可超过3个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  172. return;
  173. }
  174. if (ultraDateTimeEditor1.DateTime.Date > ultraDateTimeEditor2.DateTime.Date)
  175. {
  176. MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  177. return;
  178. }
  179. string strFrom = ultraDateTimeEditor1.DateTime.ToString("yyyy-MM-dd") + " 00:00:00";
  180. string strTo = ultraDateTimeEditor2.DateTime.ToString("yyyy-MM-dd") + " 23:59:59";
  181. sqlStr = string.Format(sqlStr, strFrom, strTo);
  182. //调用服务端方法
  183. CoreClientParam CCP_LgEts = new CoreClientParam();
  184. DataTable dt = new DataTable();
  185. CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute";
  186. CCP_LgEts.MethodName = "doSimpleQuery";
  187. CCP_LgEts.ServerParams = new object[] { sqlStr };
  188. CCP_LgEts.SourceDataTable = dt;
  189. this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal);
  190. DataSet ds = new DataSet();
  191. if (dt != null && dt.Rows.Count > 0)
  192. {
  193. this.dataTable1.Rows.Clear();
  194. DataRow dr;
  195. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  196. {
  197. dr = this.dataTable1.NewRow();
  198. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  199. {
  200. if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
  201. {
  202. dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
  203. }
  204. }
  205. this.dataTable1.Rows.Add(dr);
  206. }
  207. }
  208. ultraGrid1.UpdateData();
  209. if (ultraGrid1.Rows.Count > 0)
  210. {
  211. ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["STATIONCODE"];
  212. ultraGrid1.Rows[0].Cells["STATIONCODE"].Selected = false;
  213. }
  214. this.proc_SetUltraGridReadOnly(ultraGrid1);
  215. ArrayList alistColumns = new ArrayList();
  216. for (int i = 0; i < this.dataTable1.Columns.Count; i++)
  217. {
  218. if (this.dataTable1.Columns[i].ColumnName != "OPTDATE" && this.dataTable1.Columns[i].ColumnName != "OPTMAN" &&
  219. this.dataTable1.Columns[i].ColumnName != "UUID_" && this.dataTable1.Columns[i].ColumnName != "STATIONCODE")
  220. alistColumns.Add(this.dataTable1.Columns[i].ColumnName);
  221. }
  222. proc_Statics(ref ultraGrid1, alistColumns, true, " {0:############0.0}");
  223. }
  224. catch
  225. { }
  226. finally
  227. {
  228. this.Cursor = oldCursor;
  229. }
  230. }
  231. public void proc_Add(string flag)
  232. {
  233. try
  234. {
  235. this.ultraGrid1.UpdateData();
  236. if (dataTable1.Rows.Count > 0)
  237. {
  238. string strErr = "";
  239. string strMess = "";
  240. if (flag == "Add")
  241. {
  242. ArrayList arry = new ArrayList();
  243. arry.Add("frmZLMaterial.Insert");
  244. string str1 = ultraGrid1.ActiveRow.Cells["STATIONCODE"].Text;
  245. string str2 = ultraGrid1.ActiveRow.Cells["ZTJ"].Text;
  246. string str3 = ultraGrid1.ActiveRow.Cells["GGTYJ"].Text;
  247. string str4 = ultraGrid1.ActiveRow.Cells["DZS"].Text;
  248. string str5 = ultraGrid1.ActiveRow.Cells["DZM"].Text;
  249. string str6 = ultraGrid1.ActiveRow.Cells["LX"].Text;
  250. string str7 = ultraGrid1.ActiveRow.Cells["WFSXGX"].Text;
  251. string str8 = ultraGrid1.ActiveRow.Cells["CGX"].Text;
  252. string str9 = ultraGrid1.ActiveRow.Cells["JBT"].Text;
  253. string str10 = ultraGrid1.ActiveRow.Cells["WYJLJ"].Text;
  254. string str11 = ultraGrid1.ActiveRow.Cells["PBL"].Text;
  255. string str12 = ultraGrid1.ActiveRow.Cells["NB"].Text;
  256. string str13 = ultraGrid1.ActiveRow.Cells["TB"].Text;
  257. string str14 = ultraGrid1.ActiveRow.Cells["PT"].Text;
  258. string str15 = ultraGrid1.ActiveRow.Cells["DML"].Text;
  259. string str16 = ultraGrid1.ActiveRow.Cells["KSBLL"].Text;
  260. string str17 = ultraGrid1.ActiveRow.Cells["LL"].Text;
  261. string str18 = ultraGrid1.ActiveRow.Cells["KRTLJ"].Text;
  262. string str19 = ultraGrid1.ActiveRow.Cells["YLS"].Text;
  263. string str20 = ultraGrid1.ActiveRow.Cells["NCBZB"].Text;
  264. string str21 = this.UserInfo.GetUserName();
  265. arry.Add(str1);
  266. arry.Add(str2);
  267. arry.Add(str3);
  268. arry.Add(str4);
  269. arry.Add(str5);
  270. arry.Add(str6);
  271. arry.Add(str7);
  272. arry.Add(str8);
  273. arry.Add(str9);
  274. arry.Add(str10);
  275. arry.Add(str11);
  276. arry.Add(str12);
  277. arry.Add(str13);
  278. arry.Add(str14);
  279. arry.Add(str15);
  280. arry.Add(str16);
  281. arry.Add(str17);
  282. arry.Add(str18);
  283. arry.Add(str19);
  284. arry.Add(str20);
  285. arry.Add(str21);
  286. CommonClientToServer cctos = new CommonClientToServer();
  287. cctos.ob = this.ob;
  288. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  289. "doSimpleSave", arry, out strErr);
  290. this.proc_setCellReadOnly(currRow, true);
  291. currRow = null;
  292. bAddNow = false;
  293. }
  294. else if (flag == "Edit")
  295. {
  296. ArrayList arry = new ArrayList();
  297. arry.Add("frmZLMaterial.Update");
  298. string str1 = ultraGrid1.ActiveRow.Cells["STATIONCODE"].Text;
  299. string str2 = ultraGrid1.ActiveRow.Cells["ZTJ"].Text;
  300. string str3 = ultraGrid1.ActiveRow.Cells["GGTYJ"].Text;
  301. string str4 = ultraGrid1.ActiveRow.Cells["DZS"].Text;
  302. string str5 = ultraGrid1.ActiveRow.Cells["DZM"].Text;
  303. string str6 = ultraGrid1.ActiveRow.Cells["LX"].Text;
  304. string str7 = ultraGrid1.ActiveRow.Cells["WFSXGX"].Text;
  305. string str8 = ultraGrid1.ActiveRow.Cells["CGX"].Text;
  306. string str9 = ultraGrid1.ActiveRow.Cells["JBT"].Text;
  307. string str10 = ultraGrid1.ActiveRow.Cells["WYJLJ"].Text;
  308. string str11 = ultraGrid1.ActiveRow.Cells["PBL"].Text;
  309. string str12 = ultraGrid1.ActiveRow.Cells["NB"].Text;
  310. string str13 = ultraGrid1.ActiveRow.Cells["TB"].Text;
  311. string str14 = ultraGrid1.ActiveRow.Cells["PT"].Text;
  312. string str15 = ultraGrid1.ActiveRow.Cells["DML"].Text;
  313. string str16 = ultraGrid1.ActiveRow.Cells["KSBLL"].Text;
  314. string str17 = ultraGrid1.ActiveRow.Cells["LL"].Text;
  315. string str18 = ultraGrid1.ActiveRow.Cells["KRTLJ"].Text;
  316. string str19 = ultraGrid1.ActiveRow.Cells["YLS"].Text;
  317. string str20 = ultraGrid1.ActiveRow.Cells["NCBZB"].Text;
  318. string str21 = this.UserInfo.GetUserName();
  319. string uuid = ultraGrid1.ActiveRow.Cells["UUID_"].Text;
  320. arry.Add(str1);
  321. arry.Add(str2);
  322. arry.Add(str3);
  323. arry.Add(str4);
  324. arry.Add(str5);
  325. arry.Add(str6);
  326. arry.Add(str7);
  327. arry.Add(str8);
  328. arry.Add(str9);
  329. arry.Add(str10);
  330. arry.Add(str11);
  331. arry.Add(str12);
  332. arry.Add(str13);
  333. arry.Add(str14);
  334. arry.Add(str15);
  335. arry.Add(str16);
  336. arry.Add(str17);
  337. arry.Add(str18);
  338. arry.Add(str19);
  339. arry.Add(str20);
  340. arry.Add(str21);
  341. arry.Add(uuid);
  342. CommonClientToServer cctos = new CommonClientToServer();
  343. cctos.ob = this.ob;
  344. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  345. "doSimpleSave", arry, out strErr);
  346. this.proc_setCellReadOnly(currRow, true);
  347. currRow = null;
  348. bEditNow = false;
  349. }
  350. if (strErr == "")
  351. {
  352. dataTable1.AcceptChanges();
  353. //JJBStaticFunction.SetRowEdit(ultraGrid1);
  354. if (!string.IsNullOrEmpty(strMess))
  355. MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  356. }
  357. else
  358. {
  359. MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误");
  360. }
  361. if (ultraGrid1.ActiveCell != null)
  362. ultraGrid1.ActiveCell.Activated = false;
  363. this.proc_SetToolbarButtons();
  364. }
  365. }
  366. catch (System.Exception ex)
  367. {
  368. Console.WriteLine(ex.ToString());
  369. }
  370. }
  371. public void proc_Delete()
  372. {
  373. try
  374. {
  375. string strErr = "";
  376. ArrayList arry = new ArrayList();
  377. if (this.ultraGrid1.ActiveRow == null) return;
  378. string uuid_ = ultraGrid1.ActiveRow.Cells["UUID_"].Text.Trim();
  379. arry.Add("frmZLMaterial.Delete");
  380. arry.Add(uuid_);
  381. CommonClientToServer cctos = new CommonClientToServer();
  382. cctos.ob = this.ob;
  383. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  384. "doSimpleSave", arry, out strErr);
  385. if (!string.IsNullOrEmpty(strErr))
  386. {
  387. MessageBox.Show("删除错误:" + strErr);
  388. }
  389. else
  390. {
  391. MessageBox.Show("删除成功:" + strErr);
  392. }
  393. }
  394. catch { }
  395. }
  396. private void proc_SetToolbarButtons()
  397. {
  398. try
  399. {
  400. this.ToolBarItemEnable(this, "Query", !(bAddNow || bEditNow || bDelNow));
  401. this.ToolBarItemEnable(this, "Add", !(bAddNow || bEditNow || bDelNow));
  402. this.ToolBarItemEnable(this, "Edit", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  403. this.ToolBarItemEnable(this, "Delete", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  404. this.ToolBarItemEnable(this, "Export", (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0));
  405. this.ToolBarItemEnable(this, "Save", (bAddNow || bEditNow));
  406. this.ToolBarItemEnable(this, "Cancel", (bAddNow || bEditNow));
  407. //this.ToolBarVisible(this, "Save");
  408. //this.Toolbars[0].Tools["Save"].SharedProps.Visible = (bAddNow || bEditNow);
  409. //this.Toolbars[0].Tools["Cancel"].SharedProps.Visible = (bAddNow || bEditNow);
  410. }
  411. catch { }
  412. }
  413. private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly)
  414. {
  415. try
  416. {
  417. if (row == null)
  418. return;
  419. if (bReadOnly)
  420. {
  421. row.Activation = Activation.ActivateOnly;
  422. row.CellAppearance.BackColor = Color.White;
  423. foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells)
  424. {
  425. cell.CancelUpdate();
  426. }
  427. }
  428. else
  429. {
  430. row.Activation = Activation.AllowEdit;
  431. row.CellAppearance.BackColor = Color.Khaki;
  432. }
  433. }
  434. catch (Exception ex)
  435. {
  436. MessageBox.Show(ex.Message);
  437. }
  438. }
  439. private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid)
  440. {
  441. foreach (UltraGridRow row in ultGrid.Rows)
  442. {
  443. row.Activation = Activation.ActivateOnly;
  444. }
  445. }
  446. public void proc_Statics(ref UltraGrid ultraGrid, ArrayList alistColumns, bool clearExists, string strFormat)
  447. {
  448. try
  449. {
  450. if (alistColumns == null)
  451. {
  452. return;
  453. }
  454. UltraGridBand band = ultraGrid.DisplayLayout.Bands[0];
  455. if (clearExists)
  456. band.Summaries.Clear();
  457. SummarySettings summary = null;
  458. UltraGridColumn cl = null;
  459. foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
  460. {
  461. if (column.RowLayoutColumnInfo.OriginX == 0)
  462. {
  463. cl = column;
  464. break;
  465. }
  466. }
  467. summary = band.Summaries.Add(SummaryType.Count, cl);
  468. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  469. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  470. summary.DisplayFormat = "合计:";
  471. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Center;
  472. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  473. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  474. if (string.IsNullOrEmpty(strFormat.Trim()))
  475. {
  476. strFormat = " {0:############0.00}";
  477. }
  478. for (int i = 0; i < alistColumns.Count; i++)
  479. {
  480. try
  481. {
  482. summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
  483. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  484. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  485. summary.DisplayFormat = strFormat;
  486. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  487. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  488. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  489. summary.Appearance.ForeColor = Color.DarkBlue;
  490. summary.Appearance.BackColor = Color.White;
  491. }
  492. catch { }
  493. }
  494. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  495. }
  496. catch { }
  497. }
  498. }
  499. }