FrmCombineCutSlabOpt.cs.svn-base 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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 System.Collections;
  11. using Infragistics.Win.UltraWinGrid.ExcelExport;
  12. using System.Diagnostics;
  13. using System.IO;
  14. using CoreFS.CA06;
  15. using Infragistics.Win.UltraWinGrid;
  16. using Core.LgMes.Client.Comm;
  17. using System.Net;
  18. namespace Core.LgMes.Client.lgIntegrationQuery
  19. {
  20. public partial class FrmCombineCutSlabOpt : frmStyleBase
  21. {
  22. public FrmCombineCutSlabOpt()
  23. {
  24. InitializeComponent();
  25. }
  26. private static UltraGridExcelExporter ultraGridExcelExporter1 = new UltraGridExcelExporter();
  27. private void FrmCombineCutSlabOpt_Load(object sender, EventArgs e)
  28. {
  29. cbbPos.SelectedIndex = 0;
  30. cbType.Enabled = false;
  31. foreach(UltraGridRow ugr in this.ultraGrid1.Rows)
  32. {
  33. ugr.Cells["Choose"].Value = false;
  34. }
  35. }
  36. public override void ToolBar_Click(object sender, string ToolbarKey)
  37. {
  38. switch (ToolbarKey)
  39. {
  40. case "Query":
  41. {
  42. proc_Query();
  43. break;
  44. }
  45. case "WeightMatch":
  46. {
  47. proc_divide();
  48. break;
  49. }
  50. case "Export":
  51. {
  52. try
  53. {
  54. if (ultraGrid2.Rows.Count == 0) return;
  55. string strFileName = "合切坯拆分历史";
  56. SaveFileDialog dlg = new SaveFileDialog();
  57. dlg.Title = "保存";
  58. dlg.OverwritePrompt = true;
  59. dlg.Filter = "Excel文件(*.xls)|*.xls";
  60. dlg.AddExtension = true;
  61. dlg.FileName = strFileName;
  62. if (dlg.ShowDialog() == DialogResult.OK)
  63. {
  64. strFileName = dlg.FileName;
  65. ultraGridExcelExporter1.Export(ultraGrid2, strFileName);
  66. if (MessageBox.Show("数据导出成功!\r\n需要打开所导出文件吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  67. {
  68. ultraGridExcelExporter1.Export(ultraGrid2, strFileName);
  69. ProcessStartInfo p = new ProcessStartInfo(strFileName);
  70. p.WorkingDirectory = Path.GetDirectoryName(strFileName);
  71. Process.Start(p);
  72. }
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. MessageBox.Show(ex.Message);
  78. }
  79. break;
  80. }
  81. case "Close":
  82. {
  83. this.Close();
  84. break;
  85. }
  86. }
  87. }
  88. public void proc_Query()
  89. {
  90. try
  91. {
  92. string strErr = "", sqlcondition = "";
  93. if (ultraTabControl2.ActiveTab.Index == 0)
  94. {
  95. sqlcondition = " WHERE 1=1 ";
  96. if (!string.IsNullOrEmpty(textBox1.Text.Trim()) && string.IsNullOrEmpty(textBox2.Text.Trim()))
  97. {
  98. sqlcondition += " AND SLAB_NO LIKE '" + textBox1.Text.Trim() + "%' ";
  99. }
  100. if(!string.IsNullOrEmpty(textBox2.Text.Trim()) && !string.IsNullOrEmpty(textBox2.Text.Trim()))
  101. {
  102. sqlcondition += " AND SUBSTR(T.SLAB_NO,1,10) BETWEEN '" + textBox1.Text.Trim() + "' AND '" + textBox2.Text.Trim() + "' ";
  103. }
  104. if (string.IsNullOrEmpty(textBox1.Text.Trim()) && string.IsNullOrEmpty(textBox2.Text.Trim()))
  105. {
  106. MessageBox.Show("请输入初始炉号");
  107. return;
  108. }
  109. if (cbType.Checked)
  110. {
  111. sqlcondition += " AND SLAB_DCS_DETAIL LIKE '%" + cbbPos.SelectedItem.ToString() + "%' ";
  112. }
  113. //定义一个ArrayList集合存储变量[参数]值
  114. ArrayList arry1 = new ArrayList();
  115. ArrayList sqlList = new ArrayList();
  116. arry1.Add("CombineCutSlab.select");//此ID为XML文件ID
  117. sqlList.Add(sqlcondition);
  118. //调用服务端方法
  119. CoreClientParam CCP_JJBQuery = new CoreClientParam();
  120. DataTable dt = new DataTable();
  121. CCP_JJBQuery.ServerName = "Core.LgMes.Server.Common.ComDBQuery";
  122. CCP_JJBQuery.MethodName = "doQuery";
  123. CCP_JJBQuery.ServerParams = new object[] { arry1, sqlList };
  124. CCP_JJBQuery.SourceDataTable = dt;
  125. this.ExecuteQueryToDataTable(CCP_JJBQuery, CoreInvokeType.Internal);
  126. if (string.IsNullOrEmpty(strErr)) {
  127. if (dt != null && dt.Rows.Count > 0)
  128. {
  129. this.dataTable1.Rows.Clear();
  130. DataRow dr;
  131. for (int iRow = 0; iRow < dt.Rows.Count; iRow++)
  132. {
  133. dr = this.dataTable1.NewRow();
  134. for (int jCol = 0; jCol < dt.Columns.Count; jCol++)
  135. {
  136. if (this.dataTable1.Columns.Contains(dt.Columns[jCol].ColumnName))
  137. {
  138. dr[dt.Columns[jCol].ColumnName] = dt.Rows[iRow][jCol];
  139. }
  140. }
  141. this.dataTable1.Rows.Add(dr);
  142. }
  143. }
  144. }
  145. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  146. {
  147. if (ugr.Cells["SLAB_STAT"].Text.Trim() == "已出库")
  148. {
  149. ugr.Cells["SLAB_STAT"].Appearance.BackColor = Color.Red;
  150. }
  151. }
  152. this.ultraGrid1.DisplayLayout.Bands[0].Columns["Choose"].CellActivation = Activation.AllowEdit;
  153. this.ultraGrid1.DisplayLayout.Bands[0].Columns["BILLETNO"].CellActivation = Activation.ActivateOnly;
  154. this.ultraGrid1.DisplayLayout.Bands[0].Columns["SLAB_STAT"].CellActivation = Activation.ActivateOnly;
  155. this.ultraGrid1.DisplayLayout.Bands[0].Columns["LENGTH"].CellActivation = Activation.ActivateOnly;
  156. this.ultraGrid1.DisplayLayout.Bands[0].Columns["WEIGHT"].CellActivation = Activation.ActivateOnly;
  157. this.ultraGrid1.DisplayLayout.Bands[0].Columns["THEORYWEIGHT"].CellActivation = Activation.ActivateOnly;
  158. }
  159. else
  160. {
  161. if (dtpBegin.DateTime.Date > dtpEnd.DateTime.Date)
  162. {
  163. MessageBox.Show("查询开始日期不能大于结束日期!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  164. return;
  165. }
  166. string strFrom = dtpBegin.DateTime.ToString("yyyy-MM-dd");
  167. string strTo = dtpEnd.DateTime.ToString("yyyy-MM-dd");
  168. sqlcondition = " WHERE SUBSTR(OPT_TIME,1,10) BETWEEN '" + strFrom + "' AND '" + strTo + "'";
  169. if (checkBox1.Checked)
  170. sqlcondition += " AND OPT_TYPE = '" + cvPos1.SelectedItem.ToString() + "'";
  171. ArrayList arry1 = new ArrayList();
  172. ArrayList sqlList = new ArrayList();
  173. arry1.Add("LogCombineCutSlabLog.select");//此ID为XML文件ID
  174. sqlList.Add(sqlcondition);
  175. //调用服务端方法
  176. CoreClientParam CCP_JJBQuery = new CoreClientParam();
  177. DataTable dt1 = new DataTable();
  178. CCP_JJBQuery.ServerName = "Core.LgMes.Server.Common.ComDBQuery";
  179. CCP_JJBQuery.MethodName = "doQuery";
  180. CCP_JJBQuery.ServerParams = new object[] { arry1, sqlList };
  181. CCP_JJBQuery.SourceDataTable = dt1;
  182. this.ExecuteQueryToDataTable(CCP_JJBQuery, CoreInvokeType.Internal);
  183. if (string.IsNullOrEmpty(strErr))
  184. {
  185. if (dt1 != null && dt1.Rows.Count > 0)
  186. {
  187. this.dataTable2.Rows.Clear();
  188. DataRow dr;
  189. for (int iRow = 0; iRow < dt1.Rows.Count; iRow++)
  190. {
  191. dr = this.dataTable2.NewRow();
  192. for (int jCol = 0; jCol < dt1.Columns.Count; jCol++)
  193. {
  194. if (this.dataTable2.Columns.Contains(dt1.Columns[jCol].ColumnName))
  195. {
  196. dr[dt1.Columns[jCol].ColumnName] = dt1.Rows[iRow][jCol];
  197. }
  198. }
  199. this.dataTable2.Rows.Add(dr);
  200. }
  201. }
  202. }
  203. JJBStaticFunction.SetRowEdit(ultraGrid2);
  204. }
  205. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  206. {
  207. if (ugr.Cells["ISVALID"].Text.Trim() == "是")
  208. {
  209. ugr.Cells["ISVALID"].Appearance.ForeColor = Color.Red;
  210. }
  211. }
  212. }
  213. catch { }
  214. }
  215. public void proc_divide()
  216. {
  217. int flag = 0;
  218. int icount = 0;
  219. double lengthAll = 0;
  220. double weightAll = 0.0;
  221. string billetAll = "重量拆分,";
  222. double length = 0;
  223. string strErr = "";
  224. if (ultraTabControl2.ActiveTab.Index == 1)
  225. {
  226. MessageBox.Show("请选择拆分管理界面进行拆分操作");
  227. return;
  228. }
  229. if (this.ultraGrid1.Rows.Count == 0)
  230. {
  231. MessageBox.Show("请先查询数据再进行重量拆分操作");
  232. return;
  233. }
  234. try
  235. {
  236. //获取统计数据
  237. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  238. {
  239. if (ugr.Cells["Choose"].Text.Trim().ToUpper() == "TRUE")
  240. {
  241. if (string.IsNullOrEmpty(ugr.Cells["LENGTH"].Text.Trim()))
  242. {
  243. MessageBox.Show("选择的合切坯中有无长度的板坯,请核实");
  244. return;
  245. }
  246. if (ugr.Cells["SLAB_STAT"].Text.Trim() == "已出库")
  247. {
  248. MessageBox.Show("选择的合切坯已出库,不可进行拆分操作");
  249. return;
  250. }
  251. if (Int32.Parse(ugr.Cells["LENGTH"].Text.Trim()) == 0 || Int32.Parse(ugr.Cells["LENGTH"].Text.Trim()) < 1000 )
  252. {
  253. MessageBox.Show("选择的合切坯中有长度不正确的板坯,请核实");
  254. return;
  255. }
  256. if (ugr.Cells["ISVALID"].Text.Trim() == "是" )
  257. {
  258. MessageBox.Show("板坯已拆分,不可再进行重量拆分操作");
  259. return;
  260. }
  261. lengthAll += Int32.Parse(ugr.Cells["LENGTH"].Text.Trim());
  262. if (!string.IsNullOrEmpty(ugr.Cells["WEIGHT"].Text.Trim()))
  263. {
  264. weightAll += double.Parse(ugr.Cells["WEIGHT"].Text.Trim());
  265. flag++;
  266. }
  267. if (flag > 1)
  268. {
  269. MessageBox.Show("选择的合切坯中有多个过磅重量,请核实");
  270. return;
  271. }
  272. billetAll += ugr.Cells["BILLETNO"].Text.Trim() + ",";
  273. }
  274. }
  275. foreach (UltraGridRow ugr in this.ultraGrid1.Rows)
  276. {
  277. if (ugr.Cells["Choose"].Text.Trim().ToUpper() == "TRUE")
  278. {
  279. if (flag == 0)
  280. {
  281. if (MessageBox.Show("选择的合切坯未过磅,是否按各板坯理重拆分?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
  282. {
  283. if (string.IsNullOrEmpty(ugr.Cells["THEORYWEIGHT"].Text.Trim()))
  284. {
  285. MessageBox.Show("选择的合切坯无理论重量,请核实");
  286. return;
  287. }
  288. //查询是否已经拆分过
  289. string sql = "select t.* from WEIGHT_DIVIDE_LOG t WHERE BILLETNO = '" + ugr.Cells["BILLETNO"].Text.Trim() + "' and isvalid = '1'";
  290. //调用服务端方法
  291. CoreClientParam CCP_JJBQuery = new CoreClientParam();
  292. DataTable dtAll = new DataTable();
  293. CCP_JJBQuery.ServerName = "Core.LgMes.Server.Common.ComDBExecute";
  294. CCP_JJBQuery.MethodName = "doSimpleQuery";
  295. CCP_JJBQuery.ServerParams = new object[] { sql };
  296. CCP_JJBQuery.SourceDataTable = dtAll;
  297. this.ExecuteQueryToDataTable(CCP_JJBQuery, CoreInvokeType.Internal);
  298. if (strErr == "")
  299. {
  300. if (dtAll.Rows.Count > 0)
  301. {
  302. MessageBox.Show("该板坯已拆分过,不可再次拆分");
  303. proc_Query();
  304. return;
  305. }
  306. }
  307. ArrayList arry = new ArrayList();
  308. arry.Add("CombineCutSlab.Update");//更新重量
  309. arry.Add(ugr.Cells["THEORYWEIGHT"].Text.Trim());
  310. arry.Add(ugr.Cells["BILLETNO"].Text.Trim());
  311. //arry.Add(this.UserInfo.GetUserName());
  312. CommonClientToServer cctos = new CommonClientToServer();
  313. cctos.ob = this.ob;
  314. DataSet ds1 = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  315. "doSimpleSave", arry, out strErr);
  316. if (strErr == "")
  317. {
  318. object[] sArgs = new object[5];
  319. sArgs[0] = ugr.Cells["BILLETNO"].Text.Trim();
  320. sArgs[1] = "11AA";
  321. sArgs[2] = "N";
  322. sArgs[3] = "合切坯重量分配";
  323. sArgs[4] = this.UserInfo.GetUserName();
  324. string strSqlID = "UpLoadData.CAL";
  325. cctos = new CommonClientToServer();
  326. cctos.ob = ob;
  327. string strRCode = cctos.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure",
  328. "ExecProcWithOneReturn", strSqlID, sArgs, out strErr);
  329. if (strRCode == "1" && !string.IsNullOrEmpty(strErr))
  330. {
  331. MessageBox.Show("数据上传失败:" + strRCode + "," + strErr);
  332. }
  333. //写操作记录
  334. ArrayList arry1 = new ArrayList();
  335. arry1.Add("LogCombineCutSlab.insert");
  336. arry1.Add("0");
  337. arry1.Add(ugr.Cells["THEORYWEIGHT"].Text.Trim());
  338. arry1.Add(cbbPos.SelectedItem.ToString());
  339. arry1.Add(GetLocalMachineIP());
  340. arry1.Add(this.UserInfo.GetUserName());
  341. arry1.Add(billetAll);
  342. arry1.Add(ugr.Cells["BILLETNO"].Text.Trim());
  343. CommonClientToServer cctos2 = new CommonClientToServer();
  344. cctos2.ob = this.ob;
  345. DataSet ds2 = cctos2.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  346. "doSimpleSave", arry1, out strErr);
  347. if (strErr == "")
  348. {
  349. icount++;
  350. }
  351. else
  352. {
  353. MessageBox.Show("记录新增失败:" + strErr + "!");
  354. return;
  355. }
  356. }
  357. else
  358. {
  359. MessageBox.Show("拆分失败:" + strErr + "!");
  360. return;
  361. }
  362. }
  363. }
  364. else
  365. {
  366. length = Int32.Parse(ugr.Cells["LENGTH"].Text.Trim());
  367. ArrayList arryOver = new ArrayList();
  368. arryOver.Add("CombineCutSlab.Update");
  369. arryOver.Add(Math.Round((length / lengthAll) * weightAll, 3));
  370. arryOver.Add(ugr.Cells["BILLETNO"].Text.Trim());
  371. CommonClientToServer cctos = new CommonClientToServer();
  372. cctos.ob = this.ob;
  373. DataSet ds3 = cctos.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  374. "doSimpleSave", arryOver, out strErr);
  375. if (strErr == "")
  376. {
  377. object[] sArgs = new object[5];
  378. sArgs[0] = ugr.Cells["BILLETNO"].Text.Trim();
  379. sArgs[1] = "11AA";
  380. sArgs[2] = "N";
  381. sArgs[3] = "合切坯重量分配";
  382. sArgs[4] = this.UserInfo.GetUserName();
  383. string strSqlID = "UpLoadData.CAL";
  384. cctos = new CommonClientToServer();
  385. cctos.ob = ob;
  386. string strRCode = cctos.ExecuteProcedureFunctions("Core.LgMes.Server.Common.ComDBProcedure",
  387. "ExecProcWithOneReturn", strSqlID, sArgs, out strErr);
  388. if (strRCode == "1" && !string.IsNullOrEmpty(strErr))
  389. {
  390. MessageBox.Show("数据上传失败:" + strRCode + "," + strErr);
  391. }
  392. //写操作记录
  393. ArrayList arry2 = new ArrayList();
  394. arry2.Add("LogCombineCutSlab.insert");
  395. arry2.Add(ugr.Cells["WEIGHT"].Text.Trim());
  396. arry2.Add(length / lengthAll * weightAll);
  397. arry2.Add(cbbPos.SelectedItem.ToString());
  398. arry2.Add(GetLocalMachineIP());
  399. arry2.Add(this.UserInfo.GetUserName());
  400. arry2.Add(billetAll);
  401. arry2.Add(ugr.Cells["BILLETNO"].Text.Trim());
  402. CommonClientToServer cctos4 = new CommonClientToServer();
  403. cctos4.ob = this.ob;
  404. DataSet ds4 = cctos4.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBSave",
  405. "doSimpleSave", arry2, out strErr);
  406. if (strErr == "")
  407. {
  408. icount++;
  409. }
  410. else
  411. {
  412. MessageBox.Show("记录新增失败:" + strErr + "!");
  413. return;
  414. }
  415. }
  416. else
  417. {
  418. MessageBox.Show("记录新增失败:" + strErr + "!");
  419. return;
  420. }
  421. }
  422. }
  423. }
  424. if (icount > 1)
  425. {
  426. MessageBox.Show("拆分成功");
  427. proc_Query();
  428. return;
  429. }
  430. }
  431. catch { }
  432. }
  433. private void uCkEditorForFilter_CheckedChanged(object sender, EventArgs e)
  434. {
  435. JJBStaticFunction.SetGridRowFilter(ref this.ultraGrid1, uCkEditorForFilter.Checked);
  436. }
  437. private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
  438. {
  439. JJBStaticFunction.SetGridRowFilter(ref this.ultraGrid2, uCkEditorForFilter.Checked);
  440. }
  441. public string GetLocalMachineIP()
  442. {
  443. IPHostEntry myHost = new IPHostEntry();
  444. //myHost = Dns.GetHostByName(Dns.GetHostName());
  445. myHost = Dns.GetHostEntry(Dns.GetHostName());
  446. string str = "";
  447. str = myHost.AddressList[0].ToString();
  448. return str;
  449. }
  450. }
  451. }