Form1.cs 66 KB

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