FrmMaterialSeparate.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. using Core.Mes.Client.Comm.Tool;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using Core.StlMes.Client.PlnSaleOrd.PlanStove.entity;
  11. using CoreFS.CA06;
  12. using CoreFS.SA06;
  13. using Core.Mes.Client.Comm.Server;
  14. using Core.Mes.Client.Comm.Control;
  15. using Infragistics.Win.UltraWinGrid;
  16. using System.Text.RegularExpressions;
  17. namespace Core.StlMes.Client.PlnSaleOrd.PlanStove.Dlg
  18. {
  19. public partial class FrmMaterialSeparate : FrmBase
  20. {
  21. private string m_userName;
  22. private bool isFirstInit=true;
  23. //action
  24. public event Action OnDataChange;
  25. public FrmMaterialSeparate(string _CustomInfo,OpeBase _ob,string _userName)
  26. {
  27. InitializeComponent();
  28. this.CustomInfo = _CustomInfo;
  29. this.ob = _ob;
  30. m_userName = _userName;
  31. this.ultraGrid1.CellChange += ultraGrid1_CellChange;
  32. this.ultraGrid1.AfterRowActivate += ultraGrid1_AfterRowActivate;
  33. this.ultraGrid2.CellChange += ultraGrid2_CellChange;
  34. }
  35. private void FrmMaterialSeprate_Load(object sender, EventArgs e)
  36. {
  37. switch (CustomInfo)
  38. {
  39. case CustomInfoDef.DEFINE_CUSTOMER_DBK:
  40. this.ultraGrid2.DataSource = this.plnZyDbkMEntityBindingSource;
  41. this.ultraGrid2.DataBind();
  42. EntityHelper.ShowGridCaption<PlnZyDbkMEntity>(this.ultraGrid2.DisplayLayout.Bands[0]);
  43. AddZYChooseColumn(0);
  44. break;
  45. case CustomInfoDef.DEFINE_CUSTOMER_JG:
  46. this.ultraGrid2.DataSource = this.plnZyJgxMEntityBindingSource;
  47. this.ultraGrid2.DataBind();
  48. EntityHelper.ShowGridCaption<PlnZyJgxMEntity>(this.ultraGrid2.DisplayLayout.Bands[0]);
  49. EntityHelper.ShowGridCaption<PlnZyJgxCEntity>(this.ultraGrid2.DisplayLayout.Bands[1]);
  50. AddZYChooseColumn(1);
  51. break;
  52. case CustomInfoDef.DEFINE_CUSTOMER_RCL:
  53. this.ultraGrid2.DataSource = this.plnZyRclMEntityBindingSource;
  54. this.ultraGrid2.DataBind();
  55. EntityHelper.ShowGridCaption<PlnZyRclMEntity>(this.ultraGrid2.DisplayLayout.Bands[0]);
  56. AddZYChooseColumn(0);
  57. break;
  58. case CustomInfoDef.DEFINE_CUSTOMER_ZG:
  59. this.ultraGrid2.DataSource = this.plnZyZgMEntityBindingSource;
  60. this.ultraGrid2.DataBind();
  61. EntityHelper.ShowGridCaption<PlnZyZgMEntity>(this.ultraGrid2.DisplayLayout.Bands[0]);
  62. EntityHelper.ShowGridCaption<PlnZyZgCEntity>(this.ultraGrid2.DisplayLayout.Bands[1]);
  63. AddZYChooseColumn(1);
  64. break;
  65. }
  66. this.ultraGrid2.DisplayLayout.Bands[0].Columns["HeatPlanNo"].Header.Caption = "炉计划号";
  67. AddZYEditedColumn();
  68. CommHelper.SetGridColNoEdit(this.ultraGrid1.DisplayLayout.Bands[0], new string[] { "Choose", "USER_ACT_COUNT" });
  69. CommHelper.SetGridColNoEdit(this.ultraGrid2.DisplayLayout.Bands[0], new string[] { "ChooseZY", "USER_ACT_COUNT" });
  70. if (this.ultraGrid2.DisplayLayout.Bands.Count > 1)
  71. {
  72. CommHelper.SetGridColNoEdit(this.ultraGrid2.DisplayLayout.Bands[1], new string[] { "USER_ACT_COUNT" });
  73. }
  74. queryMat();
  75. CommHelper.SetColumnAutoFitSize1(this.ultraGrid1.DisplayLayout.Bands[0]);
  76. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "PlineName", 1);
  77. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "OrderNo", 2);
  78. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "OrderSeq", 3);
  79. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "USER_ACT_COUNT", 4);
  80. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "InNum", 5);
  81. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "USER_ACT_WEIGHT", 6);
  82. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "InWt", 7);
  83. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "ProPlanId", 8);
  84. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "GxPlanNo", 9);
  85. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "HeatPlanNo", 10);
  86. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "HeatnoLast", 11);
  87. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "ZgBatchNo", 12);
  88. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "LastBatchNo", 13);
  89. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "BatchGroudNo", 14);
  90. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "OrderSource", 15);
  91. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "OutNum", 16);
  92. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "OutWt", 17);
  93. CommHelper.SetColumsHide(this.ultraGrid2.DisplayLayout.Bands[0], new List<string>() { "PlineCode", "InwlId" });
  94. this.ultraGrid2.DisplayLayout.Bands[0].Columns["OrderSource"].Header.Caption = "主合同来源";
  95. this.ultraGrid2.DisplayLayout.Bands[0].Columns["Planstatus"].Header.Caption = "执行状态";
  96. }
  97. #region 初始化
  98. /// <summary>
  99. /// 往作业计划表中加入选择列,如果有子表,insertIndex应为1
  100. /// </summary>
  101. /// <param name="insertIndex"></param>
  102. private void AddZYChooseColumn(int insertIndex)
  103. {
  104. Infragistics.Win.UltraWinGrid.UltraGridColumn col = CommHelper.InsertColumn("ChooseZY", "", this.ultraGrid2.DisplayLayout.Bands[0], insertIndex);
  105. col.DataType = typeof(bool);
  106. col.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
  107. col.CellAppearance.BackColor = Color.Yellow;
  108. col.Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
  109. }
  110. private void AddZYEditedColumn()
  111. {
  112. UltraGridColumn col = CommHelper.InsertColumn("USER_ACT_COUNT", "脱单支数", this.ultraGrid2.DisplayLayout.Bands[0], 4);
  113. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "InNum", 5);
  114. col.DataType = typeof(long);
  115. col.EditorComponent = this.ultraNumericEditor1;
  116. col.MaskInput = "";
  117. col.PromptChar = ' ';
  118. col.CellAppearance.BackColor = Color.Yellow;
  119. if (ultraGrid2.DisplayLayout.Bands.Count > 1)
  120. {
  121. UltraGridColumn childcol = CommHelper.InsertColumn("USER_ACT_COUNT", "脱单支数", this.ultraGrid2.DisplayLayout.Bands[1], 4);
  122. childcol.EditorComponent = this.ultraNumericEditor1;
  123. childcol.DataType = typeof(long);
  124. childcol.MaskInput = "";
  125. childcol.PromptChar = ' ';
  126. childcol.CellAppearance.BackColor = Color.Yellow;
  127. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[1], "InGpNum", 5);
  128. UltraGridColumn childcol1 = CommHelper.InsertColumn("USER_ACT_WEIGHT", "脱单重量", this.ultraGrid2.DisplayLayout.Bands[1], 6);
  129. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[1], "InGpWt", 7);
  130. }
  131. else
  132. {
  133. UltraGridColumn col1 = CommHelper.InsertColumn("USER_ACT_WEIGHT", "脱单重量", this.ultraGrid2.DisplayLayout.Bands[0], 6);
  134. CommHelper.SetColumnPosition(this.ultraGrid2.DisplayLayout.Bands[0], "InWt", 7);
  135. }
  136. }
  137. #endregion
  138. #region 控件事件
  139. void ultraGrid2_CellChange(object sender, CellEventArgs e)
  140. {
  141. this.ultraGrid2.UpdateData();
  142. if (e.Cell.Column.Key.Equals("USER_ACT_COUNT"))
  143. {
  144. if (!Regex.IsMatch(e.Cell.Value.ToString().Trim(), @"^-?[1-9]\d*$|^0$"))
  145. {
  146. e.Cell.Value = 0;
  147. return;
  148. }
  149. }
  150. if (e.Cell.Text != null)
  151. {
  152. if (!e.Cell.Row.HasParent() && e.Cell.Column.Key.Equals("USER_ACT_COUNT"))
  153. {
  154. if ( e.Cell.Row.Cells["ChooseZY"].Text.Equals("True"))
  155. {
  156. e.Cell.Value = 0;
  157. return;
  158. }
  159. if (Convert.ToInt64(e.Cell.Value) != 0)
  160. {
  161. long user_act_count = Convert.ToInt64(e.Cell.Value);
  162. long act_count = 0;
  163. if (CustomInfo != CustomInfoDef.DEFINE_CUSTOMER_ZG)
  164. {
  165. act_count = Convert.ToInt64(e.Cell.Row.Cells["InNum"].Text);
  166. }
  167. else
  168. {
  169. act_count = Convert.ToInt64(e.Cell.Row.Cells["PlanGpNum"].Text);
  170. }
  171. int nTotalCount=0;
  172. var matrow = this.ultraGrid1.Rows.FirstOrDefault(c => c.Cells["Choose"].Text.Equals("True"));
  173. int maxCount = 0;
  174. if (!String.IsNullOrEmpty(matrow.Cells["USER_ACT_COUNT"].Text.Trim()))
  175. {
  176. maxCount = Convert.ToInt32(matrow.Cells["USER_ACT_COUNT"].Value);
  177. }
  178. var rows = this.ultraGrid2.Rows.Where(c => !String.IsNullOrEmpty(c.Cells["USER_ACT_COUNT"].Text) && c.Cells["ChooseZY"].Text.Equals("True"));
  179. foreach(var row in rows)
  180. {
  181. nTotalCount += Convert.ToInt32(row.Cells["USER_ACT_COUNT"].Value);
  182. }
  183. if (nTotalCount > maxCount || user_act_count > act_count)
  184. {
  185. e.Cell.Value = e.Cell.OriginalValue;
  186. }
  187. else
  188. {
  189. UltraGridRow childrow =null;
  190. double act_weight = 0;
  191. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  192. {
  193. childrow = e.Cell.Row.ChildBands[0].Rows.FirstOrDefault(c => c.Cells["LengthGp"].Text.Trim().Equals(matrow.Cells["ACT_LEN"].Text.Trim()));
  194. act_weight =Convert.ToDouble(childrow.Cells["InGpWt"].Text);
  195. }
  196. else
  197. {
  198. act_weight = Convert.ToDouble(e.Cell.Row.Cells["InWt"].Value);
  199. }
  200. double single_weight = act_weight / act_count;
  201. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  202. {
  203. }
  204. else
  205. {
  206. e.Cell.Row.Cells["USER_ACT_WEIGHT"].Value = CommHelper.GetSpecDecimalBit(user_act_count * single_weight, 3);
  207. }
  208. e.Cell.Appearance.BackColor = System.Drawing.Color.Pink;
  209. }
  210. }
  211. else
  212. {
  213. e.Cell.Row.Cells["USER_ACT_WEIGHT"].Value = 0;
  214. }
  215. }
  216. else if (e.Cell.Column.Key.Equals("ChooseZY"))
  217. {
  218. if (e.Cell.Text.ToLower() == "true")
  219. {
  220. e.Cell.Row.Cells["USER_ACT_COUNT"].Activation = Activation.AllowEdit;
  221. }
  222. else
  223. {
  224. e.Cell.Row.Cells["USER_ACT_COUNT"].Value = 0 ;
  225. }
  226. }
  227. }
  228. }
  229. void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
  230. {
  231. this.ultraGrid1.UpdateData();
  232. //throw new NotImplementedException();
  233. }
  234. void ultraGrid1_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  235. {
  236. this.ultraGrid1.UpdateData();
  237. if (e.Cell.Column.Key.Equals("USER_ACT_COUNT"))
  238. {
  239. if (!Regex.IsMatch(e.Cell.Value.ToString(), @"^-?[1-9]\d*$|^0$"))
  240. {
  241. e.Cell.Value = 0;
  242. return;
  243. }
  244. }
  245. if (e.Cell.Text != null)
  246. {
  247. if (e.Cell.Column.Key.Equals("USER_ACT_COUNT"))
  248. {
  249. if (!e.Cell.Row.Cells["Choose"].Text.Equals("True"))
  250. {
  251. e.Cell.Value = e.Cell.OriginalValue;
  252. return;
  253. }
  254. long user_act_count = Convert.ToInt64(e.Cell.Value);
  255. long act_count = Convert.ToInt64(e.Cell.Row.Cells["ACT_COUNT"].Value);
  256. if (user_act_count > act_count)
  257. {
  258. e.Cell.Value = e.Cell.OriginalValue;
  259. }
  260. else
  261. {
  262. double act_weight = Convert.ToDouble(e.Cell.Row.Cells["ACT_WEIGHT"].Value);
  263. double single_weight = act_weight / act_count;
  264. e.Cell.Row.Cells["USER_ACT_WEIGHT"].Value = CommHelper.GetSpecDecimalBit(user_act_count * single_weight, 3);
  265. e.Cell.Appearance.BackColor = System.Drawing.Color.Pink;
  266. if (this.ultraGrid2.Rows.Count > 0)
  267. {
  268. setUserActCount(user_act_count, e.Cell.Row.Cells["ACT_LEN"].Value);
  269. }
  270. this.ultraGrid1.Refresh();
  271. }
  272. }
  273. else if (e.Cell.Column.Key.Equals("Choose"))
  274. {
  275. if (e.Cell.Text.ToLower() == "true")
  276. {
  277. e.Cell.Row.Cells["USER_ACT_COUNT"].Activation = Activation.AllowEdit;
  278. this.ultraGrid1.Refresh();
  279. var rows = this.ultraGrid1.Rows.Where(c => c.Cells["Choose"].Text.ToLower() == "true");
  280. if (rows.Count() > 1)
  281. {
  282. e.Cell.Row.Cells["Choose"].Value = false;
  283. }
  284. else if(rows.Count() == 1)
  285. {
  286. var row = rows.First();
  287. InitZYData(row.Cells["JUDGE_STOVE_NO"].Text, row.Cells["BATCH_NO"].Text, row.Cells["BATCH_GROUD_NO"].Text, row.Cells["PRO_ORDER_ID"].Text, row.Cells["GX_PLAN_NO"].Text);
  288. }
  289. }
  290. else
  291. {
  292. e.Cell.Row.Cells["USER_ACT_COUNT"].Value = 0;
  293. switch (CustomInfo)
  294. {
  295. case CustomInfoDef.DEFINE_CUSTOMER_DBK:
  296. this.plnZyDbkMEntityBindingSource.Clear();
  297. break;
  298. case CustomInfoDef.DEFINE_CUSTOMER_JG:
  299. this.plnZyJgxMEntityBindingSource.Clear();
  300. break;
  301. case CustomInfoDef.DEFINE_CUSTOMER_RCL:
  302. this.plnZyRclMEntityBindingSource.Clear();
  303. break;
  304. case CustomInfoDef.DEFINE_CUSTOMER_ZG:
  305. this.plnZyZgMEntityBindingSource.Clear();
  306. break;
  307. }
  308. }
  309. }
  310. }
  311. //throw new NotImplementedException();
  312. }
  313. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  314. {
  315. switch (e.Tool.Key)
  316. {
  317. case "separate": separate(); break;
  318. case "close":
  319. if (OnDataChange != null)
  320. {
  321. OnDataChange();
  322. }
  323. this.Close();
  324. break;
  325. case "search": queryMat(); break;
  326. }
  327. }
  328. #endregion
  329. #region 数据库操作
  330. private void InitZYData(string stoveNo, string BatchNo, string BatchGroupNo, string proPlanId, string GxPlanNo)
  331. {
  332. Object[] parameters = new object[] { stoveNo, BatchNo, BatchGroupNo, proPlanId, GxPlanNo };
  333. switch (CustomInfo)
  334. {
  335. case CustomInfoDef.DEFINE_CUSTOMER_DBK:
  336. var datasourcedbkM = EntityHelper.GetData<PlnZyDbkMEntity>(MethodDef.PlanLuDBK.queryZYDBK, parameters, this.ob);
  337. this.plnZyDbkMEntityBindingSource.DataSource = datasourcedbkM;
  338. break;
  339. case CustomInfoDef.DEFINE_CUSTOMER_JG:
  340. var datasourcesjgxM = EntityHelper.GetData<PlnZyJgxMEntity>(MethodDef.PlanLuJGX.queryZYJGXM, parameters, this.ob);
  341. var datasourcesjgxC = EntityHelper.GetData<PlnZyJgxCEntity>(MethodDef.StoveBase.queryZy, new Object[] { SqlIDDef.PlanLuJGX.queryZYJGXC }, this.ob);
  342. EntityHelper.AddEntityRelation<PlnZyJgxMEntity, PlnZyJgxCEntity>(datasourcesjgxM, datasourcesjgxC, "HeatPlanNo", "HeatPlanNo");
  343. this.plnZyJgxMEntityBindingSource.DataSource = datasourcesjgxM;
  344. break;
  345. case CustomInfoDef.DEFINE_CUSTOMER_RCL:
  346. var datasourcerclM = EntityHelper.GetData<PlnZyRclMEntity>(MethodDef.PlanLuRCL.queryZYRCL, parameters, this.ob);
  347. this.plnZyRclMEntityBindingSource.DataSource = datasourcerclM;
  348. break;
  349. case CustomInfoDef.DEFINE_CUSTOMER_ZG:
  350. var datasourcesZgM = EntityHelper.GetData<PlnZyZgMEntity>(MethodDef.PlanLuZG.queryZYZGM, parameters, this.ob);
  351. var datasourcesZgC = EntityHelper.GetData<PlnZyZgCEntity>(MethodDef.StoveBase.queryZy, new Object[] { SqlIDDef.PlanLuZG.queryZYZGC }, this.ob);
  352. EntityHelper.AddEntityRelation<PlnZyZgMEntity, PlnZyZgCEntity>(datasourcesZgM, datasourcesZgC, "HeatPlanNo", "HeatPlanNo");
  353. this.plnZyZgMEntityBindingSource.DataSource = datasourcesZgM;
  354. break;
  355. }
  356. if (isFirstInit)
  357. {
  358. CommHelper.SetColumnAutoFitSize1(this.ultraGrid2.DisplayLayout.Bands[0]);
  359. if (this.ultraGrid2.DisplayLayout.Bands.Count > 1)
  360. {
  361. CommHelper.SetColumnAutoFitSize1(this.ultraGrid2.DisplayLayout.Bands[1]);
  362. }
  363. isFirstInit = false;
  364. }
  365. }
  366. private void separate()
  367. {
  368. var matrow = this.ultraGrid1.Rows.FirstOrDefault(c => c.Cells["Choose"].Text.Equals("True"));
  369. if (matrow == null)
  370. {
  371. MessageUtil.ShowWarning("没有勾选物料!");
  372. return;
  373. }
  374. int maxCount = 0;
  375. if (!String.IsNullOrEmpty(matrow.Cells["USER_ACT_COUNT"].Text.Trim()))
  376. {
  377. maxCount = Convert.ToInt32(matrow.Cells["USER_ACT_COUNT"].Text.Trim());
  378. }
  379. int nTotalCount = 0;
  380. var rows = this.ultraGrid2.Rows.Where(c => !String.IsNullOrEmpty(c.Cells["USER_ACT_COUNT"].Text) && c.Cells["ChooseZY"].Text.Equals("True"));
  381. if (rows.Count() <= 0)
  382. {
  383. MessageUtil.ShowTips("没有勾选作业计划或者没有指定脱单量,脱单时需要指定作业计划以及脱单量!");
  384. return;
  385. }
  386. foreach (var row in rows)
  387. {
  388. if (row.HasChild())
  389. {
  390. var childrows = row.ChildBands[0].Rows.Where(c=>!CommHelper.IsNullOrEmptry(c.Cells["USER_ACT_COUNT"].Text));
  391. foreach(var childRow in childrows)
  392. {
  393. nTotalCount += Convert.ToInt32(childRow.Cells["USER_ACT_COUNT"].Text);
  394. }
  395. }
  396. else
  397. {
  398. nTotalCount += Convert.ToInt32(row.Cells["USER_ACT_COUNT"].Text);
  399. }
  400. }
  401. if (nTotalCount != maxCount)
  402. {
  403. MessageUtil.ShowError("所选物料脱单支数和计划脱单支数不一致,请检查输入!");
  404. return;
  405. }
  406. List<string> sqlidList = new List<string>();
  407. List<List<Object>> parameters = new List<List<object>>();
  408. foreach (var row in rows)//针对所选的作业计划逐行脱单
  409. {
  410. int sepOutNum = 0;//脱单的计划产出数
  411. double sepOutWt = 0;//脱单的计划产出重量
  412. int sepcount = Convert.ToInt32(row.Cells["USER_ACT_COUNT"].Text);//脱单支数
  413. int innum = 0;
  414. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  415. {
  416. if (!row.Cells["Planstatus"].Text.Trim().Equals("计划"))
  417. {
  418. MessageUtil.ShowWarning("轧管只允状态为计划的作业计划进行脱单");
  419. return;
  420. }
  421. if(row.HasChild())
  422. {
  423. innum = Convert.ToInt32(row.ChildBands[0].Rows.FirstOrDefault(c => c.Cells["LengthGp"].Text.Trim().Equals(matrow.Cells["ACT_LEN"].Text.Trim())).Cells["InGpNum"].Value);
  424. }
  425. else
  426. {
  427. continue;
  428. }
  429. }
  430. else
  431. {
  432. innum = Convert.ToInt32(row.Cells["InNum"].Text);//原投入支数;
  433. }
  434. double singleinwt = Convert.ToDouble(matrow.Cells["ACT_WEIGHT"].Text) / Convert.ToInt32(matrow.Cells["ACT_COUNT"].Text);//投入料单支重量
  435. double singleoutwt = Convert.ToDouble(row.Cells["OutWt"].Value) / Convert.ToInt32(row.Cells["OutNum"].Value);//产出料单支重量
  436. string sqlIdDelete = "";
  437. string sqlUpdateZy = "";
  438. string sqlIdUpdateMatBack = SqlIDDef.MaterialChoose.updateMaterialBack;
  439. string sqlIdUpdateBatch = "";
  440. string sqlIdUpdateMatch = "";
  441. switch (CustomInfo)
  442. {
  443. case CustomInfoDef.DEFINE_CUSTOMER_DBK:
  444. sqlIdDelete = SqlIDDef.PlanLuDBK.deleteZyDbkM;
  445. sqlUpdateZy = SqlIDDef.PlanLuDBK.UpdateZYDBK_WT_NUM;
  446. sqlIdUpdateBatch = SqlIDDef.PlanLuDBK.UpdateOrderDBK_WT_NUM;
  447. sqlIdUpdateMatch = SqlIDDef.PlanLuDBK.UpdateOrderDBK_MATCH_WT_NUM;
  448. break;
  449. case CustomInfoDef.DEFINE_CUSTOMER_JG:
  450. sqlIdDelete = SqlIDDef.PlanLuJGX.deleteZyJgxM;
  451. sqlUpdateZy = SqlIDDef.PlanLuJGX.UpdateZYJGX_WT_NUM;
  452. sqlIdUpdateBatch = SqlIDDef.PlanLuJGX.UpdateOrderJGX_WT_NUM;
  453. sqlIdUpdateMatch = SqlIDDef.PlanLuJGX.UpdateOrderJGX_MATCH_WT_NUM;
  454. break;
  455. case CustomInfoDef.DEFINE_CUSTOMER_RCL:
  456. sqlIdDelete = SqlIDDef.PlanLuRCL.deleteZyRclM;
  457. sqlUpdateZy = SqlIDDef.PlanLuRCL.UpdateZYRCL_WT_NUM;
  458. sqlIdUpdateBatch = SqlIDDef.PlanLuRCL.UpdateRCLORDER_WT_NUM;
  459. sqlIdUpdateMatch = SqlIDDef.PlanLuRCL.UpdateOrderRCL_MATCH_WT_NUM;
  460. break;
  461. case CustomInfoDef.DEFINE_CUSTOMER_ZG:
  462. sqlIdDelete = SqlIDDef.PlanLuZG.deleteZyZgM;
  463. sqlUpdateZy = SqlIDDef.PlanLuZG.UpdateZYZG_WT_NUM;
  464. sqlIdUpdateMatBack = SqlIDDef.MaterialChoose.updateGPBack;
  465. sqlIdUpdateBatch = SqlIDDef.PlanLuZG.UpdateOrderZG_WT_NUM;
  466. sqlIdUpdateMatch = SqlIDDef.PlanLuZG.UpdateOrderZG_MATCH_WT_NUM;
  467. break;
  468. }
  469. if (sepcount == innum)
  470. {
  471. //删除作业计划(轧管和加工线可能只删除从表)
  472. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_JG)
  473. {
  474. sqlidList.Add(SqlIDDef.PlanLuJGX.deleteZyJgxC);
  475. parameters.Add(new List<Object>() { row.Cells["HeatPlanNo"].Text });
  476. }
  477. else if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)//只删除对应长度的从表
  478. {
  479. if (row.HasChild())
  480. {
  481. UltraGridRow childrow = row.ChildBands[0].Rows.FirstOrDefault(c => c.Cells["LengthGp"].Text.Trim().Equals(matrow.Cells["ACT_LEN"].Text.Trim()));
  482. PlnZyZgCEntity zyzgc = (PlnZyZgCEntity)childrow.ListObject;
  483. PlnZyZgMEntity zyzgm = (PlnZyZgMEntity)row.ListObject;
  484. sqlidList.Add(SqlIDDef.PlanLuZG.deleteZyZgCByCutNo);
  485. parameters.Add(new List<Object>() { zyzgm.HeatPlanNo, zyzgc.GpCutNo });
  486. if (row.ChildBands[0].Rows.Count == 1)
  487. {
  488. sqlidList.Add(SqlIDDef.PlanLuZG.deleteZyZgM);
  489. parameters.Add(new List<Object>() {zyzgm.HeatPlanNo });
  490. }
  491. else//冲减作业计划量
  492. {
  493. int cutsinglenum = Convert.ToInt32(zyzgm.CutSingleNum);
  494. double cutsinglewt = Convert.ToDouble(zyzgm.CutSingleWt);
  495. //脱单单倍坯量
  496. int sepCutSingleNum = Convert.ToInt32(zyzgc.CutSingleNum);
  497. double sepCutSingleWt = Convert.ToDouble(zyzgc.CutSingleWt);
  498. //原始量
  499. int OriOutNum=Convert.ToInt32(zyzgm.OutNum);
  500. Double OriOutWt = Convert.ToDouble(zyzgm.OutWt);
  501. int OrioutNumCut = Convert.ToInt32(zyzgm.OutnumCut);
  502. //脱单计划产出量
  503. sepOutNum = sepCutSingleNum * OrioutNumCut;
  504. sepOutWt = CommHelper.GetSpecDecimalBit(sepOutNum * PlanComm.WeightOfMi(Convert.ToDouble(zyzgm.Aimoutdiameter), Convert.ToDouble(zyzgm.Aimwallthick)) * Convert.ToDouble(zyzgm.Aimlength), 3);
  505. cutsinglewt -= sepCutSingleWt;
  506. cutsinglenum -= sepCutSingleNum;
  507. int outNum = OriOutNum - sepOutNum;
  508. double outWt = OriOutWt - sepOutWt;
  509. int plngpnum = Convert.ToInt32(zyzgm.PlanGpNum) - sepcount;
  510. sqlidList.Add(SqlIDDef.PlanLuZG.UpdateZYZG_WT_NUM);
  511. parameters.Add(new List<Object>() {cutsinglenum,cutsinglewt,outNum,outWt,m_userName,plngpnum,zyzgm.HeatPlanNo });
  512. }
  513. }
  514. else
  515. {
  516. sqlidList.Add(sqlIdDelete);
  517. parameters.Add(new List<Object>() { row.Cells["HeatPlanNo"].Text });
  518. }
  519. }
  520. else
  521. {
  522. sqlidList.Add(sqlIdDelete);
  523. parameters.Add(new List<Object>() { row.Cells["HeatPlanNo"].Text });
  524. }
  525. }
  526. else if (sepcount < innum)
  527. {
  528. //冲减作业计划量
  529. int finalinnum = innum - sepcount;//最终投入支数
  530. int finaloutnum = innum - sepcount;//最终产出重量(轧管不可用)
  531. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  532. {
  533. //冲减从表作业计划量
  534. if (row.HasChild())
  535. {
  536. UltraGridRow childrow = row.ChildBands[0].Rows.FirstOrDefault(c => c.Cells["LengthGp"].Text.Trim().Equals(matrow.Cells["ACT_LEN"].Text.Trim()));
  537. PlnZyZgCEntity zyzgc = (PlnZyZgCEntity)childrow.ListObject;
  538. PlnZyZgMEntity zyzgm = (PlnZyZgMEntity)row.ListObject;
  539. int oriInGpNum = Convert.ToInt32(zyzgc.InGpNum);
  540. double oriInGpWt = Convert.ToDouble(zyzgc.InGpWt);
  541. int oriCutSingleNum = Convert.ToInt32(zyzgc.CutSingleNum);
  542. double oriCutSingleWt = Convert.ToDouble(zyzgc.CutSingleWt);
  543. double sepGpWt = sepcount * singleinwt;
  544. int sepCutSingleNum = sepcount * Convert.ToInt32(zyzgc.MultipleNum);
  545. double sepCutSingleWt = Convert.ToInt32(zyzgc.LenGpSingle) * PlanComm.GpweightOfmi(Convert.ToDouble(zyzgm.DiameterGp)) * sepCutSingleNum * 0.001;
  546. oriInGpNum -= sepcount;
  547. oriInGpWt -= sepGpWt;
  548. oriCutSingleNum -= sepCutSingleNum;
  549. oriCutSingleWt -= sepCutSingleWt;//单倍坯长*米单重*单倍坯支数
  550. sqlidList.Add(SqlIDDef.PlanLuZG.UpdateZYZGC_GPWT_GPNUM);
  551. parameters.Add(new List<Object>() {oriCutSingleNum,CommHelper.GetSpecDecimalBit(oriCutSingleWt,3),oriInGpNum,CommHelper.GetSpecDecimalBit(oriInGpWt,3),zyzgc.HeatPlanNo,zyzgc.GpCutNo });
  552. //冲减主表作业计划量
  553. int oriMCutSingleNum = Convert.ToInt32(zyzgm.CutSingleNum);
  554. double oriMCutSingleWt = Convert.ToDouble(zyzgm.CutSingleWt);
  555. int oriPlnGpNum = Convert.ToInt32(zyzgm.PlanGpNum);
  556. int oriOutNum = Convert.ToInt32(zyzgm.OutNum);
  557. double oriOutWt = Convert.ToDouble(zyzgm.OutWt);
  558. sepOutNum = sepCutSingleNum * Convert.ToInt32(zyzgm.OutnumCut);
  559. sepOutWt = CommHelper.GetSpecDecimalBit(sepOutNum * PlanComm.WeightOfMi(Convert.ToDouble(zyzgm.Aimoutdiameter), Convert.ToDouble(zyzgm.Aimwallthick)) * Convert.ToDouble(zyzgm.Aimlength), 3);//计划产出重量= 计划产出支数*管米单重*工序目标长度
  560. oriMCutSingleNum -= sepCutSingleNum;
  561. oriMCutSingleWt -=sepCutSingleWt ;
  562. oriOutNum -= sepOutNum;
  563. oriOutWt -= sepOutWt;
  564. oriPlnGpNum -= sepcount;
  565. sqlidList.Add(SqlIDDef.PlanLuZG.UpdateZYZG_WT_NUM);
  566. parameters.Add(new List<Object>() {oriMCutSingleNum,CommHelper.GetSpecDecimalBit(oriMCutSingleWt,3),oriOutNum,CommHelper.GetSpecDecimalBit(oriOutWt,3),m_userName,oriPlnGpNum,zyzgm.HeatPlanNo });
  567. }
  568. }
  569. else
  570. {
  571. sqlidList.Add(sqlUpdateZy);
  572. double inWt = CommHelper.GetSpecDecimalBit(singleinwt * (finalinnum), 3);
  573. double outWt = CommHelper.GetSpecDecimalBit(singleoutwt * (finaloutnum), 3);
  574. parameters.Add(new List<Object>() { inWt, finalinnum, finaloutnum, outWt, m_userName, row.Cells["HeatPlanNo"].Text });
  575. }
  576. }
  577. //退回物料
  578. string stoveNo = row.Cells["HeatnoLast"].Text;
  579. string batchedNo = "";
  580. string batchGroupNo = "";
  581. if (CustomInfo != CustomInfoDef.DEFINE_CUSTOMER_ZG)
  582. {
  583. batchedNo = CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_DBK ? row.Cells["ZgBatchNo"].Text : row.Cells["LastBatchNo"].Text;
  584. batchGroupNo = row.Cells["BatchGroudNo"].Text;
  585. }
  586. string materialNo = row.Cells["InwlId"].Text;
  587. string gxPlanNo = row.Cells["GxPlanNo"].Text;
  588. string proPlanId = row.Cells["ProPlanId"].Text;
  589. int lockliku = 0;
  590. lockliku = DBComm.queryLockLiku(stoveNo, batchedNo, batchGroupNo, proPlanId, gxPlanNo, this.ob);
  591. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  592. {
  593. sqlidList.Add(SqlIDDef.MaterialChoose.updateGPBack);
  594. parameters.Add(new List<Object>() { materialNo, stoveNo, proPlanId, gxPlanNo, matrow.Cells["ACT_LEN"].Value, CommHelper.getProcessCode(CustomInfo), CommHelper.getProcessDesc(CustomInfo), CommHelper.getProcessCode(CustomInfo), sepcount, m_userName });
  595. }
  596. else
  597. {
  598. sqlidList.Add(SqlIDDef.MaterialChoose.updateMaterialBack);
  599. parameters.Add(new List<object>() { materialNo, stoveNo, gxPlanNo, batchedNo, batchGroupNo, CommHelper.getProcessCode(CustomInfo), CommHelper.getProcessDesc(CustomInfo), proPlanId, CommHelper.getProcessCode(CustomInfo), sepcount, 0, m_userName });
  600. }
  601. //更新工序订单炉计划已排量
  602. DataTable dt = ServerHelper.GetData(MethodDef.StoveBase.queryBatchMatch, new Object[] { CommHelper.GetOrdertableName(CustomInfo), proPlanId, gxPlanNo }, this.ob);
  603. var OrderRow = dt.Rows[0];
  604. double Batch_Wt = 0;
  605. int Batch_Num = 0;
  606. double Match_Wt_In = 0;
  607. int Match_Num_In = 0;
  608. try
  609. {
  610. Batch_Num = Convert.ToInt32(OrderRow["BATCHED_NUM"].ToString());
  611. Batch_Wt = Convert.ToDouble(OrderRow["BATCHED_WT"].ToString());
  612. if (CustomInfo != CustomInfoDef.DEFINE_CUSTOMER_ZG)
  613. {
  614. Batch_Num -= sepcount;
  615. Batch_Wt -= CommHelper.GetSpecDecimalBit(singleoutwt * sepcount, 3);
  616. }
  617. else
  618. {
  619. Batch_Num -= sepOutNum;
  620. Batch_Wt -= sepOutWt;
  621. }
  622. }
  623. catch
  624. {
  625. }
  626. Batch_Num = Batch_Num < 0 ? 0 : Batch_Num;
  627. Batch_Wt = Batch_Wt < 0 ? 0 : Batch_Wt;
  628. sqlidList.Add(sqlIdUpdateBatch);
  629. parameters.Add(new List<Object>() { Batch_Wt, Batch_Num, proPlanId, gxPlanNo });
  630. //更新工序订单投入利库量
  631. if (lockliku == 1)
  632. {
  633. try
  634. {
  635. Match_Wt_In = Convert.ToDouble(OrderRow["MATCH_WT_IN"].ToString());
  636. Match_Num_In = Convert.ToInt32(OrderRow["MATCH_NUM_IN"].ToString());
  637. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  638. {
  639. Match_Num_In -= sepOutNum;
  640. Match_Wt_In -= sepOutWt;
  641. }
  642. else
  643. {
  644. Match_Num_In -= sepcount;
  645. Match_Wt_In -= CommHelper.GetSpecDecimalBit(sepcount * singleoutwt, 3);
  646. }
  647. }
  648. catch
  649. {
  650. }
  651. Match_Num_In = Match_Num_In < 0 ? 0 : Match_Num_In;
  652. Match_Wt_In = Match_Wt_In < 0 ? 0 : Match_Wt_In;
  653. sqlidList.Add(sqlIdUpdateMatch);
  654. parameters.Add(new List<object>() { Match_Wt_In, Match_Num_In, proPlanId, gxPlanNo });
  655. }
  656. }
  657. if (sqlidList.Count > 0)
  658. {
  659. BaseEntityDAL.ExcuteTransaction(sqlidList, parameters, this.ob);
  660. queryMat();
  661. }
  662. }
  663. private void queryMat()
  664. {
  665. DataTable dt=new DataTable();
  666. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG)
  667. {
  668. dt = ServerHelper.GetData(MethodDef.MaterialChoose.getBindedGp, new Object[] { CommHelper.getProcessCode(CustomInfo), CommHelper.getProcessDesc(CustomInfo) }, this.ob);
  669. }
  670. else
  671. {
  672. dt = ServerHelper.GetData(MethodDef.MaterialChoose.getBindedMaterial, new Object[] { CommHelper.getProcessCode(CustomInfo), CommHelper.getProcessDesc(CustomInfo) }, this.ob);
  673. }
  674. GridHelper.CopyDataToDatatable(dt, this.dataTable1, true);
  675. switch (CustomInfo)
  676. {
  677. case CustomInfoDef.DEFINE_CUSTOMER_DBK: this.plnZyDbkMEntityBindingSource.Clear(); break;
  678. case CustomInfoDef.DEFINE_CUSTOMER_JG: this.plnZyJgxMEntityBindingSource.Clear(); break;
  679. case CustomInfoDef.DEFINE_CUSTOMER_RCL: this.plnZyRclMEntityBindingSource.Clear(); break;
  680. case CustomInfoDef.DEFINE_CUSTOMER_ZG: this.plnZyZgMEntityBindingSource.Clear(); break;
  681. }
  682. }
  683. #endregion
  684. private void setUserActCount(long leftNum,Object ActLen)
  685. {
  686. foreach (var row in this.ultraGrid2.Rows)
  687. {
  688. int inNum = 0;
  689. double inWt = 0;
  690. UltraGridRow childrow = null;
  691. if (CustomInfo != CustomInfoDef.DEFINE_CUSTOMER_ZG)
  692. {
  693. inNum = Convert.ToInt32(row.Cells["InNum"].Text);
  694. inWt = Convert.ToDouble(row.Cells["InWt"].Text);
  695. }
  696. else
  697. {
  698. childrow = row.ChildBands[0].Rows.FirstOrDefault(c => c.Cells["LengthGp"].Text.Trim().Equals(ActLen.ToString()));
  699. if(childrow != null)
  700. {
  701. inNum = Convert.ToInt32(childrow.Cells["InGpNum"].Value);
  702. inWt = Convert.ToDouble(childrow.Cells["InGpWt"].Value);
  703. }
  704. row.Expanded = true;
  705. }
  706. double singleInWt = inWt/inNum;
  707. if (inNum >= leftNum)
  708. {
  709. row.Cells["ChooseZY"].Value = true;
  710. row.Cells["USER_ACT_COUNT"].Appearance.BackColor = Color.Pink;
  711. row.Cells["USER_ACT_COUNT"].Value = leftNum;
  712. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG && row.HasChild())
  713. {
  714. childrow.Cells["USER_ACT_COUNT"].Value = leftNum;
  715. childrow.Cells["USER_ACT_WEIGHT"].Value = leftNum * singleInWt;
  716. childrow.Cells["USER_ACT_COUNT"].Appearance.BackColor = Color.Pink;
  717. }
  718. else
  719. {
  720. row.Cells["USER_ACT_WEIGHT"].Value = leftNum * singleInWt;
  721. }
  722. break;
  723. }
  724. else
  725. {
  726. row.Cells["ChooseZY"].Value = true;
  727. row.Cells["USER_ACT_COUNT"].Appearance.BackColor = Color.Pink;
  728. row.Cells["USER_ACT_COUNT"].Value = inNum;
  729. if (CustomInfo == CustomInfoDef.DEFINE_CUSTOMER_ZG && row.HasChild())
  730. {
  731. childrow.Cells["USER_ACT_COUNT"].Value = inNum;
  732. childrow.Cells["USER_ACT_WEIGHT"].Value = inNum * singleInWt;
  733. childrow.Cells["USER_ACT_COUNT"].Appearance.BackColor = Color.Pink;
  734. }
  735. else
  736. {
  737. row.Cells["USER_ACT_WEIGHT"].Value = inNum * singleInWt;
  738. }
  739. leftNum -=inNum;
  740. }
  741. }
  742. }
  743. }
  744. }