frmBuyCheck.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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.Net;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using Core.Mes.Client.Comm.Format;
  11. using Core.Mes.Client.Comm.Server;
  12. using Core.Mes.Client.Comm.Tool;
  13. using Core.StlMes.Client.LgResMgt.Mcms.entity;
  14. using CoreFS.CA06;
  15. using Infragistics.Win;
  16. using Infragistics.Win.UltraWinGrid;
  17. namespace Core.StlMes.Client.LgResMgt.Mcms
  18. {
  19. public partial class FrmBuyCheck : FrmBase
  20. {
  21. public FrmBuyCheck()
  22. {
  23. InitializeComponent();
  24. buyGpCheckResultEntityBindingSource.DataSource = new List<BuyGpCheckResultEntity>(){new BuyGpCheckResultEntity()};
  25. buyGpCheckResultDEntityBindingSource.DataSource = new List<BuyGpCheckResultDEntity>() { new BuyGpCheckResultDEntity() };
  26. EntityHelper.ShowGridCaption<CmmBlankPredictionEntity>(planGrid.DisplayLayout.Bands[0]);
  27. EntityHelper.ShowGridCaption<BuyGpCheckResultEntity>(ugResult.DisplayLayout.Bands[0]);
  28. }
  29. private List<BuyGpCheckResultFEntity> listFail = new List<BuyGpCheckResultFEntity>();
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. base.OnLoad(e);
  33. ugData.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  34. ugData.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  35. var dt = ServerHelper.GetData("com.steering.Mcms.BuyCheckServer.doQueryName",
  36. new object[] { }, ob);
  37. if ((dt != null) && (dt.Rows.Count > 0))
  38. {
  39. uceUserName.DataSource = dt;
  40. uceUserName.ValueMember = "USER_NAME";
  41. uceUserName.DisplayMember = "USER_NAME";
  42. }
  43. }
  44. public override void ToolBar_Click(object sender, string ToolbarKey)
  45. {
  46. switch (ToolbarKey)
  47. {
  48. case "DoQuery":
  49. Query();
  50. break;
  51. case "DoAdd":
  52. DoAdd();
  53. break;
  54. case "DoDelete":
  55. DoDelete();
  56. break;
  57. case "DoBeside":
  58. DoBeside();
  59. break;
  60. case "CelBeside":
  61. DoCelBeside();
  62. break;
  63. case "DoClose":
  64. Close();
  65. break;
  66. }
  67. }
  68. private void DoDelete()
  69. {
  70. if (planGrid.ActiveRow == null) return;
  71. if (ugResult.ActiveRow == null)
  72. {
  73. MessageBox.Show("清选择需求要删除的记录");
  74. return;
  75. }
  76. BuyGpCheckResultEntity entity = ugResult.ActiveRow.ListObject as BuyGpCheckResultEntity;
  77. var blank = planGrid.ActiveRow.ListObject as CmmBlankPredictionEntity;
  78. var ccp = new CoreClientParam();
  79. ccp.ServerName = "com.steering.Mcms.BuyCheckServer";
  80. ccp.MethodName = "DoDelete";
  81. ccp.ServerParams = new object[]
  82. {
  83. JSONFormat.Format(entity),
  84. };
  85. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  86. if (ccp.ReturnCode != -1)
  87. {
  88. MessageUtil.ShowTips(ccp.ReturnInfo);
  89. if (ccp.ReturnInfo.Contains("成功!"))
  90. {
  91. if (!string.IsNullOrEmpty(blank.ReportPath))
  92. {
  93. try
  94. {
  95. FileHelper.Delete(entity.ReportPath);
  96. ServerHelper.SetData("com.steering.Mcms.BlankPredictionServer.UpdatePath",
  97. new object[] { "", entity.PredictionId }, ob);
  98. }
  99. catch (Exception)
  100. {
  101. MessageUtil.ShowTips("报告删除失败!");
  102. }
  103. }
  104. Query();
  105. }
  106. }
  107. }
  108. private void DoCelBeside()
  109. {
  110. if (planGrid.ActiveRow == null) return;
  111. CmmBlankPredictionEntity entity = planGrid.ActiveRow.ListObject as CmmBlankPredictionEntity;
  112. var ccp = new CoreClientParam();
  113. ccp.ServerName = "com.steering.Mcms.BuyCheckServer";
  114. ccp.MethodName = "DoCelBeside";
  115. ccp.ServerParams = new object[]
  116. {
  117. JSONFormat.Format(entity),
  118. };
  119. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  120. if (ccp.ReturnCode != -1)
  121. {
  122. MessageUtil.ShowTips(ccp.ReturnInfo);
  123. if (ccp.ReturnInfo.Contains("成功!"))
  124. Query();
  125. }
  126. }
  127. private void DoBeside()
  128. {
  129. if(planGrid.ActiveRow==null) return;
  130. CmmBlankPredictionEntity entity = planGrid.ActiveRow.ListObject as CmmBlankPredictionEntity;
  131. Upload(entity, false);
  132. var ccp = new CoreClientParam();
  133. ccp.ServerName = "com.steering.Mcms.BuyCheckServer";
  134. ccp.MethodName = "DoBeside";
  135. ccp.ServerParams = new object[]
  136. {
  137. JSONFormat.Format(entity),
  138. };
  139. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  140. if (ccp.ReturnCode != -1)
  141. {
  142. MessageUtil.ShowTips(ccp.ReturnInfo);
  143. if (ccp.ReturnInfo.Contains("成功!"))
  144. Query();
  145. }
  146. }
  147. private void DoAdd()
  148. {
  149. if (planGrid.ActiveRow == null) return;
  150. matGrid.UpdateData();
  151. ugData.UpdateData();
  152. List<BuyGpCheckResultEntity> list =
  153. buyGpCheckResultEntityBindingSource.DataSource as List<BuyGpCheckResultEntity>;
  154. List<BuyGpCheckResultDEntity> listd =
  155. buyGpCheckResultDEntityBindingSource.DataSource as List<BuyGpCheckResultDEntity>;
  156. if(listd==null) listd = new List<BuyGpCheckResultDEntity>();
  157. var ccp = new CoreClientParam();
  158. ccp.ServerName = "com.steering.Mcms.BuyCheckServer";
  159. ccp.MethodName = "DoAdd";
  160. ccp.ServerParams = new object[]
  161. {
  162. JSONFormat.Format(list[0]), listd.Select(JSONFormat.Format).ToList(),listFail.Select(JSONFormat.Format).ToList()
  163. };
  164. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  165. if (ccp.ReturnCode != -1)
  166. {
  167. MessageUtil.ShowTips(ccp.ReturnInfo);
  168. if (ccp.ReturnInfo.Contains("成功"))
  169. Query();
  170. }
  171. }
  172. private void Query()
  173. {
  174. var dic = new Dictionary<string, object>();
  175. if (chkJudgeStove.Checked) dic.Add("judgeStoveNoD", txtJudgeStove.Text);
  176. if (chkPound.Checked) dic.Add("isPound","1");
  177. if (chkShippersName.Checked) dic.Add("shippersName", uteShippersName.Text);
  178. dic.Add("checkFlag", ultraOptionSet2.Value.ToString2());
  179. cmmBlankPredictionEntityBindingSource.DataSource = EntityHelper.GetData<CmmBlankPredictionEntity>(
  180. "com.steering.Mcms.BlankPredictionServer.doQuery",
  181. new object[] { dic },
  182. ob).OrderBy(p=>p.JudgeStoveNo).ToList();
  183. Comm.RefreshAndAutoSize(planGrid, new string[] { "ReportPath" });
  184. }
  185. private void planGrid_AfterRowActivate(object sender, EventArgs e)
  186. {
  187. buyGpCheckResultDEntityBindingSource.Clear();
  188. CmmBlankPredictionEntity row = planGrid.ActiveRow.ListObject as CmmBlankPredictionEntity;
  189. if(row==null) return;
  190. var proList = QueryResult(row.PredictionId);
  191. decimal total = row.PlanNum ?? 0;
  192. decimal addNum = proList != null && proList.Any()
  193. ? proList.Where(p => p.ProNum != null).Select(p => (decimal) p.ProNum).Sum()
  194. : 0;
  195. decimal proNum = total - addNum;
  196. if (proNum <= 0) proNum = 0;
  197. decimal check = 0;
  198. if (proNum > 0)
  199. {
  200. check = decimal.Parse(Math.Ceiling(proNum / 5).ToString3());
  201. }
  202. buyGpCheckResultEntityBindingSource.DataSource = new List<BuyGpCheckResultEntity>()
  203. {
  204. new BuyGpCheckResultEntity()
  205. {
  206. ActDimater = "Φ" + row.ActDimater + "*" + row.ActLen + "mm",
  207. JudgeStoveNo = row.JudgeStoveNo,
  208. ProNum =proNum,
  209. CheckNum = check,
  210. PassNum = proNum,
  211. UnpassNum = 0,
  212. Steelcode = row.Gradecode,
  213. Steelname = row.Gradename,
  214. ProShift = this.UserInfo.GetUserOrder(),
  215. ProGroup = this.UserInfo.GetUserGroup(),
  216. ProUser = ugData.Rows[0].Cells["ProUser"].Value.ToString2(),
  217. ProTime = DateTime.Now.ToString("yyyy-MM-dd"),
  218. PredictionId = row.PredictionId,
  219. Standard = row.Standard
  220. }
  221. };
  222. listFail = new List<BuyGpCheckResultFEntity>();
  223. }
  224. private List<BuyGpCheckResultEntity> QueryResult(string id)
  225. {
  226. var dic = new Dictionary<string, object>();
  227. dic.Add("predictionId", id);
  228. List<BuyGpCheckResultEntity> proList = EntityHelper.GetData<BuyGpCheckResultEntity>(
  229. "com.steering.Mcms.BuyCheckServer.doQuery",
  230. new object[] {dic},
  231. ob);
  232. bindingSource1.DataSource = proList;
  233. Comm.RefreshAndAutoSize(ugResult, new string[] {"ReportPath"});
  234. return proList;
  235. }
  236. private void matGrid_ClickCell(object sender, ClickCellEventArgs e)
  237. {
  238. if (matGrid.ActiveRow.IsAddRow)
  239. {
  240. int a = matGrid.ActiveCell.Row.Index;
  241. int b = matGrid.ActiveCell.Column.Index;
  242. matGrid.Rows.Band.AddNew();
  243. matGrid.Rows[a].Cells[b].Activated = true;
  244. matGrid.PerformAction(UltraGridAction.EnterEditMode);
  245. matGrid.PerformAction(UltraGridAction.EnterEditMode);
  246. }
  247. }
  248. private void uteUnpass_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  249. {
  250. using (var FrmUnpassEdit = new FrmUnpassEdit(ob, listFail))
  251. {
  252. if (FrmUnpassEdit.ShowDialog() == DialogResult.OK)
  253. {
  254. listFail = FrmUnpassEdit.UnPassList;
  255. ugData.Rows[0].Cells["UnpassNum"].Value = listFail.Any() ?listFail.Select(p => p.FailNum).Sum():0;
  256. ugData_CellChange(null, null);
  257. }
  258. }
  259. }
  260. private void ugData_CellChange(object sender, CellEventArgs e)
  261. {
  262. decimal total = 0;
  263. decimal unPass = 0;
  264. if (decimal.TryParse(ugData.Rows[0].Cells["ProNum"].Text, out total) && decimal.TryParse(ugData.Rows[0].Cells["UnpassNum"].Text, out unPass))
  265. {
  266. decimal pass = total - unPass;
  267. ugData.Rows[0].Cells["PassNum"].Value = pass < 0 ? 0 : pass;
  268. }
  269. }
  270. private void utUpLoad1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  271. {
  272. }
  273. private void Upload(CmmBlankPredictionEntity entity, bool showMsg = true)
  274. {
  275. string strurl;
  276. // strurl = "http://172.16.2.145/WebReport/ReportServer?reportlet=RepGpPipeRecordTH.cpt&format=pdf&PREDICTION_ID=" + entity.PredictionId;
  277. strurl = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepGpPipeRecordTH.cpt&format=pdf&PREDICTION_ID=" + entity.PredictionId;
  278. var webClient = new WebClient();
  279. var listPdf = new List<FileBean>();
  280. var date = DateTime.Now.ToString("yyyyMMdd");
  281. var filePathNew = ""; //报告目录
  282. var reportNo = ""; //报告编号
  283. filePathNew = "BuyCheck/" + entity.JudgeStoveNo + "/";
  284. reportNo = entity.PredictionId;
  285. var pdf = webClient.DownloadData(strurl);
  286. var fileBean = new FileBean();
  287. fileBean.setFile(pdf);
  288. fileBean.setFileName(reportNo + ".pdf");
  289. fileBean.setPathName(filePathNew);
  290. listPdf.Add(fileBean);
  291. webClient.Dispose();
  292. var a = FileHelper.Upload(listPdf);
  293. if (a)
  294. {
  295. ServerHelper.SetData("com.steering.Mcms.BlankPredictionServer.UpdatePath",
  296. new object[] { filePathNew + reportNo + ".pdf", entity.PredictionId }, ob);
  297. if (showMsg)
  298. {
  299. MessageUtil.ShowTips("上传报告成功!");
  300. Query();
  301. }
  302. }
  303. }
  304. private void ugResult_InitializeRow(object sender, InitializeRowEventArgs e)
  305. {
  306. var BuyGpCheckResultEntity = e.Row.ListObject as BuyGpCheckResultEntity;
  307. e.Row.Cells["ReportPath"].Appearance.BackColor = string.IsNullOrEmpty(BuyGpCheckResultEntity.ReportPath)
  308. ? Color.Red
  309. : Color.LightGreen;
  310. }
  311. private void uteUpload2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  312. {
  313. var entity = planGrid.ActiveRow.ListObject as CmmBlankPredictionEntity;
  314. var strurl = "";
  315. if (e.Button.Key == "VIEW")
  316. {
  317. //strurl =
  318. // "http://172.16.2.145/WebReport/ReportServer?reportlet=RepGpPipeRecordTH.cpt&op=view&PREDICTION_ID=" +
  319. // entity.PredictionId;
  320. strurl =
  321. "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepGpPipeRecordTH.cpt&op=view&PREDICTION_ID=" +
  322. entity.PredictionId;
  323. var fre = new FrmRepExcel(ob, strurl);
  324. fre.AutoSize = true;
  325. fre.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width,
  326. Screen.PrimaryScreen.WorkingArea.Height);
  327. fre.WindowState = FormWindowState.Maximized;
  328. fre.Show();
  329. }
  330. else if (e.Button.Key == "UPLOAD")
  331. {
  332. Upload(entity);
  333. }
  334. else
  335. {
  336. MessageUtil.ShowError("系统生成PDF失败,请稍后再试!");
  337. }
  338. }
  339. private void matGrid_AfterRowInsert(object sender, RowEventArgs e)
  340. {
  341. e.Row.Cells["SurfaceQuality"].Value = "合格";
  342. e.Row.Cells["Identification"].Value = "合格";
  343. }
  344. }
  345. }