frmLocalTruckScaleNew.cs 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Timers;
  10. using System.Windows.Forms;
  11. using System.Xml.Linq;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Server;
  14. using Core.Mes.Client.Comm.Tool;
  15. using Core.StlMes.Client.LgResMgt.Mcms.entity;
  16. using CoreFS.CA06;
  17. using Infragistics.Win;
  18. using Infragistics.Win.Misc;
  19. using Infragistics.Win.UltraWinEditors;
  20. using Infragistics.Win.UltraWinGrid;
  21. using Infragistics.Win.UltraWinListView;
  22. using Infragistics.Win.UltraWinTabControl;
  23. using Newtonsoft.Json;
  24. using Newtonsoft.Json.Serialization;
  25. using NPOI.HSSF.UserModel;
  26. using NPOI.SS.UserModel;
  27. using NPOI.SS.Util;
  28. using BorderStyle = NPOI.SS.UserModel.BorderStyle;
  29. using HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment;
  30. using Timer = System.Timers.Timer;
  31. using System.Net.Sockets;
  32. using System.Threading;
  33. using System.Text;
  34. using System.Collections;
  35. using Core.Mes.Client.Comm.Format;
  36. using System.Threading.Tasks;
  37. using NPOI.SS.Formula.Functions;
  38. using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
  39. namespace Core.StlMes.Client.LgResMgt.Mcms
  40. {
  41. public partial class frmLocalTruckScaleNew : FrmBase
  42. {
  43. private static readonly string _path = Environment.CurrentDirectory + "\\data\\SerialPort.xml";
  44. private readonly Timer timer = new Timer();
  45. private List<CmmInputRecordEntity> _cmmInputRecordEntities;
  46. private frmMessage _frmMessage;
  47. private List<CmmRecordTemplateEntity> _templateList;
  48. private bool canUpdateWt;
  49. private CmmPoundBaseEntity cmmPoundBase;
  50. private CommunicationEntity communicationnow;
  51. private List<CommunicationEntity> CommunicationEntitys = new List<CommunicationEntity>();
  52. // private SerialPortEntity defultPortEntity;
  53. private bool isLoading = true;
  54. private List<CmmPoundBaseEntity> poundInfos;
  55. //TODO:等陆硬盘录像机
  56. private Log l = Log.GetInstance();
  57. private DataCollectionControl collection = new DataCollectionControl();
  58. //private SocketClient defultClenttEntity;
  59. private List<CmmBaseSpotInfoEntity> CmmBaseSpotInfo;
  60. //private CmmBaseSpotInfoEntity CmmBase = new CmmBaseSpotInfoEntity();
  61. //private TcpListener tcpListener;
  62. //图片控制器含图片压缩及上传sftp
  63. private ImageControl imageControl;
  64. List<CmmLoadinfoCEntity> loadinfo;
  65. string strip;
  66. // private CmmWorkImageEntity CmmImage=new CmmWorkImageEntity();
  67. public frmLocalTruckScaleNew()
  68. {
  69. InitializeComponent();
  70. IsLoadUserView = true;
  71. // timer.Elapsed += timer_Elapsed;
  72. // timer.Interval = 1 * 60 * 1000;
  73. // timer.Start();
  74. }
  75. private void timer_Elapsed(object sender, ElapsedEventArgs e)
  76. {
  77. try
  78. {
  79. CurrentGrid.SafeRefreshControl(() =>
  80. {
  81. var dic = new Dictionary<string, object>();
  82. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  83. dic.Add("poundNo", cboPoundList.Text);
  84. dic.Add("validflag", new List<string> { "1" });
  85. dic.Add("effRemaind", "1");
  86. List<CmmWeightRecordEntity> list = EntityHelper.GetData<CmmWeightRecordEntity>(
  87. "com.steering.Mcms.RecordServer.doQueryRecord",
  88. new object[] { dic },
  89. ob);
  90. if ((list != null) && list.Any())
  91. foreach (
  92. var ultraGridRow in
  93. CurrentGrid.Rows.Where(
  94. p => list.Any(q => q.RecordNo == p.Cells["RecordNo"].Value.ToString2())))
  95. ultraGridRow.Cells["RecordDate"].Appearance.BackColor = Color.Red;
  96. });
  97. GC.Collect();
  98. }
  99. catch (Exception)
  100. {
  101. }
  102. }
  103. protected override async void OnLoad(EventArgs e)
  104. {
  105. //try
  106. //{
  107. System.Net.IPHostEntry hostIP = System.Net.Dns.GetHostEntry(Environment.MachineName);
  108. strip = hostIP.AddressList[0].ToString();
  109. // strip = UserInfo.GetMachineIP();
  110. base.OnLoad(e);
  111. tbFirstWt.Controls.OfType<UltraTabPageControl>()
  112. .SelectMany(p => p.Controls.OfType<MatInfo>())
  113. .ToList()
  114. .ForEach(p => p.ini(ob));
  115. tbOther.Controls.OfType<UltraTabPageControl>()
  116. .SelectMany(p => p.Controls.OfType<MatInfo>())
  117. .ToList()
  118. .ForEach(p => p.ini(ob));
  119. matInfo15.ini(ob);
  120. matInfo16.ini(ob);
  121. tbWt.Appearance.ForeColor = SystemColors.ControlText;
  122. ;
  123. tbFirstWt.Appearance.ForeColor = SystemColors.ControlText;
  124. ;
  125. tbScondWt.Appearance.ForeColor = SystemColors.ControlText;
  126. ;
  127. tbOther.Appearance.ForeColor = SystemColors.ControlText;
  128. ;
  129. //TUDO
  130. poundInfos = EntityHelper.GetData<CmmPoundBaseEntity>(
  131. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  132. new object[] { ValidDataPurviewIds },
  133. ob);
  134. CmmBaseSpotInfo = EntityHelper.GetData<CmmBaseSpotInfoEntity>(
  135. "com.steering.Mcms.CmmBaseSpotInfoServer.doQuery",
  136. new object[] { },
  137. ob);
  138. List<CmmPoundBaseEntity> list = EntityHelper.GetData<CmmPoundBaseEntity>(
  139. "com.steering.Mcms.PoundBaseServer.getPoudInfo",
  140. new object[] { new string[] { } },
  141. ob);
  142. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  143. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  144. LoadRecord();
  145. LoadTempate();
  146. //加载配置
  147. // 构造 ImageControl 对象
  148. imageControl = new ImageControl(
  149. CmmBaseSpotInfo[0].FtpIp,
  150. CmmBaseSpotInfo[0].FtpPort,
  151. CmmBaseSpotInfo[0].FtpUserName,
  152. CmmBaseSpotInfo[0].FtpPassword,
  153. CmmBaseSpotInfo[0].Ftptype,
  154. CmmBaseSpotInfo[0].Ftppath,
  155. ob);
  156. // 异步启动,避免卡UI
  157. await Task.Run(() => imageControl.Start());
  158. // }
  159. // catch
  160. //{ }
  161. comboCount.Text = "1";
  162. }
  163. private void defultClenttEntity_ReceiveData(object sender, object data, string message, DataType datatype,
  164. byte[] bdata)
  165. {
  166. SocketClient client = sender as SocketClient;
  167. if (client.Show == true)
  168. {
  169. ShowMessage(data, message, datatype, sender);
  170. }
  171. }
  172. private async void LoadRecord()
  173. {
  174. var dic1 = new Dictionary<string, object>
  175. {
  176. { "recordType", new List<string> { "1" } }
  177. };
  178. var dic2 = new Dictionary<string, object>
  179. {
  180. { "recordType", new List<string> { "2", "7", "8", "9" } }
  181. };
  182. // 并行执行
  183. var task1 = Task.Run(() => EntityHelper.GetData<CmmInputRecordEntity>(
  184. "com.steering.Mcms.InputRecordServer.doQuery",
  185. new object[] { dic1 },
  186. ob
  187. ));
  188. var task2 = Task.Run(() => EntityHelper.GetData<CmmInputRecordEntity>(
  189. "com.steering.Mcms.InputRecordServer.doQuery",
  190. new object[] { dic2 },
  191. ob
  192. ));
  193. var datas = await task1;
  194. _cmmInputRecordEntities = await task2;
  195. // 更新UI
  196. txtCar2.DataSource = datas
  197. .Where(p => p.RecordType == "1")
  198. .Select(p => p.RecordValue)
  199. .Distinct()
  200. .ToList();
  201. txtCar2.Text = "";
  202. }
  203. private void utbConnect_Click(object sender, EventArgs e)
  204. {
  205. if (communicationnow.Communication == null) return;
  206. if ((communicationnow.Communication != null) && communicationnow.Communication.Status)
  207. {
  208. communicationnow.Communication.Stop();
  209. }
  210. else
  211. {
  212. communicationnow.Communication.Start();
  213. }
  214. }
  215. private void utbMessage_Click(object sender, EventArgs e)
  216. {
  217. _frmMessage = new frmMessage();
  218. _frmMessage.Show();
  219. }
  220. //TUDO
  221. private void ShowMessage(object data, string message, DataType dataType, object sender)
  222. {
  223. SocketClient client = sender as SocketClient;
  224. if (dataType == DataType.ReceiveData)
  225. {
  226. double wt;
  227. if (double.TryParse(data.ToString2(), out wt))
  228. lblWtNow.SafeRefreshControl(() => { lblWtNow.Text = (wt / 100d).ToString("0.00") + "t"; });
  229. }
  230. else if (dataType == DataType.Open)
  231. {
  232. utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Red);
  233. lblMsg.SafeRefreshControl(
  234. () =>
  235. lblMsg.Text =
  236. client.Status
  237. ? "已打开"
  238. : "已关闭");
  239. // cboNo.SafeRefreshControl(() => cboNo.Enabled = false);
  240. }
  241. else if (dataType == DataType.Close)
  242. {
  243. utbConnect.SafeRefreshControl(() => utbConnect.Appearance.ForeColor = Color.Lime);
  244. lblMsg.SafeRefreshControl(
  245. () =>
  246. lblMsg.Text =
  247. client.Status
  248. ? "已打开"
  249. : "已关闭");
  250. }
  251. else if (dataType == DataType.Error)
  252. {
  253. MessageBox.Show(message);
  254. }
  255. else if (dataType == DataType.ClientReconnect)
  256. {
  257. lblMsg.SafeRefreshControl(() => lblMsg.Text = "网络异常,正在重连服务!");
  258. }
  259. lblStatus.SafeRefreshControl(() => lblStatus.Text = client.ToString());
  260. if ((_frmMessage != null) && !_frmMessage.IsDisposed)
  261. _frmMessage.SafeShowMsg(message, dataType);
  262. else
  263. _frmMessage = null;
  264. }
  265. private void utbShowWt_Click(object sender, EventArgs e)
  266. {
  267. string.Format("当前重量{0}", lblWt.Text.Replace("t", "吨")).Speak();
  268. }
  269. private async void lblWtNow_Click(object sender, EventArgs e)
  270. {
  271. lblWt.Text = lblWtNow.Text;
  272. if (CurrentGrid.ActiveRow != null)
  273. {
  274. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  275. if ((current == null) || ("" == current.CarNo)) return;
  276. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  277. if (tbScondWt.ActiveTab.Key == "3")
  278. {
  279. }
  280. else if (tbScondWt.ActiveTab.Key == "0")
  281. {
  282. }
  283. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  284. (tbOther.ActiveTab.Key == "205"))
  285. {
  286. decimal wt, fwt;
  287. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  288. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  289. await ShowOutInfo(current.CarNo, wt - fwt, comboCount.Text);
  290. }
  291. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  292. (tbOther.ActiveTab.Key == "206"))
  293. {
  294. decimal wt, fwt;
  295. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  296. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  297. if (wt - fwt > 0)
  298. matInfo13.SetWt(wt - fwt);
  299. // ShowOutInfoGp(current.CarNo, wt - fwt);
  300. }
  301. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  302. (tbOther.ActiveTab.Key == "109"))
  303. {
  304. var matInfo = GetMatInfo();
  305. if (matInfo != null)
  306. {
  307. decimal wt, fwt;
  308. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  309. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  310. if (wt - fwt > 0)
  311. matInfo.SetWt(wt - fwt);
  312. }
  313. }
  314. }
  315. }
  316. private void utbShowCarNo_Click(object sender, EventArgs e)
  317. {
  318. if ((cbxCar1.SelectedIndex < 0) || string.IsNullOrWhiteSpace(txtCar2.Text)) return;
  319. string.Format(" {0}", cbxCar1.Text + txtCar2.Text).Speak();
  320. }
  321. private void chkGross_CheckedChanged(object sender, EventArgs e)
  322. {
  323. tbFirstWt.Visible = chkGross.Checked;
  324. utbSaveAsT.Visible = chkGross.Checked;
  325. if (chkGross.Checked)
  326. {
  327. checkBox1.Visible = false;
  328. recordType.Visible = false;
  329. }
  330. else
  331. {
  332. checkBox1.Visible = true;
  333. recordType.Visible = true;
  334. }
  335. }
  336. Thread thsave;
  337. Point screenPoint;
  338. void Savepicture(object str)
  339. {
  340. //*
  341. //截取屏幕信息
  342. // PbCache.actualFirstNo = CmmImage.ActualFirstNo;
  343. Rectangle rect = new Rectangle(screenPoint, this.Size);
  344. Image img = new Bitmap(rect.Width, rect.Height);
  345. Graphics g = Graphics.FromImage(img);
  346. g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
  347. img.Save(string.Format("{0}\\imgShort\\formalImg\\{1}_{2}_{3}.jpg",
  348. AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  349. PbCache.sportInfo.BaseSpotNo,
  350. PbCache.actualFirstNo,
  351. (5)), System.Drawing.Imaging.ImageFormat.Jpeg);// 最后一张图片名称写死了
  352. //*
  353. //最后进行截图操作
  354. CameraShotCls cameraShot = new CameraShotCls();
  355. cameraShot.CapMethod(PbCache.actualFirstNo, communicationnow.PoundNo);
  356. }
  357. /// <summary>
  358. /// 一次称重保存
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void utbSave1_Click(object sender, EventArgs e)
  363. {
  364. if (lblWt.Text != lblWtNow.Text)
  365. {
  366. if ( MessageUtil.ShowYesNoAndQuestion("吨位不一致!请确认是否继续保存 ?") == DialogResult.No)
  367. return;
  368. }
  369. if (cmmPoundBase == null)
  370. {
  371. MessageBox.Show(@"无磅房权限");
  372. return;
  373. }
  374. if (string.IsNullOrWhiteSpace(txtCar2.Text) || string.IsNullOrWhiteSpace(cbxCar1.Text))
  375. {
  376. MessageBox.Show(@"未录入车牌号!");
  377. return;
  378. }
  379. decimal wt = 0;
  380. //测试注释 TZH
  381. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  382. {
  383. MessageBox.Show(@"重量异常!");
  384. return;
  385. }
  386. var cmmWeightRecord = new CmmWeightRecordEntityFull();
  387. if (chkGross.Checked)
  388. {
  389. var matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  390. if (matInfo != null) cmmWeightRecord = matInfo.GetData();
  391. }
  392. if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
  393. cmmWeightRecord.MatInfos.Any())
  394. {
  395. MessageBox.Show("支数不能为空!");
  396. return;
  397. }
  398. cmmWeightRecord.CarNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
  399. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  400. cmmWeightRecord.RecordType = !chkGross.Checked ? "101" : tbFirstWt.ActiveTab.Key;
  401. cmmWeightRecord.WtType = chkGross.Checked ? "1" : "0";
  402. cmmWeightRecord.Validflag = "1";
  403. cmmWeightRecord.RecordWeight = wt;
  404. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  405. cmmWeightRecord.MatType = chkGross.Checked ? tbFirstWt.ActiveTab.Text
  406. : checkBox1.Checked ? recordType.Text : "";
  407. cmmWeightRecord.Memo = chkSteelCar.Checked ? "钢管" : "";
  408. if ("102" == cmmWeightRecord.RecordType)
  409. if ((cmmWeightRecord.RecordNumber == null) || (cmmWeightRecord.RecordNumber <= 0) ||
  410. (cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()
  411. || cmmWeightRecord.MatInfos.Any(p => (p.ActCount == null) || (p.ActCount <= 0)))
  412. {
  413. MessageBox.Show("支数不能为空!");
  414. return;
  415. }
  416. // 先毛后皮
  417. if (checkBox1.Checked)
  418. {
  419. var key = "";
  420. key = recordType.Value.ToString2();
  421. if (key == "" || key == null)
  422. {
  423. MessageBox.Show("请选择过磅类型!");
  424. return;
  425. }
  426. cmmWeightRecord.WtType = "1";
  427. cmmWeightRecord.RecordType = key;
  428. }
  429. var list =
  430. cmmWeightRecordEntityBindingSource.DataSource as List<CmmWeightRecordEntity>;
  431. if ((list != null) && list.Any(p => p.CarNo == cmmWeightRecord.CarNo))
  432. if (MessageUtil.ShowYesNoAndQuestion("车牌已经存在皮重,是否继续保存皮重?") == DialogResult.No)
  433. return;
  434. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None, new JsonSerializerSettings
  435. { ContractResolver = new CamelCasePropertyNamesContractResolver() });
  436. var ccp = new CoreClientParam
  437. {
  438. ServerName = "com.steering.Mcms.LocalTruckScale",
  439. MethodName = "DoAdd",
  440. ServerParams = new object[]
  441. {
  442. "",
  443. json
  444. }
  445. };
  446. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  447. PbCache.actualFirstNo = ccp.ReturnObject.ToString();//tudo
  448. #region 截取图片信息
  449. try
  450. {
  451. screenPoint = this.PointToScreen(new Point());
  452. thsave = new Thread(new ParameterizedThreadStart(Savepicture));
  453. thsave.Start("");
  454. playVioce("称重完成");
  455. }
  456. catch (Exception ex)
  457. {
  458. l.WriteLog(5, PbCache.lockCarNo + "截图失败");
  459. }
  460. #endregion
  461. if (true)//(ccp.ReturnCode != -1)
  462. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  463. {
  464. ccp.ReturnInfo.ToString2().Speak();
  465. lblWt.Text = "0.000t";
  466. LoadRecord();
  467. Query();
  468. //tzh 24.11.25 清空提单信息
  469. CX_HT.Text = "";
  470. tb_order.Text = "";
  471. var matInfo = GetMatInfo();
  472. if (matInfo != null) matInfo.SetDefault(null);
  473. }
  474. else
  475. {
  476. MessageUtil.ShowTips(ccp.ReturnInfo);
  477. }
  478. addActual(communicationnow.PoundNo, PbCache.actualFirstNo);
  479. checkBox1.Checked = false;
  480. chkSteelCar.Checked = false;
  481. chkGross.Checked = false;
  482. tbFirstWt.Visible = chkGross.Checked;
  483. utbSaveAsT.Visible = chkGross.Checked;
  484. //TUDO//
  485. }
  486. /// <summary>
  487. /// 二次称重
  488. /// </summary>
  489. /// <param name="sender"></param>
  490. /// <param name="e"></param>
  491. private void btnSave2_Click(object sender, EventArgs e)
  492. {
  493. string CX = "";
  494. if ( CX_HT.Value != null)
  495. {
  496. CX = CX_HT.Value.ToString();
  497. }
  498. if (cmmPoundBase == null)
  499. {
  500. MessageBox.Show(@"无磅房权限");
  501. return;
  502. }
  503. if (lblWt.Text != lblWtNow.Text)
  504. {
  505. if (MessageUtil.ShowYesNoAndQuestion("吨位不一致!请确认是否继续保存 ?") == DialogResult.No)
  506. return;
  507. }
  508. if (tbScondWt.ActiveTab == null) return;
  509. if (CurrentGrid.ActiveRow == null)
  510. {
  511. MessageBox.Show(@"请选择第一次称重记录");
  512. return;
  513. }
  514. decimal wt = 0;
  515. //测试注释 TZH
  516. if (!decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) || (wt <= 0))
  517. {
  518. MessageBox.Show(@"重量异常!");
  519. return;
  520. }
  521. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  522. if (current == null) return;
  523. if (current.CarNo != (cbxCar1.Text + txtCar2.Text))
  524. {
  525. MessageBox.Show("选中的车号与显示的车号不一致");
  526. return;
  527. }
  528. var key = GetKey();
  529. CmmWeightRecordEntityFull cmmWeightRecord;
  530. if ("207" == key)
  531. {
  532. cmmWeightRecord = new CmmWeightRecordEntityFull();
  533. if (checkBox3.Checked)
  534. {
  535. var matInfo = GetMatInfo();
  536. cmmWeightRecord = matInfo.GetData();
  537. cmmWeightRecord.WtType = "0";
  538. }
  539. }
  540. else
  541. {
  542. var matInfo = GetMatInfo();
  543. if (matInfo == null) return;
  544. cmmWeightRecord = matInfo.GetData();
  545. cmmWeightRecord.WtType = "1";
  546. if ((cmmWeightRecord.RecordNumber == null) && (cmmWeightRecord.MatInfos != null) &&
  547. cmmWeightRecord.MatInfos.Any())
  548. {
  549. MessageBox.Show("数量不能为空!");
  550. return;
  551. }
  552. }
  553. var hookWtStr = "";
  554. if (key == "201")
  555. {
  556. if ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any())
  557. {
  558. MessageBox.Show("无配送单信息!");
  559. return;
  560. }
  561. if (cmmWeightRecord.MatInfos.Any(p => p.ActWeight == null))
  562. {
  563. MessageBox.Show("有炉号没有钩子称重量!");
  564. return;
  565. }
  566. var hookWt = cmmWeightRecord.MatInfos.Select(p => (decimal)p.ActWeight).Sum();
  567. hookWtStr = hookWt.ToString();
  568. decimal NetWt;
  569. decimal wt2, wt1;
  570. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
  571. decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
  572. {
  573. NetWt = wt2 - wt1;
  574. }
  575. else
  576. {
  577. MessageBox.Show("数据异常!");
  578. return;
  579. }
  580. if (NetWt <= 0)
  581. {
  582. MessageBox.Show("净重小于0!");
  583. return;
  584. }
  585. cmmWeightRecord.RealWt = NetWt;
  586. if (Math.Abs(NetWt - hookWt) * 1000 / NetWt >= 5)
  587. {
  588. var msg = " 净重与钩子称 误差超过千分之5";
  589. msg.Speak();
  590. if (
  591. MessageUtil.ShowYesNoAndQuestion(" 净重: " + NetWt + "t 钩子称重量: " + hookWt + "t 磅差 " +
  592. (NetWt - hookWt) + "t 误差超过千分之5, 请确认是否继续保存 ?") ==
  593. DialogResult.No)
  594. return;
  595. }
  596. }
  597. cmmWeightRecord.RecordType = GetKey();
  598. cmmWeightRecord.Recoder = UserInfo.GetUserName();
  599. cmmWeightRecord.Validflag = "2";
  600. cmmWeightRecord.RecordWeight = wt;
  601. cmmWeightRecord.RecoderLocation = cmmPoundBase.PoundNo;
  602. cmmWeightRecord.CarNo = current.CarNo;
  603. cmmWeightRecord.MatType = GetMatType();
  604. if (("208" == cmmWeightRecord.RecordType) &&
  605. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  606. {
  607. MessageBox.Show(@"无废品出库信息,无法保存!");
  608. return;
  609. }
  610. if (("201" == cmmWeightRecord.RecordType) &&
  611. ((cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()))
  612. {
  613. MessageBox.Show(@"无装车单信息,无法保存!");
  614. return;
  615. }
  616. //钢坯采购空车回皮直接做法,下次判断
  617. var newKey = "";
  618. if (checkBox3.Checked && cmmWeightRecord.RecordType == "207")
  619. {
  620. newKey = qitahuipi.ActiveTab.Key;
  621. cmmWeightRecord.MatType = qitahuipi.ActiveTab.Text;
  622. }
  623. var json = JsonConvert.SerializeObject(cmmWeightRecord, Formatting.None,
  624. new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });
  625. object[] o = null;
  626. if (cmmWeightRecord.RecordType == "207" && checkBox3.Checked)
  627. {
  628. if ("102" == newKey)
  629. {
  630. cmmWeightRecord.WtType = "0";
  631. decimal NetWt;
  632. decimal wt2, wt1;
  633. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2) &&
  634. decimal.TryParse(current.RecordWeight.ToString3(), out wt1))
  635. {
  636. NetWt = wt1 - wt2;
  637. }
  638. else
  639. {
  640. MessageBox.Show("数据异常!");
  641. return;
  642. }
  643. if (NetWt <= 0)
  644. {
  645. MessageBox.Show("净重小于0!");
  646. return;
  647. }
  648. cmmWeightRecord.RealWt = NetWt;
  649. }
  650. if ("102" == newKey)
  651. if ((cmmWeightRecord.RecordNumber == null) || (cmmWeightRecord.RecordNumber <= 0) ||
  652. (cmmWeightRecord.MatInfos == null) || !cmmWeightRecord.MatInfos.Any()
  653. || cmmWeightRecord.MatInfos.Any(p => (p.ActCount == null) || (p.ActCount <= 0)))
  654. {
  655. MessageBox.Show("支数不能为空!");
  656. return;
  657. }
  658. o = new object[]
  659. {
  660. current.RecordNo,
  661. hookWtStr,
  662. json,
  663. newKey,
  664. CX
  665. };
  666. }
  667. else
  668. {
  669. o = new object[]
  670. {
  671. current.RecordNo,
  672. hookWtStr,
  673. json,
  674. CX
  675. };
  676. }
  677. var ccp = new CoreClientParam
  678. {
  679. ServerName = "com.steering.Mcms.LocalTruckScale",
  680. MethodName = "DoAdd",
  681. ServerParams = o
  682. };
  683. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  684. if (ccp.ReturnCode != -1)
  685. {
  686. PbCache.actualFirstNo = ccp.ReturnObject.ToString();
  687. addActual(communicationnow.PoundNo, PbCache.actualFirstNo);
  688. checkBox3.Checked = false;
  689. checkBox3.Visible = false;
  690. qitahuipi.Visible = checkBox3.Checked;
  691. #region 截取图片信息
  692. try
  693. {
  694. screenPoint = this.PointToScreen(new Point());
  695. thsave = new Thread(new ParameterizedThreadStart(Savepicture));
  696. thsave.Start("");
  697. playVioce("称重完成");
  698. }
  699. catch (Exception ex)
  700. {
  701. l.WriteLog(5, PbCache.lockCarNo + "截图失败");
  702. }
  703. #endregion
  704. if (ccp.ReturnInfo.ToString2().Contains("称重完成"))
  705. {
  706. decimal wt2;
  707. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt2);
  708. lblWt.Text = "0.000t";
  709. var result = ccp.ReturnInfo.ToString2().Split('|');
  710. result[0].Speak();
  711. if (result.Length > 1)
  712. if ((key == "201") && (wt2 > 50) && (MessageUtil.ShowYesNoAndQuestion("称重完成! 毛重超过50吨, 是否继续打印磅单?") ==
  713. DialogResult.No))
  714. {
  715. }
  716. else
  717. {
  718. Print(result[1]);
  719. }
  720. LoadRecord();
  721. Query();
  722. Query2();
  723. //tzh 24.11.25 清空提单信息
  724. CX_HT.Text = "";
  725. tb_order.Text = "";
  726. //TODO 打印
  727. var matInfo = GetMatInfo();
  728. if (matInfo != null) matInfo.SetDefault(null);
  729. }
  730. else
  731. {
  732. MessageUtil.ShowTips(ccp.ReturnInfo);
  733. }
  734. }
  735. }
  736. private void Print(string resultNo, bool spilt = false)
  737. {
  738. var strurl =
  739. "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=" +
  740. (spilt ? "RepThCattyListCut" : "RepThCattyList") +
  741. ".cpt&RESULT_NO=" +
  742. resultNo;
  743. var fre = new FrmRepBrower(ob, strurl)
  744. {
  745. Size = new Size(900,
  746. 500)
  747. };
  748. fre.Show();
  749. }
  750. private void Print2(string resultNo, bool spilt = false)
  751. {
  752. var strurl =
  753. "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=" +
  754. (spilt ? "RepThCattyListCut" : "RepThCattyList") +
  755. ".cpt&RESULT_NO=" +
  756. resultNo;
  757. var fre = new FrmRepBrower(ob, strurl)
  758. {
  759. Size = new Size(900,
  760. 500)
  761. };
  762. fre.Show();
  763. }
  764. //TUDO
  765. private void frmLocalTruckScale_FormClosed(object sender, FormClosedEventArgs e)
  766. {
  767. //if ((communication != null) && communication.Status)
  768. // communication.Stop();
  769. timer.Stop();
  770. }
  771. private async void Query()
  772. {
  773. var dic = new Dictionary<string, object>();
  774. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  775. dic.Add("poundNo", cboPoundList.Text);
  776. dic.Add("validflag", new List<string> { "1" });
  777. // 在后台线程执行数据库查询
  778. var list = await Task.Factory.StartNew(() =>
  779. {
  780. return EntityHelper.GetData<CmmWeightRecordEntity>(
  781. "com.steering.Mcms.RecordServer.doQueryRecord",
  782. new object[] { dic },
  783. ob
  784. );
  785. });
  786. // 回到 UI 线程更新控件
  787. cmmWeightRecordEntityBindingSource.DataSource = list;
  788. Comm.RefreshAndAutoSize(CurrentGrid);
  789. }
  790. private async void LoadTempate()
  791. {
  792. // 如果 cmmPoundBase 要判断的话,恢复这行
  793. // if (cmmPoundBase == null) return;
  794. _templateList = await Task.Run(() =>
  795. {
  796. return EntityHelper.GetData<CmmRecordTemplateEntity>(
  797. "com.steering.Mcms.TemplateServer.doQueryTempate",
  798. new object[] { "" },
  799. ob
  800. );
  801. });
  802. // 数据加载完后,再调用 UI 更新方法
  803. tbFirstWt_SelectedTabChanged(null, null);
  804. }
  805. private void utbSaveAsT_Click(object sender, EventArgs e)
  806. {
  807. if (cmmPoundBase == null)
  808. {
  809. MessageBox.Show(@"无磅房权限");
  810. return;
  811. }
  812. if (tbWt.ActiveTab == null) return;
  813. var matInfo = GetMatInfo();
  814. if (matInfo != null)
  815. {
  816. var cmmWeightRecord = matInfo.GetData();
  817. string projectName;
  818. using (var fractureInfo = new ProjectName("模板名"))
  819. {
  820. fractureInfo.ShowDialog();
  821. if (fractureInfo.DialogResult != DialogResult.OK) return;
  822. projectName = fractureInfo.ProjectNameStr;
  823. }
  824. var template = new CmmRecordTemplateEntity
  825. {
  826. CreateUser = UserInfo.GetUserName(),
  827. TemplateKey = GetKey(),
  828. TemplateLocation = cmmPoundBase.PoundNo,
  829. TemplateXml = cmmWeightRecord.ToString(),
  830. TemplateName = projectName
  831. };
  832. var ccp = new CoreClientParam
  833. {
  834. ServerName = "com.steering.Mcms.TemplateServer",
  835. MethodName = "DoSaveTemplateNo",
  836. ServerParams = new object[]
  837. {
  838. JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
  839. {ContractResolver = new CamelCasePropertyNamesContractResolver()})
  840. }
  841. };
  842. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  843. if (ccp.ReturnCode != -1)
  844. {
  845. MessageUtil.ShowTips(ccp.ReturnInfo);
  846. if (ccp.ReturnInfo.Equals("保存成功!"))
  847. LoadTempate();
  848. }
  849. }
  850. }
  851. private MatInfo GetMatInfo()
  852. {
  853. MatInfo matInfo = null;
  854. if (tbWt.ActiveTab == null) return null;
  855. if ((tbWt.ActiveTab.Key == "1") && (tbFirstWt.ActiveTab != null))
  856. matInfo = tbFirstWt.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  857. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  858. (tbOther.ActiveTab != null))
  859. matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  860. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "3"))
  861. matInfo = matInfo15;
  862. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0"))
  863. matInfo = matInfo16;
  864. // ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  865. // (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null)
  866. // matInfo = qitahuipi.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();这个以后试试可以用不--byzc
  867. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  868. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
  869. matInfo = matInfo20;
  870. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  871. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "110")
  872. matInfo = matInfo28;
  873. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  874. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "103")
  875. matInfo = matInfo21;
  876. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  877. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "104")
  878. matInfo = matInfo22;
  879. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  880. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "105")
  881. matInfo = matInfo23;
  882. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  883. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "106")
  884. matInfo = matInfo24;
  885. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  886. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "107")
  887. matInfo = matInfo25;
  888. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  889. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "108")
  890. matInfo = matInfo26;
  891. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  892. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "109")
  893. matInfo = matInfo27;
  894. else if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  895. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "301")
  896. matInfo = matInfo19;
  897. return matInfo;
  898. }
  899. private MatInfo GetMatInfo2()
  900. {
  901. MatInfo matInfo = null;
  902. if (CX_HT.Text == null) return null;
  903. matInfo = tbOther.ActiveTab.TabPage.Controls.OfType<MatInfo>().FirstOrDefault();
  904. return matInfo;
  905. }
  906. private MatInfo GetMatInfoByKey(string key)
  907. {
  908. MatInfo matInfo = null;
  909. foreach (var ultraTab in tbFirstWt.Tabs)
  910. {
  911. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
  912. if (matinfo.Any()) return matinfo[0];
  913. }
  914. foreach (var ultraTab in tbOther.Tabs)
  915. {
  916. var matinfo = ultraTab.TabPage.Controls.OfType<MatInfo>().Where(p => p.Key == key).ToList();
  917. if (matinfo.Any()) return matinfo[0];
  918. }
  919. if (key == "201") return matInfo16;
  920. if (key == "301") return matInfo19;
  921. return matInfo;
  922. }
  923. private void utbDelete_Click(object sender, EventArgs e)
  924. {
  925. var matInfo = GetMatInfo();
  926. if (matInfo != null) matInfo.DeleteRow();
  927. }
  928. private void utbClear_Click(object sender, EventArgs e)
  929. {
  930. var matInfo = GetMatInfo();
  931. if (matInfo != null) matInfo.Clear();
  932. }
  933. private void tbFirstWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  934. {
  935. LoadTem();
  936. var matInfo = GetMatInfo();
  937. if (matInfo != null) matInfo.Clear();
  938. //TZH 24.11.7 加入取产销的废品合同号
  939. if (tbOther.ActiveTab.Key == "202")
  940. {
  941. CX_HTH.Visible = true;
  942. CX_HT.Visible = true;
  943. lb_order.Visible = true;
  944. tb_order.Visible = true;
  945. DataTable dt = ServerHelper.GetData("com.steering.Mcms.TemplateServer.SelectCX", new object[] { }, ob);
  946. if (dt != null && dt.Rows.Count > 0)
  947. {
  948. CX_HT.DataSource = dt;
  949. CX_HT.ValueMember = "BILL_NO";
  950. CX_HT.DisplayMember = "BILL_NO";
  951. }
  952. }
  953. else
  954. {
  955. CX_HTH.Visible = false;
  956. CX_HT.Visible = false;
  957. lb_order.Visible = false;
  958. tb_order.Visible = false;
  959. }
  960. if (CurrentGrid.ActiveRow != null)
  961. {
  962. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  963. if ((current == null) || ("" == current.CarNo)) return;
  964. if ((tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null))
  965. if (tbScondWt.ActiveTab.Key == "3")
  966. {
  967. }
  968. else if (tbScondWt.ActiveTab.Key == "0")
  969. {
  970. }
  971. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  972. (tbOther.ActiveTab.Key == "205"))
  973. {
  974. decimal wt, fwt;
  975. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  976. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  977. ShowOutInfo(current.CarNo, wt - fwt, comboCount.Text);
  978. }
  979. else if ((tbScondWt.ActiveTab.Key == "1") && (tbOther.ActiveTab != null) &&
  980. (tbOther.ActiveTab.Key == "206"))
  981. {
  982. decimal wt, fwt;
  983. decimal.TryParse(lblWt.Text.Replace("t", ""), out wt);
  984. decimal.TryParse(current.RecordWeight.ToString3(), out fwt);
  985. if (wt - fwt > 0)
  986. matInfo13.SetWt(wt - fwt);
  987. //ShowOutInfoGp(current.CarNo, wt - fwt);
  988. }
  989. else
  990. {
  991. if (matInfo != null)
  992. {
  993. decimal wt, fwt;
  994. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out wt) &&
  995. decimal.TryParse(current.RecordWeight.ToString3(), out fwt))
  996. if (wt - fwt > 0)
  997. matInfo.SetWt(wt - fwt);
  998. }
  999. }
  1000. }
  1001. utbSelect.Visible = (tbWt.ActiveTab != null) && (tbWt.ActiveTab.Key == "1") && (tbFirstWt.ActiveTab != null) &&
  1002. (tbFirstWt.ActiveTab.Key == "102");
  1003. utbSelect2.Visible = utbSelect.Visible;
  1004. }
  1005. private void LoadTem()
  1006. {
  1007. if (_templateList == null) return;
  1008. var key = GetKey();
  1009. if (string.IsNullOrWhiteSpace(key)) return;
  1010. if ((_cmmInputRecordEntities != null) && _cmmInputRecordEntities.Any())
  1011. {
  1012. var matInfo = GetMatInfo();
  1013. if (matInfo != null)
  1014. matInfo.iniMatName(
  1015. _cmmInputRecordEntities.Where(
  1016. p => (p.RecordKey == key) || string.IsNullOrWhiteSpace(p.RecordKey)).ToList());
  1017. }
  1018. lvTemplate.Items.Clear();
  1019. lvTemplate.Items.AddRange(_templateList.Where(p => CheckShowKey(p.TemplateKey, key))
  1020. .Select(p =>
  1021. {
  1022. var
  1023. temp =
  1024. new UltraListViewItem(p.TemplateName, null, null) { Key = p.TemplateNo };
  1025. try
  1026. {
  1027. temp.Tag =
  1028. XmlHelper.FromXElement<CmmWeightRecordEntityFull>(XElement.Parse(p.TemplateXml));
  1029. }
  1030. catch (Exception)
  1031. {
  1032. // ignored
  1033. }
  1034. return temp;
  1035. }
  1036. ).
  1037. ToArray()
  1038. );
  1039. }
  1040. private string GetKey()
  1041. {
  1042. return tbWt.ActiveTab.Key == "1"
  1043. ? (tbFirstWt.ActiveTab == null ? "" : tbFirstWt.ActiveTab.Key)
  1044. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  1045. (tbOther.ActiveTab != null)
  1046. ? tbOther.ActiveTab.Key
  1047. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  1048. ? "201"
  1049. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1050. (tbScondWt.ActiveTab.Key == "2")
  1051. ? "207"
  1052. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1053. (tbScondWt.ActiveTab.Key == "3")
  1054. ? "208"
  1055. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1056. (tbScondWt.ActiveTab.Key == "4")
  1057. ? "102"
  1058. : "";
  1059. }
  1060. private string GetMatType()
  1061. {
  1062. return tbWt.ActiveTab.Key == "1"
  1063. ? ""
  1064. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  1065. (tbOther.ActiveTab != null)
  1066. ? tbOther.ActiveTab.Text
  1067. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  1068. ? "钢管发运"
  1069. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1070. (tbScondWt.ActiveTab.Key == "2")
  1071. ? ""
  1072. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1073. (tbScondWt.ActiveTab.Key == "3")
  1074. ? "其它内转"
  1075. : ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  1076. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
  1077. ? "钢坯采购"
  1078. : "";
  1079. }
  1080. private void lvTemplate_MouseClick(object sender, MouseEventArgs e)
  1081. {
  1082. var listView = sender as UltraListView;
  1083. if (e.Button == MouseButtons.Right)
  1084. {
  1085. var itemAtPoint = lvTemplate.ItemFromPoint(e.Location);
  1086. if (itemAtPoint != null)
  1087. {
  1088. lvTemplate.ContextMenuStrip = listViewMenuStrip;
  1089. ISelectionManager selectionManager = listView;
  1090. if (selectionManager != null) selectionManager.SelectItem(itemAtPoint, true);
  1091. itemAtPoint.Activate();
  1092. }
  1093. }
  1094. }
  1095. private void deleteTemplate_Click(object sender, EventArgs e)
  1096. {
  1097. if (lvTemplate.ActiveItem == null) return;
  1098. var ccp = new CoreClientParam
  1099. {
  1100. ServerName = "com.steering.Mcms.TemplateServer",
  1101. MethodName = "DoDeleteTemplate",
  1102. ServerParams = new object[]
  1103. {
  1104. lvTemplate.ActiveItem.Key,
  1105. UserInfo.GetUserName()
  1106. }
  1107. };
  1108. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1109. if (ccp.ReturnCode != -1)
  1110. {
  1111. MessageUtil.ShowTips(ccp.ReturnInfo);
  1112. if (ccp.ReturnInfo.Equals("删除成功!"))
  1113. LoadTempate();
  1114. }
  1115. }
  1116. private async void CurrentGrid_AfterRowActivate(object sender, EventArgs e)
  1117. {
  1118. CurrentGrid.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
  1119. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1120. if ((current == null) || string.IsNullOrEmpty(current.CarNo)) return;
  1121. checkBox3.Visible = current.firstGross == "是";
  1122. ultraButton2.Visible = current.firstGross == "是";
  1123. var tabKey = tbScondWt?.ActiveTab?.Key;
  1124. var otherKey = tbOther?.ActiveTab?.Key;
  1125. if (tbWt?.ActiveTab?.Key == "2" && !string.IsNullOrEmpty(tabKey))
  1126. {
  1127. if (tabKey == "3")
  1128. {
  1129. await ShowWasteInfo(current.CarNo);
  1130. }
  1131. else if (tabKey == "0")
  1132. {
  1133. await ShowLoadvehicleInfo(current.CarNo);
  1134. }
  1135. else if (tabKey == "1" && otherKey == "205")
  1136. {
  1137. var diff = GetWeightDiff(current);
  1138. if (diff.HasValue)
  1139. await ShowOutInfo(current.CarNo, diff.Value, comboCount.Text);
  1140. }
  1141. else if (tabKey == "1" && otherKey == "206")
  1142. {
  1143. var diff = GetWeightDiff(current);
  1144. if (diff.HasValue && diff > 0)
  1145. matInfo13.SetWt(diff.Value);
  1146. }
  1147. else
  1148. {
  1149. var matInfo = GetMatInfo();
  1150. var diff = GetWeightDiff(current);
  1151. if (matInfo != null && diff.HasValue && diff > 0)
  1152. matInfo.SetWt(diff.Value);
  1153. }
  1154. }
  1155. }
  1156. private decimal? GetWeightDiff(CmmWeightRecordEntity current)
  1157. {
  1158. if (decimal.TryParse(lblWt.Text.Replace("t", ""), out var wt) &&
  1159. decimal.TryParse(current.RecordWeight.ToString3(), out var fwt))
  1160. {
  1161. return wt - fwt;
  1162. }
  1163. return null;
  1164. }
  1165. // 显示废品信息(异步版本)
  1166. public async Task ShowWasteInfo(string carNo)
  1167. {
  1168. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1169. // 后台线程执行数据库查询
  1170. var dt = await Task.Run(() =>
  1171. {
  1172. return ServerHelper.GetData(
  1173. "com.steering.Mcms.MatOutServer.doQueryWasteInfo",
  1174. new object[] { carNo },
  1175. ob
  1176. );
  1177. });
  1178. if (dt != null && dt.Rows.Count > 0)
  1179. {
  1180. var firstRow = dt.Rows[0];
  1181. cmmWeightRecordEntityFull.ShippersName = firstRow["STORAGE_NAME_FROM"].ToString2();
  1182. cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["OUTSTOCK_DOC"].ToString2();
  1183. cmmWeightRecordEntityFull.ReceiveName = firstRow["STORAGE_NAME_TO"].ToString2();
  1184. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(firstRow["ACT_COUNT"].ToString3());
  1185. cmmWeightRecordEntityFull.MatName = "废品管";
  1186. foreach (DataRow dtcRow in dt.Rows)
  1187. {
  1188. var cmmWeightMatEntity = new CmmWeightMatEntity
  1189. {
  1190. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  1191. Producname = dtcRow["PRODUCNAME"].ToString2(),
  1192. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1193. Gradename = dtcRow["GRADENAME"].ToString2(),
  1194. Steelcode = dtcRow["STEELCODE"].ToString2(),
  1195. Steelname = dtcRow["STEELNAME"].ToString2(),
  1196. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" +
  1197. dtcRow["ACT_LEN_MAX"].ToString3(),
  1198. ActWeight = decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3()),
  1199. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1200. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1201. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  1202. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  1203. };
  1204. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1205. }
  1206. }
  1207. // UI 更新(保持在 UI 线程)
  1208. matInfo15.SetDefault(cmmWeightRecordEntityFull);
  1209. }
  1210. // 显示装车单信息(异步版本)
  1211. public async Task ShowLoadvehicleInfo(string carNo)
  1212. {
  1213. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1214. // 后台线程查询第一个数据表
  1215. var dt = await Task.Run(() =>
  1216. {
  1217. return ServerHelper.GetData(
  1218. "com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleInfo",
  1219. new object[] { carNo },
  1220. ob);
  1221. });
  1222. if (dt != null && dt.Rows.Count > 0)
  1223. {
  1224. var firstRow = dt.Rows[0];
  1225. cmmWeightRecordEntityFull.ShippersName = firstRow["BASENAME"].ToString2();
  1226. cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["LOADVEHICLE_NO"].ToString2();
  1227. cmmWeightRecordEntityFull.ReceiveName = firstRow["RECEIV_NM"].ToString2();
  1228. cmmWeightRecordEntityFull.RecordNumber = decimal.Parse(firstRow["STACKING_PIECE"].ToString3());
  1229. cmmWeightRecordEntityFull.OrderName = firstRow["CUSTOMER_NM"].ToString2();
  1230. cmmWeightRecordEntityFull.MatName = "钢管";
  1231. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1232. // 后台线程查询第二个数据表
  1233. var dtc = await Task.Run(() =>
  1234. {
  1235. return ServerHelper.GetData(
  1236. "com.steering.Mcms.LoadVehicleServer.doQueryLoadvehicleMatInfo",
  1237. new object[] { cmmWeightRecordEntityFull.LoadvehicleNo },
  1238. ob);
  1239. });
  1240. if (dtc != null && dtc.Rows.Count > 0)
  1241. {
  1242. foreach (DataRow dtcRow in dtc.Rows)
  1243. {
  1244. var cmmWeightMatEntity = new CmmWeightMatEntity
  1245. {
  1246. StorageNo = dtcRow["STORAGE_NO"].ToString2(),
  1247. StorageName = dtcRow["STORAGE_NAME"].ToString2(),
  1248. StoveNo = dtcRow["STOVE_NO"].ToString2(),
  1249. OrderNo = dtcRow["ORDER_NO"].ToString2(),
  1250. OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
  1251. OrderSeqNo = dtcRow["ORDER_SEQ_NO"].ToString2(),
  1252. ProOrderNo = dtcRow["ORDER_NO"].ToString2() + "/" + dtcRow["ORDER_SEQ"].ToString2(),
  1253. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  1254. Producname = dtcRow["PRODUCNAME"].ToString2(),
  1255. StdCode = dtcRow["STD_CODE"].ToString2(),
  1256. StdName = dtcRow["STD_NAME"].ToString2(),
  1257. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1258. Gradename = dtcRow["GRADENAME"].ToString2(),
  1259. Steelcode = dtcRow["STEELCODE"].ToString2(),
  1260. Steelname = dtcRow["STEELNAME"].ToString2(),
  1261. SpecCode = dtcRow["SPEC_CODE"].ToString2(),
  1262. SpecName = dtcRow["SPEC_NAME"].ToString2(),
  1263. ModelCode = dtcRow["MODEL_CODE"].ToString2(),
  1264. ModelDesc = dtcRow["MODEL_DESC"].ToString2(),
  1265. ActLenMin = decimal.Parse(dtcRow["ACT_LEN_MIN"].ToString3()),
  1266. ActLenMax = decimal.Parse(dtcRow["ACT_LEN_MAX"].ToString3()),
  1267. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" + dtcRow["ACT_LEN_MAX"].ToString3(),
  1268. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1269. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1270. ActDimater = decimal.Parse(dtcRow["ACT_DIMATER"].ToString3()),
  1271. ActHeight = decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  1272. };
  1273. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1274. }
  1275. }
  1276. // 钩重数据查询,也用异步
  1277. try
  1278. {
  1279. var dth = await Task.Run(() =>
  1280. {
  1281. return ServerHelper.GetData(
  1282. "com.steering.Mcms.LoadVehicleServer.doQueryHook",
  1283. new object[] { cmmWeightRecordEntityFull.LoadvehicleNo },
  1284. ob);
  1285. });
  1286. if (dth != null && dth.Rows.Count > 0)
  1287. {
  1288. foreach (DataRow dthRow in dth.Rows)
  1289. {
  1290. var total = double.Parse(dthRow["HOOK_WEIGHT"].ToString3());
  1291. double num = int.Parse(cmmWeightRecordEntityFull.MatInfos
  1292. .Where(p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
  1293. .Sum(p => p.ActCount).ToString3());
  1294. var perWt = Math.Round(total / num, 3);
  1295. var list = cmmWeightRecordEntityFull.MatInfos
  1296. .Where(p => p.JudgeStoveNo == dthRow["JUDGE_STOVE_NO"].ToString2())
  1297. .ToList();
  1298. for (var i = 0; i < list.Count; i++)
  1299. {
  1300. if (i == 0)
  1301. list[i].ActWeight = decimal.Parse(
  1302. (total - perWt * (num - double.Parse(list[i].ActCount.ToString3()))).ToString3());
  1303. else
  1304. list[i].ActWeight = decimal.Parse(
  1305. (perWt * double.Parse(list[i].ActCount.ToString3())).ToString3());
  1306. }
  1307. }
  1308. }
  1309. }
  1310. catch (Exception e)
  1311. {
  1312. // 可选:日志记录异常
  1313. Console.WriteLine("异常" + e.StackTrace);
  1314. }
  1315. }
  1316. else
  1317. {
  1318. cmmWeightRecordEntityFull = null;
  1319. }
  1320. // UI 线程更新控件
  1321. matInfo16.SetDefault(cmmWeightRecordEntityFull);
  1322. }
  1323. public async Task ShowOutInfo(string carNo, decimal nutWt,String boCount)
  1324. {
  1325. string comboCountText = comboCount.Text;
  1326. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1327. // 异步查询数据
  1328. var dt = await Task.Run(() =>
  1329. ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfo", new object[] { carNo, boCount }, ob));
  1330. if (dt != null && dt.Rows.Count > 0)
  1331. {
  1332. var firstRow = dt.Rows[0];
  1333. cmmWeightRecordEntityFull.ShippersName = firstRow["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"
  1334. ? "江苏天淮钢管有限公司"
  1335. : firstRow["STORAGE_NAME_FROM"].ToString2();
  1336. cmmWeightRecordEntityFull.LoadvehicleNo = firstRow["OUTSTOCK_DOC"].ToString2();
  1337. cmmWeightRecordEntityFull.ReceiveName = firstRow["STORAGE_NAME_TO"].ToString2();
  1338. cmmWeightRecordEntityFull.OrderName = firstRow["STORAGE_NAME_D"].ToString2();
  1339. // 安全计算总件数,避免空序列异常
  1340. cmmWeightRecordEntityFull.RecordNumber = dt.AsEnumerable()
  1341. .Where(p => p["ACT_COUNT"] != DBNull.Value && !string.IsNullOrWhiteSpace(p["ACT_COUNT"].ToString()))
  1342. .Select(p => decimal.Parse(p["ACT_COUNT"].ToString3()))
  1343. .DefaultIfEmpty(0)
  1344. .Sum();
  1345. cmmWeightRecordEntityFull.MatName = firstRow["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"
  1346. ? "调拨钢管"
  1347. : "内转钢管";
  1348. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1349. // 安全计算总重量,避免空序列异常
  1350. var totalWt = dt.AsEnumerable()
  1351. .Where(p => p["ACT_WEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(p["ACT_WEIGHT"].ToString()))
  1352. .Select(p => decimal.Parse(p["ACT_WEIGHT"].ToString3()))
  1353. .DefaultIfEmpty(0)
  1354. .Sum();
  1355. var perWt = totalWt > 0 ? nutWt / totalWt : 0;
  1356. var remainWt = nutWt;
  1357. for (var i = 0; i < dt.Rows.Count; i++)
  1358. {
  1359. var dtcRow = dt.Rows[i];
  1360. decimal actWeight;
  1361. if (i == dt.Rows.Count - 1)
  1362. {
  1363. actWeight = remainWt;
  1364. }
  1365. else
  1366. {
  1367. var rawWeight = (dtcRow["ACT_WEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_WEIGHT"].ToString()))
  1368. ? decimal.Parse(dtcRow["ACT_WEIGHT"].ToString3())
  1369. : 0m;
  1370. actWeight = Math.Round(rawWeight * perWt, 3);
  1371. }
  1372. var cmmWeightMatEntity = new CmmWeightMatEntity
  1373. {
  1374. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  1375. Producname = dtcRow["PRODUCNAME"].ToString2(),
  1376. Gradecode = dtcRow["GRADECODE"].ToString2(),
  1377. Gradename = dtcRow["GRADENAME"].ToString2(),
  1378. Steelcode = dtcRow["STEELCODE"].ToString2(),
  1379. Steelname = dtcRow["STEELNAME"].ToString2(),
  1380. ActLenTemp = dtcRow["ACT_LEN_MIN"].ToString3() + "-" + dtcRow["ACT_LEN_MAX"].ToString3(),
  1381. ActWeight = actWeight,
  1382. ActCount = (dtcRow["ACT_COUNT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_COUNT"].ToString()))
  1383. ? decimal.Parse(dtcRow["ACT_COUNT"].ToString3())
  1384. : 0,
  1385. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1386. ActDimater = (dtcRow["ACT_DIMATER"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_DIMATER"].ToString()))
  1387. ? decimal.Parse(dtcRow["ACT_DIMATER"].ToString3())
  1388. : 0,
  1389. ActHeight = (dtcRow["ACT_HEIGHT"] != DBNull.Value && !string.IsNullOrWhiteSpace(dtcRow["ACT_HEIGHT"].ToString()))
  1390. ? decimal.Parse(dtcRow["ACT_HEIGHT"].ToString3())
  1391. : 0
  1392. };
  1393. l.WriteLog(3, "车号:"+ carNo+ " nutWt:"+ nutWt+ " boCount:" + boCount+ "actWeight:"+ actWeight+ " remainWt:"+ remainWt+ " totalWt:"+ totalWt);
  1394. remainWt -= actWeight;
  1395. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1396. }
  1397. // UI 线程更新
  1398. matInfo12.SetDefault(cmmWeightRecordEntityFull);
  1399. }
  1400. else
  1401. {
  1402. if (nutWt > 0)
  1403. matInfo12.SetWt(nutWt);
  1404. }
  1405. }
  1406. public void ShowOutInfoGp(string carNo, decimal nutWt)
  1407. {
  1408. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  1409. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", new object[] { carNo }, ob);
  1410. if ((dt != null) && (dt.Rows.Count > 0))
  1411. {
  1412. cmmWeightRecordEntityFull.ShippersName = dt.Rows[0]["STORAGE_NAME_FROM"].ToString2();
  1413. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  1414. cmmWeightRecordEntityFull.ReceiveName = dt.Rows[0]["STORAGE_NAME_TO"].ToString2();
  1415. cmmWeightRecordEntityFull.RecordNumber =
  1416. dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
  1417. decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  1418. cmmWeightRecordEntityFull.MatName = "内转钢坯";
  1419. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  1420. var perWt = Math.Round(nutWt / (decimal)cmmWeightRecordEntityFull.RecordNumber, 3);
  1421. var remainWt = nutWt;
  1422. for (var i = 0; i < dt.Rows.Count; i++)
  1423. {
  1424. var dtcRow = dt.Rows[i];
  1425. var cmmWeightMatEntity = new CmmWeightMatEntity
  1426. {
  1427. Steelcode = dtcRow["GRADECODE"].ToString2(),
  1428. Steelname = dtcRow["GRADENAME"].ToString2(),
  1429. ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
  1430. ActWeight =
  1431. i == dt.Rows.Count - 1 ? remainWt : decimal.Parse(dtcRow["ACT_COUNT"].ToString3()) * perWt,
  1432. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  1433. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  1434. ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
  1435. ActHeight = decimal.Parse(dtcRow["HEIGHT"].ToString3())
  1436. };
  1437. remainWt = remainWt - perWt;
  1438. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  1439. }
  1440. matInfo13.SetDefault(cmmWeightRecordEntityFull);
  1441. }
  1442. else
  1443. {
  1444. if (nutWt > 0)
  1445. matInfo13.SetWt(nutWt);
  1446. }
  1447. }
  1448. private void tbScondWt_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  1449. {
  1450. if (CurrentGrid.ActiveRow != null)
  1451. {
  1452. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1453. if (current != null)
  1454. if (tbScondWt.ActiveTab.Key == "3")
  1455. _ = ShowWasteInfo(current.CarNo);
  1456. else if (tbScondWt.ActiveTab.Key == "0")
  1457. _ = ShowLoadvehicleInfo(current.CarNo);
  1458. }
  1459. LoadTem();
  1460. }
  1461. private void utnQuery_Click(object sender, EventArgs e)
  1462. {
  1463. Query2();
  1464. }
  1465. private async void Query2()
  1466. {
  1467. try
  1468. {
  1469. var dic = new Dictionary<string, object>();
  1470. if (chkTim.Checked)
  1471. {
  1472. dic.Add("time", RegStartTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  1473. dic.Add("time1", RegEndTime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  1474. }
  1475. dic.Add("carNo", uteCarNo.Text);
  1476. dic.Add("matType", uceQueryCarType.Text);
  1477. dic.Add("resultNo", utePound.Text);
  1478. dic.Add("orderName", uteOrder.Text);
  1479. dic.Add("shippersName", uteShippersName.Text);
  1480. dic.Add("receiveName", uteReceiveName.Text);
  1481. dic.Add("memo", uteMemo.Text);
  1482. dic.Add("validflag", new List<string> { "1" });
  1483. dic.Add("judgeStoveNo", uteJudgeStoveNo.Text);
  1484. // 在后台线程执行查询
  1485. var list = await Task.Factory.StartNew(() =>
  1486. {
  1487. return EntityHelper.GetData<CmmWeightResultEntity>(
  1488. "com.steering.Mcms.ResultServer.doQuery",
  1489. new object[] { dic },
  1490. ob
  1491. );
  1492. });
  1493. // 回到 UI 线程更新控件
  1494. lblCount.Text = string.Format("共{0}条记录", list.Count);
  1495. QueryBS.DataSource = list;
  1496. Comm.RefreshAndAutoSize(ugData);
  1497. }
  1498. catch
  1499. {
  1500. // 建议这里至少写日志
  1501. }
  1502. }
  1503. private void tbMain_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  1504. {
  1505. if (tbMain.SelectedTab.Key == "1")
  1506. Query();
  1507. else
  1508. Query2();
  1509. }
  1510. private void utbReset_Click(object sender, EventArgs e)
  1511. {
  1512. RegStartTime.Value = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 07:00:00"));
  1513. RegEndTime.Value = DateTime.Parse(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd 07:00:00"));
  1514. uteCarNo.Text = "";
  1515. uceQueryCarType.Text = "";
  1516. utePound.Text = "";
  1517. uteOrder.Text = "";
  1518. uteShippersName.Text = "";
  1519. uteReceiveName.Text = "";
  1520. uteMemo.Text = "";
  1521. uteJudgeStoveNo.Text = "";
  1522. }
  1523. private void btnDelete_Click(object sender, EventArgs e)
  1524. {
  1525. if (ugData.ActiveRow == null) return;
  1526. var ub = sender as UltraButton;
  1527. if (ub == null) return;
  1528. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1529. if (data == null) return;
  1530. ("是否" + ub.Text + " 车辆 " + data.CarNo + " 的过磅单?").Speak();
  1531. if (MessageUtil.ShowYesNoAndQuestion("是否" + ub.Text + " 车牌[" + data.CarNo + "]过磅单?") == DialogResult.No)
  1532. return;
  1533. var ccp = new CoreClientParam
  1534. {
  1535. ServerName = "com.steering.Mcms.LocalTruckScale",
  1536. MethodName = "DoDeleteResult",
  1537. ServerParams = new object[]
  1538. {
  1539. data.ResultNo,
  1540. UserInfo.GetUserName(),
  1541. "重过" == ub.Text ? "2" : "1",
  1542. }
  1543. };
  1544. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1545. if (ccp.ReturnCode != -1)
  1546. {
  1547. MessageUtil.ShowTips(ccp.ReturnInfo);
  1548. if (ccp.ReturnInfo.Equals("操作成功!"))
  1549. {
  1550. Query2();
  1551. Query();
  1552. }
  1553. }
  1554. }
  1555. private void lvTemplate_ItemDoubleClick(object sender, ItemDoubleClickEventArgs e)
  1556. {
  1557. var matInfo = GetMatInfo();
  1558. if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(e.Item.Tag as CmmWeightRecordEntityFull, e.Item.Text);
  1559. }
  1560. private void cboPoundList_SelectedValueChanged(object sender, EventArgs e)
  1561. {
  1562. Query();
  1563. }
  1564. private void delete_EditorButtonClick(object sender, EditorButtonEventArgs e)
  1565. {
  1566. if (cmmPoundBase == null)
  1567. {
  1568. MessageBox.Show(@"无磅房权限");
  1569. return;
  1570. }
  1571. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1572. if ((current == null) || ("" == current.CarNo)) return;
  1573. if (MessageUtil.ShowYesNoAndQuestion("是否删除" + current.CarNo + " 过磅记录?") == DialogResult.No)
  1574. return;
  1575. var ccp = new CoreClientParam
  1576. {
  1577. ServerName = "com.steering.Mcms.RecordServer",
  1578. MethodName = "DoUpdateRecord",
  1579. ServerParams = new object[]
  1580. {
  1581. current.RecordNo
  1582. }
  1583. };
  1584. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  1585. if (ccp.ReturnCode != -1)
  1586. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  1587. Query();
  1588. else
  1589. MessageUtil.ShowTips(ccp.ReturnInfo);
  1590. }
  1591. private void ugData_InitializeRow(object sender, InitializeRowEventArgs e)
  1592. {
  1593. var data = e.Row.ListObject as CmmWeightResultEntity;
  1594. if (data == null) return;
  1595. if (data.RecordType2 == "201") e.Row.Appearance.BackColor = Color.ForestGreen;
  1596. }
  1597. private void uteCarNo_KeyPress(object sender, KeyPressEventArgs e)
  1598. {
  1599. if (e.KeyChar == 13)
  1600. Query2();
  1601. }
  1602. private void utnUpdate_Click(object sender, EventArgs e)
  1603. {
  1604. if (ugData.ActiveRow == null)
  1605. {
  1606. MessageBox.Show("请选择需要修改磅单记录!");
  1607. return;
  1608. }
  1609. var cmm = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1610. var matInfo = GetMatInfoByKey("101" == cmm.RecordType1 ? cmm.RecordType2 : cmm.RecordType1);
  1611. if (matInfo == null)
  1612. {
  1613. MessageBox.Show("该类型不允许修改!");
  1614. return;
  1615. }
  1616. var recordNo = "101" == cmm.RecordType1 ? cmm.RecordNo2 : cmm.RecordNo1;
  1617. if ("207" == cmm.RecordType2 && (cmm.MatType == "钢坯采购"|| cmm.MatType == "钢坯退货" ||
  1618. cmm.MatType == "钢管退货" || cmm.MatType == "采购辅料" || cmm.MatType == "修复返厂" ||
  1619. cmm.MatType == "设备采购" || cmm.MatType == "其他内转" || cmm.MatType == "内转钢管"
  1620. || cmm.MatType == "外购钢管"))
  1621. {
  1622. recordNo = cmm.RecordNo2;
  1623. }
  1624. using (var frmUpdate = new FrmUpdate(ob, cmm, recordNo, canUpdateWt)
  1625. {
  1626. ColumnsM = matInfo.ColumnsM,
  1627. ColumnsC = matInfo.ColumnsC
  1628. })
  1629. {
  1630. frmUpdate.ShowDialog();
  1631. if (frmUpdate.DialogResult == DialogResult.OK)
  1632. Query2();
  1633. }
  1634. }
  1635. private void utbPrint_Click(object sender, EventArgs e)
  1636. {
  1637. if (ugData.ActiveRow == null) return;
  1638. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1639. if (data == null) return;
  1640. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  1641. DialogResult.No))
  1642. {
  1643. }
  1644. else
  1645. {
  1646. Print(data.ResultNo);
  1647. }
  1648. }
  1649. private void utbPrintSingle_Click(object sender, EventArgs e)
  1650. {
  1651. if (ugData.ActiveRow == null) return;
  1652. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  1653. if (data == null) return;
  1654. if ((data.RecordType2 == "205") || (data.RecordType2 == "201") || (data.RecordType2 == "200"))
  1655. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  1656. DialogResult.No))
  1657. {
  1658. }
  1659. else
  1660. {
  1661. Print(data.ResultNo, true);
  1662. }
  1663. }
  1664. private void unExcel_Click(object sender, EventArgs e)
  1665. {
  1666. var hssfworkbook = new HSSFWorkbook();
  1667. var sheet = hssfworkbook.CreateSheet("磅房统计");
  1668. var index = 0;
  1669. SetHead(sheet, hssfworkbook, index++);
  1670. SetHeadRow(sheet, hssfworkbook
  1671. , new List<string> { "磅房号", "称重类型", "物资名称", "物资数量", "称重次数", "物资净重" },
  1672. new List<int> { 9, 15, 25, 15, 15, 15 },
  1673. index++
  1674. );
  1675. setData(sheet, hssfworkbook, ref index);
  1676. SetSumm(sheet, index, hssfworkbook);
  1677. sheet.ForceFormulaRecalculation = true;
  1678. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateAll();
  1679. using (var saveFileDialog1 = new SaveFileDialog())
  1680. {
  1681. saveFileDialog1.FileName = "磅房统计" + DateTime.Now.ToString("yyMMdd");
  1682. saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
  1683. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  1684. {
  1685. var sFullName = saveFileDialog1.FileName;
  1686. var ms = new MemoryStream();
  1687. hssfworkbook.Write(ms);
  1688. using (var fs = new FileStream(saveFileDialog1.FileName, FileMode.Create, FileAccess.Write))
  1689. {
  1690. var bArr = ms.ToArray();
  1691. fs.Write(bArr, 0, bArr.Length);
  1692. fs.Flush();
  1693. }
  1694. var p = new ProcessStartInfo(sFullName);
  1695. p.WorkingDirectory = Path.GetDirectoryName(sFullName);
  1696. Process.Start(p);
  1697. }
  1698. }
  1699. }
  1700. private void SetSumm(ISheet sheet, int index, HSSFWorkbook hssfworkbook)
  1701. {
  1702. var IRow = sheet.CreateRow(index);
  1703. IRow.Height = 20 * 20;
  1704. var Icell1 = IRow.CreateCell(1);
  1705. Icell1.SetCellValue("合计");
  1706. var style = CenterStyle(hssfworkbook);
  1707. var font = ContextFont(hssfworkbook);
  1708. style.SetFont(font);
  1709. style.BorderTop = BorderStyle.Medium;
  1710. style.BorderBottom = BorderStyle.Medium;
  1711. style.BorderLeft = BorderStyle.Medium;
  1712. style.BorderRight = BorderStyle.Thin;
  1713. //将新的样式赋给单元格
  1714. Icell1.CellStyle = style;
  1715. var Icell12 = IRow.CreateCell(2);
  1716. var style12 = CenterStyle(hssfworkbook);
  1717. style12.SetFont(font);
  1718. style12.BorderTop = BorderStyle.Medium;
  1719. style12.BorderBottom = BorderStyle.Medium;
  1720. style12.BorderLeft = BorderStyle.Thin;
  1721. style12.BorderRight = BorderStyle.Thin;
  1722. //将新的样式赋给单元格
  1723. Icell12.CellStyle = style12;
  1724. var Icell13 = IRow.CreateCell(3);
  1725. var style13 = CenterStyle(hssfworkbook);
  1726. style13.SetFont(font);
  1727. style13.BorderTop = BorderStyle.Medium;
  1728. style13.BorderBottom = BorderStyle.Medium;
  1729. style13.BorderLeft = BorderStyle.Thin;
  1730. style13.BorderRight = BorderStyle.Thin;
  1731. //将新的样式赋给单元格
  1732. Icell13.CellStyle = style13;
  1733. //合并单元格
  1734. sheet.AddMergedRegion(new CellRangeAddress(index, index, 1, 3));
  1735. var list = new List<string>();
  1736. for (var i = 2; i < index; i++)
  1737. list.Add(i + 1 + "");
  1738. var Icell2 = IRow.CreateCell(4);
  1739. if (list.Any())
  1740. {
  1741. //Icell2.SetCellType(CellType.Formula);
  1742. //Icell2.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "E" + p).ToList())));
  1743. //hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell2);
  1744. Icell2.SetCellType(CellType.Formula);
  1745. Icell2.SetCellFormula(string.Format("SUM({0})", "E"+list[0]+":E"+list[list.Count-1]));
  1746. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell2);
  1747. }
  1748. var style2 = numStyle(hssfworkbook);
  1749. var font2 = ContextFont(hssfworkbook);
  1750. style2.SetFont(font2);
  1751. style2.BorderTop = BorderStyle.Medium;
  1752. style2.BorderBottom = BorderStyle.Medium;
  1753. style2.BorderLeft = BorderStyle.Thin;
  1754. style2.BorderRight = BorderStyle.Thin;
  1755. //将新的样式赋给单元格
  1756. Icell2.CellStyle = style2;
  1757. var Icell3 = IRow.CreateCell(5);
  1758. if (list.Any())
  1759. {
  1760. Icell3.SetCellType(CellType.Formula);
  1761. // Icell3.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "F" + p).ToList())));
  1762. Icell3.SetCellFormula(string.Format("SUM({0})", "F" + list[0] + ":F" + list[list.Count - 1]));
  1763. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell3);
  1764. }
  1765. var style3 = numStyle(hssfworkbook);
  1766. var font3 = ContextFont(hssfworkbook);
  1767. style3.SetFont(font3);
  1768. style3.BorderTop = BorderStyle.Medium;
  1769. style3.BorderBottom = BorderStyle.Medium;
  1770. style3.BorderLeft = BorderStyle.Thin;
  1771. style3.BorderRight = BorderStyle.Thin;
  1772. //将新的样式赋给单元格
  1773. Icell3.CellStyle = style3;
  1774. var Icell4 = IRow.CreateCell(6);
  1775. if (list.Any())
  1776. {
  1777. Icell4.SetCellType(CellType.Formula);
  1778. // Icell4.SetCellFormula(string.Format("SUM({0})", string.Join(",", list.Select(p => "G" + p).ToList())));
  1779. Icell4.SetCellFormula(string.Format("SUM({0})", "G" + list[0] + ":G" + list[list.Count - 1]));
  1780. hssfworkbook.GetCreationHelper().CreateFormulaEvaluator().EvaluateFormulaCell(Icell4);
  1781. }
  1782. var style4 = numStyle(hssfworkbook);
  1783. var font4 = ContextFont(hssfworkbook);
  1784. style4.SetFont(font4);
  1785. style4.BorderTop = BorderStyle.Medium;
  1786. style4.BorderBottom = BorderStyle.Medium;
  1787. style4.BorderLeft = BorderStyle.Thin;
  1788. style4.BorderRight = BorderStyle.Medium;
  1789. //将新的样式赋给单元格
  1790. Icell4.CellStyle = style4;
  1791. }
  1792. private void setData(ISheet sheet, HSSFWorkbook hssfworkbook, ref int index)
  1793. {
  1794. var index1 = index;
  1795. var data = QueryBS.DataSource as List<CmmWeightResultEntity>;
  1796. if ((data != null) && data.Any())
  1797. data.GroupBy(p => new { p.RecoderLocation2, p.MatName, p.MatType })
  1798. .Select(p => new
  1799. {
  1800. p.Key.MatName,
  1801. p.Key.MatType,
  1802. p.Key.RecoderLocation2,
  1803. count = p.Count(),
  1804. num = int.Parse(p.Select(q => q.MatNum ?? 0).Sum().ToString3()),
  1805. wt = double.Parse(p.Select(q => q.NetWt).Sum().ToString3())
  1806. }).ToList()
  1807. .ForEach(
  1808. p =>
  1809. {
  1810. var IRow = sheet.CreateRow(index1++);
  1811. IRow.Height = 20 * 20;
  1812. for (var i = 0; i < 6; i++)
  1813. {
  1814. var Icell = IRow.CreateCell(i + 1);
  1815. if (i <= 2)
  1816. {
  1817. Icell.SetCellType(CellType.String);
  1818. Icell.SetCellValue(
  1819. i == 0
  1820. ? p.RecoderLocation2
  1821. : i == 1
  1822. ? p.MatType
  1823. : p.MatName);
  1824. }
  1825. else
  1826. {
  1827. Icell.SetCellType(CellType.Numeric);
  1828. if (i == 3)
  1829. Icell.SetCellValue(p.num);
  1830. if (i == 4)
  1831. Icell.SetCellValue(p.count);
  1832. if (i == 5)
  1833. Icell.SetCellValue(p.wt);
  1834. }
  1835. ;
  1836. var style = i <= 2 ? textStyle(hssfworkbook) : numStyle(hssfworkbook);
  1837. style.BorderTop = BorderStyle.Thin;
  1838. style.BorderBottom = BorderStyle.Thin;
  1839. style.BorderLeft = i == 0 ? BorderStyle.Medium : BorderStyle.Thin;
  1840. style.BorderRight = i == 5 ? BorderStyle.Medium : BorderStyle.Thin;
  1841. var font = ContextFont(hssfworkbook);
  1842. //使用SetFont方法将字体样式添加到单元格样式中
  1843. style.SetFont(font);
  1844. //将新的样式赋给单元格
  1845. Icell.CellStyle = style;
  1846. }
  1847. }
  1848. );
  1849. index = index1;
  1850. }
  1851. private void SetHeadRow(ISheet sheet, HSSFWorkbook hssfworkbook, List<string> name, List<int> columsWidth,
  1852. int rowIndex)
  1853. {
  1854. var IRow = sheet.CreateRow(rowIndex);
  1855. IRow.Height = 20 * 20;
  1856. for (var i = 0; i < name.Count; i++)
  1857. {
  1858. sheet.SetColumnWidth(i + 1, columsWidth[i] * 256);
  1859. var Icell = IRow.CreateCell(i + 1);
  1860. Icell.SetCellValue(name[i]);
  1861. var style = CenterStyle(hssfworkbook);
  1862. style.BorderTop = BorderStyle.Medium;
  1863. style.BorderBottom = BorderStyle.Medium;
  1864. style.BorderLeft = BorderStyle.Medium;
  1865. style.BorderRight = BorderStyle.Medium;
  1866. var font = ContextFont(hssfworkbook);
  1867. //使用SetFont方法将字体样式添加到单元格样式中
  1868. style.SetFont(font);
  1869. //将新的样式赋给单元格
  1870. Icell.CellStyle = style;
  1871. }
  1872. }
  1873. private void SetHead(ISheet sheet, HSSFWorkbook hssfworkbook, int rowindex)
  1874. {
  1875. var IRow = sheet.CreateRow(rowindex);
  1876. IRow.Height = 50 * 20;
  1877. var Icell = IRow.CreateCell(1);
  1878. Icell.SetCellValue("磅房统计");
  1879. var style = CenterStyle(hssfworkbook);
  1880. var font = TitleFont(hssfworkbook);
  1881. //使用SetFont方法将字体样式添加到单元格样式中
  1882. style.SetFont(font);
  1883. //将新的样式赋给单元格
  1884. Icell.CellStyle = style;
  1885. //合并单元格
  1886. sheet.AddMergedRegion(new CellRangeAddress(0, 0, 1, 6));
  1887. }
  1888. private static IFont TitleFont(HSSFWorkbook hssfworkbook)
  1889. {
  1890. //新建一个字体样式对象
  1891. var font = hssfworkbook.CreateFont();
  1892. font.FontName = "宋体";
  1893. font.FontHeightInPoints = 30;
  1894. //设置字体加粗样式
  1895. font.Boldweight = (short)FontBoldWeight.Bold;
  1896. return font;
  1897. }
  1898. private static IFont ContextFont(HSSFWorkbook hssfworkbook)
  1899. {
  1900. //新建一个字体样式对象
  1901. var font = hssfworkbook.CreateFont();
  1902. font.FontName = "宋体";
  1903. font.FontHeightInPoints = 12;
  1904. //设置字体加粗样式
  1905. font.Boldweight = (short)FontBoldWeight.Bold;
  1906. return font;
  1907. }
  1908. private ICellStyle CenterStyle(HSSFWorkbook hssfworkbook)
  1909. {
  1910. var style = hssfworkbook.CreateCellStyle();
  1911. //设置单元格的样式:水平对齐居中
  1912. style.Alignment = HorizontalAlignment.Center;
  1913. style.VerticalAlignment = VerticalAlignment.Center;
  1914. return style;
  1915. }
  1916. private ICellStyle textStyle(HSSFWorkbook hssfworkbook)
  1917. {
  1918. var style = hssfworkbook.CreateCellStyle();
  1919. //设置单元格的样式:水平对齐居中
  1920. style.Alignment = HorizontalAlignment.Left;
  1921. style.VerticalAlignment = VerticalAlignment.Center;
  1922. return style;
  1923. }
  1924. private ICellStyle numStyle(HSSFWorkbook hssfworkbook)
  1925. {
  1926. var style = hssfworkbook.CreateCellStyle();
  1927. //设置单元格的样式:水平对齐居中
  1928. style.Alignment = HorizontalAlignment.Right;
  1929. style.VerticalAlignment = VerticalAlignment.Center;
  1930. return style;
  1931. }
  1932. private void CurrentGrid_InitializeLayout(object sender, InitializeLayoutEventArgs e)
  1933. {
  1934. }
  1935. private void CurrentGrid_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
  1936. {
  1937. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  1938. if ((current == null) || ("" == current.CarNo)) return;
  1939. foreach (var cbxCar1Item in cbxCar1.Items)
  1940. if (current.CarNo.StartsWith(cbxCar1Item.ToString2().Trim()))
  1941. {
  1942. cbxCar1.SelectedItem = cbxCar1Item;
  1943. txtCar2.Text = current.CarNo.Replace(cbxCar1Item.ToString2().Trim(), "").Trim();
  1944. }
  1945. if (!tbWt.Tabs["2"].Selected)
  1946. {
  1947. tbWt.Tabs["2"].Selected = true;
  1948. if (current.RecordType != "101")
  1949. tbScondWt.Tabs["2"].Selected = true;
  1950. else
  1951. tbScondWt_SelectedTabChanged(null, null);
  1952. }
  1953. }
  1954. private void utbExport_Click(object sender, EventArgs e)
  1955. {
  1956. GridHelper.ulGridToExcel(ugData, "称重记录");
  1957. }
  1958. private void utbExport2_Click(object sender, EventArgs e)
  1959. {
  1960. GridHelper.ulGridToExcel(CurrentGrid, "称重记录");
  1961. }
  1962. private void cbxCar1_SelectedValueChanged(object sender, EventArgs e)
  1963. {
  1964. txtCar2.Focus();
  1965. if (cbxCar1.Text.Trim() == "厂内")
  1966. txtCar2.Text = "自用车";
  1967. }
  1968. private void splitContainer2_SplitterMoved(object sender, SplitterEventArgs e)
  1969. {
  1970. if (isLoading) return;
  1971. XmlHelper.SetXmlData(_path, "splitContainer2", splitContainer2.SplitterDistance);
  1972. }
  1973. private void splitContainer1_SplitterMoved(object sender, SplitterEventArgs e)
  1974. {
  1975. if (isLoading) return;
  1976. XmlHelper.SetXmlData(_path, "splitContainer1", splitContainer1.SplitterDistance);
  1977. }
  1978. private void frmLocalTruckScale_Shown(object sender, EventArgs e)
  1979. {
  1980. // timer.Start();
  1981. splitContainer1.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer1",
  1982. splitContainer1.SplitterDistance);
  1983. splitContainer2.SplitterDistance = XmlHelper.GetXmlData(_path, "splitContainer2",
  1984. splitContainer2.SplitterDistance);
  1985. var x = new FontConverter();
  1986. CurrentGrid.Font =
  1987. x.ConvertFromString(XmlHelper.GetXmlData(_path, CurrentGrid.Name, x.ConvertToString(CurrentGrid.Font)))
  1988. as Font;
  1989. ugData.Font =
  1990. x.ConvertFromString(XmlHelper.GetXmlData(_path, ugData.Name, x.ConvertToString(ugData.Font))) as Font;
  1991. isLoading = false;
  1992. CurrentGrid.DisplayLayout.Bands[0].Columns["RecordType"].EditorComponent = uceType2;
  1993. CurrentGrid.DisplayLayout.Bands[0].Columns["RecordNo"].EditorComponent = delete;
  1994. CurrentGrid.DisplayLayout.Bands[0].Columns["CarNo"].EditorComponent = uteEdit;
  1995. Query();
  1996. Query2();
  1997. try
  1998. {
  1999. if (toolMenu == null) return;
  2000. if (toolMenu.Toolbars[0].Tools.Exists("UpdateWt"))
  2001. canUpdateWt = true;
  2002. toolMenu.Visible = false;
  2003. }
  2004. catch (Exception ex)
  2005. {
  2006. Console.WriteLine("异常" + ex.StackTrace);
  2007. }
  2008. }
  2009. private void CurrentGrid_KeyDown(object sender, KeyEventArgs e)
  2010. {
  2011. if (e.KeyCode == Keys.F5)
  2012. using (var dr = new FontDialog { Font = (sender as Control).Font })
  2013. {
  2014. if (dr.ShowDialog() == DialogResult.OK)
  2015. {
  2016. (sender as Control).Font = dr.Font;
  2017. var x = new FontConverter();
  2018. var font = x.ConvertToString(dr.Font);
  2019. // t = x.ConvertFromString(s) as Font;
  2020. XmlHelper.SetXmlData(_path, (sender as Control).Name, font);
  2021. }
  2022. }
  2023. }
  2024. private void txtCar2_TextChanged(object sender, EventArgs e)
  2025. {
  2026. foreach (var currentGridRow in CurrentGrid.Rows)
  2027. if (currentGridRow.Cells["CarNo"].Value.ToString2() == cbxCar1.Text + txtCar2.Text.Trim())
  2028. if (!tbWt.Tabs["2"].Selected)
  2029. {
  2030. tbWt.Tabs["2"].Selected = true;
  2031. currentGridRow.Activated = true;
  2032. if (currentGridRow.Cells["RecordType"].Value.ToString2() != "101")
  2033. tbScondWt.Tabs["2"].Selected = true;
  2034. else
  2035. tbScondWt_SelectedTabChanged(null, null);
  2036. return;
  2037. }
  2038. tbWt.Tabs["1"].Selected = true;
  2039. }
  2040. private void uteEdit_EditorButtonClick(object sender, EditorButtonEventArgs e)
  2041. {
  2042. if (cmmPoundBase == null)
  2043. {
  2044. MessageBox.Show(@"无磅房权限");
  2045. return;
  2046. }
  2047. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  2048. string carNo;
  2049. using (var update = new UpdateCar { CarNo = current.CarNo })
  2050. {
  2051. var result = update.ShowDialog();
  2052. if (result != DialogResult.OK) return;
  2053. carNo = update.CarNo;
  2054. }
  2055. var ccp = new CoreClientParam
  2056. {
  2057. ServerName = "com.steering.Mcms.RecordServer",
  2058. MethodName = "DoUpdateCarNo",
  2059. ServerParams = new object[]
  2060. {
  2061. current.RecordNo,
  2062. carNo
  2063. }
  2064. };
  2065. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2066. if (ccp.ReturnCode != -1)
  2067. {
  2068. MessageUtil.ShowTips(ccp.ReturnInfo);
  2069. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  2070. Query();
  2071. }
  2072. }
  2073. public bool CheckShowKey(string key1, string key2)
  2074. {
  2075. if (key1 == key2) return true;
  2076. if (((key1 == "107") && (key2 == "204")) || ((key2 == "107") && (key1 == "204"))) return true;
  2077. if (((key1 == "108") && (key2 == "205")) || ((key2 == "108") && (key1 == "205"))) return true;
  2078. if (((key1 == "206") && (key2 == "206")) || ((key2 == "109") && (key1 == "206"))) return true;
  2079. return false;
  2080. }
  2081. private void txtCar2_KeyPress(object sender, KeyPressEventArgs e)
  2082. {
  2083. if ((e.KeyChar >= 97) && (e.KeyChar <= 122))
  2084. e.KeyChar = (char)(e.KeyChar - 32);
  2085. }
  2086. private void CurrentGrid_InitializeRow(object sender, InitializeRowEventArgs e)
  2087. {
  2088. var cmmWeightRecord = e.Row.ListObject as CmmWeightRecordEntity;
  2089. if (cmmWeightRecord == null) return;
  2090. if ((cmmWeightRecord.EffRemaind != null) && (cmmWeightRecord.EffRemaind <= 1))
  2091. e.Row.Cells["RecordDate"].Appearance.BackColor = Color.Red;
  2092. }
  2093. private void utbSelect_Click(object sender, EventArgs e)
  2094. {
  2095. using (var BlankPredictionSelect = new BlankPredictionSelect(ob, matInfo3.GetData()))
  2096. {
  2097. if (BlankPredictionSelect.ShowDialog() == DialogResult.OK)
  2098. matInfo3.UpdateData(new CmmWeightRecordEntityFull
  2099. {
  2100. MatName = "连铸圆坯",
  2101. ShippersName = BlankPredictionSelect.ShipperName,
  2102. RecordNumber = BlankPredictionSelect.ListMatNo == null ? null : BlankPredictionSelect.ListMatNo.Sum(p => p.ActCount),
  2103. ReceiveName = "江苏天淮钢管有限公司",
  2104. Memo = BlankPredictionSelect.Memo,
  2105. MatInfos =
  2106. BlankPredictionSelect.ListMatNo ?? new List<CmmWeightMatEntity> { new CmmWeightMatEntity() }
  2107. });
  2108. }
  2109. }
  2110. private void uteChangeType_EditorButtonClick(object sender, EditorButtonEventArgs e)
  2111. {
  2112. if (cmmPoundBase == null)
  2113. {
  2114. MessageBox.Show(@"无磅房权限");
  2115. return;
  2116. }
  2117. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  2118. string type;
  2119. string name;
  2120. using (var changeType = new ChangeType { Type = current.RecordType })
  2121. {
  2122. var result = changeType.ShowDialog();
  2123. if (result != DialogResult.OK) return;
  2124. type = changeType.Type;
  2125. name = changeType.TypeName;
  2126. }
  2127. var ccp = new CoreClientParam
  2128. {
  2129. ServerName = "com.steering.Mcms.RecordServer",
  2130. MethodName = "DoUpdateType",
  2131. ServerParams = new object[]
  2132. {
  2133. current.RecordNo,
  2134. type,
  2135. name
  2136. }
  2137. };
  2138. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2139. if (ccp.ReturnCode != -1)
  2140. {
  2141. MessageUtil.ShowTips(ccp.ReturnInfo);
  2142. if (ccp.ReturnInfo.ToString2().Contains("成功"))
  2143. Query();
  2144. }
  2145. }
  2146. private void ugData_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
  2147. {
  2148. var dex = e.RowScrollRegion.FirstRow;
  2149. dex.Activate();
  2150. }
  2151. private void CurrentGrid_AfterRowRegionScroll(object sender, RowScrollRegionEventArgs e)
  2152. {
  2153. /* UltraGridRow dex = e.RowScrollRegion.FirstRow;
  2154. dex.Activate();*/
  2155. }
  2156. private void ugData_AfterRowActivate(object sender, EventArgs e)
  2157. {
  2158. ugData.ActiveRow.RowSelectorAppearance.BackColor = Color.LightGreen;
  2159. }
  2160. private void ugData_BeforeRowDeactivate(object sender, CancelEventArgs e)
  2161. {
  2162. ugData.ActiveRow.RowSelectorAppearance.ResetBackColor();
  2163. }
  2164. private void CurrentGrid_BeforeRowDeactivate(object sender, CancelEventArgs e)
  2165. {
  2166. CurrentGrid.ActiveRow.RowSelectorAppearance.ResetBackColor();
  2167. }
  2168. private void utbSelect2_Click(object sender, EventArgs e)
  2169. {
  2170. var carNo = cbxCar1.Text + txtCar2.Text.ToUpper().Trim();
  2171. var cmmWeightRecordEntityFull = new CmmWeightRecordEntityFull();
  2172. var dt = ServerHelper.GetData("com.steering.Mcms.MatOutServer.doQueryOutInfoGp", new object[] { carNo }, ob);
  2173. if ((dt != null) && (dt.Rows.Count > 0) && (dt.Rows[0]["STORAGE_NAME_D"].ToString2() == "天津钢管制造有限公司"))
  2174. {
  2175. cmmWeightRecordEntityFull.ShippersName = "天津钢管制造有限公司";
  2176. cmmWeightRecordEntityFull.LoadvehicleNo = dt.Rows[0]["OUTSTOCK_DOC"].ToString2();
  2177. cmmWeightRecordEntityFull.ReceiveName = "江苏天淮钢管有限公司";
  2178. cmmWeightRecordEntityFull.RecordNumber =
  2179. dt.AsEnumerable().Select(p => decimal.Parse(p["ACT_COUNT"].ToString3())).Sum();
  2180. decimal.Parse(dt.Rows[0]["ACT_COUNT"].ToString3());
  2181. cmmWeightRecordEntityFull.MatName = "连铸圆坯";
  2182. cmmWeightRecordEntityFull.MatInfos = new List<CmmWeightMatEntity>();
  2183. for (var i = 0; i < dt.Rows.Count; i++)
  2184. {
  2185. var dtcRow = dt.Rows[i];
  2186. var cmmWeightMatEntity = new CmmWeightMatEntity
  2187. {
  2188. JudgeStoveNoOld = dtcRow["STOVE_NO"].ToString2(),
  2189. JudgeStoveNo = dtcRow["JUDGE_STOVE_NO"].ToString2(),
  2190. ActDimater = decimal.Parse(dtcRow["DIMATER"].ToString3()),
  2191. ActLenTemp = dtcRow["ACT_LEN"].ToString3(),
  2192. ActCount = decimal.Parse(dtcRow["ACT_COUNT"].ToString3()),
  2193. DocumentNo = dtcRow["OUTSTOCK_DOC"].ToString2(),
  2194. ProOrderNo = dtcRow["ORDER_NO"].ToString2(),
  2195. OrderNo = dtcRow["ORDER_NO"].ToString2(),
  2196. OrderSeq = dtcRow["ORDER_SEQ"].ToString2(),
  2197. OrdNoPk = dtcRow["ORD_PK"].ToString2(),
  2198. Produccode = dtcRow["PRODUCCODE"].ToString2(),
  2199. Producname = dtcRow["PRODUCNAME"].ToString2(),
  2200. Gradecode = dtcRow["GRADECODE"].ToString2(),
  2201. Gradename = dtcRow["GRADENAME"].ToString2(),
  2202. Steelcode = dtcRow["GRADECODE"].ToString2(),
  2203. Steelname = dtcRow["GRADENAME"].ToString2()
  2204. };
  2205. cmmWeightRecordEntityFull.MatInfos.Add(cmmWeightMatEntity);
  2206. }
  2207. matInfo3.SetDefault(cmmWeightRecordEntityFull);
  2208. }
  2209. else
  2210. {
  2211. MessageBox.Show("未找到该车的出库记录!");
  2212. }
  2213. }
  2214. //TODO
  2215. /// <summary>
  2216. /// 必须先打开连接
  2217. /// </summary>
  2218. private bool GetIPVideo(CmmBaseSpotInfoEntity video)
  2219. {
  2220. try
  2221. {
  2222. DhCameraShot tt = new DhCameraShot();
  2223. CarCache.cameraShots = tt;
  2224. CarCache.cameraShots.ip = video.VideoIp;
  2225. CarCache.cameraShots.port = video.VideoPort;
  2226. CarCache.cameraShots.uid = video.VideoUserName;
  2227. CarCache.cameraShots.pwd = video.VideoPassword;
  2228. CarCache.cameraShots.Connection();
  2229. }
  2230. catch (Exception ex)
  2231. {
  2232. Console.WriteLine("异常" + ex.StackTrace);
  2233. // setMsgInfo(txtMsgInfo, "视频连接打开失败:" + ex.Message, "");
  2234. //MessageBox.Show(ex.Message);
  2235. return false;
  2236. }
  2237. return true;
  2238. }
  2239. //如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  2240. public void setMsgInfo(Control control, string ResultMessage, string sType)
  2241. {
  2242. setMsgMsg(control, ResultMessage, sType);
  2243. }
  2244. /// <summary>
  2245. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable 3为check
  2246. /// </summary>
  2247. /// <param name="control"></param>
  2248. /// <param name="ResultMessage"></param>
  2249. /// <param name="sType"></param>
  2250. private void setMsgMsg(Control control, string ResultMessage, string sType)
  2251. {
  2252. if (control.InvokeRequired)
  2253. {
  2254. Action<Control, string, string> action = new Action<Control, string, string>(setMsgInfo);
  2255. Invoke(action, new object[] { control, ResultMessage, sType });
  2256. }
  2257. else
  2258. {
  2259. if (ResultMessage != "true" && ResultMessage != "false")
  2260. {
  2261. control.Text = ResultMessage == null ? "" : ResultMessage.Replace("请远程求助", "").Replace(",请点击语音求助", "");
  2262. }
  2263. else
  2264. {
  2265. switch (sType)
  2266. {
  2267. case "1":
  2268. control.Enabled = ResultMessage == "true" ? true : false;
  2269. ; break;
  2270. case "2":
  2271. control.Visible = ResultMessage == "true" ? true : false;
  2272. ; break;
  2273. case "3":
  2274. ((CheckBox)control).Checked = ResultMessage == "true" ? true : false;
  2275. break;
  2276. default: break;
  2277. }
  2278. }
  2279. }
  2280. }
  2281. //private bool bVoice = false;
  2282. /// <summary>
  2283. /// 必须先打开视频,然后再打开语音
  2284. /// </summary>
  2285. private void VoiceOpen()
  2286. {
  2287. try
  2288. {
  2289. //if (CarCache.cameraShots.StartTalk())
  2290. //{
  2291. // // btnOpenVoice.Text = "关闭对讲";
  2292. // bVoice = true;
  2293. // }
  2294. }
  2295. catch (Exception ex)
  2296. {
  2297. // setMsgInfo(txtMsgInfo, "打开语音失败:" + ex.Message, "");
  2298. //MessageBox.Show("打开语音失败:" + ex.Message);
  2299. }
  2300. }
  2301. /// <summary>
  2302. /// 关闭语音对讲
  2303. /// </summary>
  2304. private void VoiceClose()
  2305. {
  2306. try
  2307. {
  2308. //if (CarCache.cameraShots.StopTalk())
  2309. //{
  2310. // // setMsgInfo(btnOpenVoice, "打开对讲", "");
  2311. // bVoice = false;
  2312. //}
  2313. }
  2314. catch (Exception ex)
  2315. {
  2316. // setMsgInfo(txtMsgInfo, "打开对讲失败:" + ex.Message, "");
  2317. //MessageBox.Show(ex.Message);
  2318. }
  2319. }
  2320. /// <summary>
  2321. /// 对讲
  2322. /// </summary>
  2323. private void btnOpenVoice_Click(object sender, EventArgs e)
  2324. {
  2325. if (panel1.Controls.Count > 0)
  2326. {
  2327. //if (btnOpenVoice.Text == "打开对讲")
  2328. //{
  2329. // VoiceOpen();
  2330. //}
  2331. //else
  2332. //{
  2333. // VoiceClose();
  2334. //}
  2335. }
  2336. }
  2337. /// <summary>
  2338. /// 关闭视频
  2339. /// </summary>
  2340. private void IPVideoClose()
  2341. {
  2342. try
  2343. {
  2344. CarCache.cameraShots.Close();
  2345. }
  2346. catch (Exception ex)
  2347. {
  2348. // setMsgInfo(txtMsgInfo, "关闭对讲失败:" + ex.Message, "");
  2349. //MessageBox.Show(ex.Message);
  2350. }
  2351. }
  2352. private void setPicBoxSet()
  2353. {
  2354. for (int i = 1; i < 5; i++)
  2355. {
  2356. PictureBox pb = new PictureBox();
  2357. pb.Name = "pb" + i;
  2358. pb.Dock = DockStyle.Top;
  2359. pb.Height = 180;
  2360. pb.DoubleClick += new EventHandler(PictureBoxDoubleClick);
  2361. pb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  2362. PicPnl.Controls.Add(pb);
  2363. CarCache.cameraShots.RealPlay(pb, i);
  2364. }
  2365. }
  2366. private void PictureBoxDoubleClick(object sender, EventArgs e)
  2367. {
  2368. if (iPic != 0)
  2369. {
  2370. CarCache.cameraShots.StopRealPlay(iPic);
  2371. }
  2372. PictureBox picture = (PictureBox)sender;
  2373. if (plImgShow.Visible == false)
  2374. {
  2375. // plImgShow.Location = new Point(170, 140);
  2376. plImgShow.Width = tbMain.Width - plImgShow.Location.X;
  2377. plImgShow.Height = tbMain.Height - plImgShow.Location.Y;
  2378. }
  2379. iPic = Convert.ToInt32(picture.Name.Substring(picture.Name.Length - 1, 1));
  2380. plImgShow.Visible = true;
  2381. CarCache.cameraShots.RealPlay(pictureShow, iPic);
  2382. }
  2383. private int iPic = 0;
  2384. /// <summary>
  2385. /// 不显示大图
  2386. /// </summary>
  2387. private void pictureShow_DoubleClick(object sender, EventArgs e)
  2388. {
  2389. plImgShow.Visible = false;
  2390. CarCache.cameraShots.StopRealPlay(iPic);
  2391. iPic = 0;
  2392. }
  2393. private void UpdatePointState(CmmMonitorEntity Cmm)
  2394. {
  2395. var ccp = new CoreClientParam
  2396. {
  2397. ServerName = "com.steering.Mcms.CmmMonitorServer",
  2398. MethodName = "DoUpdateisTakeOver ",
  2399. ServerParams = new object[]
  2400. {
  2401. JSONFormat.Format(Cmm)
  2402. }
  2403. };
  2404. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2405. }
  2406. private void btn_SelectedValueChanged(object sender, EventArgs e)
  2407. {
  2408. //tzh 24.11.8 测试 改成10
  2409. lblWtNow.Text = "0.00t";
  2410. CleanCloseDb();
  2411. if (communicationnow != null)
  2412. {
  2413. communicationnow.Communication.Show = false;
  2414. communicationnow.Communication.Stop();
  2415. communicationnow.Communication.ReceiveData -= defultClenttEntity_ReceiveData;
  2416. }
  2417. communicationnow = null;
  2418. Button btnConect = sender as Button;
  2419. //foreach (Control a in ultraPanel21.Controls)//遍历控件有问题,在demo里面测试没有问题
  2420. //{
  2421. // if (a is Button)
  2422. // {
  2423. // a.ForeColor = a.Tag.ToString() == btnConect.Tag.ToString() ? Color.Blue : Color.Green;
  2424. // }
  2425. //}
  2426. if (btnConect.Tag.ToString() == "A")
  2427. {
  2428. btnA.BackColor = Color.Red;
  2429. // btnB.BackColor = btnC.BackColor = Color.Green;
  2430. }
  2431. if (btnConect.Tag.ToString() == "B")
  2432. {
  2433. btnB.BackColor = Color.Red;
  2434. // btnA.BackColor = btnC.BackColor = Color.Green;
  2435. }
  2436. if (btnConect.Tag.ToString() == "C")
  2437. {
  2438. btnC.BackColor = Color.Red;
  2439. // btnB.BackColor = btnA.BackColor = Color.Green;
  2440. }
  2441. PbCache.Load();
  2442. PbCache.sportInfo = CmmBaseSpotInfo.First(p => p.BaseSpotNo == btnConect.Tag.ToString());
  2443. communicationnow = new CommunicationEntity();
  2444. communicationnow.PoundNo = PbCache.sportInfo.BaseSpotNo;
  2445. communicationnow.Communication = new SocketClient
  2446. {
  2447. Ip = PbCache.sportInfo.WeightIp,
  2448. Port = PbCache.sportInfo.WeightPort,
  2449. Show = false
  2450. };
  2451. communicationnow.PoundNo = PbCache.sportInfo.BaseSpotNo;
  2452. communicationnow.Communication.Show = true;
  2453. WeightLoad(communicationnow.Communication, communicationnow.PoundNo);
  2454. GetIPVideo(PbCache.sportInfo);
  2455. setPicBoxSet();
  2456. }
  2457. /// <summary>
  2458. /// 启动采集
  2459. /// </summary>
  2460. /// <param name="communication"></param>
  2461. private void WeightLoad(iCommunication communication, string PNO)
  2462. {
  2463. communication.ReceiveData += defultClenttEntity_ReceiveData;
  2464. CmmBaseProtocolEntity cmmBaseProtocol = null;
  2465. cmmPoundBase = poundInfos.First(p => p.PoundNo == PNO);
  2466. if (cmmPoundBase != null)
  2467. {
  2468. List<CmmBaseProtocolCEntity> protocols = EntityHelper.GetData<CmmBaseProtocolCEntity>(
  2469. "com.steering.Mcms.ProcotolServer.getProcotolId",
  2470. new object[] { cmmPoundBase.PoundProtocolId },
  2471. ob);
  2472. if ((protocols != null) && protocols.Any())
  2473. cmmBaseProtocol = new CmmBaseProtocolEntity
  2474. {
  2475. ProtocolId = cmmPoundBase.PoundProtocolId,
  2476. ListC = protocols
  2477. };
  2478. // cboPoundList.Text = cmmPoundBase.PoundNo;
  2479. }
  2480. communication.ChangeProtocol(new TruckScaleProtocol(cmmBaseProtocol));
  2481. utbConnect_Click(null, null);
  2482. }
  2483. /// <summary>
  2484. /// 保存重量数据
  2485. /// </summary>
  2486. /// <param name="sender"></param>
  2487. /// <param name="e"></param>
  2488. //private void timer1_Tick(object sender, EventArgs e)
  2489. //{
  2490. // double wt;
  2491. // if (double.TryParse(lblWtNow.Text.Replace("t", ""), out wt))
  2492. // {
  2493. // if (wt >= 0.5)
  2494. // {
  2495. // if (PbCache.isLockFrm == false)
  2496. // {
  2497. // PbCache.dtStartTime = DateTime.Now;
  2498. // PbCache.isLockFrm = true;
  2499. // }
  2500. // if (communicationnow == null)
  2501. // return;
  2502. // var info = CmmBaseSpotInfo.First(t => t.BaseSpotNo == communicationnow.PoundNo);
  2503. // var template = new CmmMonitorWeightEntity
  2504. // {
  2505. // WeightNo = Guid.NewGuid().ToString(),
  2506. // BaseSpotNo = info.BaseSpotNo,
  2507. // BaseSpotName = info.BaseSpotName,
  2508. // CollectWeight = communicationnow.Communication.WeightValue,
  2509. // CollectStartTime = PbCache.dtStartTime.ToString()
  2510. // };
  2511. // var list = new List<string >();
  2512. // list.Add(JSONFormat.Format(template));
  2513. // var ccp = new CoreClientParam
  2514. // {
  2515. // ServerName = "com.steering.Mcms.CmmMonitorWeightServer",
  2516. // MethodName = "addCmmMonitorInfo",
  2517. // ServerParams = new object[]
  2518. // {
  2519. // list
  2520. // }
  2521. // };
  2522. // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2523. // }
  2524. // if (wt <= 0.3)
  2525. // {
  2526. // if (communicationnow == null)
  2527. // return;
  2528. // if ( PbCache.isLockFrm == true)
  2529. // {
  2530. // PbCache.isLockFrm = false;
  2531. // var template = new CmmMonitorWeightEntity
  2532. // {
  2533. // BaseSpotNo = PbCache.sportInfo.BaseSpotNo,
  2534. // BaseSpotName = PbCache.sportInfo.BaseSpotName,
  2535. // CollectStartTime = PbCache.dtStartTime.ToString(),
  2536. // CollectEndTime = DateTime.Now.ToString(),
  2537. // ActualFirstNo = PbCache.actualFirstNo
  2538. // };
  2539. // var ccp = new CoreClientParam
  2540. // {
  2541. // ServerName = "com.steering.Mcms.CmmMonitorWeightServer",
  2542. // MethodName = "updateBySpotNoStartTime",
  2543. // ServerParams = new object[]
  2544. // {
  2545. // JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
  2546. // {ContractResolver = new CamelCasePropertyNamesContractResolver()})
  2547. // }
  2548. // };
  2549. // ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2550. // }
  2551. // }
  2552. // else
  2553. // {
  2554. // // MessageBox.Show("数据异常!");
  2555. // return;
  2556. // }
  2557. // }
  2558. //}
  2559. /// <summary>
  2560. /// 接管之前,清空
  2561. /// </summary>
  2562. private void CleanCloseDb()
  2563. {
  2564. //*****************这里需要将语音对讲/视频都关闭*******************
  2565. //退出语音登录
  2566. try
  2567. {
  2568. // VoiceClose();
  2569. IPVideoClose();
  2570. }
  2571. catch (Exception ex)
  2572. {
  2573. }
  2574. // ls = null;
  2575. //*****************************************************************
  2576. // flagCarNo = false;
  2577. setMsgInfo(plImgShow, "false", "2");
  2578. /// DataTable dtJld = dtJGPointInfo.Clone();
  2579. // setGridInfo(ultraGridPW, dtJld, this.dtJGPointInfo);
  2580. // setMsgInfo(lbPointName, "", "");
  2581. // setMsgInfo(lbMeterMan, "", "");
  2582. PbCache.Load();
  2583. PbCache.sportInfo = null;
  2584. CarCache.cameraShots = null;
  2585. // PbCache.relations = null;
  2586. setPanelRemovenfo(PicPnl);
  2587. // bCollectionStart = false;
  2588. //关闭采集进程
  2589. // collection.Stop();
  2590. }
  2591. private void GetRecord_No(string carNO, string state)
  2592. {
  2593. var dic = new Dictionary<string, object>();
  2594. if (!string.IsNullOrWhiteSpace(cboPoundList.Text))
  2595. dic.Add("poundNo", cboPoundList.Text);
  2596. dic.Add("validflag", new List<string> { state });
  2597. var list = EntityHelper.GetData<CmmWeightRecordEntity>(
  2598. "com.steering.Mcms.RecordServer.doQueryRecord",
  2599. new object[] { dic },
  2600. ob).Where(p => p.CarNo == carNO).OrderByDescending(p => p.RecordDate).FirstOrDefault();
  2601. }
  2602. public void setPanelRemovenfo(Panel control)
  2603. {
  2604. setPanelRemoveMsg(control);
  2605. }
  2606. /// <summary>
  2607. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  2608. /// </summary>
  2609. /// <param name="control"></param>
  2610. /// <param name="ResultMessage"></param>
  2611. /// <param name="sType"></param>
  2612. private void setPanelRemoveMsg(Panel p)
  2613. {
  2614. if (p.InvokeRequired)
  2615. {
  2616. Action<Panel> action = new Action<Panel>(setPanelRemovenfo);
  2617. Invoke(action, new object[] { p });
  2618. }
  2619. else
  2620. {
  2621. for (int i = p.Controls.Count - 1; i >= 0; i--)
  2622. {
  2623. p.Controls.RemoveAt(i);
  2624. }
  2625. }
  2626. }
  2627. //private void button1_Click(object sender, EventArgs e)
  2628. //{
  2629. // DhCameraShot tt = new DhCameraShot();
  2630. // CarCache.cameraShots = tt;
  2631. // //todu
  2632. // CarCache.cameraShots.ip = "192.168.21.54";
  2633. // CarCache.cameraShots.port = "8000";
  2634. // CarCache.cameraShots.uid = "admin";
  2635. // CarCache.cameraShots.pwd = "hk123456";
  2636. // CarCache.cameraShots.Connection();
  2637. // setPicBoxSet();
  2638. //}
  2639. //private void button2_Click(object sender, EventArgs e)
  2640. //{
  2641. // imageControl = new ImageControl("192.168.21.220","21","admin", "th2021","1", "/pub/",ob);
  2642. // imageControl.Start();
  2643. // try
  2644. // {
  2645. // PbCache.sportInfo = new CmmBaseSpotInfoEntity();
  2646. // PbCache.sportInfo.BaseSpotNo = "testno";
  2647. // PbCache.actualFirstNo = "actualFirstNo";
  2648. // //string strPath = System.Environment.CurrentDirectory +@"\imgShort\formalImg\" +PbCache.sportInfo.BaseSpotNo +"_"+ "PbCache.actualFirstNo" +"_"+ "7.jpg";
  2649. // //Rectangle r = Screen.PrimaryScreen.Bounds;
  2650. // //Image img = new Bitmap(r.Width, r.Height);
  2651. // //Graphics g = Graphics.FromImage(img);
  2652. // //g.CopyFromScreen(new Point(0, 0), new Point(0, 0), r.Size);
  2653. // //img.Save(strPath);
  2654. // // 截取屏幕信息
  2655. // // PbCache.actualFirstNo = CmmImage.ActualFirstNo;
  2656. // Point screenPoint = this.PointToScreen(new Point());
  2657. // Rectangle rect = new Rectangle(screenPoint, this.Size);
  2658. // Image img = new Bitmap(rect.Width, rect.Height);
  2659. // Graphics g = Graphics.FromImage(img);
  2660. // g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
  2661. // img.Save(string.Format("{0}\\imgShort\\formalImg\\{1}_{2}_{3}.jpg",
  2662. // AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  2663. // PbCache.sportInfo.BaseSpotNo,
  2664. // "C" + PbCache.actualFirstNo,
  2665. // 5), System.Drawing.Imaging.ImageFormat.Jpeg);// 最后一张图片名称写死了
  2666. // //最后进行截图操作
  2667. // CameraShotCls cameraShot = new CameraShotCls();
  2668. // // CarCache.cameraShots.CapMethod("PbCache.actualFirstNo");
  2669. // cameraShot.CapMethod(PbCache.actualFirstNo);
  2670. // //*/
  2671. // }
  2672. // catch (Exception ex)
  2673. // {
  2674. // // l.WriteLog(5, PbCache.lockCarNo + "截图失败");
  2675. // MessageBox.Show(ex.ToString());
  2676. // }
  2677. //}
  2678. //private void button3_Click(object sender, EventArgs e)
  2679. //{
  2680. // communicationnow = new CommunicationEntity();
  2681. // communicationnow.Communication = new SocketClient
  2682. // {
  2683. // Ip = "127.0.0.1",
  2684. // Port = "4001",
  2685. // Show = true
  2686. // };
  2687. // communicationnow.PoundNo = "A";
  2688. // communicationnow.Communication.Show = true;
  2689. // WeightLoad(communicationnow.Communication, communicationnow.PoundNo);
  2690. //}
  2691. private void playVioce(string btName)
  2692. {
  2693. try
  2694. {
  2695. bool rets;
  2696. // CarCache.cameraShots.Connection();
  2697. rets = CarCache.cameraShots.PlayMusic(System.Environment.CurrentDirectory + "\\sound\\称重完成.wav");
  2698. // if (rets) MessageBox.Show("【 称重完成】语音播放成功!");
  2699. }
  2700. catch (Exception ex)
  2701. {
  2702. ex.ToString();
  2703. }
  2704. }
  2705. private void timer2_Tick(object sender, EventArgs e)
  2706. {
  2707. try
  2708. {
  2709. if (communicationnow != null && communicationnow.Communication.Show == true)
  2710. {
  2711. var c4 = new CmmLoadinfoEntity
  2712. {
  2713. Loadip = strip,
  2714. BaseSpotNo = communicationnow.PoundNo,
  2715. };
  2716. var ccp4 = new CoreClientParam
  2717. {
  2718. ServerName = "com.steering.Mcms.CmmLoadinfoServer",
  2719. MethodName = "addLoadinfo",
  2720. ServerParams = new object[]
  2721. {
  2722. JSONFormat.Format(c4)
  2723. }
  2724. };
  2725. ccp4 = ExecuteNonQuery(ccp4, CoreInvokeType.Internal);
  2726. }
  2727. GetColorsAsync();
  2728. }
  2729. catch
  2730. { }
  2731. }
  2732. private async Task GetColorsAsync()
  2733. {
  2734. try
  2735. {
  2736. loadinfo = await Task.Run(() => EntityHelper.GetData<CmmLoadinfoCEntity>(
  2737. "com.steering.Mcms.CmmLoadinfoServer.queryAll",
  2738. new object[] { },
  2739. ob));
  2740. // 确保这里的getColor是同步且不耗时,处理UI时要在UI线程
  2741. getColor(btnB);
  2742. getColor(btnA);
  2743. getColor(btnC);
  2744. }
  2745. catch (Exception ex)
  2746. {
  2747. // 你可以选择记录异常,或者提示
  2748. Console.WriteLine(ex);
  2749. }
  2750. }
  2751. /// <summary>
  2752. /// 通过系统时间和最近一次时间对比,判断是否在线
  2753. /// </summary>
  2754. /// <param name="b"></param>
  2755. void getColor(Control b)
  2756. {
  2757. Button btnco = (Button)b;
  2758. if (communicationnow != null && btnco.Tag.ToString() == communicationnow.PoundNo && communicationnow.Communication.Show == true)
  2759. {
  2760. btnco.BackColor = Color.Red;
  2761. return;
  2762. }
  2763. int countco = 0;
  2764. foreach (var p in loadinfo)
  2765. {
  2766. DateTime updatetime = Convert.ToDateTime(p.Actualtime);
  2767. DateTime time = Convert.ToDateTime(p.UpdateTime);
  2768. TimeSpan ts = updatetime - time;
  2769. // 逻辑没变,只简化判断
  2770. if (ts.TotalSeconds <= 7)
  2771. {
  2772. if (btnco.Tag.ToString() == p.BaseSpotNo.ToString() && p.Loadip != strip)
  2773. {
  2774. countco++;
  2775. }
  2776. }
  2777. }
  2778. if (countco == 0)
  2779. btnco.UseVisualStyleBackColor = true;
  2780. else
  2781. btnco.BackColor = Color.Green;
  2782. }
  2783. void addActual(string spot, string record)
  2784. {
  2785. var c2 = new CmmActualWeightEntity
  2786. {
  2787. BaseSpotNo = spot,
  2788. RecordNo = record,
  2789. };
  2790. var ccp3 = new CoreClientParam
  2791. {
  2792. ServerName = "com.steering.Mcms.CmmActualWeightServer",
  2793. MethodName = "addActualWeight",
  2794. ServerParams = new object[]
  2795. {
  2796. JSONFormat.Format(c2)
  2797. }
  2798. };
  2799. ccp3 = ExecuteNonQuery(ccp3, CoreInvokeType.Internal);
  2800. }
  2801. private void btn_Click(object sender, EventArgs e)
  2802. {
  2803. //tzh 24.11.8 测试 改成10
  2804. lblWtNow.Text = "0.00t";
  2805. CleanCloseDb();
  2806. if (communicationnow != null)
  2807. {
  2808. communicationnow.Communication.Show = false;
  2809. communicationnow.Communication.Stop();
  2810. communicationnow.Communication.ReceiveData -= defultClenttEntity_ReceiveData;
  2811. }
  2812. communicationnow = null;
  2813. lblStatus.SafeRefreshControl(() => lblStatus.Text = "重量采集已断开");
  2814. }
  2815. private void ugData_DoubleClickCell(object sender, DoubleClickCellEventArgs e)
  2816. {
  2817. var current = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  2818. if ((current == null) || ("" == current.ResultNo)) return;
  2819. var loadinfo1 = EntityHelper.GetData<CmmWorkImageEntity>(
  2820. "com.steering.Mcms.CmmWorkImageServer.doQuery",
  2821. new object[] { current.RecordNo1 },
  2822. ob);
  2823. var loadinfo2 = EntityHelper.GetData<CmmWorkImageEntity>(
  2824. "com.steering.Mcms.CmmWorkImageServer.doQuery",
  2825. new object[] { current.RecordNo2 },
  2826. ob);
  2827. if ((loadinfo1.Count == 0) && (loadinfo2.Count == 0))
  2828. {
  2829. MessageBox.Show("没有单号" + current.ResultNo + "图片记录");
  2830. return;
  2831. }
  2832. Form form = frmLocalTruckImageShow.GetSingleton(ob, current, CmmBaseSpotInfo[0]); // 有参数
  2833. form.Show();
  2834. form.Activate();
  2835. }
  2836. private void uctMemo_EditorButtonClick(object sender, EditorButtonEventArgs e)
  2837. {
  2838. if (cmmPoundBase == null)
  2839. {
  2840. MessageBox.Show(@"无磅房权限");
  2841. return;
  2842. }
  2843. var current = CurrentGrid.ActiveRow.ListObject as CmmWeightRecordEntity;
  2844. string Memo;
  2845. using (var update = new ChangeMemo { Memo = current.Memo })
  2846. {
  2847. var result = update.ShowDialog();
  2848. if (result != DialogResult.OK) return;
  2849. Memo = update.Memo;
  2850. }
  2851. var ccp = new CoreClientParam
  2852. {
  2853. ServerName = "com.steering.Mcms.RecordServer",
  2854. MethodName = "DoUpdateMemo",
  2855. ServerParams = new object[]
  2856. {
  2857. current.RecordNo,
  2858. Memo
  2859. }
  2860. };
  2861. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  2862. if (ccp.ReturnCode != -1)
  2863. {
  2864. MessageUtil.ShowTips(ccp.ReturnInfo);
  2865. if (ccp.ReturnInfo.ToString2().Contains("操作成功"))
  2866. Query();
  2867. }
  2868. }
  2869. private void button1_Click(object sender, EventArgs e)
  2870. {
  2871. playVioce("称重完成");
  2872. }
  2873. private void button1_Click_1(object sender, EventArgs e)
  2874. {
  2875. lblWt.Text = "1.00t";
  2876. }
  2877. private void button2_Click(object sender, EventArgs e)
  2878. {
  2879. // playVioce("称重完成");
  2880. lblWt.Text = "2.00t";
  2881. }
  2882. private void checkBox3_CheckedChanged(object sender, EventArgs e)
  2883. {
  2884. if (checkBox3.Checked)
  2885. {
  2886. qitahuipi.Visible = true;
  2887. }
  2888. else
  2889. {
  2890. qitahuipi.Visible = false;
  2891. }
  2892. }
  2893. private void ultraButton2_Click(object sender, EventArgs e)
  2894. {
  2895. using (var BlankPredictionSelect = new BlankPredictionSelect(ob, matInfo20.GetData()))
  2896. {
  2897. if (BlankPredictionSelect.ShowDialog() == DialogResult.OK)
  2898. matInfo20.UpdateData(new CmmWeightRecordEntityFull
  2899. {
  2900. MatName = "连铸圆坯",
  2901. ShippersName = BlankPredictionSelect.ShipperName,
  2902. RecordNumber = BlankPredictionSelect.ListMatNo == null ? null : BlankPredictionSelect.ListMatNo.Sum(p => p.ActCount),
  2903. ReceiveName = "江苏天淮钢管有限公司",
  2904. Memo = BlankPredictionSelect.Memo,
  2905. MatInfos =
  2906. BlankPredictionSelect.ListMatNo ?? new List<CmmWeightMatEntity> { new CmmWeightMatEntity() }
  2907. });
  2908. }
  2909. }
  2910. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  2911. {
  2912. if (checkBox1.Checked)
  2913. {
  2914. chkSteelCar.Visible = false;
  2915. chkGross.Visible = false;
  2916. }
  2917. else
  2918. {
  2919. chkGross.Visible = true;
  2920. chkSteelCar.Visible = true;
  2921. }
  2922. }
  2923. private void qitahuipi_SelectedTabChanged(object sender, SelectedTabChangedEventArgs e)
  2924. {
  2925. LoadTem2();
  2926. if ((tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  2927. (tbScondWt.ActiveTab.Key == "2") && qitahuipi.ActiveTab != null && qitahuipi.ActiveTab.Key == "102")
  2928. {
  2929. ultraButton2.Visible = true;
  2930. }
  2931. else
  2932. {
  2933. ultraButton2.Visible = false;
  2934. }
  2935. }
  2936. private void button3_Click(object sender, EventArgs e)
  2937. {
  2938. cmmPoundBase = poundInfos.First(p => p.PoundNo == "A");
  2939. }
  2940. private void chkSteelCar_CheckedChanged(object sender, EventArgs e)
  2941. {
  2942. if (chkSteelCar.Checked == true)
  2943. {
  2944. checkBox1.Visible = false;
  2945. }
  2946. else
  2947. {
  2948. checkBox1.Visible = true;
  2949. }
  2950. }
  2951. private void timer1_Tick(object sender, EventArgs e)
  2952. {
  2953. Query();
  2954. }
  2955. private void button4_Click(object sender, EventArgs e)
  2956. {
  2957. button1_Click(null, null);
  2958. }
  2959. private void LoadTem2()
  2960. {
  2961. if (_templateList == null) return;
  2962. var key = GetKey2();
  2963. if (string.IsNullOrWhiteSpace(key)) return;
  2964. if ((_cmmInputRecordEntities != null) && _cmmInputRecordEntities.Any())
  2965. {
  2966. var matInfo = GetMatInfo();
  2967. if (matInfo != null)
  2968. matInfo.iniMatName(
  2969. _cmmInputRecordEntities.Where(
  2970. p => (p.RecordKey == key) || string.IsNullOrWhiteSpace(p.RecordKey)).ToList());
  2971. }
  2972. lvTemplate.Items.Clear();
  2973. lvTemplate.Items.AddRange(_templateList.Where(p => CheckShowKey(p.TemplateKey, key))
  2974. .Select(p =>
  2975. {
  2976. var
  2977. temp =
  2978. new UltraListViewItem(p.TemplateName, null, null) { Key = p.TemplateNo };
  2979. try
  2980. {
  2981. temp.Tag =
  2982. XmlHelper.FromXElement<CmmWeightRecordEntityFull>(XElement.Parse(p.TemplateXml));
  2983. }
  2984. catch (Exception)
  2985. {
  2986. // ignored
  2987. }
  2988. return temp;
  2989. }
  2990. ).
  2991. ToArray()
  2992. );
  2993. }
  2994. private string GetKey2()
  2995. {
  2996. return tbWt.ActiveTab.Key == "1"
  2997. ? (tbFirstWt.ActiveTab == null ? "" : tbFirstWt.ActiveTab.Key)
  2998. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "1") &&
  2999. (tbOther.ActiveTab != null)
  3000. ? tbOther.ActiveTab.Key
  3001. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) && (tbScondWt.ActiveTab.Key == "0")
  3002. ? "201"
  3003. : (tbWt.ActiveTab.Key == "2") && (tbScondWt.ActiveTab != null) &&
  3004. (tbScondWt.ActiveTab.Key == "2")&& qitahuipi.Visible==true
  3005. ? qitahuipi.ActiveTab.Key
  3006. : "";
  3007. }
  3008. private void utbSaveAsT2_Click(object sender, EventArgs e)
  3009. {
  3010. if (cmmPoundBase == null)
  3011. {
  3012. MessageBox.Show(@"无磅房权限");
  3013. return;
  3014. }
  3015. if (tbWt.ActiveTab == null) return;
  3016. var matInfo = GetMatInfo();
  3017. if (matInfo != null)
  3018. {
  3019. var cmmWeightRecord = matInfo.GetData();
  3020. string projectName;
  3021. using (var fractureInfo = new ProjectName("模板名"))
  3022. {
  3023. fractureInfo.ShowDialog();
  3024. if (fractureInfo.DialogResult != DialogResult.OK) return;
  3025. projectName = fractureInfo.ProjectNameStr;
  3026. }
  3027. var template = new CmmRecordTemplateEntity
  3028. {
  3029. CreateUser = UserInfo.GetUserName(),
  3030. TemplateKey = GetKey2(),
  3031. TemplateLocation = cmmPoundBase.PoundNo,
  3032. TemplateXml = cmmWeightRecord.ToString(),
  3033. TemplateName = projectName
  3034. };
  3035. var ccp = new CoreClientParam
  3036. {
  3037. ServerName = "com.steering.Mcms.TemplateServer",
  3038. MethodName = "DoSaveTemplateNo",
  3039. ServerParams = new object[]
  3040. {
  3041. JsonConvert.SerializeObject(template, Formatting.None, new JsonSerializerSettings
  3042. {ContractResolver = new CamelCasePropertyNamesContractResolver()})
  3043. }
  3044. };
  3045. ccp = ExecuteNonQuery(ccp, CoreInvokeType.Internal);
  3046. if (ccp.ReturnCode != -1)
  3047. {
  3048. MessageUtil.ShowTips(ccp.ReturnInfo);
  3049. if (ccp.ReturnInfo.Equals("保存成功!"))
  3050. LoadTempate2();
  3051. }
  3052. }
  3053. }
  3054. private void LoadTempate2()
  3055. {
  3056. /* if (cmmPoundBase == null)
  3057. return;
  3058. */
  3059. _templateList = EntityHelper.GetData<CmmRecordTemplateEntity>(
  3060. "com.steering.Mcms.TemplateServer.doQueryTempate",
  3061. new object[] { "" },
  3062. ob);
  3063. qitahuipi_SelectedTabChanged(null, null);
  3064. }
  3065. private void btnPlay_Click(object sender, EventArgs e)
  3066. {
  3067. try
  3068. {
  3069. bool rets;
  3070. // CarCache.cameraShots.Connection();
  3071. rets = CarCache.cameraShots.PlayMusic(System.Environment.CurrentDirectory + "\\sound\\"+ cmbVioce.Text+".wav");
  3072. // if (rets) MessageBox.Show("【 称重完成】语音播放成功!");
  3073. }
  3074. catch (Exception ex)
  3075. {
  3076. ex.ToString();
  3077. }
  3078. }
  3079. private void ultraButton3_Click(object sender, EventArgs e)
  3080. {
  3081. if (ugData.ActiveRow == null) return;
  3082. var data = ugData.ActiveRow.ListObject as CmmWeightResultEntity;
  3083. if (data == null) return;
  3084. if ((data.RecordType2 == "201") && (data.GrossWt != null) && (data.GrossWt > 50) && (MessageUtil.ShowYesNoAndQuestion("毛重超过50吨, 是否继续打印磅单?") ==
  3085. DialogResult.No))
  3086. {
  3087. }
  3088. else
  3089. {
  3090. Print2(data.ResultNo);
  3091. }
  3092. }
  3093. private void CX_HT_ValueChanged(object sender, EventArgs e)
  3094. {
  3095. //string v_carno;
  3096. string v_cus;
  3097. string v_material;
  3098. string v_name;
  3099. var matInfo = GetMatInfo2();
  3100. if (!CX_HT.Text.ToString().Equals(""))
  3101. {
  3102. DataTable dt = ServerHelper.GetData("com.steering.Mcms.TemplateServer.SelectCX2", new object[] { CX_HT.Value.ToString() }, ob);
  3103. if (dt != null && dt.Rows.Count > 0)
  3104. {
  3105. v_cus = dt.Rows[0]["CUS_NAME"].ToString2();
  3106. v_material = dt.Rows[0]["MATERIAL_NAME"].ToString2();
  3107. v_name = v_material + '-' + v_cus;
  3108. tb_order.Text = dt.Rows[0]["BILL_STATUS"].ToString2();
  3109. CmmWeightRecordEntityFull xx = new CmmWeightRecordEntityFull() { MatName = v_material, ReceiveName = v_cus, ShippersName = "江苏天淮钢管有限公司" };
  3110. if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, v_name);
  3111. }
  3112. }
  3113. else
  3114. {
  3115. tb_order.Text = "";
  3116. CmmWeightRecordEntityFull xx = new CmmWeightRecordEntityFull() { MatName = "", ReceiveName = "", ShippersName = "" };
  3117. if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, "");
  3118. }
  3119. // if ((matInfo != null) && matInfo.AddNew) matInfo.SetDefault(xx, '1');
  3120. }
  3121. }
  3122. }