frmMain.cs 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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 = "陕AAB221";
  291. // e.weight = 23580;
  292. // e.weightStatus = 1;
  293. //}
  294. //else if (num < 26)
  295. //{
  296. // e.carno = "陕AAB221";
  297. // e.weight = 23580;
  298. // e.weightStatus = 0;
  299. //}
  300. //else if (num < 39)
  301. //{
  302. // e.carno = "陕AAB221";
  303. // e.weight = 23580;
  304. // e.weightStatus = 0;
  305. //}
  306. //else if (num < 74)
  307. //{
  308. // e.carno = "陕AAB221";
  309. // e.weight = 23580;
  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. if (string.IsNullOrEmpty(PbCache.resultWgt) || !PbCache.resultWgt.Contains(e.weight + ""))
  408. {
  409. PbCache.resultWgt += e.weight + "||";
  410. }
  411. if (!string.IsNullOrEmpty(e.carno))
  412. {
  413. PbCache.resultCarNo = e.carno + "";
  414. }
  415. }
  416. }
  417. //*/
  418. // 更新监控表
  419. doLive();
  420. //重量大于500的情况下
  421. if (e.weight > 500)
  422. {
  423. #region 记录从上秤到下秤的所有的提示信息
  424. if (!string.IsNullOrEmpty(PbCache.resultMsgAll) && !PbCache.resultMsgAll.Contains(PbCache.ResultMessage))
  425. {
  426. PbCache.resultMsgAll = PbCache.resultMsgAll + " || " + PbCache.ResultMessage;
  427. }
  428. else if (string.IsNullOrEmpty(PbCache.resultMsgAll))
  429. {
  430. PbCache.resultMsgAll = PbCache.ResultMessage;
  431. }
  432. else
  433. {
  434. //提示信息重复,不做处理
  435. }
  436. #endregion 记录从上秤到下秤的所有的提示信息
  437. if (PbCache.dtStartTime == null)
  438. PbCache.dtStartTime = DateTime.Now;
  439. isLedWrite = true;
  440. #region 车上人员请下车
  441. try
  442. {
  443. //界面未锁定的情况下,有车号,如果重量稳定了,停车线验证通过,未超量程的情况下,则按钮可用
  444. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status && PbCache.collect.weight < PbCache.range.upperRange)
  445. {
  446. if (!isVoiceDownCar)
  447. {
  448. isVoiceDownCar = true;
  449. vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
  450. }
  451. }
  452. }
  453. catch { }
  454. #endregion
  455. setWelecomeVis(false);
  456. //每隔1秒刷一次计量实时监控表数据值
  457. if (iCount % 2 == 0)
  458. {
  459. //调用该方法时已赋值
  460. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  461. if (!rm.Succeed)
  462. {
  463. l.WriteLog(0, "frmMain.EventData异常419:" + rm.ResultMessage);
  464. }
  465. else
  466. {
  467. if (rm.Data != null && rm.Data.Count > 0)
  468. {
  469. PbCache.monitor = rm.Data[0];
  470. if (string.IsNullOrEmpty(PbCache.collect_no))
  471. {
  472. PbCache.collect_no = rm.Data[0].collectionCode;
  473. }
  474. if (ledTxt != rm.Data[0].ledWriter && rm.Data[0].ledWriter != "")
  475. {
  476. //调用LED信息写入******************************
  477. ledTxt = rm.Data[0].ledWriter;
  478. }
  479. if (string.IsNullOrEmpty(ledTxt))
  480. {
  481. ledTxt = "欢迎使用酒钢汽车衡智能计量系统!";
  482. }
  483. }
  484. }
  485. #region 2021-03-29
  486. #region 摄像头当前采集的车号与上次采集的不一样且当前未勾选不验证,且当前车号未进行手动修正的情况下
  487. if (preCarNo != e.carno && PbCache.monitor != null && PbCache.monitor.validCarno != "0" && !bEditCar)
  488. {
  489. flagCarMonit = false;
  490. }
  491. preCarNo = e.carno;
  492. #endregion
  493. if (!flagCarMonit)
  494. {
  495. sCarNo = e.carno;
  496. }
  497. //*
  498. //有车号,且重量稳定的情况下,只修正一次车号
  499. if (!string.IsNullOrEmpty(e.carno) && e.weightStatus == 0 && !flagCarMonit && PbCache.monitor != null && PbCache.monitor.carMonitor == "1" && PbCache.monitor.carMonitorLvl > 0)
  500. {
  501. flagCarMonit = true;
  502. string methods = "";
  503. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  504. {
  505. methods += "CarNoTrustCorrect" + i + ",";
  506. }
  507. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  508. sCarNo = editCarNo;
  509. //mwUpdate
  510. }
  511. //勾选了不验证车号的情况
  512. if (PbCache.monitor.validCarno == "0")
  513. {
  514. flagCarMonit = true;
  515. }
  516. #endregion
  517. #region 每隔1秒写入一次重量曲线
  518. try
  519. {
  520. if (preWgt != e.weight)
  521. {
  522. preWgt = e.weight;
  523. sPreNo = PbCache.sportInfo.baseSpotNo + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  524. monitorWeightService.doAddWf(new MeterMonitorWeight
  525. {
  526. weightNo = sPreNo,
  527. baseSpotNo = PbCache.sportInfo.baseSpotNo,
  528. baseSpotName = PbCache.sportInfo.baseSpotName,
  529. collectWeight = e.weight + "",
  530. collectStartTime = PbCache.dtStartTime.Value,
  531. collectEndTime = DateTime.Now,
  532. spotTypeNo = "001002001",
  533. spotTypeName = "汽车衡",
  534. actualFirstNo = PbCache.actualFirstNo
  535. });
  536. }
  537. else
  538. {
  539. if (!string.IsNullOrEmpty(sPreNo))
  540. {
  541. monitorWeightService.doUpdateWf(new MeterMonitorWeight
  542. {
  543. weightNo = sPreNo,
  544. collectEndTime = DateTime.Now
  545. });
  546. }
  547. }
  548. }
  549. catch { }
  550. #endregion
  551. #region 停留超时
  552. iHodeTime++;
  553. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  554. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  555. mwUpdate.editCar = editCarNo;
  556. if (PbCache.holdTime != null && PbCache.holdTime.Count > 0)
  557. {
  558. if (PbCache.holdTime[0].retentionTime != null)
  559. {
  560. if (PbCache.holdTime[0].retentionTime.Value < iHodeTime)
  561. {
  562. PbCache.isOvertimeAlarm = true; //是否超时报警
  563. mwUpdate.stopOverTime = "1"; //写入一次停留超时
  564. //mwUpdate.isHelp = "1";//派位
  565. //mwUpdate.isTakeOver = "1";
  566. iHodeTime = 99999;//不再增长避免超出
  567. }
  568. }
  569. }
  570. #endregion
  571. #region RFID识别车号信息
  572. mwUpdate.rfidCar = "";
  573. mwUpdate.photoCar = e.vdioCarNos;
  574. if (codeFlag)
  575. {
  576. mwUpdate.scanCar = PbCache.collect.carno;
  577. }
  578. //mwUpdate.photoCar = PbCache.collect.carno;
  579. if (!string.IsNullOrEmpty(e.RfidNos))
  580. {
  581. string sqls = @"SELECT RFID_ID id,CAR_NO text FROM METER_BASE_RFID_INFO where RFID_CODE = '" + e.RfidNos + "'";
  582. PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
  583. RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
  584. if (rmT.Data == null || rmT.Data.Count == 0)
  585. { }
  586. else
  587. {
  588. mwUpdate.rfidCar = rmT.Data[0].text;
  589. sCarNo = rmT.Data[0].text;
  590. }
  591. }
  592. #endregion
  593. #region 计量员修改的车号信息
  594. if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.setCar))
  595. {
  596. sCarNo = PbCache.monitor.setCar;
  597. bEditCar = true;
  598. flagCarMonit = true;
  599. codeFlag = false;
  600. sweepCodeClass.StrCode = "";
  601. }
  602. #endregion
  603. #region 重量信息
  604. if (!PbCache.isLockFrm)
  605. {
  606. mwUpdate.wgt = e.weight;
  607. }
  608. else
  609. {
  610. mwUpdate.wgt = Convert.ToInt32(PbCache.lockWgt);
  611. }
  612. #endregion
  613. #region 写入一次监控表,将重量/车号停留超时等信息写入
  614. mwUpdate.msgInfo = PbCache.ResultMessage;
  615. mwUpdate.weightStatus = PbCache.collect.weightStatus;
  616. //另外初始化一次监控数据
  617. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  618. if (!rms.Succeed)
  619. {
  620. l.WriteLog(0, "frmMain.EventData异常583:写入信息异常" + mwUpdate);
  621. }
  622. #endregion
  623. //验证对射
  624. valid.ValidMethod();
  625. if (!isOpenMeter)
  626. {
  627. //if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  628. if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  629. {
  630. //超量程
  631. vicPlayClass.GetVoicePlay("已超量程", e.carno);
  632. //return;
  633. }
  634. else if (e.weightStatus == 0)
  635. {
  636. if (!PbCache.monitorResult.valid_park_status)
  637. {
  638. iCountPark++;
  639. if (iCountPark > 9)
  640. {
  641. //重量稳定,且对射验证不合格
  642. vicPlayClass.GetVoicePlay("您的车辆未停到位", e.carno);
  643. //return;
  644. iCountPark = 0; //2021年7月27日5s播一次,然后重新在播
  645. }
  646. }
  647. else
  648. {
  649. iCountPark = 0;
  650. }
  651. }
  652. }
  653. if (!lu[0].bcEnable)
  654. {
  655. foreach (ucBusinessType uc in lu)
  656. {
  657. uc.setControlEnable(true);
  658. }
  659. }
  660. if (sweepCodeClass.StrCode == "" && !codeFlag)
  661. {
  662. PbCache.collect.carno = sCarNo;
  663. }
  664. }
  665. //写入LED信息
  666. //if (PbCache.sportInfo != null && PbCache.ledInfo != PbCache.OldLedInfo)
  667. //{
  668. // PbCache.OldLedInfo = PbCache.ledInfo;
  669. // if (PbCache.monitor != null && PbCache.monitor.ledKeep == "0")
  670. // {
  671. // //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  672. // }
  673. //}
  674. }
  675. else
  676. {
  677. if (e.weight > 10 && e.weight < 500)
  678. {
  679. //重量小于500,大于10
  680. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  681. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  682. mwUpdate.wgt = e.weight;
  683. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  684. }
  685. if (e.weight > 0 && e.weight < 200)
  686. {
  687. doOperateLive();
  688. }
  689. if (e.weight == 0)
  690. {
  691. PbCache.isZeroAlarm = false;
  692. }
  693. isOpened = false; //下次上秤直接打开主界面
  694. editCarNo = "";
  695. firstCode = ""; //历史的扫码枪的值
  696. preCarNo = "";
  697. sCarNo = "";
  698. sPreNo = "";
  699. preWgt = 0;
  700. //不等于空的时候说明写过一次日志了
  701. if (!string.IsNullOrEmpty(PbCache.resultMsgAll))
  702. {
  703. l.WriteLog(28, "车号:" + (string.IsNullOrEmpty(PbCache.resultCarNo) ? "未识别" : PbCache.resultCarNo) + ";重量:" + (PbCache.lockWgt == 0 ? PbCache.resultWgt : PbCache.lockWgt + "") + ";提示信息:" + PbCache.resultMsgAll);
  704. MeterWorkScheduledHelp meterWorkScheduledHelp1 = new MeterWorkScheduledHelp();
  705. meterWorkScheduledHelp1.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  706. meterWorkScheduledHelp1.baseSpotName = PbCache.sportInfo.baseSpotName;
  707. meterWorkScheduledHelp1.carNo = string.IsNullOrEmpty(PbCache.collect.carno) ? PbCache.resultCarNo : PbCache.collect.carno;
  708. meterWorkScheduledHelp1.helpContent = "车号:" + (string.IsNullOrEmpty(PbCache.resultCarNo) ? "未识别" : PbCache.resultCarNo) + ";重量:" + (PbCache.lockWgt == 0 ? PbCache.resultWgt : PbCache.lockWgt + "") + ";提示信息:" + PbCache.resultMsgAll;
  709. meterWorkScheduledHelp1.warmType = "5";
  710. meterWorkScheduledHelp1.warmTypeName = "计量提示跟踪";
  711. meterWorkScheduledHelpService.add(meterWorkScheduledHelp1);
  712. }
  713. PbCache.isOvertimeAlarm = false; //是否超时报警
  714. PbCache.strCode = "";
  715. PbCache.ResultMessage = "";
  716. PbCache.resultMsgAll = "";
  717. bEditCar = false;
  718. isVoiceDownCar = false;
  719. flagCarMonit = false;
  720. iHodeTime = 0;
  721. isOpenMeter = false;
  722. PbCache.isLockFrm = false;
  723. PbCache.dtStartTime = null;
  724. PbCache.voiceOver = true;
  725. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
  726. {
  727. PbCache.collect.carno = "";
  728. }
  729. setWelecomeVis(true);
  730. if (lu[0].bcEnable)
  731. {
  732. foreach (ucBusinessType uc in lu)
  733. {
  734. uc.setControlEnable(false);
  735. }
  736. }
  737. //LED写入
  738. if (isLedWrite)
  739. {
  740. //if (PbCache.monitor == null || string.IsNullOrEmpty(PbCache.monitor.ledWriter))
  741. //{
  742. // PbCache.ledInfo = "欢迎使用酒钢汽车衡智能计量系统";
  743. //}
  744. //else
  745. //{
  746. // PbCache.ledInfo = PbCache.monitor == null ? "" : PbCache.monitor.ledWriter;
  747. //}
  748. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  749. isLedWrite = false;
  750. //*
  751. //另外初始化一次监控数据
  752. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor
  753. {
  754. pointNo = PbCache.sportInfo.baseSpotNo,
  755. validWgt = "1",
  756. validCarno = "1",
  757. validTareTime = "1",
  758. validMatTime = "1",
  759. validTimeInterval = "1",
  760. validParkStatus = "1",
  761. validExceedWgt = "1",
  762. validPredictionDiff = "1",
  763. validLianda = "1",
  764. validMatClick = "1",
  765. setCar = "",
  766. rfidCar = "",
  767. photoCar = "",
  768. scanCar = "",
  769. editCar = "",
  770. zeroState = "0",
  771. carErr = "0",
  772. ferroalloyResult = "0",
  773. wgtErr = "0",
  774. stopOverTime = "0",
  775. msgInfo = "",
  776. ledWriter = "",
  777. isOverWgt = "",
  778. isHelp = "0",
  779. wgt = 0
  780. });
  781. if (!rms.Succeed)
  782. {
  783. l.WriteLog(0, "frmMain.EventData异常754:写入信息异常");
  784. isLedWrite = true;
  785. }
  786. //*/
  787. }
  788. }
  789. #endregion
  790. }
  791. catch (Exception ex)
  792. {
  793. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  794. }
  795. }
  796. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  797. /// <summary>
  798. /// 操作Live表的数据:零点报警
  799. /// </summary>
  800. private void doOperateLive () {
  801. if (PbCache.collect_no==null)
  802. {
  803. return;
  804. }
  805. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  806. if (ll != null)
  807. {
  808. foreach (LiveData lv in ll)
  809. {
  810. if (lv.Tagname == "ZeroWeightStatus")
  811. {
  812. lv.Value = "1";
  813. }
  814. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  815. {
  816. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  817. break;
  818. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  819. break;
  820. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  821. break;
  822. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  823. if (((lv.Value ?? "0") + "").Equals("1"))
  824. {
  825. doInsertZeroAlarm();
  826. PbCache.isZeroAlarm = true;
  827. }
  828. else
  829. {
  830. PbCache.isZeroAlarm = false;
  831. }
  832. break;
  833. }
  834. }
  835. }
  836. }
  837. /// <summary>
  838. /// 操作Live表的数据:零点报警
  839. /// </summary>
  840. private void doLive()
  841. {
  842. if (PbCache.collect_no == null)
  843. {
  844. return;
  845. }
  846. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  847. MeterWorkMonitor mwm = new MeterWorkMonitor();
  848. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  849. mwm.redGreenLightState = "0";
  850. if (ll != null)
  851. {
  852. foreach (LiveData lv in ll)
  853. {
  854. if (lv.Tagname == "ZeroWeightStatus")
  855. {
  856. lv.Value = "1";
  857. }
  858. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  859. {
  860. case "PowerStatus":
  861. mwm.powerState = lv.Value.ToString();
  862. break;
  863. case "PlcWatchDog":
  864. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  865. {
  866. mwm.plcState = 0.ToString();
  867. }
  868. break;
  869. case "InfraredWest":
  870. if (lv.Value.ToString() == "2")
  871. {
  872. mwm.leftInfraredRayState = "0";
  873. }
  874. else
  875. {
  876. mwm.leftInfraredRayState = lv.Value.ToString();
  877. }
  878. break;
  879. case "InfraredEast":
  880. if (lv.Value.ToString() == "2")
  881. {
  882. mwm.rightInfraredRayState = "0";
  883. }
  884. else
  885. {
  886. mwm.rightInfraredRayState = lv.Value.ToString();
  887. }
  888. break;
  889. case "AmplifierState":
  890. mwm.amplifierState = lv.Value.ToString();
  891. break;
  892. case "LampState":
  893. mwm.lampState = lv.Value.ToString();
  894. break;
  895. case "InfraredLeft":
  896. if (lv.Value.ToString() == "2")
  897. {
  898. mwm.frontInfraredRayState = "0";
  899. }
  900. else
  901. {
  902. mwm.frontInfraredRayState = lv.Value.ToString();
  903. }
  904. break;
  905. case "InfraredRight":
  906. if (lv.Value.ToString() == "2")
  907. {
  908. mwm.rearInfraredRayState = "0";
  909. }
  910. else
  911. {
  912. mwm.rearInfraredRayState = lv.Value.ToString();
  913. }
  914. break;
  915. case "RfidState":
  916. mwm.rfidState = lv.Value.ToString();
  917. break;
  918. case "ZeroWeightStatus":
  919. mwm.zeroState = lv.Value.ToString();
  920. break;
  921. }
  922. }
  923. }
  924. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  925. }
  926. /// <summary>
  927. /// 新增零点报警的数据
  928. /// </summary>
  929. private void doInsertZeroAlarm()
  930. {
  931. if (!PbCache.isZeroAlarm)
  932. {
  933. PbCache.isZeroAlarm = true;
  934. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  935. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  936. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  937. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  938. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  939. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  940. workZeroAlarm.scalePointNo = PbCache.collect_no;
  941. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  942. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  943. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  944. if (rms.Succeed)
  945. {
  946. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName +":"+ workZeroAlarm.zeroWeight);
  947. }
  948. else
  949. {
  950. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  951. }
  952. }
  953. }
  954. /// <summary>
  955. /// 关闭程序
  956. /// </summary>
  957. /// <param name="sender"></param>
  958. /// <param name="e"></param>
  959. private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
  960. {
  961. collection.Stop();
  962. imageCurlControl.Stop();
  963. sweepCodeClass.CloseThread();
  964. timer1.Stop();
  965. timer1.Dispose();
  966. }
  967. private bool SystemUpdate(bool isMessage)
  968. {
  969. ReleaseList releaseList = new ReleaseList(Application.StartupPath + @"\" + GlobalVariable.Instance.ReleaseFileName);
  970. DownloadTools dt = new DownloadTools();
  971. try
  972. {
  973. bool isDownload = dt.IsDownloadFile(GlobalVariable.Instance.LocalPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ReleaseFileName);
  974. if (!isDownload)
  975. {
  976. if (isMessage) MessageBox.Show("无法连接到远程主机!", Application.ProductName);
  977. return false;
  978. }
  979. }
  980. catch (Exception e)
  981. {
  982. MessageBox.Show(e.Message);
  983. }
  984. bool flag = this.CheckUpdate(releaseList);
  985. if (flag)
  986. {
  987. MessageBox.Show("有新版本,现在更新");
  988. string t = dt.DownloadFile(Application.StartupPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ApplicationUpdater);
  989. this.Close();
  990. Application.Exit();
  991. GC.Collect();
  992. Process.Start(Application.StartupPath + @"\" + GlobalVariable.Instance.ApplicationUpdater);
  993. return true;
  994. }
  995. else
  996. {
  997. if (isMessage) MessageBox.Show("你的系统已经是最新版本,不需要更新!", Application.ProductName);
  998. return false;
  999. }
  1000. }
  1001. private bool CheckUpdate(ReleaseList localRelease)
  1002. {
  1003. try
  1004. {
  1005. string fileNameAll = Application.StartupPath + "\\" + GlobalVariable.Instance.LocalPath + "\\" + GlobalVariable.Instance.ReleaseFileName;
  1006. ReleaseList remoteRelease = new ReleaseList(fileNameAll);
  1007. return (((localRelease != null) && (remoteRelease != null)) && localRelease.ReleaseDate.CompareTo(remoteRelease.ReleaseDate) < 0);
  1008. }
  1009. catch (Exception exception)
  1010. {
  1011. MessageBox.Show(exception.Message);
  1012. }
  1013. return false;
  1014. }
  1015. }
  1016. }