FrmBuyGpIn.cs 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. using Core.Mes.Client.Comm.Control;
  9. using Core.Mes.Client.Comm.Format;
  10. using Core.Mes.Client.Comm.Server;
  11. using Core.Mes.Client.Comm.Tool;
  12. using Core.StlMes.Client.LgCommon;
  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 FrmBuyGpIn : FrmBase
  20. {
  21. public FrmBuyGpIn()
  22. {
  23. InitializeComponent();
  24. IsLoadUserView = true;
  25. }
  26. private string defaulStorage = "";
  27. private string defaulLocation = "";
  28. private string WeightPerMeterFormula = string.Empty;
  29. private Dictionary<string,List<LocationInfo>> storageList = new Dictionary<string, List<LocationInfo>>();
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. base.OnLoad(e);
  33. RegStartTime.Value = DateTime.Parse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 00:00:00"));
  34. RegEndTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  35. RegStartTime1.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  36. RegEndTime1.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  37. matGrid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Default;
  38. matGrid.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
  39. EntityHelper.ShowGridCaption<YdmGpInlistEntity>(ugInlist.DisplayLayout.Bands[0]);
  40. GetWeightPerMeterFormula();
  41. BindStorageDropDown();
  42. Query1();
  43. Query2();
  44. }
  45. public override void ToolBar_Click(object sender, string ToolbarKey)
  46. {
  47. switch (ToolbarKey)
  48. {
  49. case "DoQuery":
  50. Query();
  51. break;
  52. case "doSave":
  53. doSave();
  54. break;
  55. case "DoAdd":
  56. DoAdd();
  57. break;
  58. case "DoDelete":
  59. DoDelete();
  60. break;
  61. case "DoBeside":
  62. DoBeside();
  63. break;
  64. case "DoClose":
  65. Close();
  66. break;
  67. case "Export":
  68. Export();
  69. break;
  70. }
  71. }
  72. private void doSave(bool showOkMessage = true)
  73. {
  74. CmmWeightResultEntity entity = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  75. if (entity == null) return;
  76. matGrid.UpdateData();
  77. List<CmmWeightMatEntityFull> data = cmmWeightMatEntityBindingSource.DataSource as List<CmmWeightMatEntityFull>;
  78. if (data != null && data.Any(p => p.Chk))
  79. {
  80. data = data.Where(p => p.Chk).ToList();
  81. }
  82. else
  83. {
  84. MessageBox.Show("请勾选需要保存的信息");
  85. return;
  86. }
  87. //if (data.Any(p => p.InstoreType == "1" && p.ActWeight != p.EditWt))
  88. //{
  89. // MessageBox.Show("入库重量需和过磅重量一致!");
  90. // return;
  91. //}
  92. var ccp = new CoreClientParam();
  93. ccp.ServerName = "com.steering.Mcms.BuyGpInServer";
  94. ccp.MethodName = "doSave";
  95. ccp.ServerParams = new object[]
  96. {
  97. data.Select(JSONFormat.Format).ToList()
  98. };
  99. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  100. if (ccp.ReturnCode != -1)
  101. {
  102. if (ccp.ReturnInfo.Contains("成功"))
  103. {
  104. if (showOkMessage)
  105. {
  106. MessageUtil.ShowTips(ccp.ReturnInfo);
  107. ugData_AfterRowActivate(null, null);
  108. }
  109. }
  110. else
  111. {
  112. MessageUtil.ShowTips(ccp.ReturnInfo);
  113. }
  114. }
  115. }
  116. private void Export()
  117. {
  118. if (tabC.ActiveTab == null) return;
  119. if (tabC.ActiveTab.Key == "1")
  120. {
  121. GridHelper.ulGridToExcel(ugData, "磅单明细");
  122. }
  123. else if (tabC.ActiveTab.Key == "2")
  124. {
  125. GridHelper.ulGridToExcel(ugInlist, "入库记录");
  126. }
  127. }
  128. private void DoBeside()
  129. {
  130. List<string> list;
  131. if ((ugData.Selected.Rows.Count <= 0) && (ugData.ActiveRow == null))
  132. {
  133. MessageBox.Show("请选择需要完成的数据!");
  134. return;
  135. }
  136. if (ugData.Selected.Rows.Count <= 0)
  137. list = new List<string>
  138. {
  139. (ugData.ActiveRow.ListObject as CmmWeightResultEntity).ResultNo
  140. };
  141. else
  142. list = (from UltraGridRow p in ugData.Selected.Rows
  143. select p.ListObject as CmmWeightResultEntity).Select(p => p.ResultNo).ToList();
  144. var ccp = new CoreClientParam();
  145. ccp.ServerName = "com.steering.Mcms.ResultServer";
  146. ccp.MethodName = "DoFinish";
  147. ccp.ServerParams = new object[]
  148. {
  149. list
  150. };
  151. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  152. if (ccp.ReturnCode != -1)
  153. {
  154. MessageUtil.ShowTips(ccp.ReturnInfo);
  155. if (ccp.ReturnInfo.Contains("成功!"))
  156. Query1();
  157. }
  158. }
  159. private void DoDelete()
  160. {
  161. ugInlist.UpdateData();
  162. List<YdmGpInlistEntity> list = ydmGpInlistEntityBindingSource.DataSource as List<YdmGpInlistEntity>;
  163. if(list==null ) return;
  164. list = list.Where(p => p.Chk).ToList();
  165. if (!list.Any())
  166. {
  167. MessageBox.Show("请勾选需要撤销入库的数据!");
  168. return;
  169. }
  170. var ccp = new CoreClientParam();
  171. ccp.ServerName = "com.steering.Mcms.BuyGpInServer";
  172. ccp.MethodName = "DoDelete";
  173. ccp.ServerParams = new object[]
  174. {
  175. list.Select(JSONFormat.Format).ToList()
  176. };
  177. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  178. if (ccp.ReturnCode != -1)
  179. {
  180. MessageUtil.ShowTips(ccp.ReturnInfo);
  181. if (ccp.ReturnInfo.Contains("成功!"))
  182. Query2();
  183. }
  184. }
  185. private void DoAdd()
  186. {
  187. CmmWeightResultEntity entity = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  188. if (entity == null) return;
  189. matGrid.UpdateData();
  190. List<CmmWeightMatEntityFull> data= cmmWeightMatEntityBindingSource.DataSource as List<CmmWeightMatEntityFull>;
  191. if (data != null && data.Any(p => p.Chk))
  192. {
  193. data = data.Where(p => p.Chk).ToList();
  194. }
  195. else
  196. {
  197. MessageBox.Show("请勾选需求要入库的信息");
  198. return;
  199. }
  200. if (data.Any(p =>
  201. {
  202. decimal editWt, actWt;
  203. if (decimal.TryParse(p.ActTheoryWeight.ToString3(), out actWt) &&
  204. decimal.TryParse(p.EditWt.ToString3(), out editWt))
  205. {
  206. if (Math.Abs(actWt - editWt) > 1)
  207. {
  208. return true;
  209. }
  210. }
  211. else
  212. {
  213. return true;
  214. }
  215. return false;
  216. }))
  217. {
  218. if (MessageUtil.ShowYesNoAndQuestion("入库重量与理论重量差别过大,请确认是否继续入库?") ==
  219. DialogResult.No) return;
  220. }
  221. //int quoteIndex = 0;//小数位数
  222. //double quoteValue = 0.0;
  223. //IQueryable<UltraGridRow> checkMagRows = this.matGrid.Rows.AsQueryable().Where(" CHK = 'True'");
  224. //foreach (UltraGridRow uRow in checkMagRows)
  225. //{
  226. // quoteValue = double.Parse(uRow.Cells["EditWt"].Text.ToString3()) / double.Parse(uRow.Cells["EditInstockNum"].Text.ToString3());
  227. // quoteIndex = quoteValue.ToString3().Length - quoteValue.ToString3().IndexOf('.') - 1;//小数位数
  228. // if (quoteIndex > 3)
  229. // {
  230. // MessageBox.Show("单支入库重量精度不对,请分多次入库。!");
  231. // return;
  232. // }
  233. //}
  234. var ccp = new CoreClientParam();
  235. ccp.ServerName = "com.steering.Mcms.BuyGpInServer";
  236. ccp.MethodName = "DoAdd";
  237. ccp.ServerParams = new object[]
  238. {
  239. data.Select(JSONFormat.Format).ToList(),entity.ResultNo, this.UserInfo.GetUserName()
  240. };
  241. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  242. if (ccp.ReturnCode != -1)
  243. {
  244. MessageUtil.ShowTips(ccp.ReturnInfo);
  245. if (ccp.ReturnInfo.Contains("成功"))
  246. Query();
  247. }
  248. }
  249. private void Query()
  250. {
  251. if(tabC.ActiveTab==null) return;
  252. if (tabC.ActiveTab.Key == "1")
  253. {
  254. Query1();
  255. }
  256. else if (tabC.ActiveTab.Key == "2")
  257. {
  258. Query2();
  259. }
  260. }
  261. private void Query1()
  262. {
  263. var dic = new Dictionary<string, object>();
  264. if (chkTim.Checked)
  265. {
  266. dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  267. dic.Add("time1", RegEndTime.Value.ToString("yyy-MM-dd HH:mm:ss"));
  268. }
  269. dic.Add("matType", "钢坯采购");
  270. if (chkShippersName.Checked)
  271. dic.Add("shippersName", uteShippersName.Text);
  272. dic.Add("validflag", new List<string> { "1" });
  273. if (chkJudgeStove.Checked)
  274. dic.Add("judgeStoveNo", uteJudgeStoveNo.Text);
  275. if (chkOrder.Checked)
  276. dic.Add("orderNo", utOrderNo.Text);
  277. dic.Add("storageFlag", new List<string>() { "1", "0" });
  278. List<CmmWeightResultEntity> list = EntityHelper.GetData<CmmWeightResultEntity>(
  279. "com.steering.Mcms.ResultServer.doQuery",
  280. new object[] { dic },
  281. ob);
  282. cmmWeightMatEntityBindingSource.Clear();
  283. if (list.Count == 0) return;
  284. List<CmmWeightResultEntity> listProject = EntityHelper.GetData<CmmWeightResultEntity>(
  285. "com.steering.Mcms.ResultServer.doCmmWeightMat",
  286. new object[] { list.Select(p => p.ResultNo).ToArray() }, ob);
  287. foreach (CmmWeightResultEntity entity in list)
  288. {
  289. entity.OrderFull = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.OrderFull).Distinct().ToList());
  290. entity.SpecName = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.SpecName).Distinct().ToList());
  291. entity.ActDimater = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.ActDimater).Distinct().ToList());
  292. entity.Steelname = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Steelname).Distinct().ToList());
  293. entity.Producname = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Producname).Distinct().ToList());
  294. entity.Gradename = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.Gradename).Distinct().ToList());
  295. entity.JudgeStoveNo = String.Join(",", listProject.Where(q => q.ResultNo == entity.ResultNo).Select(q => q.JudgeStoveNo).Distinct().ToList());
  296. }
  297. QueryBS.DataSource = list;
  298. Comm.RefreshAndAutoSize(ugData);
  299. }
  300. private void Query2()
  301. {
  302. var dic = new Dictionary<string, object>();
  303. if (chkTim.Checked)
  304. {
  305. dic.Add("time", RegStartTime1.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  306. dic.Add("time1", RegEndTime1.Value.ToString("yyy-MM-dd HH:mm:ss"));
  307. }
  308. if (chkJudgeStove1.Checked)
  309. dic.Add("judgeStoveNo", uteJudgeStoveNo1.Text);
  310. if (chkOrder1.Checked)
  311. dic.Add("orderNo", utOrderNo1.Text);
  312. List<YdmGpInlistEntity> list = EntityHelper.GetData<YdmGpInlistEntity>(
  313. "com.steering.Mcms.BuyGpInServer.doQueryInList",
  314. new object[] { dic },
  315. ob);
  316. ydmGpInlistEntityBindingSource.DataSource = list;
  317. Comm.RefreshAndAutoSize(ugInlist);
  318. }
  319. private void FrmBuyGpIn_Shown(object sender, EventArgs e)
  320. {
  321. if (toolMenu == null) return;
  322. if (toolMenu.Toolbars[0].Tools.Exists("DoDelete"))
  323. {
  324. toolMenu.Toolbars[0].Tools["DoDelete"].InstanceProps.Visible = DefaultableBoolean.False;
  325. }
  326. if (toolMenu.Toolbars[0].Tools.Exists("doSave"))
  327. {
  328. toolMenu.Toolbars[0].Tools["doSave"].InstanceProps.Visible = DefaultableBoolean.True;
  329. }
  330. }
  331. private void tabC_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
  332. {
  333. if (toolMenu == null) return;
  334. if (toolMenu.Toolbars[0].Tools.Exists("DoDelete"))
  335. toolMenu.Toolbars[0].Tools["DoDelete"].InstanceProps.Visible = tabC.SelectedTab.Key == "1" ? DefaultableBoolean.False : DefaultableBoolean.True;
  336. if (toolMenu.Toolbars[0].Tools.Exists("doSave"))
  337. toolMenu.Toolbars[0].Tools["doSave"].InstanceProps.Visible = tabC.SelectedTab.Key == "1" ? DefaultableBoolean.True : DefaultableBoolean.False;
  338. if (toolMenu.Toolbars[0].Tools.Exists("DoAdd"))
  339. toolMenu.Toolbars[0].Tools["DoAdd"].InstanceProps.Visible = tabC.SelectedTab.Key == "2" ? DefaultableBoolean.False : DefaultableBoolean.True;
  340. if (toolMenu.Toolbars[0].Tools.Exists("DoBeside"))
  341. toolMenu.Toolbars[0].Tools["DoBeside"].InstanceProps.Visible = tabC.SelectedTab.Key == "2" ? DefaultableBoolean.False : DefaultableBoolean.True;
  342. }
  343. private void ugData_AfterRowActivate(object sender, EventArgs e)
  344. {
  345. CmmWeightResultEntity data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  346. if (data == null) return;
  347. List<CmmWeightMatEntityFull> list = EntityHelper.GetData<CmmWeightMatEntityFull>(
  348. "com.steering.Mcms.PoundMatServer.doQuery",
  349. new object[] { data.ResultNo },
  350. ob);
  351. for (var i = 0; i < list.Count; i++)
  352. {
  353. CmmWeightMatEntityFull p = list[i];
  354. decimal num = 0;
  355. if (decimal.TryParse(p.UnInstockNum, out num))
  356. {
  357. //入库支不等于0的自动勾上
  358. //p.Chk = num > 0;
  359. if (p.EditInstockNum == null || (!string.IsNullOrWhiteSpace(p.InstockNum) &&decimal.Parse( p.InstockNum)>0))
  360. p.EditInstockNum = num;
  361. }
  362. if (string.IsNullOrWhiteSpace(p.InstockNum)) p.InstockNum = "0";
  363. decimal len = 0;
  364. if (decimal.TryParse(p.ActLenTemp, out len) && p.EditLength==null)
  365. p.EditLength = len;
  366. decimal actCount = p.ActCount ?? 0;
  367. decimal dimater = 0;
  368. decimal.TryParse(p.ActDimater.ToString3(), out dimater);
  369. p.ActTheoryWeight = GetActTheoryWt(len,p.ActDimater) * p.ActCount;
  370. if (p.EditWt == null || (p.InstockNum != null && decimal.Parse(p.InstockNum) > 0))
  371. {
  372. if (p.InstoreType == "1")
  373. {
  374. if (p.EditInstockNum != null && p.EditInstockNum <= decimal.Parse(p.UnInstockNum) && p.PerWt != null)
  375. {
  376. try
  377. {
  378. p.EditWt = p.EditInstockNum == decimal.Parse(p.UnInstockNum)
  379. ? decimal.Parse(p.UnInstockWt)
  380. : Math.Round((decimal)(decimal.Parse(p.UnInstockWt) / decimal.Parse(p.UnInstockNum) * p.EditInstockNum), 3);
  381. }
  382. catch (Exception)
  383. {
  384. p.EditWt = null;
  385. }
  386. }
  387. else
  388. {
  389. p.EditWt = null;
  390. }
  391. }
  392. else
  393. {
  394. if (p.EditInstockNum != null && p.EditInstockNum <= p.RemainNum && p.PerWt != null)
  395. {
  396. try
  397. {
  398. p.EditWt = p.EditInstockNum == p.RemainNum
  399. ? p.RemainWt
  400. : Math.Round((decimal) (p.PerWt*p.EditInstockNum*p.EditLength), 3);
  401. }
  402. catch (Exception)
  403. {
  404. p.EditWt = null;
  405. }
  406. }
  407. else
  408. {
  409. p.EditWt = null;
  410. }
  411. }
  412. }
  413. else
  414. {
  415. //预报标记了来料清单 且是最后几支 不取保存的重量
  416. if (p.InstoreType != null && p.InstoreType == "2" && p.EditInstockNum == p.RemainNum)
  417. {
  418. p.EditWt = p.RemainWt;
  419. }
  420. }
  421. try
  422. {
  423. p.ActTheoryWeight = GetActTheoryWt(p.EditLength, p.ActDimater) * p.EditInstockNum;
  424. }
  425. catch (Exception)
  426. {
  427. p.ActTheoryWeight = null;
  428. }
  429. if (uceStorageNo.Items.Count > 0)
  430. {
  431. p.StorageNo = string.IsNullOrWhiteSpace(defaulStorage) ? uceStorageNo.Items[0].DataValue.ToString2() : defaulStorage;
  432. List<LocationInfo> locationInfos;
  433. if (!storageList.ContainsKey(p.StorageNo))
  434. {
  435. locationInfos = EntityHelper.GetData<LocationInfo>(
  436. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
  437. new[] {p.StorageNo}, ob);
  438. storageList.Add(p.StorageNo, locationInfos);
  439. }
  440. else
  441. {
  442. locationInfos = storageList[p.StorageNo];
  443. }
  444. if (locationInfos != null && locationInfos.Any())
  445. {
  446. var selectLoc = locationInfos.Where(no => no.LocationNo == defaulLocation).ToList();
  447. if (selectLoc.Any())
  448. {
  449. p.LocationNo = selectLoc[0].LocationNo;
  450. p.LocationName = selectLoc[0].LocationName;
  451. }
  452. else
  453. {
  454. p.LocationNo = locationInfos[0].LocationNo;
  455. p.LocationName = locationInfos[0].LocationName;
  456. }
  457. }
  458. }
  459. p.LaryNo = "1";
  460. }
  461. // uceStorageNoEdit.SelectedIndex = -1;
  462. cmmWeightMatEntityBindingSource.DataSource = list;
  463. if (matGrid.Rows.Count>0)
  464. {
  465. matGrid.Rows[0].Cells["EditWt"].EditorComponent = uteInputWt;
  466. }
  467. Comm.RefreshAndAutoSize(matGrid, new string[] { "EditWt" });
  468. }
  469. private decimal? GetActTheoryWt( decimal? len, decimal? actDimater)
  470. {
  471. try
  472. {
  473. var dt = new DataTable();
  474. decimal weightPerMeter;
  475. decimal.TryParse(
  476. dt.Compute(WeightPerMeterFormula.Replace("断面", actDimater.ToString2().Replace("250", "251")),
  477. null).ToString(),
  478. out weightPerMeter);
  479. return Math.Round(decimal.Parse((weightPerMeter*len/1000).ToString2()),3);
  480. }
  481. catch (Exception)
  482. {
  483. }
  484. return null;
  485. }
  486. private void matGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  487. {
  488. CmmWeightMatEntityFull list = e.Row.ListObject as CmmWeightMatEntityFull;
  489. if(list==null ) return;
  490. if (string.IsNullOrWhiteSpace(list.DocumentNo)) e.Row.Cells["OrderFull"].Appearance.BackColor = Color.Red;
  491. //if (!list.Chk) e.Row.Cells["Chk"].Appearance.BackColor = Color.DarkGray;
  492. //入库支为0时整行变灰
  493. if (int.Parse( e.Row.Cells["EditInstockNum"].Text.Replace("_", "").ToString3()) == 0)
  494. {
  495. e.Row.Appearance.BackColor = Color.DarkGray;
  496. }
  497. }
  498. private void matGrid_CellChange(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
  499. {
  500. if (e.Cell.Column.Key == "Chk")
  501. {
  502. matGrid.UpdateData();
  503. //if((bool)e.Cell.Value) e.Cell.Appearance.ResetBackColor();
  504. //else e.Cell.Appearance.BackColor = Color.DarkGray;
  505. }
  506. else if (e.Cell.Column.Key == "StorageNo")
  507. {
  508. matGrid.UpdateData();
  509. List<LocationInfo> locationInfos;
  510. if (!storageList.ContainsKey(e.Cell.Value.ToString2()))
  511. {
  512. locationInfos = EntityHelper.GetData<LocationInfo>(
  513. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
  514. new[] { e.Cell.Value.ToString2() }, ob);
  515. storageList.Add(e.Cell.Value.ToString2(), locationInfos);
  516. }
  517. else
  518. {
  519. locationInfos = storageList[e.Cell.Value.ToString2()];
  520. }
  521. e.Cell.Row.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any()
  522. ? locationInfos[0].LocationNo
  523. : "";
  524. e.Cell.Row.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any()
  525. ? locationInfos[0].LocationName
  526. : "";
  527. }
  528. else if (e.Cell.Column.Key == "EditInstockNum" || e.Cell.Column.Key == "EditLength")
  529. {
  530. try
  531. {
  532. e.Cell.Row.Cells["ActTheoryWeight"].Value = GetActTheoryWt(
  533. decimal.Parse(
  534. e.Cell.Row.Cells["EditLength"].Text.Replace(
  535. "_", "")),
  536. decimal.Parse(
  537. e.Cell.Row.Cells["ActDimater"].Value.ToString3()))
  538. *
  539. decimal.Parse(
  540. e.Cell.Row.Cells["EditInstockNum"].Text.Replace(
  541. "_", ""));
  542. }
  543. catch (Exception)
  544. {
  545. e.Cell.Row.Cells["ActTheoryWeight"].Value = null;
  546. }
  547. if (e.Cell.Row.Cells["InstoreType"].Value.ToString2() == "1")
  548. {
  549. if (string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", ""))
  550. || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditLength"].Text.Replace("_", ""))
  551. || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["PerWt"].Text.Replace("_", ""))
  552. )
  553. e.Cell.Row.Cells["EditWt"].Value = null;
  554. else
  555. {
  556. decimal num = decimal.Parse(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", ""));
  557. decimal len = decimal.Parse(e.Cell.Row.Cells["EditLength"].Text.Replace("_", ""));
  558. decimal perWt = decimal.Parse(e.Cell.Row.Cells["PerWt"].Text.Replace("_", ""));
  559. decimal UnInstockNum = decimal.Parse(e.Cell.Row.Cells["UnInstockNum"].Value.ToString3());
  560. decimal UnInstockWt = decimal.Parse(e.Cell.Row.Cells["UnInstockWt"].Value.ToString3());
  561. if (num <= UnInstockNum)
  562. {
  563. decimal wt = num == UnInstockNum
  564. ? UnInstockWt
  565. : Math.Round(UnInstockWt / UnInstockNum * num, 3);
  566. if (wt > UnInstockWt) wt = UnInstockWt;
  567. e.Cell.Row.Cells["EditWt"].Value = wt;
  568. }
  569. else
  570. {
  571. e.Cell.Row.Cells["EditWt"].Value = null;
  572. }
  573. }
  574. }else
  575. {
  576. if (string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", ""))
  577. || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["EditLength"].Text.Replace("_", ""))
  578. || string.IsNullOrWhiteSpace(e.Cell.Row.Cells["PerWt"].Text.Replace("_", ""))
  579. )
  580. e.Cell.Row.Cells["EditWt"].Value = null;
  581. else
  582. {
  583. decimal num = decimal.Parse(e.Cell.Row.Cells["EditInstockNum"].Text.Replace("_", ""));
  584. decimal len = decimal.Parse(e.Cell.Row.Cells["EditLength"].Text.Replace("_", ""));
  585. decimal perWt = decimal.Parse(e.Cell.Row.Cells["PerWt"].Text.Replace("_", ""));
  586. decimal RemaindNum = decimal.Parse(e.Cell.Row.Cells["RemainNum"].Value.ToString3());
  587. decimal RemainWt = decimal.Parse(e.Cell.Row.Cells["RemainWt"].Value.ToString3());
  588. if (num <= RemaindNum)
  589. {
  590. decimal wt = num == RemaindNum
  591. ? RemainWt
  592. : Math.Round(perWt*len*num, 3);
  593. if (wt > RemainWt) wt = RemainWt;
  594. e.Cell.Row.Cells["EditWt"].Value = wt;
  595. }
  596. else
  597. {
  598. e.Cell.Row.Cells["EditWt"].Value = null;
  599. }
  600. }
  601. }
  602. if (e.Cell.Column.Key == "EditLength")
  603. {
  604. //CmmWeightResultEntity data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  605. //if (data == null) return;
  606. //List<CmmWeightMatEntityFull> list =
  607. // cmmWeightMatEntityBindingSource.DataSource as List<CmmWeightMatEntityFull>;
  608. //decimal singleLenWt = (decimal)data.NetWt / list.Where(p => p.ActCount != null && StringUtil.IsInt(p.ActLenTemp))
  609. // .Select(p => (decimal)p.ActCount * decimal.Parse(p.ActLenTemp) * decimal.Parse(p.ActDimater.ToString3()) * decimal.Parse(p.ActDimater.ToString3())).Sum();
  610. //decimal usedWt = 0;
  611. //for (var i = 0; i < matGrid.Rows.Count; i++)
  612. //{
  613. // decimal actCount, editLength,actDimater;
  614. // if (!decimal.TryParse(matGrid.Rows[i].Cells["ActCount"].Text.Replace(
  615. // "_", ""), out actCount))
  616. // {
  617. // actCount = 0;
  618. // }
  619. // if (!decimal.TryParse(matGrid.Rows[i].Cells["EditLength"].Text.Replace(
  620. // "_", ""), out editLength))
  621. // {
  622. // editLength = 0;
  623. // }
  624. // if (!decimal.TryParse(matGrid.Rows[i].Cells["ActDimater"].Text.Replace(
  625. //"_", ""), out actDimater))
  626. // {
  627. // actDimater = 0;
  628. // }
  629. // decimal actWt =
  630. // Math.Round(
  631. // i == list.Count - 1
  632. // ? (decimal)data.NetWt - usedWt
  633. // : singleLenWt * actCount * editLength * actDimater * actDimater, 3);
  634. // matGrid.Rows[i].Cells["ActWeight"].Value = actWt;
  635. // if (matGrid.Rows[i].Cells["EditLength"].Value.ToString2() == "1")
  636. // matGrid.Rows[i].Cells["EditWt"].Value = actWt;
  637. // usedWt = usedWt + actWt;
  638. //}
  639. }
  640. }
  641. }
  642. public void GetWeightPerMeterFormula()
  643. {
  644. try
  645. {
  646. var strErr = "";
  647. var arry = new ArrayList();
  648. arry.Add("frmBaseInfo_Parent.select");
  649. arry.Add("405202");
  650. var ccs = new CommonClientToServer();
  651. ccs.ob = ob;
  652. var ds = ccs.ExecuteQueryFunctions("Core.LgMes.Server.Common.ComDBQuery", "doSimpleQuery", arry,
  653. out strErr);
  654. if ((ds != null) && (ds.Tables.Count > 0) && (ds.Tables[0].Rows.Count > 0))
  655. WeightPerMeterFormula = Convert.ToString(ds.Tables[0].Rows[0]["BASENAME"]);
  656. }
  657. catch
  658. {
  659. }
  660. }
  661. public void BindStorageDropDown()
  662. {
  663. var dic = new Dictionary<string, object>();
  664. var customInfo = CustomInfo.ToString2();
  665. if (!string.IsNullOrWhiteSpace(customInfo))
  666. dic.Add("storageTypeNo", customInfo.Split(','));
  667. dic.Add("managementNo", ValidDataPurviewIds);
  668. var dt = ServerHelper.GetData("Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageNoList",
  669. new object[] { dic }, ob);
  670. if ((dt != null) && (dt.Rows.Count > 0))
  671. {
  672. uceStorageNo.DataSource = dt;
  673. uceStorageNo.ValueMember = "STORAGE_NO";
  674. uceStorageNo.DisplayMember = "STORAGE_NAME";
  675. uceStorageNoEdit.DataSource = dt;
  676. uceStorageNoEdit.ValueMember = "STORAGE_NO";
  677. uceStorageNoEdit.DisplayMember = "STORAGE_NAME";
  678. if (dt.AsEnumerable().Any(p => p["STORAGE_NO"].ToString2() == "LSG2"))
  679. {
  680. defaulStorage = "LSG2";
  681. }
  682. }
  683. }
  684. private void uteUpload2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  685. {
  686. if (string.IsNullOrWhiteSpace(matGrid.ActiveRow.Cells["StorageNo"].Value.ToString2())) return;
  687. using (var s = new StorageInfoSelect(matGrid.ActiveRow.Cells["StorageNo"].Value.ToString2(),ob))
  688. {
  689. if (s.ShowDialog() == DialogResult.OK)
  690. {
  691. matGrid.ActiveRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo;
  692. matGrid.ActiveRow.Cells["LocationName"].Value = s.SelectLocation.LocationName;
  693. matGrid.DisplayLayout.Bands[0].Columns["LocationName"].PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand, true);
  694. }
  695. }
  696. }
  697. private void utbLocaiton_Click(object sender, EventArgs e)
  698. {
  699. if (uceStorageNoEdit.SelectedIndex<0) return;
  700. using (var s = new StorageInfoSelect(uceStorageNoEdit.SelectedItem.DataValue.ToString2(), ob))
  701. {
  702. if (s.ShowDialog() == DialogResult.OK)
  703. {
  704. defaulLocation = s.SelectLocation.LocationNo;
  705. defaulStorage = s.SelectLocation.StorageNo;
  706. if (matGrid.Selected.Rows.Count > 0)
  707. {
  708. foreach (var ultraGridRow in matGrid.Selected.Rows)
  709. {
  710. ultraGridRow.Cells["StorageNo"].Value = s.SelectLocation.StorageNo;
  711. ultraGridRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo;
  712. ultraGridRow.Cells["LocationName"].Value = s.SelectLocation.LocationName;
  713. }
  714. }
  715. else
  716. {
  717. foreach (var ultraGridRow in matGrid.Rows)
  718. {
  719. ultraGridRow.Cells["StorageNo"].Value = s.SelectLocation.StorageNo;
  720. ultraGridRow.Cells["LocationNo"].Value = s.SelectLocation.LocationNo;
  721. ultraGridRow.Cells["LocationName"].Value = s.SelectLocation.LocationName;
  722. }
  723. }
  724. }
  725. }
  726. }
  727. private void uceStorageNoEdit_ValueChanged(object sender, EventArgs e)
  728. {
  729. defaulStorage = uceStorageNoEdit.Value.ToString2();
  730. if (matGrid.Selected.Rows.Count > 0)
  731. {
  732. foreach (var ultraGridRow in matGrid.Selected.Rows)
  733. {
  734. ultraGridRow.Cells["StorageNo"].Value = uceStorageNoEdit.Value.ToString2();
  735. List<LocationInfo> locationInfos;
  736. if (!storageList.ContainsKey( uceStorageNoEdit.Value.ToString2()))
  737. {
  738. locationInfos = EntityHelper.GetData<LocationInfo>(
  739. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
  740. new[] { uceStorageNoEdit.Value.ToString2() }, ob);
  741. storageList.Add( uceStorageNoEdit.Value.ToString2(), locationInfos);
  742. }
  743. else
  744. {
  745. locationInfos = storageList[uceStorageNoEdit.Value.ToString2()];
  746. }
  747. ultraGridRow.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any()
  748. ? locationInfos[0].LocationNo
  749. : "";
  750. ultraGridRow.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any()
  751. ? locationInfos[0].LocationName
  752. : "";
  753. defaulLocation = locationInfos != null && locationInfos.Any()
  754. ? locationInfos[0].LocationNo
  755. : "";
  756. }
  757. }
  758. else
  759. {
  760. foreach (var ultraGridRow in matGrid.Rows)
  761. {
  762. ultraGridRow.Cells["StorageNo"].Value = uceStorageNoEdit.Value.ToString2();
  763. List<LocationInfo> locationInfos;
  764. if (!storageList.ContainsKey(uceStorageNoEdit.Value.ToString2()))
  765. {
  766. locationInfos = EntityHelper.GetData<LocationInfo>(
  767. "Core.LgMes.Server.LgDeviceManager.StorageManage.GetStorageLocationInfoNew",
  768. new[] { uceStorageNoEdit.Value.ToString2() }, ob);
  769. storageList.Add(uceStorageNoEdit.Value.ToString2(), locationInfos);
  770. }
  771. else
  772. {
  773. locationInfos = storageList[uceStorageNoEdit.Value.ToString2()];
  774. }
  775. ultraGridRow.Cells["LocationNo"].Value = locationInfos != null && locationInfos.Any()
  776. ? locationInfos[0].LocationNo
  777. : "";
  778. ultraGridRow.Cells["LocationName"].Value = locationInfos != null && locationInfos.Any()
  779. ? locationInfos[0].LocationName
  780. : "";
  781. }
  782. }
  783. }
  784. private void uteInputWt_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  785. {
  786. decimal wt = 0;
  787. decimal currentWt = 0;
  788. bool canInput = false;
  789. foreach (var ultraGridRow in matGrid.Rows)
  790. {
  791. if ((bool) ultraGridRow.Cells["Chk"].Value)
  792. {
  793. decimal rowWt = 0;
  794. decimal rowActWt = 0;
  795. if (decimal.TryParse(ultraGridRow.Cells["ActTheoryWeight"].Value.ToString2(), out rowWt))
  796. {
  797. wt += rowWt;
  798. canInput = true;
  799. }
  800. if (decimal.TryParse(ultraGridRow.Cells["EditWt"].Value.ToString2(), out rowActWt))
  801. {
  802. currentWt += rowActWt;
  803. canInput = true;
  804. }
  805. }
  806. }
  807. if (!canInput)
  808. {
  809. MessageBox.Show("请先勾选数据,或者输入入库支");
  810. return;
  811. }
  812. using (var InputWt = new InputWt(currentWt))
  813. {
  814. if (InputWt.ShowDialog() == DialogResult.OK)
  815. {
  816. decimal remaidWt = wt;
  817. decimal remaidInputWt = InputWt.TotalWt;
  818. decimal perWt = InputWt.TotalWt/wt;
  819. foreach (var ultraGridRow in matGrid.Rows)
  820. {
  821. if ((bool)ultraGridRow.Cells["Chk"].Value)
  822. {
  823. decimal rowWt = 0;
  824. if (decimal.TryParse(ultraGridRow.Cells["ActTheoryWeight"].Value.ToString2(), out rowWt))
  825. {
  826. remaidWt = remaidWt - rowWt;
  827. decimal cWt = remaidWt <= 0
  828. ? remaidInputWt
  829. : Math.Round(perWt*rowWt, 3);
  830. ultraGridRow.Cells["EditWt"].Value = cWt;
  831. remaidInputWt = remaidInputWt - cWt;
  832. }
  833. }
  834. }
  835. doSave(false);
  836. }
  837. }
  838. }
  839. }
  840. }