FrmAlloyInOut.cs 22 KB

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