fromContect.cs 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  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.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Windows.Forms;
  16. namespace CarMeterSystem
  17. {
  18. public partial class fromContect : Form
  19. {
  20. public fromContect()
  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. //历史皮操作
  52. private MeterBaseHisTareDataService hisTareDataService = new MeterBaseHisTareDataService();
  53. /// <summary>
  54. /// 欢迎界面
  55. /// </summary>
  56. private frmWelcome_Jisco frmWelcome = new frmWelcome_Jisco();//欢迎
  57. private int startCar = 0;
  58. private int startWeight = 0;
  59. private DateTime startTime;
  60. private DateTime endTime;
  61. /// <summary>
  62. /// 基础数据载入
  63. /// </summary>
  64. private BaseDbCls bd = new BaseDbCls();
  65. //扫码修正车号标识
  66. private bool codeFlag = false;
  67. private List<ucBusinessType> lu = new List<ucBusinessType>();
  68. private bool isVoiceDownCar = false;//车上人员请下车播放一次
  69. private bool isShowFrmWelcome = false; //是否显示欢迎界面
  70. private bool isOpened = false;//是否已经打开了扫码计量界面
  71. private void fromContect_Load(object sender, EventArgs e)
  72. {
  73. //*
  74. try
  75. {
  76. //this.Hide();
  77. LoginCls lg = new LoginCls();
  78. timer1.Start();
  79. //2021年6月21日 杨秀东添加
  80. if (isShowFrmWelcome)
  81. {
  82. frmWelcome.Show();
  83. frmWelcome.Visible = true;
  84. }
  85. if (lg.LoginIn())
  86. {
  87. if (bd.setBaseDb() && bd.getBaseDb())
  88. {
  89. if (!string.IsNullOrEmpty(PbCache.sportInfo.ledIp))
  90. {
  91. led_controler = new LED_Control(PbCache.sportInfo.ledIp);
  92. }
  93. //调用该方法时已赋值 test git 测试git推送代码123;456
  94. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  95. if (!rm.Succeed)
  96. {
  97. l.WriteLog(1, "载入监控表数据异常");
  98. return;
  99. }
  100. else if (rm.Data != null && rm.Data.Count > 0)
  101. {
  102. if (string.IsNullOrEmpty(PbCache.collect_no))
  103. {
  104. PbCache.collect_no = rm.Data[0].collectionCode;
  105. MemoClass = new MemoryTableDataSocket(PbCache.collect_no);
  106. }
  107. }
  108. else
  109. {
  110. l.WriteLog(1, "为配置监控数据");
  111. return;
  112. }
  113. //若未校秤的话,也不允许计量
  114. //载入界面业务按钮
  115. if (PbCache.businessType != null && PbCache.businessType.Count > 0)
  116. {
  117. foreach (ComBaseInfo info in PbCache.businessType)
  118. {
  119. ucBusinessType uc = new ucBusinessType();
  120. switch (info.baseCode)
  121. {
  122. case "001006003":
  123. uc.setControl(info.baseName, info.memo, info.baseCode);
  124. break;
  125. case "001006001":
  126. case "001006002":
  127. uc.setControl(info.baseName, info.memo, info.baseCode);
  128. break;
  129. default:
  130. uc.setControl(info.baseName, info.memo, info.baseCode);
  131. break;
  132. }
  133. uc.Dock = DockStyle.Top;
  134. //uc.setControl("","","",);
  135. uc.ucEvent += new EventHandler(ucEvents);
  136. lu.Add(uc);
  137. //panel7.Controls.Add(uc);
  138. }
  139. }
  140. //开启基础进程
  141. l.WriteLog(0, "系统登录成功");
  142. collection.EventDataCollectionArgs += new EventDataCollection(EventData);//数据采集及扫码信息
  143. collection.Start(PbCache.sportInfo.baseSpotNo, PbCache.sportInfo.baseSpotName);
  144. imageCurlControl.Start(); //图片上传线程
  145. sweepCodeClass.StartThreadSweep(); //扫码线程
  146. }
  147. else
  148. {
  149. l.WriteLog(0, "系统登录失败");
  150. }
  151. }
  152. else
  153. {
  154. l.WriteLog(0, "按IP地址找不到计量点信息,系统登录失败");
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. l.WriteLog(0, "系统加载失败:" + ex.Message);
  160. }
  161. //*/
  162. }
  163. /// <summary>
  164. /// 直接打开扫码计量界面
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void timer1_Tick(object sender, EventArgs e)
  169. {
  170. if (!isOpened && PbCache.collect?.weight > 500)
  171. {
  172. isOpened = true;
  173. PbCache.bussinessTypeName = "";
  174. PbCache.bussinessTypeCode = "";
  175. //frmOneYardToEnd fcc = new frmOneYardToEnd();
  176. //fcc.ShowDialog();
  177. }
  178. }
  179. #region
  180. //*
  181. /// <summary>
  182. /// 委托的方式调用控件的点击事件
  183. /// </summary>
  184. /// <param name="sender"></param>
  185. /// <param name="e"></param>
  186. public void ucEvents(object sender, EventArgs e)
  187. {
  188. Control control = (Control)sender;
  189. ucBusinessType um = control.Parent.Parent as ucBusinessType;
  190. try
  191. {
  192. switch (control.Name)
  193. {
  194. case "btnContext":
  195. case "btnPurchase":
  196. {
  197. PbCache.bussinessTypeName = um._bussiness == null ? "" : um._bussiness;
  198. PbCache.bussinessTypeCode = um._code;
  199. switch (um._code)
  200. {
  201. case "001006003":
  202. frmInternalTransport frm = new frmInternalTransport();
  203. frm.ShowDialog();
  204. break;
  205. /*
  206. case "001006001":
  207. case "001006002":
  208. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  209. frmCar.ShowDialog();
  210. break;
  211. //*/
  212. default:
  213. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  214. frmCar.ShowDialog();
  215. break;
  216. }
  217. };
  218. break;
  219. default: break;
  220. }
  221. }
  222. catch (Exception ex)
  223. {
  224. //MessageBox.Show("操作异常:" + ex.Message);
  225. }
  226. }
  227. //*/
  228. #endregion
  229. #region
  230. private void setThisVis(bool visb)
  231. {
  232. if (this.InvokeRequired)
  233. {
  234. Action<bool> action = new Action<bool>(setThisVis);
  235. Invoke(action, new object[] { visb });
  236. }
  237. else
  238. {
  239. if (this.Visible != visb)
  240. {
  241. this.Visible = visb;
  242. }
  243. }
  244. }
  245. #endregion
  246. #region
  247. private void setWelecomeVis(bool visb)
  248. {
  249. if (!isShowFrmWelcome) return;//2021年6月21日 杨秀东添加
  250. if (frmWelcome.InvokeRequired)
  251. {
  252. Action<bool> action = new Action<bool>(setWelecomeVis);
  253. Invoke(action, new object[] { visb });
  254. }
  255. else
  256. {
  257. if (frmWelcome.Visible != visb)
  258. {
  259. frmWelcome.Visible = visb;
  260. frmWelcome.setLogin();
  261. }
  262. }
  263. //*/
  264. }
  265. #endregion
  266. private int iCount = 0, iHodeTime = 0;
  267. private bool flagCarMonit = false;//车号修正
  268. private bool bEditCar = false; //手动修正车号
  269. private bool isOpenMeter = false; //是否已打开计量界面,若已经打开则这里关于超量程及红外的语音将停止播报
  270. private string firstCode = "";//上次扫码的信息
  271. private string ledTxt = "";
  272. private bool isLedWrite = false;//是否写入一次LED
  273. private string sPreNo = ""; //记录重量曲线变化
  274. private int preWgt = 0;//前一次重量,用于重量曲线
  275. private string sCarNo = "";
  276. private int iCountPark = 0;
  277. private string editCarNo = "";
  278. /// <summary>
  279. /// 数据采集
  280. /// </summary>
  281. /// <param name="o"></param>
  282. /// <param name="e"></param>
  283. private void EventData(object o, DataCollectionArgs e)
  284. {
  285. //这里每隔0.5秒执行一次
  286. try
  287. {
  288. #region 扫码信息
  289. sweepCodeClass.StrState = e.weightStatus + ""; //重量状态信息;当StrState= 0时,获取扫码信息,StrState= 2时将扫码信息置位“”空;其他状态不处理
  290. if (string.IsNullOrEmpty(sweepCodeClass.StrCode))
  291. {
  292. codeFlag = false;
  293. if (string.IsNullOrEmpty(PbCache.strCode))
  294. {
  295. firstCode = "";
  296. PbCache.strCode = "";
  297. //l.WriteLog(12, "主线程扫码值为空时清空;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode值为:" + PbCache.strCode);
  298. }
  299. }
  300. else
  301. {
  302. ////日期2021年12月22日:重复扫码,取前面12位
  303. //if (sweepCodeClass.StrCode.Length > 15)
  304. //{
  305. // // todo: 加入车号截取逻辑
  306. // sweepCodeClass.StrCode = sweepCodeClass.StrCode.Substring(0,12);
  307. //}
  308. //if (firstCode != sweepCodeClass.StrCode || string.IsNullOrEmpty(PbCache.strCode))
  309. //{
  310. // l.WriteLog(12, "主线程扫码值赋值;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode前值为:" + PbCache.strCode);
  311. // PbCache.strCode = sweepCodeClass.StrCode;
  312. // firstCode = PbCache.strCode;
  313. //}
  314. l.WriteLog(12, "测试扫码值" + PbCache.strCode);
  315. PbCache.collect.carno = sweepCodeClass.StrCode;
  316. codeFlag = true;
  317. }
  318. #endregion 扫码信息
  319. #region 秤上无车10分钟获取一次基础数据
  320. if (iCount < 1200)
  321. {
  322. iCount++;
  323. }
  324. else
  325. {
  326. try
  327. {
  328. //秤上没有车时,每隔10分钟获取一次基础数据
  329. if (e.weight < 500)
  330. {
  331. if (bd.setBaseDb())
  332. {
  333. l.WriteLog(0, "十分钟获取基础数据成功");
  334. }
  335. else
  336. {
  337. l.WriteLog(0, "十分钟获取基础数据失败");
  338. }
  339. iCount = 0;
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. l.WriteLog(0, "十分钟获取基础数据失败:" + ex.Message);
  345. iCount = 0;
  346. }
  347. }
  348. #endregion
  349. #region 每10秒写入一次当前时间
  350. if (iCount % 20 == 0)
  351. {
  352. //更新在线时间
  353. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo, lastTime = DateTime.Now });
  354. if (!rms.Succeed)
  355. {
  356. l.WriteLog(0, "frmMain.EventData异常:写入时间异常");
  357. }
  358. }
  359. #endregion
  360. #region
  361. //一旦界面锁定则不采集数据
  362. if (!PbCache.isLockFrm)
  363. {
  364. PbCache.collect.pointid = PbCache.sportInfo.baseSpotNo;
  365. PbCache.collect.weight = e.weight;
  366. PbCache.collect.weightStatus = e.weightStatus;
  367. PbCache.collect.parkStatus = e.parkStatus;
  368. PbCache.collect.datetime = e.datetime;
  369. PbCache.collect.licType = e.licType;
  370. }
  371. //*/
  372. // 更新监控表
  373. doLive();
  374. //重量大于500的情况下
  375. if (e.weight > 500)
  376. {
  377. if (startWeight == 0)
  378. {
  379. startTime = DateTime.Now;
  380. startWeight = 1;
  381. }
  382. if (startCar == 0 && e.vdioCarNos != "")
  383. {
  384. WriteText(0, "当前采集车号:" + e.vdioCarNos);
  385. startCar = 1;
  386. }
  387. if (startWeight == 1 && PbCache.collect.weightStatus == 0)
  388. {
  389. endTime = DateTime.Now;
  390. startWeight = 2;
  391. TimeSpan secondSpan = new TimeSpan(endTime.Ticks - startTime.Ticks);
  392. WriteText(1,"开始时间:"+ startTime.ToString("yyyy-MM-dd HH:mm:ss:fff") +",结束时间:"+ endTime.ToString("yyyy-MM-dd HH:mm:ss:fff") + ",时间差:"+ secondSpan.TotalSeconds +"秒" + ",重量:" + e.weight);
  393. }
  394. if (PbCache.dtStartTime == null)
  395. PbCache.dtStartTime = DateTime.Now;
  396. isLedWrite = true;
  397. #region 车上人员请下车
  398. try
  399. {
  400. //界面未锁定的情况下,有车号,如果重量稳定了,停车线验证通过,未超量程的情况下,则按钮可用
  401. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status && PbCache.collect.weight < PbCache.range.upperRange)
  402. {
  403. if (!isVoiceDownCar)
  404. {
  405. isVoiceDownCar = true;
  406. vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
  407. }
  408. }
  409. }
  410. catch { }
  411. #endregion
  412. setWelecomeVis(false);
  413. //每隔1秒刷一次计量实时监控表数据值
  414. if (iCount % 2 == 0)
  415. {
  416. //调用该方法时已赋值
  417. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  418. if (!rm.Succeed)
  419. {
  420. l.WriteLog(0, "frmMain.EventData异常419:" + rm.ResultMessage);
  421. }
  422. else
  423. {
  424. if (rm.Data != null && rm.Data.Count > 0)
  425. {
  426. PbCache.monitor = rm.Data[0];
  427. if (string.IsNullOrEmpty(PbCache.collect_no))
  428. {
  429. PbCache.collect_no = rm.Data[0].collectionCode;
  430. }
  431. if (ledTxt != rm.Data[0].ledWriter && rm.Data[0].ledWriter != "")
  432. {
  433. //调用LED信息写入******************************
  434. ledTxt = rm.Data[0].ledWriter;
  435. }
  436. if (string.IsNullOrEmpty(ledTxt))
  437. {
  438. ledTxt = "欢迎使用酒钢汽车衡智能计量系统!";
  439. }
  440. }
  441. }
  442. #region 2021-03-29
  443. #region 摄像头当前采集的车号与上次采集的不一样且当前未勾选不验证,且当前车号未进行手动修正的情况下
  444. if (preCarNo != e.carno && PbCache.monitor != null && PbCache.monitor.validCarno != "0" && !bEditCar)
  445. {
  446. flagCarMonit = false;
  447. }
  448. preCarNo = e.carno;
  449. #endregion
  450. if (!flagCarMonit)
  451. {
  452. sCarNo = e.carno;
  453. }
  454. //*
  455. //有车号,且重量稳定的情况下,只修正一次车号
  456. if (!string.IsNullOrEmpty(e.carno) && e.weightStatus == 0 && !flagCarMonit && PbCache.monitor != null && PbCache.monitor.carMonitor == "1" && PbCache.monitor.carMonitorLvl > 0)
  457. {
  458. flagCarMonit = true;
  459. string methods = "";
  460. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  461. {
  462. methods += "CarNoTrustCorrect" + i + ",";
  463. }
  464. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  465. sCarNo = editCarNo;
  466. //mwUpdate
  467. }
  468. //勾选了不验证车号的情况
  469. if (PbCache.monitor.validCarno == "0")
  470. {
  471. flagCarMonit = true;
  472. }
  473. #endregion
  474. #region 每隔1秒写入一次重量曲线
  475. try
  476. {
  477. if (preWgt != e.weight)
  478. {
  479. preWgt = e.weight;
  480. sPreNo = PbCache.sportInfo.baseSpotNo + DateTime.Now.ToString("yyyyMMddHHmmssfff");
  481. monitorWeightService.doAddWf(new MeterMonitorWeight
  482. {
  483. weightNo = sPreNo,
  484. baseSpotNo = PbCache.sportInfo.baseSpotNo,
  485. baseSpotName = PbCache.sportInfo.baseSpotName,
  486. collectWeight = e.weight + "",
  487. collectStartTime = PbCache.dtStartTime.Value,
  488. collectEndTime = DateTime.Now,
  489. spotTypeNo = "001002001",
  490. spotTypeName = "汽车衡",
  491. actualFirstNo = PbCache.actualFirstNo
  492. });
  493. }
  494. else
  495. {
  496. if (!string.IsNullOrEmpty(sPreNo))
  497. {
  498. monitorWeightService.doUpdateWf(new MeterMonitorWeight
  499. {
  500. weightNo = sPreNo,
  501. collectEndTime = DateTime.Now
  502. });
  503. }
  504. }
  505. }
  506. catch { }
  507. #endregion
  508. #region 停留超时
  509. iHodeTime++;
  510. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  511. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  512. mwUpdate.editCar = editCarNo;
  513. if (PbCache.holdTime != null && PbCache.holdTime.Count > 0)
  514. {
  515. if (PbCache.holdTime[0].retentionTime != null)
  516. {
  517. if (PbCache.holdTime[0].retentionTime.Value < iHodeTime)
  518. {
  519. PbCache.isOvertimeAlarm = true; //是否超时报警
  520. mwUpdate.stopOverTime = "1"; //写入一次停留超时
  521. //mwUpdate.isHelp = "1";//派位
  522. //mwUpdate.isTakeOver = "1";
  523. iHodeTime = 99999;//不再增长避免超出
  524. }
  525. }
  526. }
  527. #endregion
  528. #region RFID识别车号信息
  529. mwUpdate.rfidCar = "";
  530. mwUpdate.photoCar = e.vdioCarNos;
  531. //mwUpdate.photoCar = PbCache.collect.carno;
  532. if (!string.IsNullOrEmpty(e.RfidNos))
  533. {
  534. string sqls = @"SELECT RFID_ID id,CAR_NO text FROM METER_BASE_RFID_INFO where RFID_CODE = '" + e.RfidNos + "'";
  535. PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
  536. RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
  537. if (rmT.Data == null || rmT.Data.Count == 0)
  538. { }
  539. else
  540. {
  541. mwUpdate.rfidCar = rmT.Data[0].text;
  542. sCarNo = rmT.Data[0].text;
  543. }
  544. }
  545. #endregion
  546. #region 计量员修改的车号信息
  547. if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.setCar))
  548. {
  549. sCarNo = PbCache.monitor.setCar;
  550. bEditCar = true;
  551. flagCarMonit = true;
  552. codeFlag = false;
  553. sweepCodeClass.StrCode = "";
  554. }
  555. #endregion
  556. #region 重量信息
  557. if (!PbCache.isLockFrm)
  558. {
  559. mwUpdate.wgt = e.weight;
  560. }
  561. else
  562. {
  563. mwUpdate.wgt = Convert.ToInt32(PbCache.lockWgt);
  564. }
  565. #endregion
  566. #region 写入一次监控表,将重量/车号停留超时等信息写入
  567. mwUpdate.msgInfo = PbCache.ResultMessage;
  568. mwUpdate.weightStatus = PbCache.collect.weightStatus;
  569. //另外初始化一次监控数据
  570. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  571. if (!rms.Succeed)
  572. {
  573. l.WriteLog(0, "frmMain.EventData异常583:写入信息异常");
  574. }
  575. #endregion
  576. //验证对射
  577. valid.ValidMethod();
  578. if (!isOpenMeter)
  579. {
  580. //if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  581. if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  582. {
  583. //超量程
  584. vicPlayClass.GetVoicePlay("已超量程", e.carno);
  585. //return;
  586. }
  587. else if (e.weightStatus == 0)
  588. {
  589. if (!PbCache.monitorResult.valid_park_status)
  590. {
  591. iCountPark++;
  592. if (iCountPark > 9)
  593. {
  594. //重量稳定,且对射验证不合格
  595. vicPlayClass.GetVoicePlay("您的车辆未停到位", e.carno);
  596. //return;
  597. iCountPark = 0; //2021年7月27日5s播一次,然后重新在播
  598. }
  599. }
  600. else
  601. {
  602. iCountPark = 0;
  603. }
  604. }
  605. }
  606. if (!lu[0].bcEnable)
  607. {
  608. foreach (ucBusinessType uc in lu)
  609. {
  610. uc.setControlEnable(true);
  611. }
  612. }
  613. if (sweepCodeClass.StrCode == "" && !codeFlag)
  614. {
  615. PbCache.collect.carno = sCarNo;
  616. }
  617. }
  618. //写入LED信息
  619. //if (PbCache.sportInfo != null && PbCache.ledInfo != PbCache.OldLedInfo)
  620. //{
  621. // PbCache.OldLedInfo = PbCache.ledInfo;
  622. // if (PbCache.monitor != null && PbCache.monitor.ledKeep == "0")
  623. // {
  624. // //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  625. // }
  626. //}
  627. }
  628. else
  629. {
  630. startCar = 0;
  631. startWeight = 0;
  632. if (e.weight > 10 && e.weight < 500)
  633. {
  634. //重量小于500,大于10
  635. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  636. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  637. mwUpdate.wgt = e.weight;
  638. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  639. }
  640. if (e.weight > 0 && e.weight < 200)
  641. {
  642. doOperateLive();
  643. }
  644. if (e.weight == 0)
  645. {
  646. PbCache.isZeroAlarm = false;
  647. }
  648. isOpened = false; //下次上秤直接打开主界面
  649. editCarNo = "";
  650. firstCode = ""; //历史的扫码枪的值
  651. preCarNo = "";
  652. sCarNo = "";
  653. sPreNo = "";
  654. preWgt = 0;
  655. PbCache.isOvertimeAlarm = false; //是否超时报警
  656. PbCache.strCode = "";
  657. PbCache.ResultMessage = "";
  658. bEditCar = false;
  659. isVoiceDownCar = false;
  660. flagCarMonit = false;
  661. iHodeTime = 0;
  662. isOpenMeter = false;
  663. PbCache.isLockFrm = false;
  664. PbCache.dtStartTime = null;
  665. PbCache.voiceOver = true;
  666. if (PbCache.collect != null && !string.IsNullOrEmpty(PbCache.collect.carno))
  667. {
  668. PbCache.collect.carno = "";
  669. }
  670. setWelecomeVis(true);
  671. if (lu[0].bcEnable)
  672. {
  673. foreach (ucBusinessType uc in lu)
  674. {
  675. uc.setControlEnable(false);
  676. }
  677. }
  678. //LED写入
  679. if (isLedWrite)
  680. {
  681. if (PbCache.monitor == null || string.IsNullOrEmpty(PbCache.monitor.ledWriter))
  682. {
  683. PbCache.ledInfo = "欢迎使用九钢汽车衡智能计量系统";
  684. }
  685. else
  686. {
  687. PbCache.ledInfo = PbCache.monitor == null ? "" : PbCache.monitor.ledWriter;
  688. }
  689. //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  690. isLedWrite = false;
  691. //*
  692. //另外初始化一次监控数据
  693. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor
  694. {
  695. pointNo = PbCache.sportInfo.baseSpotNo,
  696. validWgt = "1",
  697. validCarno = "1",
  698. validTareTime = "1",
  699. validMatTime = "1",
  700. validTimeInterval = "1",
  701. validParkStatus = "1",
  702. validExceedWgt = "1",
  703. validPredictionDiff = "1",
  704. validLianda = "1",
  705. validMatClick = "1",
  706. setCar = "",
  707. rfidCar = "",
  708. photoCar = "",
  709. scanCar = "",
  710. editCar = "",
  711. carErr = "0",
  712. wgtErr = "0",
  713. stopOverTime = "0",
  714. msgInfo = "",
  715. ledWriter = "",
  716. isOverWgt = "",
  717. isHelp = "0",
  718. wgt = 0
  719. });
  720. if (!rms.Succeed)
  721. {
  722. l.WriteLog(0, "frmMain.EventData异常754:写入信息异常");
  723. isLedWrite = true;
  724. }
  725. //*/
  726. }
  727. }
  728. #endregion
  729. }
  730. catch (Exception ex)
  731. {
  732. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  733. }
  734. }
  735. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  736. /// <summary>
  737. /// 操作Live表的数据:零点报警
  738. /// </summary>
  739. private void doOperateLive()
  740. {
  741. if (PbCache.collect_no == null)
  742. {
  743. return;
  744. }
  745. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  746. if (ll != null)
  747. {
  748. foreach (LiveData lv in ll)
  749. {
  750. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  751. {
  752. case "StaticStatus"://
  753. // "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. }