frmLocalTruckScale.cs 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431
  1. using Core.Mes.Client.Comm.Control;
  2. using Core.Mes.Client.Comm.Server;
  3. using Core.Mes.Client.Comm.Tool;
  4. using Core.StlMes.Client.LgResMgt.Mcms.entity;
  5. using CoreFS.CA06;
  6. using Infragistics.Win;
  7. using Infragistics.Win.Misc;
  8. using Infragistics.Win.UltraWinEditors;
  9. using Infragistics.Win.UltraWinGrid;
  10. using Infragistics.Win.UltraWinListView;
  11. using Infragistics.Win.UltraWinTabControl;
  12. using Newtonsoft.Json;
  13. using Newtonsoft.Json.Serialization;
  14. using NPOI.HSSF.UserModel;
  15. using NPOI.SS.Formula.Functions;
  16. using NPOI.SS.UserModel;
  17. using NPOI.SS.Util;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.ComponentModel;
  21. using System.Data;
  22. using System.Diagnostics;
  23. using System.Drawing;
  24. using System.IO;
  25. using System.Linq;
  26. using System.Timers;
  27. using System.Windows.Forms;
  28. using System.Xml.Linq;
  29. using BorderStyle = NPOI.SS.UserModel.BorderStyle;
  30. using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
  31. using Timer = System.Timers.Timer;
  32. namespace Core.StlMes.Client.LgResMgt.Mcms
  33. {
  34. public partial class frmLocalTruckScale : FrmBase
  35. {
  36. private static readonly string _path = Environment.CurrentDirectory + "\\data\\SerialPort.xml";
  37. private readonly Timer timer = new Timer();
  38. private List<CmmInputRecordEntity> _cmmInputRecordEntities;
  39. private frmMessage _frmMessage;
  40. private List<CmmRecordTemplateEntity> _templateList;
  41. private bool canUpdateWt;
  42. private CmmPoundBaseEntity cmmPoundBase;
  43. private iCommunication communication;
  44. private List<CommunicationEntity> CommunicationEntitys = new List<CommunicationEntity>();
  45. private SerialPortEntity defultPortEntity;
  46. private bool isLoading = true;
  47. private List<CmmPoundBaseEntity> poundInfos;
  48. private Log l = Log.GetInstance();
  49. public frmLocalTruckScale()
  50. {
  51. InitializeComponent();
  52. IsLoadUserView = true;
  53. timer.Elapsed += timer_Elapsed;
  54. timer.Interval = 1*60*1000;
  55. }
  56. private void timer_Elapsed(object sender, ElapsedEventArgs e)
  57. {
  58. try
  59. {
  60. CurrentGrid.SafeRefreshControl(() =>
  61. {
  62. var dic = new Dictionary<string, object>();
  63. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  64. dic.Add("poundNo", cboPoundList.Text);
  65. dic.Add("validflag", new List<string> {"1"});
  66. dic.Add("effRemaind", "1");
  67. List<CmmWeightRecordEntity> list = EntityHelper.GetData<CmmWeightRecordEntity>(
  68. "com.steering.Mcms.RecordServer.doQueryRecord",
  69. new object[] {dic},
  70. ob);
  71. if ((list != null) && list.Any())
  72. foreach (
  73. var ultraGridRow in
  74. CurrentGrid.Rows.Where(
  75. p => list.Any(q => q.RecordNo == p.Cells["RecordNo"].Value.ToString2())))
  76. ultraGridRow.Cells["RecordDate"].Appearance.BackColor = Color.Red;
  77. });
  78. GC.Collect();
  79. }
  80. catch (Exception)
  81. {
  82. }
  83. }
  84. protected override void OnLoad(EventArgs e)
  85. {
  86. base.OnLoad(e);
  87. tbFirstWt.Controls.OfType<UltraTabPageControl>()
  88. .SelectMany(p => p.Controls.OfType<MatInfo>())
  89. .ToList()
  90. .ForEach(p => p.ini(ob));
  91. tbOther.Controls.OfType<UltraTabPageControl>()
  92. .SelectMany(p => p.Controls.OfType<MatInfo>())
  93. .ToList()
  94. .ForEach(p => p.ini(ob));
  95. matInfo15.ini(ob);
  96. matInfo16.ini(ob);
  97. tbWt.Appearance.ForeColor = SystemColors.ControlText;
  98. ;
  99. tbFirstWt.Appearance.ForeColor = SystemColors.ControlText;
  100. ;
  101. tbScondWt.Appearance.ForeColor = SystemColors.ControlText;
  102. ;
  103. tbOther.Appearance.ForeColor = SystemColors.ControlText;
  104. ;
  105. defultPortEntity = new SerialPortEntity
  106. {
  107. StrBaudRate = XmlHelper.GetXmlData(_path, "StrBaudRate", "9600"),
  108. StrDataBits = XmlHelper.GetXmlData(_path, "StrDataBits", "8"),
  109. StrParity = XmlHelper.GetXmlData(_path, "StrParity", "NONE"),
  110. StrStopBits = XmlHelper.GetXmlData(_path, "StrStopBits", "ONE"),
  111. PortName = XmlHelper.GetXmlData(_path, "PortName", "COM1")
  112. };
  113. poundInfos = EntityHelper.GetData<CmmPoundBaseEntity>(
  114. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  115. new object[] {ValidDataPurviewIds},
  116. ob);
  117. var data = XmlHelper.GetXElement(_path, "CommunicationInfo");
  118. CommunicationEntitys = new List<CommunicationEntity>();
  119. if (data != null)
  120. foreach (var xElement in data.Elements())
  121. {
  122. var temp = new CommunicationEntity();
  123. temp.PoundNo = xElement.Name.ToString3().Replace("POUND_", "");
  124. var type = XmlHelper.GetAttribute(xElement, "type", "1");
  125. if (type == "1")
  126. temp.Communication = new SerialPortEntity
  127. {
  128. StrBaudRate =
  129. XmlHelper.GetAttribute(xElement, "StrBaudRate",
  130. XmlHelper.GetXmlData(_path, "StrBaudRate", "9600")),
  131. StrDataBits =
  132. XmlHelper.GetAttribute(xElement, "StrDataBits",
  133. XmlHelper.GetXmlData(_path, "StrDataBits", "8")),
  134. StrParity =
  135. XmlHelper.GetAttribute(xElement, "StrParity",
  136. XmlHelper.GetXmlData(_path, "StrParity", "NONE")),
  137. StrStopBits =
  138. XmlHelper.GetAttribute(xElement, "StrStopBits",
  139. XmlHelper.GetXmlData(_path, "StrStopBits", "ONE")),
  140. PortName =
  141. XmlHelper.GetAttribute(xElement, "PortName",
  142. XmlHelper.GetXmlData(_path, "PortName", "COM1"))
  143. };
  144. else
  145. temp.Communication = new SocketClient
  146. {
  147. Ip = XmlHelper.GetAttribute(xElement, "Ip", ""),
  148. Port = XmlHelper.GetAttribute(xElement, "Port", "")
  149. };
  150. CommunicationEntitys.Add(temp);
  151. }
  152. CommunicationEntitys =
  153. poundInfos.Select(p =>
  154. {
  155. var entity = new CommunicationEntity { PoundNo = p.PoundNo};
  156. var tmplist = CommunicationEntitys.Where(q => q.PoundNo == p.PoundNo).ToList();
  157. if (tmplist.Any()) entity.Communication = tmplist[0].Communication;
  158. if (entity.Communication == null) entity.Communication = defultPortEntity;
  159. return entity;
  160. }
  161. ).ToList();
  162. List<CmmPoundBaseEntity> list = EntityHelper.GetData<CmmPoundBaseEntity>(
  163. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  164. new object[] {new string[] {}},
  165. ob);
  166. cboPoundList.DataSource = new List<string> {""}.Concat(list.Select(p => p.PoundNo)).ToList();
  167. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  168. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  169. LoadRecord();
  170. /* var source = new AutoCompleteStringCollection();
  171. source.AddRange( _cmmInputRecordEntity.Where(p => p.RecordType == "1")
  172. .Select(p => p.RecordValue).ToArray());*/
  173. cboNo.DisplayMember = "PoundNo";
  174. cboNo.DataSource = poundInfos;
  175. cboNo.SelectedIndex = -1;
  176. cboNo.SelectedValueChanged += cboNo_SelectedValueChanged;
  177. var location = "";
  178. location = XmlHelper.GetXmlData(_path, "cboNo", "");
  179. if ("" == location)
  180. {
  181. if (cboNo.Items.Count > 0)
  182. {
  183. cboNo.SelectedIndex = 0;
  184. cboPoundList.Text = cboNo.Text;
  185. }
  186. }
  187. else
  188. {
  189. cboNo.Text = location;
  190. }
  191. LoadRecord();
  192. LoadTempate();
  193. }
  194. private void defultPortEntity_ReceiveData(object sender, object data, string message, DataType datatype,
  195. byte[] bdata)
  196. {
  197. ShowMessage(data, message, datatype);
  198. }
  199. private void LoadRecord()
  200. {
  201. var dic = new Dictionary<string, object>();
  202. dic.Add("recordType", new List<string> {"1"});
  203. List<CmmInputRecordEntity> datas = EntityHelper.GetData<CmmInputRecordEntity>(
  204. "com.steering.Mcms.InputRecordServer.doQuery",
  205. new object[] {dic},
  206. ob);
  207. txtCar2.DataSource = datas.Where(p => p.RecordType == "1")
  208. .Select(p => p.RecordValue).Distinct().ToList();
  209. txtCar2.Text = "";
  210. dic = new Dictionary<string, object>();
  211. dic.Add("recordType", new List<string> {"2", "7", "8", "9"});
  212. _cmmInputRecordEntities = EntityHelper.GetData<CmmInputRecordEntity>(
  213. "com.steering.Mcms.InputRecordServer.doQuery",
  214. new object[] {dic},
  215. ob);
  216. }
  217. private void utbConnect_Click(object sender, EventArgs e)
  218. {
  219. if (communication == null) return;
  220. if ((communication != null) && communication.Status)
  221. {
  222. communication.Stop();
  223. }
  224. else
  225. {
  226. communication.Start();
  227. XmlHelper.SetXmlData(_path, "cboNo", cmmPoundBase.PoundNo);
  228. if (communication is SerialPortEntity)
  229. {
  230. XmlHelper.SetXmlData(_path, "PortName", ((SerialPortEntity) communication).PortName);
  231. XmlHelper.SetXmlData(_path, "StrBaudRate", ((SerialPortEntity) communication).StrBaudRate);
  232. }
  233. }
  234. }
  235. private void utbMessage_Click(object sender, EventArgs e)
  236. {
  237. _frmMessage = new frmMessage();
  238. _frmMessage.Show();
  239. }
  240. private void ShowMessage(object data, string message, DataType dataType)
  241. {
  242. if (dataType == DataType.ReceiveData)
  243. {
  244. double wt;
  245. if (double.TryParse(data.ToString2(), out wt))
  246. lblWtNow.SafeRefreshControl(() => { lblWtNow.Text = (wt/100d).ToString("0.00") + "t"; });
  247. }
  248. else if (dataType == DataType.Open)
  249. {
  250. utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Red);
  251. lblMsg.SafeRefreshControl(
  252. () =>
  253. lblMsg.Text =
  254. communication.Status
  255. ? (communication is SerialPortEntity ? "已打开" : "已连接")
  256. : (communication is SerialPortEntity ? "已关闭" : "断开连接"));
  257. // cboNo.SafeRefreshControl(() => cboNo.Enabled = false);
  258. }
  259. else if (dataType == DataType.Close)
  260. {
  261. utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Lime);
  262. lblMsg.SafeRefreshControl(
  263. () =>
  264. lblMsg.Text =
  265. communication.Status
  266. ? (communication is SerialPortEntity ? "已打开" : "已连接")
  267. : (communication is SerialPortEntity ? "已关闭" : "断开连接"));
  268. }
  269. else if (dataType == DataType.Error)
  270. {
  271. MessageBox.Show(message);
  272. }
  273. else if (dataType == DataType.ClientReconnect)
  274. {
  275. lblMsg.SafeRefreshControl(() => lblMsg.Text = "网络异常,正在重连服务!");
  276. }
  277. lblStatus.SafeRefreshControl(() => lblStatus.Text = communication.ToString());
  278. if ((_frmMessage != null) && !_frmMessage.IsDisposed)
  279. _frmMessage.SafeShowMsg(message, dataType);
  280. else
  281. _frmMessage = null;
  282. }
  283. private void utbShowWt_Click(object sender, EventArgs e)
  284. {
  285. string.Format("当前重量{0}", lblWt.Text.Replace("t", "吨")).Speak();
  286. }
  287. private void lblWtNow_Click(object sender, EventArgs e)
  288. {
  289. /* var ccp = new CoreClientParam
  290. {
  291. ServerName = "com.steering.Mcms.MatOutServer",
  292. MethodName = "DoTest",
  293. ServerParams = new object[]
  294. {
  295. }
  296. };
  297. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  298. */
  299. lblWt.Text = lblWtNow.Text;
  300. if (CurrentGrid.ActiveRow != null)
  301. {
  302. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  303. if ((current == null) || ("" == current.CarNo)) return;
  304. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  305. if (tbScondWt.ActiveTab.Key == "3")
  306. {
  307. }
  308. else if (tbScondWt.ActiveTab.Key == "0")
  309. {
  310. }
  311. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  312. (tbOther.ActiveTab.Key == "205"))
  313. {
  314. decimal wt, fwt;
  315. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  316. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  317. ShowOutInfo(current.CarNo, wt - fwt);
  318. }
  319. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  320. (tbOther.ActiveTab.Key == "206"))
  321. {
  322. decimal wt, fwt;
  323. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  324. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  325. if (wt - fwt > 0)
  326. matInfo13.SetWt(wt - fwt);
  327. // ShowOutInfoGp(current.CarNo, wt - fwt);
  328. }
  329. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  330. (tbOther.ActiveTab.Key == "109"))
  331. {
  332. var matInfo = GetMatInfo();
  333. if (matInfo != null)
  334. {
  335. decimal wt, fwt;
  336. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  337. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  338. if (wt - fwt > 0)
  339. matInfo.SetWt(wt - fwt);
  340. }
  341. }
  342. }
  343. }
  344. private void utbShowCarNo_Click(object sender, EventArgs e)
  345. {
  346. if ((cbxCar1.SelectedIndex < 0) || string.IsNullOrWhiteSpace(txtCar2.Text)) return;
  347. string.Format(" {0}", cbxCar1.Text + txtCar2.Text).Speak();
  348. }
  349. private void chkGross_CheckedChanged(object sender, EventArgs e)
  350. {
  351. tbFirstWt.Visible = chkGross.Checked;
  352. utbSaveAsT.Visible = chkGross.Checked;
  353. }
  354. /// <summary>
  355. /// 一次称重保存
  356. /// </summary>
  357. /// <param name="sender"></param>
  358. /// <param name="e"></param>
  359. private void utbSave1_Click(object sender, EventArgs e)
  360. {
  361. if (cmmPoundBase == null)
  362. {
  363. MessageBox.Show(@"无磅房权限");
  364. return;
  365. }
  366. if (string.IsNullOrWhiteSpace(txtCar2.Text) || string.IsNullOrWhiteSpace(cbxCar1.Text))
  367. {
  368. MessageBox.Show(@"未录入车牌号!");
  369. return;
  370. }
  371. decimal wt;
  372. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  373. {
  374. MessageBox.Show(@"重量异常!");
  375. return;
  376. }
  377. var cmmWeightRecord = new CmmWeightRecordEntityFull();
  378. if (chkGross.Checked)
  379. {
  380. var matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  381. if (matInfo != null) cmmWeightRecord = matInfo.GetData();
  382. }
  383. if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
  384. cmmWeightRecord.MatInfos.Any())
  385. {
  386. MessageBox.Show("支数不能为空!");
  387. return;
  388. }
  389. cmmWeightRecord.CarNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
  390. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  391. cmmWeightRecord.RecordType = !chkGross.Checked ? "101" : tbFirstWt.ActiveTab.Key;
  392. cmmWeightRecord.WtType = chkGross.Checked ? "1" : "0";
  393. cmmWeightRecord.Validflag = "1";
  394. cmmWeightRecord.RecordWeight = wt;
  395. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  396. cmmWeightRecord.MatType = chkGross.Checked ? tbFirstWt.ActiveTab.Text : "";
  397. //cmmWeightRecord.Memo = chkSteelCar.Checked ? "钢管" : "";
  398. if ("102" == cmmWeightRecord.RecordType)
  399. if ((cmmWeightRecord.RecordNumber == null) || (cmmWeightRecord.RecordNumber <= 0) ||
  400. (cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()
  401. || cmmWeightRecord.MatInfos.Any(p => (p.ActCount == null) || (p.ActCount <= 0)))
  402. {
  403. MessageBox.Show("支数不能为空!");
  404. return;
  405. }
  406. var list =
  407. cmmWeightRecordEntityBindingSource.DataSource as List<CmmWeightRecordEntity>;
  408. if ((list != null) && list.Any(p => p.CarNo == cmmWeightRecord.CarNo))
  409. if (MessageUtil.ShowYesNoAndQuestion("车牌已经存在皮重,是否继续保存皮重?") == DialogResult.No)
  410. return;
  411. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None, new JsonSerializerSettings
  412. {ContractResolver = new CamelCasePropertyNamesContractResolver()});
  413. var ccp = new CoreClientParam
  414. {
  415. ServerName = "com.steering.Mcms.LocalTruckScale",
  416. MethodName = "DoAdd",
  417. ServerParams = new object[]
  418. {
  419. "",
  420. json
  421. }
  422. };
  423. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  424. if (ccp.ReturnCode != -1)
  425. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  426. {
  427. ccp.ReturnInfo.ToString2().Speak();
  428. lblWt.Text = "0.000t";
  429. LoadRecord();
  430. Query();
  431. //ccp.ReturnObject;
  432. var matInfo = GetMatInfo();
  433. if (matInfo != null) matInfo.SetDefault(null);
  434. }
  435. else
  436. {
  437. MessageUtil.ShowTips(ccp.ReturnInfo);
  438. }
  439. }
  440. /// <summary>
  441. /// 二次称重
  442. /// </summary>
  443. /// <param name="sender"></param>
  444. /// <param name="e"></param>
  445. private void btnSave2_Click(object sender, EventArgs e)
  446. {
  447. if (cmmPoundBase == null)
  448. {
  449. MessageBox.Show(@"无磅房权限");
  450. return;
  451. }
  452. if (tbScondWt.ActiveTab == null) return;
  453. if (CurrentGrid.ActiveRow == null)
  454. {
  455. MessageBox.Show(@"请选择第一次称重记录");
  456. return;
  457. }
  458. decimal wt;
  459. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  460. {
  461. MessageBox.Show(@"重量异常!");
  462. return;
  463. }
  464. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  465. if (current == null) return;
  466. var key = GetKey();
  467. CmmWeightRecordEntityFull cmmWeightRecord;
  468. if ("207" == key)
  469. {
  470. cmmWeightRecord = new CmmWeightRecordEntityFull();
  471. cmmWeightRecord.WtType = "0";
  472. }
  473. else
  474. {
  475. var matInfo = GetMatInfo();
  476. if (matInfo == null) return;
  477. cmmWeightRecord = matInfo.GetData();
  478. cmmWeightRecord.WtType = "1";
  479. if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
  480. cmmWeightRecord.MatInfos.Any())
  481. {
  482. MessageBox.Show("数量不能为空!");
  483. return;
  484. }
  485. }
  486. var hookWtStr = "";
  487. if (key == "201")
  488. {
  489. if ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any())
  490. {
  491. MessageBox.Show("无配送单信息!");
  492. return;
  493. }
  494. if (cmmWeightRecord.MatInfos.Any(p => p.ActWeight == null))
  495. {
  496. MessageBox.Show("有炉号没有钩子称重量!");
  497. return;
  498. }
  499. var hookWt = cmmWeightRecord.MatInfos.Select(p => (decimal) p.ActWeight).Sum();
  500. hookWtStr = hookWt.ToString();
  501. decimal NetWt;
  502. decimal wt2, wt1;
  503. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
  504. decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
  505. {
  506. NetWt = wt2 - wt1;
  507. }
  508. else
  509. {
  510. MessageBox.Show("数据异常!");
  511. return;
  512. }
  513. if (NetWt <= 0)
  514. {
  515. MessageBox.Show("净重小于0!");
  516. return;
  517. }
  518. cmmWeightRecord.RealWt = NetWt;
  519. if (Math.Abs(NetWt - hookWt)*1000/NetWt >= 5)
  520. {
  521. var msg = " 净重与钩子称 误差超过千分之5";
  522. msg.Speak();
  523. if (
  524. MessageUtil.ShowYesNoAndQuestion(" 净重: " + NetWt + "t 钩子称重量: " + hookWt + "t 磅差 " +
  525. (NetWt - hookWt) + "t 误差超过千分之5, 请确认是否继续保存 ?") ==
  526. DialogResult.No)
  527. return;
  528. }
  529. }
  530. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  531. cmmWeightRecord.RecordType = GetKey();
  532. cmmWeightRecord.Validflag = "2";
  533. cmmWeightRecord.RecordWeight = wt;
  534. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  535. cmmWeightRecord.CarNo = current.CarNo;
  536. cmmWeightRecord.MatType = GetMatType();
  537. if (("208" == cmmWeightRecord.RecordType) &&
  538. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  539. {
  540. MessageBox.Show(@"无废品出库信息,无法保存!");
  541. return;
  542. }
  543. if (("201" == cmmWeightRecord.RecordType) &&
  544. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  545. {
  546. MessageBox.Show(@"无装车单信息,无法保存!");
  547. return;
  548. }
  549. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None,
  550. new JsonSerializerSettings {ContractResolver = new CamelCasePropertyNamesContractResolver()});
  551. var ccp = new CoreClientParam
  552. {
  553. ServerName = "com.steering.Mcms.LocalTruckScale",
  554. MethodName = "DoAdd",
  555. ServerParams = new object[]
  556. {
  557. current.RecordNo,
  558. hookWtStr,
  559. json
  560. }
  561. };
  562. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  563. if (ccp.ReturnCode != -1)
  564. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  565. {
  566. decimal wt2;
  567. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2);
  568. lblWt.Text = "0.000t";
  569. var result = ccp.ReturnInfo.ToString2().Split('|');
  570. result[0].Speak();
  571. if (result.Length > 1)
  572. if ((key == "201") && (wt2 > 50) && (MessageUtil.ShowYesNoAndQuestion("称重完成! 毛重超过50吨, 是否继续打印磅单?") ==
  573. DialogResult.No))
  574. {
  575. }
  576. else
  577. {
  578. Print(result[1]);
  579. }
  580. LoadRecord();
  581. Query();
  582. Query2();
  583. //TODO 打印
  584. var matInfo = GetMatInfo();
  585. if (matInfo != null) matInfo.SetDefault(null);
  586. }
  587. else
  588. {
  589. MessageUtil.ShowTips(ccp.ReturnInfo);
  590. }
  591. }
  592. private void Print(string resultNo, bool spilt = false)
  593. {
  594. var strurl =
  595. "http://172.16.2.145/WebReport/ReportServer?reportlet=" +
  596. (spilt ? "RepThCattyListCut" : "RepThCattyList") +
  597. ".cpt&RESULT_NO=" +
  598. resultNo;
  599. var fre = new FrmRepBrower(ob, strurl)
  600. {
  601. Size = new Size(900,
  602. 500)
  603. };
  604. fre.Show();
  605. }
  606. private void Print2(string resultNo, bool spilt = false)
  607. {
  608. var strurl =
  609. "http://172.16.2.145/WebReport/ReportServer?reportlet=" +
  610. (spilt ? "RepThCattyListCut" : "RepThCattyList") +
  611. ".cpt&RESULT_NO=" +
  612. resultNo;
  613. System.Diagnostics.Process.Start(strurl);
  614. //var fre = new FrmRepBrower(ob, strurl)
  615. //{
  616. // Size = new Size(900,
  617. // 500)
  618. //};
  619. //fre.Show();
  620. }
  621. private void frmLocalTruckScale_FormClosed(object sender, FormClosedEventArgs e)
  622. {
  623. if ((communication != null) && communication.Status)
  624. communication.Stop();
  625. timer.Stop();
  626. }
  627. private void Query()
  628. {
  629. var dic = new Dictionary<string, object>();
  630. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  631. dic.Add("poundNo", cboPoundList.Text);
  632. dic.Add("validflag", new List<string> {"1"});
  633. cmmWeightRecordEntityBindingSource.DataSource = EntityHelper.GetData<CmmWeightRecordEntity>(
  634. "com.steering.Mcms.RecordServer.doQueryRecord",
  635. new object[] {dic},
  636. ob);
  637. Comm.RefreshAndAutoSize(CurrentGrid);
  638. }
  639. private void LoadTempate()
  640. {
  641. /* if (cmmPoundBase == null)
  642. return;
  643. */
  644. _templateList = EntityHelper.GetData<CmmRecordTemplateEntity>(
  645. "com.steering.Mcms.TemplateServer.doQueryTempate",
  646. new object[] {""},
  647. ob);
  648. tbFirstWt_SelectedTabChanged(null, null);
  649. }
  650. private void utbSaveAsT_Click(object sender, EventArgs e)
  651. {
  652. if (cmmPoundBase == null)
  653. {
  654. MessageBox.Show(@"无磅房权限");
  655. return;
  656. }
  657. if (tbWt.ActiveTab == null) return;
  658. var matInfo = GetMatInfo();
  659. if (matInfo != null)
  660. {
  661. var cmmWeightRecord = matInfo.GetData();
  662. string projectName;
  663. using (var fractureInfo = new ProjectName("模板名"))
  664. {
  665. fractureInfo.ShowDialog();
  666. if (fractureInfo.DialogResult != DialogResult.OK) return;
  667. projectName = fractureInfo.ProjectNameStr;
  668. }
  669. var template = new CmmRecordTemplateEntity
  670. {
  671. CreateUser = UserInfo.GetUserName(),
  672. TemplateKey = GetKey(),
  673. TemplateLocation = cmmPoundBase.PoundNo,
  674. TemplateXml = cmmWeightRecord.ToString(),
  675. TemplateName = projectName
  676. };
  677. var ccp = new CoreClientParam
  678. {
  679. ServerName = "com.steering.Mcms.TemplateServer",
  680. MethodName = "DoSaveTemplateNo",
  681. ServerParams = new object[]
  682. {
  683. JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
  684. {ContractResolver = new CamelCasePropertyNamesContractResolver()})
  685. }
  686. };
  687. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  688. if (ccp.ReturnCode != -1)
  689. {
  690. MessageUtil.ShowTips(ccp.ReturnInfo);
  691. if (ccp.ReturnInfo.Equals("保存成功!"))
  692. LoadTempate();
  693. }
  694. }
  695. }
  696. private MatInfo GetMatInfo()
  697. {
  698. MatInfo matInfo = null;
  699. if (tbWt.ActiveTab == null) return null;
  700. if ((tbWt.ActiveTab.Key == "1") && (tbFirstWt.ActiveTab != null))
  701. matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  702. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  703. (tbOther.ActiveTab != null))
  704. matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  705. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "3"))
  706. matInfo = matInfo15;
  707. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0"))
  708. matInfo = matInfo16;
  709. return matInfo;
  710. }
  711. private MatInfo GetMatInfoByKey(string key)
  712. {
  713. MatInfo matInfo = null;
  714. foreach (var ultraTab in tbFirstWt.Tabs)
  715. {
  716. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
  717. if (matinfo.Any()) return matinfo[0];
  718. }
  719. foreach (var ultraTab in tbOther.Tabs)
  720. {
  721. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
  722. if (matinfo.Any()) return matinfo[0];
  723. }
  724. if (key == "201") return matInfo16;
  725. return matInfo;
  726. }
  727. private void utbDelete_Click(object sender, EventArgs e)
  728. {
  729. var matInfo = GetMatInfo();
  730. if (matInfo != null) matInfo.DeleteRow();
  731. }
  732. private void utbClear_Click(object sender, EventArgs e)
  733. {
  734. var matInfo = GetMatInfo();
  735. if (matInfo != null) matInfo.Clear();
  736. }
  737. private void tbFirstWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  738. {
  739. LoadTem();
  740. var matInfo = GetMatInfo();
  741. if (matInfo != null) matInfo.Clear();
  742. if (CurrentGrid.ActiveRow != null)
  743. {
  744. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  745. if ((current == null) || ("" == current.CarNo)) return;
  746. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  747. if (tbScondWt.ActiveTab.Key == "3")
  748. {
  749. }
  750. else if (tbScondWt.ActiveTab.Key == "0")
  751. {
  752. }
  753. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  754. (tbOther.ActiveTab.Key == "205"))
  755. {
  756. decimal wt, fwt;
  757. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  758. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  759. ShowOutInfo(current.CarNo, wt - fwt);
  760. }
  761. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  762. (tbOther.ActiveTab.Key == "206"))
  763. {
  764. decimal wt, fwt;
  765. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  766. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  767. if (wt - fwt > 0)
  768. matInfo13.SetWt(wt - fwt);
  769. //ShowOutInfoGp(current.CarNo, wt - fwt);
  770. }
  771. else
  772. {
  773. if (matInfo != null)
  774. {
  775. decimal wt, fwt;
  776. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  777. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  778. if (wt - fwt > 0)
  779. matInfo.SetWt(wt - fwt);
  780. }
  781. }
  782. }
  783. utbSelect.Visible = (tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "1") && (tbFirstWt.ActiveTab != null) &&
  784. (tbFirstWt.ActiveTab.Key == "102");
  785. utbSelect2.Visible = utbSelect.Visible;
  786. }
  787. private void LoadTem()
  788. {
  789. if (_templateList == null) return;
  790. var key = GetKey();
  791. if (string.IsNullOrWhiteSpace(key)) return;
  792. if ((_cmmInputRecordEntities != null) && _cmmInputRecordEntities.Any())
  793. {
  794. var matInfo = GetMatInfo();
  795. if (matInfo != null)
  796. matInfo.iniMatName(
  797. _cmmInputRecordEntities.Where(
  798. p => (p.RecordKey == key) || string.IsNullOrWhiteSpace(p.RecordKey)).ToList());
  799. }
  800. lvTemplate.Items.Clear();
  801. lvTemplate.Items.AddRange(_templateList.Where(p => CheckShowKey(p.TemplateKey, key))
  802. .Select(p =>
  803. {
  804. var
  805. temp =
  806. new UltraListViewItem(p.TemplateName, null, null) {Key = p.TemplateNo};
  807. try
  808. {
  809. temp.Tag =
  810. XmlHelper.FromXElement<CmmWeightRecordEntityFull>(XElement.Parse(p.TemplateXml));
  811. }
  812. catch (Exception)
  813. {
  814. // ignored
  815. }
  816. return temp;
  817. }
  818. ).
  819. ToArray()
  820. );
  821. }
  822. private string GetKey()
  823. {
  824. return tbWt.ActiveTab.Key == "1"
  825. ? (tbFirstWt.ActiveTab == null ? "" : tbFirstWt.ActiveTab.Key)
  826. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  827. (tbOther.ActiveTab != null)
  828. ? tbOther.ActiveTab.Key
  829. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  830. ? "201"
  831. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  832. (tbScondWt.ActiveTab.Key == "2")
  833. ? "207"
  834. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  835. (tbScondWt.ActiveTab.Key == "3")
  836. ? "208"
  837. : "";
  838. }
  839. private string GetMatType()
  840. {
  841. return tbWt.ActiveTab.Key == "1"
  842. ? ""
  843. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  844. (tbOther.ActiveTab != null)
  845. ? tbOther.ActiveTab.Text
  846. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  847. ? "钢管发运"
  848. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  849. (tbScondWt.ActiveTab.Key == "2")
  850. ? ""
  851. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  852. (tbScondWt.ActiveTab.Key == "3")
  853. ? "其它内转"
  854. : "";
  855. }
  856. private void lvTemplate_MouseClick(object sender, MouseEventArgs e)
  857. {
  858. var listView = sender as UltraListView;
  859. if (e.Button == MouseButtons.Right)
  860. {
  861. var itemAtPoint = lvTemplate.ItemFromPoint(e.Location);
  862. if (itemAtPoint != null)
  863. {
  864. lvTemplate.ContextMenuStrip = listViewMenuStrip;
  865. ISelectionManager selectionManager = listView;
  866. if (selectionManager != null) selectionManager.SelectItem(itemAtPoint, true);
  867. itemAtPoint.Activate();
  868. }
  869. }
  870. }
  871. private void deleteTemplate_Click(object sender, EventArgs e)
  872. {
  873. if (lvTemplate.ActiveItem == null) return;
  874. var ccp = new CoreClientParam
  875. {
  876. ServerName = "com.steering.Mcms.TemplateServer",
  877. MethodName = "DoDeleteTemplate",
  878. ServerParams = new object[]
  879. {
  880. lvTemplate.ActiveItem.Key,
  881. UserInfo.GetUserName()
  882. }
  883. };
  884. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  885. if (ccp.ReturnCode != -1)
  886. {
  887. MessageUtil.ShowTips(ccp.ReturnInfo);
  888. if (ccp.ReturnInfo.Equals("删除成功!"))
  889. LoadTempate();
  890. }
  891. }
  892. private void CurrentGrid_AfterRowActivate(object sender, EventArgs e)
  893. {
  894. CurrentGrid.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
  895. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  896. if ((current == null) || ("" == current.CarNo)) return;
  897. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  898. if (tbScondWt.ActiveTab.Key == "3")
  899. ShowWasteInfo(current.CarNo);
  900. else if (tbScondWt.ActiveTab.Key == "0")
  901. ShowLoadvehicleInfo(current.CarNo);
  902. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) && (tbOther.ActiveTab.Key == "205"))
  903. {
  904. decimal wt, fwt;
  905. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  906. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  907. ShowOutInfo(current.CarNo, wt - fwt);
  908. }
  909. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) && (tbOther.ActiveTab.Key == "206"))
  910. {
  911. decimal wt, fwt;
  912. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  913. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  914. if (wt - fwt > 0)
  915. matInfo13.SetWt(wt - fwt);
  916. //ShowOutInfoGp(current.CarNo, wt - fwt);
  917. }
  918. else
  919. {
  920. var matInfo = GetMatInfo();
  921. if (matInfo != null)
  922. {
  923. decimal wt, fwt;
  924. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  925. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  926. if (wt - fwt > 0)
  927. matInfo.SetWt(wt - fwt);
  928. }
  929. }
  930. }
  931. // 显示废品信息
  932. public void ShowWasteInfo(string carNo)
  933. {
  934. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  935. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryWasteInfo", new object[] {carNo}, ob);
  936. if ((dt != null) && (dt.Rows.Count > 0))
  937. {
  938. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
  939. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  940. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
  941. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  942. cmmWeightRecordEntityFull.MatName = "废品管";
  943. foreach (DataRow dtcRow in dt.Rows)
  944. {
  945. var cmmWeightMatEntity = new CmmWeightMatEntity
  946. {
  947. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  948. Producname = dtcRow["PRODUCNAME"].ToString2(),
  949. Gradecode = dtcRow["GRADECODE"].ToString2(),
  950. Gradename = dtcRow["GRADENAME"].ToString2(),
  951. Steelcode = dtcRow["STEELCODE"].ToString2(),
  952. Steelname = dtcRow["STEELNAME"].ToString2(),
  953. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
  954. dtcRow["ACT_LEN_MAX"].ToString3(),
  955. ActWeight = decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3()),
  956. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  957. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  958. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  959. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  960. };
  961. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  962. }
  963. }
  964. matInfo15.SetDefault(cmmWeightRecordEntityFull);
  965. }
  966. //显示装车单信息
  967. public void ShowLoadvehicleInfo(string carNo)
  968. {
  969. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  970. var dt = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleInfo",
  971. new object[] {carNo}, ob);
  972. if ((dt != null) && (dt.Rows.Count > 0))
  973. {
  974. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
  975. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["LOADVEHICLE_NO"].ToString2();
  976. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["RECEIV_NM"].ToString2();
  977. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(dt.Rows[0]["STACKING_PIECE"].ToString3());
  978. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["BASENAME"].ToString2();
  979. cmmWeightRecordEntityFull.OrderName = dt.Rows[0]["CUSTOMER_NM"].ToString2();
  980. cmmWeightRecordEntityFull.MatName = "钢管";
  981. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  982. var dtc = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleMatInfo",
  983. new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
  984. if ((dtc != null) && (dtc.Rows.Count > 0))
  985. foreach (DataRow dtcRow in dtc.Rows)
  986. {
  987. var cmmWeightMatEntity = new CmmWeightMatEntity
  988. {
  989. StorageNo = dtcRow["STORAGE_NO"].ToString2(),
  990. StorageName = dtcRow["STORAGE_NAME"].ToString2(),
  991. StoveNo = dtcRow["STOVE_NO"].ToString2(),
  992. OrderNo = dtcRow["ORDER_NO"].ToString2(),
  993. OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
  994. OrderSeqNo = dtcRow["ORDER_SEQ_NO"].ToString2(),
  995. ProOrderNo = dtcRow["ORDER_NO"].ToString2() + "/" +
  996. dtcRow["ORDER_SEQ"].ToString2(),
  997. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  998. Producname = dtcRow["PRODUCNAME"].ToString2(),
  999. StdCode = dtcRow["STD_CODE"].ToString2(),
  1000. StdName = dtcRow["STD_NAME"].ToString2(),
  1001. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1002. Gradename = dtcRow["GRADENAME"].ToString2(),
  1003. Steelcode = dtcRow["STEELCODE"].ToString2(),
  1004. Steelname = dtcRow["STEELNAME"].ToString2(),
  1005. SpecCode = dtcRow["SPEC_CODE"].ToString2(),
  1006. SpecName = dtcRow["SPEC_NAME"].ToString2(),
  1007. ModelCode = dtcRow["MODEL_CODE"].ToString2(),
  1008. ModelDesc = dtcRow["MODEL_DESC"].ToString2(),
  1009. ActLenMin = decimal.Parse(dtcRow["ACT_LEN_MIN"].ToString3()),
  1010. ActLenMax = decimal.Parse(dtcRow["ACT_LEN_MAX"].ToString3()),
  1011. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
  1012. dtcRow["ACT_LEN_MAX"].ToString3(),
  1013. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1014. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1015. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  1016. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  1017. };
  1018. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1019. }
  1020. try
  1021. {
  1022. var dth = ServerHelper.GetData("com.steering.Mcms.LoadVehicleServer.doQueryHook",
  1023. new object[] {cmmWeightRecordEntityFull.LoadvehicleNo}, ob);
  1024. if ((dth != null) && (dth.Rows.Count > 0))
  1025. foreach (DataRow dthRow in dth.Rows)
  1026. {
  1027. var total = double.Parse(dthRow["HOOK_WEIGHT"].ToString3());
  1028. double num = int.Parse(cmmWeightRecordEntityFull.MatInfos.Where(
  1029. p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
  1030. .Select(p => p.ActCount)
  1031. .Sum()
  1032. .ToString3());
  1033. var perWt = Math.Round(total/num, 3);
  1034. var list = cmmWeightRecordEntityFull.MatInfos.Where(
  1035. p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2()).ToList();
  1036. for (var i = 0; i < list.Count; i++)
  1037. if (i == 0)
  1038. list[i].ActWeight =
  1039. decimal.Parse(
  1040. (total - perWt*(num - double.Parse(list[i].ActCount.ToString3()))).ToString3
  1041. ());
  1042. else
  1043. list[i].ActWeight =
  1044. decimal.Parse(
  1045. (perWt*double.Parse(list[i].ActCount.ToString3())).ToString3());
  1046. }
  1047. }
  1048. catch (Exception)
  1049. {
  1050. }
  1051. }
  1052. else
  1053. {
  1054. cmmWeightRecordEntityFull = null;
  1055. }
  1056. matInfo16.SetDefault(cmmWeightRecordEntityFull);
  1057. }
  1058. public void ShowOutInfo(string carNo, decimal nutWt)
  1059. {
  1060. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1061. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfo", new object[] {carNo}, ob);
  1062. if ((dt != null) && (dt.Rows.Count > 0) && ((dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司") || ((dt.Rows[0]["STORAGE_NAME_TO"].ToString2() == "天淮室外成品库" || dt.Rows[0]["STORAGE_NAME_TO"].ToString2() == "天淮室内成品库") && dt.Rows[0]["OUTSTOCK_PLAN_NO"].ToString2() == "1"))) // 调整 只有去天津和天淮室外成品库 才带出出库记录 2021.3.15
  1063. {
  1064. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司" ? "江苏天淮钢管有限公司" : dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
  1065. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  1066. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
  1067. cmmWeightRecordEntityFull.OrderName = dt.Rows[0]["STORAGE_NAME_D"].ToString2();
  1068. cmmWeightRecordEntityFull.RecordNumber =
  1069. dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
  1070. decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  1071. cmmWeightRecordEntityFull.MatName = dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"
  1072. ? "调拨钢管"
  1073. : "内转钢管";
  1074. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1075. var totalWt = dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_WEIGHT"].ToString3())).Sum();
  1076. var perWt = nutWt/totalWt;
  1077. var remainWt = nutWt;
  1078. for (var i = 0; i < dt.Rows.Count; i++)
  1079. {
  1080. var dtcRow = dt.Rows[i];
  1081. var cmmWeightMatEntity = new CmmWeightMatEntity
  1082. {
  1083. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  1084. Producname = dtcRow["PRODUCNAME"].ToString2(),
  1085. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1086. Gradename = dtcRow["GRADENAME"].ToString2(),
  1087. Steelcode = dtcRow["STEELCODE"].ToString2(),
  1088. Steelname = dtcRow["STEELNAME"].ToString2(),
  1089. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
  1090. dtcRow["ACT_LEN_MAX"].ToString3(),
  1091. ActWeight = i == dt.Rows.Count - 1 ? remainWt : Math.Round(decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3())*perWt, 3),
  1092. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1093. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1094. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  1095. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  1096. };
  1097. l.WriteLog(3, "车号:" + carNo + " nutWt:" + nutWt + " remainWt:" + remainWt + " totalWt:" + totalWt + "perWt:"+ perWt);
  1098. remainWt = remainWt - (decimal) cmmWeightMatEntity.ActWeight;
  1099. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1100. }
  1101. matInfo12.SetDefault(cmmWeightRecordEntityFull);
  1102. }
  1103. else
  1104. {
  1105. if (nutWt > 0)
  1106. matInfo12.SetWt(nutWt);
  1107. }
  1108. }
  1109. public void ShowOutInfoGp(string carNo, decimal nutWt)
  1110. {
  1111. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1112. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", new object[] {carNo}, ob);
  1113. if ((dt != null) && (dt.Rows.Count > 0))
  1114. {
  1115. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
  1116. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  1117. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
  1118. cmmWeightRecordEntityFull.RecordNumber =
  1119. dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
  1120. decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  1121. cmmWeightRecordEntityFull.MatName = "内转钢坯";
  1122. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1123. var perWt = Math.Round(nutWt/(decimal) cmmWeightRecordEntityFull.RecordNumber, 3);
  1124. var remainWt = nutWt;
  1125. for (var i = 0; i < dt.Rows.Count; i++)
  1126. {
  1127. var dtcRow = dt.Rows[i];
  1128. var cmmWeightMatEntity = new CmmWeightMatEntity
  1129. {
  1130. Steelcode = dtcRow["GRADECODE"].ToString2(),
  1131. Steelname = dtcRow["GRADENAME"].ToString2(),
  1132. ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
  1133. ActWeight =
  1134. i == dt.Rows.Count - 1 ? remainWt : decimal.Parse(dtcRow["ACT_COUNT"].ToString3())*perWt,
  1135. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1136. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1137. ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
  1138. ActHeight = decimal.Parse(dtcRow["HEIGHT"].ToString3())
  1139. };
  1140. remainWt = remainWt - perWt;
  1141. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1142. }
  1143. matInfo13.SetDefault(cmmWeightRecordEntityFull);
  1144. }
  1145. else
  1146. {
  1147. if (nutWt > 0)
  1148. matInfo13.SetWt(nutWt);
  1149. }
  1150. }
  1151. private void tbScondWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  1152. {
  1153. if (CurrentGrid.ActiveRow != null)
  1154. {
  1155. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1156. if (current != null)
  1157. if (tbScondWt.ActiveTab.Key == "3")
  1158. ShowWasteInfo(current.CarNo);
  1159. else if (tbScondWt.ActiveTab.Key == "0")
  1160. ShowLoadvehicleInfo(current.CarNo);
  1161. }
  1162. LoadTem();
  1163. }
  1164. private void utnQuery_Click(object sender, EventArgs e)
  1165. {
  1166. Query2();
  1167. }
  1168. private void Query2()
  1169. {
  1170. var dic = new Dictionary<string, object>();
  1171. if (chkTim.Checked)
  1172. {
  1173. dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  1174. dic.Add("time1", RegEndTime.Value.ToString("yyy-MM-dd HH:mm:ss"));
  1175. }
  1176. dic.Add("carNo", uteCarNo.Text);
  1177. dic.Add("matType", uceQueryCarType.Text);
  1178. dic.Add("resultNo", utePound.Text);
  1179. dic.Add("orderName", uteOrder.Text);
  1180. dic.Add("shippersName", uteShippersName.Text);
  1181. dic.Add("receiveName", uteReceiveName.Text);
  1182. dic.Add("memo", uteMemo.Text);
  1183. dic.Add("validflag", new List<string> {"1"});
  1184. dic.Add("judgeStoveNo", uteJudgeStoveNo.Text);
  1185. List<CmmWeightResultEntity> list = EntityHelper.GetData<CmmWeightResultEntity>(
  1186. "com.steering.Mcms.ResultServer.doQuery",
  1187. new object[] {dic},
  1188. ob);
  1189. lblCount.Text = string.Format("共{0}条记录", list.Count);
  1190. QueryBS.DataSource = list;
  1191. Comm.RefreshAndAutoSize(ugData);
  1192. }
  1193. private void tbMain_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  1194. {
  1195. if (tbMain.SelectedTab.Key == "1")
  1196. Query();
  1197. else
  1198. Query2();
  1199. }
  1200. private void utbReset_Click(object sender, EventArgs e)
  1201. {
  1202. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  1203. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  1204. uteCarNo.Text = "";
  1205. uceQueryCarType.Text = "";
  1206. utePound.Text = "";
  1207. uteOrder.Text = "";
  1208. uteShippersName.Text = "";
  1209. uteReceiveName.Text = "";
  1210. uteMemo.Text = "";
  1211. uteJudgeStoveNo.Text = "";
  1212. }
  1213. private void btnDelete_Click(object sender, EventArgs e)
  1214. {
  1215. if (ugData.ActiveRow == null) return;
  1216. var ub = sender as UltraButton;
  1217. if (ub == null) return;
  1218. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1219. if (data == null) return;
  1220. ("是否" + ub.Text + " 车辆 " + data.CarNo + " 的过磅单?").Speak();
  1221. if (MessageUtil.ShowYesNoAndQuestion("是否" + ub.Text + " 车牌[" + data.CarNo + "]过磅单?") == DialogResult.No)
  1222. return;
  1223. var ccp = new CoreClientParam
  1224. {
  1225. ServerName = "com.steering.Mcms.LocalTruckScale",
  1226. MethodName = "DoDeleteResult",
  1227. ServerParams = new object[]
  1228. {
  1229. data.ResultNo,
  1230. UserInfo.GetUserName(),
  1231. "重过" == ub.Text ? "2" : "1"
  1232. }
  1233. };
  1234. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1235. if (ccp.ReturnCode != -1)
  1236. {
  1237. MessageUtil.ShowTips(ccp.ReturnInfo);
  1238. if (ccp.ReturnInfo.Equals("操作成功!"))
  1239. {
  1240. Query2();
  1241. Query();
  1242. }
  1243. }
  1244. }
  1245. private void cboNo_SelectedValueChanged(object sender, EventArgs e)
  1246. {
  1247. lblWtNow.Text = "0.00t";
  1248. if (cboNo.SelectedIndex < 0) return;
  1249. cmmPoundBase = cboNo.SelectedItem as CmmPoundBaseEntity;
  1250. if (communication != null)
  1251. {
  1252. if (communication.Status) utbConnect_Click(null, null);
  1253. communication.ReceiveData -= defultPortEntity_ReceiveData;
  1254. }
  1255. communication = null;
  1256. if (cboNo.SelectedIndex < 0) return;
  1257. var list = CommunicationEntitys.Where(p => p.PoundNo == cmmPoundBase.PoundNo).ToList();
  1258. if (list.Any())
  1259. communication = list[0].Communication;
  1260. if (communication == null) communication = defultPortEntity;
  1261. communication.ReceiveData += defultPortEntity_ReceiveData;
  1262. CmmBaseProtocolEntity cmmBaseProtocol = null;
  1263. if (cmmPoundBase != null)
  1264. {
  1265. List<CmmBaseProtocolCEntity> protocols = EntityHelper.GetData<CmmBaseProtocolCEntity>(
  1266. "com.steering.Mcms.ProcotolServer.getProcotolId",
  1267. new object[] {cmmPoundBase.PoundProtocolId},
  1268. ob);
  1269. if ((protocols != null) && protocols.Any())
  1270. cmmBaseProtocol = new CmmBaseProtocolEntity
  1271. {
  1272. ProtocolId = cmmPoundBase.PoundProtocolId,
  1273. ListC = protocols
  1274. };
  1275. cboPoundList.Text = cmmPoundBase.PoundNo;
  1276. }
  1277. communication.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol));
  1278. utbConnect_Click(null, null);
  1279. }
  1280. private void btnSetting_Click(object sender, EventArgs e)
  1281. {
  1282. if (communication != null)
  1283. {
  1284. if (communication.Status) utbConnect_Click(null, null);
  1285. communication.ReceiveData -= defultPortEntity_ReceiveData;
  1286. }
  1287. using (var communicationSetting = new CommunicationSetting(CommunicationEntitys))
  1288. {
  1289. if (communicationSetting.ShowDialog() == DialogResult.OK)
  1290. {
  1291. CommunicationEntitys = communicationSetting.Entitys;
  1292. var xElementRoot = new XElement("CommunicationInfo");
  1293. foreach (var communicationEntity in CommunicationEntitys)
  1294. {
  1295. var temp = new XElement("POUND_" + communicationEntity.PoundNo);
  1296. var type = communicationEntity.Communication is SerialPortEntity ? "1" : "2";
  1297. temp.SetAttributeValue("type", type);
  1298. if (type == "1")
  1299. {
  1300. temp.SetAttributeValue("StrBaudRate",
  1301. ((SerialPortEntity) communicationEntity.Communication).StrBaudRate);
  1302. temp.SetAttributeValue("StrDataBits",
  1303. ((SerialPortEntity) communicationEntity.Communication).StrDataBits);
  1304. temp.SetAttributeValue("StrParity",
  1305. ((SerialPortEntity) communicationEntity.Communication).StrParity);
  1306. temp.SetAttributeValue("StrStopBits",
  1307. ((SerialPortEntity) communicationEntity.Communication).StrStopBits);
  1308. temp.SetAttributeValue("PortName",
  1309. ((SerialPortEntity) communicationEntity.Communication).PortName);
  1310. }
  1311. else
  1312. {
  1313. temp.SetAttributeValue("Ip",
  1314. ((SocketClient) communicationEntity.Communication).Ip);
  1315. temp.SetAttributeValue("Port",
  1316. ((SocketClient) communicationEntity.Communication).Port);
  1317. }
  1318. xElementRoot.Add(temp);
  1319. }
  1320. XmlHelper.SetXElement(_path, xElementRoot,true);
  1321. }
  1322. }
  1323. communication = null;
  1324. cboNo_SelectedValueChanged(null, null);
  1325. }
  1326. private void lvTemplate_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
  1327. {
  1328. var matInfo = GetMatInfo();
  1329. if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(e.Item.Tag as CmmWeightRecordEntityFull, e.Item.Text);
  1330. }
  1331. private void cboPoundList_SelectedValueChanged(object sender, EventArgs e)
  1332. {
  1333. Query();
  1334. }
  1335. private void delete_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1336. {
  1337. if (cmmPoundBase == null)
  1338. {
  1339. MessageBox.Show(@"无磅房权限");
  1340. return;
  1341. }
  1342. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1343. if ((current == null) || ("" == current.CarNo)) return;
  1344. if (MessageUtil.ShowYesNoAndQuestion("是否删除" + current.CarNo + " 过磅记录?") == DialogResult.No)
  1345. return;
  1346. var ccp = new CoreClientParam
  1347. {
  1348. ServerName = "com.steering.Mcms.RecordServer",
  1349. MethodName = "DoUpdateRecord",
  1350. ServerParams = new object[]
  1351. {
  1352. current.RecordNo
  1353. }
  1354. };
  1355. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1356. if (ccp.ReturnCode != -1)
  1357. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  1358. Query();
  1359. else
  1360. MessageUtil.ShowTips(ccp.ReturnInfo);
  1361. }
  1362. private void ugData_InitializeRow(object sender, InitializeRowEventArgs e)
  1363. {
  1364. var data = e.Row.ListObject as CmmWeightResultEntity;
  1365. if (data == null) return;
  1366. if (data.RecordType2 == "201") e.Row.Appearance.BackColor = Color.ForestGreen;
  1367. }
  1368. private void uteCarNo_KeyPress(object sender, KeyPressEventArgs e)
  1369. {
  1370. if (e.KeyChar == 13)
  1371. Query2();
  1372. }
  1373. private void utnUpdate_Click(object sender, EventArgs e)
  1374. {
  1375. if (ugData.ActiveRow == null)
  1376. {
  1377. MessageBox.Show("请选择需要修改磅单记录!");
  1378. return;
  1379. }
  1380. var cmm = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1381. var matInfo = GetMatInfoByKey("101" == cmm.RecordType1 ? cmm.RecordType2 : cmm.RecordType1);
  1382. if (matInfo == null)
  1383. {
  1384. MessageBox.Show("该类型不允许修改!");
  1385. return;
  1386. }
  1387. using (var frmUpdate = new FrmUpdate(ob, cmm, "101" == cmm.RecordType1
  1388. ? cmm.RecordNo2
  1389. : cmm.RecordNo1, canUpdateWt)
  1390. {
  1391. ColumnsM = matInfo.ColumnsM,
  1392. ColumnsC = matInfo.ColumnsC
  1393. })
  1394. {
  1395. frmUpdate.ShowDialog();
  1396. if (frmUpdate.DialogResult == DialogResult.OK)
  1397. Query2();
  1398. }
  1399. }
  1400. private void utbPrint_Click(object sender, EventArgs e)
  1401. {
  1402. if (ugData.ActiveRow == null) return;
  1403. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1404. if (data == null) return;
  1405. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  1406. DialogResult.No))
  1407. {
  1408. }
  1409. else
  1410. {
  1411. Print(data.ResultNo);
  1412. }
  1413. }
  1414. private void utbPrintSingle_Click(object sender, EventArgs e)
  1415. {
  1416. if (ugData.ActiveRow == null) return;
  1417. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1418. if (data == null) return;
  1419. if ((data.RecordType2 == "205") || (data.RecordType2 == "201") || (data.RecordType2 == "200"))
  1420. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  1421. DialogResult.No))
  1422. {
  1423. }
  1424. else
  1425. {
  1426. Print(data.ResultNo, true);
  1427. }
  1428. }
  1429. private void unExcel_Click(object sender, EventArgs e)
  1430. {
  1431. var hssfworkbook = new HSSFWorkbook();
  1432. var sheet = hssfworkbook.CreateSheet("磅房统计");
  1433. var index = 0;
  1434. SetHead(sheet, hssfworkbook, index++);
  1435. SetHeadRow(sheet, hssfworkbook
  1436. , new List<string> {"磅房号", "称重类型", "物资名称", "物资数量", "称重次数", "物资净重"},
  1437. new List<int> {9, 15, 25, 15, 15, 15},
  1438. index++
  1439. );
  1440. setData(sheet, hssfworkbook, ref index);
  1441. SetSumm(sheet, index, hssfworkbook);
  1442. sheet.ForceFormulaRecalculation = true;
  1443. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
  1444. using (var saveFileDialog1 = new SaveFileDialog())
  1445. {
  1446. saveFileDialog1.FileName = "磅房统计" + DateTime.Now.ToString("yyMMdd");
  1447. saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
  1448. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  1449. {
  1450. var sFullName = saveFileDialog1.FileName;
  1451. var ms = new MemoryStream();
  1452. hssfworkbook.Write(ms);
  1453. using (var fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
  1454. {
  1455. var bArr = ms.ToArray();
  1456. fs.Write(bArr, 0, bArr.Length);
  1457. fs.Flush();
  1458. }
  1459. var p = new ProcessStartInfo(sFullName);
  1460. p.WorkingDirectory = Path.GetDirectoryName(sFullName);
  1461. Process.Start(p);
  1462. }
  1463. }
  1464. }
  1465. private void SetSumm(ISheet sheet, int index, HSSFWorkbook hssfworkbook)
  1466. {
  1467. var IRow = sheet.CreateRow(index);
  1468. IRow.Height = 20*20;
  1469. var Icell1 = IRow.CreateCell(1);
  1470. Icell1.SetCellValue("合计");
  1471. var style = CenterStyle(hssfworkbook);
  1472. var font = ContextFont(hssfworkbook);
  1473. style.SetFont(font);
  1474. style.BorderTop = BorderStyle.Medium;
  1475. style.BorderBottom = BorderStyle.Medium;
  1476. style.BorderLeft = BorderStyle.Medium;
  1477. style.BorderRight = BorderStyle.Thin;
  1478. //将新的样式赋给单元格
  1479. Icell1.CellStyle = style;
  1480. var Icell12 = IRow.CreateCell(2);
  1481. var style12 = CenterStyle(hssfworkbook);
  1482. style12.SetFont(font);
  1483. style12.BorderTop = BorderStyle.Medium;
  1484. style12.BorderBottom = BorderStyle.Medium;
  1485. style12.BorderLeft = BorderStyle.Thin;
  1486. style12.BorderRight = BorderStyle.Thin;
  1487. //将新的样式赋给单元格
  1488. Icell12.CellStyle = style12;
  1489. var Icell13 = IRow.CreateCell(3);
  1490. var style13 = CenterStyle(hssfworkbook);
  1491. style13.SetFont(font);
  1492. style13.BorderTop = BorderStyle.Medium;
  1493. style13.BorderBottom = BorderStyle.Medium;
  1494. style13.BorderLeft = BorderStyle.Thin;
  1495. style13.BorderRight = BorderStyle.Thin;
  1496. //将新的样式赋给单元格
  1497. Icell13.CellStyle = style13;
  1498. //合并单元格
  1499. sheet.AddMergedRegion(new CellRangeAddress(index, index, 1, 3));
  1500. var list = new List<string>();
  1501. for (var i = 2; i < index; i++)
  1502. list.Add(i + 1 + "");
  1503. var Icell2 = IRow.CreateCell(4);
  1504. if (list.Any())
  1505. {
  1506. Icell2.SetCellType(CellType.Formula);
  1507. Icell2.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "E" + p).ToList())));
  1508. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell2);
  1509. }
  1510. var style2 = numStyle(hssfworkbook);
  1511. var font2 = ContextFont(hssfworkbook);
  1512. style2.SetFont(font2);
  1513. style2.BorderTop = BorderStyle.Medium;
  1514. style2.BorderBottom = BorderStyle.Medium;
  1515. style2.BorderLeft = BorderStyle.Thin;
  1516. style2.BorderRight = BorderStyle.Thin;
  1517. //将新的样式赋给单元格
  1518. Icell2.CellStyle = style2;
  1519. var Icell3 = IRow.CreateCell(5);
  1520. if (list.Any())
  1521. {
  1522. Icell3.SetCellType(CellType.Formula);
  1523. Icell3.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "F" + p).ToList())));
  1524. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell3);
  1525. }
  1526. var style3 = numStyle(hssfworkbook);
  1527. var font3 = ContextFont(hssfworkbook);
  1528. style3.SetFont(font3);
  1529. style3.BorderTop = BorderStyle.Medium;
  1530. style3.BorderBottom = BorderStyle.Medium;
  1531. style3.BorderLeft = BorderStyle.Thin;
  1532. style3.BorderRight = BorderStyle.Thin;
  1533. //将新的样式赋给单元格
  1534. Icell3.CellStyle = style3;
  1535. var Icell4 = IRow.CreateCell(6);
  1536. if (list.Any())
  1537. {
  1538. Icell4.SetCellType(CellType.Formula);
  1539. Icell4.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "G" + p).ToList())));
  1540. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell4);
  1541. }
  1542. var style4 = numStyle(hssfworkbook);
  1543. var font4 = ContextFont(hssfworkbook);
  1544. style4.SetFont(font4);
  1545. style4.BorderTop = BorderStyle.Medium;
  1546. style4.BorderBottom = BorderStyle.Medium;
  1547. style4.BorderLeft = BorderStyle.Thin;
  1548. style4.BorderRight = BorderStyle.Medium;
  1549. //将新的样式赋给单元格
  1550. Icell4.CellStyle = style4;
  1551. }
  1552. private void setData(ISheet sheet, HSSFWorkbook hssfworkbook, ref int index)
  1553. {
  1554. var index1 = index;
  1555. var data = QueryBS.DataSource as List<CmmWeightResultEntity>;
  1556. if ((data != null) && data.Any())
  1557. data.GroupBy(p => new {p.RecoderLocation2, p.MatName, p.MatType})
  1558. .Select(p => new
  1559. {
  1560. p.Key.MatName,
  1561. p.Key.MatType,
  1562. p.Key.RecoderLocation2,
  1563. count = p.Count(),
  1564. num = int.Parse(p.Select(q => q.MatNum ?? 0).Sum().ToString3()),
  1565. wt = double.Parse(p.Select(q => q.NetWt).Sum().ToString3())
  1566. }).ToList()
  1567. .ForEach(
  1568. p =>
  1569. {
  1570. var IRow = sheet.CreateRow(index1++);
  1571. IRow.Height = 20*20;
  1572. for (var i = 0; i < 6; i++)
  1573. {
  1574. var Icell = IRow.CreateCell(i + 1);
  1575. if (i <= 2)
  1576. {
  1577. Icell.SetCellType(CellType.String);
  1578. Icell.SetCellValue(
  1579. i == 0
  1580. ? p.RecoderLocation2
  1581. : i == 1
  1582. ? p.MatType
  1583. : p.MatName);
  1584. }
  1585. else
  1586. {
  1587. Icell.SetCellType(CellType.Numeric);
  1588. if (i == 3)
  1589. Icell.SetCellValue(p.num);
  1590. if (i == 4)
  1591. Icell.SetCellValue(p.count);
  1592. if (i == 5)
  1593. Icell.SetCellValue(p.wt);
  1594. }
  1595. ;
  1596. var style = i <= 2 ? textStyle(hssfworkbook) : numStyle(hssfworkbook);
  1597. style.BorderTop = BorderStyle.Thin;
  1598. style.BorderBottom = BorderStyle.Thin;
  1599. style.BorderLeft = i == 0 ? BorderStyle.Medium : BorderStyle.Thin;
  1600. style.BorderRight = i == 5 ? BorderStyle.Medium : BorderStyle.Thin;
  1601. var font = ContextFont(hssfworkbook);
  1602. //使用SetFont方法将字体样式添加到单元格样式中
  1603. style.SetFont(font);
  1604. //将新的样式赋给单元格
  1605. Icell.CellStyle = style;
  1606. }
  1607. }
  1608. );
  1609. index = index1;
  1610. }
  1611. private void SetHeadRow(ISheet sheet, HSSFWorkbook hssfworkbook, List<string> name, List<int> columsWidth,
  1612. int rowIndex)
  1613. {
  1614. var IRow = sheet.CreateRow(rowIndex);
  1615. IRow.Height = 20*20;
  1616. for (var i = 0; i < name.Count; i++)
  1617. {
  1618. sheet.SetColumnWidth(i + 1, columsWidth[i]*256);
  1619. var Icell = IRow.CreateCell(i + 1);
  1620. Icell.SetCellValue(name[i]);
  1621. var style = CenterStyle(hssfworkbook);
  1622. style.BorderTop = BorderStyle.Medium;
  1623. style.BorderBottom = BorderStyle.Medium;
  1624. style.BorderLeft = BorderStyle.Medium;
  1625. style.BorderRight = BorderStyle.Medium;
  1626. var font = ContextFont(hssfworkbook);
  1627. //使用SetFont方法将字体样式添加到单元格样式中
  1628. style.SetFont(font);
  1629. //将新的样式赋给单元格
  1630. Icell.CellStyle = style;
  1631. }
  1632. }
  1633. private void SetHead(ISheet sheet, HSSFWorkbook hssfworkbook, int rowindex)
  1634. {
  1635. var IRow = sheet.CreateRow(rowindex);
  1636. IRow.Height = 50*20;
  1637. var Icell = IRow.CreateCell(1);
  1638. Icell.SetCellValue("磅房统计");
  1639. var style = CenterStyle(hssfworkbook);
  1640. var font = TitleFont(hssfworkbook);
  1641. //使用SetFont方法将字体样式添加到单元格样式中
  1642. style.SetFont(font);
  1643. //将新的样式赋给单元格
  1644. Icell.CellStyle = style;
  1645. //合并单元格
  1646. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 1, 6));
  1647. }
  1648. private static IFont TitleFont(HSSFWorkbook hssfworkbook)
  1649. {
  1650. //新建一个字体样式对象
  1651. var font = hssfworkbook.CreateFont();
  1652. font.FontName = "宋体";
  1653. font.FontHeightInPoints = 30;
  1654. //设置字体加粗样式
  1655. font.Boldweight = (short) FontBoldWeight.Bold;
  1656. return font;
  1657. }
  1658. private static IFont ContextFont(HSSFWorkbook hssfworkbook)
  1659. {
  1660. //新建一个字体样式对象
  1661. var font = hssfworkbook.CreateFont();
  1662. font.FontName = "宋体";
  1663. font.FontHeightInPoints = 12;
  1664. //设置字体加粗样式
  1665. font.Boldweight = (short) FontBoldWeight.Bold;
  1666. return font;
  1667. }
  1668. private ICellStyle CenterStyle(HSSFWorkbook hssfworkbook)
  1669. {
  1670. var style = hssfworkbook.CreateCellStyle();
  1671. //设置单元格的样式:水平对齐居中
  1672. style.Alignment = HorizontalAlignment.Center;
  1673. style.VerticalAlignment = VerticalAlignment.Center;
  1674. return style;
  1675. }
  1676. private ICellStyle textStyle(HSSFWorkbook hssfworkbook)
  1677. {
  1678. var style = hssfworkbook.CreateCellStyle();
  1679. //设置单元格的样式:水平对齐居中
  1680. style.Alignment = HorizontalAlignment.Left;
  1681. style.VerticalAlignment = VerticalAlignment.Center;
  1682. return style;
  1683. }
  1684. private ICellStyle numStyle(HSSFWorkbook hssfworkbook)
  1685. {
  1686. var style = hssfworkbook.CreateCellStyle();
  1687. //设置单元格的样式:水平对齐居中
  1688. style.Alignment = HorizontalAlignment.Right;
  1689. style.VerticalAlignment = VerticalAlignment.Center;
  1690. return style;
  1691. }
  1692. private void CurrentGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  1693. {
  1694. }
  1695. private void CurrentGrid_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
  1696. {
  1697. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1698. if ((current == null) || ("" == current.CarNo)) return;
  1699. foreach (var cbxCar1Item in cbxCar1.Items)
  1700. if (current.CarNo.StartsWith(cbxCar1Item.ToString2().Trim()))
  1701. {
  1702. cbxCar1.SelectedItem = cbxCar1Item;
  1703. txtCar2.Text = current.CarNo.Replace(cbxCar1Item.ToString2().Trim(), "").Trim();
  1704. }
  1705. if (!tbWt.Tabs["2"].Selected)
  1706. {
  1707. tbWt.Tabs["2"].Selected = true;
  1708. if (current.RecordType != "101")
  1709. tbScondWt.Tabs["2"].Selected = true;
  1710. else
  1711. tbScondWt_SelectedTabChanged(null, null);
  1712. }
  1713. }
  1714. private void utbExport_Click(object sender, EventArgs e)
  1715. {
  1716. GridHelper.ulGridToExcel(ugData, "称重记录");
  1717. }
  1718. private void utbExport2_Click(object sender, EventArgs e)
  1719. {
  1720. GridHelper.ulGridToExcel(CurrentGrid, "称重记录");
  1721. }
  1722. private void cbxCar1_SelectedValueChanged(object sender, EventArgs e)
  1723. {
  1724. txtCar2.Focus();
  1725. if (cbxCar1.Text.Trim() == "厂内")
  1726. txtCar2.Text = "自用车";
  1727. }
  1728. private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
  1729. {
  1730. if (isLoading) return;
  1731. XmlHelper.SetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
  1732. }
  1733. private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
  1734. {
  1735. if (isLoading) return;
  1736. XmlHelper.SetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
  1737. }
  1738. private void frmLocalTruckScale_Shown(object sender, EventArgs e)
  1739. {
  1740. timer.Start();
  1741. splitContainer1.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer1",
  1742. splitContainer1.SplitterDistance);
  1743. splitContainer2.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer2",
  1744. splitContainer2.SplitterDistance);
  1745. var x = new FontConverter();
  1746. CurrentGrid.Font =
  1747. x.ConvertFromString(XmlHelper.GetXmlData(_path, CurrentGrid.Name, x.ConvertToString(CurrentGrid.Font)))
  1748. as Font;
  1749. ugData.Font =
  1750. x.ConvertFromString(XmlHelper.GetXmlData(_path, ugData.Name, x.ConvertToString(ugData.Font))) as Font;
  1751. isLoading = false;
  1752. CurrentGrid.DisplayLayout.Bands[0].Columns["RecordType"].EditorComponent = uceType2;
  1753. CurrentGrid.DisplayLayout.Bands[0].Columns["RecordNo"].EditorComponent = delete;
  1754. CurrentGrid.DisplayLayout.Bands[0].Columns["CarNo"].EditorComponent = uteEdit;
  1755. Query();
  1756. Query2();
  1757. try
  1758. {
  1759. if (toolMenu == null) return;
  1760. if (toolMenu.Toolbars[0].Tools.Exists("UpdateWt"))
  1761. canUpdateWt = true;
  1762. toolMenu.Visible = false;
  1763. }
  1764. catch (Exception ex)
  1765. {
  1766. }
  1767. }
  1768. private void CurrentGrid_KeyPress(object sender, KeyPressEventArgs e)
  1769. {
  1770. }
  1771. private void CurrentGrid_KeyDown(object sender, KeyEventArgs e)
  1772. {
  1773. if (e.KeyCode == Keys.F5)
  1774. using (var dr = new FontDialog {Font = (sender as Control).Font})
  1775. {
  1776. if (dr.ShowDialog() == DialogResult.OK)
  1777. {
  1778. (sender as Control).Font = dr.Font;
  1779. var x = new FontConverter();
  1780. var font = x.ConvertToString(dr.Font);
  1781. // t = x.ConvertFromString(s) as Font;
  1782. XmlHelper.SetXmlData(_path, (sender as Control).Name, font);
  1783. }
  1784. }
  1785. }
  1786. private void txtCar2_TextChanged(object sender, EventArgs e)
  1787. {
  1788. foreach (var currentGridRow in CurrentGrid.Rows)
  1789. if (currentGridRow.Cells["CarNo"].Value.ToString2() == cbxCar1.Text + txtCar2.Text.Trim())
  1790. if (!tbWt.Tabs["2"].Selected)
  1791. {
  1792. tbWt.Tabs["2"].Selected = true;
  1793. currentGridRow.Activated = true;
  1794. if (currentGridRow.Cells["RecordType"].Value.ToString2() != "101")
  1795. tbScondWt.Tabs["2"].Selected = true;
  1796. else
  1797. tbScondWt_SelectedTabChanged(null, null);
  1798. return;
  1799. }
  1800. tbWt.Tabs["1"].Selected = true;
  1801. }
  1802. private void uteEdit_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1803. {
  1804. if (cmmPoundBase == null)
  1805. {
  1806. MessageBox.Show(@"无磅房权限");
  1807. return;
  1808. }
  1809. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1810. string carNo;
  1811. using (var update = new UpdateCar {CarNo = current.CarNo})
  1812. {
  1813. var result = update.ShowDialog();
  1814. if (result != DialogResult.OK) return;
  1815. carNo = update.CarNo;
  1816. }
  1817. var ccp = new CoreClientParam
  1818. {
  1819. ServerName = "com.steering.Mcms.RecordServer",
  1820. MethodName = "DoUpdateCarNo",
  1821. ServerParams = new object[]
  1822. {
  1823. current.RecordNo,
  1824. carNo
  1825. }
  1826. };
  1827. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1828. if (ccp.ReturnCode != -1)
  1829. {
  1830. MessageUtil.ShowTips(ccp.ReturnInfo);
  1831. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  1832. Query();
  1833. }
  1834. }
  1835. public bool CheckShowKey(string key1, string key2)
  1836. {
  1837. if (key1 == key2) return true;
  1838. if (((key1 == "107") && (key2 == "204")) || ((key2 == "107") && (key1 == "204"))) return true;
  1839. if (((key1 == "108") && (key2 == "205")) || ((key2 == "108") && (key1 == "205"))) return true;
  1840. if (((key1 == "206") && (key2 == "206")) || ((key2 == "109") && (key1 == "206"))) return true;
  1841. return false;
  1842. }
  1843. private void txtCar2_KeyPress(object sender, KeyPressEventArgs e)
  1844. {
  1845. if ((e.KeyChar >= 97) && (e.KeyChar <= 122))
  1846. e.KeyChar = (char) (e.KeyChar - 32);
  1847. }
  1848. private void CurrentGrid_InitializeRow(object sender, InitializeRowEventArgs e)
  1849. {
  1850. var cmmWeightRecord = e.Row.ListObject as CmmWeightRecordEntity;
  1851. if (cmmWeightRecord == null) return;
  1852. if ((cmmWeightRecord.EffRemaind != null) && (cmmWeightRecord.EffRemaind <= 1))
  1853. e.Row.Cells["RecordDate"].Appearance.BackColor = Color.Red;
  1854. }
  1855. private void utbSelect_Click(object sender, EventArgs e)
  1856. {
  1857. using (var BlankPredictionSelect = new BlankPredictionSelect(ob, matInfo3.GetData()))
  1858. {
  1859. if (BlankPredictionSelect.ShowDialog() == DialogResult.OK)
  1860. matInfo3.UpdateData(new CmmWeightRecordEntityFull
  1861. {
  1862. MatName = "连铸圆坯",
  1863. ShippersName = BlankPredictionSelect.ShipperName,
  1864. RecordNumber = BlankPredictionSelect.ListMatNo == null ? null : BlankPredictionSelect.ListMatNo.Sum(p => p.ActCount),
  1865. ReceiveName = "江苏天淮钢管有限公司",
  1866. Memo = BlankPredictionSelect.Memo,
  1867. MatInfos =
  1868. BlankPredictionSelect.ListMatNo ?? new List<CmmWeightMatEntity> {new CmmWeightMatEntity()}
  1869. });
  1870. }
  1871. }
  1872. private void uteChangeType_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1873. {
  1874. if (cmmPoundBase == null)
  1875. {
  1876. MessageBox.Show(@"无磅房权限");
  1877. return;
  1878. }
  1879. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1880. string type;
  1881. string name;
  1882. using (var changeType = new ChangeType {Type = current.RecordType})
  1883. {
  1884. var result = changeType.ShowDialog();
  1885. if (result != DialogResult.OK) return;
  1886. type = changeType.Type;
  1887. name = changeType.TypeName;
  1888. }
  1889. var ccp = new CoreClientParam
  1890. {
  1891. ServerName = "com.steering.Mcms.RecordServer",
  1892. MethodName = "DoUpdateType",
  1893. ServerParams = new object[]
  1894. {
  1895. current.RecordNo,
  1896. type,
  1897. name
  1898. }
  1899. };
  1900. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1901. if (ccp.ReturnCode != -1)
  1902. {
  1903. MessageUtil.ShowTips(ccp.ReturnInfo);
  1904. if (ccp.ReturnInfo.ToString2().Contains("成功"))
  1905. Query();
  1906. }
  1907. }
  1908. private void ugData_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
  1909. {
  1910. var dex = e.RowScrollRegion.FirstRow;
  1911. dex.Activate();
  1912. }
  1913. private void CurrentGrid_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
  1914. {
  1915. /* UltraGridRow dex = e.RowScrollRegion.FirstRow;
  1916. dex.Activate();*/
  1917. }
  1918. private void ugData_AfterRowActivate(object sender, EventArgs e)
  1919. {
  1920. ugData.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
  1921. }
  1922. private void ugData_BeforeRowDeactivate(object sender, CancelEventArgs e)
  1923. {
  1924. ugData.ActiveRow.RowSelectorAppearance.ResetBackColor();
  1925. }
  1926. private void CurrentGrid_BeforeRowDeactivate(object sender, CancelEventArgs e)
  1927. {
  1928. CurrentGrid.ActiveRow.RowSelectorAppearance.ResetBackColor();
  1929. }
  1930. private void utbSelect2_Click(object sender, EventArgs e)
  1931. {
  1932. var carNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
  1933. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1934. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", new object[] {carNo}, ob);
  1935. if ((dt != null) && (dt.Rows.Count > 0) && (dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"))
  1936. {
  1937. cmmWeightRecordEntityFull.ShippersName = "天津钢管制造有限公司";
  1938. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  1939. cmmWeightRecordEntityFull.ReceiveName = "江苏天淮钢管有限公司";
  1940. cmmWeightRecordEntityFull.RecordNumber =
  1941. dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
  1942. decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  1943. cmmWeightRecordEntityFull.MatName = "连铸圆坯";
  1944. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1945. for (var i = 0; i < dt.Rows.Count; i++)
  1946. {
  1947. var dtcRow = dt.Rows[i];
  1948. var cmmWeightMatEntity = new CmmWeightMatEntity
  1949. {
  1950. JudgeStoveNoOld = dtcRow["STOVE_NO"].ToString2(),
  1951. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1952. ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
  1953. ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
  1954. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1955. DocumentNo = dtcRow["OUTSTOCK_DOC"].ToString2(),
  1956. ProOrderNo = dtcRow["ORDER_NO"].ToString2(),
  1957. OrderNo = dtcRow["ORDER_NO"].ToString2(),
  1958. OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
  1959. OrdNoPk = dtcRow["ORD_PK"].ToString2(),
  1960. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  1961. Producname = dtcRow["PRODUCNAME"].ToString2(),
  1962. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1963. Gradename = dtcRow["GRADENAME"].ToString2(),
  1964. Steelcode = dtcRow["GRADECODE"].ToString2(),
  1965. Steelname = dtcRow["GRADENAME"].ToString2()
  1966. };
  1967. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1968. }
  1969. matInfo3.SetDefault(cmmWeightRecordEntityFull);
  1970. }
  1971. else
  1972. {
  1973. MessageBox.Show("未找到该车的出库记录!");
  1974. }
  1975. }
  1976. private void uctMemo_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1977. {
  1978. if (cmmPoundBase == null)
  1979. {
  1980. MessageBox.Show(@"无磅房权限");
  1981. return;
  1982. }
  1983. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1984. string Memo;
  1985. using (var update = new ChangeMemo { Memo = current.Memo })
  1986. {
  1987. var result = update.ShowDialog();
  1988. if (result != DialogResult.OK) return;
  1989. Memo = update.Memo;
  1990. }
  1991. var ccp = new CoreClientParam
  1992. {
  1993. ServerName = "com.steering.Mcms.RecordServer",
  1994. MethodName = "DoUpdateMemo",
  1995. ServerParams = new object[]
  1996. {
  1997. current.RecordNo,
  1998. Memo
  1999. }
  2000. };
  2001. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2002. if (ccp.ReturnCode != -1)
  2003. {
  2004. MessageUtil.ShowTips(ccp.ReturnInfo);
  2005. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  2006. Query();
  2007. }
  2008. }
  2009. private void ultraButton2_Click(object sender, EventArgs e)
  2010. {
  2011. if (ugData.ActiveRow == null) return;
  2012. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  2013. if (data == null) return;
  2014. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  2015. DialogResult.No))
  2016. {
  2017. }
  2018. else
  2019. {
  2020. Print2(data.ResultNo);
  2021. }
  2022. }
  2023. }
  2024. }