frmMeterMain2.cs 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389
  1. using com.hnshituo.core.webapp.vo;
  2. using Common;
  3. using Infragistics.Win;
  4. using Infragistics.Win.UltraWinGrid;
  5. using JC_MeasuringSystem;
  6. using MeterConditionLibrary;
  7. using MeterModelLibrary;
  8. using MeterModuleLibrary;
  9. using MeterPlugInLibrary;
  10. using MeterSceneLibrary;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Configuration;
  14. using System.Data;
  15. using System.Drawing;
  16. using System.Linq;
  17. using System.Net;
  18. using System.Windows.Forms;
  19. namespace CarRemoteMeter
  20. {
  21. public partial class frmMeterMain2 : Form
  22. {
  23. public frmMeterMain2()
  24. {
  25. InitializeComponent();
  26. }
  27. //图片控制器含图片压缩及上传sftp
  28. //ImageControl imageControl = new ImageControl();
  29. /// <summary>
  30. /// 基础数据载入
  31. /// </summary>
  32. private BaseDbCls bd = new BaseDbCls();
  33. private Log l = Log.GetInstance();
  34. private string userId = "", userName = "";
  35. private CoreAppUser appUser = null;
  36. //实时表数据采集
  37. private DataCollectionControl collection = new DataCollectionControl();
  38. private bool bCollectionStart = false;
  39. #region 服务查询
  40. //预报查询
  41. private PreTrackScaleService service = new PreTrackScaleService();
  42. private PreTrackScale preTack = null;
  43. //与监控界面对接的表
  44. private MeterWorkMonitorService monitorService = new MeterWorkMonitorService();
  45. //实时在线写入,每隔2秒一次
  46. private MeterWorkOnlineService onlineService = new MeterWorkOnlineService();
  47. //验证是否可留期限皮
  48. private validTermTareCar termTareCar = new validTermTareCar();
  49. //留期限皮操作
  50. private MeterBaseTermTareDataService termTareDate = new MeterBaseTermTareDataService();
  51. //内倒业务处理
  52. private InnerRemoteMeter inner = new InnerRemoteMeter();
  53. //非内倒业务处理
  54. private SceneControl scene = new SceneControl();
  55. //历史皮重数据
  56. private MeterBaseHisTareDataService meterBaseHisTareData = new MeterBaseHisTareDataService();
  57. //计量实绩
  58. private MeterWorkCarActualService mwas = new MeterWorkCarActualService();
  59. //校秤记录
  60. private MeterWorkCalibrationMainService mainService = new MeterWorkCalibrationMainService();
  61. //附加重量
  62. private PerAddWeightService perAddWeight = new PerAddWeightService();
  63. //一次计量重量
  64. private MeterWorkCarActualFirst first = null;
  65. private MeterMonitorWeightService monitorWeightService = new MeterMonitorWeightService();
  66. private validCalibration vCalib = new validCalibration();
  67. //车号修正
  68. private CarNoModfiy modfiy = new CarNoModfiy();
  69. private string sPreNo = ""; //记录重量曲线变化
  70. private int preWgt = 0;//前一次重量,用于重量曲线
  71. //一次计量数据查询
  72. private MeterWorkCarActualFirstService workCarActualFirstService = new MeterWorkCarActualFirstService();
  73. //物料信息
  74. private MeterBaseMatterInfoService matterInfoService = new MeterBaseMatterInfoService(); //物料信息
  75. //联达过磅
  76. LianDaMeter2 lianda = new LianDaMeter2();
  77. int lianDaWgt = Convert.ToInt32(ConfigurationManager.AppSettings["lianDaWgt"]?.ToString() ?? "0");
  78. string lianDaPointNo = ConfigurationManager.AppSettings["lianDaPointNo"]?.ToString() ?? "00019";
  79. #endregion 服务查询
  80. #region 初始化数据
  81. private void frmMeterMain2_Load(object sender, EventArgs e)
  82. {
  83. setMsgInfo(btnInnerQuery, "false", "1");
  84. setMsgInfo(btnCheck, "false", "1");
  85. setMsgInfo(btnSave, "false", "1");
  86. setMsgInfo(btnTareWgt, "false", "1");
  87. setMsgInfo(btnCheckBalance, "false", "1");
  88. ValueList vlist = new ValueList();
  89. vlist.ValueListItems.Add("0", "批次预报");
  90. vlist.ValueListItems.Add("1", "单次预报");
  91. vlist.ValueListItems.Add("2", "联运预报");
  92. vlist.ValueListItems.Add("3", "分检预报");
  93. ultraGridYb.DisplayLayout.Bands[0].Columns["predictionType"].ValueList = vlist;
  94. timer1.Start();
  95. collection.EventDataCollectionArgs += new EventDataCollection(EventData);//数据采集
  96. userId = ((ST_MainForm)(this.MdiParent)).UserID;
  97. userName = ((ST_MainForm)(this.MdiParent)).UserName;
  98. appUser = ((ST_MainForm)(this.MdiParent)).AppUser;
  99. if (bd.setBaseDb() && bd.getBaseDb())
  100. {
  101. timer2.Start();
  102. lbPointName.Text = "";
  103. lbMeterMan.Text = userName;
  104. PbCache.isNotValid = true;
  105. //imageControl.Start();
  106. }
  107. else
  108. {
  109. MessageBox.Show("基础数据载入失败,请关闭界面并稍后打开,或联系管理员");
  110. return;
  111. }
  112. string _controlIp = GetIP();
  113. if (!_controlIp.Contains("192") && !_controlIp.Contains("168")) //只有在测试环境,【测试】按钮才有效
  114. {
  115. btnTest.Visible = false;
  116. btnTest.Enabled = false;
  117. txtTestWeight.Visible = false;
  118. txtTestWeight.Enabled = false;
  119. }
  120. //txtCarNo.LostFocus += new EventHandler(txtCarNo_KeyDown);
  121. lbWgt.LostFocus += new EventHandler(lbWgt_ValueChanged);
  122. }
  123. #endregion 初始化数据
  124. #region 数据采集部分
  125. private int iCounts = 0; //计数器
  126. private bool iWgtChange = true; //重量初次大于500
  127. private string preCarNo = "";//上次车号
  128. private string editCarNo = "";//修正车号
  129. private bool ndRemind = true;//内倒提示信息;提示当前是毛重或者皮重;
  130. /// <summary>
  131. /// 数据采集;由于自动接管,相当于程序入口
  132. /// </summary>
  133. private void EventData(object o, DataCollectionArgs e)
  134. {
  135. //测试 固定重量
  136. if (testFlage)
  137. {
  138. txtTestWeight.Text = "".Equals(txtTestWeight.Text.Trim()) ? "0" : txtTestWeight.Text.Trim();
  139. e.weight = Convert.ToInt32(txtTestWeight.Text);
  140. }
  141. //这里每隔0.5秒执行一次
  142. try
  143. {
  144. if (iCounts < 1200)
  145. {
  146. iCounts++;
  147. }
  148. else
  149. {
  150. iCounts = 0;
  151. try
  152. {
  153. //秤上没有车时,每隔10分钟获取一次基础数据
  154. if (e.weight < 500)
  155. {
  156. editCarNo = "";
  157. preCarNo = "";
  158. if (bd.setBaseDb())
  159. {
  160. l.WriteLog(0, "十分钟获取基础数据成功");
  161. }
  162. else
  163. {
  164. l.WriteLog(0, "十分钟获取基础数据失败");
  165. }
  166. }
  167. }
  168. catch (Exception ex)
  169. {
  170. l.WriteLog(0, "十分钟获取基础数据失败:" + ex.Message);
  171. }
  172. }
  173. #region
  174. PbCache.collect.pointid = PbCache.sportInfo.baseSpotNo;
  175. PbCache.collect.weight = e.weight;
  176. PbCache.collect.weightStatus = e.weightStatus;
  177. PbCache.collect.parkStatus = e.parkStatus;
  178. PbCache.collect.datetime = e.datetime;
  179. PbCache.collect.licType = e.licType;
  180. #region 车号设置
  181. getFocusInfo(txtCarNo);
  182. if (!isFocus) //光标不在里面
  183. {
  184. if (strCbCarNo == "" || strTxtCarNo == "")
  185. {
  186. PbCache.collect.carno = e.carno;
  187. if (!string.IsNullOrEmpty(e.carno) && e.carno.Length > 1)
  188. {
  189. if (preCarNo == "")
  190. {
  191. preCarNo = e.carno;
  192. string methods = "";
  193. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  194. {
  195. methods += "CarNoTrustCorrect" + i + ",";
  196. }
  197. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  198. }
  199. e.carno = editCarNo;
  200. setTxtCarNo(e.carno.Substring(1, e.carno.Length - 1));
  201. setCbCarNoInfo(e.carno.Substring(0, 1));
  202. QueryCarNo();
  203. }
  204. }
  205. else
  206. {
  207. if (!flagCarNo && (strCbCarNo + strTxtCarNo) != e.carno) //没有按回车,且车号不等于的时候
  208. {
  209. if (!string.IsNullOrEmpty(e.carno) && e.carno.Length > 1)
  210. {
  211. if (preCarNo == "" || preCarNo != e.carno)
  212. {
  213. preCarNo = e.carno;
  214. string methods = "";
  215. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  216. {
  217. methods += "CarNoTrustCorrect" + i + ",";
  218. }
  219. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  220. }
  221. e.carno = editCarNo;
  222. PbCache.collect.carno = e.carno;
  223. setTxtCarNo(e.carno.Substring(1, e.carno.Length - 1));
  224. setCbCarNoInfo(e.carno.Substring(0, 1));
  225. QueryCarNo();
  226. }
  227. }
  228. else if (flagCarNo)
  229. {
  230. PbCache.collect.carno = strCbCarNo + strTxtCarNo;
  231. }
  232. }
  233. }
  234. #endregion 车号设置
  235. //重量大于500的情况下
  236. if (e.weight > 500)
  237. {
  238. if (!PbCache.isLockFrm)
  239. {
  240. ucWeightT1.setWgt(PbCache.collect.weight);
  241. ucWeightT1.setStable(PbCache.collect.weightStatus != 1 ? true : false);
  242. ucWeightT1.setExceed(PbCache.collect.weight > PbCache.range.upperRange ? false : true);
  243. PbCache.addWgt = dAddWgt;
  244. if (first != null)
  245. {
  246. if (PbCache.collect.weight < first.meterWeight.Value)
  247. {
  248. setMsgInfo(txtTare, PbCache.collect.weight + "", "");
  249. setMsgInfo(txtGroess, first.meterWeight.Value + "", "");
  250. }
  251. else
  252. {
  253. setMsgInfo(txtGroess, PbCache.collect.weight + "", "");
  254. setMsgInfo(txtTare, first.meterWeight.Value + "", "");
  255. }
  256. double dbAddWgt = 0;
  257. if (first.addWeight != null && first.addWeight.Value > 0)
  258. {
  259. dbAddWgt = first.addWeight.Value;
  260. }
  261. else
  262. {
  263. dbAddWgt = dAddWgt;
  264. }
  265. //PbCache.addWgt = dbAddWgt;
  266. setMsgInfo(txtNet, Math.Abs(PbCache.collect.weight - first.meterWeight.Value) - dbAddWgt + "", "");
  267. }
  268. }
  269. if (iWgtChange)
  270. {
  271. setMsgInfo(btnInnerQuery, "true", "1");
  272. setMsgInfo(btnSave, "true", "1");
  273. setMsgInfo(btnTareWgt, "true", "1");
  274. setMsgInfo(btnCheckBalance, "true", "1");
  275. setMsgInfo(btnCheck, "true", "1");
  276. setReadOnlyInfo(txtPREDICTION_NO, "false", "0");
  277. }
  278. if (PbCache.dtStartTime == null)
  279. PbCache.dtStartTime = DateTime.Now;
  280. //每隔1秒刷一次计量实时监控表数据值
  281. if (iCounts % 2 == 0)
  282. {
  283. #region 每隔1秒写入一次重量曲线
  284. try
  285. {
  286. if (preWgt != e.weight)
  287. {
  288. preWgt = e.weight;
  289. sPreNo = PbCache.sportInfo.baseSpotNo + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  290. monitorWeightService.doAddWf(new MeterMonitorWeight
  291. {
  292. weightNo = sPreNo,
  293. baseSpotNo = PbCache.sportInfo.baseSpotNo,
  294. baseSpotName = PbCache.sportInfo.baseSpotName,
  295. collectWeight = e.weight + "",
  296. collectStartTime = PbCache.dtStartTime.Value,
  297. collectEndTime = DateTime.Now,
  298. spotTypeNo = "001002001",
  299. spotTypeName = "汽车衡",
  300. actualFirstNo = PbCache.actualFirstNo
  301. });
  302. }
  303. else
  304. {
  305. if (!string.IsNullOrEmpty(sPreNo))
  306. {
  307. monitorWeightService.doUpdateWf(new MeterMonitorWeight
  308. {
  309. weightNo = sPreNo,
  310. collectEndTime = DateTime.Now
  311. });
  312. }
  313. }
  314. }
  315. catch { }
  316. #endregion 每隔1秒写入一次重量曲线
  317. switch (e.parkStatus)
  318. {
  319. case 1:
  320. setPicQRed(true);
  321. setPicHRed(false);
  322. break;
  323. case 2:
  324. setPicQRed(false);
  325. setPicHRed(true);
  326. break;
  327. case 3:
  328. setPicQRed(true);
  329. setPicHRed(true);
  330. break;
  331. default:
  332. setPicQRed(false);
  333. setPicHRed(false);
  334. break;
  335. }
  336. }
  337. iWgtChange = false;
  338. }
  339. else
  340. {
  341. if (flagStart && strIsRemote == "0")
  342. {
  343. Clean();
  344. }
  345. else
  346. {
  347. CleanForm();
  348. }
  349. }
  350. #endregion 数据采集部分
  351. }
  352. catch (Exception ex)
  353. {
  354. l.WriteLog(0, "frmMeterMain2.EventData异常3:" + ex.Message);
  355. }
  356. }
  357. #endregion
  358. #region 从接管到未的时候清理下数据
  359. //清理一次数据
  360. private void Clean()
  361. {
  362. if (PbCache.sportInfo == null || string.IsNullOrEmpty(PbCache.sportInfo.baseSpotNo)) return;
  363. MeterWorkMonitor mwmUpdate = new MeterWorkMonitor
  364. {
  365. pointNo = PbCache.sportInfo.baseSpotNo,
  366. validWgt = "1",
  367. validCarno = "1",
  368. validTareTime = "1",
  369. validMatTime = "1",
  370. validTimeInterval = "1",
  371. validParkStatus = "1",
  372. validExceedWgt = "1",
  373. validPredictionDiff = "1",
  374. validLianda = "1",
  375. validMatClick = "1",
  376. setCar = "",
  377. rfidCar = "",
  378. photoCar = "",
  379. scanCar = "",
  380. editCar = "",
  381. carErr = "0",
  382. wgtErr = "0",
  383. stopOverTime = "0",
  384. msgInfo = "",
  385. //isTakeOver = "0",
  386. //userNo = "",
  387. ledWriter = ""
  388. };
  389. if (bVoice)
  390. {
  391. mwmUpdate.isHelp = "0";
  392. }
  393. //如果为1则是监控点击的远程计量,这个时候是不能清理的
  394. if (strIsRemote == "0")
  395. {
  396. mwmUpdate.userNo = "";
  397. mwmUpdate.isTakeOver = "0";
  398. }
  399. RESTfulResult<string> rm = monitorService.doUpdateWf(mwmUpdate);
  400. if (!rm.Succeed)
  401. {
  402. l.WriteLog(5, "初始化远程计量信息失败");
  403. }
  404. else
  405. {
  406. RESTfulResult<string> rmx = onlineService.doSaveWf(new MeterWorkOnline { userId = userId, workFlag = "0" });
  407. if (rmx.Succeed)
  408. {
  409. CleanForm();
  410. CleanCloseDb();
  411. }
  412. else
  413. {
  414. l.WriteLog(5, "初始化在线接管状态失败");
  415. }
  416. }
  417. }
  418. //如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  419. public void setMsgInfo(Control control, string ResultMessage, string sType)
  420. {
  421. setMsgMsg(control, ResultMessage, sType);
  422. }
  423. /// <summary>
  424. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable 3为check
  425. /// </summary>
  426. /// <param name="control"></param>
  427. /// <param name="ResultMessage"></param>
  428. /// <param name="sType"></param>
  429. private void setMsgMsg(Control control, string ResultMessage, string sType)
  430. {
  431. if (control.InvokeRequired)
  432. {
  433. Action<Control, string, string> action = new Action<Control, string, string>(setMsgInfo);
  434. Invoke(action, new object[] { control, ResultMessage, sType });
  435. }
  436. else
  437. {
  438. if (ResultMessage != "true" && ResultMessage != "false")
  439. {
  440. control.Text = ResultMessage == null ? "" : ResultMessage.Replace("请远程求助", "").Replace(",请点击语音求助", "");
  441. }
  442. else
  443. {
  444. switch (sType)
  445. {
  446. case "1":
  447. control.Enabled = ResultMessage == "true" ? true : false;
  448. ; break;
  449. case "2":
  450. control.Visible = ResultMessage == "true" ? true : false;
  451. ; break;
  452. case "3":
  453. ((CheckBox)control).Checked = ResultMessage == "true" ? true : false;
  454. break;
  455. default: break;
  456. }
  457. }
  458. }
  459. }
  460. public void setListBoxInfo(ListBox control)
  461. {
  462. setListBoxMsg(control);
  463. }
  464. /// <summary>
  465. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  466. /// </summary>
  467. /// <param name="control"></param>
  468. /// <param name="ResultMessage"></param>
  469. /// <param name="sType"></param>
  470. private void setListBoxMsg(ListBox control)
  471. {
  472. if (control.InvokeRequired)
  473. {
  474. Action<ListBox> action = new Action<ListBox>(setListBoxInfo);
  475. Invoke(action, new object[] { control });
  476. }
  477. else
  478. {
  479. control.Items.Clear();
  480. }
  481. }
  482. /// <summary>
  483. /// 设置readonly
  484. /// </summary>
  485. /// <param name="control"></param>
  486. /// <param name="sType">0为textbox 1为button</param>
  487. public void setReadOnlyInfo(Control control, string resultMsg, string sType)
  488. {
  489. setReadOnlyMsg(control, resultMsg, sType);
  490. }
  491. /// <summary>
  492. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  493. /// </summary>
  494. /// <param name="control"></param>
  495. /// <param name="ResultMessage"></param>
  496. /// <param name="sType"></param>
  497. private void setReadOnlyMsg(Control control, string resultMsg, string sType)
  498. {
  499. if (control.InvokeRequired)
  500. {
  501. Action<Control, string, string> action = new Action<Control, string, string>(setReadOnlyInfo);
  502. Invoke(action, new object[] { control, resultMsg, sType });
  503. }
  504. else
  505. {
  506. switch (sType)
  507. {
  508. case "0":
  509. ((TextBox)control).ReadOnly = resultMsg == "true" ? true : false;
  510. break;
  511. }
  512. }
  513. }
  514. public void setPanelRemovenfo(Panel control)
  515. {
  516. setPanelRemoveMsg(control);
  517. }
  518. /// <summary>
  519. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  520. /// </summary>
  521. /// <param name="control"></param>
  522. /// <param name="ResultMessage"></param>
  523. /// <param name="sType"></param>
  524. private void setPanelRemoveMsg(Panel p)
  525. {
  526. if (p.InvokeRequired)
  527. {
  528. Action<Panel> action = new Action<Panel>(setPanelRemovenfo);
  529. Invoke(action, new object[] { p });
  530. }
  531. else
  532. {
  533. for (int i = p.Controls.Count - 1; i >= 0; i--)
  534. {
  535. p.Controls.RemoveAt(i);
  536. }
  537. }
  538. }
  539. public void setGridInfo(UltraGrid control, DataTable dt1, DataTable dt2)
  540. {
  541. setGridMsg(control, dt1, dt2);
  542. }
  543. /// <summary>
  544. /// 如果ResultMessage为true或者false,则sType 为0的时候readonly 1为enable 2为visable
  545. /// </summary>
  546. /// <param name="control"></param>
  547. /// <param name="ResultMessage"></param>
  548. /// <param name="sType"></param>
  549. private void setGridMsg(UltraGrid p, DataTable dt1, DataTable dt2)
  550. {
  551. if (p.InvokeRequired)
  552. {
  553. Action<UltraGrid, DataTable, DataTable> action = new Action<UltraGrid, DataTable, DataTable>(setGridInfo);
  554. Invoke(action, new object[] { p, dt1, dt2 });
  555. }
  556. else
  557. {
  558. ClsControlPack.CopyDataToDatatable(ref dt1, ref dt2, true);
  559. ClsControlPack.RefreshAndAutoSize(p);
  560. }
  561. }
  562. private void CleanCloseDb()
  563. {
  564. //*****************这里需要将语音对讲/视频都关闭*******************
  565. //退出语音登录
  566. try
  567. {
  568. VoiceClose();
  569. IPVideoClose();
  570. }
  571. catch (Exception ex)
  572. {
  573. }
  574. ls = null;
  575. //*****************************************************************
  576. flagCarNo = false;
  577. setMsgInfo(plImgShow, "false", "2");
  578. DataTable dtJld = dtJGPointInfo.Clone();
  579. setGridInfo(ultraGridPW, dtJld, this.dtJGPointInfo);
  580. setMsgInfo(lbPointName, "", "");
  581. setMsgInfo(lbMeterMan, "", "");
  582. PbCache.Load();
  583. PbCache.sportInfo = null;
  584. PbCache.videoInfo = null;
  585. PbCache.videoChild = null;
  586. CarCache.cameraShots = null;
  587. PbCache.range = null;
  588. PbCache.relations = null;
  589. setPanelRemovenfo(panel1);
  590. bCollectionStart = false;
  591. //关闭采集进程
  592. collection.Stop();
  593. }
  594. private void CleanForm()
  595. {
  596. editCarNo = "";
  597. preCarNo = "";
  598. sPreNo = "";
  599. preWgt = 0;
  600. ndRemind = true;
  601. ls = null;
  602. preTack = null;
  603. iWgtChange = true;
  604. PbCache.dtStartTime = null;
  605. PbCache.isTermTare = false;
  606. dAddWgt = 0;
  607. PbCache.addWgt = 0;
  608. first = null;
  609. PbCache.isLockFrm = false;
  610. PbCache.lockWgt = 0;
  611. PbCache.lockCarNo = "";
  612. strCbCarNo = "";
  613. strTxtCarNo = "";
  614. strType = "0";
  615. PbCache.ResultMessage = "";
  616. setMsgInfo(btnInnerQuery, "false", "1");
  617. setMsgInfo(btnCheck, "false", "1");
  618. setMsgInfo(btnSave, "false", "1");
  619. setMsgInfo(btnTareWgt, "false", "1");
  620. setMsgInfo(btnCheckBalance, "false", "1");
  621. setMsgInfo(txtGroess, "", "");
  622. setMsgInfo(txtTare, "", "");
  623. setMsgInfo(txtNet, "", "");
  624. setMsgInfo(lbWgt, "", "");
  625. setMsgInfo(txtPage, "", "");
  626. setCbCarNoInfo("");
  627. setTxtCarNoInfo("");
  628. ucWeightT1.setWgt(0);
  629. ucWeightT1.setStable(true);
  630. ucWeightT1.setExceed(true);
  631. setPicQRed(false);
  632. setPicHRed(false);
  633. setPreTrackInfo(new PreTrackScale());
  634. setHistWgt(null, null);
  635. setReadOnlyInfo(txtPREDICTION_NO, "true", "0");
  636. setListBoxInfo(lb1);
  637. setListBoxInfo(lb2);
  638. setMsgInfo(txtMsgInfo, "", "");
  639. DataTable dtYb = dtPreTrackScale.Clone();
  640. setGridInfo(ultraGridYb, dtYb, this.dtPreTrackScale);
  641. DataTable dtSj = dataTable1.Clone();
  642. setGridInfo(ultraGridSj, dtSj, this.dataTable1);
  643. DataTable dtQxp = dtTare.Clone();
  644. setGridInfo(ultraGridTare, dtQxp, this.dtTare);
  645. DataTable dtJl = dtCalibration.Clone();
  646. setGridInfo(ultraGridJl, dtJl, this.dtCalibration);
  647. }
  648. #endregion
  649. #region button按钮事件
  650. private bool flagStart = true;
  651. private bool testFlage = false; //若为true,则重量就是输入的重量
  652. /// <summary>
  653. /// 自动派位
  654. /// </summary>
  655. private void btnStart_Click(object sender, EventArgs e)
  656. {
  657. if (btnStart.Text == "自动派位")
  658. {
  659. if (PbCache.sportInfo != null)
  660. {
  661. btnStart.BackColor = Color.Red;
  662. btnStart.Text = "取消接管";
  663. timer2.Stop();
  664. flagStart = false;
  665. }
  666. }
  667. else
  668. {
  669. strIsRemote = "0";
  670. if (PbCache.sportInfo != null)
  671. {
  672. Clean();
  673. }
  674. try
  675. {
  676. bCollectionStart = false;
  677. btnStart.BackColor = Color.DodgerBlue;
  678. btnStart.Text = "自动派位";
  679. timer2.Start();
  680. flagStart = true;
  681. }
  682. catch { }
  683. }
  684. }
  685. private bool bGQ = false;
  686. private void btnGQ_Click(object sender, EventArgs e)
  687. {
  688. if (btnGQ.Text == "挂起")
  689. {
  690. btnGQ.Text = "取消挂起";
  691. btnGQ.BackColor = Color.Red;
  692. bGQ = true;
  693. btnStart.Enabled = false;
  694. btnStart.BackColor = Color.DodgerBlue;
  695. btnStart.Text = "自动派位";
  696. timer2.Stop();
  697. flagStart = false;
  698. strIsRemote = "0";
  699. if (PbCache.sportInfo != null)
  700. {
  701. Clean();
  702. }
  703. try
  704. {
  705. //让用户处于掉线状态
  706. string sql = @"update Meter_Work_Online set last_time=sysdate-1 where user_id='" + appUser.userid + "'";
  707. PbModelDbService<string> pb = new PbModelDbService<string>();
  708. RESTfulResult<string> rm = pb.executeSqlDataWf(sql);
  709. }
  710. catch { }
  711. }
  712. else
  713. {
  714. bCollectionStart = false;
  715. btnGQ.Text = "挂起"; //改为非挂起状态
  716. btnGQ.BackColor = Color.DodgerBlue;
  717. bGQ = false;
  718. btnStart.Enabled = true;
  719. timer2.Start();
  720. flagStart = true;
  721. }
  722. }
  723. private List<string> ls = new List<string>();
  724. private double dAddWgt = 0;
  725. /// <summary>
  726. /// 选择器具
  727. /// </summary>
  728. private void btnCheck_Click(object sender, EventArgs e)
  729. {
  730. double dWgt = 0;
  731. //if (PbCache.collect.weightStatus == 0 && PbCache.collect.weight > 500)
  732. {
  733. frmApplianceCheck fac = new frmApplianceCheck();
  734. fac.ltAddWeightNo = ls == null ? null : ls;
  735. if (fac.ShowDialog() == DialogResult.OK)
  736. {
  737. dAddWgt = 0;
  738. lbUTENSIL_UTENSIL_NAME.Text = "";
  739. lbWgt.Text = "0";
  740. lb1.Items.Clear();
  741. lb2.Items.Clear();
  742. DataTable dt = fac.dtChecked;
  743. ls = fac.ltAddWeightNo;
  744. if (dt != null && dt.Rows.Count > 0)
  745. {
  746. foreach (DataRow dr in dt.Rows)
  747. {
  748. if (lbUTENSIL_UTENSIL_NAME.Text == "")
  749. {
  750. lbUTENSIL_UTENSIL_NAME.Text = dr["utensilUtensilName"].ToString();
  751. }
  752. if (lb1.Items.Count < 7)
  753. {
  754. lb1.Items.Add(dr["utensilNo"].ToString());
  755. }
  756. else
  757. {
  758. lb2.Items.Add(dr["utensilNo"].ToString());
  759. }
  760. dWgt += Convert.ToDouble(dr["utensilWeight"].ToString());
  761. }
  762. lbWgt.Text = dWgt + "";
  763. dAddWgt = dWgt;
  764. }
  765. }
  766. if (txtGroess.Text.Trim() != "" && txtTare.Text.Trim() != "")
  767. {
  768. txtNet.Text = (Convert.ToInt32(txtGroess.Text.Trim()) - Convert.ToInt32(txtTare.Text.Trim()) - dWgt) + "";
  769. }
  770. }
  771. }
  772. #region 对讲代码
  773. /// <summary>
  774. /// 硬盘录像机登录
  775. /// </summary>
  776. private DhCameraShot cameraShotMain = new DhCameraShot();
  777. /// <summary>
  778. /// 必须先打开连接
  779. /// </summary>
  780. private bool GetIPVideo(MeterBaseVideoinfo video)
  781. {
  782. try
  783. {
  784. cameraShotMain.ip = video.videoip;
  785. cameraShotMain.port = video.vdoPort;
  786. cameraShotMain.uid = video.vdoUser;
  787. cameraShotMain.pwd = video.vdoPwd;
  788. cameraShotMain.Connection();
  789. }
  790. catch (Exception ex)
  791. {
  792. setMsgInfo(txtMsgInfo, "视频连接打开失败:" + ex.Message, "");
  793. //MessageBox.Show(ex.Message);
  794. return false;
  795. }
  796. return true;
  797. }
  798. private bool bVoice = false;
  799. /// <summary>
  800. /// 必须先打开视频,然后再打开语音
  801. /// </summary>
  802. private void VoiceOpen()
  803. {
  804. try
  805. {
  806. if (cameraShotMain.StartTalk())
  807. {
  808. btnOpenVoice.Text = "关闭对讲";
  809. bVoice = true;
  810. }
  811. }
  812. catch (Exception ex)
  813. {
  814. setMsgInfo(txtMsgInfo, "打开语音失败:" + ex.Message, "");
  815. //MessageBox.Show("打开语音失败:" + ex.Message);
  816. }
  817. }
  818. /// <summary>
  819. /// 关闭语音对讲
  820. /// </summary>
  821. private void VoiceClose()
  822. {
  823. try
  824. {
  825. if (cameraShotMain.StopTalk())
  826. {
  827. setMsgInfo(btnOpenVoice, "打开对讲", "");
  828. bVoice = false;
  829. }
  830. }
  831. catch (Exception ex)
  832. {
  833. setMsgInfo(txtMsgInfo, "打开对讲失败:" + ex.Message, "");
  834. //MessageBox.Show(ex.Message);
  835. }
  836. }
  837. /// <summary>
  838. /// 关闭视频
  839. /// </summary>
  840. private void IPVideoClose()
  841. {
  842. try
  843. {
  844. cameraShotMain.Close();
  845. }
  846. catch (Exception ex)
  847. {
  848. setMsgInfo(txtMsgInfo, "关闭对讲失败:" + ex.Message, "");
  849. //MessageBox.Show(ex.Message);
  850. }
  851. }
  852. #endregion
  853. /// <summary>
  854. /// 对讲
  855. /// </summary>
  856. private void btnOpenVoice_Click(object sender, EventArgs e)
  857. {
  858. if (panel1.Controls.Count > 0)
  859. {
  860. if (btnOpenVoice.Text == "打开对讲")
  861. {
  862. VoiceOpen();
  863. }
  864. else
  865. {
  866. VoiceClose();
  867. }
  868. }
  869. }
  870. /// <summary>
  871. /// 校秤
  872. /// </summary>
  873. private void btnCheckBalance_Click(object sender, EventArgs e)
  874. {
  875. //if (PbCache.collect.weightStatus == 0 && PbCache.collect.weight > 500)
  876. {
  877. PbCache.isLockFrm = true;
  878. if (PbCache.collect != null)
  879. {
  880. txtMsgInfo.Text = "";
  881. PbCache.lockWgt = PbCache.collect.weight;
  882. frmCalibration fc = new frmCalibration();
  883. fc.userId = userId;
  884. fc.userName = userName;
  885. if (fc.ShowDialog() == DialogResult.OK)
  886. {
  887. txtMsgInfo.Text = "校秤完成";
  888. PbCache.isLockFrm = false;
  889. //Clean();
  890. }
  891. else
  892. {
  893. PbCache.isLockFrm = false;
  894. }
  895. }
  896. }
  897. }
  898. /// <summary>
  899. /// 期限皮
  900. /// </summary>
  901. private void btnTareWgt_Click(object sender, EventArgs e)
  902. {
  903. //if (PbCache.collect.weightStatus == 0 && PbCache.collect.weight > 500)
  904. {
  905. if (string.IsNullOrEmpty(strCbCarNo + strTxtCarNo))
  906. {
  907. MessageBox.Show("请先输入一个车号");
  908. return;
  909. }
  910. PbCache.lockWgt = PbCache.collect.weight;
  911. //是否可留期限皮
  912. if (!termTareCar.ValidMethod(PbCache.collect.carno))
  913. {
  914. if (PbCache.ResultMessage.Contains("无法留期限皮"))
  915. {
  916. DialogResult drs = MessageBox.Show(PbCache.ResultMessage.Replace("无法留期限皮", "") + " 确认留期限皮吗?", "提示", MessageBoxButtons.OKCancel);
  917. if (drs != DialogResult.OK)
  918. return;
  919. }
  920. else
  921. {
  922. txtMsgInfo.Text = PbCache.ResultMessage;
  923. //MessageBox.Show(PbCache.ResultMessage);
  924. return;
  925. }
  926. }
  927. else
  928. {
  929. DialogResult dr = MessageBox.Show("确认留期限皮吗?", "提示", MessageBoxButtons.OKCancel);
  930. if (dr != DialogResult.OK)
  931. return;
  932. }
  933. txtMsgInfo.Text = "称重保存中,请稍等......";
  934. PbCache.isLockFrm = true;
  935. PbCache.lockCarNo = strCbCarNo + strTxtCarNo;
  936. MeterBaseTermTareData mbttd = new MeterBaseTermTareData();
  937. mbttd.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  938. mbttd.baseSpotName = PbCache.sportInfo.baseSpotName;
  939. mbttd.carNo = PbCache.collect.carno;
  940. mbttd.meterWeight = PbCache.lockWgt;
  941. mbttd.valueFlag = "0";
  942. mbttd.createTime = DateTime.Now;
  943. mbttd.createManNo = PbCache.sportInfo.baseSpotNo;
  944. mbttd.createManName = PbCache.sportInfo.baseSpotName;
  945. mbttd.meterTime = mbttd.createTime.Value;
  946. mbttd.startTime = mbttd.createTime.Value;
  947. //操作日志
  948. MeterMonitorNote monitorNote = new MeterMonitorNote();
  949. monitorNote.baseSpotNo = mbttd.baseSpotNo;
  950. monitorNote.baseSpotName = mbttd.baseSpotName;
  951. monitorNote.operationContent = string.Format("保存期限皮重");
  952. monitorNote.operationTime = mbttd.createTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  953. monitorNote.carNo = mbttd.carNo;
  954. monitorNote.meterNoteSource = "4";
  955. monitorNote.meterManNo = userId;
  956. monitorNote.meterManName = userName;
  957. //期限皮重数据保存
  958. RESTfulResult<string> RESTfulResult = termTareDate.doSaveWf(mbttd, monitorNote);
  959. if (RESTfulResult.Succeed)
  960. {
  961. txtMsgInfo.Text = "期限皮重保存成功!";
  962. //MessageBox.Show("期限皮重保存成功!");
  963. //Clean();
  964. }
  965. else
  966. {
  967. txtMsgInfo.Text = "期限皮重保存失败!" + RESTfulResult.ResultMessage;
  968. //MessageBox.Show("保存失败:" + RESTfulResult.ResultMessage);
  969. }
  970. }
  971. }
  972. /// <summary>
  973. /// 保存
  974. /// </summary>
  975. private void btnSave_Click(object sender, EventArgs e)
  976. {
  977. //if (PbCache.collect.weightStatus == 0 && PbCache.collect.weight > 500)
  978. {
  979. if (string.IsNullOrEmpty(strCbCarNo + strTxtCarNo))
  980. {
  981. MessageBox.Show("请先输入一个车号");
  982. return;
  983. }
  984. txtMsgInfo.Text = "";
  985. DialogResult dr = MessageBox.Show("是否确认保存当前计量数据?", "提示", MessageBoxButtons.OKCancel);
  986. #region 增加校秤判断
  987. string msgInfo = "";
  988. bool isCalibration = vCalib.ValidMethod(new MeterWorkCalibrationMain { baseSpotNo = PbCache.sportInfo.baseSpotNo, valueFlag = "2" }, out msgInfo);
  989. if (!isCalibration)
  990. {
  991. MeterBaseCalibraNumRel calibraNumRel = PbCache.ltBaseCalibraNumRel.Where(s => s.baseSpotNo == PbCache.sportInfo.baseSpotNo).FirstOrDefault();
  992. if (calibraNumRel == null || calibraNumRel.isMeter == "否" || PbCache.collect.weight > (calibraNumRel.upWeight == null ? 0 : calibraNumRel.upWeight.Value))
  993. {
  994. txtMsgInfo.Text = "未校秤无法计量";
  995. return;
  996. }
  997. }
  998. #endregion
  999. PbCache.isLockFrm = true;
  1000. PbCache.lockWgt = PbCache.collect.weight;
  1001. PbCache.lockCarNo = strCbCarNo + strTxtCarNo;
  1002. btnSave.Enabled = false;
  1003. //PbCache.addWgt = lbWgt.Text.Trim() == "" ? 0 : Convert.ToDouble(lbWgt.Text.Trim());
  1004. PbCache.addWgt = Convert.ToDouble(string.IsNullOrEmpty(lbWgt.Text) ? 0 : lbWgt.Value);
  1005. if (dr == DialogResult.OK)
  1006. {
  1007. txtMsgInfo.Text = "称重保存中,请稍等......";
  1008. btnSave.Enabled = false;
  1009. try
  1010. {
  1011. bool flag = false;
  1012. string strMsg = "";
  1013. #region =================eason add 2021-11-26联达业务=====================
  1014. bool fLianda = false;
  1015. RESTfulResult<MeterBaseMatterInfo> result = matterInfoService.doQueryId(preTack.matterNo);
  1016. if (result.Succeed)
  1017. {
  1018. RESTfulResult<List<MeterWorkCarActualFirst>> resultFst = workCarActualFirstService.doQueryWf(new MeterWorkCarActualFirst { carNo = (cbCarNo.Text.Trim() + txtCarNo.Text.Trim()), valueFlag = "1" });
  1019. //计量实绩
  1020. CommonPage<MeterWorkCarActual> cpc = new CommonPage<MeterWorkCarActual>();
  1021. MeterWorkCarActual mwca = new MeterWorkCarActual();
  1022. mwca.carNo = (cbCarNo.Text.Trim() + txtCarNo.Text.Trim());
  1023. mwca.predictionNo = txtPREDICTION_NO.Text.Trim();
  1024. cpc.param = mwca;
  1025. cpc.pageSize = 1;
  1026. RESTfulResult<List<MeterWorkCarActual>> rm = mwas.doQueryOneWf(cpc);
  1027. if (!resultFst.Succeed)
  1028. {
  1029. throw new Exception("获取一次计量数据失败!");
  1030. }
  1031. if (PbCache.sportInfo?.baseSpotNo == lianDaPointNo)
  1032. {
  1033. //1.1是联达秤点则判断是不是联达物料
  1034. if (result?.Data?.isLianda == "1")
  1035. {
  1036. //1.1.1是联达物料则判断是否存在未结净的数据,若存在则该数据必须与当前预报编号一致,不一致则提示错误,
  1037. //一致则看结净表中存在一条预报编号一致的正常结净数据若存在则联达结净,若不存在正常结净的数据则提示先去过其它磅
  1038. if (resultFst.Data == null)
  1039. {
  1040. //=====================直接联达过毛重即可=====================
  1041. rtInfo ri = lianda.MeterMethod(preTack, appUser, lianDaWgt);
  1042. fLianda = true;
  1043. flag = ri.result;
  1044. strMsg = PbCache.ResultMessage;
  1045. }
  1046. else if (resultFst.Data.Count == 1)
  1047. {
  1048. //若存在则该数据必须与当前预报编号一致,不一致则提示错误
  1049. if (resultFst.Data[0].predictionNo == $"{preTack.predictionNo}_")
  1050. {
  1051. if (rm.Succeed)
  1052. {
  1053. if (rm.Data == null || rm.Data.Count == 0)
  1054. {
  1055. throw new Exception("请先去其它秤点完成一、二次计量,最后再来联达过皮重");
  1056. }
  1057. else
  1058. {
  1059. //=====================联达结净=====================
  1060. rtInfo ri = lianda.MeterMethod(preTack, appUser, lianDaWgt);
  1061. fLianda = true;
  1062. flag = ri.result;
  1063. strMsg = PbCache.ResultMessage;
  1064. }
  1065. }
  1066. else
  1067. {
  1068. throw new Exception("获取结净数据失败!");
  1069. }
  1070. }
  1071. else
  1072. {
  1073. throw new Exception($"存在一条未完成计量的联达数据,预报编号为{resultFst.Data[0].predictionNo}");
  1074. }
  1075. }
  1076. else
  1077. {
  1078. //可能是一条联达的未结净,然后一条正常过磅的未结净,需要先将未结净的结净再来过联达的
  1079. throw new Exception("存在多条未结净的数据");
  1080. }
  1081. }
  1082. else
  1083. {
  1084. //1.1.2不是联达物料则看是否存在未结净的联达物料
  1085. if (resultFst.Data != null)
  1086. {
  1087. //1.1.2.1存在未结净的物料若不是同一个预报编号则提示
  1088. if (resultFst.Data.Count == 1)
  1089. {
  1090. if (resultFst.Data[0].predictionNo != preTack.predictionNo)
  1091. {
  1092. throw new Exception("当前过磅预报与未结净预报编号不一致");
  1093. }
  1094. //否则正常结净
  1095. }
  1096. else
  1097. {
  1098. throw new Exception("存在多条未结净的数据");
  1099. }
  1100. }
  1101. //1.1.2.2不存在未结净的物料则按正常过磅走
  1102. }
  1103. }
  1104. else
  1105. {
  1106. //1.2不是联达秤点则判断是不是联达物料
  1107. if (result?.Data?.isLianda == "1")
  1108. {
  1109. //如果是联达的物料,则判断是否存在该预报对应的未结净的联达数据,若存在则结净,不存在则提示 这里严谨点的话,得根据车号未结净的判断
  1110. if (resultFst.Data == null)
  1111. {
  1112. throw new Exception("当前物料为联达物料请先到联达秤过磅");
  1113. }
  1114. else if (resultFst.Data.Count == 1)
  1115. {
  1116. //如果预报编号相同,且是联达的预报编号,则让其正常走过毛的流程,若不相同则提示
  1117. if (resultFst.Data[0].predictionNo != $"{preTack.predictionNo}_")
  1118. {
  1119. throw new Exception("当前过磅预报与未结净预报编号不一致");
  1120. }
  1121. //正常过毛重即可
  1122. }
  1123. else if (resultFst.Data.Count == 2)
  1124. {
  1125. //如果两条数据分别是联达的及一条普通毛则走结净,否则提示错误
  1126. int icnt = 0;
  1127. foreach (MeterWorkCarActualFirst firstD in resultFst.Data)
  1128. {
  1129. if (firstD.predictionNo == preTack.predictionNo || firstD.predictionNo == $"{preTack.predictionNo}_")
  1130. {
  1131. icnt++;
  1132. }
  1133. }
  1134. if (icnt != 2)
  1135. {
  1136. throw new Exception("存在多条未结净的数据");
  1137. }
  1138. //否则正常结净即可
  1139. }
  1140. else
  1141. {
  1142. throw new Exception("存在多条未结净的数据");
  1143. }
  1144. }
  1145. else
  1146. {
  1147. //不是联达的物料则看是否存在未结净的计量数据,若存在则必须预报编号一致否则提示错误,若不存在还是往后走
  1148. if (resultFst.Data != null)
  1149. {
  1150. if (resultFst.Data.Count == 1)
  1151. {
  1152. if (resultFst.Data[0].predictionNo != preTack.predictionNo)
  1153. {
  1154. throw new Exception("当前过磅预报与未结净预报编号不一致");
  1155. }
  1156. //继续走结净流程
  1157. }
  1158. else
  1159. {
  1160. throw new Exception("存在多条未结净的数据");
  1161. }
  1162. }
  1163. //走一次计量流程
  1164. }
  1165. }
  1166. }
  1167. else
  1168. {
  1169. throw new Exception("获取物料信息失败!");
  1170. }
  1171. if (!fLianda)
  1172. {
  1173. #endregion ===============================================================
  1174. //没有业务编号或者业务编号不是非内倒业务则认为是内倒
  1175. if (strType == "0")
  1176. {
  1177. rtInfo ri = null;
  1178. //获取稳定的重量,车号,计量信息等,然后进行计量业务操作; preTack仅有一个来源即输入业务号的时候,否则全是皮重;
  1179. if (preTack != null)
  1180. {
  1181. ri = inner.MeterMethod(new InnerMeterInfo
  1182. {
  1183. carNo = cbCarNo.Text.Trim() + txtCarNo.Text.Trim(),
  1184. batchNo = "",
  1185. forwardingUnitNo = preTack.forwardingUnitNo,
  1186. forwardingUnitName = preTack.forwardingUnitName,
  1187. matterNo = preTack.matterNo,
  1188. matterName = preTack.matterName,
  1189. receivingUintName = preTack.receivingUintName,
  1190. receivingUintNo = preTack.receivingUintNo,
  1191. meterTypeNo = "001006003",
  1192. meterTypeName = PbCache.businessType.Where(s => s.baseCode == "001006003").FirstOrDefault().baseName,
  1193. predictionNo = txtPREDICTION_NO.Text.Trim()
  1194. }, appUser);
  1195. }
  1196. else
  1197. {
  1198. ri = inner.MeterMethod(new InnerMeterInfo
  1199. {
  1200. carNo = cbCarNo.Text.Trim() + txtCarNo.Text.Trim(),
  1201. batchNo = "",
  1202. forwardingUnitNo = "",
  1203. forwardingUnitName = "",
  1204. matterNo = "",
  1205. matterName = "",
  1206. receivingUintName = "",
  1207. receivingUintNo = "",
  1208. meterTypeNo = "001006003",
  1209. meterTypeName = PbCache.businessType.Where(s => s.baseCode == "001006003").FirstOrDefault().baseName,
  1210. predictionNo = ""
  1211. }, appUser);
  1212. }
  1213. flag = ri.result;
  1214. strMsg = PbCache.ResultMessage;
  1215. }
  1216. else if (strType == "1")//存在业务编号且是非内倒计量业务
  1217. {
  1218. //将卡控条件设置为0,放过所有卡控
  1219. PbCache.isNotValid = true;
  1220. flag = false;
  1221. if (scene.WeightMeter(preTack, appUser, out strMsg)) //meterTypeNo "001006001","001006002"
  1222. {
  1223. flag = true;
  1224. }
  1225. }
  1226. else
  1227. {
  1228. flag = false;
  1229. PbCache.ResultMessage = "请输入正确的业务编号之后按回车";
  1230. }
  1231. }
  1232. if (flag)
  1233. {
  1234. #region 截取图片信息
  1235. try
  1236. {
  1237. //*
  1238. //截取屏幕信息
  1239. Point screenPoint = this.PointToScreen(new Point());
  1240. Rectangle rect = new Rectangle(screenPoint, this.Size);
  1241. Image img = new Bitmap(rect.Width, rect.Height);
  1242. Graphics g = Graphics.FromImage(img);
  1243. g.CopyFromScreen(rect.X - 1, rect.Y - 1, 0, 0, rect.Size);//"D://file/1.jpg"
  1244. img.Save(string.Format("{0}imgShort\\tempImg\\{1}_{2}_{3}.jpg",
  1245. AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
  1246. PbCache.sportInfo.baseSpotNo,
  1247. "C" + PbCache.actualFirstNo,
  1248. (PbCache.videoChild.Count + 1)), System.Drawing.Imaging.ImageFormat.Jpeg);
  1249. //*
  1250. //最后进行截图操作
  1251. CameraShotCls cameraShot = new CameraShotCls();
  1252. cameraShot.CapMethod(PbCache.actualFirstNo);
  1253. //*/
  1254. }
  1255. catch (Exception ex)
  1256. {
  1257. l.WriteLog(5, PbCache.lockCarNo + "截图失败");
  1258. }
  1259. #endregion
  1260. #region LED写入
  1261. PbCache.ledInfo = string.Format("计量完成,车号:{0},车重:{1},物资:{2}", PbCache.lockCarNo, PbCache.lockWgt, txtMATTER_NAME.Text.Trim());
  1262. #endregion
  1263. //Clean();
  1264. try
  1265. {
  1266. QueryCarNo();
  1267. }
  1268. catch { }
  1269. }
  1270. else
  1271. {
  1272. PbCache.isLockFrm = false;
  1273. btnSave.Enabled = true;
  1274. }
  1275. txtMsgInfo.Text = PbCache.ResultMessage;
  1276. if (!string.IsNullOrEmpty(PbCache.ResultMessage))
  1277. {
  1278. txtMsgInfo.Text = PbCache.ResultMessage;
  1279. //MessageBox.Show(PbCache.ResultMessage);
  1280. }
  1281. }
  1282. catch (Exception ex)
  1283. {
  1284. btnSave.Enabled = true;
  1285. PbCache.isLockFrm = false;
  1286. txtMsgInfo.Text = "保存失败:" + ex.Message.Trim();
  1287. l.WriteLog(5, "保存失败:" + ex.Message.Trim());
  1288. //MessageBox.Show("保存失败:" + ex.Message.Trim());
  1289. }
  1290. }
  1291. else
  1292. {
  1293. txtMsgInfo.Text = PbCache.ResultMessage;
  1294. btnSave.Enabled = true;
  1295. PbCache.isLockFrm = false;
  1296. }
  1297. }
  1298. }
  1299. /// <summary>
  1300. /// 0为内倒 1为非内倒
  1301. /// </summary>
  1302. private string strType = "0";
  1303. /// <summary>
  1304. /// 回车时触发查询
  1305. /// </summary>
  1306. private void txtPREDICTION_NO_KeyDown(object sender, KeyEventArgs e)
  1307. {
  1308. if (e.KeyValue == 13)
  1309. {
  1310. QueryInnerInfo(); //回车时触发查询
  1311. }
  1312. }
  1313. /// <summary>
  1314. /// 查询内倒业务号信息
  1315. /// </summary>
  1316. private void QueryInnerInfo()
  1317. {
  1318. txtFORWARDING_UNIT_NAME.Text = "";
  1319. txtMATTER_NAME.Text = "";
  1320. txtRECEIVING_UINT_NAME.Text = "";
  1321. preTack = null;
  1322. string strM = txtPREDICTION_NO.Text.Trim();
  1323. PbCache.strCode = strM;
  1324. setPreTrackInfo(new PreTrackScale());
  1325. if (strM.Length == 9)
  1326. {
  1327. strType = "0";
  1328. //内部物料,需确认车辆是否为内倒车辆
  1329. string sql = @"select t1.load_point_no as id, t1.load_point_name text, t1.meter_code text2
  1330. from meter_base_load_point t1
  1331. where t1.meter_code = '" + strM.Substring(3, 3) + @"'
  1332. and t1.valid_Flag = '1'
  1333. union all
  1334. select t1.load_point_no as id, t1.load_point_name text, t1.meter_code text2
  1335. from meter_base_load_point t1
  1336. where t1.meter_code = '" + strM.Substring(6, 3) + @"'
  1337. and t1.valid_Flag = '1'
  1338. union all
  1339. select t2.matter_no as id, t2.matter_name text, t2.meter_code text2
  1340. from meter_base_matter_info t2
  1341. where t2.meter_code = '" + strM.Substring(0, 3) + @"'
  1342. and t2.valid_Flag = '1'";
  1343. PbModelDbService<List<PbModelDb>> pb = new PbModelDbService<List<PbModelDb>>();
  1344. RESTfulResult<List<PbModelDb>> rm = pb.executeSqlDataWf(sql);
  1345. if (rm.Succeed && rm.Data.Count == 3)
  1346. {
  1347. txtMsgInfo.Text = "内倒计量:当前为毛重状态";
  1348. txtFORWARDING_UNIT_NAME.Text = rm.Data[0].text;
  1349. txtMATTER_NAME.Text = rm.Data[2].text;
  1350. txtRECEIVING_UINT_NAME.Text = rm.Data[1].text;
  1351. preTack = new PreTrackScale
  1352. {
  1353. predictionNo = strM,
  1354. forwardingUnitNo = rm.Data[0].id,
  1355. forwardingUnitName = rm.Data[0].text,
  1356. matterNo = rm.Data[2].id,
  1357. matterName = rm.Data[2].text,
  1358. receivingUintNo = rm.Data[1].id,
  1359. receivingUintName = rm.Data[1].text,
  1360. meterTypeNo = "001006003",
  1361. meterTypeName = ""
  1362. };
  1363. setPreTrackInfo(preTack);
  1364. seValidWhp();
  1365. txtMETER_TYPE.Text = "内倒";
  1366. #region 是否可用期限皮
  1367. PbCache.isTermTare = false;
  1368. sql = @"select matter_no id,
  1369. allowed_tare_weight text,
  1370. allowed_add_weight text2
  1371. from meter_base_matter_info
  1372. where valid_Flag = '1' and matter_no = '" + rm.Data[2].id + "'";
  1373. RESTfulResult<List<PbModelDb>> rmT = pb.executeSqlDataWf(sql);
  1374. if (rmT.Succeed)
  1375. {
  1376. if (rmT.Data != null && rmT.Data.Count > 0 && rmT.Data[0].text == "1")
  1377. {
  1378. PbCache.isTermTare = true;
  1379. }
  1380. }
  1381. #endregion
  1382. }
  1383. else
  1384. {
  1385. txtMsgInfo.Text = "不存在该业务编码,请确定输入的信息是否有错或业务编码是否存在";
  1386. //MessageBox.Show("不存在该业务编码,请确定输入的信息是否有错或业务编码是否存在");
  1387. }
  1388. }
  1389. else if (strM.Length > 0)
  1390. {
  1391. strType = "2";
  1392. RESTfulResult<List<PreTrackScale>> rm = service.doQueryWf(new PreTrackScale { predictionNo = strM });
  1393. if (rm.Succeed)
  1394. {
  1395. if (rm.Data == null || rm.Data.Count == 0)
  1396. {
  1397. txtMsgInfo.Text = "未找到预报信息,请确定输入的信息是否有错";
  1398. }
  1399. else
  1400. {
  1401. if (rm.Data[0].valueFlag != "1" && rm.Data[0].valueFlag != "4") //1未使用,4正使用
  1402. {
  1403. txtMsgInfo.Text = "请确保当前预报已配车且未使用或正使用";
  1404. }
  1405. else
  1406. {
  1407. preTack = rm.Data[0];
  1408. setPreTrackInfo(preTack);
  1409. seValidWhp();
  1410. strType = "1";
  1411. btnSave.Visible = validPredictionNo(preTack.predictionNo);
  1412. }
  1413. }
  1414. }
  1415. }
  1416. txtPREDICTION_NO.Text = strM;
  1417. }
  1418. #endregion
  1419. #region 数据设置及清空
  1420. /// <summary>
  1421. /// 清空或设置预报信息
  1422. /// </summary>
  1423. private void setPreTrackInfo(PreTrackScale pts)
  1424. {
  1425. setMsgInfo(txtPREDICTION_NO, pts.predictionNo == null ? "" : pts.predictionNo, "");
  1426. setMsgInfo(txtBATCH_NO, pts.batchNo == null ? "" : pts.batchNo, "");
  1427. setMsgInfo(txtBATCH_NO, pts.batchNo == null ? "" : pts.batchNo, "");
  1428. setMsgInfo(txtMATTER_NAME, pts.matterName == null ? "" : pts.matterName, "");
  1429. setMsgInfo(txtMETER_TYPE, pts.meterTypeName == null ? "" : pts.meterTypeName, "");
  1430. setMsgInfo(txtFORWARDING_UNIT_NAME, pts.forwardingUnitName == null ? "" : pts.forwardingUnitName, "");
  1431. setMsgInfo(txtRECEIVING_UINT_NAME, pts.receivingUintName == null ? "" : pts.receivingUintName, "");
  1432. setMsgInfo(txtLOAD_POINT_NAME, pts.loadPointName == null ? "" : pts.loadPointName, "");
  1433. setMsgInfo(txtCARRIER_UNIT_NAME, pts.carrierUnitName == null ? "" : pts.carrierUnitName, "");
  1434. setMsgInfo(txtRemark, pts.memo == null ? "" : pts.memo, "");
  1435. setMsgInfo(txtSHIPMENT_NET_WEIGHT, pts.shipmentNetWeight == null ? "" : pts.shipmentNetWeight.Value + "", "");
  1436. setMsgInfo(txtSHIPMENT_GROSS_WEIGHT, pts.shipmentGrossWeight == null ? "" : pts.shipmentGrossWeight.Value + "", "");
  1437. setMsgInfo(chkSample, string.IsNullOrEmpty(pts.sampleNo) ? "false" : "true", "3");
  1438. setMsgInfo(chkChemical, "false", "3");
  1439. }
  1440. private void setHistWgt(double? dHisTareWgt, int? iCount)
  1441. {
  1442. setMsgInfo(txtHisTare, dHisTareWgt == null ? "" : dHisTareWgt.Value + "", "");
  1443. setMsgInfo(txtCount, iCount == null ? "" : iCount.Value + "", "");
  1444. }
  1445. private string strCbCarNo = "";
  1446. public void setCbCarNoInfo(string ResultMessage)
  1447. {
  1448. setCbCarNo(ResultMessage);
  1449. }
  1450. private void setCbCarNo(string ResultMessage)
  1451. {
  1452. if (cbCarNo.InvokeRequired)
  1453. {
  1454. Action<string> action = new Action<string>(setCbCarNoInfo);
  1455. Invoke(action, new object[] { ResultMessage });
  1456. }
  1457. else
  1458. {
  1459. if (string.IsNullOrEmpty(ResultMessage))
  1460. {
  1461. cbCarNo.SelectedIndex = -1;
  1462. }
  1463. cbCarNo.Text = ResultMessage;
  1464. strCbCarNo = cbCarNo.Text.Trim();
  1465. }
  1466. }
  1467. private string strTxtCarNo = "";
  1468. public void setTxtCarNoInfo(string ResultMessage)
  1469. {
  1470. setTxtCarNo(ResultMessage);
  1471. }
  1472. private void setTxtCarNo(string ResultMessage)
  1473. {
  1474. if (txtCarNo.InvokeRequired)
  1475. {
  1476. Action<string> action = new Action<string>(setTxtCarNoInfo);
  1477. Invoke(action, new object[] { ResultMessage });
  1478. }
  1479. else
  1480. {
  1481. txtCarNo.Text = ResultMessage;
  1482. strTxtCarNo = txtCarNo.Text.Trim();
  1483. }
  1484. }
  1485. public void setPicQRed(bool bRed)
  1486. {
  1487. setQRed(bRed);
  1488. }
  1489. private void setQRed(bool bRed)
  1490. {
  1491. if (picQRed.InvokeRequired)
  1492. {
  1493. Action<bool> action = new Action<bool>(setPicQRed);
  1494. Invoke(action, new object[] { bRed });
  1495. }
  1496. else
  1497. {
  1498. if (bRed)
  1499. {
  1500. picQRed.Load(PbCache.path + "\\image\\icon\\red.gif");
  1501. }
  1502. else
  1503. {
  1504. picQRed.Load(PbCache.path + "\\image\\icon\\green.gif");
  1505. }
  1506. }
  1507. }
  1508. public void setPicHRed(bool bRed)
  1509. {
  1510. setHRed(bRed);
  1511. }
  1512. private void setHRed(bool bRed)
  1513. {
  1514. if (picHRed.InvokeRequired)
  1515. {
  1516. Action<bool> action = new Action<bool>(setPicHRed);
  1517. Invoke(action, new object[] { bRed });
  1518. }
  1519. else
  1520. {
  1521. if (bRed)
  1522. {
  1523. picHRed.Load(PbCache.path + "\\image\\icon\\red.gif");
  1524. }
  1525. else
  1526. {
  1527. picHRed.Load(PbCache.path + "\\image\\icon\\green.gif");
  1528. }
  1529. }
  1530. }
  1531. #endregion
  1532. private int iCnt = 0, iTimes = 0;
  1533. private void timer1_Tick(object sender, EventArgs e)
  1534. {
  1535. iCnt++;
  1536. if (iCnt % 3 == 0)
  1537. {
  1538. //未挂起则3秒写入一次在线状态
  1539. if (!bGQ)
  1540. {
  1541. RESTfulResult<string> rm = onlineService.doSaveWf(new MeterWorkOnline { userId = userId });
  1542. }
  1543. iCnt = 0;
  1544. }
  1545. iTimes++;
  1546. if (iTimes > 600 && !bCollectionStart)
  1547. {
  1548. //没有远程接管的情况下十分钟载入一次基础数据
  1549. iTimes = 0;
  1550. bd.setBaseDb();
  1551. }
  1552. }
  1553. private void cbCarNo_SelectedIndexChanged(object sender, EventArgs e)
  1554. {
  1555. if (PbCache.collect != null && PbCache.collect.weight > 0)
  1556. {
  1557. if (cbCarNo.SelectedIndex > -1)
  1558. {
  1559. strCbCarNo = cbCarNo.Text.Trim();
  1560. QueryCarNo();
  1561. flagCarNo = true;
  1562. }
  1563. }
  1564. }
  1565. private bool flagCarNo = false, isFocus = false;
  1566. private void txtCarNo_KeyDown(object sender, EventArgs e)
  1567. {
  1568. if (PbCache.collect != null && PbCache.collect.weight > 0)
  1569. {
  1570. strTxtCarNo = txtCarNo.Text.Trim();
  1571. QueryCarNo();
  1572. flagCarNo = true;
  1573. }
  1574. }
  1575. private void getFocusInfo(Control control)
  1576. {
  1577. if (txtCarNo.InvokeRequired)
  1578. {
  1579. Action<Control> action = new Action<Control>(getFocusInfo);
  1580. Invoke(action, new object[] { control });
  1581. }
  1582. else
  1583. {
  1584. isFocus = control.Focused;
  1585. }
  1586. }
  1587. private void QueryCarNo()
  1588. {
  1589. if (PbCache.sportInfo != null)
  1590. {
  1591. if (strTxtCarNo != "" && strCbCarNo != "") //&& PbCache.collect.weightStatus == 0)
  1592. {
  1593. PbCache.collect.carno = strCbCarNo + strTxtCarNo;
  1594. first = null;
  1595. //setHistWgt(null, null);
  1596. //METER_BASE_HIS_TARE_DATA
  1597. RESTfulResult<List<MeterBaseHisTareData>> rmH = meterBaseHisTareData.doQueryWf(new MeterBaseHisTareData { carNo = PbCache.collect.carno, valueFlag = "0" });
  1598. if (rmH.Succeed && rmH.Data != null && rmH.Data.Count > 0)
  1599. {
  1600. string HisTareWgt = PbCache.tareCount != null ? (PbCache.tareCount.contrastTypeNo == "001012001" ? rmH.Data[0].upWeight.Value : rmH.Data[0].avgWeight.Value) + "" : rmH.Data[0].avgWeight.Value + "";
  1601. setMsgInfo(txtHisTare, HisTareWgt, "");
  1602. setMsgInfo(txtCount, rmH.Data[0].meterNum + "", "");
  1603. }
  1604. //通过车号查询计量预报
  1605. RESTfulResult<List<PreTrackScale>> rmx = service.doQueryTenWf(new PreTrackScale { carNo = PbCache.collect.carno });
  1606. dtPreTrackScale.Clear();
  1607. DataTable dt = dtPreTrackScale.Clone();
  1608. if (rmx.Succeed && rmx.Data != null && rmx.Data.Count > 0)
  1609. {
  1610. dt = rmx.Data.ListToDataTable<PreTrackScale>();
  1611. }
  1612. ClsControlPack.CopyDataToDatatable(ref dt, ref this.dtPreTrackScale, true);
  1613. ClsControlPack.RefreshAndAutoSize(ultraGridYb);
  1614. //计量实绩
  1615. CommonPage<MeterWorkCarActual> cpc = new CommonPage<MeterWorkCarActual>();
  1616. MeterWorkCarActual mwca = new MeterWorkCarActual();
  1617. mwca.carNo = PbCache.collect.carno;
  1618. cpc.param = mwca;
  1619. cpc.pageNum = 1;
  1620. cpc.pageSize = 10;
  1621. RESTfulResult<DataTable> rm = mwas.doQueryWf(cpc);
  1622. if (rm.Succeed)
  1623. {
  1624. //WriteLog("二次计量数据查询失败!" + rm.ResultMessage);
  1625. dataTable1.Clear();
  1626. DataTable dts = dataTable1.Clone();
  1627. if (rm.Data != null && rm.Data.Rows.Count > 0)
  1628. {
  1629. dts = rm.Data;
  1630. }
  1631. ClsControlPack.CopyDataToDatatable(ref dts, ref this.dataTable1, true);
  1632. ClsControlPack.RefreshAndAutoSize(ultraGridSj);
  1633. }
  1634. //期限皮重
  1635. RESTfulResult<List<MeterBaseTermTareData>> rmTerm = termTareDate.doQueryWf(new MeterBaseTermTareData { carNo = PbCache.collect.carno, valueFlag = "0" });
  1636. dtTare.Clear();
  1637. DataTable dtTerm = dtTare.Clone();
  1638. if (rmTerm.Succeed && rmTerm.Data != null && rmTerm.Data.Count > 0)
  1639. {
  1640. dtTerm = rmTerm.Data.ListToDataTable<MeterBaseTermTareData>();
  1641. }
  1642. ClsControlPack.CopyDataToDatatable(ref dtTerm, ref this.dtTare, true);
  1643. ClsControlPack.RefreshAndAutoSize(ultraGridTare);
  1644. //校秤记录
  1645. RESTfulResult<List<MeterWorkCalibrationMain>> rmMain = mainService.doQueryWf(new MeterWorkCalibrationMain { baseSpotNo = PbCache.sportInfo.baseSpotNo });
  1646. dtCalibration.Clear();
  1647. DataTable dtMain = dtCalibration.Clone();
  1648. if (rmMain.Succeed && rmMain.Data != null && rmMain.Data.Count > 0)
  1649. {
  1650. dtMain = rmMain.Data.ListToDataTable<MeterWorkCalibrationMain>();
  1651. }
  1652. ClsControlPack.CopyDataToDatatable(ref dtMain, ref this.dtCalibration, true);
  1653. ClsControlPack.RefreshAndAutoSize(ultraGridJl);
  1654. //剩余纸张数 meter_work_monitor
  1655. RESTfulResult<List<MeterWorkMonitor>> rmMonitor = monitorService.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  1656. if (rmMonitor.Succeed)
  1657. {
  1658. if (rmMonitor.Data != null && rmMonitor.Data.Count > 0)
  1659. {
  1660. //txtPage.Text = rmMonitor.Data[0].printNum == null ? "0" : (rmMonitor.Data[0].printNum.Value + "");
  1661. setMsgInfo(txtPage, rmMonitor.Data[0].printNum == null ? "0" : (rmMonitor.Data[0].printNum.Value + ""), "");
  1662. }
  1663. }
  1664. //是否存在一次计量数据,存在则毛皮净写入界面
  1665. RESTfulResult<List<MeterWorkCarActualFirst>> RESTfulResult = workCarActualFirstService.doQueryWf(new MeterWorkCarActualFirst { carNo = PbCache.collect.carno, valueFlag = "1" });
  1666. if (RESTfulResult.Succeed)
  1667. {
  1668. if (RESTfulResult.Data != null && RESTfulResult.Data.Count > 0)
  1669. {
  1670. #region ===========eason add 2021-11-27先判断下当前车号对应的秤点是不是联达磅=================
  1671. bool flag = false;
  1672. bool fLianDa = false;
  1673. int iDb = 0;
  1674. //是联达磅,且存在一次计量数据,若一次计量数据只有1条,看预报编号是不是有_,若没有则认为是普通过磅,若有则看最后结净的数据是不是跟这个预报相同只是没有_,若有最后结净数据则一次写入
  1675. if (PbCache.sportInfo?.baseSpotNo == lianDaPointNo)
  1676. {
  1677. if (RESTfulResult.Data.Count == 1)
  1678. {
  1679. if (RESTfulResult.Data[0].predictionNo.Contains("_"))
  1680. {
  1681. //看最后结净的数据是不是跟这个预报相同只是没有_,若有最后结净数据则一次写入
  1682. if (rm.Data != null && rm.Data.Rows.Count > 0)
  1683. {
  1684. if (RESTfulResult.Data[0].predictionNo.Replace("_", "") == rm.Data.Rows[0]["predictionNo"].ToString().Trim())
  1685. {
  1686. flag = true;
  1687. fLianDa = true;
  1688. }
  1689. }
  1690. }
  1691. else
  1692. {
  1693. flag = true;
  1694. }
  1695. }
  1696. }
  1697. else
  1698. {
  1699. //非联达的磅
  1700. if (RESTfulResult.Data.Count == 1)
  1701. {
  1702. if (!RESTfulResult.Data[0].predictionNo.Contains("_")) //未结净的不是联达的数据,则为true
  1703. {
  1704. flag = true;
  1705. }
  1706. }
  1707. else if (RESTfulResult.Data.Count == 2)
  1708. {
  1709. //有两条一条是联达,1条是非联达的,则使用非联达的数据
  1710. if (RESTfulResult.Data[0].predictionNo.Replace("_", "") == RESTfulResult.Data[1].predictionNo.Replace("_", "")
  1711. && RESTfulResult.Data[0].predictionNo != RESTfulResult.Data[1].predictionNo)
  1712. {
  1713. flag = true;
  1714. if (RESTfulResult.Data[0].predictionNo.Contains("_")) iDb = 1;
  1715. }
  1716. }
  1717. }
  1718. if (flag)
  1719. {
  1720. #endregion ====================================================================================
  1721. first = RESTfulResult.Data[iDb];
  1722. first.predictionNo = first.predictionNo.Replace("_", "");
  1723. PbCache.strCode = first.predictionNo;
  1724. //setMsgInfo(lbWgt, (first.addWeight == null ? 0 : first.addWeight.Value) + "", ""); //一次附加重量作为附加重量显示
  1725. if (first.meterTypeNo == "001006003")
  1726. {
  1727. strType = "0"; //如果是内倒计量
  1728. setMsgInfo(txtPREDICTION_NO, first.predictionNo, "");
  1729. setMsgInfo(txtMATTER_NAME, first.matterName, "");
  1730. setMsgInfo(txtMETER_TYPE, first.meterTypeName, "");
  1731. setMsgInfo(txtFORWARDING_UNIT_NAME, first.forwardingUnitName, "");
  1732. setMsgInfo(txtRECEIVING_UINT_NAME, first.receivingUintName, "");
  1733. if (ndRemind)
  1734. {
  1735. ndRemind = false;
  1736. txtMsgInfo.Text = "内倒计量:当前为皮重状态,若计量皮重,直接点击保存;若计量毛重请点击【业务编号】输入业务号,若业务号已存在,请在业务号文本框中按回车键!";
  1737. }
  1738. }
  1739. else
  1740. {
  1741. setAddWgt(first.predictionNo); //非内倒才有这款逻辑
  1742. strType = "1"; //非内倒计量,此时计量预报中存在编号与一次一致的情况,则认为是非一车联运,或者一车联运互锁的方式或者最后一车一车联运预报,此时可将一次的信息填充到界面
  1743. //如果是联达的物料,那么此时预报实际上是没有了,我们需要从1次计量里面的数据提取出信息出来然后重新查一次预报信息
  1744. if (fLianDa)
  1745. {
  1746. rmx = service.doQueryWf(new PreTrackScale { predictionNo = first.predictionNo });
  1747. }
  1748. if (rmx.Succeed && rmx.Data != null && rmx.Data.Count > 0)
  1749. {
  1750. PreTrackScale ptsQ = rmx.Data.Where(s => s.predictionNo == RESTfulResult.Data[0].predictionNo).FirstOrDefault();
  1751. if (ptsQ != null && ptsQ.predictionNo != "")
  1752. {
  1753. setMsgInfo(txtPREDICTION_NO, ptsQ.predictionNo, "");
  1754. setMsgInfo(txtBATCH_NO, ptsQ.batchNo, "");
  1755. setMsgInfo(txtMATTER_NAME, ptsQ.matterName, "");
  1756. setMsgInfo(txtMETER_TYPE, ptsQ.meterTypeName, "");
  1757. setMsgInfo(txtCount, ptsQ.shipmentNum == null ? "" : ptsQ.shipmentNum.Value + "", "");
  1758. setMsgInfo(txtFORWARDING_UNIT_NAME, ptsQ.forwardingUnitName, "");
  1759. setMsgInfo(txtRECEIVING_UINT_NAME, ptsQ.receivingUintName, "");
  1760. setMsgInfo(txtCARRIER_UNIT_NAME, ptsQ.carrierUnitName, "");
  1761. setMsgInfo(txtLOAD_POINT_NAME, ptsQ.loadPointName, "");
  1762. setMsgInfo(txtSHIPMENT_GROSS_WEIGHT, ptsQ.shipmentGrossWeight == null ? "" : ptsQ.shipmentGrossWeight.Value + "", "");
  1763. setMsgInfo(txtSHIPMENT_NET_WEIGHT, ptsQ.shipmentNetWeight == null ? "" : ptsQ.shipmentNetWeight.Value + "", "");
  1764. preTack = ptsQ;
  1765. }
  1766. }
  1767. }
  1768. }
  1769. }
  1770. }
  1771. seValidWhp();
  1772. }
  1773. }
  1774. }
  1775. /// <summary>
  1776. /// 验证当前物料是否是危化品
  1777. /// </summary>
  1778. private void seValidWhp()
  1779. {
  1780. if (txtCarNo.Text.Trim() != "" && cbCarNo.Text.Trim() != "" && preTack != null && preTack.matterNo != "")
  1781. {
  1782. string strCarNo = cbCarNo.Text.Trim() + txtCarNo.Text.Trim();
  1783. if (PbCache.limit != null && PbCache.limit.Count > 0)
  1784. {
  1785. List<MeterBaseLimitChemical> mblc = PbCache.limit.Where(s => s.matterNo == preTack.matterNo).ToList();
  1786. //该物料是危化品
  1787. if (mblc.Count > 0)
  1788. {
  1789. chkChemical.Checked = true;
  1790. }
  1791. }
  1792. }
  1793. }
  1794. /// <summary>
  1795. /// 预报数据双击
  1796. /// </summary>
  1797. /// <param name="sender"></param>
  1798. /// <param name="e"></param>
  1799. private void ultraGridYb_DoubleClick(object sender, EventArgs e)
  1800. {
  1801. UltraGridRow ugr = ultraGridYb.ActiveRow;
  1802. if (ugr != null)
  1803. {
  1804. DataRow[] dr = dtPreTrackScale.Select("predictionNo='" + ugr.Cells["predictionNo"].Text.Trim() + "'"); //Select(" CAR_NO = '" + strCarNO + "'")
  1805. if (dr != null && dr.Length > 0)
  1806. {
  1807. preTack = dr[0].CreateItem<PreTrackScale>();
  1808. setPreTrackInfo(preTack);
  1809. seValidWhp();
  1810. strType = "1";
  1811. lbWgt.Text = string.IsNullOrEmpty(dr[0]["addWeightSum"].ToString().Trim()) ? "" : dr[0]["addWeightSum"].ToString().Trim();
  1812. setAddWgt(preTack.predictionNo);
  1813. PbCache.strCode = preTack.predictionNo;
  1814. btnSave.Visible = validPredictionNo(ugr.Cells["predictionNo"].Text.Trim());
  1815. }
  1816. }
  1817. }
  1818. //
  1819. private void setAddWgt(string predictionNo)
  1820. {
  1821. try
  1822. {
  1823. setMsgInfo(lbUTENSIL_UTENSIL_NAME, "", "");
  1824. ls = new List<string>();
  1825. setListBoxInfo(lb1, "", "1");
  1826. setListBoxInfo(lb2, "", "1");
  1827. dAddWgt = 0;
  1828. RESTfulResult<List<PerAddWeight>> rm = perAddWeight.doQueryWf(new PerAddWeight { predictionNo = predictionNo });
  1829. if (rm.Succeed)
  1830. {
  1831. if (rm.Data != null && rm.Data.Count > 0)
  1832. {
  1833. int i = 0;
  1834. foreach (PerAddWeight per in rm.Data)
  1835. {
  1836. setMsgInfo(lbUTENSIL_UTENSIL_NAME, per.utensilUtensilName, "");
  1837. ls.Add(per.addWeightNo);
  1838. i++;
  1839. if (i < 8)
  1840. {
  1841. setListBoxInfo(lb1, per.utensilNo, "2");
  1842. }
  1843. else
  1844. {
  1845. setListBoxInfo(lb2, per.utensilNo, "2");
  1846. }
  1847. dAddWgt += string.IsNullOrEmpty(per.utensilWeight) ? 0 : Convert.ToDouble(per.utensilWeight);
  1848. }
  1849. }
  1850. }
  1851. //PbCache.addWgt = dAddWgt;
  1852. setMsgInfo(lbWgt, dAddWgt + "", "");
  1853. }
  1854. catch (Exception ex)
  1855. {
  1856. l.WriteLog(1, ex.Message.Trim());
  1857. }
  1858. }
  1859. public void setListBoxInfo(ListBox control, string ResultMessage, string sType)
  1860. {
  1861. setListBoxMsg(control, ResultMessage, sType);
  1862. }
  1863. private void setListBoxMsg(ListBox control, string ResultMessage, string sType)
  1864. {
  1865. if (control.InvokeRequired)
  1866. {
  1867. Action<ListBox, string, string> action = new Action<ListBox, string, string>(setListBoxInfo);
  1868. Invoke(action, new object[] { control, ResultMessage, sType });
  1869. }
  1870. else
  1871. {
  1872. switch (sType)
  1873. {
  1874. case "1":
  1875. control.Items.Clear();
  1876. ; break;
  1877. case "2":
  1878. control.Items.Add(ResultMessage);
  1879. ; break;
  1880. case "3":
  1881. control.Items.Remove(ResultMessage);
  1882. break;
  1883. default: break;
  1884. }
  1885. }
  1886. }
  1887. private bool validPredictionNo(string predictionNo)
  1888. {
  1889. bool flag = true;
  1890. txtMsgInfo.Text = "";
  1891. #region 如果存在一次信息,且当前预报编号与一次的不一样
  1892. if (first != null && !string.IsNullOrEmpty(first.predictionNo) && !string.IsNullOrEmpty(predictionNo))
  1893. {
  1894. if (PbCache.strCode != first.predictionNo)
  1895. {
  1896. if (first.predictionType != "2")//一次计量的计量预报如果不是联运预报,那么当前扫的码必须与前面那个一致
  1897. {
  1898. txtMsgInfo.Text = "当前计量预报【" + predictionNo + "】与上次未结净数据预报【" + first.predictionNo + "】不一致,请重新扫码或语音求助!";
  1899. flag = false;
  1900. }
  1901. else //如果一次计量是联运预报,且预报的使用状态为4(正使用)则认为走了互锁式计量,因为非互锁的情况计量一次预报状态会变为2
  1902. {
  1903. RESTfulResult<List<PreTrackScale>> rm = service.doQueryWf(new PreTrackScale { predictionNo = first.predictionNo, valueFlag = "4" });
  1904. if (rm.Succeed)
  1905. {
  1906. if (rm.Data != null && rm.Data.Count > 0)
  1907. {
  1908. txtMsgInfo.Text = "当前计量预报【" + predictionNo + "】与上次未结净数据预报【" + first.predictionNo + "】不一致,请重新扫码或语音求助!";
  1909. flag = false;
  1910. }
  1911. else //非互锁的情况计量,此时编号应该存在在一次计量中的编号中
  1912. {
  1913. string sCode = first.predictionCombination.Split(',').ToList().Where(s => s.CompareTo(predictionNo) == 0).FirstOrDefault();
  1914. if (string.IsNullOrEmpty(sCode))
  1915. {
  1916. txtMsgInfo.Text = "当前计量预报【" + predictionNo + "】不在上次计量联运预报【" + first.predictionCombination + "】中,请重新扫码或语音求助!";
  1917. flag = false;
  1918. }
  1919. }
  1920. }
  1921. else
  1922. {
  1923. l.WriteLog(0, "查询预报编号异常");
  1924. txtMsgInfo.Text = "获取一次计量时的预报失败,请稍后再试,预报编号【" + first.predictionNo + "】!";
  1925. flag = false;
  1926. }
  1927. }
  1928. }
  1929. }
  1930. #endregion
  1931. return flag;
  1932. }
  1933. /// <summary>
  1934. /// 计量实绩数据双击
  1935. /// </summary>
  1936. /// <param name="sender"></param>
  1937. /// <param name="e"></param>
  1938. private void ultraGridSj_DoubleClick(object sender, EventArgs e)
  1939. {
  1940. UltraGridRow ugr = ultraGridSj.ActiveRow;
  1941. if (ugr != null)
  1942. {
  1943. strType = "0";
  1944. preTack = new PreTrackScale
  1945. {
  1946. predictionNo = ugr.Cells["predictionNo"].Text.Trim(),
  1947. forwardingUnitNo = ugr.Cells["forwardingUnitNo"].Text.Trim(),
  1948. forwardingUnitName = ugr.Cells["forwardingUnitName"].Text.Trim(),
  1949. matterNo = ugr.Cells["matterNo"].Text.Trim(),
  1950. matterName = ugr.Cells["matterName"].Text.Trim(),
  1951. receivingUintNo = ugr.Cells["receivingUintNo"].Text.Trim(),
  1952. receivingUintName = ugr.Cells["receivingUintName"].Text.Trim()
  1953. };
  1954. setPreTrackInfo(preTack);
  1955. seValidWhp();
  1956. }
  1957. }
  1958. private string strIsRemote = "0";
  1959. private void timer2_Tick(object sender, EventArgs e)
  1960. {
  1961. if (!bCollectionStart)
  1962. {
  1963. //RESTfulResult<List<MeterWorkMonitor>> rm = monitorService.doQueryOneWf(new MeterWorkMonitor { userNo = userId });
  1964. RESTfulResult<List<MeterWorkMonitor>> rm = monitorService.doQueryOneWf(new MeterWorkMonitor { userNo = userId });
  1965. if (rm.Succeed)
  1966. {
  1967. if (rm.Data != null && rm.Data.Count > 0)
  1968. {
  1969. strIsRemote = rm.Data[0].isRemote;
  1970. #region 将按钮设置为接管的状态
  1971. btnStart.BackColor = Color.Red;
  1972. btnStart.Text = "取消接管";
  1973. timer2.Stop();
  1974. flagStart = false;
  1975. #endregion
  1976. lbPointName.Text = "";
  1977. lbMeterMan.Text = "";
  1978. txtPREDICTION_NO.ReadOnly = false;
  1979. cbCarNo.Enabled = true;
  1980. txtCarNo.ReadOnly = false;
  1981. DataTable dt = dtJGPointInfo.Clone();
  1982. DataRow dr = dt.NewRow();
  1983. PbCache.sportInfo = PbCache.sportInfos.Where(s => s.baseSpotNo == rm.Data[0].pointNo).FirstOrDefault();
  1984. dr["baseSpotNo"] = rm.Data[0].pointNo;
  1985. dr["baseSpotName"] = rm.Data[0].pointName;
  1986. dt.Rows.Add(dr);
  1987. ClsControlPack.CopyDataToDatatable(ref dt, ref this.dtJGPointInfo, true);
  1988. ClsControlPack.RefreshAndAutoSize(ultraGridPW);
  1989. PbCache.collect_no = rm.Data[0].collectionCode;
  1990. bd.getSpot();
  1991. //=====如果此时的远程接管状态是2,则说明是监控端点击的远程接管,此时将自动派位改为挂起状态===========
  1992. /*
  1993. if (rm.Data[0].isTakeOver == "2")
  1994. {
  1995. btnStart.BackColor = Color.Red;
  1996. btnStart.Text = "挂起";
  1997. timer2.Enabled = false;
  1998. flagStart = false;
  1999. }
  2000. //*/
  2001. //===================================================================================================
  2002. collection.Start(rm.Data[0].pointNo, rm.Data[0].pointName);
  2003. GetIPVideo(PbCache.videoInfo);
  2004. setPicBoxSet();
  2005. bCollectionStart = true;
  2006. lbPointName.Text = rm.Data[0].pointName;
  2007. lbMeterMan.Text = userName;
  2008. //放开按钮
  2009. /*
  2010. btnOpenVoice.Enabled = true;
  2011. btnCheckBalance.Enabled = true;
  2012. btnTareWgt.Enabled = true;
  2013. btnSave.Enabled = true;
  2014. //*/
  2015. }
  2016. }
  2017. }
  2018. else
  2019. {
  2020. /*
  2021. if (btnOpenVoice.Enabled)
  2022. {
  2023. //禁用按钮
  2024. btnOpenVoice.Enabled = false;
  2025. btnCheckBalance.Enabled = false;
  2026. btnTareWgt.Enabled = false;
  2027. btnSave.Enabled = false;
  2028. }
  2029. //*/
  2030. }
  2031. }
  2032. private List<PictureBox> ltPicBoxs = new List<PictureBox>();
  2033. private void setPicBoxSet()
  2034. {
  2035. if (PbCache.videoChild != null && PbCache.videoChild.Count > 0)
  2036. {
  2037. int i = 0;
  2038. foreach (MeterBaseVideoChild child in PbCache.videoChild.OrderByDescending(s => s.p_ip))
  2039. {
  2040. i++;
  2041. if (i < 4 || i == 6) //只开启4个视频 1-3通道 左右上 6通道室内
  2042. {
  2043. PictureBox pb = new PictureBox();
  2044. pb.Name = "pb" + i;
  2045. pb.Dock = DockStyle.Top;
  2046. pb.Height = 245;
  2047. pb.DoubleClick += new EventHandler(PictureBoxDoubleClick);
  2048. pb.BorderStyle = BorderStyle.FixedSingle;
  2049. panel1.Controls.Add(pb);
  2050. cameraShotMain.RealPlay(pb, i);
  2051. }
  2052. }
  2053. }
  2054. }
  2055. private void frmMeterMain2_FormClosing(object sender, FormClosingEventArgs e)
  2056. {
  2057. try
  2058. {
  2059. timer1.Stop();
  2060. timer2.Stop();
  2061. }
  2062. catch { }
  2063. try
  2064. {
  2065. strIsRemote = "0";
  2066. Clean();
  2067. }
  2068. catch { }
  2069. //imageControl.Stop();
  2070. }
  2071. private void lbWgt_ValueChanged(object sender, EventArgs e)
  2072. {
  2073. try
  2074. {
  2075. dAddWgt = Convert.ToDouble(lbWgt.Value);
  2076. }
  2077. catch
  2078. {
  2079. dAddWgt = 0;
  2080. }
  2081. }
  2082. private void txtCarNo_KeyDown(object sender, KeyEventArgs e)
  2083. {
  2084. if (e.KeyValue == 13)
  2085. {
  2086. if (PbCache.collect != null && PbCache.collect.weight > 0)
  2087. {
  2088. strTxtCarNo = txtCarNo.Text.Trim();
  2089. QueryCarNo(); //txtCarNo_KeyDown
  2090. flagCarNo = true;
  2091. }
  2092. }
  2093. }
  2094. /// <summary>
  2095. /// 业务编号 点击事件
  2096. /// </summary>
  2097. /// <param name="sender"></param>
  2098. /// <param name="e"></param>
  2099. private void btnInnerQuery_Click(object sender, EventArgs e)
  2100. {
  2101. frmMatCompanyInfo frmM = new frmMatCompanyInfo();
  2102. if (frmM.ShowDialog() == DialogResult.OK)
  2103. {
  2104. txtPREDICTION_NO.Text = frmM.PreNo;
  2105. QueryInnerInfo(); //业务编号点击事件
  2106. }
  2107. }
  2108. /// <summary>
  2109. /// 测试按钮
  2110. /// </summary>
  2111. /// <param name="sender"></param>
  2112. /// <param name="e"></param>
  2113. private void btnTest_Click(object sender, EventArgs e)
  2114. {
  2115. testFlage = true;
  2116. }
  2117. private int iPic = 0;
  2118. /// <summary>
  2119. /// 不显示大图
  2120. /// </summary>
  2121. private void pictureShow_DoubleClick(object sender, EventArgs e)
  2122. {
  2123. plImgShow.Visible = false;
  2124. cameraShotMain.StopRealPlay(iPic);
  2125. iPic = 0;
  2126. }
  2127. /// <summary>
  2128. /// 放大图像
  2129. /// </summary>
  2130. private void PictureBoxDoubleClick(object sender, EventArgs e)
  2131. {
  2132. if (iPic != 0)
  2133. {
  2134. cameraShotMain.StopRealPlay(iPic);
  2135. }
  2136. PictureBox picture = (PictureBox)sender;
  2137. iPic = Convert.ToInt32(picture.Name.Substring(picture.Name.Length - 1, 1));
  2138. plImgShow.Visible = true;
  2139. cameraShotMain.RealPlay(pictureShow, iPic);
  2140. }
  2141. public string GetIP()
  2142. {
  2143. try
  2144. {
  2145. IPHostEntry ipHost = Dns.Resolve(Dns.GetHostName());
  2146. IPAddress ipAddr = ipHost.AddressList[0];
  2147. return ipAddr.ToString();
  2148. }
  2149. catch (Exception ex)
  2150. {
  2151. Random rd = new Random();
  2152. l.WriteLog(13, "GetIP方法异常:" + ex.Message);
  2153. return rd.Next(99999, 999999) + "";
  2154. }
  2155. }
  2156. }
  2157. }