fromContect.cs 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. using CarMeterSystem.OptionCls;
  2. using CarMeterSystem;
  3. using com.hnshituo.core.webapp.vo;
  4. using Common;
  5. using iCore.Rtdb.RtdbTable;
  6. using MeterConditionLibrary;
  7. using MeterModelLibrary;
  8. using MeterModuleLibrary.uc;
  9. using MeterPlugInLibrary;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.IO;
  15. using System.Linq;
  16. using System.Windows.Forms;
  17. namespace CarMeterMonitor
  18. {
  19. public partial class fromContect : Form
  20. {
  21. public fromContect()
  22. {
  23. InitializeComponent();
  24. }
  25. private Log l = Log.GetInstance();
  26. private Print printClass = new Print();//打印
  27. //内存表
  28. private MemoryTableDataSocket MemoClass = new MemoryTableDataSocket("");
  29. //实时表数据采集
  30. private DataCollectionControl collection = new DataCollectionControl();
  31. //图片控制器含图片压缩及上传curl
  32. private ImageCurlControl imageCurlControl = new ImageCurlControl();
  33. //与监控界面对接的表
  34. private MeterWorkMonitorService meterWorkMonitor = new MeterWorkMonitorService();
  35. //零点报警表
  36. private meterworkzeroalarmservice zeroAlarmService = new meterworkzeroalarmservice();
  37. //车号修正
  38. private CarNoModfiy modfiy = new CarNoModfiy();
  39. /// <summary>
  40. /// 这个是保存前一次采集中的车号信息
  41. /// </summary>
  42. private string preCarNo = "";
  43. //验证对射
  44. private validParkStatus valid = new validParkStatus();
  45. //语音播报
  46. private VoicePlay vicPlayClass = new VoicePlay();
  47. //扫码枪
  48. private SweepCode sweepCodeClass = new SweepCode();
  49. private LED_Control led_controler = null;
  50. //监控表操作
  51. private MeterMonitorWeightService monitorWeightService = new MeterMonitorWeightService();
  52. //历史皮操作
  53. private MeterBaseHisTareDataService hisTareDataService = new MeterBaseHisTareDataService();
  54. /// <summary>
  55. /// 欢迎界面
  56. /// </summary>
  57. private frmWelcome_Jisco frmWelcome = new frmWelcome_Jisco();//欢迎
  58. private int startCar = 0;
  59. private int startWeight = 0;
  60. private DateTime startTime;
  61. private DateTime endTime;
  62. /// <summary>
  63. /// 基础数据载入
  64. /// </summary>
  65. private BaseDbCls bd = new BaseDbCls();
  66. //扫码修正车号标识
  67. private bool codeFlag = false;
  68. private List<ucBusinessType> lu = new List<ucBusinessType>();
  69. private bool isVoiceDownCar = false;//车上人员请下车播放一次
  70. private bool isShowFrmWelcome = false; //是否显示欢迎界面
  71. private bool isOpened = false;//是否已经打开了扫码计量界面
  72. private void fromContect_Load(object sender, EventArgs e)
  73. {
  74. //*
  75. try
  76. {
  77. //this.Hide();
  78. LoginCls lg = new LoginCls();
  79. timer1.Start();
  80. //2021年6月21日 杨秀东添加
  81. if (isShowFrmWelcome)
  82. {
  83. frmWelcome.Show();
  84. frmWelcome.Visible = true;
  85. }
  86. if (lg.LoginIn())
  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. /// <summary>
  280. /// 数据采集
  281. /// </summary>
  282. /// <param name="o"></param>
  283. /// <param name="e"></param>
  284. private void EventData(object o, DataCollectionArgs e)
  285. {
  286. //这里每隔0.5秒执行一次
  287. try
  288. {
  289. #region 扫码信息
  290. sweepCodeClass.StrState = e.weightStatus + ""; //重量状态信息;当StrState= 0时,获取扫码信息,StrState= 2时将扫码信息置位“”空;其他状态不处理
  291. if (string.IsNullOrEmpty(sweepCodeClass.StrCode))
  292. {
  293. codeFlag = false;
  294. if (string.IsNullOrEmpty(PbCache.strCode))
  295. {
  296. firstCode = "";
  297. PbCache.strCode = "";
  298. l.WriteLog(12, "主线程扫码值为空时清空;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode值为:" + PbCache.strCode);
  299. }
  300. }
  301. else
  302. {
  303. ////日期2021年12月22日:重复扫码,取前面12位
  304. //if (sweepCodeClass.StrCode.Length > 15)
  305. //{
  306. // // todo: 加入车号截取逻辑
  307. // sweepCodeClass.StrCode = sweepCodeClass.StrCode.Substring(0,12);
  308. //}
  309. //if (firstCode != sweepCodeClass.StrCode || string.IsNullOrEmpty(PbCache.strCode))
  310. //{
  311. // l.WriteLog(12, "主线程扫码值赋值;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode前值为:" + PbCache.strCode);
  312. // PbCache.strCode = sweepCodeClass.StrCode;
  313. // firstCode = PbCache.strCode;
  314. //}
  315. l.WriteLog(12, "测试扫码值" + PbCache.strCode);
  316. PbCache.collect.carno = sweepCodeClass.StrCode;
  317. codeFlag = true;
  318. }
  319. #endregion 扫码信息
  320. #region 秤上无车10分钟获取一次基础数据
  321. if (iCount < 1200)
  322. {
  323. iCount++;
  324. }
  325. else
  326. {
  327. try
  328. {
  329. //秤上没有车时,每隔10分钟获取一次基础数据
  330. if (e.weight < 500)
  331. {
  332. if (bd.setBaseDb())
  333. {
  334. l.WriteLog(0, "十分钟获取基础数据成功");
  335. }
  336. else
  337. {
  338. l.WriteLog(0, "十分钟获取基础数据失败");
  339. }
  340. iCount = 0;
  341. }
  342. }
  343. catch (Exception ex)
  344. {
  345. l.WriteLog(0, "十分钟获取基础数据失败:" + ex.Message);
  346. iCount = 0;
  347. }
  348. }
  349. #endregion
  350. #region 每10秒写入一次当前时间
  351. if (iCount % 20 == 0)
  352. {
  353. //更新在线时间
  354. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, lastTime = DateTime.Now });
  355. if (!rms.Succeed)
  356. {
  357. l.WriteLog(0, "frmMain.EventData异常:写入时间异常");
  358. }
  359. }
  360. #endregion
  361. #region
  362. //一旦界面锁定则不采集数据
  363. if (!PbCache.isLockFrm)
  364. {
  365. PbCache.collect.pointid = PbCache.sportInfo.baseSpotNo;
  366. PbCache.collect.weight = e.weight;
  367. PbCache.collect.weightStatus = e.weightStatus;
  368. PbCache.collect.parkStatus = e.parkStatus;
  369. PbCache.collect.datetime = e.datetime;
  370. PbCache.collect.licType = e.licType;
  371. }
  372. //*/
  373. // 更新监控表
  374. doLive();
  375. //重量大于500的情况下
  376. if (e.weight > 500)
  377. {
  378. if (startWeight == 0)
  379. {
  380. startTime = DateTime.Now;
  381. startWeight = 1;
  382. }
  383. if (startCar == 0 && e.vdioCarNos != "")
  384. {
  385. WriteText(0, "当前采集车号:" + e.vdioCarNos);
  386. startCar = 1;
  387. }
  388. if (startWeight == 1 && PbCache.collect.weightStatus == 0)
  389. {
  390. endTime = DateTime.Now;
  391. startWeight = 2;
  392. TimeSpan secondSpan = new TimeSpan(endTime.Ticks - startTime.Ticks);
  393. WriteText(1, "开始时间:" + startTime.ToString("yyyy-MM-dd HH:mm:ss:fff") + ",结束时间:" + endTime.ToString("yyyy-MM-dd HH:mm:ss:fff") + ",时间差:" + secondSpan.TotalSeconds + "秒" + ",重量:" + e.weight);
  394. }
  395. if (PbCache.dtStartTime == null)
  396. PbCache.dtStartTime = DateTime.Now;
  397. isLedWrite = true;
  398. #region 车上人员请下车
  399. try
  400. {
  401. //界面未锁定的情况下,有车号,如果重量稳定了,停车线验证通过,未超量程的情况下,则按钮可用
  402. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status && PbCache.collect.weight < PbCache.range.upperRange)
  403. {
  404. if (!isVoiceDownCar)
  405. {
  406. isVoiceDownCar = true;
  407. vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
  408. }
  409. }
  410. }
  411. catch { }
  412. #endregion
  413. setWelecomeVis(false);
  414. //每隔1秒刷一次计量实时监控表数据值
  415. if (iCount % 2 == 0)
  416. {
  417. //调用该方法时已赋值
  418. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  419. if (!rm.Succeed)
  420. {
  421. l.WriteLog(0, "frmMain.EventData异常419:" + rm.ResultMessage);
  422. }
  423. else
  424. {
  425. if (rm.Data != null && rm.Data.Count > 0)
  426. {
  427. PbCache.monitor = rm.Data[0];
  428. if (string.IsNullOrEmpty(PbCache.collect_no))
  429. {
  430. PbCache.collect_no = rm.Data[0].collectionCode;
  431. }
  432. if (ledTxt != rm.Data[0].ledWriter && rm.Data[0].ledWriter != "")
  433. {
  434. //调用LED信息写入******************************
  435. ledTxt = rm.Data[0].ledWriter;
  436. }
  437. if (string.IsNullOrEmpty(ledTxt))
  438. {
  439. ledTxt = "欢迎使用酒钢汽车衡智能计量系统!";
  440. }
  441. }
  442. }
  443. #region 2021-03-29
  444. #region 摄像头当前采集的车号与上次采集的不一样且当前未勾选不验证,且当前车号未进行手动修正的情况下
  445. if (preCarNo != e.carno && PbCache.monitor != null && PbCache.monitor.validCarno != "0" && !bEditCar)
  446. {
  447. flagCarMonit = false;
  448. }
  449. preCarNo = e.carno;
  450. #endregion
  451. if (!flagCarMonit)
  452. {
  453. sCarNo = e.carno;
  454. }
  455. //*
  456. //有车号,且重量稳定的情况下,只修正一次车号
  457. if (!string.IsNullOrEmpty(e.carno) && e.weightStatus == 0 && !flagCarMonit && PbCache.monitor != null && PbCache.monitor.carMonitor == "1" && PbCache.monitor.carMonitorLvl > 0)
  458. {
  459. flagCarMonit = true;
  460. string methods = "";
  461. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  462. {
  463. methods += "CarNoTrustCorrect" + i + ",";
  464. }
  465. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  466. sCarNo = editCarNo;
  467. //mwUpdate
  468. }
  469. //勾选了不验证车号的情况
  470. if (PbCache.monitor.validCarno == "0")
  471. {
  472. flagCarMonit = true;
  473. }
  474. #endregion
  475. #region 每隔1秒写入一次重量曲线
  476. try
  477. {
  478. if (preWgt != e.weight)
  479. {
  480. preWgt = e.weight;
  481. sPreNo = PbCache.sportInfo.baseSpotNo + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  482. monitorWeightService.doAddWf(new MeterMonitorWeight
  483. {
  484. weightNo = sPreNo,
  485. baseSpotNo = PbCache.sportInfo.baseSpotNo,
  486. baseSpotName = PbCache.sportInfo.baseSpotName,
  487. collectWeight = e.weight + "",
  488. collectStartTime = PbCache.dtStartTime.Value,
  489. collectEndTime = DateTime.Now,
  490. spotTypeNo = "001002001",
  491. spotTypeName = "汽车衡",
  492. actualFirstNo = PbCache.actualFirstNo
  493. });
  494. }
  495. else
  496. {
  497. if (!string.IsNullOrEmpty(sPreNo))
  498. {
  499. monitorWeightService.doUpdateWf(new MeterMonitorWeight
  500. {
  501. weightNo = sPreNo,
  502. collectEndTime = DateTime.Now
  503. });
  504. }
  505. }
  506. }
  507. catch { }
  508. #endregion
  509. #region 停留超时
  510. iHodeTime++;
  511. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  512. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  513. mwUpdate.editCar = editCarNo;
  514. if (PbCache.holdTime != null && PbCache.holdTime.Count > 0)
  515. {
  516. if (PbCache.holdTime[0].retentionTime != null)
  517. {
  518. if (PbCache.holdTime[0].retentionTime.Value < iHodeTime)
  519. {
  520. PbCache.isOvertimeAlarm = true; //是否超时报警
  521. mwUpdate.stopOverTime = "1"; //写入一次停留超时
  522. //mwUpdate.isHelp = "1";//派位
  523. //mwUpdate.isTakeOver = "1";
  524. iHodeTime = 99999;//不再增长避免超出
  525. }
  526. }
  527. }
  528. #endregion
  529. #region RFID识别车号信息
  530. mwUpdate.rfidCar = "";
  531. mwUpdate.photoCar = e.vdioCarNos;
  532. //mwUpdate.photoCar = PbCache.collect.carno;
  533. if (!string.IsNullOrEmpty(e.RfidNos))
  534. {
  535. string sqls = @"SELECT RFID_ID id,CAR_NO text FROM METER_BASE_RFID_INFO where RFID_CODE = '" + e.RfidNos + "'";
  536. PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
  537. RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
  538. if (rmT.Data == null || rmT.Data.Count == 0)
  539. { }
  540. else
  541. {
  542. mwUpdate.rfidCar = rmT.Data[0].text;
  543. sCarNo = rmT.Data[0].text;
  544. }
  545. }
  546. #endregion
  547. #region 计量员修改的车号信息
  548. if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.setCar))
  549. {
  550. sCarNo = PbCache.monitor.setCar;
  551. bEditCar = true;
  552. flagCarMonit = true;
  553. codeFlag = false;
  554. sweepCodeClass.StrCode = "";
  555. }
  556. #endregion
  557. #region 重量信息
  558. if (!PbCache.isLockFrm)
  559. {
  560. mwUpdate.wgt = e.weight;
  561. }
  562. else
  563. {
  564. mwUpdate.wgt = Convert.ToInt32(PbCache.lockWgt);
  565. }
  566. #endregion
  567. #region 写入一次监控表,将重量/车号停留超时等信息写入
  568. mwUpdate.msgInfo = PbCache.ResultMessage;
  569. mwUpdate.weightStatus = PbCache.collect.weightStatus;
  570. //另外初始化一次监控数据
  571. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  572. if (!rms.Succeed)
  573. {
  574. l.WriteLog(0, "frmMain.EventData异常583:写入信息异常");
  575. }
  576. #endregion
  577. //验证对射
  578. valid.ValidMethod();
  579. if (!isOpenMeter)
  580. {
  581. //if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  582. if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  583. {
  584. //超量程
  585. vicPlayClass.GetVoicePlay("已超量程", e.carno);
  586. //return;
  587. }
  588. else if (e.weightStatus == 0)
  589. {
  590. if (!PbCache.monitorResult.valid_park_status)
  591. {
  592. iCountPark++;
  593. if (iCountPark > 9)
  594. {
  595. //重量稳定,且对射验证不合格
  596. vicPlayClass.GetVoicePlay("您的车辆未停到位", e.carno);
  597. //return;
  598. iCountPark = 0; //2021年7月27日5s播一次,然后重新在播
  599. }
  600. }
  601. else
  602. {
  603. iCountPark = 0;
  604. }
  605. }
  606. }
  607. if (!lu[0].bcEnable)
  608. {
  609. foreach (ucBusinessType uc in lu)
  610. {
  611. uc.setControlEnable(true);
  612. }
  613. }
  614. if (sweepCodeClass.StrCode == "" && !codeFlag)
  615. {
  616. PbCache.collect.carno = sCarNo;
  617. }
  618. }
  619. //写入LED信息
  620. if (PbCache.sportInfo != null && PbCache.ledInfo != PbCache.OldLedInfo)
  621. {
  622. PbCache.OldLedInfo = PbCache.ledInfo;
  623. if (PbCache.monitor != null && PbCache.monitor.ledKeep == "0")
  624. {
  625. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  626. }
  627. }
  628. }
  629. else
  630. {
  631. startCar = 0;
  632. startWeight = 0;
  633. if (e.weight > 10 && e.weight < 500)
  634. {
  635. //重量小于500,大于10
  636. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  637. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  638. mwUpdate.wgt = e.weight;
  639. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  640. }
  641. if (e.weight > 0 && e.weight < 200)
  642. {
  643. doOperateLive();
  644. }
  645. if (e.weight == 0)
  646. {
  647. PbCache.isZeroAlarm = false;
  648. }
  649. isOpened = false; //下次上秤直接打开主界面
  650. editCarNo = "";
  651. firstCode = ""; //历史的扫码枪的值
  652. preCarNo = "";
  653. sCarNo = "";
  654. sPreNo = "";
  655. preWgt = 0;
  656. PbCache.isOvertimeAlarm = false; //是否超时报警
  657. PbCache.strCode = "";
  658. PbCache.ResultMessage = "";
  659. bEditCar = false;
  660. isVoiceDownCar = false;
  661. flagCarMonit = false;
  662. iHodeTime = 0;
  663. isOpenMeter = false;
  664. PbCache.isLockFrm = false;
  665. PbCache.dtStartTime = null;
  666. PbCache.voiceOver = true;
  667. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
  668. {
  669. PbCache.collect.carno = "";
  670. }
  671. setWelecomeVis(true);
  672. if (lu[0].bcEnable)
  673. {
  674. foreach (ucBusinessType uc in lu)
  675. {
  676. uc.setControlEnable(false);
  677. }
  678. }
  679. //LED写入
  680. if (isLedWrite)
  681. {
  682. if (PbCache.monitor == null || string.IsNullOrEmpty(PbCache.monitor.ledWriter))
  683. {
  684. PbCache.ledInfo = "欢迎使用九钢汽车衡智能计量系统";
  685. }
  686. else
  687. {
  688. PbCache.ledInfo = PbCache.monitor == null ? "" : PbCache.monitor.ledWriter;
  689. }
  690. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  691. isLedWrite = false;
  692. //*
  693. //另外初始化一次监控数据
  694. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor
  695. {
  696. pointNo = PbCache.sportInfo.baseSpotNo,
  697. validWgt = "1",
  698. validCarno = "1",
  699. validTareTime = "1",
  700. validMatTime = "1",
  701. validTimeInterval = "1",
  702. validParkStatus = "1",
  703. validExceedWgt = "1",
  704. validPredictionDiff = "1",
  705. validLianda = "1",
  706. validMatClick = "1",
  707. setCar = "",
  708. rfidCar = "",
  709. photoCar = "",
  710. scanCar = "",
  711. editCar = "",
  712. carErr = "0",
  713. wgtErr = "0",
  714. stopOverTime = "0",
  715. msgInfo = "",
  716. ledWriter = "",
  717. isOverWgt = "",
  718. isHelp = "0",
  719. wgt = 0
  720. });
  721. if (!rms.Succeed)
  722. {
  723. l.WriteLog(0, "frmMain.EventData异常754:写入信息异常");
  724. isLedWrite = true;
  725. }
  726. //*/
  727. }
  728. }
  729. #endregion
  730. }
  731. catch (Exception ex)
  732. {
  733. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  734. }
  735. }
  736. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  737. /// <summary>
  738. /// 操作Live表的数据:零点报警
  739. /// </summary>
  740. private void doOperateLive()
  741. {
  742. if (PbCache.collect_no == null)
  743. {
  744. return;
  745. }
  746. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  747. if (ll != null)
  748. {
  749. foreach (LiveData lv in ll)
  750. {
  751. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  752. {
  753. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  754. break;
  755. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  756. break;
  757. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  758. break;
  759. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  760. if (((lv.Value ?? "0") + "").Equals("1"))
  761. {
  762. doInsertZeroAlarm();
  763. PbCache.isZeroAlarm = true;
  764. }
  765. else
  766. {
  767. PbCache.isZeroAlarm = false;
  768. }
  769. break;
  770. }
  771. }
  772. }
  773. }
  774. /// <summary>
  775. /// 操作Live表的数据:零点报警
  776. /// </summary>
  777. private void doLive()
  778. {
  779. if (PbCache.collect_no == null)
  780. {
  781. return;
  782. }
  783. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  784. MeterWorkMonitor mwm = new MeterWorkMonitor();
  785. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  786. mwm.redGreenLightState = "0";
  787. if (ll != null)
  788. {
  789. foreach (LiveData lv in ll)
  790. {
  791. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  792. {
  793. case "PowerStatus":
  794. mwm.powerState = lv.Value.ToString();
  795. break;
  796. case "PlcWatchDog":
  797. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  798. {
  799. mwm.plcState = 0.ToString();
  800. }
  801. break;
  802. case "InfraredWest":
  803. if (lv.Value.ToString() == "2")
  804. {
  805. mwm.leftInfraredRayState = "0";
  806. }
  807. else
  808. {
  809. mwm.leftInfraredRayState = lv.Value.ToString();
  810. }
  811. break;
  812. case "InfraredEast":
  813. if (lv.Value.ToString() == "2")
  814. {
  815. mwm.rightInfraredRayState = "0";
  816. }
  817. else
  818. {
  819. mwm.rightInfraredRayState = lv.Value.ToString();
  820. }
  821. break;
  822. case "AmplifierState":
  823. mwm.amplifierState = lv.Value.ToString();
  824. break;
  825. case "LampState":
  826. mwm.lampState = lv.Value.ToString();
  827. break;
  828. case "InfraredLeft":
  829. if (lv.Value.ToString() == "2")
  830. {
  831. mwm.frontInfraredRayState = "0";
  832. }
  833. else
  834. {
  835. mwm.frontInfraredRayState = lv.Value.ToString();
  836. }
  837. break;
  838. case "InfraredRight":
  839. if (lv.Value.ToString() == "2")
  840. {
  841. mwm.rearInfraredRayState = "0";
  842. }
  843. else
  844. {
  845. mwm.rearInfraredRayState = lv.Value.ToString();
  846. }
  847. break;
  848. case "RfidState":
  849. mwm.rfidState = lv.Value.ToString();
  850. break;
  851. }
  852. }
  853. }
  854. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  855. }
  856. /// <summary>
  857. /// 新增零点报警的数据
  858. /// </summary>
  859. private void doInsertZeroAlarm()
  860. {
  861. if (!PbCache.isZeroAlarm)
  862. {
  863. PbCache.isZeroAlarm = true;
  864. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  865. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  866. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  867. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  868. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  869. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  870. workZeroAlarm.scalePointNo = PbCache.collect_no;
  871. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  872. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  873. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  874. if (rms.Succeed)
  875. {
  876. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight);
  877. }
  878. else
  879. {
  880. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  881. }
  882. }
  883. }
  884. /// <summary>
  885. /// 关闭程序
  886. /// </summary>
  887. /// <param name="sender"></param>
  888. /// <param name="e"></param>
  889. private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
  890. {
  891. collection.Stop();
  892. imageCurlControl.Stop();
  893. sweepCodeClass.CloseThread();
  894. timer1.Stop();
  895. timer1.Dispose();
  896. }
  897. public void WriteText(int iType, string str)
  898. {
  899. try
  900. {
  901. string strLogName = "";
  902. switch (iType)
  903. {
  904. case 0:
  905. strLogName = "车号采集_";
  906. break;
  907. case 1:
  908. strLogName = "判稳时间_";
  909. break;
  910. }
  911. string m_szRunPath;
  912. m_szRunPath = System.Environment.CurrentDirectory;
  913. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  914. {
  915. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  916. }
  917. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  918. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  919. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  920. {
  921. Directory.CreateDirectory(strPathFile);
  922. }
  923. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\" + strLogName + strDate + ".log", true);
  924. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  925. tw.WriteLine(str);
  926. tw.WriteLine("\r\n");
  927. tw.Close();
  928. }
  929. catch (Exception ex)
  930. {
  931. }
  932. }
  933. }
  934. }