FrmTBCheckInfo.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. namespace Core.LgMes.Client.lgIntegrationQuery
  18. {
  19. public partial class FrmTBCheckInfo : frmStyleBase
  20. {
  21. private bool bAddNow, bEditNow, bDelNow;
  22. private UltraGridRow currRow = null;
  23. public FrmTBCheckInfo()
  24. {
  25. InitializeComponent();
  26. }
  27. private void FrmTBCheckInfo_Load(object sender, EventArgs e)
  28. {
  29. ultraDateTimeEditor1.DateTime = DateTime.Today;
  30. ultraDateTimeEditor2.DateTime = DateTime.Today;
  31. proc_SetToolbarButtons();
  32. }
  33. public override void ToolBar_Click(object sender, string ToolbarKey)
  34. {
  35. switch (ToolbarKey)
  36. {
  37. case "Query":
  38. {
  39. if (bAddNow || bEditNow || bDelNow)
  40. return;
  41. proc_Query();
  42. proc_SetToolbarButtons();
  43. break;
  44. }
  45. case "Add":
  46. {
  47. if (bAddNow || bEditNow || bDelNow)
  48. return;
  49. currRow = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  50. this.proc_setCellReadOnly(currRow, false);
  51. bAddNow = true;
  52. this.proc_SetToolbarButtons();
  53. break;
  54. }
  55. case "Edit":
  56. {
  57. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  58. return;
  59. currRow = ultraGrid1.ActiveRow;
  60. this.proc_setCellReadOnly(currRow, false);
  61. bEditNow = true;
  62. this.proc_SetToolbarButtons();
  63. break;
  64. }
  65. case "Save":
  66. {
  67. if (bAddNow)
  68. {
  69. proc_Add("Add");
  70. }
  71. else if (bEditNow)
  72. {
  73. proc_Add("Edit");
  74. }
  75. proc_Query();
  76. break;
  77. }
  78. case "Delete":
  79. {
  80. if (ultraGrid1.ActiveRow == null || (bAddNow || bEditNow || bDelNow))
  81. return;
  82. bDelNow = true;
  83. this.proc_SetToolbarButtons();
  84. proc_Delete();
  85. bDelNow = false;
  86. proc_Query();
  87. this.proc_SetToolbarButtons();
  88. break;
  89. }
  90. case "Export":
  91. {
  92. try
  93. {
  94. if (ultraGrid1.Rows.Count == 0) return;
  95. string strFileName = "铁包在线记录" + DateTime.Now.ToString("yyyyMMdd");
  96. SaveFileDialog dlg = new SaveFileDialog();
  97. dlg.Title = "保存";
  98. dlg.OverwritePrompt = true;
  99. dlg.Filter = "Excel文件(*.xls)|*.xls";
  100. dlg.AddExtension = true;
  101. dlg.FileName = strFileName;
  102. if (dlg.ShowDialog() == DialogResult.OK)
  103. {
  104. strFileName = dlg.FileName;
  105. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  106. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  107. {
  108. ultraGridExcelExporter1.Export(ultraGrid1, strFileName);
  109. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  110. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  111. Process.Start(p);
  112. }
  113. }
  114. }
  115. catch (Exception ex)
  116. {
  117. MessageBox.Show(ex.Message);
  118. }
  119. break;
  120. }
  121. case "Cancel":
  122. {
  123. if (!(bAddNow || bEditNow)) return;
  124. string strOpt = " [" + (bAddNow ? "新增" : (bEditNow ? "修改" : "")) + "]";
  125. if (MessageBox.Show("确定要取消" + strOpt + "操作吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
  126. return;
  127. if (bAddNow)
  128. {
  129. currRow.Delete(false);
  130. currRow = null;
  131. if (ultraGrid1.Rows.Count > 0)
  132. {
  133. ultraGrid1.ActiveCell = ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"];
  134. ultraGrid1.Rows[ultraGrid1.Rows.Count - 1].Cells["STATIONCODE"].Selected = false;
  135. }
  136. bAddNow = false;
  137. }
  138. else if (bEditNow)
  139. {
  140. this.proc_setCellReadOnly(currRow, true);
  141. currRow = null;
  142. bEditNow = false;
  143. }
  144. this.proc_SetToolbarButtons();
  145. break;
  146. }
  147. case "Close":
  148. {
  149. this.Close();
  150. break;
  151. }
  152. }
  153. }
  154. public void proc_Query()
  155. {
  156. Cursor oldCursor = this.Cursor;
  157. this.Cursor = Cursors.WaitCursor;
  158. try
  159. {
  160. this.dataTable1.Clear();
  161. string sqlStr = @"SELECT * FROM DEV_IB_CHECK_INFO WHERE
  162. OPTDATE BETWEEN TO_DATE('{0}','YYYY-MM-DD HH24:MI:SS') AND TO_DATE('{1}','YYYY-MM-DD HH24:MI:SS')";
  163. if (ultraDateTimeEditor2.DateTime.Date.Subtract(ultraDateTimeEditor1.DateTime.Date).Days > 90)
  164. {
  165. MessageBox.Show("查询时间不可超过3个月。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  166. return;
  167. }
  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. if (ultraGrid1.Rows.Count > 0)
  203. {
  204. ultraGrid1.ActiveCell = ultraGrid1.Rows[0].Cells["UUID_"];
  205. ultraGrid1.Rows[0].Cells["UUID_"].Selected = false;
  206. }
  207. ultraGrid1.UpdateData();
  208. this.proc_SetUltraGridReadOnly(ultraGrid1);
  209. }
  210. catch
  211. { }
  212. finally
  213. {
  214. this.Cursor = oldCursor;
  215. }
  216. }
  217. public void proc_Add(string flag)
  218. {
  219. try
  220. {
  221. this.ultraGrid1.UpdateData();
  222. if (dataTable1.Rows.Count > 0)
  223. {
  224. string strErr = "";
  225. string strMess = "";
  226. if (flag == "Add")
  227. {
  228. ArrayList arry = new ArrayList();
  229. arry.Add("frmTBCHECKInfo.Insert");
  230. string str1 = ultraGrid1.ActiveRow.Cells["LADLEID"].Text;
  231. string str2 = ultraGrid1.ActiveRow.Cells["FACTORY"].Text;
  232. string str3 = ultraGrid1.ActiveRow.Cells["CHECK_DATE"].Text;
  233. string str4 = ultraGrid1.ActiveRow.Cells["LS"].Text;
  234. string str5 = ultraGrid1.ActiveRow.Cells["SHIFT_GROUP"].Text;
  235. string str6 = ultraGrid1.ActiveRow.Cells["SHIFT_CLASS"].Text;
  236. string str7 = ultraGrid1.ActiveRow.Cells["FJ"].Text;
  237. string str8 = ultraGrid1.ActiveRow.Cells["BZ"].Text;
  238. string str9 = ultraGrid1.ActiveRow.Cells["BDZ"].Text;
  239. string str10 = ultraGrid1.ActiveRow.Cells["RCZ"].Text;
  240. string str11 = ultraGrid1.ActiveRow.Cells["ZXZ"].Text;
  241. string str12 = ultraGrid1.ActiveRow.Cells["CHECK_MAN"].Text;
  242. string str13 = ultraGrid1.ActiveRow.Cells["REMARK"].Text;
  243. string str14 = this.UserInfo.GetUserName().Trim();
  244. arry.Add(str1);
  245. arry.Add(str2);
  246. arry.Add(str3);
  247. arry.Add(str4);
  248. arry.Add(str5);
  249. arry.Add(str6);
  250. arry.Add(str7);
  251. arry.Add(str8);
  252. arry.Add(str9);
  253. arry.Add(str10);
  254. arry.Add(str11);
  255. arry.Add(str12);
  256. arry.Add(str13);
  257. arry.Add(str14);
  258. CommonClientToServer cctos = new CommonClientToServer();
  259. cctos.ob = this.ob;
  260. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  261. "doSimpleSave", arry, out strErr);
  262. this.proc_setCellReadOnly(currRow, true);
  263. currRow = null;
  264. bAddNow = false;
  265. }
  266. else if (flag == "Edit")
  267. {
  268. ArrayList arry = new ArrayList();
  269. arry.Add("frmTBCHECKInfo.Update");
  270. string str1 = ultraGrid1.ActiveRow.Cells["LADLEID"].Text;
  271. string str2 = ultraGrid1.ActiveRow.Cells["FACTORY"].Text;
  272. string str3 = ultraGrid1.ActiveRow.Cells["CHECK_DATE"].Text;
  273. string str4 = ultraGrid1.ActiveRow.Cells["LS"].Text;
  274. string str5 = ultraGrid1.ActiveRow.Cells["SHIFT_GROUP"].Text;
  275. string str6 = ultraGrid1.ActiveRow.Cells["SHIFT_CLASS"].Text;
  276. string str7 = ultraGrid1.ActiveRow.Cells["FJ"].Text;
  277. string str8 = ultraGrid1.ActiveRow.Cells["BZ"].Text;
  278. string str9 = ultraGrid1.ActiveRow.Cells["BDZ"].Text;
  279. string str10 = ultraGrid1.ActiveRow.Cells["RCZ"].Text;
  280. string str11 = ultraGrid1.ActiveRow.Cells["ZXZ"].Text;
  281. string str12 = ultraGrid1.ActiveRow.Cells["CHECK_MAN"].Text;
  282. string str13 = ultraGrid1.ActiveRow.Cells["REMARK"].Text;
  283. string str14 = this.UserInfo.GetUserName().Trim();
  284. string uuid = ultraGrid1.ActiveRow.Cells["UUID_"].Text;
  285. arry.Add(str1);
  286. arry.Add(str2);
  287. arry.Add(str3);
  288. arry.Add(str4);
  289. arry.Add(str5);
  290. arry.Add(str6);
  291. arry.Add(str7);
  292. arry.Add(str8);
  293. arry.Add(str9);
  294. arry.Add(str10);
  295. arry.Add(str11);
  296. arry.Add(str12);
  297. arry.Add(str13);
  298. arry.Add(str14);
  299. arry.Add(uuid);
  300. CommonClientToServer cctos = new CommonClientToServer();
  301. cctos.ob = this.ob;
  302. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  303. "doSimpleSave", arry, out strErr);
  304. this.proc_setCellReadOnly(currRow, true);
  305. currRow = null;
  306. bEditNow = false;
  307. }
  308. if (strErr == "")
  309. {
  310. dataTable1.AcceptChanges();
  311. //JJBStaticFunction.SetRowEdit(ultraGrid1);
  312. if (!string.IsNullOrEmpty(strMess))
  313. MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  314. }
  315. else
  316. {
  317. MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误");
  318. }
  319. if (ultraGrid1.ActiveCell != null)
  320. ultraGrid1.ActiveCell.Activated = false;
  321. this.proc_SetToolbarButtons();
  322. }
  323. }
  324. catch (System.Exception ex)
  325. {
  326. Console.WriteLine(ex.ToString());
  327. }
  328. }
  329. public void proc_Delete()
  330. {
  331. try
  332. {
  333. string strErr = "";
  334. ArrayList arry = new ArrayList();
  335. if (this.ultraGrid1.ActiveRow == null) return;
  336. string uuid_ = ultraGrid1.ActiveRow.Cells["UUID_"].Text.Trim();
  337. arry.Add("frmTBCHECKInfo.Delete");
  338. arry.Add(uuid_);
  339. CommonClientToServer cctos = new CommonClientToServer();
  340. cctos.ob = this.ob;
  341. cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  342. "doSimpleSave", arry, out strErr);
  343. if (!string.IsNullOrEmpty(strErr))
  344. {
  345. MessageBox.Show("删除错误:" + strErr);
  346. }
  347. else
  348. {
  349. MessageBox.Show("删除成功:" + strErr);
  350. }
  351. }
  352. catch { }
  353. }
  354. private void proc_SetToolbarButtons()
  355. {
  356. try
  357. {
  358. this.ToolBarItemEnable(this, "Query", !(bAddNow || bEditNow || bDelNow));
  359. this.ToolBarItemEnable(this, "Add", !(bAddNow || bEditNow || bDelNow));
  360. this.ToolBarItemEnable(this, "Edit", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  361. this.ToolBarItemEnable(this, "Delete", (!(bAddNow || bEditNow || bDelNow) && (ultraGrid1.ActiveRow != null)));
  362. this.ToolBarItemEnable(this, "Export", (!(bAddNow || bEditNow || bDelNow) && ultraGrid1.Rows.Count > 0));
  363. this.ToolBarItemEnable(this, "Save", (bAddNow || bEditNow));
  364. this.ToolBarItemEnable(this, "Cancel", (bAddNow || bEditNow));
  365. //this.ToolBarVisible(this, "Save");
  366. //this.Toolbars[0].Tools["Save"].SharedProps.Visible = (bAddNow || bEditNow);
  367. //this.Toolbars[0].Tools["Cancel"].SharedProps.Visible = (bAddNow || bEditNow);
  368. }
  369. catch { }
  370. }
  371. private void proc_setCellReadOnly(UltraGridRow row, bool bReadOnly)
  372. {
  373. try
  374. {
  375. if (row == null)
  376. return;
  377. if (bReadOnly)
  378. {
  379. row.Activation = Activation.ActivateOnly;
  380. row.CellAppearance.BackColor = Color.White;
  381. foreach (Infragistics.Win.UltraWinGrid.UltraGridCell cell in row.Cells)
  382. {
  383. cell.CancelUpdate();
  384. }
  385. }
  386. else
  387. {
  388. row.Activation = Activation.AllowEdit;
  389. row.CellAppearance.BackColor = Color.Khaki;
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. MessageBox.Show(ex.Message);
  395. }
  396. }
  397. private void proc_SetUltraGridReadOnly(Infragistics.Win.UltraWinGrid.UltraGridBase ultGrid)
  398. {
  399. foreach (UltraGridRow row in ultGrid.Rows)
  400. {
  401. row.Activation = Activation.ActivateOnly;
  402. }
  403. }
  404. }
  405. }