frmMain.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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. wgtErr = "0",
  698. stopOverTime = "0",
  699. msgInfo = "",
  700. ledWriter = "",
  701. isOverWgt = "",
  702. isHelp = "0",
  703. wgt = 0
  704. });
  705. if (!rms.Succeed)
  706. {
  707. l.WriteLog(0, "frmMain.EventData异常754:写入信息异常");
  708. isLedWrite = true;
  709. }
  710. //*/
  711. }
  712. }
  713. #endregion
  714. }
  715. catch (Exception ex)
  716. {
  717. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  718. }
  719. }
  720. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  721. /// <summary>
  722. /// 操作Live表的数据:零点报警
  723. /// </summary>
  724. private void doOperateLive () {
  725. if (PbCache.collect_no==null)
  726. {
  727. return;
  728. }
  729. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  730. if (ll != null)
  731. {
  732. foreach (LiveData lv in ll)
  733. {
  734. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  735. {
  736. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  737. break;
  738. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  739. break;
  740. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  741. break;
  742. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  743. if (((lv.Value ?? "0") + "").Equals("1"))
  744. {
  745. doInsertZeroAlarm();
  746. PbCache.isZeroAlarm = true;
  747. }
  748. else {
  749. PbCache.isZeroAlarm = false;
  750. }
  751. break;
  752. }
  753. }
  754. }
  755. }
  756. /// <summary>
  757. /// 操作Live表的数据:零点报警
  758. /// </summary>
  759. private void doLive()
  760. {
  761. if (PbCache.collect_no == null)
  762. {
  763. return;
  764. }
  765. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  766. MeterWorkMonitor mwm = new MeterWorkMonitor();
  767. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  768. mwm.redGreenLightState = "0";
  769. if (ll != null)
  770. {
  771. foreach (LiveData lv in ll)
  772. {
  773. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  774. {
  775. case "PowerStatus":
  776. mwm.powerState = lv.Value.ToString();
  777. break;
  778. case "PlcWatchDog":
  779. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  780. {
  781. mwm.plcState = 0.ToString();
  782. }
  783. break;
  784. case "InfraredWest":
  785. if (lv.Value.ToString() == "2")
  786. {
  787. mwm.leftInfraredRayState = "0";
  788. }
  789. else
  790. {
  791. mwm.leftInfraredRayState = lv.Value.ToString();
  792. }
  793. break;
  794. case "InfraredEast":
  795. if (lv.Value.ToString() == "2")
  796. {
  797. mwm.rightInfraredRayState = "0";
  798. }
  799. else
  800. {
  801. mwm.rightInfraredRayState = lv.Value.ToString();
  802. }
  803. break;
  804. case "AmplifierState":
  805. mwm.amplifierState = lv.Value.ToString();
  806. break;
  807. case "LampState":
  808. mwm.lampState = lv.Value.ToString();
  809. break;
  810. case "InfraredLeft":
  811. if (lv.Value.ToString() == "2")
  812. {
  813. mwm.frontInfraredRayState = "0";
  814. }
  815. else
  816. {
  817. mwm.frontInfraredRayState = lv.Value.ToString();
  818. }
  819. break;
  820. case "InfraredRight":
  821. if (lv.Value.ToString() == "2")
  822. {
  823. mwm.rearInfraredRayState = "0";
  824. }
  825. else
  826. {
  827. mwm.rearInfraredRayState = lv.Value.ToString();
  828. }
  829. break;
  830. case "RfidState":
  831. mwm.rfidState = lv.Value.ToString();
  832. break;
  833. }
  834. }
  835. }
  836. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  837. }
  838. /// <summary>
  839. /// 新增零点报警的数据
  840. /// </summary>
  841. private void doInsertZeroAlarm()
  842. {
  843. if (!PbCache.isZeroAlarm)
  844. {
  845. PbCache.isZeroAlarm = true;
  846. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  847. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  848. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  849. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  850. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  851. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  852. workZeroAlarm.scalePointNo = PbCache.collect_no;
  853. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  854. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  855. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  856. if (rms.Succeed)
  857. {
  858. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName +":"+ workZeroAlarm.zeroWeight);
  859. }
  860. else
  861. {
  862. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  863. }
  864. }
  865. }
  866. /// <summary>
  867. /// 关闭程序
  868. /// </summary>
  869. /// <param name="sender"></param>
  870. /// <param name="e"></param>
  871. private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
  872. {
  873. collection.Stop();
  874. imageCurlControl.Stop();
  875. sweepCodeClass.CloseThread();
  876. timer1.Stop();
  877. timer1.Dispose();
  878. }
  879. private bool SystemUpdate(bool isMessage)
  880. {
  881. ReleaseList releaseList = new ReleaseList(Application.StartupPath + @"\" + GlobalVariable.Instance.ReleaseFileName);
  882. DownloadTools dt = new DownloadTools();
  883. try
  884. {
  885. bool isDownload = dt.IsDownloadFile(GlobalVariable.Instance.LocalPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ReleaseFileName);
  886. if (!isDownload)
  887. {
  888. if (isMessage) MessageBox.Show("无法连接到远程主机!", Application.ProductName);
  889. return false;
  890. }
  891. }
  892. catch (Exception e)
  893. {
  894. MessageBox.Show(e.Message);
  895. }
  896. bool flag = this.CheckUpdate(releaseList);
  897. if (flag)
  898. {
  899. MessageBox.Show("有新版本,现在更新");
  900. string t = dt.DownloadFile(Application.StartupPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ApplicationUpdater);
  901. this.Close();
  902. Application.Exit();
  903. GC.Collect();
  904. Process.Start(Application.StartupPath + @"\" + GlobalVariable.Instance.ApplicationUpdater);
  905. return true;
  906. }
  907. else
  908. {
  909. if (isMessage) MessageBox.Show("你的系统已经是最新版本,不需要更新!", Application.ProductName);
  910. return false;
  911. }
  912. }
  913. private bool CheckUpdate(ReleaseList localRelease)
  914. {
  915. try
  916. {
  917. string fileNameAll = Application.StartupPath + "\\" + GlobalVariable.Instance.LocalPath + "\\" + GlobalVariable.Instance.ReleaseFileName;
  918. ReleaseList remoteRelease = new ReleaseList(fileNameAll);
  919. return (((localRelease != null) && (remoteRelease != null)) && localRelease.ReleaseDate.CompareTo(remoteRelease.ReleaseDate) < 0);
  920. }
  921. catch (Exception exception)
  922. {
  923. MessageBox.Show(exception.Message);
  924. }
  925. return false;
  926. }
  927. }
  928. }