frmMain.cs 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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. 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.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, lastTime = DateTime.Now });
  394. if (!rms.Succeed)
  395. {
  396. l.WriteLog(0, "frmMain.EventData异常:写入时间异常");
  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. //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. }