FrmSubContractAffrim.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using Core.Mes.Client.Comm.Format;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.YdmStuffManage.Entity;
  5. using CoreFS.CA06;
  6. using Infragistics.Win.UltraWinGrid;
  7. using System;
  8. using System.Collections;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. namespace Core.StlMes.Client.YdmStuffManage
  17. {
  18. public partial class FrmSubContractAffrim : FrmBase
  19. {
  20. public FrmSubContractAffrim()
  21. {
  22. InitializeComponent();
  23. }
  24. private void FrmSubContractAffrim_Load(object sender, EventArgs e)
  25. {
  26. DateTime now = DateTime.Now;
  27. DateTime dt1 = new DateTime(now.Year, now.Month, 1);//当月第一天
  28. DateTime dt2 = dt1.AddMonths(1).AddDays(-1);//当月最后一天
  29. this.StartTime.Value = DateTime.Parse(dt1.ToString("yyyy-MM-dd") + " 00:00:00");
  30. this.EndTime.Value = DateTime.Parse(dt2.ToString("yyyy-MM-dd") + " 23:59:59");
  31. EntityHelper.ShowGridCaption<StlLgEntrustBillEntity>(ultraGrid1.DisplayLayout.Bands[0]);
  32. EntityHelper.ShowGridCaption<StlLgEntrustBillDetialEntity>(ultraGrid2.DisplayLayout.Bands[0]);
  33. }
  34. /// <summary>
  35. /// 重写基类方法
  36. /// </summary>
  37. /// <param name="sender"></param>
  38. /// <param name="ToolbarKey"></param>
  39. public override void ToolBar_Click(object sender, string ToolbarKey)
  40. {
  41. switch (ToolbarKey)
  42. {
  43. case"Query":
  44. doQueryEntrustBill();
  45. break;
  46. case "subcontractComplete":
  47. subcontractComplete();
  48. break;
  49. case "cancelSubcontractComplete":
  50. cancelSubcontractComplete();
  51. break;
  52. case"doAffrim":
  53. doAffrim();
  54. break;
  55. case"cancelDoAffrim":
  56. cancelDoAffrim();
  57. break;
  58. case "Close":
  59. this.Close();
  60. break;
  61. }
  62. }
  63. /// <summary>
  64. /// 确认实绩
  65. /// </summary>
  66. private void doAffrim()
  67. {
  68. this.ultraGrid1.UpdateData();
  69. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  70. if (uRow == null) return;
  71. if (uRow.Cells["SubcontractFlag"].Value.Equals("未完成"))
  72. {
  73. MessageUtil.ShowTips("请先回报实绩,完成委托!");
  74. return;
  75. }
  76. StlLgEntrustBillEntity stlLgEntity = (StlLgEntrustBillEntity)uRow.ListObject;
  77. string stlLgTity = JSONFormat.Format(stlLgEntity);
  78. if (MessageUtil.ShowYesNoAndQuestion("是否确认该委托实绩?") == DialogResult.No) return;
  79. CoreClientParam ccp = new CoreClientParam();
  80. ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim";
  81. ccp.MethodName = "doAffrim";
  82. ccp.ServerParams = new object[] { stlLgTity,UserInfo.GetUserName() };
  83. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  84. if (ccp.ReturnCode != -1)
  85. {
  86. if (ccp.ReturnInfo.Equals("确认成功!"))
  87. {
  88. doQueryEntrustBill();
  89. MessageUtil.ShowTips(ccp.ReturnInfo);
  90. }
  91. else
  92. {
  93. MessageUtil.ShowTips(ccp.ReturnInfo);
  94. }
  95. }
  96. }
  97. /// <summary>
  98. /// 撤销确认
  99. /// </summary>
  100. private void cancelDoAffrim()
  101. {
  102. this.ultraGrid1.UpdateData();
  103. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  104. if (uRow == null) return;
  105. StlLgEntrustBillEntity stlLgEntity = (StlLgEntrustBillEntity)uRow.ListObject;
  106. string stlLgTity = JSONFormat.Format(stlLgEntity);
  107. if (MessageUtil.ShowYesNoAndQuestion("是否撤销确认?") == DialogResult.No) return;
  108. CoreClientParam ccp = new CoreClientParam();
  109. ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim";
  110. ccp.MethodName = "cancelDoAffrim";
  111. ccp.ServerParams = new object[] { stlLgTity,this.UserInfo.GetUserName() };
  112. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  113. if (ccp.ReturnCode != -1)
  114. {
  115. if (ccp.ReturnInfo.Equals("撤销成功!"))
  116. {
  117. doQueryEntrustBill();
  118. MessageUtil.ShowTips(ccp.ReturnInfo);
  119. }
  120. else
  121. {
  122. MessageUtil.ShowTips(ccp.ReturnInfo);
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// 委外完成
  128. /// </summary>
  129. private void subcontractComplete()
  130. {
  131. this.ultraGrid2.UpdateData();
  132. int toalNum = 0;
  133. string dbWgt = "";//单倍尺重量
  134. decimal quailToalWgt = 0;//合格总重量
  135. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  136. if (uRow == null)
  137. {
  138. MessageUtil.ShowTips("请选择对应委托回报实绩信息!");
  139. return;
  140. }
  141. IQueryable<UltraGridRow> checkMags = this.ultraGrid2.Rows.AsQueryable().Where(" CHK = 'True'");
  142. if(checkMags.Count() == 0)
  143. {
  144. MessageUtil.ShowTips("请勾选所回报实绩!");
  145. return;
  146. }
  147. if (!CheckQuerySub()) return;
  148. StlLgEntrustBillEntity stlEntrust = (StlLgEntrustBillEntity)uRow.ListObject;
  149. string stlLgEntrustTity = JSONFormat.Format(stlEntrust);
  150. DataTable ds = ServerHelper.GetData("Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryDbWgt", new object[] { stlLgEntrustTity }, ob);
  151. if(ds.Rows.Count>0)
  152. {
  153. dbWgt = ds.Rows[0]["WEIGHT_GP_ONE"].ToString();
  154. }
  155. ArrayList parm = new ArrayList();
  156. foreach (UltraGridRow row in checkMags)
  157. {
  158. StlLgEntrustBillDetialEntity stlLgEntrustDetial = (StlLgEntrustBillDetialEntity)row.ListObject;
  159. if (int.Parse(stlLgEntrustDetial.ComFixNum.ToString3()) > int.Parse(uRow.Cells["FixNum"].Text))
  160. {
  161. MessageUtil.ShowTips("回报的倍尺数不允许比原倍尺大");
  162. return;
  163. }
  164. if (stlLgEntrustDetial.SubcontractcompleteNum * stlLgEntrustDetial.ComFixNum == stlEntrust.FixNum * stlEntrust.SubcontractNum)
  165. {
  166. stlLgEntrustDetial.SubcontractCompleteWgt = stlEntrust.SubcontractWgt;
  167. }
  168. else
  169. {
  170. stlLgEntrustDetial.SubcontractCompleteWgt = int.Parse(stlLgEntrustDetial.ComFixNum.ToString()) * int.Parse(stlLgEntrustDetial.SubcontractcompleteNum.ToString()) * decimal.Parse(dbWgt);
  171. }
  172. stlLgEntrustDetial.ComLength = int.Parse(stlEntrust.Length.ToString()) * int.Parse(stlLgEntrustDetial.ComFixNum.ToString()) / int.Parse(stlEntrust.FixNum.ToString());
  173. string stlLgEntrustDetialTity = JSONFormat.Format(stlLgEntrustDetial);
  174. parm.Add(stlLgEntrustDetialTity);
  175. toalNum = toalNum + int.Parse(row.Cells["SubcontractcompleteNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3())
  176. + int.Parse(row.Cells["SubcontractscrapNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3());
  177. quailToalWgt = quailToalWgt + decimal.Parse(stlLgEntrustDetial.SubcontractCompleteWgt.ToString());
  178. }
  179. //int subToalNum = int.Parse(stlEntrust.SubcontractNum.ToString())*int.Parse(stlEntrust.FixNum.ToString());//委托单倍坯支数
  180. DataTable subToalNumDs = ServerHelper.GetData("Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryDbTrust", new object[] { stlLgEntrustTity }, ob);
  181. int subToalNum = int.Parse(subToalNumDs.Rows[0][0].ToString3());
  182. if (subToalNum >= toalNum)
  183. {
  184. StlLgEntrustBillDetialEntity stlLgEntrustDetialScrap = new StlLgEntrustBillDetialEntity();
  185. stlLgEntrustDetialScrap.SubcontractscrapNum = subToalNum - toalNum;
  186. stlLgEntrustDetialScrap.SubcontractscrapWgt = decimal.Parse(stlEntrust.SubcontractWgt.ToString()) - quailToalWgt;
  187. stlLgEntrustDetialScrap.ComFixNum = 1;
  188. stlLgEntrustDetialScrap.ComLength = stlEntrust.FixLen;
  189. string stlLgDetialScrap = JSONFormat.Format(stlLgEntrustDetialScrap);
  190. parm.Add(stlLgDetialScrap);
  191. }
  192. else
  193. {
  194. MessageUtil.ShowTips("回报的单倍尺支数不能比原单倍尺支数多!");
  195. return;
  196. }
  197. CoreClientParam ccp = new CoreClientParam();
  198. ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim";
  199. ccp.MethodName = "subcontractComplete";
  200. ccp.ServerParams = new object[] { stlLgEntrustTity,parm };
  201. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  202. if (ccp.ReturnCode != -1)
  203. {
  204. if (ccp.ReturnInfo.Equals("回报成功!"))
  205. {
  206. doQueryEntrustBill();
  207. MessageUtil.ShowTips(ccp.ReturnInfo);
  208. }
  209. else
  210. {
  211. MessageUtil.ShowTips(ccp.ReturnInfo);
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// 撤销委外完成
  217. /// </summary>
  218. private void cancelSubcontractComplete()
  219. {
  220. this.ultraGrid1.UpdateData();
  221. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  222. if (uRow == null)
  223. {
  224. MessageUtil.ShowTips("请选择需要撤销回报实绩的委托信息!");
  225. return;
  226. }
  227. StlLgEntrustBillEntity stlEntrust = (StlLgEntrustBillEntity)uRow.ListObject;
  228. string stlLgEntrustTity = JSONFormat.Format(stlEntrust);
  229. if (MessageUtil.ShowYesNoAndQuestion("是否确认撤销?") == DialogResult.No) return;
  230. CoreClientParam ccp = new CoreClientParam();
  231. ccp.ServerName = "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim";
  232. ccp.MethodName = "cancelSubcontractComplete";
  233. ccp.ServerParams = new object[] { stlLgEntrustTity };
  234. ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  235. if (ccp.ReturnCode != -1)
  236. {
  237. if (ccp.ReturnInfo.Equals("撤销成功!"))
  238. {
  239. doQueryEntrustBill();
  240. MessageUtil.ShowTips(ccp.ReturnInfo);
  241. }
  242. else
  243. {
  244. MessageUtil.ShowTips(ccp.ReturnInfo);
  245. }
  246. }
  247. }
  248. /// <summary>
  249. /// 查询委托
  250. /// </summary>
  251. private void doQueryEntrustBill()
  252. {
  253. string startTim = "";
  254. string endTim = "";
  255. string judgeNo = "";
  256. string subContractNo = "";
  257. string[] arr = BaseMethod.InitLgPermissions(this.ValidDataPurviewIds,"B", this.ob);
  258. if (!CheckQuery()) return;
  259. if (this.chkTim2.Checked)
  260. {
  261. startTim = this.StartTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  262. endTim = this.EndTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  263. }
  264. if (this.chkJugeNo.Checked)
  265. {
  266. judgeNo = this.txtJugeNo.Text.Trim();
  267. }
  268. if (this.chkSubContractNo.Checked)
  269. {
  270. subContractNo = this.txtSubContractNo.Text.Trim();
  271. }
  272. ArrayList parm = new ArrayList();
  273. parm.Add(subContractNo);
  274. parm.Add(judgeNo);
  275. List<StlLgEntrustBillEntity> listSource = EntityHelper.GetData<StlLgEntrustBillEntity>(
  276. "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryEntrustBill", new object[] { parm, startTim, endTim, arr }, this.ob);
  277. StlLgEntrustBillEntitybindingSource.DataSource = listSource;
  278. }
  279. /// <summary>
  280. /// 数据验证
  281. /// </summary>
  282. /// <returns></returns>
  283. private bool CheckQuery()
  284. {
  285. if (this.chkSubContractNo.Checked && string.IsNullOrEmpty(this.txtSubContractNo.Text.Trim()))
  286. {
  287. MessageUtil.ShowWarning("请输入委托单号!");
  288. return false;
  289. }
  290. if (this.chkJugeNo.Checked && string.IsNullOrEmpty(this.txtJugeNo.Text.Trim()))
  291. {
  292. MessageUtil.ShowWarning("请输入判定炉号!");
  293. return false;
  294. }
  295. return true;
  296. }
  297. /// <summary>
  298. /// 对录入数据验证
  299. /// </summary>
  300. /// <returns></returns>
  301. private bool CheckQuerySub()
  302. {
  303. this.ultraGrid2.UpdateData();
  304. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  305. var checkMags = this.ultraGrid2.Rows.Where(a=>a.GetValue("CHK") == "True");
  306. int groupCnt = checkMags.GroupBy(a => a.GetValue("ComFixNum")).Count();
  307. if (groupCnt != checkMags.Count())
  308. {
  309. MessageUtil.ShowTips("同样倍尺数的需回报在一行!");
  310. return false;
  311. }
  312. int toalNum = 0;//回报的总单倍支数
  313. foreach (UltraGridRow row in checkMags)
  314. {
  315. if(!StringUtil.IsInt(row.Cells["ComFixNum"].Text.Trim()))
  316. {
  317. MessageUtil.ShowTips("倍尺请输入整数!");
  318. return false;
  319. }
  320. //if (!StringUtil.IsInt(row.Cells["ComLength"].Text.Trim()))
  321. //{
  322. // MessageUtil.ShowTips("坯长度请输整数!");
  323. // return false;
  324. //}
  325. //if (row.Cells["SubcontractcompleteNum"].Text.Trim() != ""&& row.Cells["SubcontractcompleteNum"].Text.Trim() !="0")
  326. //{
  327. // if (row.Cells["SubcontractCompleteWgt"].Text.Trim() == "" || row.Cells["SubcontractCompleteWgt"].Text.Trim() == "0")
  328. // {
  329. // MessageUtil.ShowTips("合格支数有时,不允许无合格重量!");
  330. // return false;
  331. // }
  332. //}
  333. //if (row.Cells["SubcontractCompleteWgt"].Text.Trim() != "" && row.Cells["SubcontractCompleteWgt"].Text.Trim() != "0")
  334. //{
  335. // if (row.Cells["SubcontractcompleteNum"].Text.Trim() == "" || row.Cells["SubcontractcompleteNum"].Text.Trim() == "0")
  336. // {
  337. // MessageUtil.ShowTips("合格重量有时,不允许无合格支数!");
  338. // return false;
  339. // }
  340. //}
  341. //if (row.Cells["SubcontractscrapNum"].Text.Trim() != "" && row.Cells["SubcontractscrapNum"].Text.Trim() != "0")
  342. //{
  343. // if (row.Cells["SubcontractscrapWgt"].Text.Trim() == "" || row.Cells["SubcontractscrapWgt"].Text.Trim() == "0")
  344. // {
  345. // MessageUtil.ShowTips("废品支数有时,不允许无废品重量!");
  346. // return false;
  347. // }
  348. //}
  349. //if (row.Cells["SubcontractscrapWgt"].Text.Trim() != "" && row.Cells["SubcontractscrapWgt"].Text.Trim() != "0")
  350. //{
  351. // if (row.Cells["SubcontractscrapNum"].Text.Trim() == "" || row.Cells["SubcontractscrapNum"].Text.Trim() == "0")
  352. // {
  353. // MessageUtil.ShowTips("废品重量有时,不允许无废品支数!");
  354. // return false;
  355. // }
  356. //}
  357. if (row.Cells["SubcontractcompleteNum"].Text.Trim() != "")
  358. {
  359. if (!StringUtil.IsInt(row.Cells["SubcontractcompleteNum"].Text.Trim()))
  360. {
  361. MessageUtil.ShowTips("合格支数请输入整数!");
  362. return false;
  363. }
  364. }
  365. //if (row.Cells["SubcontractCompleteWgt"].Text.Trim() != "")
  366. //{
  367. // if (!StringUtil.IsDouble(row.Cells["SubcontractCompleteWgt"].Text.Trim()))
  368. // {
  369. // MessageUtil.ShowTips("合格重量请输入小数或者整数!");
  370. // return false;
  371. // }
  372. //}
  373. //if (row.Cells["SubcontractscrapNum"].Text.Trim() != "")
  374. //{
  375. // if (!StringUtil.IsInt(row.Cells["SubcontractscrapNum"].Text.Trim()))
  376. // {
  377. // MessageUtil.ShowTips("废品支数请输入整数!");
  378. // return false;
  379. // }
  380. //}
  381. //if (row.Cells["SubcontractscrapWgt"].Text.Trim() != "")
  382. //{
  383. // if (!StringUtil.IsDouble(row.Cells["SubcontractscrapWgt"].Text.Trim()))
  384. // {
  385. // MessageUtil.ShowTips("废品重量请输入小数或者整数!");
  386. // return false;
  387. // }
  388. //}
  389. toalNum = toalNum + int.Parse(row.Cells["SubcontractcompleteNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3())
  390. + int.Parse(row.Cells["SubcontractscrapNum"].Text.Trim().ToString3()) * int.Parse(row.Cells["ComFixNum"].Text.Trim().ToString3());
  391. }
  392. //if (int.Parse(uRow.Cells["SubcontractNum"].Text.Trim()) * int.Parse(uRow.Cells["FixNum"].Text.Trim()) != toalNum)
  393. //{
  394. // MessageUtil.ShowTips("委外加工支数与回报实绩支数不符!");
  395. // return false;
  396. //}
  397. return true;
  398. }
  399. private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  400. {
  401. UltraGridRow uRow = this.ultraGrid1.ActiveRow;
  402. if (uRow == null) return;
  403. ArrayList list = new ArrayList();
  404. list.Add(uRow.Cells["SubcontractNo"].Text);
  405. list.Add(uRow.Cells["StoveNo"].Text);
  406. list.Add(uRow.Cells["JudgeStoveNoSeq"].Text);
  407. list.Add(uRow.Cells["SubcontractNoSeq"].Text);
  408. StlLgEntrustBillDetialEntitybindingSource.Clear();
  409. List<StlLgEntrustBillDetialEntity> listSource = EntityHelper.GetData<StlLgEntrustBillDetialEntity>(
  410. "Core.LgMes.Server.Stuffmanage.FrmSubContractAffrim.doQueryEntrustBillDetial", new object[] { list }, this.ob);
  411. StlLgEntrustBillDetialEntitybindingSource.DataSource = listSource;
  412. }
  413. private void chkTim2_CheckedChanged(object sender, EventArgs e)
  414. {
  415. this.StartTime.Enabled = this.EndTime.Enabled = this.chkTim2.Checked;
  416. }
  417. private void chkJugeNo_CheckedChanged(object sender, EventArgs e)
  418. {
  419. this.txtJugeNo.Enabled = this.chkJugeNo.Checked;
  420. }
  421. private void chkSubContractNo_CheckedChanged(object sender, EventArgs e)
  422. {
  423. this.txtSubContractNo.Enabled = this.chkSubContractNo.Checked;
  424. }
  425. private void txtJugeNo_KeyDown(object sender, KeyEventArgs e)
  426. {
  427. if (e.KeyValue == 13)
  428. {
  429. doQueryEntrustBill();
  430. }
  431. }
  432. }
  433. }