FrmAlloyInOut.cs.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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 (ultraDateTimeEditor1.DateTime.Date > ultraDateTimeEditor2.DateTime.Date)
  169. {
  170. MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  171. return;
  172. }
  173. string strFrom = ultraDateTimeEditor1.DateTime.ToString("yyyy-MM-dd") + " 00:00:00";
  174. string strTo = ultraDateTimeEditor2.DateTime.ToString("yyyy-MM-dd") + " 23:59:59";
  175. sqlStr = string.Format(sqlStr, strFrom, strTo);
  176. //调用服务端方法
  177. CoreClientParam CCP_LgEts = new CoreClientParam();
  178. DataTable dt = new DataTable();
  179. CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBExecute";
  180. CCP_LgEts.MethodName = "doSimpleQuery";
  181. CCP_LgEts.ServerParams = new object[] { sqlStr };
  182. CCP_LgEts.SourceDataTable = dt;
  183. this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal);
  184. DataSet ds = new DataSet();
  185. if (dt != null && dt.Rows.Count > 0)
  186. {
  187. this.dataTable1.Rows.Clear();
  188. DataRow dr;
  189. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  190. {
  191. dr = this.dataTable1.NewRow();
  192. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  193. {
  194. if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
  195. {
  196. dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
  197. }
  198. }
  199. this.dataTable1.Rows.Add(dr);
  200. }
  201. }
  202. ultraGrid1.UpdateData();
  203. if (ultraGrid1.Rows.Count > 0)
  204. {
  205. ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["STATIONCODE"];
  206. ultraGrid1.Rows[0].Cells["STATIONCODE"].Selected = false;
  207. }
  208. this.proc_SetUltraGridReadOnly(ultraGrid1);
  209. ArrayList alistColumns = new ArrayList();
  210. for (int i = 0; i < this.dataTable1.Columns.Count; i++)
  211. {
  212. if (this.dataTable1.Columns[i].ColumnName != "OPTDATE" && this.dataTable1.Columns[i].ColumnName != "OPTMAN" &&
  213. this.dataTable1.Columns[i].ColumnName != "UUID_" && this.dataTable1.Columns[i].ColumnName != "STATIONCODE")
  214. alistColumns.Add(this.dataTable1.Columns[i].ColumnName);
  215. }
  216. proc_Statics(ref ultraGrid1, alistColumns, true, " {0:############0.0}");
  217. }
  218. catch
  219. { }
  220. finally
  221. {
  222. this.Cursor = oldCursor;
  223. }
  224. }
  225. public void proc_Add(string flag)
  226. {
  227. try
  228. {
  229. this.ultraGrid1.UpdateData();
  230. if (dataTable1.Rows.Count > 0)
  231. {
  232. string strErr = "";
  233. string strMess = "";
  234. if (flag == "Add")
  235. {
  236. ArrayList arry = new ArrayList();
  237. arry.Add("frmAlloy.Insert");
  238. string str1 = ultraGrid1.ActiveRow.Cells["STATIONCODE"].Text;
  239. string str2 = ultraGrid1.ActiveRow.Cells["LK"].Text;
  240. string str3 = ultraGrid1.ActiveRow.Cells["GGM"].Text;
  241. string str4 = ultraGrid1.ActiveRow.Cells["GT"].Text;
  242. string str5 = ultraGrid1.ActiveRow.Cells["GM"].Text;
  243. string str6 = ultraGrid1.ActiveRow.Cells["ZTJ"].Text;
  244. string str7 = ultraGrid1.ActiveRow.Cells["ZTMT"].Text;
  245. string str8 = ultraGrid1.ActiveRow.Cells["TT"].Text;
  246. string str9 = ultraGrid1.ActiveRow.Cells["JSMK"].Text;
  247. string str10 = ultraGrid1.ActiveRow.Cells["ZTGT"].Text;
  248. string str11 = ultraGrid1.ActiveRow.Cells["MT"].Text;
  249. string str12 = ultraGrid1.ActiveRow.Cells["GTGT"].Text;
  250. string str13 = ultraGrid1.ActiveRow.Cells["JLZ"].Text;
  251. string str14 = ultraGrid1.ActiveRow.Cells["RHGZJ"].Text;
  252. string str15 = ultraGrid1.ActiveRow.Cells["DGYSQ"].Text;
  253. string str16 = ultraGrid1.ActiveRow.Cells["HZYSH"].Text;
  254. string str17 = this.UserInfo.GetUserName();
  255. arry.Add(str1);
  256. arry.Add(str2);
  257. arry.Add(str3);
  258. arry.Add(str4);
  259. arry.Add(str5);
  260. arry.Add(str6);
  261. arry.Add(str7);
  262. arry.Add(str8);
  263. arry.Add(str9);
  264. arry.Add(str10);
  265. arry.Add(str11);
  266. arry.Add(str12);
  267. arry.Add(str13);
  268. arry.Add(str14);
  269. arry.Add(str15);
  270. arry.Add(str16);
  271. arry.Add(str17);
  272. CommonClientToServer cctos = new CommonClientToServer();
  273. cctos.ob = this.ob;
  274. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  275. "doSimpleSave", arry, out strErr);
  276. this.proc_setCellReadOnly(currRow, true);
  277. currRow = null;
  278. bAddNow = false;
  279. }
  280. else if (flag == "Edit")
  281. {
  282. ArrayList arry = new ArrayList();
  283. arry.Add("frmAlloy.Update");
  284. string str1 = ultraGrid1.ActiveRow.Cells["STATIONCODE"].Text;
  285. string str2 = ultraGrid1.ActiveRow.Cells["LK"].Text;
  286. string str3 = ultraGrid1.ActiveRow.Cells["GGM"].Text;
  287. string str4 = ultraGrid1.ActiveRow.Cells["GT"].Text;
  288. string str5 = ultraGrid1.ActiveRow.Cells["GM"].Text;
  289. string str6 = ultraGrid1.ActiveRow.Cells["ZTJ"].Text;
  290. string str7 = ultraGrid1.ActiveRow.Cells["ZTMT"].Text;
  291. string str8 = ultraGrid1.ActiveRow.Cells["TT"].Text;
  292. string str9 = ultraGrid1.ActiveRow.Cells["JSMK"].Text;
  293. string str10 = ultraGrid1.ActiveRow.Cells["ZTGT"].Text;
  294. string str11 = ultraGrid1.ActiveRow.Cells["MT"].Text;
  295. string str12 = ultraGrid1.ActiveRow.Cells["GTGT"].Text;
  296. string str13 = ultraGrid1.ActiveRow.Cells["JLZ"].Text;
  297. string str14 = ultraGrid1.ActiveRow.Cells["RHGZJ"].Text;
  298. string str15 = ultraGrid1.ActiveRow.Cells["DGYSQ"].Text;
  299. string str16 = ultraGrid1.ActiveRow.Cells["HZYSH"].Text;
  300. string str17 = this.UserInfo.GetUserName();
  301. string uuid = ultraGrid1.ActiveRow.Cells["UUID_"].Text;
  302. arry.Add(str1);
  303. arry.Add(str2);
  304. arry.Add(str3);
  305. arry.Add(str4);
  306. arry.Add(str5);
  307. arry.Add(str6);
  308. arry.Add(str7);
  309. arry.Add(str8);
  310. arry.Add(str9);
  311. arry.Add(str10);
  312. arry.Add(str11);
  313. arry.Add(str12);
  314. arry.Add(str13);
  315. arry.Add(str14);
  316. arry.Add(str15);
  317. arry.Add(str16);
  318. arry.Add(str17);
  319. arry.Add(uuid);
  320. CommonClientToServer cctos = new CommonClientToServer();
  321. cctos.ob = this.ob;
  322. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  323. "doSimpleSave", arry, out strErr);
  324. this.proc_setCellReadOnly(currRow, true);
  325. currRow = null;
  326. bEditNow = false;
  327. }
  328. if (strErr == "")
  329. {
  330. dataTable1.AcceptChanges();
  331. //JJBStaticFunction.SetRowEdit(ultraGrid1);
  332. if (!string.IsNullOrEmpty(strMess))
  333. MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  334. }
  335. else
  336. {
  337. MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误");
  338. }
  339. if (ultraGrid1.ActiveCell != null)
  340. ultraGrid1.ActiveCell.Activated = false;
  341. this.proc_SetToolbarButtons();
  342. }
  343. }
  344. catch (System.Exception ex)
  345. {
  346. Console.WriteLine(ex.ToString());
  347. }
  348. }
  349. public void proc_Delete()
  350. {
  351. try
  352. {
  353. string strErr = "";
  354. ArrayList arry = new ArrayList();
  355. if (this.ultraGrid1.ActiveRow == null) return;
  356. string uuid_ = ultraGrid1.ActiveRow.Cells["UUID_"].Text.Trim();
  357. arry.Add("frmAlloy.Delete");
  358. arry.Add(uuid_);
  359. CommonClientToServer cctos = new CommonClientToServer();
  360. cctos.ob = this.ob;
  361. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  362. "doSimpleSave", arry, out strErr);
  363. if (!string.IsNullOrEmpty(strErr))
  364. {
  365. MessageBox.Show("删除错误:" + strErr);
  366. }
  367. else
  368. {
  369. MessageBox.Show("删除成功:" + strErr);
  370. }
  371. }
  372. catch { }
  373. }
  374. private void proc_SetToolbarButtons()
  375. {
  376. try
  377. {
  378. this.ToolBarItemEnable(this, "Query", !(bAddNow || bEditNow || bDelNow));
  379. this.ToolBarItemEnable(this, "Add", !(bAddNow || bEditNow || bDelNow));
  380. this.ToolBarItemEnable(this, "Edit", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  381. this.ToolBarItemEnable(this, "Delete", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  382. this.ToolBarItemEnable(this, "Export", (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0));
  383. this.ToolBarItemEnable(this, "Save", (bAddNow || bEditNow));
  384. this.ToolBarItemEnable(this, "Cancel", (bAddNow || bEditNow));
  385. //this.ToolBarVisible(this, "Save");
  386. //this.Toolbars[0].Tools["Save"].SharedProps.Visible = (bAddNow || bEditNow);
  387. //this.Toolbars[0].Tools["Cancel"].SharedProps.Visible = (bAddNow || bEditNow);
  388. }
  389. catch { }
  390. }
  391. private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly)
  392. {
  393. try
  394. {
  395. if (row == null)
  396. return;
  397. if (bReadOnly)
  398. {
  399. row.Activation = Activation.ActivateOnly;
  400. row.CellAppearance.BackColor = Color.White;
  401. foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells)
  402. {
  403. cell.CancelUpdate();
  404. }
  405. }
  406. else
  407. {
  408. row.Activation = Activation.AllowEdit;
  409. row.CellAppearance.BackColor = Color.Khaki;
  410. }
  411. }
  412. catch (Exception ex)
  413. {
  414. MessageBox.Show(ex.Message);
  415. }
  416. }
  417. private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid)
  418. {
  419. foreach (UltraGridRow row in ultGrid.Rows)
  420. {
  421. row.Activation = Activation.ActivateOnly;
  422. }
  423. }
  424. public void proc_Statics(ref UltraGrid ultraGrid, ArrayList alistColumns, bool clearExists, string strFormat)
  425. {
  426. try
  427. {
  428. if (alistColumns == null)
  429. {
  430. return;
  431. }
  432. UltraGridBand band = ultraGrid.DisplayLayout.Bands[0];
  433. if (clearExists)
  434. band.Summaries.Clear();
  435. SummarySettings summary = null;
  436. UltraGridColumn cl = null;
  437. foreach (UltraGridColumn column in ultraGrid.DisplayLayout.Bands[0].Columns)
  438. {
  439. if (column.RowLayoutColumnInfo.OriginX == 0)
  440. {
  441. cl = column;
  442. break;
  443. }
  444. }
  445. summary = band.Summaries.Add(SummaryType.Count, cl);
  446. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  447. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  448. summary.DisplayFormat = "合计:";
  449. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Center;
  450. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  451. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  452. if (string.IsNullOrEmpty(strFormat.Trim()))
  453. {
  454. strFormat = " {0:############0.00}";
  455. }
  456. for (int i = 0; i < alistColumns.Count; i++)
  457. {
  458. try
  459. {
  460. summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
  461. summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
  462. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  463. summary.DisplayFormat = strFormat;
  464. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
  465. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  466. summary.Appearance.FontData.Bold = DefaultableBoolean.True;
  467. summary.Appearance.ForeColor = Color.DarkBlue;
  468. summary.Appearance.BackColor = Color.White;
  469. }
  470. catch { }
  471. }
  472. band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
  473. }
  474. catch { }
  475. }
  476. }
  477. }