frmLocalTruckScale.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Windows.Forms;
  9. using System.Xml.Linq;
  10. using Core.Mes.Client.Comm.Control;
  11. using Core.Mes.Client.Comm.Server;
  12. using Core.Mes.Client.Comm.Tool;
  13. using Core.StlMes.Client.Mcp.Mch.Mcms.entity;
  14. using CoreFS.CA06;
  15. using Infragistics.Win;
  16. using Infragistics.Win.Misc;
  17. using Infragistics.Win.UltraWinListView;
  18. using Infragistics.Win.UltraWinTabControl;
  19. using Newtonsoft.Json;
  20. using Newtonsoft.Json.Serialization;
  21. using NPOI.HSSF.UserModel;
  22. using NPOI.SS.UserModel;
  23. using NPOI.SS.Util;
  24. using BorderStyle = NPOI.SS.UserModel.BorderStyle;
  25. namespace Core.StlMes.Client.Mcp.Mch.Mcms
  26. {
  27. public partial class frmLocalTruckScale : FrmBase
  28. {
  29. private static readonly string _path = Environment.CurrentDirectory + "\\data\\SerialPort.xml";
  30. private frmMessage _frmMessage;
  31. private SerialPortEntity _serialPortEntity;
  32. private List<CmmRecordTemplateEntity> _templateList;
  33. private CmmPoundBaseEntity cmmPoundBase;
  34. private List<CmmInputRecordEntity> _cmmInputRecordEntities;
  35. private bool isLoading = true;
  36. public frmLocalTruckScale()
  37. {
  38. InitializeComponent();
  39. this.IsLoadUserView = true;
  40. }
  41. protected override void OnLoad(EventArgs e)
  42. {
  43. base.OnLoad(e);
  44. tbFirstWt.Controls.OfType<UltraTabPageControl>()
  45. .SelectMany(p => p.Controls.OfType<MatInfo>())
  46. .ToList()
  47. .ForEach(p => p.ini(ob));
  48. tbOther.Controls.OfType<UltraTabPageControl>()
  49. .SelectMany(p => p.Controls.OfType<MatInfo>())
  50. .ToList()
  51. .ForEach(p => p.ini(ob));
  52. matInfo15.ini(ob);
  53. matInfo16.ini(ob);
  54. tbWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
  55. tbFirstWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
  56. tbScondWt.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
  57. tbOther.Appearance.ForeColor = System.Drawing.SystemColors.ControlText; ;
  58. _serialPortEntity = new SerialPortEntity(new TruckScaleProtocol(null))
  59. {
  60. StrBaudRate = XmlHelper.GetXmlData(_path, "StrBaudRate", "9600"),
  61. StrDataBits = XmlHelper.GetXmlData(_path, "StrDataBits", "8"),
  62. StrParity = XmlHelper.GetXmlData(_path, "StrParity", "NONE"),
  63. StrStopBits = XmlHelper.GetXmlData(_path, "StrStopBits", "ONE"),
  64. PortName = XmlHelper.GetXmlData(_path, "PortName", "COM1")
  65. };
  66. cboNo.DataSource = EntityHelper.GetData<CmmPoundBaseEntity>(
  67. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  68. new object[] {this.ValidDataPurviewIds},
  69. ob);
  70. List<CmmPoundBaseEntity> list = EntityHelper.GetData<CmmPoundBaseEntity>(
  71. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  72. new object[] { new string[]{} },
  73. ob);
  74. cboPoundList.DataSource = new List<string>() {""}.Concat(list.Select(p=>p.PoundNo)).ToList();
  75. cboNo.DisplayMember = "PoundNo";
  76. if (cboNo.Items.Count > 0)
  77. {
  78. cboNo.SelectedIndex = 0;
  79. cboPoundList.Text = cboNo.Text;
  80. }
  81. baudRate.Text = _serialPortEntity.StrBaudRate;
  82. cmbCom.Text = _serialPortEntity.PortName;
  83. CurrentGrid.DisplayLayout.Override.ActiveCellRowSelectorAppearance.BackColor = Color.ForestGreen;
  84. _serialPortEntity.ReceiveData += (sender, data, message, type) => ShowMessage(data, message, type);
  85. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  86. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  87. if (cmmPoundBase == null)
  88. {
  89. MessageBox.Show(@"无磅房权限");
  90. return;
  91. }
  92. LoadRecord();
  93. /* var source = new AutoCompleteStringCollection();
  94. source.AddRange( _cmmInputRecordEntity.Where(p => p.RecordType == "1")
  95. .Select(p => p.RecordValue).ToArray());*/
  96. utbConnect_Click(null, null);
  97. LoadTempate();
  98. Query();
  99. Query2();
  100. }
  101. private void LoadRecord()
  102. {
  103. var dic = new Dictionary<string, object>();
  104. dic.Add("recordType","1");
  105. List<CmmInputRecordEntity> datas = EntityHelper.GetData<CmmInputRecordEntity>(
  106. "com.steering.Mcms.InputRecordServer.doQuery",
  107. new object[] {dic},
  108. ob);
  109. txtCar2.DataSource = datas.Where(p => p.RecordType == "1")
  110. .Select(p => p.RecordValue).Distinct().ToList();
  111. txtCar2.Text = "";
  112. dic = new Dictionary<string, object>();
  113. dic.Add("recordType", new List<string>() { "2", "7", "8", "9" });
  114. _cmmInputRecordEntities = EntityHelper.GetData<CmmInputRecordEntity>(
  115. "com.steering.Mcms.InputRecordServer.doQuery",
  116. new object[] { dic },
  117. ob);
  118. }
  119. private void utbConnect_Click(object sender, EventArgs e)
  120. {
  121. if (_serialPortEntity == null) return;
  122. if ((_serialPortEntity != null) && _serialPortEntity.IsOpen)
  123. {
  124. _serialPortEntity.Stop();
  125. }
  126. else
  127. {
  128. if (string.IsNullOrEmpty(cmbCom.Text))
  129. {
  130. if (sender == null) return;
  131. MessageBox.Show(@"端口号不能为空!");
  132. }
  133. if (string.IsNullOrEmpty(baudRate.Text))
  134. {
  135. if (sender == null) return;
  136. MessageBox.Show(@"端口速率不能为空!");
  137. }
  138. _serialPortEntity.Start();
  139. }
  140. }
  141. private void utbMessage_Click(object sender, EventArgs e)
  142. {
  143. _frmMessage = new frmMessage();
  144. _frmMessage.Show();
  145. }
  146. private void ShowMessage(object data, string message, DataType dataType)
  147. {
  148. if (dataType == DataType.ReceiveData)
  149. {
  150. double wt;
  151. if (double.TryParse(data.ToString2(), out wt))
  152. lblWtNow.SafeRefreshControl(() => { lblWtNow.Text = (wt/100d).ToString("0.00") + "t"; });
  153. }
  154. else if (dataType == DataType.Open)
  155. {
  156. utbConnect.Appearance.ForeColor = Color.Red;
  157. cmbCom.SafeRefreshControl(() => cmbCom.Enabled = false);
  158. baudRate.SafeRefreshControl(() => baudRate.Enabled = false);
  159. cboNo.SafeRefreshControl(() => cboNo.Enabled = false);
  160. }
  161. else if (dataType == DataType.Close)
  162. {
  163. utbConnect.Appearance.ForeColor = Color.Lime;
  164. cmbCom.SafeRefreshControl(() => cmbCom.Enabled = true);
  165. baudRate.SafeRefreshControl(() => baudRate.Enabled = true);
  166. cboNo.SafeRefreshControl(() => cboNo.Enabled = true);
  167. }
  168. else if (dataType == DataType.Error)
  169. {
  170. MessageBox.Show(message);
  171. }
  172. if ((_frmMessage != null) && !_frmMessage.IsDisposed)
  173. _frmMessage.SafeShowMsg(message, dataType);
  174. else
  175. _frmMessage = null;
  176. }
  177. private void utbShowWt_Click(object sender, EventArgs e)
  178. {
  179. string.Format("当前重量{0}", lblWt.Text.Replace("t", "吨")).Speak();
  180. }
  181. private void cmbCom_SelectedValueChanged(object sender, EventArgs e)
  182. {
  183. _serialPortEntity.PortName = cmbCom.Text;
  184. XmlHelper.SetXmlData(_path, "PortName", _serialPortEntity.PortName);
  185. }
  186. private void baudRate_SelectedValueChanged(object sender, EventArgs e)
  187. {
  188. _serialPortEntity.StrBaudRate = baudRate.Text;
  189. XmlHelper.SetXmlData(_path, "StrBaudRate", _serialPortEntity.StrBaudRate);
  190. }
  191. private void lblWtNow_Click(object sender, EventArgs e)
  192. {
  193. lblWt.Text = lblWtNow.Text;
  194. if (CurrentGrid.ActiveRow != null)
  195. {
  196. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  197. if ((current == null) || ("" == current.CarNo)) return;
  198. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  199. if (tbScondWt.ActiveTab.Key == "3")
  200. {
  201. }
  202. else if (tbScondWt.ActiveTab.Key == "0")
  203. {
  204. }
  205. else
  206. {
  207. var matInfo = GetMatInfo();
  208. if (matInfo != null)
  209. {
  210. decimal wt, fwt;
  211. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  212. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  213. {
  214. if (wt - fwt > 0)
  215. matInfo.SetWt(wt - fwt);
  216. }
  217. }
  218. }
  219. }
  220. }
  221. private void utbShowCarNo_Click(object sender, EventArgs e)
  222. {
  223. if ((cbxCar1.SelectedIndex < 0) || string.IsNullOrWhiteSpace(txtCar2.Text)) return;
  224. string.Format(" {0}", cbxCar1.Text + txtCar2.Text).Speak();
  225. }
  226. private void chkGross_CheckedChanged(object sender, EventArgs e)
  227. {
  228. tbFirstWt.Visible = chkGross.Checked;
  229. utbSaveAsT.Visible = chkGross.Checked;
  230. }
  231. /// <summary>
  232. /// 一次称重保存
  233. /// </summary>
  234. /// <param name="sender"></param>
  235. /// <param name="e"></param>
  236. private void utbSave1_Click(object sender, EventArgs e)
  237. {
  238. if (cmmPoundBase==null)
  239. {
  240. MessageBox.Show(@"无磅房权限");
  241. return;
  242. }
  243. if (string.IsNullOrWhiteSpace(txtCar2.Text) || string.IsNullOrWhiteSpace(cbxCar1.Text))
  244. {
  245. MessageBox.Show(@"未录入车牌号!");
  246. return;
  247. }
  248. decimal wt;
  249. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  250. {
  251. MessageBox.Show(@"重量异常!");
  252. return;
  253. }
  254. var cmmWeightRecord = new CmmWeightRecordEntityFull();
  255. if (chkGross.Checked)
  256. {
  257. var matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  258. if (matInfo != null) cmmWeightRecord = matInfo.GetData();
  259. }
  260. cmmWeightRecord.CarNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
  261. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  262. cmmWeightRecord.RecordType = !chkGross.Checked ? "101" : tbFirstWt.ActiveTab.Key;
  263. cmmWeightRecord.WtType = chkGross.Checked ? "1" : "0";
  264. cmmWeightRecord.Validflag = "1";
  265. cmmWeightRecord.RecordWeight = wt;
  266. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  267. cmmWeightRecord.MatType = chkGross.Checked ? tbFirstWt.ActiveTab.Text : "";
  268. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None, new JsonSerializerSettings
  269. {ContractResolver = new CamelCasePropertyNamesContractResolver()});
  270. var ccp = new CoreClientParam
  271. {
  272. ServerName = "com.steering.Mcms.LocalTruckScale",
  273. MethodName = "DoAdd",
  274. ServerParams = new object[]
  275. {
  276. "",
  277. json
  278. }
  279. };
  280. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  281. if (ccp.ReturnCode != -1)
  282. {
  283. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  284. {
  285. ccp.ReturnInfo.ToString2().Speak();
  286. lblWt.Text = "0.000t";
  287. LoadRecord();
  288. Query();
  289. var matInfo = GetMatInfo();
  290. if (matInfo != null) matInfo.SetDefault(null);
  291. }
  292. else
  293. {
  294. MessageUtil.ShowTips(ccp.ReturnInfo);
  295. }
  296. }
  297. }
  298. /// <summary>
  299. /// 二次称重
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void btnSave2_Click(object sender, EventArgs e)
  304. {
  305. if (cmmPoundBase == null)
  306. {
  307. MessageBox.Show(@"无磅房权限");
  308. return;
  309. }
  310. if (tbScondWt.ActiveTab == null) return;
  311. if (CurrentGrid.ActiveRow == null)
  312. {
  313. MessageBox.Show(@"请选择第一次称重记录");
  314. return;
  315. }
  316. decimal wt;
  317. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  318. {
  319. MessageBox.Show(@"重量异常!");
  320. return;
  321. }
  322. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  323. if (current == null) return;
  324. var key = GetKey();
  325. CmmWeightRecordEntityFull cmmWeightRecord;
  326. if ("207" == key)
  327. {
  328. cmmWeightRecord = new CmmWeightRecordEntityFull();
  329. cmmWeightRecord.WtType = "0";
  330. }
  331. else
  332. {
  333. var matInfo = GetMatInfo();
  334. if (matInfo == null) return;
  335. cmmWeightRecord = matInfo.GetData();
  336. cmmWeightRecord.WtType = "1";
  337. if (cmmWeightRecord.RecordNumber == null)
  338. {
  339. MessageBox.Show("数量不能为空!");
  340. return;
  341. }
  342. }
  343. string hookWtStr ="";
  344. if (key == "201")
  345. {
  346. if (cmmWeightRecord.MatInfos == null || !cmmWeightRecord.MatInfos.Any())
  347. {
  348. MessageBox.Show("无配送单信息!");
  349. return;
  350. }
  351. if (cmmWeightRecord.MatInfos.Any(p => p.ActWeight == null))
  352. {
  353. MessageBox.Show("有炉号没有钩子称重量!");
  354. return;
  355. }
  356. decimal hookWt = cmmWeightRecord.MatInfos.Select(p =>(decimal) p.ActWeight).Sum();
  357. hookWtStr = hookWt.ToString();
  358. decimal NetWt;
  359. decimal wt2, wt1;
  360. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
  361. decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
  362. {
  363. NetWt = wt2 - wt1;
  364. }
  365. else
  366. {
  367. MessageBox.Show("数据异常!");
  368. return;
  369. }
  370. if (NetWt <= 0)
  371. {
  372. MessageBox.Show("净重小于0!");
  373. return;
  374. }
  375. cmmWeightRecord.RealWt = NetWt;
  376. if (Math.Abs(NetWt - hookWt)*1000/NetWt >= 5)
  377. {
  378. string msg = " 净重与钩子称 误差超过千分之5";
  379. msg.Speak();
  380. if (MessageUtil.ShowYesNoAndQuestion(" 净重: " + NetWt + "t 钩子称重量: " + hookWt + "t 磅差 " + (NetWt - hookWt) + "t 误差超过千分之5, 请确认是否继续保存 ?") == DialogResult.No)
  381. return;
  382. }
  383. }
  384. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  385. cmmWeightRecord.RecordType = GetKey();
  386. cmmWeightRecord.Validflag = "2";
  387. cmmWeightRecord.RecordWeight = wt;
  388. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  389. cmmWeightRecord.CarNo = current.CarNo;
  390. cmmWeightRecord.MatType = GetMatType();
  391. if (("208" == cmmWeightRecord.RecordType) &&
  392. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  393. {
  394. MessageBox.Show(@"无废品出库信息,无法保存!");
  395. return;
  396. }
  397. if (("201" == cmmWeightRecord.RecordType) &&
  398. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  399. {
  400. MessageBox.Show(@"无装车单信息,无法保存!");
  401. return;
  402. }
  403. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None,
  404. new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()});
  405. var ccp = new CoreClientParam
  406. {
  407. ServerName = "com.steering.Mcms.LocalTruckScale",
  408. MethodName = "DoAdd",
  409. ServerParams = new object[]
  410. {
  411. current.RecordNo,
  412. hookWtStr,
  413. json
  414. }
  415. };
  416. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  417. if (ccp.ReturnCode != -1)
  418. {
  419. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  420. {
  421. lblWt.Text = "0.000t";
  422. string[] result = ccp.ReturnInfo.ToString2().Split('|');
  423. result[0].Speak();
  424. if (result.Length > 1)
  425. {
  426. Print(result[1]);
  427. }
  428. LoadRecord();
  429. Query();
  430. Query2();
  431. //TODO 打印
  432. var matInfo = GetMatInfo();
  433. if (matInfo != null) matInfo.SetDefault(null);
  434. }
  435. else
  436. {
  437. MessageUtil.ShowTips(ccp.ReturnInfo);
  438. }
  439. }
  440. }
  441. private void Print(string resultNo,bool spilt = false)
  442. {
  443. var strurl =
  444. "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=" +
  445. (spilt?"RepThCattyListCut":"RepThCattyList") +
  446. ".cpt&RESULT_NO=" +
  447. resultNo;
  448. var fre = new FrmRepBrower(ob, strurl)
  449. {
  450. Size = new Size(900,
  451. 500)
  452. };
  453. fre.Show();
  454. }
  455. private void frmLocalTruckScale_FormClosed(object sender, FormClosedEventArgs e)
  456. {
  457. if ((_serialPortEntity != null) && _serialPortEntity.IsOpen)
  458. _serialPortEntity.Stop();
  459. }
  460. private void Query()
  461. {
  462. var dic = new Dictionary<string, object>();
  463. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  464. dic.Add("poundNo", cboPoundList.Text );
  465. dic.Add("validflag", new List<string>() { "1"});
  466. cmmWeightRecordEntityBindingSource.DataSource = EntityHelper.GetData<CmmWeightRecordEntity>(
  467. "com.steering.Mcms.RecordServer.doQueryRecord",
  468. new object[] { dic },
  469. ob);
  470. }
  471. private void LoadTempate()
  472. {
  473. if (cmmPoundBase == null)
  474. {
  475. return;
  476. }
  477. _templateList = EntityHelper.GetData<CmmRecordTemplateEntity>(
  478. "com.steering.Mcms.TemplateServer.doQueryTempate",
  479. new object[] { ""},
  480. ob);
  481. tbFirstWt_SelectedTabChanged(null, null);
  482. }
  483. private void utbSaveAsT_Click(object sender, EventArgs e)
  484. {
  485. if (cmmPoundBase == null)
  486. {
  487. MessageBox.Show(@"无磅房权限");
  488. return;
  489. }
  490. if (tbWt.ActiveTab == null) return;
  491. var matInfo = GetMatInfo();
  492. if (matInfo != null)
  493. {
  494. var cmmWeightRecord = matInfo.GetData();
  495. string projectName;
  496. using (var fractureInfo = new ProjectName())
  497. {
  498. fractureInfo.ShowDialog();
  499. if (fractureInfo.DialogResult != DialogResult.OK) return;
  500. projectName = fractureInfo.ProjectNameStr;
  501. }
  502. var template = new CmmRecordTemplateEntity
  503. {
  504. CreateUser = UserInfo.GetUserName(),
  505. TemplateKey = GetKey(),
  506. TemplateLocation = cmmPoundBase.PoundNo,
  507. TemplateXml = cmmWeightRecord.ToString(),
  508. TemplateName = projectName
  509. };
  510. var ccp = new CoreClientParam
  511. {
  512. ServerName = "com.steering.Mcms.TemplateServer",
  513. MethodName = "DoSaveTemplateNo",
  514. ServerParams = new object[]
  515. {
  516. JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
  517. {ContractResolver = new CamelCasePropertyNamesContractResolver()})
  518. }
  519. };
  520. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  521. if (ccp.ReturnCode != -1)
  522. {
  523. MessageUtil.ShowTips(ccp.ReturnInfo);
  524. if (ccp.ReturnInfo.Equals("保存成功!"))
  525. LoadTempate();
  526. }
  527. }
  528. }
  529. private MatInfo GetMatInfo()
  530. {
  531. MatInfo matInfo = null;
  532. if (tbWt.ActiveTab == null) return null ;
  533. if (tbWt.ActiveTab.Key == "1" && tbFirstWt.ActiveTab!=null)
  534. matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  535. else if ( (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  536. (tbOther.ActiveTab != null))
  537. matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  538. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "3"))
  539. matInfo = matInfo15;
  540. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0"))
  541. matInfo = matInfo16;
  542. return matInfo;
  543. }
  544. private MatInfo GetMatInfoByKey(string key)
  545. {
  546. MatInfo matInfo = null;
  547. foreach (var ultraTab in tbFirstWt.Tabs)
  548. {
  549. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p=>p.Key == key) .ToList();
  550. if (matinfo.Any()) return matinfo[0];
  551. }
  552. foreach (var ultraTab in tbOther.Tabs)
  553. {
  554. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
  555. if (matinfo.Any()) return matinfo[0];
  556. }
  557. if (key == "201") return matInfo16;
  558. return matInfo;
  559. }
  560. private void utbDelete_Click(object sender, EventArgs e)
  561. {
  562. var matInfo = GetMatInfo();
  563. if (matInfo != null) matInfo.DeleteRow();
  564. }
  565. private void utbClear_Click(object sender, EventArgs e)
  566. {
  567. var matInfo = GetMatInfo();
  568. if (matInfo != null) matInfo.Clear();
  569. }
  570. private void tbFirstWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  571. {
  572. LoadTem();
  573. var matInfo = GetMatInfo();
  574. if (matInfo != null) matInfo.Clear();
  575. if (CurrentGrid.ActiveRow != null)
  576. {
  577. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  578. if ((current == null) || ("" == current.CarNo)) return;
  579. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  580. if (tbScondWt.ActiveTab.Key == "3")
  581. {
  582. }
  583. else if (tbScondWt.ActiveTab.Key == "0")
  584. {
  585. }
  586. else
  587. {
  588. if (matInfo != null)
  589. {
  590. decimal wt, fwt;
  591. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  592. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  593. {
  594. if (wt - fwt > 0)
  595. matInfo.SetWt(wt - fwt);
  596. }
  597. }
  598. }
  599. }
  600. }
  601. private void LoadTem()
  602. {
  603. if (_templateList == null) return;
  604. var key = GetKey();
  605. if (string.IsNullOrWhiteSpace(key)) return;
  606. if (_cmmInputRecordEntities != null && _cmmInputRecordEntities.Any())
  607. {
  608. MatInfo matInfo = GetMatInfo();
  609. if (matInfo != null)
  610. {
  611. matInfo.iniMatName(_cmmInputRecordEntities.Where(p => p.RecordKey == key || string.IsNullOrWhiteSpace(p.RecordKey)).ToList());
  612. }
  613. }
  614. lvTemplate.Items.Clear();
  615. lvTemplate.Items.AddRange(_templateList.Where(p => p.TemplateKey == key)
  616. .Select(p =>
  617. {
  618. var
  619. temp =
  620. new UltraListViewItem(p.TemplateName, null, null) {Key = p.TemplateNo};
  621. try
  622. {
  623. temp.Tag =
  624. XmlHelper.FromXElement<CmmWeightRecordEntityFull>(XElement.Parse(p.TemplateXml));
  625. }
  626. catch (Exception)
  627. {
  628. // ignored
  629. }
  630. return temp;
  631. }
  632. ).
  633. ToArray()
  634. );
  635. }
  636. private string GetKey()
  637. {
  638. return tbWt.ActiveTab.Key == "1"
  639. ? (tbFirstWt.ActiveTab == null ? "" : tbFirstWt.ActiveTab.Key)
  640. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  641. (tbOther.ActiveTab != null)
  642. ? tbOther.ActiveTab.Key
  643. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  644. ? "201"
  645. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  646. (tbScondWt.ActiveTab.Key == "2")
  647. ? "207"
  648. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  649. (tbScondWt.ActiveTab.Key == "3")
  650. ? "208"
  651. : "";
  652. }
  653. private string GetMatType()
  654. {
  655. return tbWt.ActiveTab.Key == "1"
  656. ? ""
  657. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  658. (tbOther.ActiveTab != null)
  659. ? tbOther.ActiveTab.Text
  660. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  661. ? "钢管发运"
  662. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  663. (tbScondWt.ActiveTab.Key == "2")
  664. ? ""
  665. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  666. (tbScondWt.ActiveTab.Key == "3")
  667. ? "其它内转"
  668. : "";
  669. }
  670. private void lvTemplate_MouseClick(object sender, MouseEventArgs e)
  671. {
  672. var listView = sender as UltraListView;
  673. if (e.Button == MouseButtons.Right)
  674. {
  675. var itemAtPoint = lvTemplate.ItemFromPoint(e.Location);
  676. if (itemAtPoint != null)
  677. {
  678. lvTemplate.ContextMenuStrip = listViewMenuStrip;
  679. ISelectionManager selectionManager = listView;
  680. if (selectionManager != null) selectionManager.SelectItem(itemAtPoint, true);
  681. itemAtPoint.Activate();
  682. }
  683. }
  684. }
  685. private void deleteTemplate_Click(object sender, EventArgs e)
  686. {
  687. if (lvTemplate.ActiveItem == null) return;
  688. var ccp = new CoreClientParam
  689. {
  690. ServerName = "com.steering.Mcms.TemplateServer",
  691. MethodName = "DoDeleteTemplate",
  692. ServerParams = new object[]
  693. {
  694. lvTemplate.ActiveItem.Key,
  695. UserInfo.GetUserName()
  696. }
  697. };
  698. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  699. if (ccp.ReturnCode != -1)
  700. {
  701. MessageUtil.ShowTips(ccp.ReturnInfo);
  702. if (ccp.ReturnInfo.Equals("删除成功!"))
  703. LoadTempate();
  704. }
  705. }
  706. private void CurrentGrid_AfterRowActivate(object sender, EventArgs e)
  707. {
  708. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  709. if ((current == null) || ("" == current.CarNo)) return;
  710. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  711. if (tbScondWt.ActiveTab.Key == "3")
  712. ShowWasteInfo(current.CarNo);
  713. else if (tbScondWt.ActiveTab.Key == "0")
  714. ShowLoadvehicleInfo(current.CarNo);
  715. else
  716. {
  717. var matInfo = GetMatInfo();
  718. if (matInfo != null)
  719. {
  720. decimal wt,fwt;
  721. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) && decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  722. {
  723. if (wt-fwt>0)
  724. matInfo.SetWt(wt - fwt);
  725. }
  726. }
  727. }
  728. }
  729. // 显示废品信息
  730. public void ShowWasteInfo(string carNo)
  731. {
  732. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  733. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryWasteInfo", new object[] { carNo }, ob);
  734. if ((dt != null) && (dt.Rows.Count > 0))
  735. {
  736. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
  737. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  738. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
  739. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  740. cmmWeightRecordEntityFull.MatName = "废品管";
  741. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>
  742. {
  743. new CmmWeightMatEntity {ActCount = cmmWeightRecordEntityFull.RecordNumber}
  744. };
  745. }
  746. matInfo15.SetDefault(cmmWeightRecordEntityFull);
  747. }
  748. //显示装车单信息
  749. public void ShowLoadvehicleInfo(string carNo)
  750. {
  751. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  752. var dt = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleInfo",
  753. new object[] {carNo}, ob);
  754. if ((dt != null) && (dt.Rows.Count > 0))
  755. {
  756. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
  757. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["LOADVEHICLE_NO"].ToString2();
  758. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["RECEIV_NM"].ToString2();
  759. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["STACKING_PIECE"].ToString3());
  760. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
  761. cmmWeightRecordEntityFull.OrderName = dt.Rows[0]["CUSTOMER_NM"].ToString2();
  762. cmmWeightRecordEntityFull.MatName = "钢管";
  763. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  764. var dtc = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleMatInfo",
  765. new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
  766. if ((dtc != null) && (dtc.Rows.Count > 0))
  767. foreach (DataRow dtcRow in dtc.Rows)
  768. {
  769. var cmmWeightMatEntity = new CmmWeightMatEntity
  770. {
  771. StorageNo = dtcRow["STORAGE_NO"].ToString2(),
  772. StorageName = dtcRow["STORAGE_NAME"].ToString2(),
  773. StoveNo = dtcRow["STOVE_NO"].ToString2(),
  774. OrderNo = dtcRow["ORDER_NO"].ToString2(),
  775. OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
  776. OrderSeqNo = dtcRow["ORDER_SEQ_NO"].ToString2(),
  777. ProOrderNo = dtcRow["ORDER_NO"].ToString2() + "/" +
  778. dtcRow["ORDER_SEQ"].ToString2(),
  779. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  780. Producname = dtcRow["PRODUCNAME"].ToString2(),
  781. StdCode = dtcRow["STD_CODE"].ToString2(),
  782. StdName = dtcRow["STD_NAME"].ToString2(),
  783. Gradecode = dtcRow["GRADECODE"].ToString2(),
  784. Gradename = dtcRow["GRADENAME"].ToString2(),
  785. Steelcode = dtcRow["STEELCODE"].ToString2(),
  786. Steelname = dtcRow["STEELNAME"].ToString2(),
  787. SpecCode = dtcRow["SPEC_CODE"].ToString2(),
  788. SpecName = dtcRow["SPEC_NAME"].ToString2(),
  789. ModelCode = dtcRow["MODEL_CODE"].ToString2(),
  790. ModelDesc = dtcRow["MODEL_DESC"].ToString2(),
  791. ActLenMin = decimal.Parse(dtcRow["ACT_LEN_MIN"].ToString3()),
  792. ActLenMax = decimal.Parse(dtcRow["ACT_LEN_MAX"].ToString3()),
  793. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
  794. dtcRow["ACT_LEN_MAX"].ToString3(),
  795. ActWeight = decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3()),
  796. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  797. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  798. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  799. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  800. };
  801. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  802. }
  803. try
  804. {
  805. var dth = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryHook",
  806. new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
  807. if ((dth != null) && (dth.Rows.Count > 0))
  808. {
  809. foreach (DataRow dthRow in dth.Rows)
  810. {
  811. double total = double.Parse(dthRow["HOOK_WEIGHT"].ToString3());
  812. double num = int.Parse(cmmWeightRecordEntityFull.MatInfos.Where(
  813. p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
  814. .Select(p => p.ActCount)
  815. .Sum()
  816. .ToString3());
  817. double perWt = Math.Round(total/num, 3);
  818. List<CmmWeightMatEntity> list = cmmWeightRecordEntityFull.MatInfos.Where(
  819. p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2()).ToList();
  820. for (var i = 0; i < list.Count; i++)
  821. {
  822. if (i == 0)
  823. list[i].ActWeight =
  824. decimal.Parse(
  825. (total - perWt*(num- double.Parse(list[i].ActCount.ToString3()))).ToString3());
  826. else
  827. list[i].ActWeight =
  828. decimal.Parse(
  829. (perWt * double.Parse(list[i].ActCount.ToString3())).ToString3());
  830. }
  831. }
  832. }
  833. }
  834. catch (Exception)
  835. {
  836. }
  837. }
  838. else
  839. {
  840. cmmWeightRecordEntityFull = null;
  841. }
  842. matInfo16.SetDefault(cmmWeightRecordEntityFull);
  843. }
  844. private void tbScondWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  845. {
  846. if (CurrentGrid.ActiveRow != null)
  847. {
  848. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  849. if (current != null)
  850. if (tbScondWt.ActiveTab.Key == "3")
  851. ShowWasteInfo(current.CarNo);
  852. else if (tbScondWt.ActiveTab.Key == "0")
  853. ShowLoadvehicleInfo(current.CarNo);
  854. }
  855. LoadTem();
  856. }
  857. private void utnQuery_Click(object sender, EventArgs e)
  858. {
  859. Query2();
  860. }
  861. private void Query2()
  862. {
  863. var dic = new Dictionary<string, object>();
  864. if (chkTim.Checked)
  865. {
  866. dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  867. dic.Add("time1", RegEndTime.Value.ToString("yyy-MM-dd HH:mm:ss"));
  868. }
  869. dic.Add("carNo", uteCarNo.Text);
  870. dic.Add("matType", uceQueryCarType.Text);
  871. if (uceValidflag.CheckedItems.Count > 0)
  872. dic.Add("validflag", uceValidflag.CheckedItems.Select(p => p.DataValue.ToString()).ToList());
  873. dic.Add("orderName", uteOrder.Text);
  874. dic.Add("shippersName", uteShippersName.Text);
  875. dic.Add("receiveName", uteReceiveName.Text);
  876. dic.Add("memo", uteMemo.Text);
  877. QueryBS.DataSource = EntityHelper.GetData<CmmWeightResultEntity>(
  878. "com.steering.Mcms.ResultServer.doQuery",
  879. new object[] {dic},
  880. ob);
  881. }
  882. private void tbMain_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  883. {
  884. if (tbMain.SelectedTab.Key == "1")
  885. Query();
  886. else
  887. Query2();
  888. }
  889. private void utbReset_Click(object sender, EventArgs e)
  890. {
  891. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  892. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  893. uteCarNo.Text = "";
  894. uceQueryCarType.Text = "";
  895. foreach (var uceValidflagItem in uceValidflag.Items)
  896. uceValidflagItem.CheckState = uceValidflagItem.DataValue.ToString2() == "1"
  897. ? CheckState.Checked
  898. : CheckState.Unchecked;
  899. uteOrder.Text = "";
  900. uteShippersName.Text = "";
  901. uteReceiveName.Text = "";
  902. uteMemo.Text = "";
  903. }
  904. private void btnDelete_Click(object sender, EventArgs e)
  905. {
  906. if (ugData.ActiveRow == null) return;
  907. UltraButton ub = (sender as UltraButton);
  908. if(ub==null) return;
  909. if (MessageUtil.ShowYesNoAndQuestion("是否" + ub.Text + "过磅单?") == DialogResult.No)
  910. return;
  911. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  912. if (data == null) return;
  913. var ccp = new CoreClientParam
  914. {
  915. ServerName = "com.steering.Mcms.LocalTruckScale",
  916. MethodName = "DoDeleteResult",
  917. ServerParams = new object[]
  918. {
  919. data.ResultNo,
  920. UserInfo.GetUserName(),
  921. "重过"==ub.Text?"2":"1"
  922. }
  923. };
  924. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  925. if (ccp.ReturnCode != -1)
  926. {
  927. MessageUtil.ShowTips(ccp.ReturnInfo);
  928. if (ccp.ReturnInfo.Equals("操作成功!"))
  929. {
  930. Query2();
  931. Query();
  932. }
  933. }
  934. }
  935. private void cboNo_SelectedValueChanged(object sender, EventArgs e)
  936. {
  937. if(cboNo.SelectedIndex<0) return;
  938. cmmPoundBase = cboNo.SelectedItem as CmmPoundBaseEntity;
  939. CmmBaseProtocolEntity cmmBaseProtocol = null;
  940. if (cmmPoundBase != null)
  941. {
  942. List<CmmBaseProtocolCEntity> protocols = EntityHelper.GetData<CmmBaseProtocolCEntity>(
  943. "com.steering.Mcms.ProcotolServer.getProcotolId",
  944. new object[] {cmmPoundBase.PoundProtocolId},
  945. ob);
  946. if (protocols != null && protocols.Any())
  947. {
  948. cmmBaseProtocol = new CmmBaseProtocolEntity()
  949. {
  950. ProtocolId = cmmPoundBase.PoundProtocolId,
  951. ListC = protocols
  952. };
  953. }
  954. cboPoundList.Text = cmmPoundBase.PoundNo;
  955. }
  956. _serialPortEntity.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol));
  957. }
  958. private void lvTemplate_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
  959. {
  960. var matInfo = GetMatInfo();
  961. if (matInfo != null) matInfo.SetDefault(e.Item.Tag as CmmWeightRecordEntityFull, e.Item.Text);
  962. }
  963. private void cboPoundList_SelectedValueChanged(object sender, EventArgs e)
  964. {
  965. Query();
  966. }
  967. private void delete_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  968. {
  969. if (cmmPoundBase == null)
  970. {
  971. MessageBox.Show(@"无磅房权限");
  972. return;
  973. }
  974. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  975. if ((current == null) || ("" == current.CarNo)) return;
  976. if (MessageUtil.ShowYesNoAndQuestion("是否删除" + current.CarNo + " 过磅记录?") == DialogResult.No)
  977. return;
  978. var ccp = new CoreClientParam
  979. {
  980. ServerName = "com.steering.Mcms.RecordServer",
  981. MethodName = "DoUpdateRecord",
  982. ServerParams = new object[]
  983. {
  984. current.RecordNo
  985. }
  986. };
  987. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  988. if (ccp.ReturnCode != -1)
  989. {
  990. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  991. {
  992. Query();
  993. }
  994. else
  995. {
  996. MessageUtil.ShowTips(ccp.ReturnInfo);
  997. }
  998. }
  999. }
  1000. private void ugData_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
  1001. {
  1002. var data = e.Row.ListObject as CmmWeightResultEntity;
  1003. if(data==null) return;
  1004. if(data.RecordType2=="201") e.Row.Appearance.BackColor = Color.ForestGreen;
  1005. }
  1006. private void uteCarNo_KeyPress(object sender, KeyPressEventArgs e)
  1007. {
  1008. if (e.KeyChar == 13 )
  1009. {
  1010. Query2();
  1011. }
  1012. }
  1013. private void utnUpdate_Click(object sender, EventArgs e)
  1014. {
  1015. if (ugData.ActiveRow == null)
  1016. {
  1017. MessageBox.Show("请选择需要修改磅单记录!");
  1018. return;
  1019. }
  1020. CmmWeightResultEntity cmm = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1021. MatInfo matInfo = GetMatInfoByKey("101" == cmm.RecordType1? cmm.RecordType2:cmm.RecordType1 );
  1022. if (matInfo == null)
  1023. {
  1024. MessageBox.Show("该类型不允许修改!");
  1025. return;
  1026. }
  1027. using (var frmUpdate = new FrmUpdate(ob, cmm.ResultNo, "101" == cmm.RecordType1
  1028. ? cmm.RecordNo2
  1029. : cmm.RecordNo1)
  1030. {
  1031. ColumnsM = matInfo.ColumnsM,
  1032. ColumnsC = matInfo.ColumnsC
  1033. })
  1034. {
  1035. frmUpdate.ShowDialog();
  1036. if (frmUpdate.DialogResult == DialogResult.OK)
  1037. {
  1038. Query2();
  1039. }
  1040. }
  1041. }
  1042. private void utbPrint_Click(object sender, EventArgs e)
  1043. {
  1044. if (ugData.ActiveRow == null) return;
  1045. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1046. if (data == null) return;
  1047. Print(data.ResultNo);
  1048. }
  1049. private void utbPrintSingle_Click(object sender, EventArgs e)
  1050. {
  1051. if (ugData.ActiveRow == null) return;
  1052. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1053. if (data == null) return;
  1054. Print(data.ResultNo,true);
  1055. }
  1056. private void unExcel_Click(object sender, EventArgs e)
  1057. {
  1058. HSSFWorkbook hssfworkbook = new HSSFWorkbook();
  1059. ISheet sheet = hssfworkbook.CreateSheet("磅房统计");
  1060. int index = 0;
  1061. SetHead(sheet, hssfworkbook, index++);
  1062. SetHeadRow(sheet, hssfworkbook
  1063. , new List<string>() {"磅房号", "称重类型", "物资名称", "物资数量", "称重次数", "物资净重"},
  1064. new List<int>() {9, 15, 25, 15, 15, 15},
  1065. index++
  1066. );
  1067. setData(sheet, hssfworkbook, ref index);
  1068. SetSumm(sheet, index, hssfworkbook);
  1069. sheet.ForceFormulaRecalculation = true;
  1070. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
  1071. using (SaveFileDialog saveFileDialog1 = new SaveFileDialog())
  1072. {
  1073. saveFileDialog1.FileName = "磅房统计" + DateTime.Now.ToString("yyMMdd");
  1074. saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
  1075. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  1076. {
  1077. string sFullName = saveFileDialog1.FileName;
  1078. MemoryStream ms = new MemoryStream();
  1079. hssfworkbook.Write(ms);
  1080. using (FileStream fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
  1081. {
  1082. byte[] bArr = ms.ToArray();
  1083. fs.Write(bArr, 0, bArr.Length);
  1084. fs.Flush();
  1085. }
  1086. ProcessStartInfo p = new ProcessStartInfo(sFullName);
  1087. p.WorkingDirectory = Path.GetDirectoryName(sFullName);
  1088. Process.Start(p);
  1089. }
  1090. }
  1091. }
  1092. private void SetSumm(ISheet sheet, int index, HSSFWorkbook hssfworkbook)
  1093. {
  1094. IRow IRow = sheet.CreateRow(index);
  1095. IRow.Height = 20*20;
  1096. ICell Icell1 = IRow.CreateCell(1);
  1097. Icell1.SetCellValue("合计");
  1098. var style = CenterStyle(hssfworkbook);
  1099. var font = ContextFont(hssfworkbook);
  1100. style.SetFont(font);
  1101. style.BorderTop = BorderStyle.Medium;
  1102. style.BorderBottom = BorderStyle.Medium;
  1103. style.BorderLeft = BorderStyle.Medium;
  1104. style.BorderRight = BorderStyle.Thin;
  1105. //将新的样式赋给单元格
  1106. Icell1.CellStyle = style;
  1107. ICell Icell12 = IRow.CreateCell(2);
  1108. var style12 = CenterStyle(hssfworkbook);
  1109. style12.SetFont(font);
  1110. style12.BorderTop = BorderStyle.Medium;
  1111. style12.BorderBottom = BorderStyle.Medium;
  1112. style12.BorderLeft = BorderStyle.Thin;
  1113. style12.BorderRight = BorderStyle.Thin;
  1114. //将新的样式赋给单元格
  1115. Icell12.CellStyle = style12;
  1116. ICell Icell13 = IRow.CreateCell(3);
  1117. var style13 = CenterStyle(hssfworkbook);
  1118. style13.SetFont(font);
  1119. style13.BorderTop = BorderStyle.Medium;
  1120. style13.BorderBottom = BorderStyle.Medium;
  1121. style13.BorderLeft = BorderStyle.Thin;
  1122. style13.BorderRight = BorderStyle.Thin;
  1123. //将新的样式赋给单元格
  1124. Icell13.CellStyle = style13;
  1125. //合并单元格
  1126. sheet.AddMergedRegion(new CellRangeAddress(index, index, 1, 3));
  1127. List<string> list = new List<string>();
  1128. for (int i = 2; i < index; i++)
  1129. {
  1130. list.Add(i + 1 + "");
  1131. }
  1132. ICell Icell2 = IRow.CreateCell(4);
  1133. if (list.Any())
  1134. {
  1135. Icell2.SetCellType(CellType.Formula);
  1136. Icell2.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "E" + p).ToList())));
  1137. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell2);
  1138. }
  1139. var style2 = numStyle(hssfworkbook);
  1140. var font2 = ContextFont(hssfworkbook);
  1141. style2.SetFont(font2);
  1142. style2.BorderTop = BorderStyle.Medium;
  1143. style2.BorderBottom = BorderStyle.Medium;
  1144. style2.BorderLeft = BorderStyle.Thin;
  1145. style2.BorderRight = BorderStyle.Thin;
  1146. //将新的样式赋给单元格
  1147. Icell2.CellStyle = style2;
  1148. ICell Icell3 = IRow.CreateCell(5);
  1149. if (list.Any())
  1150. {
  1151. Icell3.SetCellType(CellType.Formula);
  1152. Icell3.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "F" + p).ToList())));
  1153. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell3);
  1154. }
  1155. var style3 = numStyle(hssfworkbook);
  1156. var font3 = ContextFont(hssfworkbook);
  1157. style3.SetFont(font3);
  1158. style3.BorderTop = BorderStyle.Medium;
  1159. style3.BorderBottom = BorderStyle.Medium;
  1160. style3.BorderLeft = BorderStyle.Thin;
  1161. style3.BorderRight = BorderStyle.Thin;
  1162. //将新的样式赋给单元格
  1163. Icell3.CellStyle = style3;
  1164. ICell Icell4 = IRow.CreateCell(6);
  1165. if (list.Any())
  1166. {
  1167. Icell4.SetCellType(CellType.Formula);
  1168. Icell4.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "G" + p).ToList())));
  1169. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell4);
  1170. }
  1171. var style4 = numStyle(hssfworkbook);
  1172. var font4 = ContextFont(hssfworkbook);
  1173. style4.SetFont(font4);
  1174. style4.BorderTop = BorderStyle.Medium;
  1175. style4.BorderBottom = BorderStyle.Medium;
  1176. style4.BorderLeft = BorderStyle.Thin;
  1177. style4.BorderRight = BorderStyle.Medium;
  1178. //将新的样式赋给单元格
  1179. Icell4.CellStyle = style4;
  1180. }
  1181. private void setData(ISheet sheet, HSSFWorkbook hssfworkbook, ref int index)
  1182. {
  1183. int index1 = index;
  1184. List<CmmWeightResultEntity> data = QueryBS.DataSource as List<CmmWeightResultEntity>;
  1185. if (data != null && data.Any())
  1186. {
  1187. data.GroupBy(p => new {p.RecoderLocation2, p.MatName, p.MatType})
  1188. .Select(p => new
  1189. {
  1190. p.Key.MatName,
  1191. p.Key.MatType,
  1192. p.Key.RecoderLocation2,
  1193. count = p.Count(),
  1194. num = int.Parse(p.Select(q => q.MatNum ?? 0).Sum().ToString3()),
  1195. wt = double.Parse( p.Select(q => q.NetWt).Sum().ToString3())
  1196. }).ToList()
  1197. .ForEach(
  1198. p =>
  1199. {
  1200. IRow IRow = sheet.CreateRow(index1++);
  1201. IRow.Height = 20*20;
  1202. for (int i = 0; i < 6; i++)
  1203. {
  1204. ICell Icell = IRow.CreateCell(i + 1);
  1205. if (i <= 2)
  1206. {
  1207. Icell.SetCellType(CellType.String);
  1208. Icell.SetCellValue(
  1209. i == 0
  1210. ? p.RecoderLocation2
  1211. : i == 1
  1212. ? p.MatType:
  1213. p.MatName);
  1214. }
  1215. else
  1216. {
  1217. Icell.SetCellType(CellType.Numeric);
  1218. if (i == 3)
  1219. {
  1220. Icell.SetCellValue(p.num);
  1221. }
  1222. if (i == 4)
  1223. {
  1224. Icell.SetCellValue(p.count);
  1225. }
  1226. if (i == 5)
  1227. {
  1228. Icell.SetCellValue(p.wt);
  1229. }
  1230. };
  1231. var style = i <= 2 ? textStyle(hssfworkbook) : numStyle(hssfworkbook);
  1232. style.BorderTop = BorderStyle.Thin;
  1233. style.BorderBottom = BorderStyle.Thin;
  1234. style.BorderLeft =i==0?BorderStyle.Medium : BorderStyle.Thin;
  1235. style.BorderRight = i == 5 ? BorderStyle.Medium : BorderStyle.Thin;
  1236. var font = ContextFont(hssfworkbook);
  1237. //使用SetFont方法将字体样式添加到单元格样式中
  1238. style.SetFont(font);
  1239. //将新的样式赋给单元格
  1240. Icell.CellStyle = style;
  1241. }
  1242. }
  1243. );
  1244. }
  1245. index = index1;
  1246. }
  1247. private void SetHeadRow(ISheet sheet, HSSFWorkbook hssfworkbook,List<string> name,List<int> columsWidth,int rowIndex )
  1248. {
  1249. IRow IRow = sheet.CreateRow(rowIndex);
  1250. IRow.Height = 20 * 20;
  1251. for (int i = 0; i < name.Count; i++)
  1252. {
  1253. sheet.SetColumnWidth(i + 1, columsWidth[i] * 256);
  1254. ICell Icell = IRow.CreateCell(i+1);
  1255. Icell.SetCellValue(name[i]);
  1256. var style = CenterStyle(hssfworkbook);
  1257. style.BorderTop = BorderStyle.Medium;
  1258. style.BorderBottom = BorderStyle.Medium;
  1259. style.BorderLeft = BorderStyle.Medium;
  1260. style.BorderRight = BorderStyle.Medium;
  1261. var font = ContextFont(hssfworkbook);
  1262. //使用SetFont方法将字体样式添加到单元格样式中
  1263. style.SetFont(font);
  1264. //将新的样式赋给单元格
  1265. Icell.CellStyle = style;
  1266. }
  1267. }
  1268. private void SetHead(ISheet sheet, HSSFWorkbook hssfworkbook,int rowindex)
  1269. {
  1270. IRow IRow = sheet.CreateRow(rowindex);
  1271. IRow.Height = 50*20;
  1272. ICell Icell = IRow.CreateCell(1);
  1273. Icell.SetCellValue("磅房统计");
  1274. var style = CenterStyle(hssfworkbook);
  1275. var font = TitleFont(hssfworkbook);
  1276. //使用SetFont方法将字体样式添加到单元格样式中
  1277. style.SetFont(font);
  1278. //将新的样式赋给单元格
  1279. Icell.CellStyle = style;
  1280. //合并单元格
  1281. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 1, 6));
  1282. }
  1283. private static IFont TitleFont(HSSFWorkbook hssfworkbook)
  1284. {
  1285. //新建一个字体样式对象
  1286. IFont font = hssfworkbook.CreateFont();
  1287. font.FontName = "宋体";
  1288. font.FontHeightInPoints = 30;
  1289. //设置字体加粗样式
  1290. font.Boldweight = (short) FontBoldWeight.Bold;
  1291. return font;
  1292. }
  1293. private static IFont ContextFont(HSSFWorkbook hssfworkbook)
  1294. {
  1295. //新建一个字体样式对象
  1296. IFont font = hssfworkbook.CreateFont();
  1297. font.FontName = "宋体";
  1298. font.FontHeightInPoints = 12;
  1299. //设置字体加粗样式
  1300. font.Boldweight = (short)FontBoldWeight.Bold;
  1301. return font;
  1302. }
  1303. private ICellStyle CenterStyle(HSSFWorkbook hssfworkbook)
  1304. {
  1305. ICellStyle style = hssfworkbook.CreateCellStyle();
  1306. //设置单元格的样式:水平对齐居中
  1307. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center;
  1308. style.VerticalAlignment = VerticalAlignment.Center;
  1309. return style;
  1310. }
  1311. private ICellStyle textStyle(HSSFWorkbook hssfworkbook)
  1312. {
  1313. ICellStyle style = hssfworkbook.CreateCellStyle();
  1314. //设置单元格的样式:水平对齐居中
  1315. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Left;
  1316. style.VerticalAlignment = VerticalAlignment.Center;
  1317. return style;
  1318. }
  1319. private ICellStyle numStyle(HSSFWorkbook hssfworkbook)
  1320. {
  1321. ICellStyle style = hssfworkbook.CreateCellStyle();
  1322. //设置单元格的样式:水平对齐居中
  1323. style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Right;
  1324. style.VerticalAlignment = VerticalAlignment.Center;
  1325. return style;
  1326. }
  1327. private void CurrentGrid_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  1328. {
  1329. }
  1330. private void CurrentGrid_DoubleClickCell(object sender, Infragistics.Win.UltraWinGrid.DoubleClickCellEventArgs e)
  1331. {
  1332. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1333. if ((current == null) || ("" == current.CarNo)) return;
  1334. foreach (var cbxCar1Item in cbxCar1.Items)
  1335. {
  1336. if (current.CarNo.StartsWith(cbxCar1Item.ToString2().Trim()))
  1337. {
  1338. cbxCar1.SelectedItem = cbxCar1Item;
  1339. txtCar2.Text = current.CarNo.Replace(cbxCar1Item.ToString2().Trim(),"").Trim();
  1340. }
  1341. }
  1342. if (!tbWt.Tabs["2"].Selected)
  1343. {
  1344. tbWt.Tabs["2"].Selected = true;
  1345. tbScondWt_SelectedTabChanged(null, null);
  1346. }
  1347. }
  1348. private void utbExport_Click(object sender, EventArgs e)
  1349. {
  1350. GridHelper.ulGridToExcel(ugData, "称重记录");
  1351. }
  1352. private void utbExport2_Click(object sender, EventArgs e)
  1353. {
  1354. GridHelper.ulGridToExcel(CurrentGrid, "称重记录");
  1355. }
  1356. private void cbxCar1_SelectedValueChanged(object sender, EventArgs e)
  1357. {
  1358. if (cbxCar1.Text.Trim() == "厂内")
  1359. {
  1360. txtCar2.Text = "自用车";
  1361. }
  1362. }
  1363. private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
  1364. {
  1365. if (isLoading) return;
  1366. XmlHelper.SetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
  1367. }
  1368. private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
  1369. {
  1370. if (isLoading) return;
  1371. XmlHelper.SetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
  1372. }
  1373. private void frmLocalTruckScale_Shown(object sender, EventArgs e)
  1374. {
  1375. isLoading = false;
  1376. splitContainer1.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
  1377. splitContainer2.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
  1378. FontConverter x = new FontConverter();
  1379. CurrentGrid.Font = x.ConvertFromString(XmlHelper.GetXmlData(_path, CurrentGrid.Name,x.ConvertToString(CurrentGrid.Font))) as Font;
  1380. ugData.Font = x.ConvertFromString(XmlHelper.GetXmlData(_path, ugData.Name, x.ConvertToString(ugData.Font))) as Font;
  1381. }
  1382. private void CurrentGrid_KeyPress(object sender, KeyPressEventArgs e)
  1383. {
  1384. }
  1385. private void CurrentGrid_KeyDown(object sender, KeyEventArgs e)
  1386. {
  1387. if (e.KeyCode == Keys.F5)
  1388. {
  1389. using (var dr = new FontDialog() { Font = (sender as System.Windows.Forms.Control).Font })
  1390. {
  1391. if (dr.ShowDialog() == DialogResult.OK)
  1392. {
  1393. (sender as System.Windows.Forms.Control).Font = dr.Font;
  1394. FontConverter x = new FontConverter();
  1395. string font = x.ConvertToString(dr.Font);
  1396. // t = x.ConvertFromString(s) as Font;
  1397. XmlHelper.SetXmlData(_path, (sender as System.Windows.Forms.Control).Name, font);
  1398. }
  1399. }
  1400. }
  1401. }
  1402. private void txtCar2_TextChanged(object sender, EventArgs e)
  1403. {
  1404. foreach (var currentGridRow in CurrentGrid.Rows)
  1405. {
  1406. if (currentGridRow.Cells["CarNo"].Value.ToString2() == cbxCar1.Text + txtCar2.Text.Trim())
  1407. {
  1408. if (!tbWt.Tabs["2"].Selected)
  1409. {
  1410. tbWt.Tabs["2"].Selected = true;
  1411. tbScondWt_SelectedTabChanged(null, null);
  1412. }
  1413. }
  1414. }
  1415. tbWt.Tabs["1"].Selected = true;
  1416. }
  1417. }
  1418. }