Form1.cs 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Diagnostics;
  14. using System.Drawing;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Windows.Forms;
  18. using SystemOffLine;
  19. namespace CarMeterSystem
  20. {
  21. public partial class Form1 : Form
  22. {
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. }
  27. private Log l = Log.GetInstance();
  28. private Print printClass = new Print();//打印
  29. //内存表
  30. private MemoryTableDataSocket MemoClass = new MemoryTableDataSocket("");
  31. //实时表数据采集
  32. private DataCollectionControl collection = new DataCollectionControl();
  33. //图片控制器含图片压缩及上传curl
  34. private ImageCurlControl imageCurlControl = new ImageCurlControl();
  35. //与监控界面对接的表
  36. private MeterWorkMonitorService meterWorkMonitor = new MeterWorkMonitorService();
  37. //零点报警表
  38. private meterworkzeroalarmservice zeroAlarmService = new meterworkzeroalarmservice();
  39. //车号修正
  40. private CarNoModfiy modfiy = new CarNoModfiy();
  41. //验证对射
  42. private validParkStatus valid = new validParkStatus();
  43. //语音播报
  44. private VoicePlay vicPlayClass = new VoicePlay();
  45. private LED_Control led_controler = null;
  46. //验证校秤数据
  47. private validCalibration vCalib = new validCalibration();
  48. private MeterWorkCarActualFirstService workCarActualFirstService = new MeterWorkCarActualFirstService(); //一次计量数据
  49. //查询当前是否校秤
  50. private bool bRelation = true;
  51. /// <summary>
  52. /// 欢迎界面
  53. /// </summary>
  54. private frmWelcome_Jisco frmWelcome = new frmWelcome_Jisco();//欢迎
  55. /// <summary>
  56. /// 计量页
  57. /// </summary>
  58. private frmOneYardToEnd fcc = null;
  59. /// <summary>
  60. /// 基础数据载入
  61. /// </summary>
  62. private BaseDbCls bd = new BaseDbCls();
  63. //扫码修正车号标识
  64. private bool codeFlag = false;
  65. private List<ucBusinessType> lu = new List<ucBusinessType>();
  66. private bool isVoiceDownCar = false;//车上人员请下车播放一次
  67. private bool isShowFrmWelcome = false; //是否显示欢迎界面;在这个测试界面,不显示欢迎界面
  68. private bool isOpened = false;//是否已经打开了扫码计量界面
  69. private SerialPortES sweepCodeClass = new SerialPortES();
  70. private SerialPortES sweepCodeClass2 = new SerialPortES();
  71. private void Form1_Load(object sender, EventArgs e)
  72. {
  73. //*
  74. try
  75. {
  76. //CollectModel temp = new CollectModel();
  77. //temp.weight = 501;
  78. //PbCache.collect = temp;
  79. //frmMatMsgInfo frmMatMsgInfo = new frmMatMsgInfo();
  80. //frmMatMsgInfo.Show();
  81. timer1.Start();
  82. //2021年6月21日 杨秀东添加
  83. if (isShowFrmWelcome)
  84. {
  85. frmWelcome.Show();
  86. frmWelcome.Visible = true;
  87. }
  88. LoginCls lg = new LoginCls();
  89. if (lg.LoginIn())
  90. {
  91. //if (SystemUpdate(false))
  92. //{
  93. // return;
  94. //}
  95. // 加载并验证基本配置
  96. if (bd.setBaseDb() && bd.getBaseDb())
  97. {
  98. if (!string.IsNullOrEmpty(PbCache.sportInfo.ledIp))
  99. {
  100. led_controler = new LED_Control(PbCache.sportInfo.ledIp);
  101. }
  102. //调用该方法时已赋值
  103. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  104. if (!rm.Succeed)
  105. {
  106. l.WriteLog(1, "载入监控表数据异常");
  107. return;
  108. }
  109. else if (rm.Data != null && rm.Data.Count > 0)
  110. {
  111. if (string.IsNullOrEmpty(PbCache.collect_no))
  112. {
  113. PbCache.collect_no = rm.Data[0].collectionCode;
  114. MemoClass = new MemoryTableDataSocket(PbCache.collect_no);
  115. }
  116. }
  117. else
  118. {
  119. //l.WriteLog(1, "为配置监控数据");
  120. //return;
  121. }
  122. //若未校秤的话,也不允许计量
  123. //载入界面业务按钮
  124. if (PbCache.businessType != null && PbCache.businessType.Count > 0)
  125. {
  126. foreach (ComBaseInfo info in PbCache.businessType)
  127. {
  128. ucBusinessType uc = new ucBusinessType();
  129. switch (info.baseCode)
  130. {
  131. case "001006003":
  132. uc.setControl(info.baseName, info.memo, info.baseCode);
  133. break;
  134. case "001006001":
  135. case "001006002":
  136. uc.setControl(info.baseName, info.memo, info.baseCode);
  137. break;
  138. default:
  139. uc.setControl(info.baseName, info.memo, info.baseCode);
  140. break;
  141. }
  142. uc.Dock = DockStyle.Top;
  143. //uc.setControl("","","",);
  144. uc.ucEvent += new EventHandler(ucEvents);
  145. lu.Add(uc);
  146. panel7.Controls.Add(uc);
  147. }
  148. }
  149. //开启基础进程
  150. l.WriteLog(0, "系统登录成功");
  151. collection.EventDataCollectionArgs += new EventDataCollection(EventData);//数据采集
  152. collection.Start(PbCache.sportInfo.baseSpotNo, PbCache.sportInfo.baseSpotName);
  153. imageCurlControl.Start(); //图片采集线程
  154. //新扫码线程
  155. if (AppConfigCache._comPara?.Split(new char[] { ',' })?.Length == 5)
  156. {
  157. sweepCodeClass.StartThreadSweep(AppConfigCache._comPara); //扫码线程
  158. }
  159. if (AppConfigCache._comPara2?.Split(new char[] { ',' })?.Length == 5)
  160. {
  161. sweepCodeClass2.StartThreadSweep(AppConfigCache._comPara2); //扫码线程
  162. }
  163. // 计量页
  164. fcc = new frmOneYardToEnd();
  165. }
  166. else
  167. {
  168. l.WriteLog(0, "系统登录失败");
  169. }
  170. }
  171. else
  172. {
  173. l.WriteLog(0, "按IP地址找不到计量点信息,系统登录失败");
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. l.WriteLog(0, "系统加载失败:" + ex.Message);
  179. }
  180. //*/
  181. }
  182. #region
  183. //*
  184. public void ucEvents(object sender, EventArgs e)
  185. {
  186. Control control = (Control)sender;
  187. ucBusinessType um = control.Parent.Parent as ucBusinessType;
  188. try
  189. {
  190. switch (control.Name)
  191. {
  192. case "btnContext":
  193. case "btnPurchase":
  194. {
  195. PbCache.bussinessTypeName = um._bussiness == null ? "" : um._bussiness;
  196. PbCache.bussinessTypeCode = um._code;
  197. switch (um._code)
  198. {
  199. case "001006003":
  200. frmInternalTransport frm = new frmInternalTransport();
  201. frm.isTest = true;
  202. frm.ShowDialog();
  203. break;
  204. /*
  205. case "001006001":
  206. case "001006002":
  207. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  208. frmCar.ShowDialog();
  209. break;
  210. //*/
  211. default:
  212. frmCarSalePurchase frmCar = new frmCarSalePurchase();
  213. frmCar.isTest = true;
  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 setWelecomeVis(bool visb)
  231. {
  232. /*
  233. if (frmWelcome.InvokeRequired)
  234. {
  235. Action<bool> action = new Action<bool>(setWelecomeVis);
  236. Invoke(action, new object[] { visb });
  237. }
  238. else
  239. {
  240. if (frmWelcome.Visible != visb)
  241. {
  242. frmWelcome.Visible = visb;
  243. frmWelcome.setLogin();
  244. }
  245. }
  246. //*/
  247. }
  248. #endregion
  249. private int iCount = 0, iHodeTime = 0;
  250. private bool flagCarMonit = false;//车号修正
  251. private bool isOpenMeter = false; //是否已打开计量界面,若已经打开则这里关于超量程及红外的语音将停止播报
  252. private string firstCode = "";//上次扫码的信息
  253. private string ledTxt = "";
  254. private bool isLedWrite = true;//是否写入一次LED
  255. private string sCarNo = "";
  256. private string editCarNo = "";
  257. private string preCarNo = "";
  258. MeterWorkCarActualFirstService mwcfs = new MeterWorkCarActualFirstService();
  259. RESTfulResult<string> rmsSweepCodeClass = new RESTfulResult<string>();
  260. /// <summary>
  261. /// 数据采集
  262. /// </summary>
  263. /// <param name="o"></param>
  264. /// <param name="e"></param>
  265. private void EventData(object o, DataCollectionArgs e)
  266. {
  267. //这里每隔0.5秒执行一次
  268. try
  269. {
  270. #region
  271. /*
  272. if (e.licType == PbCache.collect.licType)
  273. {
  274. iCollection++;
  275. if (iCollection > 59 && iCollection % 20 == 0) //若连续30秒采集不到数据则提示中断,并每隔10秒播放一次
  276. {
  277. //采集线程中断
  278. vicPlayClass.GetVoicePlay("实时库采集中断", "");
  279. sweepCodeClass.StrState = "";
  280. }
  281. }
  282. else
  283. {
  284. sweepCodeClass.StrState = e.weightStatus + "";
  285. iCollection = 0;
  286. }
  287. //*/
  288. #endregion
  289. #region 扫码信息
  290. if (!string.IsNullOrEmpty(sweepCodeClass2.StrCode))
  291. {
  292. Console.WriteLine("code:"+sweepCodeClass2.StrCode);
  293. }
  294. // 司机扫码为空,取工控机二维码
  295. if (string.IsNullOrEmpty(sweepCodeClass2.StrCode))
  296. {
  297. if (string.IsNullOrEmpty(sweepCodeClass.StrCode))
  298. {
  299. if (string.IsNullOrEmpty(PbCache.strCode))
  300. {
  301. codeFlag = false;
  302. firstCode = "";
  303. PbCache.strCode = "";
  304. l.WriteLog(12, "主线程扫码值为空时清空;sweepCodeClass.StrCode值为" + sweepCodeClass.StrCode + " ;PbCache.strCode值为:" + PbCache.strCode);
  305. }
  306. }
  307. else
  308. {
  309. DecodeQRCode(sweepCodeClass.StrCode);
  310. }
  311. }
  312. else
  313. {
  314. DecodeQRCode(sweepCodeClass2.StrCode);
  315. }
  316. #endregion
  317. #region 秤上无车10分钟获取一次基础数据
  318. if (iCount < 1200)
  319. {
  320. iCount++;
  321. }
  322. else
  323. {
  324. iCount = 0;
  325. try
  326. {
  327. //秤上没有车时,每隔10分钟获取一次基础数据
  328. if (e.weight < 500)
  329. {
  330. editCarNo = "";
  331. preCarNo = "";
  332. if (bd.setBaseDb())
  333. {
  334. l.WriteLog(0, "十分钟获取基础数据成功");
  335. }
  336. else
  337. {
  338. l.WriteLog(0, "十分钟获取基础数据失败");
  339. }
  340. }
  341. }
  342. catch (Exception ex)
  343. {
  344. l.WriteLog(0, "十分钟获取基础数据失败:" + ex.Message);
  345. }
  346. }
  347. #endregion
  348. #region 每10秒写入一次当前时间
  349. if (iCount % 20 == 0)
  350. {
  351. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWfBySpotNo(new MeterWorkMonitor { pointNo = PbCache.sportInfo.baseSpotNo });
  352. if (!rms.Succeed)
  353. {
  354. l.WriteLog(0, "frmMain.EventData异常:写入时间异常");
  355. }
  356. }
  357. #endregion
  358. #region
  359. //一旦界面锁定则不采集数据
  360. //if (!PbCache.isLockFrm)
  361. //{
  362. PbCache.collect.pointid = PbCache.sportInfo.baseSpotNo;
  363. PbCache.collect.parkStatus = e.parkStatus;
  364. PbCache.collect.datetime = e.datetime;
  365. PbCache.collect.licType = e.licType;
  366. if (testFlag)
  367. {
  368. sCarNo = testCarNo;
  369. //PbCache.collect.carno = testCarNo;
  370. PbCache.collect.weight = testWgt;
  371. PbCache.collect.weightStatus = 0;
  372. PbCache.monitorResult.valid_park_status = true;
  373. PbCache.collect.parkStatus = 0;
  374. if (PbCache.collect.weight > e.weight)
  375. e.weight = PbCache.collect.weight;
  376. PbCache.strCode = testPlanNo;
  377. e.carno = testCarNo;
  378. //PbCache.strQRCode = testCode;
  379. }
  380. else
  381. {
  382. PbCache.collect.weight = e.weight;
  383. PbCache.collect.weightStatus = e.weightStatus;
  384. }
  385. if (!flagCarMonit)
  386. {
  387. sCarNo = e.carno;
  388. //PbCache.collect.carno = e.carno;
  389. }
  390. #if DEBUG
  391. #endif
  392. #region 摄像头当前采集的车号与上次采集的不一样且当前未勾选不验证的情况
  393. if (preCarNo != e.carno && PbCache.monitor != null && PbCache.monitor.validCarno != "0")
  394. {
  395. flagCarMonit = false;
  396. }
  397. preCarNo = e.carno;
  398. #endregion
  399. //*
  400. //有车号,且重量稳定的情况下,只修正一次车号
  401. if (!string.IsNullOrEmpty(e.carno) && e.weightStatus == 0 && !flagCarMonit && PbCache.monitor != null && PbCache.monitor.carMonitor == "1" && PbCache.monitor.carMonitorLvl > 0)
  402. {
  403. flagCarMonit = true;
  404. string methods = "";
  405. for (int i = 0; i <= PbCache.monitor.carMonitorLvl; i++)
  406. {
  407. methods += "CarNoTrustCorrect" + i + ",";
  408. }
  409. editCarNo = modfiy.CarNoCorrect(e.carno, methods.Substring(0, methods.Length - 1));
  410. sCarNo = editCarNo;
  411. }
  412. //勾选了不验证车号的情况
  413. if (PbCache.monitor.validCarno == "0")
  414. {
  415. flagCarMonit = true;
  416. }
  417. // 更新监控表
  418. doLive();
  419. //}
  420. //*/
  421. //重量大于500的情况下
  422. if (e.weight > 500)
  423. {
  424. if (PbCache.dtStartTime == null)
  425. PbCache.dtStartTime = DateTime.Now;
  426. isLedWrite = true;
  427. PbCache.strState = "0";
  428. #region 查一次是否校秤,若未校秤则不能计量
  429. /*
  430. if (bRelation)
  431. {
  432. string msgInfo = "";
  433. isCalibration = vCalib.ValidMethod(new MeterWorkCalibrationMain { baseSpotNo = PbCache.sportInfo.baseSpotNo, valueFlag = "2" }, out msgInfo);
  434. if (!isCalibration)
  435. {
  436. foreach (ucBusinessType uc in lu)
  437. {
  438. uc.setControlEnable(false);
  439. }
  440. ledTxt = msgInfo;
  441. l.WriteLog(1, msgInfo);
  442. }
  443. bRelation = false;
  444. }
  445. if (!isCalibration)
  446. {
  447. vicPlayClass.GetVoicePlay("未校秤", "");
  448. Thread.Sleep(2000);
  449. return;
  450. }
  451. //*/
  452. #endregion
  453. #region 车上人员请下车
  454. try
  455. {
  456. //界面未锁定的情况下,有车号,如果重量稳定了,停车线验证通过,未超量程的情况下,则按钮可用
  457. if (!string.IsNullOrEmpty(PbCache.collect.carno) && PbCache.collect.weightStatus == 0 && PbCache.monitorResult.valid_park_status && PbCache.collect.weight < PbCache.range.upperRange)
  458. {
  459. if (!isVoiceDownCar)
  460. {
  461. isVoiceDownCar = true;
  462. vicPlayClass.GetVoicePlay("车上人员请下车", PbCache.collect.carno);
  463. }
  464. }
  465. }
  466. catch { }
  467. #endregion
  468. setWelecomeVis(false);
  469. //每隔1秒刷一次计量实时监控表数据值
  470. if (iCount % 2 == 0)
  471. {
  472. #region 停留超时
  473. iHodeTime++;
  474. MeterWorkMonitor mwUpdate = new MeterWorkMonitor();
  475. mwUpdate.pointNo = PbCache.sportInfo.baseSpotNo;
  476. if (PbCache.holdTime != null && PbCache.holdTime.Count > 0)
  477. {
  478. if (PbCache.holdTime[0].retentionTime != null)
  479. {
  480. if (PbCache.holdTime[0].retentionTime.Value < iHodeTime)
  481. {
  482. PbCache.isOvertimeAlarm = true; //是否超时报警
  483. mwUpdate.stopOverTime = "1"; //写入一次停留超时
  484. //mwUpdate.isHelp = "1";//派位
  485. //mwUpdate.isTakeOver = "1";
  486. iHodeTime = 99999;//不再增长避免超出
  487. }
  488. }
  489. }
  490. #endregion
  491. #region 车号信息
  492. mwUpdate.rfidCar = "";
  493. mwUpdate.photoCar = e.vdioCarNos;
  494. if (testFlag)
  495. {
  496. mwUpdate.photoCar = PbCache.collect.carno;
  497. }
  498. //e.RfidNos = "0003";
  499. if (!string.IsNullOrEmpty(e.RfidNos))
  500. {
  501. string sqls = @"SELECT RFID_ID id,CAR_NO text FROM METER_BASE_RFID_INFO where RFID_CODE = '" + e.RfidNos + "'";
  502. PbModelDbService<List<PbModelDb>> pbp = new PbModelDbService<List<PbModelDb>>();
  503. RESTfulResult<List<PbModelDb>> rmT = pbp.executeSqlDataWf(sqls);
  504. if (rmT.Data == null || rmT.Data.Count == 0)
  505. {}
  506. else
  507. {
  508. mwUpdate.rfidCar = rmT.Data[0].text;
  509. sCarNo = rmT.Data[0].text;
  510. }
  511. }
  512. if (PbCache.monitor != null && !string.IsNullOrEmpty(PbCache.monitor.setCar))
  513. {
  514. //未锁定的情况下,若监控界面设置了车号,则车号将改为设定车号
  515. sCarNo = PbCache.monitor.setCar;
  516. codeFlag = false;
  517. sweepCodeClass.StrCode = "";
  518. sweepCodeClass2.StrCode = "";
  519. }
  520. #endregion
  521. #region 重量信息
  522. if (!PbCache.isLockFrm)
  523. {
  524. mwUpdate.wgt = e.weight;
  525. }
  526. else
  527. {
  528. mwUpdate.wgt = Convert.ToInt32(PbCache.lockWgt);
  529. }
  530. #endregion
  531. #region 写入一次监控表,将重量/车号停留超时等信息写入
  532. mwUpdate.weightStatus = PbCache.collect.weightStatus;
  533. mwUpdate.msgInfo = PbCache.ResultMessage;
  534. if (codeFlag)
  535. {
  536. mwUpdate.scanCar = PbCache.collect.carno;
  537. }
  538. //另外初始化一次监控数据
  539. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwUpdate);
  540. if (!rms.Succeed)
  541. {
  542. l.WriteLog(0, "frmMain.EventData异常doUpdateWf:写入信息异常");
  543. }
  544. #endregion
  545. //调用该方法时已赋值
  546. RESTfulResult<List<MeterWorkMonitor>> rm = meterWorkMonitor.doQueryOneWf(new MeterWorkMonitor { validFlag = "1", pointNo = PbCache.sportInfo.baseSpotNo });
  547. if (!rm.Succeed)
  548. {
  549. l.WriteLog(0, "frmMain.EventData异常doQueryWf:" + rm.ResultMessage);
  550. }
  551. else
  552. {
  553. if (rm.Data != null && rm.Data.Count > 0)
  554. {
  555. PbCache.monitor = rm.Data[0];
  556. if (string.IsNullOrEmpty(PbCache.collect_no))
  557. {
  558. PbCache.collect_no = rm.Data[0].collectionCode;
  559. }
  560. if (ledTxt != rm.Data[0].ledWriter && rm.Data[0].ledWriter != "")
  561. {
  562. //调用LED信息写入******************************
  563. ledTxt = rm.Data[0].ledWriter;
  564. }
  565. if (string.IsNullOrEmpty(ledTxt))
  566. {
  567. ledTxt = "车号甘A12345,重量98.76吨,计量完成";
  568. }
  569. }
  570. }
  571. //验证对射
  572. valid.ValidMethod();
  573. if (!isOpenMeter)
  574. {
  575. //if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  576. if (PbCache.range != null && PbCache.range.upperRange < e.weight)
  577. {
  578. //超量程
  579. vicPlayClass.GetVoicePlay("已超量程", e.carno);
  580. //return;
  581. }
  582. else if (e.weightStatus == 0 && !PbCache.monitorResult.valid_park_status)
  583. {
  584. //重量稳定,且对射验证不合格
  585. vicPlayClass.GetVoicePlay("您的车辆未停到位", e.carno);
  586. //return;
  587. }
  588. }
  589. if (!lu[0].bcEnable)
  590. {
  591. foreach (ucBusinessType uc in lu)
  592. {
  593. uc.setControlEnable(true);
  594. }
  595. }
  596. if ((sweepCodeClass.StrCode == "" || sweepCodeClass2.StrCode == "") && !codeFlag)
  597. {
  598. PbCache.collect.carno = sCarNo;
  599. }
  600. }
  601. ////写入LED信息
  602. //if (PbCache.sportInfo != null && PbCache.ledInfo != PbCache.OldLedInfo)
  603. //{
  604. // PbCache.OldLedInfo = PbCache.ledInfo;
  605. // if (PbCache.monitor != null && PbCache.monitor.ledKeep == "0")
  606. // {
  607. // //led_controler.setOneLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  608. // }
  609. //}
  610. }
  611. else
  612. {
  613. if (e.weight > 0 && e.weight < 200)
  614. {
  615. doOperateLive();
  616. }
  617. if (e.weight==0)
  618. {
  619. PbCache.isZeroAlarm = false;
  620. }
  621. //======测试 的时候注释,正式用的时候启用下面这行代码***************************************************************
  622. //PbCache.ResultMessage = "";
  623. PbCache.isOvertimeAlarm = false;
  624. isOpened = false;
  625. isVoiceDownCar = false;
  626. flagCarMonit = false;
  627. iHodeTime = 0;
  628. sCarNo = "";
  629. if (!testFlag)
  630. {
  631. bRelation = true;
  632. PbCache.isLockFrm = false;
  633. PbCache.dtStartTime = null;
  634. PbCache.voiceOver = true;
  635. setWelecomeVis(true);
  636. if (lu[0].bcEnable)
  637. {
  638. foreach (ucBusinessType uc in lu)
  639. {
  640. uc.setControlEnable(false);
  641. }
  642. }
  643. //LED写入
  644. if (isLedWrite)
  645. {
  646. //if (PbCache.monitor == null || string.IsNullOrEmpty(PbCache.monitor.ledWriter))
  647. //{
  648. // PbCache.ledInfo = "车号甘A12345\n\r重量98.76吨\n\r之前存在一个未结净的毛重\n\r请联系";
  649. //}
  650. //else
  651. //{
  652. // PbCache.ledInfo = PbCache.monitor == null ? "" : PbCache.monitor.ledWriter;
  653. //}
  654. //led_controler.setStaticLineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  655. //led_controler.setStatic4LineMsg(PbCache.sportInfo.ledIp, PbCache.ledInfo);
  656. isLedWrite = false;
  657. //*
  658. //另外初始化一次监控数据
  659. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(new MeterWorkMonitor
  660. {
  661. pointNo = PbCache.sportInfo.baseSpotNo,
  662. validWgt = "1",
  663. validCarno = "1",
  664. validTareTime = "1",
  665. validMatTime = "1",
  666. validTimeInterval = "1",
  667. validParkStatus = "1",
  668. validExceedWgt = "1",
  669. validPredictionDiff = "1",
  670. validLianda = "1",
  671. validMatClick = "1",
  672. setCar = "",
  673. rfidCar = "",
  674. photoCar = "",
  675. scanCar = "",
  676. editCar = "",
  677. carErr = "0",
  678. wgtErr = "0",
  679. ferroalloyResult = "0",
  680. stopOverTime = "0",
  681. msgInfo = "",
  682. ledWriter = "",
  683. isOverWgt = "",
  684. isHelp = "0",
  685. wgt = 0
  686. });
  687. if (!rms.Succeed)
  688. {
  689. l.WriteLog(0, "frmMain.EventData异常:写入信息异常");
  690. isLedWrite = true;
  691. }
  692. //*/
  693. }
  694. //*
  695. }
  696. else
  697. {
  698. if (!lu[0].bcEnable)
  699. {
  700. foreach (ucBusinessType uc in lu)
  701. {
  702. uc.setControlEnable(true);
  703. }
  704. }
  705. }
  706. //*/
  707. }
  708. #endregion
  709. }
  710. catch (Exception ex)
  711. {
  712. l.WriteLog(0, "frmMain.EventData异常:" + ex.Message);
  713. }
  714. }
  715. private void DecodeQRCode(string strCode)
  716. {
  717. codeFlag = true;
  718. frmOneYardToEnd frmOneYardToEnd = new frmOneYardToEnd();
  719. Hashtable hashTable = new Hashtable();
  720. hashTable.Add("message", strCode);
  721. rmsSweepCodeClass = mwcfs.DecryptionForWfTest(hashTable);
  722. if (rmsSweepCodeClass.Code == "0")
  723. {
  724. PbCache.collect.carno = rmsSweepCodeClass.Data;
  725. PbCache.strCode = rmsSweepCodeClass.Data;
  726. }
  727. if (rmsSweepCodeClass.Code == "1")
  728. {
  729. vicPlayClass.GetVoicePlay("车号二维码已过期", PbCache.collect.carno);
  730. frmOneYardToEnd.setMsgInfo("车号二维码已过期");
  731. }
  732. if (rmsSweepCodeClass.Code == "2")
  733. {
  734. vicPlayClass.GetVoicePlay("不是有效车号二维码", PbCache.collect.carno);
  735. frmOneYardToEnd.setMsgInfo("不是有效车号二维码");
  736. }
  737. if (rmsSweepCodeClass.Code == "9")
  738. {
  739. vicPlayClass.GetVoicePlay("不是有效车号二维码", PbCache.collect.carno);
  740. frmOneYardToEnd.setMsgInfo("不是有效车号二维码");
  741. }
  742. l.WriteLog(12, "测试扫码值" + rmsSweepCodeClass.Data);
  743. }
  744. private delegate void ShowBtnTare(bool flag);//定义委托 期限皮重按钮
  745. private int testWgt = 1000;
  746. private string testCarNo = "", testPlanNo = "";
  747. private bool testFlag = false;
  748. /// <summary>
  749. /// 截图测试
  750. /// </summary>
  751. /// <param name="sender"></param>
  752. /// <param name="e"></param>
  753. private void button2_Click(object sender, EventArgs e)
  754. {
  755. CameraShotCls cameraShot = new CameraShotCls();
  756. //cameraShot.CapMethod("1");
  757. _ = Invoke(new Action(() => { cameraShot.CapMethod("15"); }));
  758. }
  759. //测试打印
  760. private string strFirstNo = "";
  761. private void btnTestPrint_Click(object sender, EventArgs e)
  762. {
  763. Print1(txtPlanNo.Text);
  764. }
  765. //弹窗
  766. private static FrmMessage FrmMess(string strMess, string strBtnSaveInfo)
  767. {
  768. FrmMessage frmMessage = new FrmMessage();
  769. frmMessage.StartPosition = FormStartPosition.Manual;
  770. frmMessage.Location = new Point(350, 450);
  771. frmMessage.ShowMessage = strMess;
  772. frmMessage.BtnSaveText = strBtnSaveInfo;
  773. frmMessage.BtnCancelText = "取消";
  774. return frmMessage;
  775. }
  776. private class PrintCls
  777. {
  778. public int printNum { get; set; }
  779. public MeterWorkCarActual printDb { get; set; }
  780. public int iType { get; set; } //0毛 1 皮 2净
  781. public string qrCode { get; set; }
  782. }
  783. private PrintCls printData = new PrintCls();
  784. private void Print1(string firstNo)
  785. {
  786. try
  787. {
  788. //lg.WriteLog(1, "打印开始");
  789. #region 获取打印信息,若需要打印则调用打印操作
  790. List<PrintCls> prrintC = new List<PrintCls>();
  791. string sql = @"select actual_no actualNo,
  792. prediction_no predictionNo,
  793. car_no carNo,
  794. matter_no matterNo,
  795. matter_name matterName,
  796. gross_weight grossWeight,
  797. gross_time grossTime,
  798. tare_weight tareWeight,
  799. tare_time tareTime,
  800. net_weight netWeight,
  801. net_Time netTime,
  802. 'x' meterTypeNo,
  803. meter_type_name meterTypeName,
  804. spec_name specName,
  805. forwarding_unit_name forwardingUnitName,
  806. receiving_uint_name receivingUintName,
  807. load_point_name loadPointName,
  808. add_weight addWeight,
  809. '1' uploadFlag --1结净数据 0一次表数据
  810. from meter_work_car_actual where actual_first1_no = '" + firstNo + @"' or actual_first2_no='" + firstNo + @"'
  811. union all
  812. select t.actual_first_no actualNo,
  813. t.prediction_no predictionNo,
  814. t.car_no carNo,
  815. t.matter_no matterNo,
  816. t.matter_name matterName,
  817. t.meter_weight grossWeight,
  818. t.create_time grossTime,
  819. 0 tareWeight,
  820. t.create_time tareTime,
  821. 0 netWeight,
  822. null netTime,
  823. t.weight_type meterTypeNo, --0毛重 否则皮重
  824. t.meter_type_name meterTypeName,
  825. t.spec_name specName,
  826. t.forwarding_unit_name forwardingUnitName,
  827. t.receiving_uint_name receivingUintName,
  828. t.load_point_name loadPointName,
  829. t.add_weight addWeight,
  830. '0' uploadFlag
  831. from METER_WORK_CAR_ACTUAL_FIRST t
  832. where t.actual_first_no = '" + firstNo + "' or t.actual_first_no = (select max(actual_first2_no) from meter_work_car_actual where actual_first1_no='" + firstNo + "')";
  833. //查下如果有毛重或者结净数据,则可进入打印判断
  834. PbModelDbService<List<MeterWorkCarActual>> pbModelDbService = new PbModelDbService<List<MeterWorkCarActual>>();
  835. RESTfulResult<List<MeterWorkCarActual>> rm = pbModelDbService.executeSqlDataWf(sql);
  836. //lg.WriteLog(1, "打印第一个sql:" + sql);
  837. if (rm.Succeed)
  838. {
  839. if (rm.Data != null && rm.Data.Count > 0)
  840. {
  841. //2021年6月26日 对一车联运的进行处理;用一次计量编号查二次计量数据,
  842. sql = @"select t3.actual_no actualNo, t3.prediction_no predictionNo, t3.car_no carNo, t3.matter_no matterNo, t3.matter_name matterName,
  843. t3.gross_weight grossWeight, t3.gross_time grossTime, t3.tare_weight tareWeight, t3.tare_time tareTime, t3.net_weight netWeight,
  844. t3.net_Time netTime, 'x' meterTypeNo, t3.meter_type_name meterTypeName, t3.spec_name specName,
  845. t3.forwarding_unit_name forwardingUnitName, t3.receiving_uint_name receivingUintName, t3.load_point_name loadPointName,
  846. t3.add_weight addWeight, '1' uploadFlag from meter_work_car_actual_first t2
  847. left join meter_work_car_actual t3 on t2.actual_first_no = t3.actual_first1_no
  848. where t2.prediction_combination in (select t.prediction_combination
  849. from meter_work_car_actual_first t
  850. where t3.value_flag = '0' and t.actual_first_no = '" + firstNo + @"' and
  851. instr(t.prediction_combination, '20') > 0) order by t3.net_time desc";
  852. RESTfulResult<List<MeterWorkCarActual>> rmLy = pbModelDbService.executeSqlDataWf(sql);
  853. if (rmLy.Succeed && rmLy.Data != null && rmLy.Data.Count == 1)
  854. {
  855. rm.Data = rmLy.Data; //一车联运,将毛重替换为净重数据
  856. }
  857. //若有毛重或者净重,找到对应数据的物料信息,若有,那么去找打印配置信息数据
  858. List<MeterWorkCarActual> mwa = rm.Data.Where(s => !string.IsNullOrEmpty(s.matterNo) && (s.meterTypeNo == "x" || s.meterTypeNo == "0")).ToList();
  859. if (mwa != null && mwa.Count > 0 && !string.IsNullOrEmpty(mwa[0].matterNo))
  860. {
  861. sql = @"select BASE_SPOT_NO baseSpotNo,
  862. load_point_no loadPointNo,
  863. matter_no matterNo,
  864. METER_TYPE_NO meterTypeNo,
  865. weight_type_name weightTypeName,
  866. PRINT_NUM printNum
  867. from METER_BASE_BILL_PRINT
  868. where matter_no = '" + mwa[0].matterNo + @"'
  869. and nvl(BASE_SPOT_NO, '" + PbCache.sportInfo.baseSpotNo + @"') = '" + PbCache.sportInfo.baseSpotNo + @"'
  870. and nvl(load_point_no, '" + (mwa[0].loadPointNo == null ? "1" : mwa[0].loadPointNo) + @"') = '" + (mwa[0].loadPointNo == null ? "1" : mwa[0].loadPointNo) + @"'";
  871. //lg.WriteLog(1, "打印第二个sql:" + sql); and nvl(METER_TYPE_NO, '" + PbCache.bussinessTypeCode + @"') = '" + PbCache.bussinessTypeCode + @"'
  872. //and nvl(METER_TYPE_NO, '') = ''
  873. PbModelDbService<List<MeterBaseBillPrint>> pbPrintService = new PbModelDbService<List<MeterBaseBillPrint>>();
  874. RESTfulResult<List<MeterBaseBillPrint>> rmPint = pbPrintService.executeSqlDataWf(sql);
  875. if (rmPint.Succeed)
  876. {
  877. if (rmPint.Data != null && rmPint.Data.Count > 0)
  878. {
  879. //若有净重信息:1毛重时间晚于皮重时间,则打印毛、皮、净重,2毛重早于皮重,打印皮、净
  880. //若只有毛重信息则打印毛重
  881. List<MeterBaseBillPrint> lGrossprint = rmPint.Data.Where(s => s.weightTypeName.Contains("毛")).ToList();
  882. List<MeterBaseBillPrint> lTarePrint = rmPint.Data.Where(s => s.weightTypeName.Contains("皮")).ToList();
  883. List<MeterBaseBillPrint> lNetprint = rmPint.Data.Where(s => s.weightTypeName.Contains("净")).ToList();
  884. List<MeterWorkCarActual> mwaChild = mwa.Where(s => s.meterTypeNo == "x").ToList();
  885. if (mwaChild != null && mwaChild.Count > 0) //若有净重信息
  886. {
  887. if (lTarePrint != null && lTarePrint.Count > 0)
  888. {
  889. //获取非毛,非净重信息如果没有则用的期限皮,此时不打,否则则打印
  890. MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo != "x" && s.meterTypeNo != "0").FirstOrDefault();
  891. if (mwca != null)
  892. {
  893. PrintCls cls = new PrintCls();
  894. cls.printNum = (int)(lTarePrint[0].printNum == null ? 0 : lTarePrint[0].printNum.Value);
  895. cls.iType = 1;//皮重
  896. cls.printDb = mwca;
  897. prrintC.Add(cls);
  898. }
  899. }
  900. if (lGrossprint != null && lGrossprint.Count > 0)
  901. {
  902. //获取毛重信息
  903. MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "0").FirstOrDefault();
  904. if (mwca != null)
  905. {
  906. PrintCls cls = new PrintCls();
  907. cls.printNum = (int)(lGrossprint[0].printNum == null ? 0 : lGrossprint[0].printNum.Value);
  908. cls.iType = 0;//毛重
  909. cls.printDb = mwca;
  910. prrintC.Add(cls);
  911. }
  912. }
  913. if (lNetprint != null && lNetprint.Count > 0)
  914. {
  915. //获取净重信息
  916. MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "x").FirstOrDefault();
  917. if (mwca != null)
  918. {
  919. PrintCls cls = new PrintCls();
  920. cls.printNum = (int)(lNetprint[0].printNum == null ? 0 : lNetprint[0].printNum.Value);
  921. cls.iType = 2;//净重
  922. cls.printDb = mwca;
  923. prrintC.Add(cls);
  924. }
  925. }
  926. }
  927. else //只有毛重信息则打印毛重
  928. {
  929. if (lGrossprint != null && lGrossprint.Count > 0)
  930. {
  931. //获取毛重信息
  932. MeterWorkCarActual mwca = rm.Data.Where(s => s.meterTypeNo == "0").FirstOrDefault();
  933. if (mwca != null)
  934. {
  935. PrintCls cls = new PrintCls();
  936. cls.printNum = (int)(lGrossprint[0].printNum == null ? 0 : lGrossprint[0].printNum.Value);
  937. cls.iType = 0;//毛重
  938. cls.printDb = mwca;
  939. prrintC.Add(cls);
  940. }
  941. }
  942. }
  943. if (prrintC != null && prrintC.Count > 0)
  944. {
  945. FrmMessage frmMessage = FrmMess("是否打印第【1】张票据!", "打印");
  946. if (frmMessage.ShowDialog(this) == DialogResult.OK)
  947. {
  948. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】是否打印选择了【是】");
  949. l.WriteLog(15, PbCache.lockCarNo + "是否打印选择了【是】");
  950. strFirstNo = firstNo;
  951. //printDocument1.PrinterSettings.PrinterName = PbCache.sportInfo.printerName;//strPntSvrName;
  952. System.Drawing.Printing.PaperSize customSize1 = new System.Drawing.Printing.PaperSize("TestPaper", 398, 433); //101mm*110mm,换算成英寸
  953. printDocument1.DefaultPageSettings.PaperSize = customSize1;//将自定义的Papersize赋给PrintDocument
  954. System.Drawing.Printing.Margins marginss = new System.Drawing.Printing.Margins(0, 0, 0, 0);
  955. printDocument1.DefaultPageSettings.Margins = marginss;
  956. printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
  957. foreach (PrintCls db in prrintC)
  958. {
  959. switch (db.printDb.meterTypeNo)
  960. {
  961. case "0": //毛
  962. db.qrCode = db.printDb.actualNo + "," + db.printDb.grossWeight + "," + "1";
  963. break;
  964. case "x": //净
  965. db.qrCode = db.printDb.actualNo + "," + db.printDb.netWeight + "," + "2";
  966. break;
  967. default: //皮
  968. db.qrCode = db.printDb.actualNo + "," + db.printDb.grossWeight + "," + "1";
  969. break;
  970. }
  971. RESTfulResult<string> rQRCode = workCarActualFirstService.doQRCodeWf(db.qrCode);
  972. db.qrCode = rQRCode.Data;
  973. for (int i = 0; i < db.printNum; i++)
  974. {
  975. if (i == 0)
  976. {
  977. printData = db;
  978. printDocument1.Print();
  979. l.WriteLog(10, "当前第" + (i + 1) + "次打印:" + printData.iType + " 车号:" + db.printDb.carNo + ",二维码:" + db.qrCode);
  980. }
  981. else
  982. {
  983. FrmMessage frmMessageContinue = FrmMess("已打印【" + i + "】张,是否继续打印第【" + (i + 1) + "】张票据!", "打印");
  984. if (frmMessageContinue.ShowDialog(this) == DialogResult.OK)
  985. {
  986. printData = db;
  987. printDocument1.Print();
  988. l.WriteLog(10, "当前第" + (i + 1) + "次打印:" + printData.iType + " 车号:" + db.printDb.carNo + ",二维码:" + db.qrCode);
  989. }
  990. else
  991. {
  992. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】第" + i + "次是否打印,选择了【否】");
  993. }
  994. }
  995. //printData = db;
  996. //printDocument1.Print();
  997. //lg.WriteLog(11, "当前打印:" + printData.iType + " 车号:" + db.printDb.carNo);
  998. }
  999. }
  1000. }
  1001. else
  1002. {
  1003. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】是否打印选择了【否】");
  1004. l.WriteLog(15, PbCache.lockCarNo + "是否打印选择了【否】");
  1005. }
  1006. }
  1007. }
  1008. }
  1009. else
  1010. {
  1011. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】获取打印配置数据信息异常sql:【" + sql + "】");
  1012. }
  1013. }
  1014. }
  1015. }
  1016. else
  1017. {
  1018. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】获取计量数据信息异常sql:【" + sql + "】");
  1019. }
  1020. #endregion 获取打印信息,若需要打印则调用打印操作
  1021. }
  1022. catch (Exception ex)
  1023. {
  1024. l.WriteLog(10, "车号【" + PbCache.lockCarNo + "】打印异常" + ex);
  1025. }
  1026. }
  1027. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
  1028. {
  1029. try
  1030. {
  1031. if (printData != null && printData.printDb != null)
  1032. {
  1033. printClass.PrintAllPage(e, printData.printDb, printData.qrCode);
  1034. /*
  1035. //结净打印
  1036. if (printData.iType == 2)
  1037. {
  1038. printClass.PrintPage(e, printData.printDb, PbCache.strQRCode);
  1039. }
  1040. else //非结净打印
  1041. {
  1042. printClass.PrintWgtPage(e, printData.printDb, PbCache.strQRCode);
  1043. }
  1044. //*/
  1045. }
  1046. }
  1047. catch (Exception ex)
  1048. {
  1049. l.WriteLog(11, "打印异常" + ex);
  1050. }
  1051. }
  1052. /// <summary>
  1053. /// 重量大于500,直接打开主界面
  1054. /// </summary>
  1055. /// <param name="sender"></param>
  1056. /// <param name="e"></param>
  1057. private void timer1_Tick(object sender, EventArgs e)
  1058. {
  1059. if (!isOpened && PbCache.collect?.weight > 500)
  1060. {
  1061. isOpened = true;
  1062. isOpenMeter = true;
  1063. PbCache.bussinessTypeName = "";
  1064. PbCache.bussinessTypeCode = "";
  1065. fcc.ShowDialog();
  1066. fcc.init();
  1067. }
  1068. }
  1069. /// <summary>
  1070. /// 操作Live表的数据:零点报警
  1071. /// </summary>
  1072. private void doOperateLive()
  1073. {
  1074. if (PbCache.collect_no == null)
  1075. {
  1076. return;
  1077. }
  1078. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  1079. if (ll != null)
  1080. {
  1081. foreach (LiveData lv in ll)
  1082. {
  1083. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  1084. {
  1085. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  1086. break;
  1087. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  1088. break;
  1089. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  1090. break;
  1091. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  1092. if (((lv.Value ?? "0") + "").Equals("1"))
  1093. {
  1094. doInsertZeroAlarm();
  1095. PbCache.isZeroAlarm = true;
  1096. }
  1097. else
  1098. {
  1099. PbCache.isZeroAlarm = false;
  1100. }
  1101. break;
  1102. }
  1103. }
  1104. }
  1105. }
  1106. /// <summary>
  1107. /// 操作Live表的数据:零点报警
  1108. /// </summary>
  1109. private void doLive()
  1110. {
  1111. if (PbCache.collect_no == null)
  1112. {
  1113. return;
  1114. }
  1115. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  1116. MeterWorkMonitor mwm = new MeterWorkMonitor();
  1117. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  1118. mwm.redGreenLightState = "0";
  1119. if (ll != null)
  1120. {
  1121. foreach (LiveData lv in ll)
  1122. {
  1123. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  1124. {
  1125. case "PowerStatus":
  1126. mwm.powerState = lv.Value.ToString();
  1127. break;
  1128. case "PlcWatchDog":
  1129. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  1130. {
  1131. mwm.plcState = 0.ToString();
  1132. }
  1133. break;
  1134. case "InfraredWest":
  1135. if (lv.Value.ToString() == "2")
  1136. {
  1137. mwm.leftInfraredRayState = "0";
  1138. }
  1139. else
  1140. {
  1141. mwm.leftInfraredRayState = lv.Value.ToString();
  1142. }
  1143. break;
  1144. case "InfraredEast":
  1145. if (lv.Value.ToString() == "2")
  1146. {
  1147. mwm.rightInfraredRayState = "0";
  1148. }
  1149. else
  1150. {
  1151. mwm.rightInfraredRayState = lv.Value.ToString();
  1152. }
  1153. break;
  1154. case "AmplifierState":
  1155. mwm.amplifierState = lv.Value.ToString();
  1156. break;
  1157. case "LampState":
  1158. mwm.lampState = lv.Value.ToString();
  1159. break;
  1160. case "InfraredLeft":
  1161. if (lv.Value.ToString() == "2")
  1162. {
  1163. mwm.frontInfraredRayState = "0";
  1164. }
  1165. else
  1166. {
  1167. mwm.frontInfraredRayState = lv.Value.ToString();
  1168. }
  1169. break;
  1170. case "InfraredRight":
  1171. if (lv.Value.ToString() == "2")
  1172. {
  1173. mwm.rearInfraredRayState = "0";
  1174. }
  1175. else
  1176. {
  1177. mwm.rearInfraredRayState = lv.Value.ToString();
  1178. }
  1179. break;
  1180. case "ZeroWeightStatus":
  1181. mwm.zeroState = lv.Value.ToString();
  1182. break;
  1183. case "RfidState":
  1184. mwm.rfidState = lv.Value.ToString();
  1185. if (((lv.Value ?? "0") + "").Equals("1"))
  1186. {
  1187. doInsertZeroAlarm();
  1188. PbCache.isZeroAlarm = true;
  1189. }
  1190. else
  1191. {
  1192. PbCache.isZeroAlarm = false;
  1193. }
  1194. break;
  1195. }
  1196. }
  1197. }
  1198. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  1199. }
  1200. /// <summary>
  1201. /// 新增零点报警的数据
  1202. /// </summary>
  1203. private void doInsertZeroAlarm()
  1204. {
  1205. if (!PbCache.isZeroAlarm)
  1206. {
  1207. PbCache.isZeroAlarm = true;
  1208. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  1209. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  1210. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  1211. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  1212. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  1213. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  1214. workZeroAlarm.scalePointNo = PbCache.collect_no;
  1215. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  1216. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  1217. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  1218. if (rms.Succeed)
  1219. {
  1220. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight);
  1221. }
  1222. else
  1223. {
  1224. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  1225. }
  1226. }
  1227. }
  1228. private void button3_Click(object sender, EventArgs e)
  1229. {
  1230. string limsResult = "";
  1231. JGLimsInterface gLimsInterface = new JGLimsInterface();
  1232. }
  1233. /// <summary>
  1234. /// 查询重量信息,显示在界面上面
  1235. /// </summary>
  1236. /// <param name="sender"></param>
  1237. /// <param name="e"></param>
  1238. private void button4_Click(object sender, EventArgs e)
  1239. {
  1240. try
  1241. {
  1242. string sqls = @"select '毛重:' || t.gross_weight / 1000 || ' T / 皮重:' || t.tare_weight / 1000 || ' T / 净重:' || t.net_weight / 1000 || ' T ' as text
  1243. from meter_work_car_actual t where t.value_flag = '0' and T.Prediction_No = '" + txtPlanNo.Text + @"'";
  1244. PbModelDbService<List<PbModelDb>> pbRelation = new PbModelDbService<List<PbModelDb>>();
  1245. RESTfulResult<List<PbModelDb>> rmRelation = pbRelation.executeSqlDataWf(sqls);
  1246. if (rmRelation.Succeed && rmRelation.Data != null && rmRelation.Data.Count > 0)
  1247. {
  1248. MessageBox.Show(rmRelation.Data[0].text);
  1249. }
  1250. else
  1251. {
  1252. MessageBox.Show("空");
  1253. }
  1254. }
  1255. catch (Exception ex)
  1256. {
  1257. }
  1258. }
  1259. private void button1_Click(object sender, EventArgs e)
  1260. {
  1261. isOpened = false;
  1262. testFlag = true;
  1263. PbCache.isTest= true;
  1264. testWgt = (int)numericUpDown1.Value;
  1265. //CollectModel model = new CollectModel();
  1266. //model.weight = testWgt;
  1267. //PbCache.collect = model;
  1268. testCarNo = textBox1.Text.Trim();
  1269. testPlanNo = txtPlanNo.Text.Trim();
  1270. }
  1271. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  1272. {
  1273. collection.Stop();
  1274. imageCurlControl.Stop();
  1275. sweepCodeClass.CloseThread();
  1276. sweepCodeClass2.CloseThread();
  1277. timer1.Stop();
  1278. timer1.Dispose();
  1279. }
  1280. private bool SystemUpdate(bool isMessage)
  1281. {
  1282. ReleaseList releaseList = new ReleaseList(Application.StartupPath + @"\" + GlobalVariable.Instance.ReleaseFileName);
  1283. DownloadTools dt = new DownloadTools();
  1284. try
  1285. {
  1286. bool isDownload = dt.IsDownloadFile(GlobalVariable.Instance.LocalPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ReleaseFileName);
  1287. if (!isDownload)
  1288. {
  1289. if (isMessage) MessageBox.Show("无法连接到远程主机!", Application.ProductName);
  1290. return false;
  1291. }
  1292. }
  1293. catch (Exception e)
  1294. {
  1295. MessageBox.Show(e.Message);
  1296. }
  1297. bool flag = this.CheckUpdate(releaseList);
  1298. if (flag)
  1299. {
  1300. MessageBox.Show("有新版本,现在更新");
  1301. string t = dt.DownloadFile(Application.StartupPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ApplicationUpdater);
  1302. this.Close();
  1303. Application.Exit();
  1304. GC.Collect();
  1305. Process.Start(Application.StartupPath + @"\" + GlobalVariable.Instance.ApplicationUpdater);
  1306. return true;
  1307. }
  1308. else
  1309. {
  1310. if (isMessage) MessageBox.Show("你的系统已经是最新版本,不需要更新!", Application.ProductName);
  1311. return false;
  1312. }
  1313. }
  1314. private bool CheckUpdate(ReleaseList localRelease)
  1315. {
  1316. try
  1317. {
  1318. string fileNameAll = Application.StartupPath + "\\" + GlobalVariable.Instance.LocalPath + "\\" + GlobalVariable.Instance.ReleaseFileName;
  1319. ReleaseList remoteRelease = new ReleaseList(fileNameAll);
  1320. return (((localRelease != null) && (remoteRelease != null)) && localRelease.ReleaseDate.CompareTo(remoteRelease.ReleaseDate) < 0);
  1321. }
  1322. catch (Exception exception)
  1323. {
  1324. MessageBox.Show(exception.Message);
  1325. }
  1326. return false;
  1327. }
  1328. }
  1329. }