fromContect.cs 43 KB

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