frmMain.cs 45 KB

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