frmMain.cs 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. using CarMeterSystem.OptionCls;
  2. using com.hnshituo.core.webapp.vo;
  3. using Common;
  4. using iCore.Rtdb.RtdbTable;
  5. using MeterConditionLibrary;
  6. using MeterModelLibrary;
  7. using MeterModuleLibrary.uc;
  8. using MeterPlugInLibrary;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Data;
  12. using System.Diagnostics;
  13. using System.Drawing;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. namespace CarMeterSystem
  17. {
  18. public partial class frmMain : Form
  19. {
  20. public frmMain()
  21. {
  22. InitializeComponent();
  23. }
  24. private Log l = Log.GetInstance();
  25. private Print printClass = new Print();//打印
  26. //内存表
  27. private MemoryTableDataSocket MemoClass = new MemoryTableDataSocket("");
  28. //实时表数据采集
  29. private DataCollectionControl collection = new DataCollectionControl();
  30. //图片控制器含图片压缩及上传curl
  31. private ImageCurlControl imageCurlControl = new ImageCurlControl();
  32. //与监控界面对接的表
  33. private MeterWorkMonitorService meterWorkMonitor = new MeterWorkMonitorService();
  34. //零点报警表
  35. private meterworkzeroalarmservice zeroAlarmService = new meterworkzeroalarmservice();
  36. //车号修正
  37. private CarNoModfiy modfiy = new CarNoModfiy();
  38. /// <summary>
  39. /// 这个是保存前一次采集中的车号信息
  40. /// </summary>
  41. private string preCarNo = "";
  42. //验证对射
  43. private validParkStatus valid = new validParkStatus();
  44. //语音播报
  45. private VoicePlay vicPlayClass = new VoicePlay();
  46. //扫码枪
  47. private SweepCode sweepCodeClass = new SweepCode();
  48. private LED_Control led_controler = null;
  49. //监控表操作
  50. private MeterMonitorWeightService monitorWeightService = new MeterMonitorWeightService();
  51. //历史皮操作
  52. private MeterBaseHisTareDataService hisTareDataService = new MeterBaseHisTareDataService();
  53. /// <summary>
  54. /// 欢迎界面
  55. /// </summary>
  56. private frmWelcome_Jisco frmWelcome = new frmWelcome_Jisco();//欢迎
  57. /// <summary>
  58. /// 基础数据载入
  59. /// </summary>
  60. private BaseDbCls bd = new BaseDbCls();
  61. //扫码修正车号标识
  62. private bool codeFlag = false;
  63. private List<ucBusinessType> lu = new List<ucBusinessType>();
  64. private bool isVoiceDownCar = false;//车上人员请下车播放一次
  65. private bool isShowFrmWelcome = true; //是否显示欢迎界面
  66. private bool isOpened = false;//是否已经打开了扫码计量界面
  67. private void frmMain_Load(object sender, EventArgs e)
  68. {
  69. //*
  70. try
  71. {
  72. this.Hide();
  73. LoginCls lg = new LoginCls();
  74. timer1.Start();
  75. //2021年6月21日 杨秀东添加
  76. if (isShowFrmWelcome)
  77. {
  78. frmWelcome.Show();
  79. frmWelcome.Visible = true;
  80. }
  81. if (lg.LoginIn())
  82. {
  83. //if (SystemUpdate(false))
  84. //{
  85. // return;
  86. //}
  87. if (bd.setBaseDb() && bd.getBaseDb())
  88. {
  89. if (!string.IsNullOrEmpty(PbCache.sportInfo.ledIp))
  90. {
  91. led_controler = new LED_Control(PbCache.sportInfo.ledIp);
  92. }
  93. //调用该方法时已赋值 test git 测试git推送代码123;456
  94. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  95. if (!rm.Succeed)
  96. {
  97. l.WriteLog(1, "载入监控表数据异常");
  98. return;
  99. }
  100. else if (rm.Data != null && rm.Data.Count > 0)
  101. {
  102. if (string.IsNullOrEmpty(PbCache.collect_no))
  103. {
  104. PbCache.collect_no = rm.Data[0].collectionCode;
  105. MemoClass = new MemoryTableDataSocket(PbCache.collect_no);
  106. }
  107. }
  108. else
  109. {
  110. l.WriteLog(1, "为配置监控数据");
  111. return;
  112. }
  113. //若未校秤的话,也不允许计量
  114. //载入界面业务按钮
  115. if (PbCache.businessType != null && PbCache.businessType.Count > 0)
  116. {
  117. foreach (ComBaseInfo info in PbCache.businessType)
  118. {
  119. ucBusinessType uc = new ucBusinessType();
  120. switch (info.baseCode)
  121. {
  122. case "001006003":
  123. uc.setControl(info.baseName, info.memo, info.baseCode);
  124. break;
  125. case "001006001":
  126. case "001006002":
  127. uc.setControl(info.baseName, info.memo, info.baseCode);
  128. break;
  129. default:
  130. uc.setControl(info.baseName, info.memo, info.baseCode);
  131. break;
  132. }
  133. uc.Dock = DockStyle.Top;
  134. //uc.setControl("","","",);
  135. uc.ucEvent += new EventHandler(ucEvents);
  136. lu.Add(uc);
  137. //panel7.Controls.Add(uc);
  138. }
  139. }
  140. //开启基础进程
  141. l.WriteLog(0, "系统登录成功");
  142. collection.EventDataCollectionArgs += new EventDataCollection(EventData);//数据采集及扫码信息
  143. collection.Start(PbCache.sportInfo.baseSpotNo, PbCache.sportInfo.baseSpotName);
  144. imageCurlControl.Start(); //图片上传线程
  145. sweepCodeClass.StartThreadSweep(); //扫码线程
  146. }
  147. else
  148. {
  149. l.WriteLog(0, "系统登录失败");
  150. }
  151. }
  152. else
  153. {
  154. l.WriteLog(0, "按IP地址找不到计量点信息,系统登录失败");
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. l.WriteLog(0, "系统加载失败:" + ex.Message);
  160. }
  161. //*/
  162. }
  163. /// <summary>
  164. /// 直接打开扫码计量界面
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void timer1_Tick(object sender, EventArgs e)
  169. {
  170. if (!isOpened && PbCache.collect?.weight > 500)
  171. {
  172. isOpened = true;
  173. PbCache.bussinessTypeName = "";
  174. PbCache.bussinessTypeCode = "";
  175. frmOneYardToEnd fcc = new frmOneYardToEnd();
  176. fcc.ShowDialog();
  177. }
  178. }
  179. #region
  180. //*
  181. /// <summary>
  182. /// 委托的方式调用控件的点击事件
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. public void ucEvents(object sender, EventArgs e)
  187. {
  188. Control control = (Control)sender;
  189. ucBusinessType um = control.Parent.Parent as ucBusinessType;
  190. try
  191. {
  192. switch (control.Name)
  193. {
  194. case "btnContext":
  195. case "btnPurchase":
  196. {
  197. PbCache.bussinessTypeName = um._bussiness == null ? "" : um._bussiness;
  198. PbCache.bussinessTypeCode = um._code;
  199. switch (um._code)
  200. {
  201. case "001006003":
  202. frmInternalTransport frm = new frmInternalTransport();
  203. frm.ShowDialog();
  204. break;
  205. /*
  206. case "001006001":
  207. case "001006002":
  208. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  209. frmCar.ShowDialog();
  210. break;
  211. //*/
  212. default:
  213. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  214. frmCar.ShowDialog();
  215. break;
  216. }
  217. };
  218. break;
  219. default: break;
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. //MessageBox.Show("操作异常:" + ex.Message);
  225. }
  226. }
  227. //*/
  228. #endregion
  229. #region
  230. private void setThisVis(bool visb)
  231. {
  232. if (this.InvokeRequired)
  233. {
  234. Action<bool> action = new Action<bool>(setThisVis);
  235. Invoke(action, new object[] { visb });
  236. }
  237. else
  238. {
  239. if (this.Visible != visb)
  240. {
  241. this.Visible = visb;
  242. }
  243. }
  244. }
  245. #endregion
  246. #region
  247. private void setWelecomeVis(bool visb)
  248. {
  249. if (!isShowFrmWelcome) return;//2021年6月21日 杨秀东添加
  250. if (frmWelcome.InvokeRequired)
  251. {
  252. Action<bool> action = new Action<bool>(setWelecomeVis);
  253. Invoke(action, new object[] { visb });
  254. }
  255. else
  256. {
  257. if (frmWelcome.Visible != visb)
  258. {
  259. frmWelcome.Visible = visb;
  260. frmWelcome.setLogin();
  261. }
  262. }
  263. //*/
  264. }
  265. #endregion
  266. private int iCount = 0, iHodeTime = 0;
  267. private bool flagCarMonit = false;//车号修正
  268. private bool bEditCar = false; //手动修正车号
  269. private bool isOpenMeter = false; //是否已打开计量界面,若已经打开则这里关于超量程及红外的语音将停止播报
  270. private string firstCode = "";//上次扫码的信息
  271. private string ledTxt = "";
  272. private bool isLedWrite = false;//是否写入一次LED
  273. private string sPreNo = ""; //记录重量曲线变化
  274. private int preWgt = 0;//前一次重量,用于重量曲线
  275. private string sCarNo = "";
  276. private int iCountPark = 0;
  277. private string editCarNo = "";
  278. /// <summary>
  279. /// 数据采集
  280. /// </summary>
  281. /// <param name="o"></param>
  282. /// <param name="e"></param>
  283. private void EventData(object o, DataCollectionArgs e)
  284. {
  285. //这里每隔0.5秒执行一次
  286. try
  287. {
  288. #region 扫码信息
  289. sweepCodeClass.StrState = e.weightStatus + ""; //重量状态信息;当StrState= 0时,获取扫码信息,StrState= 2时将扫码信息置位“”空;其他状态不处理
  290. if (string.IsNullOrEmpty(sweepCodeClass.StrCode))
  291. {
  292. codeFlag = false;
  293. if (string.IsNullOrEmpty(PbCache.strCode))
  294. {
  295. firstCode = "";
  296. PbCache.strCode = "";
  297. l.WriteLog(12, "主线程扫码值为空时清空;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode值为:" + PbCache.strCode);
  298. }
  299. }
  300. else
  301. {
  302. ////日期2021年12月22日:重复扫码,取前面12位
  303. //if (sweepCodeClass.StrCode.Length > 15)
  304. //{
  305. // // todo: 加入车号截取逻辑
  306. // sweepCodeClass.StrCode = sweepCodeClass.StrCode.Substring(0,12);
  307. //}
  308. //if (firstCode != sweepCodeClass.StrCode || string.IsNullOrEmpty(PbCache.strCode))
  309. //{
  310. // l.WriteLog(12, "主线程扫码值赋值;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode前值为:" + PbCache.strCode);
  311. // PbCache.strCode = sweepCodeClass.StrCode;
  312. // firstCode = PbCache.strCode;
  313. //}
  314. l.WriteLog(12, "测试扫码值" + PbCache.strCode);
  315. PbCache.collect.carno = sweepCodeClass.StrCode;
  316. codeFlag = true;
  317. }
  318. #endregion 扫码信息
  319. #region 秤上无车10分钟获取一次基础数据
  320. if (iCount < 1200)
  321. {
  322. iCount++;
  323. }
  324. else
  325. {
  326. try
  327. {
  328. //秤上没有车时,每隔10分钟获取一次基础数据
  329. if (e.weight < 500)
  330. {
  331. if (bd.setBaseDb())
  332. {
  333. l.WriteLog(0, "十分钟获取基础数据成功");
  334. }
  335. else
  336. {
  337. l.WriteLog(0, "十分钟获取基础数据失败");
  338. }
  339. iCount = 0;
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. l.WriteLog(0, "十分钟获取基础数据失败:" + ex.Message);
  345. iCount = 0;
  346. }
  347. }
  348. #endregion
  349. #region 每10秒写入一次当前时间
  350. if (iCount % 20 == 0)
  351. {
  352. //更新在线时间
  353. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, lastTime = DateTime.Now });
  354. if (!rms.Succeed)
  355. {
  356. l.WriteLog(0, "frmMain.EventData异常:写入时间异常");
  357. }
  358. }
  359. #endregion
  360. #region
  361. //一旦界面锁定则不采集数据
  362. if (!PbCache.isLockFrm)
  363. {
  364. PbCache.collect.pointid = PbCache.sportInfo.baseSpotNo;
  365. PbCache.collect.weight = e.weight;
  366. PbCache.collect.weightStatus = e.weightStatus;
  367. PbCache.collect.parkStatus = e.parkStatus;
  368. PbCache.collect.datetime = e.datetime;
  369. PbCache.collect.licType = e.licType;
  370. }
  371. //*/
  372. // 更新监控表
  373. doLive();
  374. //重量大于500的情况下
  375. if (e.weight > 500)
  376. {
  377. if (PbCache.dtStartTime == null)
  378. PbCache.dtStartTime = DateTime.Now;
  379. isLedWrite = true;
  380. #region 车上人员请下车
  381. try
  382. {
  383. //界面未锁定的情况下,有车号,如果重量稳定了,停车线验证通过,未超量程的情况下,则按钮可用
  384. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status && PbCache.collect.weight < PbCache.range.upperRange)
  385. {
  386. if (!isVoiceDownCar)
  387. {
  388. isVoiceDownCar = true;
  389. vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
  390. }
  391. }
  392. }
  393. catch { }
  394. #endregion
  395. setWelecomeVis(false);
  396. //每隔1秒刷一次计量实时监控表数据值
  397. if (iCount % 2 == 0)
  398. {
  399. //调用该方法时已赋值
  400. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  401. if (!rm.Succeed)
  402. {
  403. l.WriteLog(0, "frmMain.EventData异常419:" + rm.ResultMessage);
  404. }
  405. else
  406. {
  407. if (rm.Data != null && rm.Data.Count > 0)
  408. {
  409. PbCache.monitor = rm.Data[0];
  410. if (string.IsNullOrEmpty(PbCache.collect_no))
  411. {
  412. PbCache.collect_no = rm.Data[0].collectionCode;
  413. }
  414. if (ledTxt != rm.Data[0].ledWriter && rm.Data[0].ledWriter != "")
  415. {
  416. //调用LED信息写入******************************
  417. ledTxt = rm.Data[0].ledWriter;
  418. }
  419. if (string.IsNullOrEmpty(ledTxt))
  420. {
  421. ledTxt = "欢迎使用酒钢汽车衡智能计量系统!";
  422. }
  423. }
  424. }
  425. #region 2021-03-29
  426. #region 摄像头当前采集的车号与上次采集的不一样且当前未勾选不验证,且当前车号未进行手动修正的情况下
  427. if (preCarNo != e.carno && PbCache.monitor != null && PbCache.monitor.validCarno != "0" && !bEditCar)
  428. {
  429. flagCarMonit = false;
  430. }
  431. preCarNo = e.carno;
  432. #endregion
  433. if (!flagCarMonit)
  434. {
  435. sCarNo = e.carno;
  436. }
  437. //*
  438. //有车号,且重量稳定的情况下,只修正一次车号
  439. if (!string.IsNullOrEmpty(e.carno) && e.weightStatus == 0 && !flagCarMonit && PbCache.monitor != null && PbCache.monitor.carMonitor == "1" && PbCache.monitor.carMonitorLvl > 0)
  440. {
  441. flagCarMonit = true;
  442. string methods = "";
  443. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  444. {
  445. methods += "CarNoTrustCorrect" + i + ",";
  446. }
  447. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  448. sCarNo = editCarNo;
  449. //mwUpdate
  450. }
  451. //勾选了不验证车号的情况
  452. if (PbCache.monitor.validCarno == "0")
  453. {
  454. flagCarMonit = true;
  455. }
  456. #endregion
  457. #region 每隔1秒写入一次重量曲线
  458. try
  459. {
  460. if (preWgt != e.weight)
  461. {
  462. preWgt = e.weight;
  463. sPreNo = PbCache.sportInfo.baseSpotNo + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  464. monitorWeightService.doAddWf(new MeterMonitorWeight
  465. {
  466. weightNo = sPreNo,
  467. baseSpotNo = PbCache.sportInfo.baseSpotNo,
  468. baseSpotName = PbCache.sportInfo.baseSpotName,
  469. collectWeight = e.weight + "",
  470. collectStartTime = PbCache.dtStartTime.Value,
  471. collectEndTime = DateTime.Now,
  472. spotTypeNo = "001002001",
  473. spotTypeName = "汽车衡",
  474. actualFirstNo = PbCache.actualFirstNo
  475. });
  476. }
  477. else
  478. {
  479. if (!string.IsNullOrEmpty(sPreNo))
  480. {
  481. monitorWeightService.doUpdateWf(new MeterMonitorWeight
  482. {
  483. weightNo = sPreNo,
  484. collectEndTime = DateTime.Now
  485. });
  486. }
  487. }
  488. }
  489. catch { }
  490. #endregion
  491. #region 停留超时
  492. iHodeTime++;
  493. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  494. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  495. mwUpdate.editCar = editCarNo;
  496. if (PbCache.holdTime != null && PbCache.holdTime.Count > 0)
  497. {
  498. if (PbCache.holdTime[0].retentionTime != null)
  499. {
  500. if (PbCache.holdTime[0].retentionTime.Value < iHodeTime)
  501. {
  502. PbCache.isOvertimeAlarm = true; //是否超时报警
  503. mwUpdate.stopOverTime = "1"; //写入一次停留超时
  504. //mwUpdate.isHelp = "1";//派位
  505. //mwUpdate.isTakeOver = "1";
  506. iHodeTime = 99999;//不再增长避免超出
  507. }
  508. }
  509. }
  510. #endregion
  511. #region RFID识别车号信息
  512. mwUpdate.rfidCar = "";
  513. mwUpdate.photoCar = e.vdioCarNos;
  514. if (codeFlag)
  515. {
  516. mwUpdate.scanCar = PbCache.collect.carno;
  517. }
  518. //mwUpdate.photoCar = PbCache.collect.carno;
  519. if (!string.IsNullOrEmpty(e.RfidNos))
  520. {
  521. string sqls = @"SELECT RFID_ID id,CAR_NO text FROM METER_BASE_RFID_INFO where RFID_CODE = '" + e.RfidNos + "'";
  522. PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
  523. RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
  524. if (rmT.Data == null || rmT.Data.Count == 0)
  525. { }
  526. else
  527. {
  528. mwUpdate.rfidCar = rmT.Data[0].text;
  529. sCarNo = rmT.Data[0].text;
  530. }
  531. }
  532. #endregion
  533. #region 计量员修改的车号信息
  534. if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.setCar))
  535. {
  536. sCarNo = PbCache.monitor.setCar;
  537. bEditCar = true;
  538. flagCarMonit = true;
  539. codeFlag = false;
  540. sweepCodeClass.StrCode = "";
  541. }
  542. #endregion
  543. #region 重量信息
  544. if (!PbCache.isLockFrm)
  545. {
  546. mwUpdate.wgt = e.weight;
  547. }
  548. else
  549. {
  550. mwUpdate.wgt = Convert.ToInt32(PbCache.lockWgt);
  551. }
  552. #endregion
  553. #region 写入一次监控表,将重量/车号停留超时等信息写入
  554. mwUpdate.msgInfo = PbCache.ResultMessage;
  555. mwUpdate.weightStatus = PbCache.collect.weightStatus;
  556. //另外初始化一次监控数据
  557. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  558. if (!rms.Succeed)
  559. {
  560. l.WriteLog(0, "frmMain.EventData异常583:写入信息异常");
  561. }
  562. #endregion
  563. //验证对射
  564. valid.ValidMethod();
  565. if (!isOpenMeter)
  566. {
  567. //if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  568. if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  569. {
  570. //超量程
  571. vicPlayClass.GetVoicePlay("已超量程", e.carno);
  572. //return;
  573. }
  574. else if (e.weightStatus == 0)
  575. {
  576. if (!PbCache.monitorResult.valid_park_status)
  577. {
  578. iCountPark++;
  579. if (iCountPark > 9)
  580. {
  581. //重量稳定,且对射验证不合格
  582. vicPlayClass.GetVoicePlay("您的车辆未停到位", e.carno);
  583. //return;
  584. iCountPark = 0; //2021年7月27日5s播一次,然后重新在播
  585. }
  586. }
  587. else
  588. {
  589. iCountPark = 0;
  590. }
  591. }
  592. }
  593. if (!lu[0].bcEnable)
  594. {
  595. foreach (ucBusinessType uc in lu)
  596. {
  597. uc.setControlEnable(true);
  598. }
  599. }
  600. if (sweepCodeClass.StrCode == "" && !codeFlag)
  601. {
  602. PbCache.collect.carno = sCarNo;
  603. }
  604. }
  605. //写入LED信息
  606. if (PbCache.sportInfo != null && PbCache.ledInfo != PbCache.OldLedInfo)
  607. {
  608. PbCache.OldLedInfo = PbCache.ledInfo;
  609. if (PbCache.monitor != null && PbCache.monitor.ledKeep == "0")
  610. {
  611. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  612. }
  613. }
  614. }
  615. else
  616. {
  617. if (e.weight > 10 && e.weight < 500)
  618. {
  619. //重量小于500,大于10
  620. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  621. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  622. mwUpdate.wgt = e.weight;
  623. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  624. }
  625. if (e.weight > 0 && e.weight < 200)
  626. {
  627. doOperateLive();
  628. }
  629. if (e.weight == 0)
  630. {
  631. PbCache.isZeroAlarm = false;
  632. }
  633. isOpened = false; //下次上秤直接打开主界面
  634. editCarNo = "";
  635. firstCode = ""; //历史的扫码枪的值
  636. preCarNo = "";
  637. sCarNo = "";
  638. sPreNo = "";
  639. preWgt = 0;
  640. PbCache.isOvertimeAlarm = false; //是否超时报警
  641. PbCache.strCode = "";
  642. PbCache.ResultMessage = "";
  643. bEditCar = false;
  644. isVoiceDownCar = false;
  645. flagCarMonit = false;
  646. iHodeTime = 0;
  647. isOpenMeter = false;
  648. PbCache.isLockFrm = false;
  649. PbCache.dtStartTime = null;
  650. PbCache.voiceOver = true;
  651. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
  652. {
  653. PbCache.collect.carno = "";
  654. }
  655. setWelecomeVis(true);
  656. if (lu[0].bcEnable)
  657. {
  658. foreach (ucBusinessType uc in lu)
  659. {
  660. uc.setControlEnable(false);
  661. }
  662. }
  663. //LED写入
  664. if (isLedWrite)
  665. {
  666. if (PbCache.monitor == null || string.IsNullOrEmpty(PbCache.monitor.ledWriter))
  667. {
  668. PbCache.ledInfo = "欢迎使用九钢汽车衡智能计量系统";
  669. }
  670. else
  671. {
  672. PbCache.ledInfo = PbCache.monitor == null ? "" : PbCache.monitor.ledWriter;
  673. }
  674. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  675. isLedWrite = false;
  676. //*
  677. //另外初始化一次监控数据
  678. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor
  679. {
  680. pointNo = PbCache.sportInfo.baseSpotNo,
  681. validWgt = "1",
  682. validCarno = "1",
  683. validTareTime = "1",
  684. validMatTime = "1",
  685. validTimeInterval = "1",
  686. validParkStatus = "1",
  687. validExceedWgt = "1",
  688. validPredictionDiff = "1",
  689. validLianda = "1",
  690. validMatClick = "1",
  691. setCar = "",
  692. rfidCar = "",
  693. photoCar = "",
  694. scanCar = "",
  695. editCar = "",
  696. carErr = "0",
  697. ferroalloyResult = "0",
  698. wgtErr = "0",
  699. stopOverTime = "0",
  700. msgInfo = "",
  701. ledWriter = "",
  702. isOverWgt = "",
  703. isHelp = "0",
  704. wgt = 0
  705. });
  706. if (!rms.Succeed)
  707. {
  708. l.WriteLog(0, "frmMain.EventData异常754:写入信息异常");
  709. isLedWrite = true;
  710. }
  711. //*/
  712. }
  713. }
  714. #endregion
  715. }
  716. catch (Exception ex)
  717. {
  718. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  719. }
  720. }
  721. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  722. /// <summary>
  723. /// 操作Live表的数据:零点报警
  724. /// </summary>
  725. private void doOperateLive () {
  726. if (PbCache.collect_no==null)
  727. {
  728. return;
  729. }
  730. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  731. if (ll != null)
  732. {
  733. foreach (LiveData lv in ll)
  734. {
  735. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  736. {
  737. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  738. break;
  739. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  740. break;
  741. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  742. break;
  743. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  744. if (((lv.Value ?? "0") + "").Equals("1"))
  745. {
  746. doInsertZeroAlarm();
  747. PbCache.isZeroAlarm = true;
  748. }
  749. else {
  750. PbCache.isZeroAlarm = false;
  751. }
  752. break;
  753. }
  754. }
  755. }
  756. }
  757. /// <summary>
  758. /// 操作Live表的数据:零点报警
  759. /// </summary>
  760. private void doLive()
  761. {
  762. if (PbCache.collect_no == null)
  763. {
  764. return;
  765. }
  766. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  767. MeterWorkMonitor mwm = new MeterWorkMonitor();
  768. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  769. mwm.redGreenLightState = "0";
  770. if (ll != null)
  771. {
  772. foreach (LiveData lv in ll)
  773. {
  774. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  775. {
  776. case "PowerStatus":
  777. mwm.powerState = lv.Value.ToString();
  778. break;
  779. case "PlcWatchDog":
  780. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  781. {
  782. mwm.plcState = 0.ToString();
  783. }
  784. break;
  785. case "InfraredWest":
  786. if (lv.Value.ToString() == "2")
  787. {
  788. mwm.leftInfraredRayState = "0";
  789. }
  790. else
  791. {
  792. mwm.leftInfraredRayState = lv.Value.ToString();
  793. }
  794. break;
  795. case "InfraredEast":
  796. if (lv.Value.ToString() == "2")
  797. {
  798. mwm.rightInfraredRayState = "0";
  799. }
  800. else
  801. {
  802. mwm.rightInfraredRayState = lv.Value.ToString();
  803. }
  804. break;
  805. case "AmplifierState":
  806. mwm.amplifierState = lv.Value.ToString();
  807. break;
  808. case "LampState":
  809. mwm.lampState = lv.Value.ToString();
  810. break;
  811. case "InfraredLeft":
  812. if (lv.Value.ToString() == "2")
  813. {
  814. mwm.frontInfraredRayState = "0";
  815. }
  816. else
  817. {
  818. mwm.frontInfraredRayState = lv.Value.ToString();
  819. }
  820. break;
  821. case "InfraredRight":
  822. if (lv.Value.ToString() == "2")
  823. {
  824. mwm.rearInfraredRayState = "0";
  825. }
  826. else
  827. {
  828. mwm.rearInfraredRayState = lv.Value.ToString();
  829. }
  830. break;
  831. case "RfidState":
  832. mwm.rfidState = lv.Value.ToString();
  833. break;
  834. }
  835. }
  836. }
  837. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  838. }
  839. /// <summary>
  840. /// 新增零点报警的数据
  841. /// </summary>
  842. private void doInsertZeroAlarm()
  843. {
  844. if (!PbCache.isZeroAlarm)
  845. {
  846. PbCache.isZeroAlarm = true;
  847. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  848. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  849. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  850. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  851. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  852. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  853. workZeroAlarm.scalePointNo = PbCache.collect_no;
  854. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  855. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  856. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  857. if (rms.Succeed)
  858. {
  859. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName +":"+ workZeroAlarm.zeroWeight);
  860. }
  861. else
  862. {
  863. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  864. }
  865. }
  866. }
  867. /// <summary>
  868. /// 关闭程序
  869. /// </summary>
  870. /// <param name="sender"></param>
  871. /// <param name="e"></param>
  872. private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
  873. {
  874. collection.Stop();
  875. imageCurlControl.Stop();
  876. sweepCodeClass.CloseThread();
  877. timer1.Stop();
  878. timer1.Dispose();
  879. }
  880. private bool SystemUpdate(bool isMessage)
  881. {
  882. ReleaseList releaseList = new ReleaseList(Application.StartupPath + @"\" + GlobalVariable.Instance.ReleaseFileName);
  883. DownloadTools dt = new DownloadTools();
  884. try
  885. {
  886. bool isDownload = dt.IsDownloadFile(GlobalVariable.Instance.LocalPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ReleaseFileName);
  887. if (!isDownload)
  888. {
  889. if (isMessage) MessageBox.Show("无法连接到远程主机!", Application.ProductName);
  890. return false;
  891. }
  892. }
  893. catch (Exception e)
  894. {
  895. MessageBox.Show(e.Message);
  896. }
  897. bool flag = this.CheckUpdate(releaseList);
  898. if (flag)
  899. {
  900. MessageBox.Show("有新版本,现在更新");
  901. string t = dt.DownloadFile(Application.StartupPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ApplicationUpdater);
  902. this.Close();
  903. Application.Exit();
  904. GC.Collect();
  905. Process.Start(Application.StartupPath + @"\" + GlobalVariable.Instance.ApplicationUpdater);
  906. return true;
  907. }
  908. else
  909. {
  910. if (isMessage) MessageBox.Show("你的系统已经是最新版本,不需要更新!", Application.ProductName);
  911. return false;
  912. }
  913. }
  914. private bool CheckUpdate(ReleaseList localRelease)
  915. {
  916. try
  917. {
  918. string fileNameAll = Application.StartupPath + "\\" + GlobalVariable.Instance.LocalPath + "\\" + GlobalVariable.Instance.ReleaseFileName;
  919. ReleaseList remoteRelease = new ReleaseList(fileNameAll);
  920. return (((localRelease != null) && (remoteRelease != null)) && localRelease.ReleaseDate.CompareTo(remoteRelease.ReleaseDate) < 0);
  921. }
  922. catch (Exception exception)
  923. {
  924. MessageBox.Show(exception.Message);
  925. }
  926. return false;
  927. }
  928. }
  929. }