FrmMaterialInoutBOF.cs.svn-base 23 KB

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