frmMain.cs 45 KB

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