Form1.cs 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  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. if(fcc.Visible == false)
  1066. {
  1067. fcc.ShowDialog();
  1068. fcc.init();
  1069. }
  1070. }
  1071. }
  1072. /// <summary>
  1073. /// 操作Live表的数据:零点报警
  1074. /// </summary>
  1075. private void doOperateLive()
  1076. {
  1077. if (PbCache.collect_no == null)
  1078. {
  1079. return;
  1080. }
  1081. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  1082. if (ll != null)
  1083. {
  1084. foreach (LiveData lv in ll)
  1085. {
  1086. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  1087. {
  1088. case "StaticStatus"://车辆检测 "0、东西方向激光均无报警;否则报警
  1089. break;
  1090. case "SwitchLight"://PLC红绿灯控制模式状态 "PLC有三种控制模式:1、自动、2、远控;3、检修
  1091. break;
  1092. case "LightWest"://红绿灯:1、为绿灯;2、为红灯;"
  1093. break;
  1094. case "ZeroWeightStatus": //0、其它,1、零点报警,红绿灯变红,
  1095. if (((lv.Value ?? "0") + "").Equals("1"))
  1096. {
  1097. doInsertZeroAlarm();
  1098. PbCache.isZeroAlarm = true;
  1099. }
  1100. else
  1101. {
  1102. PbCache.isZeroAlarm = false;
  1103. }
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. /// <summary>
  1110. /// 操作Live表的数据:零点报警
  1111. /// </summary>
  1112. private void doLive()
  1113. {
  1114. if (PbCache.collect_no == null)
  1115. {
  1116. return;
  1117. }
  1118. List<LiveData> ll = MemoClass.getWarnInfo(PbCache.collect_no);
  1119. MeterWorkMonitor mwm = new MeterWorkMonitor();
  1120. mwm.pointNo = PbCache.sportInfo.baseSpotNo;
  1121. mwm.redGreenLightState = "0";
  1122. if (ll != null)
  1123. {
  1124. foreach (LiveData lv in ll)
  1125. {
  1126. switch (lv.Tagname.Replace(PbCache.collect_no, ""))
  1127. {
  1128. case "PowerStatus":
  1129. mwm.powerState = lv.Value.ToString();
  1130. break;
  1131. case "PlcWatchDog":
  1132. if (int.Parse(lv.Value.ToString()) >= 0 && int.Parse(lv.Value.ToString()) <= 0)
  1133. {
  1134. mwm.plcState = 0.ToString();
  1135. }
  1136. break;
  1137. case "InfraredWest":
  1138. if (lv.Value.ToString() == "2")
  1139. {
  1140. mwm.leftInfraredRayState = "0";
  1141. }
  1142. else
  1143. {
  1144. mwm.leftInfraredRayState = lv.Value.ToString();
  1145. }
  1146. break;
  1147. case "InfraredEast":
  1148. if (lv.Value.ToString() == "2")
  1149. {
  1150. mwm.rightInfraredRayState = "0";
  1151. }
  1152. else
  1153. {
  1154. mwm.rightInfraredRayState = lv.Value.ToString();
  1155. }
  1156. break;
  1157. case "AmplifierState":
  1158. mwm.amplifierState = lv.Value.ToString();
  1159. break;
  1160. case "LampState":
  1161. mwm.lampState = lv.Value.ToString();
  1162. break;
  1163. case "InfraredLeft":
  1164. if (lv.Value.ToString() == "2")
  1165. {
  1166. mwm.frontInfraredRayState = "0";
  1167. }
  1168. else
  1169. {
  1170. mwm.frontInfraredRayState = lv.Value.ToString();
  1171. }
  1172. break;
  1173. case "InfraredRight":
  1174. if (lv.Value.ToString() == "2")
  1175. {
  1176. mwm.rearInfraredRayState = "0";
  1177. }
  1178. else
  1179. {
  1180. mwm.rearInfraredRayState = lv.Value.ToString();
  1181. }
  1182. break;
  1183. case "ZeroWeightStatus":
  1184. mwm.zeroState = lv.Value.ToString();
  1185. break;
  1186. case "RfidState":
  1187. mwm.rfidState = lv.Value.ToString();
  1188. if (((lv.Value ?? "0") + "").Equals("1"))
  1189. {
  1190. doInsertZeroAlarm();
  1191. PbCache.isZeroAlarm = true;
  1192. }
  1193. else
  1194. {
  1195. PbCache.isZeroAlarm = false;
  1196. }
  1197. break;
  1198. }
  1199. }
  1200. }
  1201. RESTfulResult<string> rms = meterWorkMonitor.doUpdateWf(mwm);
  1202. }
  1203. /// <summary>
  1204. /// 新增零点报警的数据
  1205. /// </summary>
  1206. private void doInsertZeroAlarm()
  1207. {
  1208. if (!PbCache.isZeroAlarm)
  1209. {
  1210. PbCache.isZeroAlarm = true;
  1211. MeterWorkZeroAlarm workZeroAlarm = new MeterWorkZeroAlarm();
  1212. workZeroAlarm.zeroWeight = PbCache.collect.weight;
  1213. workZeroAlarm.spotTypeNo = PbCache.sportInfo.spotTypeNo;
  1214. workZeroAlarm.spotTypeName = PbCache.sportInfo.spotTypeName;
  1215. workZeroAlarm.baseSpotNo = PbCache.sportInfo.baseSpotNo;
  1216. workZeroAlarm.baseSpotName = PbCache.sportInfo.baseSpotName;
  1217. workZeroAlarm.scalePointNo = PbCache.collect_no;
  1218. workZeroAlarm.createManNo = PbCache.sportInfo.baseSpotNo;
  1219. workZeroAlarm.createManName = PbCache.sportInfo.baseSpotName;
  1220. RESTfulResult<String> rms = zeroAlarmService.doInsertZeroAlarm(workZeroAlarm);
  1221. if (rms.Succeed)
  1222. {
  1223. l.WriteLog(20, "新增成功:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight);
  1224. }
  1225. else
  1226. {
  1227. l.WriteLog(20, "操作失败:" + workZeroAlarm.baseSpotName + ":" + workZeroAlarm.zeroWeight + rms.Data + rms.Message);
  1228. }
  1229. }
  1230. }
  1231. private void button3_Click(object sender, EventArgs e)
  1232. {
  1233. string limsResult = "";
  1234. JGLimsInterface gLimsInterface = new JGLimsInterface();
  1235. }
  1236. /// <summary>
  1237. /// 查询重量信息,显示在界面上面
  1238. /// </summary>
  1239. /// <param name="sender"></param>
  1240. /// <param name="e"></param>
  1241. private void button4_Click(object sender, EventArgs e)
  1242. {
  1243. try
  1244. {
  1245. string sqls = @"select '毛重:' || t.gross_weight / 1000 || ' T / 皮重:' || t.tare_weight / 1000 || ' T / 净重:' || t.net_weight / 1000 || ' T ' as text
  1246. from meter_work_car_actual t where t.value_flag = '0' and T.Prediction_No = '" + txtPlanNo.Text + @"'";
  1247. PbModelDbService<List<PbModelDb>> pbRelation = new PbModelDbService<List<PbModelDb>>();
  1248. RESTfulResult<List<PbModelDb>> rmRelation = pbRelation.executeSqlDataWf(sqls);
  1249. if (rmRelation.Succeed && rmRelation.Data != null && rmRelation.Data.Count > 0)
  1250. {
  1251. MessageBox.Show(rmRelation.Data[0].text);
  1252. }
  1253. else
  1254. {
  1255. MessageBox.Show("空");
  1256. }
  1257. }
  1258. catch (Exception ex)
  1259. {
  1260. }
  1261. }
  1262. private void button1_Click(object sender, EventArgs e)
  1263. {
  1264. isOpened = false;
  1265. testFlag = true;
  1266. PbCache.isTest= true;
  1267. testWgt = (int)numericUpDown1.Value;
  1268. //CollectModel model = new CollectModel();
  1269. //model.weight = testWgt;
  1270. //PbCache.collect = model;
  1271. testCarNo = textBox1.Text.Trim();
  1272. testPlanNo = txtPlanNo.Text.Trim();
  1273. }
  1274. private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  1275. {
  1276. collection.Stop();
  1277. imageCurlControl.Stop();
  1278. sweepCodeClass.CloseThread();
  1279. sweepCodeClass2.CloseThread();
  1280. timer1.Stop();
  1281. timer1.Dispose();
  1282. }
  1283. private bool SystemUpdate(bool isMessage)
  1284. {
  1285. ReleaseList releaseList = new ReleaseList(Application.StartupPath + @"\" + GlobalVariable.Instance.ReleaseFileName);
  1286. DownloadTools dt = new DownloadTools();
  1287. try
  1288. {
  1289. bool isDownload = dt.IsDownloadFile(GlobalVariable.Instance.LocalPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ReleaseFileName);
  1290. if (!isDownload)
  1291. {
  1292. if (isMessage) MessageBox.Show("无法连接到远程主机!", Application.ProductName);
  1293. return false;
  1294. }
  1295. }
  1296. catch (Exception e)
  1297. {
  1298. MessageBox.Show(e.Message);
  1299. }
  1300. bool flag = this.CheckUpdate(releaseList);
  1301. if (flag)
  1302. {
  1303. MessageBox.Show("有新版本,现在更新");
  1304. string t = dt.DownloadFile(Application.StartupPath, GlobalVariable.Instance.ReleaseURL, GlobalVariable.Instance.ApplicationUpdater);
  1305. this.Close();
  1306. Application.Exit();
  1307. GC.Collect();
  1308. Process.Start(Application.StartupPath + @"\" + GlobalVariable.Instance.ApplicationUpdater);
  1309. return true;
  1310. }
  1311. else
  1312. {
  1313. if (isMessage) MessageBox.Show("你的系统已经是最新版本,不需要更新!", Application.ProductName);
  1314. return false;
  1315. }
  1316. }
  1317. private bool CheckUpdate(ReleaseList localRelease)
  1318. {
  1319. try
  1320. {
  1321. string fileNameAll = Application.StartupPath + "\\" + GlobalVariable.Instance.LocalPath + "\\" + GlobalVariable.Instance.ReleaseFileName;
  1322. ReleaseList remoteRelease = new ReleaseList(fileNameAll);
  1323. return (((localRelease != null) && (remoteRelease != null)) && localRelease.ReleaseDate.CompareTo(remoteRelease.ReleaseDate) < 0);
  1324. }
  1325. catch (Exception exception)
  1326. {
  1327. MessageBox.Show(exception.Message);
  1328. }
  1329. return false;
  1330. }
  1331. }
  1332. }