frmMain.cs 35 KB

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