frmSteelTemp.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using Core.Mes.Client.Common;
  9. using Infragistics.Win.UltraWinGrid;
  10. using System.Collections;
  11. using CoreFS.CA06;
  12. using System.Diagnostics;
  13. using System.IO;
  14. namespace Core.LgMes.Client.lgIntegrationQuery
  15. {
  16. public partial class frmSteelTemp : Core.Mes.Client.Common.frmStyleBase
  17. {
  18. string strMess = "";
  19. string username = "";
  20. DataSet ds = new DataSet();
  21. DataSet dsSteel = new DataSet();
  22. public frmSteelTemp()
  23. {
  24. InitializeComponent();
  25. }
  26. private void frmSteelTemp_Load(object sender, EventArgs e)
  27. {
  28. InitSteel();
  29. }
  30. public override void ToolBar_Click(object sender, string ToolbarKey)
  31. {
  32. switch (ToolbarKey)
  33. {
  34. case "Query":
  35. GetDataSource();
  36. break;
  37. case "Add":
  38. Add(urGridLTemp);
  39. strMess = "钢水温度范围标准保存成功!";
  40. break;
  41. case "Update":
  42. UpdateGrid();
  43. break;
  44. case "Delete":
  45. username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
  46. if ("jsk02".Equals(username))
  47. {
  48. DeleteGrid();
  49. }
  50. else
  51. {
  52. strMess = "您的权限不足!\r\n请联系技术科!";
  53. MessageBox.Show(strMess);
  54. }
  55. break;
  56. case "Save":
  57. username = CoreFS.SA06.CoreUserInfo.UserInfo.GetUserID().Trim();
  58. if ("jsk02".Equals(username))
  59. {
  60. urGridLTemp.UpdateData();
  61. SaveData();
  62. }
  63. else
  64. {
  65. strMess = "您的权限不足!\r\n请联系技术科!";
  66. MessageBox.Show(strMess);
  67. }
  68. break;
  69. case "Export":
  70. if (urGridLTemp.Rows.Count > 0) ExportDataWithSaveDialog(ref this.urGridLTemp,"钢水温度范围标准");
  71. break;
  72. case "Rollback"://cancel
  73. JJBStaticFunction.dataCancel(urGridLTemp, dataTable1);
  74. break;
  75. case "Exit":
  76. this.Close();
  77. break;
  78. default:
  79. break;
  80. }
  81. }
  82. private void GetDataSource()
  83. {
  84. string strErr = "";
  85. string strSteel = "";
  86. string _strWhere2 = "";
  87. if (chkSteel.Checked && ultcboSteel.SelectedIndex > -1)
  88. {
  89. strSteel = Convert.ToString(ultcboSteel.Text);
  90. _strWhere2 = String.Format(" where t.steelname = '{0}'", strSteel);
  91. }
  92. else
  93. {
  94. _strWhere2 = "";
  95. }
  96. ArrayList arry = new ArrayList();
  97. ArrayList sqlList = new ArrayList();
  98. arry.Add("frmSTemp.select");
  99. sqlList.Add(_strWhere2);
  100. //调用服务端方法
  101. CoreClientParam CCP_LgEts = new CoreClientParam();
  102. DataTable dt = new DataTable();
  103. CCP_LgEts.ServerName = "Core.LgMes.Server.Common.ComDBQuery";
  104. CCP_LgEts.MethodName = "doQuery";
  105. CCP_LgEts.ServerParams = new object[] { arry, sqlList };
  106. CCP_LgEts.SourceDataTable = dt;
  107. this.ExecuteQueryToDataTable(CCP_LgEts, CoreInvokeType.Internal);
  108. ds.Tables.Add(dt);
  109. dsSTemp.Clear();
  110. this.dataTable1.Rows.Clear();
  111. if (strErr == "" && ds != null)
  112. {
  113. DataRow dr;
  114. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  115. {
  116. dr = this.dataTable1.NewRow();
  117. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  118. {
  119. try
  120. {
  121. if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
  122. {
  123. dr[dt.Columns[jCol].ColumnName] = Convert.ToString(dt.Rows[iRow][jCol]);
  124. }
  125. }
  126. catch { }
  127. }
  128. this.dataTable1.Rows.Add(dr);
  129. }
  130. urGridLTemp.UpdateData();
  131. dataTable1.AcceptChanges();
  132. }
  133. JJBStaticFunction.SetRowEdit(urGridLTemp);//Grid可编辑性
  134. }
  135. /// <summary>
  136. /// 更新数据
  137. /// </summary>
  138. private void UpdateGrid()
  139. {
  140. JJBStaticFunction.Update(urGridLTemp);
  141. strMess = "钢水温度范围标准修改成功!";
  142. if (urGridLTemp.ActiveRow != null)
  143. {
  144. for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
  145. {
  146. if (ds.Tables[0].Columns[i].ColumnName == "STEELNAME")
  147. {
  148. urGridLTemp.ActiveRow.Cells["STEELNAME"].Activation = Infragistics.Win.UltraWinGrid.Activation.NoEdit;
  149. }
  150. else
  151. {
  152. urGridLTemp.ActiveRow.Cells[ds.Tables[0].Columns[i].ColumnName].Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
  153. }
  154. }
  155. }
  156. else
  157. MessageBox.Show("请选择需要修改的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  158. }
  159. private void DeleteGrid()
  160. {
  161. if (urGridLTemp.ActiveRow != null)
  162. {
  163. string strMCode = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text.Trim();
  164. JJBStaticFunction.Delete(urGridLTemp);
  165. DelData(strMCode);
  166. }
  167. else
  168. MessageBox.Show("请选择需要删除的数据行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  169. }
  170. /// <summary>
  171. /// 删除钢水温度范围标准标准
  172. /// </summary>
  173. private void DelData(string strMCode)
  174. {
  175. string strErr = "";
  176. if (dataTable1.GetChanges() != null)
  177. {
  178. ArrayList arry = new ArrayList();
  179. arry.Add("frmSTemp_Del.select");
  180. arry.Add(strMCode);
  181. CommonClientToServer cctos = new CommonClientToServer();
  182. cctos.ob = this.ob;
  183. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  184. "doSimpleSave", arry, out strErr);
  185. if (strErr != "" && ds != null)
  186. {
  187. MessageBox.Show(strErr);
  188. }
  189. else
  190. {
  191. MessageBox.Show("钢水温度范围标准删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 新增数据
  197. /// </summary>
  198. /// <param name="Grid"></param>
  199. public static void Add(Infragistics.Win.UltraWinGrid.UltraGridBase Grid)
  200. {
  201. Grid.UpdateData();
  202. UltraGridRow ur = Grid.DisplayLayout.Bands[0].AddNew();
  203. ur.Activation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit;
  204. }
  205. /// <summary>
  206. /// 保存钢水温度范围标准
  207. /// </summary>
  208. private void SaveData()
  209. {
  210. try
  211. {
  212. urGridLTemp.UpdateData();
  213. if (dataTable1.Rows.Count > 0)
  214. {
  215. string strErr = "";
  216. ArrayList arry = new ArrayList();
  217. string STEELNAME = urGridLTemp.ActiveRow.Cells["STEELNAME"].Text;
  218. string LEAVETEMPTC_D = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_D"].Text;
  219. string ARRIVETEMPTD_D = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_D"].Text;
  220. string LEAVETEMPTD_D = urGridLTemp.ActiveRow.Cells["LEAVETEMPTD_D"].Text;
  221. string ARRIVETEMPTG_D = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_D"].Text;
  222. string LEAVETEMPTC_E = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_E"].Text;
  223. string ARRIVETEMPTD_E = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_E"].Text;
  224. string LEAVETEMPTE_E = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_E"].Text;
  225. string ARRIVETEMPTG_E = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_E"].Text;
  226. string LEAVETEMPTC_F = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_F"].Text;
  227. string ARRIVETEMPTD_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_F"].Text;
  228. string ARRIVETEMPTF_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTF_F"].Text;
  229. string LEAVETEMPTF_F = urGridLTemp.ActiveRow.Cells["LEAVETEMPTF_F"].Text;
  230. string ARRIVETEMPTG_F = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_F"].Text;
  231. string LEAVETEMPTC_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_EF"].Text;
  232. string ARRIVETEMPTD_EF = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_EF"].Text;
  233. string LEAVETEMPTE_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_EF"].Text;
  234. string LEAVETEMPTF_EF = urGridLTemp.ActiveRow.Cells["LEAVETEMPTF_EF"].Text;
  235. string ARRIVETEMPTG_EF = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_EF"].Text;
  236. string LEAVETEMPTC_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTC_EI"].Text;
  237. string ARRIVETEMPTD_EI = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTD_EI"].Text;
  238. string LEAVETEMPTE_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTE_EI"].Text;
  239. string LEAVETEMPTI_EI = urGridLTemp.ActiveRow.Cells["LEAVETEMPTI_EI"].Text;
  240. string ARRIVETEMPTG_EI = urGridLTemp.ActiveRow.Cells["ARRIVETEMPTG_EI"].Text;
  241. if (strMess == "钢水温度范围标准保存成功!")
  242. {
  243. arry.Add("frmSTemp_Save.select");
  244. arry.Add(STEELNAME);
  245. }
  246. if (strMess == "钢水温度范围标准修改成功!")
  247. {
  248. arry.Add("frmSTemp_Update.select");
  249. }
  250. arry.Add(LEAVETEMPTC_D);
  251. arry.Add(ARRIVETEMPTD_D);
  252. arry.Add(LEAVETEMPTD_D);
  253. arry.Add(ARRIVETEMPTG_D);
  254. arry.Add(LEAVETEMPTC_E);
  255. arry.Add(ARRIVETEMPTD_E);
  256. arry.Add(LEAVETEMPTE_E);
  257. arry.Add(ARRIVETEMPTG_E);
  258. arry.Add(LEAVETEMPTC_F);
  259. arry.Add(ARRIVETEMPTD_F);
  260. arry.Add(ARRIVETEMPTF_F);
  261. arry.Add(LEAVETEMPTF_F);
  262. arry.Add(ARRIVETEMPTG_F);
  263. arry.Add(LEAVETEMPTC_EF);
  264. arry.Add(ARRIVETEMPTD_EF);
  265. arry.Add(LEAVETEMPTE_EF);
  266. arry.Add(LEAVETEMPTF_EF);
  267. arry.Add(ARRIVETEMPTG_EF);
  268. arry.Add(LEAVETEMPTC_EI);
  269. arry.Add(ARRIVETEMPTD_EI);
  270. arry.Add(LEAVETEMPTE_EI);
  271. arry.Add(LEAVETEMPTI_EI);
  272. arry.Add(ARRIVETEMPTG_EI);
  273. if (strMess == "钢水温度范围标准修改成功!")
  274. {
  275. arry.Add(STEELNAME);
  276. }
  277. CommonClientToServer cctos = new CommonClientToServer();
  278. cctos.ob = this.ob;
  279. DataSet ds = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  280. "doSimpleSave", arry, out strErr);
  281. if (strErr == "" && ds != null)
  282. {
  283. dataTable1.AcceptChanges();
  284. JJBStaticFunction.SetRowEdit(urGridLTemp);
  285. if (!string.IsNullOrEmpty(strMess))
  286. MessageBox.Show(strMess, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  287. }
  288. else
  289. {
  290. MessageBox.Show("保存失败!输入信息已经存在或数据无效。", "错误");
  291. }
  292. if (urGridLTemp.ActiveCell != null)
  293. urGridLTemp.ActiveCell.Activated = false;
  294. }
  295. }
  296. catch (System.Exception ex)
  297. {
  298. Console.WriteLine(ex.ToString());
  299. }
  300. }
  301. private void InitSteel()
  302. {
  303. try
  304. {
  305. string strErr = "";
  306. //获取钢种
  307. ArrayList arrySteel = new ArrayList();
  308. arrySteel.Add("GetSteelInfo.select");
  309. CommonClientToServer cctos = new CommonClientToServer();
  310. cctos.ob = this.ob;
  311. dsSteel = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery",
  312. "doSimpleQuery", arrySteel, out strErr);
  313. if (strErr == "" && dsSteel != null)
  314. {
  315. Core.Mes.Client.Common.Globals.FillUltraComboItems(ultcboSteel, dsSteel);
  316. }
  317. }
  318. catch { }
  319. }
  320. private void chkSteel_CheckedChanged(object sender, EventArgs e)
  321. {
  322. ultcboSteel.Enabled = chkSteel.Checked;
  323. if (chkSteel.Checked == true)
  324. {
  325. InitSteel();
  326. }
  327. }
  328. public void ExportDataWithSaveDialog(ref UltraGrid ultGrid, string strFileName)
  329. {
  330. try
  331. {
  332. if (ultGrid.Rows.Count == 0) return;
  333. if (strFileName.Length == 0)
  334. strFileName = "未命名";
  335. SaveFileDialog dlg = new SaveFileDialog();
  336. dlg.Title = "保存";
  337. dlg.OverwritePrompt = true;
  338. dlg.Filter = "Excel文件(*.xls)|*.xls";
  339. dlg.AddExtension = true;
  340. dlg.FileName = strFileName;
  341. if (dlg.ShowDialog() == DialogResult.OK)
  342. {
  343. strFileName = dlg.FileName;
  344. ultraGridExcelExporter1.Export(ultGrid, strFileName);
  345. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  346. {
  347. ultraGridExcelExporter1.Export(ultGrid, strFileName);
  348. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  349. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  350. Process.Start(p);
  351. }
  352. }
  353. }
  354. catch (Exception ex)
  355. {
  356. MessageBox.Show(ex.Message);
  357. }
  358. }
  359. }
  360. }