Terminal.cs 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  1. using Terminal;
  2. using db;
  3. using System.Collections.Generic;
  4. using System.Threading.Tasks;
  5. using PLCS7;
  6. using System;
  7. using System.Text;
  8. using MySql.Data.MySqlClient;
  9. using System.Threading;
  10. using BroadcastModule;
  11. using parkMonitor.LOG;
  12. using centralController.model;
  13. namespace Terminal
  14. {
  15. public class Terminal
  16. {
  17. public static List<TerminalStru> terminalInfo = new List<PLCS7.TerminalStru>();
  18. /// <summary>
  19. /// 记录地面停车位id与获取号牌映射
  20. /// </summary>
  21. private static Dictionary<int, string> idLicMap = new Dictionary<int, string>();
  22. /// <summary>
  23. /// 记录地面停车位id与凭证号映射
  24. /// </summary>
  25. private static Dictionary<int, int> idReceiptMap = new Dictionary<int, int>();
  26. /// <summary>
  27. /// 取车地面位id与是否已计费标记映射
  28. /// </summary>
  29. public static Dictionary<int, bool> termCalcMap = new Dictionary<int, bool>();
  30. /// <summary>
  31. /// 终端ID与取车完成标志映射
  32. /// </summary>
  33. public static Dictionary<int, bool> fetchCompleteMap = new Dictionary<int, bool>();
  34. /// <summary>
  35. /// 终端ID与取车信息映射
  36. /// </summary>
  37. private static Dictionary<int, FetchInfo> fetchInfoMap = new Dictionary<int, FetchInfo>();
  38. private static List<bool> lockList = new List<bool>();
  39. public static bool isClosing = false;
  40. /// <summary>
  41. /// 从终端结构体中获得车牌号
  42. /// </summary>
  43. /// <param name="ts"></param>
  44. /// <returns></returns>
  45. private static string GetLicenseFromTerm(TerminalStru ts)
  46. {
  47. string header = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeB));
  48. string identityA = Encoding.ASCII.GetString(BitConverter.GetBytes(ts.licenseCodeC));
  49. byte[] bytes = BitConverter.GetBytes(ts.licenseCodeD);
  50. List<byte> newBytes = new List<byte>();
  51. for (int i = 0; i < bytes.Length; i++)
  52. {
  53. if (bytes[i] != 0x00) { newBytes.Add(bytes[i]); }
  54. }
  55. string identityB = Encoding.ASCII.GetString(newBytes.ToArray());
  56. Log.WriteLog(LogType.process, LogFile.INFO, "已从终端" + ts.terminalID + "获得号牌:" + header + identityA + identityB);
  57. //根据省份对应的两位数字查找汉字
  58. string province = header.Substring(0, 2);
  59. string provinceIndex = header.Substring(2);
  60. string provinceQuerySql = "select NumberPlateHeader from numberplatemapping where mappedString = " + province + ";";
  61. if (province != "/0/0")
  62. {
  63. lock (Monitor.Monitor.localDBOper)
  64. {
  65. //object[] result = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
  66. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
  67. try
  68. {
  69. if (reader != null && reader.Read() && reader.HasRows)
  70. {
  71. province = reader.GetString("NumberPlateHeader");
  72. //Console.WriteLine(province);
  73. }
  74. }
  75. catch { }
  76. try
  77. {
  78. //if (result!=null && result.Length > 0) { province = (string)result[0]; }
  79. if (reader != null)
  80. {
  81. reader.Close();
  82. reader.Dispose();
  83. }
  84. }
  85. catch { }
  86. }
  87. return province + provinceIndex + identityA + identityB;
  88. }
  89. else
  90. return "";
  91. }
  92. /// <summary>
  93. /// 更新所有车位信息
  94. /// </summary>
  95. private static void UpdateAllParkingSpace(bool remote)
  96. {
  97. string findParkingSpace = "select parkingSpaceID from parkingspace;";
  98. HashSet<int> recordsIDSet = new HashSet<int>();
  99. DBOperation dbHandle = null;
  100. if (!remote)
  101. {
  102. dbHandle = Monitor.Monitor.localDBOper;
  103. }
  104. else
  105. {
  106. dbHandle = Monitor.Monitor.remoteDBOper;
  107. }
  108. lock (dbHandle)
  109. {
  110. MySqlDataReader reader = dbHandle.Query(findParkingSpace);
  111. if (reader != null)
  112. {
  113. try
  114. {
  115. while (reader.Read())
  116. {
  117. if (reader.HasRows)
  118. {
  119. recordsIDSet.Add(reader.GetInt32("parkingSpaceID"));
  120. }
  121. }
  122. }
  123. catch { Log.WriteLog(LogType.process, LogFile.INFO, "数据库车位查询异常"); }
  124. try
  125. {
  126. reader.Close();
  127. reader.Dispose();
  128. }
  129. catch { }
  130. }
  131. }
  132. List<string> updateSpaceList = new List<string>();
  133. List<string> insertSpaceList = new List<string>();
  134. string updateParkingSpace = "";
  135. string insertParkingSpace = "";
  136. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  137. {
  138. if (recordsIDSet.Contains(Monitor.Monitor.parkingSpaceInfo[i].parkingSpace))
  139. {
  140. updateParkingSpace = "update parkingspace set parkingSpaceX = " + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  141. ",parkingSpaceY = " + Monitor.Monitor.parkingSpaceInfo[i].coordY + ",parkingSpaceZ = " + Monitor.Monitor.parkingSpaceInfo[i].floorNo + ",parkingSpaceState = " + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + " where (parkingSpaceID = " + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + ");";
  142. updateSpaceList.Add(updateParkingSpace);
  143. }
  144. else
  145. {
  146. if (!remote)
  147. {
  148. insertParkingSpace = "insert into parkingspace (parkingSpaceID,parkingSpaceX,parkingSpaceY,parkingSpaceZ,parkingSpaceState) values (" + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + "," + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  149. "," + Monitor.Monitor.parkingSpaceInfo[i].coordY + "," + Monitor.Monitor.parkingSpaceInfo[i].floorNo + "," + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + ");";
  150. insertSpaceList.Add(insertParkingSpace);
  151. }
  152. else
  153. {
  154. insertParkingSpace = "insert into parkingspace (parkingSpaceID,parkingSpaceX,parkingSpaceY,parkingSpaceZ,parkingSpaceState,garageID,parkingSpaceName) values (" + Monitor.Monitor.parkingSpaceInfo[i].parkingSpace + "," + Monitor.Monitor.parkingSpaceInfo[i].coordX +
  155. "," + Monitor.Monitor.parkingSpaceInfo[i].coordY + "," + Monitor.Monitor.parkingSpaceInfo[i].floorNo + "," + Monitor.Monitor.parkingSpaceInfo[i].spaceStatus + "," + Monitor.Monitor.garageID + ",'默认');";
  156. insertSpaceList.Add(insertParkingSpace);
  157. }
  158. }
  159. }
  160. try
  161. {
  162. lock (dbHandle)
  163. {
  164. int id = 0;
  165. dbHandle.UpdateTransaction(updateSpaceList);
  166. dbHandle.Insert(insertSpaceList, out id);
  167. }
  168. }
  169. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "更新本地所有车位异常"); Console.WriteLine("更新本地所有车位异常" + e.Message); }
  170. }
  171. /// <summary>
  172. /// 更新车辆状态
  173. /// </summary>
  174. /// <param name="lic"></param>
  175. /// <param name="state"></param>
  176. private static void UpdateVehicle(string lic, int state, int parkingRecordsID, bool park, bool remote, int parkingSpaceID)
  177. {
  178. if (lic != "")
  179. {
  180. MySqlDataReader reader;
  181. //查询车辆是否在车辆表中
  182. string checkVehicleState = "select * from vehicle where numberPlate = '" + lic + "';";
  183. if (!remote)
  184. {
  185. reader = Monitor.Monitor.localDBOper.Query(checkVehicleState);
  186. }
  187. else
  188. {
  189. //Log.WriteLog(LogType.database, "update, query: \n");
  190. reader = Monitor.Monitor.remoteDBOper.Query(checkVehicleState);
  191. //Log.WriteLog(LogType.database, "update, query: \n" + checkVehicleState);
  192. }
  193. if (reader != null)
  194. {
  195. if (reader.Read() && reader.HasRows)
  196. {
  197. //更新车辆状态
  198. string updateVehicleState = "";
  199. string updateRemoteVehicleState = "";
  200. if (park)
  201. {
  202. if (parkingRecordsID > 0)
  203. {
  204. if (parkingSpaceID == 0)
  205. {
  206. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + " where numberPlate = '" + lic + "';";
  207. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  208. }
  209. else
  210. {
  211. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + " where numberPlate = '" + lic + "';";
  212. updateRemoteVehicleState = "update vehicle set vehiclepParkState = " + state + " ,parkingRecordsID = " + parkingRecordsID + ",parkingSpaceID = " + parkingSpaceID + ",garageID = " + Monitor.Monitor.garageID + " where numberPlate = '" + lic + "';";
  213. }
  214. }
  215. else
  216. {
  217. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  218. updateRemoteVehicleState = updateVehicleState;
  219. }
  220. }
  221. else
  222. {
  223. updateVehicleState = "update vehicle set vehiclepParkState = " + state + " where numberPlate = '" + lic + "';";
  224. updateRemoteVehicleState = updateVehicleState;
  225. }
  226. List<string> list = new List<string>();
  227. if (!remote)
  228. {
  229. list.Add(updateVehicleState);
  230. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  231. }
  232. else
  233. {
  234. //Log.WriteLog(LogType.database, "update, update: \n");
  235. list.Add(updateRemoteVehicleState);
  236. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  237. //Log.WriteLog(LogType.database, "update, update: \n" + updateRemoteVehicleState);
  238. }
  239. }
  240. else
  241. {
  242. //插入车辆
  243. string insertVehicleWithState = "";
  244. if (park)
  245. {
  246. if (parkingRecordsID > 0)
  247. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState,parkingRecordsID) values " +
  248. "('" + lic + "',NULL,'" + state + "'," + parkingRecordsID + ");";
  249. else
  250. insertVehicleWithState = "insert into vehicle (numberPlate,vehicleTypeID,vehiclepParkState) values " +
  251. "('" + lic + "',NULL,'" + state + "');";
  252. }
  253. else
  254. {
  255. Log.WriteLog(LogType.process, LogFile.ERROR, "取车无法获得车辆信息");
  256. Console.WriteLine("明显异常,取车发现无车辆");
  257. try
  258. {
  259. reader.Close();
  260. reader.Dispose();
  261. }
  262. catch { }
  263. return;
  264. }
  265. List<string> list = new List<string>();
  266. list.Add(insertVehicleWithState);
  267. int id = 0;
  268. if (!remote)
  269. {
  270. Monitor.Monitor.localDBOper.Insert(list, out id);
  271. }
  272. else
  273. {
  274. Monitor.Monitor.remoteDBOper.Insert(list, out id);
  275. }
  276. }
  277. try
  278. {
  279. reader.Close();
  280. reader.Dispose();
  281. }
  282. catch { }
  283. }
  284. }
  285. }
  286. /// <summary>
  287. /// 流程结束清除终端相关信息,同时允许再次根据地感拍号牌
  288. /// </summary>
  289. /// <param name="id"></param>
  290. private static void ClearTerminal(int id, bool removeReceipt)
  291. {
  292. for (int i = 0; i < terminalInfo.Count; i++)
  293. {
  294. if (terminalInfo[i].terminalID == id)
  295. {
  296. Log.WriteLog(LogType.process, LogFile.WARNING, "即将删除终端" + id + "数据:" + terminalInfo[i].ToString());
  297. lockList[i] = false;
  298. }
  299. }
  300. TerminalStru tsFromCentral = new TerminalStru
  301. {
  302. terminalID = (short)id,
  303. parkingFee = (short)32767,
  304. receiptNum = removeReceipt ? 0 : (short)-1
  305. };
  306. TerminalStru tsFromTerminal = new TerminalStru
  307. {
  308. terminalID = (short)id,
  309. btnStatus = (short)0,
  310. receiptNum = removeReceipt ? 0 : (short)-1
  311. };
  312. Monitor.Monitor.PLC.WriteToPLC(tsFromCentral, PLCDataType.central);
  313. Thread.Sleep(300);
  314. Monitor.Monitor.PLC.WriteToPLC(tsFromTerminal, PLCDataType.terminal);
  315. }
  316. /// <summary>
  317. /// 清除流程完成标记
  318. /// </summary>
  319. private static void ResetCompleteSignal()
  320. {
  321. MainBlockStru mbs = new MainBlockStru
  322. {
  323. centralHearbeat = (short)-1,
  324. bookParkCmd = -1,
  325. bookFetchCmd = -1,
  326. processCompleted = (short)0,
  327. licenseReceived = (short)-1
  328. };
  329. Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
  330. }
  331. /// <summary>
  332. /// 更新PLC提供的特定车位状态
  333. /// </summary>
  334. /// <param name="state"></param>
  335. private static void UpdateSpecificParkingSpace()
  336. {
  337. try
  338. {
  339. lock (Monitor.Monitor.PLCReadLock)
  340. {
  341. //获取当前车位ID
  342. int parkingSpaceID = Monitor.Monitor.mainBlockInfo.currentParkingSpaceID;
  343. //获取车位状态
  344. List<object> received = Monitor.Monitor.PLC.ReadFromPLC(PLCDataType.parkingSpace, parkingSpaceID);
  345. //本地车位更新
  346. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  347. {
  348. if (Monitor.Monitor.parkingSpaceInfo[i].parkingSpace == parkingSpaceID)
  349. {
  350. ParkingSpaceStru ps = Monitor.Monitor.parkingSpaceInfo[i];
  351. ps.spaceStatus = (short)((ParkingSpaceStru)received[0]).spaceStatus;
  352. ps.receiptNum = ((ParkingSpaceStru)received[0]).receiptNum;
  353. ps.length = (short)((ParkingSpaceStru)received[0]).length;
  354. ps.width = (short)((ParkingSpaceStru)received[0]).width;
  355. ps.height = (short)((ParkingSpaceStru)received[0]).height;
  356. Monitor.Monitor.parkingSpaceInfo[i] = ps;
  357. break;
  358. }
  359. }
  360. }
  361. }
  362. catch { Console.WriteLine("更新此车位异常"); }
  363. }
  364. /// <summary>
  365. /// 验证会员信息
  366. /// </summary>
  367. /// <param name="ts"></param>
  368. /// <param name="userID"></param>
  369. /// <param name="license"></param>
  370. /// <param name="status"></param>
  371. private static void ValidateUserInfo(TerminalStru ts, int userID, string license, out int status)
  372. {
  373. status = 0;
  374. //与云端数据比对
  375. string checkNetSql = "select * from user where userID = 1;";
  376. MySqlDataReader readerTest = Monitor.Monitor.remoteDBOper.Query(checkNetSql);
  377. if (readerTest != null)
  378. {
  379. if (readerTest.Read() && readerTest.HasRows)
  380. {
  381. try
  382. {
  383. readerTest.Close();
  384. readerTest.Dispose();
  385. }
  386. catch { }
  387. string userInfoCheckSql = "select * from usercarrelation where userID = '" + userID + "' and numberPlate = '" + license + "';";
  388. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(userInfoCheckSql);
  389. if (reader != null && reader.Read() && reader.HasRows && userID != 0 && license != "")
  390. {
  391. ts.licVerification = 1;//验证成功
  392. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  393. status = 1;
  394. Log.WriteLog(LogType.process, LogFile.INFO, "号牌验证成功");
  395. Monitor.Monitor.SetNotification("注册用户,号牌验证成功", parkMonitor.model.TextColor.Info);
  396. }
  397. else
  398. {
  399. ts.licVerification = 1;//验证失败
  400. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  401. status = 2;
  402. Log.WriteLog(LogType.process, LogFile.WARNING, "号牌验证失败");
  403. Monitor.Monitor.SetNotification("注册用户,号牌验证失败", parkMonitor.model.TextColor.Error);
  404. }
  405. try
  406. {
  407. reader.Close();
  408. reader.Dispose();
  409. }
  410. catch { }
  411. }
  412. else
  413. {
  414. try
  415. {
  416. readerTest.Close();
  417. readerTest.Dispose();
  418. }
  419. catch { }
  420. ts.licVerification = 1;//网络异常,跳过验证
  421. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  422. status = 1;
  423. Log.WriteLog(LogType.process, LogFile.ERROR, "网络异常,无法验证号牌");
  424. }
  425. }
  426. }
  427. /// <summary>
  428. /// 查询停车记录id
  429. /// </summary>
  430. /// <param name="querySql"></param>
  431. /// <param name="recordsID"></param>
  432. /// <param name="remote"></param>
  433. private static void QueryParkingRecordsID(string querySql, out int recordsID, bool remote)
  434. {
  435. recordsID = 0;
  436. MySqlDataReader reader = null;
  437. if (!remote)
  438. {
  439. reader = Monitor.Monitor.localDBOper.Query(querySql);
  440. }
  441. else
  442. {
  443. reader = Monitor.Monitor.remoteDBOper.Query(querySql);
  444. }
  445. if (reader != null)
  446. {
  447. try
  448. {
  449. while (reader.Read())
  450. {
  451. if (reader.HasRows)
  452. recordsID = reader.GetInt32("parkingRecordsID");
  453. }
  454. }
  455. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "查询停车记录id失败"); Console.WriteLine(e.Message); };
  456. try
  457. {
  458. reader.Close();
  459. reader.Dispose();
  460. }
  461. catch { }
  462. }
  463. }
  464. //private static void BookedCarProcess()
  465. //{
  466. // for (int i = 0; i < terminalInfo.Count; i++)
  467. // {
  468. // if (terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0)
  469. // {
  470. // string license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
  471. // if (license == "") { break; }
  472. // else
  473. // {
  474. // }
  475. // }
  476. // }
  477. //}
  478. #region 获取号牌方法,已调整
  479. /// <summary>
  480. /// 停车流程,收到号牌机启动后操作过程
  481. /// </summary>
  482. private static void ParkNumSubProcess()
  483. {
  484. for (int i = 0; i < terminalInfo.Count; i++)
  485. {
  486. //启动指令与终端id匹配
  487. //if (numMachineLaunch == terminalInfo[i].terminalID)
  488. if (terminalInfo[i].numMachineLaunch == 1 && terminalInfo[i].licVerification == 0)
  489. {
  490. if (!Monitor.Monitor.globalStatus)
  491. {
  492. Monitor.Monitor.SetNotification("号牌系统已暂停,将清除终端数据", parkMonitor.model.TextColor.Warning);
  493. ClearTerminal(i, true);
  494. Thread.Sleep(5000);
  495. return;
  496. }
  497. int numReceivedStatus = 0;//1获得,2终止
  498. TerminalStru term = terminalInfo[i];
  499. if (term.terminalStatus == (short)1)
  500. {
  501. string license = "";
  502. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(term.terminalID);
  503. //判断之前是否已拍摄号牌
  504. if (!idLicMap.ContainsKey(term.terminalID))
  505. {
  506. Monitor.Monitor.SetNotification("启动" + term.terminalID + "号号牌机,号牌:[" + license + "]", parkMonitor.model.TextColor.Info);
  507. }
  508. else
  509. {
  510. string lic = "";
  511. idLicMap.TryGetValue(term.terminalID, out lic);
  512. if (license != lic && lic != "")
  513. {
  514. Monitor.Monitor.SetNotification("与地感获得号牌[" + lic + "]不一致,启动" + term.terminalID + "号号牌机,号牌:[" + license + "],最终使用[" + lic + "]停车", parkMonitor.model.TextColor.Warning);
  515. license = lic;
  516. }
  517. }
  518. //记录或更新当前号牌,若无则填入默认号牌
  519. string currentLic = "";
  520. lock (idLicMap)
  521. {
  522. if (license == "")
  523. {
  524. currentLic = Monitor.Monitor.defaultLic;
  525. Monitor.Monitor.SetNotification("使用默认号牌,凭证号" + term.receiptNum, parkMonitor.model.TextColor.Error);
  526. Log.WriteLog(LogType.process, LogFile.ERROR, term.terminalID + "号号牌机未获得号牌,使用默认号牌,凭证号:" + term.receiptNum);
  527. }
  528. else
  529. {
  530. currentLic = license;
  531. }
  532. try
  533. {
  534. if (idLicMap.ContainsKey(term.terminalID))
  535. {
  536. if (!idLicMap[term.terminalID].Equals(currentLic))
  537. idLicMap[term.terminalID] = currentLic;
  538. }
  539. else
  540. {
  541. idLicMap.Add(term.terminalID, currentLic);
  542. }
  543. }
  544. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "号牌" + license + "记录号牌异常\n" + e.StackTrace); }
  545. }
  546. Log.WriteLog(LogType.process, LogFile.INFO, "号牌" + license + "已记录");
  547. ////未获得号牌,告知PLC终止,告诉终端提示用户重新操作
  548. //if (currentLic == "")
  549. //{
  550. // MainBlockStru mbs = new MainBlockStru
  551. // {
  552. // centralHearbeat = (short)-1,
  553. // bookParkCmd = -1,
  554. // bookFetchCmd = -1,
  555. // processCompleted = (short)-1,
  556. // licenseReceived = (short)2
  557. // };
  558. // Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
  559. // TerminalStru ts = new TerminalStru
  560. // {
  561. // terminalID = (short)term.terminalID,
  562. // paymentStatus = -1,
  563. // parkingFee = -1,
  564. // userType = -1,
  565. // licVerification = (short)1
  566. // };
  567. // Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  568. // Thread.Sleep(500);
  569. // ClearTerminal(term.terminalID, false);
  570. // ResetCompleteSignal();
  571. // Log.WriteLog(LogType.process, LogFile.ERROR, "未获得号牌");
  572. //}
  573. //else
  574. //{
  575. TerminalStru ts = new TerminalStru
  576. {
  577. terminalID = (short)term.terminalID,
  578. paymentStatus = -1,
  579. parkingFee = -1,
  580. userType = -1
  581. };
  582. //注册用户
  583. if (term.btnStatus == (short)2 || term.btnStatus == (short)3)
  584. {
  585. int userID = term.licenseCodeA;
  586. string userLicense = GetLicenseFromTerm(term);
  587. //注册用户缺ID信息,转为普通用户停车,终端将限制该情况发生
  588. if (userID == 0)
  589. {
  590. term.btnStatus = 1;
  591. }
  592. else
  593. {
  594. //与云端数据比对,比对失败转普通用户停车
  595. ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
  596. if (numReceivedStatus == 2)
  597. {
  598. term.btnStatus = 1;
  599. //idLicMap.Remove(term.terminalID);
  600. }
  601. }
  602. }
  603. //非注册用户
  604. if (term.btnStatus == (short)1 || term.btnStatus == (short)4)
  605. {
  606. numReceivedStatus = 1;
  607. ts.licVerification = 1;
  608. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  609. }
  610. if (term.btnStatus == (short)0)
  611. {
  612. ts.licVerification = 1;
  613. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.central);
  614. Log.WriteLog(LogType.process, LogFile.ERROR, "空按钮状态拍号牌");
  615. }
  616. //无论是否注册,皆告知PLC,已获取号牌或比对异常、终止流程
  617. MainBlockStru mbst = new MainBlockStru
  618. {
  619. centralHearbeat = -1,
  620. bookFetchCmd = -1,
  621. bookParkCmd = -1,
  622. processCompleted = (short)-1,
  623. licenseReceived = (short)numReceivedStatus
  624. };
  625. Monitor.Monitor.PLC.WriteToPLC(mbst, PLCDataType.central);
  626. int receiptCount = 6;
  627. while (receiptCount-- > 0)
  628. {
  629. term = terminalInfo[i];
  630. try
  631. {
  632. if (idReceiptMap.ContainsKey(term.terminalID))
  633. {
  634. if (!idReceiptMap[term.terminalID].Equals(term.receiptNum))
  635. idReceiptMap[term.terminalID] = term.receiptNum;
  636. }
  637. else
  638. {
  639. idReceiptMap.Add(term.terminalID, term.receiptNum);
  640. }
  641. Log.WriteLog(LogType.process, LogFile.INFO, "记录凭证号:" + term.receiptNum + "\n");
  642. if (term.receiptNum != 0)
  643. break;
  644. }
  645. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "凭证号" + term.receiptNum + "记录凭证号异常\n" + e.StackTrace); }
  646. Thread.Sleep(1000);
  647. }
  648. //号牌获取结果被清零才跳出
  649. Monitor.Monitor.SetNotification("已写入号牌获取结果" + numReceivedStatus + ",等待号牌机启动指令清零", parkMonitor.model.TextColor.Info);
  650. //}
  651. int countdown = 10;
  652. while (countdown-- > 0)
  653. {
  654. if (terminalInfo[i].numMachineLaunch == 0)
  655. {
  656. Monitor.Monitor.SetNotification("号牌机启动指令已被清零", parkMonitor.model.TextColor.Info); break;
  657. }
  658. else
  659. Thread.Sleep(500);
  660. }
  661. if (countdown == 0)
  662. Monitor.Monitor.SetNotification("提醒:未检测到号牌机启动指令被清零", parkMonitor.model.TextColor.Warning);
  663. }
  664. }
  665. }
  666. }
  667. #endregion
  668. /// <summary>
  669. /// 停车流程,收到PLC停车完成信号后操作过程
  670. /// </summary>
  671. private static void ParkCompleteSubProcess()
  672. {
  673. //Console.WriteLine(Monitor.Monitor.mainBlockInfo.parkingRunning+","+ Monitor.Monitor.mainBlockInfo.processCompleted);
  674. int processAttrib = Monitor.Monitor.mainBlockInfo.parkingRunning;
  675. //int processCompleted = Monitor.Monitor.mainBlockInfo.processCompleted;
  676. int currentTerm = Monitor.Monitor.mainBlockInfo.terminalID;
  677. int parkingSpaceID = 0;
  678. if (processAttrib == 1)
  679. {
  680. TerminalStru term = new TerminalStru();
  681. string license;
  682. //等待完成信号
  683. while (true)
  684. {
  685. if (Monitor.Monitor.mainBlockInfo.processStopped == 1 || !Monitor.Monitor.globalStatus)
  686. {
  687. Log.WriteLog(LogType.process, LogFile.ERROR, "停车流程中断");
  688. Monitor.Monitor.SetNotification("停车流程中断", parkMonitor.model.TextColor.Warning);
  689. Thread.Sleep(500);
  690. ClearTerminal(currentTerm, false);
  691. ResetCompleteSignal();
  692. //流程终端清除记录的号牌
  693. try { idLicMap.Remove(currentTerm); }
  694. catch { }
  695. return;
  696. }
  697. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  698. {
  699. if (!idLicMap.ContainsKey(currentTerm))
  700. {
  701. Thread.Sleep(500);
  702. ClearTerminal(currentTerm, false);
  703. ResetCompleteSignal();
  704. Log.WriteLog(LogType.process, LogFile.ERROR, "停车结束时未找到号牌");
  705. }
  706. break;
  707. }
  708. Thread.Sleep(200);
  709. }
  710. //找到终端号,判断是否注册用户
  711. //拿到号牌
  712. if (/*terminalInfo[i].terminalID == currentTerm && */idLicMap.TryGetValue(currentTerm, out license) && license != "")
  713. {
  714. UpdateSpecificParkingSpace();
  715. for (int i = 0; i < terminalInfo.Count; i++)
  716. {
  717. if (terminalInfo[i].terminalID == currentTerm)
  718. term = terminalInfo[i];
  719. }
  720. //term = terminalInfo[currentTerm - 1];
  721. Thread.Sleep(500);
  722. parkingSpaceID = Monitor.Monitor.mainBlockInfo.currentParkingSpaceID;
  723. int receipt = 0;
  724. idReceiptMap.TryGetValue(term.terminalID, out receipt);
  725. //无车位信息则跳出当前循环
  726. if (parkingSpaceID == 0 || receipt == 0)
  727. {
  728. try
  729. {
  730. idLicMap.Remove(currentTerm);
  731. ClearTerminal(term.terminalID, false);
  732. }
  733. catch { }
  734. Monitor.Monitor.SetNotification("无车位或凭证号,车位:" + parkingSpaceID + ",凭证号:" + receipt, parkMonitor.model.TextColor.Warning);
  735. bool getReceiptFromParkingSpace = false;
  736. if (parkingSpaceID != 0)
  737. {
  738. for (int i = 0; i < Monitor.Monitor.parkingSpaceInfo.Count; i++)
  739. {
  740. if (Monitor.Monitor.parkingSpaceInfo[i].parkingSpace == parkingSpaceID)
  741. {
  742. int myReceipt = Monitor.Monitor.parkingSpaceInfo[i].receiptNum;
  743. if(myReceipt != 0)
  744. {
  745. receipt = myReceipt;
  746. getReceiptFromParkingSpace = true;
  747. }
  748. break;
  749. }
  750. }
  751. }
  752. if (!getReceiptFromParkingSpace)
  753. {
  754. //中控清除车牌、凭证号、号牌验证等信息
  755. ClearTerminal(term.terminalID, false);
  756. //停车流程确保已清除中控块完成信号
  757. ResetCompleteSignal();
  758. return;
  759. }
  760. else
  761. {
  762. Monitor.Monitor.SetNotification("从车位获取凭证号,车位:" + parkingSpaceID + ",凭证号:" + receipt, parkMonitor.model.TextColor.Warning);
  763. }
  764. }
  765. //中控清除车牌、凭证号、号牌验证等信息
  766. ClearTerminal(term.terminalID, false);
  767. //停车流程确保已清除中控块完成信号
  768. ResetCompleteSignal();
  769. // LED屏显示,停车完成可能不提示
  770. //if (Monitor.Monitor.allInOneMachine.boardList.Count >= currentTerm)
  771. //{
  772. // Monitor.Monitor.allInOneMachine.boardList[currentTerm - 1].UpdateText("停车完成", 60, 2);
  773. // Monitor.Monitor.allInOneMachine.boardList[currentTerm - 1].UpdateArrow(-1, 2, 0);
  774. //}
  775. UpdateVehicle(license, 0, 0, true, false, 0);
  776. UpdateVehicle(license, 0, 0, true, true, 0);
  777. //插入停车记录
  778. string parkingRecordsSql = "";
  779. if (term.licenseCodeA != 0)
  780. {
  781. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  782. "values ('" + term.licenseCodeA + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + receipt + "',NULL);";
  783. Monitor.Monitor.SetNotification("用户" + term.licenseCodeA + "插入停车记录", parkMonitor.model.TextColor.Info);
  784. Log.WriteLog(LogType.process, LogFile.INFO, "用户" + term.licenseCodeA + "插入停车记录," + license + "停在" + parkingSpaceID + ",凭证号:" + receipt);
  785. }
  786. else
  787. {
  788. parkingRecordsSql = "INSERT INTO parkingrecords (userID, numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,receiptNum,parkingPrice)" +
  789. "values ('" + 28 + "','" + license + "','" + parkingSpaceID + "','" + Monitor.Monitor.garageID + "',3,'" + DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + "','" + receipt + "',NULL);";
  790. Monitor.Monitor.SetNotification("管理员用户,插入停车记录," + license + "停在" + parkingSpaceID, parkMonitor.model.TextColor.Info);
  791. Log.WriteLog(LogType.process, LogFile.INFO, "管理员用户,插入停车记录,凭证号: " + receipt + ",终端块数据:" + term.ToString());
  792. }
  793. List<string> list = new List<string>();
  794. list.Add(parkingRecordsSql);
  795. int parkingRecordsID = 0;
  796. int remoteParkingRecordsID = 0;
  797. Monitor.Monitor.localDBOper.Insert(list, out parkingRecordsID);
  798. bool remote_insert_record = Monitor.Monitor.remoteDBOper.Insert(list, out remoteParkingRecordsID);
  799. //Log.WriteLog(LogType.database, "insert, record: \n" + parkingRecordsSql);
  800. //查询记录ID号
  801. //string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
  802. //QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
  803. //QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
  804. //更新车辆表
  805. if (parkingRecordsID != 0)
  806. {
  807. UpdateVehicle(license, 1, parkingRecordsID, true, false, parkingSpaceID);
  808. }
  809. if (remoteParkingRecordsID != 0)
  810. {
  811. UpdateVehicle(license, 1, remoteParkingRecordsID, true, true, parkingSpaceID);
  812. }
  813. Log.WriteLog(LogType.process, LogFile.INFO, "停车记录表已更新");
  814. //更新车位
  815. UpdateAllParkingSpace(false);
  816. //Monitor.Monitor.AddNotification("停车数据库已更新,等待流程结束状态清零。");
  817. //while (Monitor.Monitor.mainBlockInfo.processCompleted != 0)
  818. //{
  819. // Thread.Sleep(1000);
  820. //}
  821. Thread.Sleep(500);
  822. try { idLicMap.Remove(currentTerm); }
  823. catch { }
  824. Monitor.Monitor.SetNotification(license + " 数据库已更新,停车流程结束", parkMonitor.model.TextColor.Info);
  825. Log.WriteLog(LogType.process, LogFile.INFO, license + " 停车流程结束");
  826. Log.WriteLog(LogType.process, LogFile.INFO, "--------------------------------");
  827. }
  828. }
  829. }
  830. /// <summary>
  831. /// 预约车辆检测
  832. /// </summary>
  833. private static void ReservedCarCheck()
  834. {
  835. if (lockList.Count != terminalInfo.Count)
  836. {
  837. lockList.Clear();
  838. for (int i = 0; i < terminalInfo.Count; i++)
  839. {
  840. lockList.Add(false);
  841. }
  842. }
  843. for (int i = 0; i < terminalInfo.Count; i++)
  844. {
  845. //Console.WriteLine(i);
  846. //找到停车终端,且有地感无按钮数据,拍摄号牌
  847. if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 1 && terminalInfo[i].btnStatus == 0 && !lockList[i])
  848. {
  849. lockList[i] = true;
  850. Action<int> reserveAction = new Action<int>(ReservedOper);
  851. reserveAction(i);
  852. //找到停车终端,且无地感有按钮数据,空闲状态,清除按钮状态
  853. }
  854. else if (terminalInfo[i].terminalStatus == 1 && terminalInfo[i].groundStatus == 0 && terminalInfo[i].btnStatus != 0 && terminalInfo[i].cmd == 0)
  855. {
  856. TerminalStru ts = new TerminalStru
  857. {
  858. terminalID = terminalInfo[i].terminalID,
  859. paymentStatus = (short)-1,
  860. btnStatus = 0,
  861. cmd = (short)-1,
  862. licenseCodeA = -1,
  863. licenseCodeB = -1,
  864. licenseCodeC = -1,
  865. licenseCodeD = -1,
  866. receiptNum = -1
  867. };
  868. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  869. Log.WriteLog(LogType.process, LogFile.INFO, "清除按钮状态,写入PLC:" + ts.btnStatus);
  870. lockList[i] = false;
  871. }
  872. //else if (lockList[i] && terminalInfo[i].terminalID == 1)
  873. //{
  874. // Log.WriteLog(LogType.process, LogFile.INFO, "停车终端,根据地感号牌获取中......");
  875. //}
  876. }
  877. }
  878. private static void ReservedOper(int index)
  879. {
  880. Task.Factory.StartNew(() =>
  881. {
  882. string license = "";
  883. int countdown = 5;
  884. short registered = 4;
  885. while (license == "" && countdown-- > 0)
  886. {
  887. license = Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
  888. }
  889. if (license != "")
  890. {
  891. Monitor.Monitor.SetNotification(terminalInfo[index].terminalID + "号车位收到地感,拍到" + license, parkMonitor.model.TextColor.Log);
  892. //map中加入或更新号牌,供完成时写入数据库用
  893. if (idLicMap.ContainsKey(terminalInfo[index].terminalID))
  894. {
  895. idLicMap[terminalInfo[index].terminalID] = license;
  896. }
  897. else
  898. {
  899. idLicMap.Add(terminalInfo[index].terminalID, license);
  900. }
  901. if (Monitor.Monitor.webServer.ReservedCarCheck(license))
  902. {
  903. registered = 3;
  904. Monitor.Monitor.SetNotification("预约车辆入场", parkMonitor.model.TextColor.Info);
  905. }
  906. #region 通过数据库查询是否预约车,方法待定
  907. //int vehicleState = -1;
  908. //string vehicleStateCheckSql = "select vehiclepParkState from vehicle where numberPlate = '" + license + "';";
  909. //MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(vehicleStateCheckSql);
  910. //if (reader != null)
  911. //{
  912. // try
  913. // {
  914. // if (reader.Read())
  915. // {
  916. // vehicleState = reader.GetInt32("vehiclepParkState");
  917. // }
  918. // }
  919. // catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约检测,查询车辆状态异常"); ; Console.WriteLine(e.Message); };
  920. // try
  921. // {
  922. // reader.Close();
  923. // reader.Dispose();
  924. // }
  925. // catch { }
  926. //}
  927. //已预约车辆入场
  928. //if (vehicleState == 4)
  929. //{
  930. // registered = 3;
  931. //}
  932. #endregion
  933. TerminalStru ts = new TerminalStru
  934. {
  935. terminalID = terminalInfo[index].terminalID,
  936. paymentStatus = (short)-1,
  937. btnStatus = registered,
  938. cmd = (short)-1,
  939. licenseCodeA = -1,
  940. licenseCodeB = -1,
  941. licenseCodeC = -1,
  942. licenseCodeD = -1,
  943. receiptNum = -1
  944. };
  945. Monitor.Monitor.PLC.WriteToPLC(ts, PLCDataType.terminal);
  946. Monitor.Monitor.SetNotification("指令写入PLC:" + ts.btnStatus, parkMonitor.model.TextColor.Log);
  947. Log.WriteLog(LogType.process, LogFile.INFO, "指令写入PLC:" + ts.btnStatus);
  948. Thread.Sleep(1000);
  949. lockList[index] = false;
  950. }
  951. else
  952. {
  953. Monitor.Monitor.SetNotification("收到地感后,尝试5次未拍到号牌。", parkMonitor.model.TextColor.Log);
  954. Log.WriteLog(LogType.process, LogFile.ERROR, "收到地感后,尝试5次未拍到号牌。");
  955. Thread.Sleep(10000);
  956. lockList[index] = false;
  957. }
  958. });
  959. }
  960. private static void UpdateLedForBarrier()
  961. {
  962. for (int i = 0; i < terminalInfo.Count; i++)
  963. {
  964. // 停车终端,收到地感,尚无停车指令,提示扫描结果
  965. bool condition = terminalInfo[i].terminalStatus == (short)1 && terminalInfo[i].groundStatus == (short)1 && terminalInfo[i].cmd != 1;
  966. int scanState = -1;
  967. switch (terminalInfo[i].terminalID)
  968. {
  969. case 1:
  970. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm1; break;
  971. case 2:
  972. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm2; break;
  973. case 3:
  974. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm3; break;
  975. case 4:
  976. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm4; break;
  977. case 5:
  978. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm5; break;
  979. case 6:
  980. scanState = Monitor.Monitor.PLCScanInfo.scanStateTerm6; break;
  981. }
  982. if (scanState != -1)
  983. {
  984. LedDisplay(terminalInfo[i].terminalID, scanState, condition);
  985. }
  986. }
  987. }
  988. private static void LedDisplay(int termID, int state, bool condition)
  989. {
  990. if (Monitor.Monitor.allInOneMachine.boardList.Count >= termID)
  991. {
  992. if (state != Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState)
  993. {
  994. if (state == 0)
  995. {
  996. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("欢迎光临智象停车", 60, 0, 5);
  997. Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState = state;
  998. }
  999. else if (condition)
  1000. {
  1001. Monitor.Monitor.allInOneMachine.boardList[termID - 1].ledScanState = state;
  1002. switch (state)
  1003. {
  1004. //case 0:
  1005. // Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("欢迎光临", 60, 2);
  1006. // //Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1007. // break;
  1008. case 1:
  1009. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("车辆位置正常", 60, 2, 5);
  1010. //Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1011. break;
  1012. case 2:
  1013. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("前超界,请向后移动", 30, 2, 5);
  1014. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(1, 30, 2);
  1015. break;
  1016. case 3:
  1017. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("后超界,请向前移动", 30, 2, 5);
  1018. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(0, 30, 2);
  1019. break;
  1020. case 4:
  1021. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("左超界,请向右移动", 30, 2, 5);
  1022. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(3, 30, 2);
  1023. break;
  1024. case 5:
  1025. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("右超界,请向左移动", 30, 2, 5);
  1026. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(2, 30, 2);
  1027. break;
  1028. case 6:
  1029. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("检测中,请稍候", 30, 2, 5);
  1030. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1031. break;
  1032. }
  1033. }
  1034. }
  1035. }
  1036. }
  1037. /// <summary>
  1038. /// 停车相关操作
  1039. /// 0.观测到地感信号,且按钮状态不为3,则启动号牌机获取号牌,并判断是否预约车
  1040. /// 1.读取到号牌机启动指令,启动号牌机并根据是否注册用户进行操作
  1041. /// 非注册拿到号牌后记录并告知plc
  1042. /// 注册用户,核对号牌与用户关联信息
  1043. /// 2.停车流程结束,写数据库
  1044. /// </summary>
  1045. ///
  1046. private static void ParkProcess()
  1047. {
  1048. Task.Factory.StartNew(() =>
  1049. {
  1050. while (!isClosing)
  1051. {
  1052. ParkNumSubProcess();
  1053. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1054. }
  1055. });
  1056. Task.Factory.StartNew(() =>
  1057. {
  1058. while (!isClosing)
  1059. {
  1060. ParkCompleteSubProcess();
  1061. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1062. }
  1063. });
  1064. Task.Factory.StartNew(() =>
  1065. {
  1066. try
  1067. {
  1068. while (!isClosing)
  1069. {
  1070. ReservedCarCheck();
  1071. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1072. }
  1073. }
  1074. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "预约异常," + e.Message + ", " + e.StackTrace); }
  1075. Log.WriteLog(LogType.process, LogFile.ERROR, "预约线程退出");
  1076. });
  1077. Task.Factory.StartNew(() =>
  1078. {
  1079. while (!isClosing)
  1080. {
  1081. UpdateLedForBarrier();
  1082. Thread.Sleep(Monitor.Monitor.plcRefreshInterval * 5);
  1083. }
  1084. });
  1085. }
  1086. /// <summary>
  1087. /// 根据凭证号查询停车记录
  1088. /// </summary>
  1089. /// <param name="receipt"></param>
  1090. /// <param name="recordID"></param>
  1091. /// <param name="userID"></param>
  1092. /// <param name="license"></param>
  1093. /// <param name="realParkTime"></param>
  1094. private static bool FindLocalParkingRecord(int receipt, out int recordID, out int userID, out string license, out string realParkTime)
  1095. {
  1096. recordID = 0;
  1097. userID = 0;
  1098. license = "";
  1099. realParkTime = "";
  1100. bool result = false;
  1101. string parkRecordsSql = "select parkingRecordsID,userID,numberPlate,realParkTime from parkingrecords where receiptNum = " + receipt + ";";
  1102. MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(parkRecordsSql);
  1103. try
  1104. {
  1105. if (reader != null && reader.Read())
  1106. {
  1107. object[] receiver = new object[4];
  1108. reader.GetValues(receiver);
  1109. recordID = (int)receiver[0];
  1110. userID = (int)receiver[1];
  1111. license = (string)receiver[2];
  1112. realParkTime = (string)receiver[3];
  1113. result = true;
  1114. }
  1115. else
  1116. {
  1117. Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号" + receipt + "查询停车记录失败");
  1118. Monitor.Monitor.SetNotification("取车流程, 根据凭证号查询停车记录失败", parkMonitor.model.TextColor.Error);
  1119. result = false;
  1120. }
  1121. //if (reader != null)
  1122. //{
  1123. // reader.Close();
  1124. // reader.Dispose();
  1125. //}
  1126. }
  1127. catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号" + receipt + "查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
  1128. try
  1129. {
  1130. if (reader != null)
  1131. {
  1132. reader.Close();
  1133. reader.Dispose();
  1134. }
  1135. }
  1136. catch { }
  1137. if (result)
  1138. Log.WriteLog(LogType.process, LogFile.INFO, "根据凭证号查询停车记录成功");
  1139. return result;
  1140. }
  1141. private static bool FindRemoteParkingRecord(int receipt, out int recordID)
  1142. {
  1143. recordID = 0;
  1144. bool result = false;
  1145. string remoteParkRecordsSql = "select parkingRecordsID from parkingrecords where receiptNum = " + receipt + ";";
  1146. //Log.WriteLog(LogType.database, "find record: \n");
  1147. MySqlDataReader reader = Monitor.Monitor.remoteDBOper.Query(remoteParkRecordsSql);
  1148. //Log.WriteLog(LogType.database, "find record: \n" + remoteParkRecordsSql);
  1149. try
  1150. {
  1151. if (reader != null && reader.Read())
  1152. {
  1153. object[] receiver = new object[1];
  1154. reader.GetValues(receiver);
  1155. recordID = (int)receiver[0];
  1156. result = true;
  1157. }
  1158. }
  1159. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1160. try
  1161. {
  1162. if (reader != null)
  1163. {
  1164. reader.Close();
  1165. reader.Dispose();
  1166. }
  1167. }
  1168. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1169. return result;
  1170. }
  1171. /// <summary>
  1172. /// 根据号牌获取本地与远端用户VIP月卡及预约信息
  1173. /// </summary>
  1174. /// <param name="license"></param>
  1175. /// <param name="orderRecordsID"></param>
  1176. /// <param name="monthCardType"></param>
  1177. /// <param name="monthCardTimeLength"></param>
  1178. /// <param name="orderTimeLength"></param>
  1179. /// <returns></returns>
  1180. private static bool FindVipInfo(string license, ref int orderRecordsID, ref int monthCardType, ref TimeSpan monthCardTimeLength, ref TimeSpan orderTimeLength)
  1181. {
  1182. bool result = true;
  1183. string monthCardTime = "";
  1184. //本地VIP信息
  1185. string vipInfoSql = "select orderRecordsID,monthCardType,monthCardTime from vehicle where numberPlate = '" + license + "';";
  1186. MySqlDataReader reader = null;
  1187. try
  1188. {
  1189. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  1190. if (reader != null && reader.Read())
  1191. {
  1192. object[] receiver = new object[3];
  1193. reader.GetValues(receiver);
  1194. Console.WriteLine(receiver[2].GetType());
  1195. if (!receiver[0].GetType().Equals(typeof(DBNull)))
  1196. {
  1197. orderRecordsID = (int)receiver[0];
  1198. }
  1199. if (!receiver[1].GetType().Equals(typeof(DBNull)))
  1200. {
  1201. monthCardType = (int)(UInt32)receiver[1];
  1202. }
  1203. if (!receiver[2].GetType().Equals(typeof(DBNull)))
  1204. {
  1205. monthCardTime = (string)receiver[2];
  1206. }
  1207. //orderRecordsID = (Int32)receiver[0];
  1208. //monthCardType = (Int32)receiver[1];
  1209. //monthCardTime = (string)receiver[2];
  1210. monthCardTimeLength = DateTime.Parse(monthCardTime) - DateTime.Now;
  1211. if (monthCardTimeLength.TotalHours <= 0)
  1212. {
  1213. monthCardType = 0;
  1214. }
  1215. Log.WriteLog(LogType.process, LogFile.INFO, "已获取本地预约与月卡信息");
  1216. }
  1217. }
  1218. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1219. try
  1220. {
  1221. if (reader != null)
  1222. {
  1223. reader.Close();
  1224. reader.Dispose();
  1225. }
  1226. }
  1227. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1228. //云端VIP信息
  1229. try
  1230. {
  1231. reader = Monitor.Monitor.remoteDBOper.Query(vipInfoSql);
  1232. if (reader != null && reader.Read())
  1233. {
  1234. object[] receiver = new object[3];
  1235. reader.GetValues(receiver);
  1236. int cardType = (int)(UInt32)receiver[1];
  1237. string CardTime = (string)receiver[2];
  1238. TimeSpan t = DateTime.Parse(CardTime) - DateTime.Now;
  1239. //云端
  1240. if (t.TotalHours > 0 && cardType > monthCardType)
  1241. {
  1242. monthCardType = cardType;
  1243. monthCardTimeLength = t;
  1244. }
  1245. Log.WriteLog(LogType.process, LogFile.INFO, "已获取云端预约与月卡信息");
  1246. }
  1247. }
  1248. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1249. try
  1250. {
  1251. if (reader != null)
  1252. {
  1253. reader.Close();
  1254. reader.Dispose();
  1255. }
  1256. }
  1257. catch (Exception e) { Console.WriteLine(e.Message); result = false; }
  1258. //有预约记录,判断记录有效性,有效则获取预约时长
  1259. if (orderRecordsID != 0)
  1260. {
  1261. //修改orderTimeLength
  1262. string orderInfoSql = "select bookHour from orderrecords where orderRecordsID = '" + orderRecordsID + "';";
  1263. try
  1264. {
  1265. reader = Monitor.Monitor.localDBOper.Query(vipInfoSql);
  1266. if (reader != null && reader.Read())
  1267. {
  1268. orderTimeLength = new TimeSpan(reader.GetInt32("bookHour"), 0, 0);
  1269. }
  1270. }
  1271. catch { }
  1272. }
  1273. try
  1274. {
  1275. if (reader != null)
  1276. {
  1277. reader.Close();
  1278. reader.Dispose();
  1279. }
  1280. }
  1281. catch (Exception e) { Console.WriteLine(e.Message); }
  1282. return result;
  1283. }
  1284. /// <summary>
  1285. /// 预约与停车费用计算
  1286. /// </summary>
  1287. /// <param name="scheme"></param>
  1288. /// <param name="parkTime"></param>
  1289. /// <param name="orderTimeLength"></param>
  1290. /// <returns></returns>
  1291. private static int FeeCalc(PaymentScheme scheme, DateTime parkTime, TimeSpan orderTimeLength)
  1292. {
  1293. try
  1294. {
  1295. int orderFee = scheme.bookCharge * (int)orderTimeLength.TotalHours;
  1296. int parkFee = 0;
  1297. int hours = (int)(DateTime.Now - parkTime).TotalHours;
  1298. switch (scheme.schemeType)
  1299. {
  1300. //按时计费
  1301. case 1:
  1302. if (hours > scheme.firstChargeTime + scheme.freeTime)
  1303. {
  1304. if (hours > 24)
  1305. {
  1306. parkFee = hours / 24 * scheme.upperBound + Math.Min(scheme.intervalCharge * (hours % 24) / scheme.chargeInterval, scheme.upperBound);
  1307. }
  1308. else
  1309. {
  1310. parkFee = Math.Min(scheme.firstCharge + scheme.intervalCharge * hours / scheme.chargeInterval, scheme.upperBound);
  1311. }
  1312. }
  1313. else if (hours > scheme.freeTime)
  1314. {
  1315. parkFee = scheme.firstCharge;
  1316. }
  1317. else
  1318. {
  1319. parkFee = 0;
  1320. }
  1321. break;
  1322. //按次计费
  1323. case 2:
  1324. //Console.WriteLine(DateTime.Now.Date.ToString()+","+ parkTime.Date.ToString());
  1325. int overnightCount = (DateTime.Now.Date - parkTime.Date).Days;
  1326. parkFee = scheme.eachCharge + overnightCount * scheme.overnightCharge;
  1327. break;
  1328. //按时间段计费
  1329. case 3:
  1330. TimeSpan currentTimeOfDay = DateTime.Now.TimeOfDay;
  1331. TimeSpan parkTimeOfDay = parkTime.TimeOfDay;
  1332. TimeSpan startTimeOfDay = DateTime.Parse(scheme.startChargeTime).TimeOfDay;
  1333. TimeSpan endTimeOfDay = DateTime.Parse(scheme.endChargeTime).TimeOfDay;
  1334. double countingHoursOfDay = endTimeOfDay.TotalHours - startTimeOfDay.TotalHours;
  1335. int days = (int)((DateTime.Now - parkTime).TotalHours - currentTimeOfDay.TotalHours + parkTimeOfDay.TotalHours);
  1336. int previousOffset = (int)(-(Math.Max(0, parkTimeOfDay.TotalHours - startTimeOfDay.TotalHours)));
  1337. int currentOffset = (int)Math.Min((currentTimeOfDay.TotalHours - startTimeOfDay.TotalHours), countingHoursOfDay);
  1338. int peakTimeLength = days * (int)countingHoursOfDay + previousOffset + currentOffset;
  1339. parkFee = peakTimeLength * scheme.chargeStandard + ((int)((DateTime.Now - parkTime).TotalHours) - peakTimeLength) * scheme.intervalCharge;
  1340. break;
  1341. }
  1342. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用" + parkFee);
  1343. return parkFee;
  1344. }
  1345. catch (Exception e) { Console.WriteLine("费用计算异常"); return -1; }
  1346. }
  1347. /// <summary>
  1348. /// 取车计费子操作
  1349. /// </summary>
  1350. private static void FetchFeeCalcSubProcess()
  1351. {
  1352. int receiptNum = 0;
  1353. int termIndex = -1;
  1354. bool failed = false;
  1355. TerminalStru ts = new TerminalStru();
  1356. for (int i = 0; i < terminalInfo.Count; i++)
  1357. {
  1358. ts = terminalInfo[i];
  1359. termIndex = ts.terminalID;
  1360. receiptNum = ts.receiptNum;
  1361. //取车状态、凭证号不为空,查询数据库计费
  1362. //Console.WriteLine((termIndex != -1) + "," + (termUsedMap.Count >= termIndex) + "," + termUsedMap.TryGetValue(termIndex, out bool valuee) + "," + (!valuee) + "," + (fetchState == 1) + "," + (receiptNum != 0));
  1363. bool value = false;
  1364. if (termIndex != -1 && termCalcMap.Count >= termIndex && termCalcMap.TryGetValue(termIndex, out value) && !value && ts.cmd == 2 && receiptNum != 0)
  1365. {
  1366. if (!Monitor.Monitor.globalStatus)
  1367. {
  1368. Monitor.Monitor.SetNotification("取车计费系统已暂停,请检查无误后手动开启", parkMonitor.model.TextColor.Warning);
  1369. ClearTerminal(termIndex, true);
  1370. Thread.Sleep(5000);
  1371. return;
  1372. }
  1373. //fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1374. Monitor.Monitor.SetNotification(termIndex + "号终端准备计算费用", parkMonitor.model.TextColor.Log);
  1375. termCalcMap[termIndex] = true;
  1376. //Console.WriteLine("终端编号" + termIndex);
  1377. int parkingRecordsID = 0;
  1378. int remoteParkingRecordsID = 0;
  1379. int userID = 0;
  1380. string license = "";
  1381. string realParkTime = "";
  1382. //1.根据凭证号查询停车记录
  1383. if (!FindLocalParkingRecord(receiptNum, out parkingRecordsID, out userID, out license, out realParkTime))
  1384. {
  1385. failed = true;
  1386. //return;
  1387. }
  1388. else
  1389. {
  1390. FindRemoteParkingRecord(receiptNum, out remoteParkingRecordsID);
  1391. }
  1392. //本地存在号牌,后续操作
  1393. //2.根据号牌查询车辆月卡信息与预约记录
  1394. int orderRecordsID = 0;
  1395. int monthCardType = -1;
  1396. string monthCardTime = "";
  1397. TimeSpan monthCardTimeLength = new TimeSpan(0);
  1398. TimeSpan orderTimeLength = new TimeSpan(0);
  1399. if (license != "")
  1400. {
  1401. bool getVIP = FindVipInfo(license, ref orderRecordsID, ref monthCardType, ref monthCardTimeLength, ref orderTimeLength);
  1402. //Log.WriteLog(LogType.database, "get vip: " + getVIP);
  1403. }
  1404. if (monthCardType == -1) monthCardType = 0;
  1405. //3.获取停车时刻,根据用户类型计费发送给PLC,暂认为无预约
  1406. DateTime parkTime = DateTime.Now, currentTime = DateTime.Now;
  1407. try
  1408. {
  1409. parkTime = DateTime.Parse(realParkTime);
  1410. }
  1411. catch { failed = true; }
  1412. int fee = 32767;
  1413. if (failed) { monthCardType = 0; }
  1414. if (PaymentScheme.ins != null)
  1415. {
  1416. if (monthCardTimeLength.TotalHours > 0)
  1417. {
  1418. fee = 0;
  1419. }
  1420. else if (failed)
  1421. {
  1422. fee = 0;
  1423. }
  1424. else
  1425. {
  1426. fee = FeeCalc(PaymentScheme.ins, parkTime, orderTimeLength);
  1427. }
  1428. try
  1429. {
  1430. if (Monitor.Monitor.PLC != null)
  1431. {
  1432. TerminalStru FeeMsg = new TerminalStru();
  1433. FeeMsg.terminalID = (short)termIndex;
  1434. FeeMsg.paymentStatus = (short)-1;
  1435. FeeMsg.licVerification = (short)-1;
  1436. FeeMsg.parkingFee = (short)fee;
  1437. FeeMsg.userType = (short)(monthCardType + 1);
  1438. Console.WriteLine(FeeMsg);
  1439. Monitor.Monitor.PLC.WriteToPLC(FeeMsg, PLCDataType.central);
  1440. Log.WriteLog(LogType.process, LogFile.INFO, "停车费用已发送至PLC");
  1441. }
  1442. }
  1443. catch { Console.WriteLine("error"); }
  1444. }
  1445. Monitor.Monitor.SetNotification("用户类型:" + (monthCardType + 1) + ",费用:" + fee + ",等待凭证号被清除且流程结束后更新车辆状态", parkMonitor.model.TextColor.Log);
  1446. FetchInfo fetchInfo = new FetchInfo(license, parkingRecordsID, remoteParkingRecordsID, fee, receiptNum);
  1447. if (!fetchInfoMap.ContainsKey(termIndex))
  1448. {
  1449. fetchInfoMap.Add(termIndex, fetchInfo);
  1450. fetchCompleteMap.Add(termIndex, true);
  1451. }
  1452. else
  1453. {
  1454. fetchInfoMap[termIndex] = fetchInfo;
  1455. fetchCompleteMap[termIndex] = true;
  1456. }
  1457. }
  1458. }
  1459. }
  1460. private static void FetchCompleteProcess()
  1461. {
  1462. int fetchState = Monitor.Monitor.mainBlockInfo.fetchingRunning;
  1463. int termID = -1;
  1464. try
  1465. {
  1466. if (fetchState == 1)
  1467. {
  1468. //找到当前取车终端
  1469. for (int i = 0; i < terminalInfo.Count; i++)
  1470. {
  1471. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID && Monitor.Monitor.mainBlockInfo.terminalID != 0)
  1472. {
  1473. termID = terminalInfo[i].terminalID;
  1474. break;
  1475. }
  1476. }
  1477. if (fetchCompleteMap.ContainsKey(termID) && fetchCompleteMap[termID])
  1478. {
  1479. fetchCompleteMap[termID] = false;
  1480. Task.Factory.StartNew(() =>
  1481. {
  1482. //4.等待终端获得收费完成信号且将凭证号清除后,清除收费完成信号并将信息写入数据库
  1483. int count = 0;
  1484. while (!isClosing && termID != -1)
  1485. {
  1486. if (Monitor.Monitor.mainBlockInfo.processStopped == 1 || !Monitor.Monitor.globalStatus)
  1487. {
  1488. Log.WriteLog(LogType.process, LogFile.INFO, "取车流程中断");
  1489. Monitor.Monitor.SetNotification("取车流程中断", parkMonitor.model.TextColor.Warning);
  1490. ClearTerminal(termID, false);
  1491. //停车流程确保已清除中控块完成信号
  1492. Thread.Sleep(500);
  1493. ResetCompleteSignal();
  1494. break;
  1495. }
  1496. if (Monitor.Monitor.mainBlockInfo.processCompleted == 1)
  1497. {
  1498. if (Monitor.Monitor.allInOneMachine.boardList.Count >= termID)
  1499. {
  1500. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateText("取车完成,请将车辆驶离车库,智象停车祝您一路顺风。", 60, 2);
  1501. Monitor.Monitor.allInOneMachine.boardList[termID - 1].UpdateArrow(-1, 2, 0);
  1502. }
  1503. UpdateSpecificParkingSpace();
  1504. //while (terminalInfo[termIndex].receiptNum != 0)
  1505. //{
  1506. // count++;
  1507. // if (count == 1)
  1508. // Monitor.Monitor.SetNotification("等待凭证号清除", parkMonitor.model.TextColor.Log);
  1509. // if (count > 10000)//避免int型数据溢出
  1510. // count = 2;
  1511. // Thread.Sleep(200);
  1512. //}
  1513. int paymentStatus = 0;
  1514. for (int i = 0; i < terminalInfo.Count; i++)
  1515. {
  1516. if (terminalInfo[i].terminalID == Monitor.Monitor.mainBlockInfo.terminalID)
  1517. {
  1518. paymentStatus = terminalInfo[i].paymentStatus;
  1519. break;
  1520. }
  1521. }
  1522. //Log.WriteLog(LogType.process, LogFile.INFO, "检测到凭证号已被清除");
  1523. FetchInfo fi = null;
  1524. ClearTerminal(termID, false);
  1525. //停车流程确保已清除中控块完成信号
  1526. Thread.Sleep(500);
  1527. ResetCompleteSignal();
  1528. UpdateAllParkingSpace(false);
  1529. if (fetchInfoMap.ContainsKey(termID))
  1530. {
  1531. fi = fetchInfoMap[termID];
  1532. }
  1533. else
  1534. {
  1535. Monitor.Monitor.SetNotification("未查询到该取车终端存在计费操作", parkMonitor.model.TextColor.Error);
  1536. Log.WriteLog(LogType.process, LogFile.ERROR, "终端" + termID + "无计费操作");
  1537. return;
  1538. }
  1539. //TerminalStru fetchReset = new TerminalStru
  1540. //{
  1541. // terminalID = (short)termIndex,
  1542. // paymentStatus = (short)0,
  1543. // licVerification = (short)0,
  1544. // parkingFee = (short)32767,
  1545. // userType = (short)0
  1546. //};
  1547. //Monitor.Monitor.PLC.WriteToPLC(fetchReset, PLCDataType.central);
  1548. //更新停车记录与车辆状态
  1549. string updateParkingRecordsSql = "update parkingrecords set parkingRecordsState = 6,realGetTime = '" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
  1550. "',parkingPrice = " + fi.fee + ",paymentStatus = " + paymentStatus + " where receiptNum = '" + fi.receiptNum + "';";
  1551. List<string> list = new List<string>();
  1552. list.Add(updateParkingRecordsSql);
  1553. lock (Monitor.Monitor.localDBOper)
  1554. {
  1555. Monitor.Monitor.localDBOper.UpdateTransaction(list);
  1556. UpdateVehicle(fi.license, 0, fi.parkingRecordsID, false, false, 0);
  1557. }
  1558. lock (Monitor.Monitor.remoteDBOper)
  1559. {
  1560. //Log.WriteLog(LogType.database, "update fetch record: " + updateParkingRecordsSql);
  1561. Monitor.Monitor.remoteDBOper.UpdateTransaction(list);
  1562. UpdateVehicle(fi.license, 0, fi.remoteParkingRecordsID, false, true, 0);
  1563. }
  1564. Monitor.Monitor.SetNotification(fi.license + " 取车流程结束", parkMonitor.model.TextColor.Info);
  1565. Log.WriteLog(LogType.process, LogFile.INFO, fi.license + " 取车流程结束");
  1566. Log.WriteLog(LogType.process, LogFile.INFO, "--------------------------------");
  1567. break;
  1568. }
  1569. Thread.Sleep(200);
  1570. }
  1571. termCalcMap[termID] = false;
  1572. fetchInfoMap.Remove(termID);
  1573. fetchCompleteMap.Remove(termID);
  1574. });
  1575. }
  1576. }
  1577. }
  1578. catch (Exception ex) { Log.WriteLog(LogType.process, LogFile.ERROR, "取车完成流程异常," + ex.StackTrace); }
  1579. }
  1580. /// <summary>
  1581. /// 取车相关操作
  1582. ///
  1583. /// </summary>
  1584. private static void FetchProcess()
  1585. {
  1586. Task.Factory.StartNew(() =>
  1587. {
  1588. while (!isClosing)
  1589. {
  1590. FetchFeeCalcSubProcess();
  1591. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1592. }
  1593. });
  1594. Task.Factory.StartNew(() =>
  1595. {
  1596. while (!isClosing)
  1597. {
  1598. FetchCompleteProcess();
  1599. Thread.Sleep(Monitor.Monitor.plcRefreshInterval);
  1600. }
  1601. });
  1602. }
  1603. public static void Start()
  1604. {
  1605. for (int i = 0; i < Monitor.Monitor.plcTerminalCount; i++)
  1606. {
  1607. lockList.Add(false);
  1608. }
  1609. ResetCompleteSignal();
  1610. ParkProcess();
  1611. FetchProcess();
  1612. //定时更新云端车位,5min
  1613. Task.Factory.StartNew(() =>
  1614. {
  1615. while (!isClosing)
  1616. {
  1617. UpdateAllParkingSpace(true);
  1618. Thread.Sleep(300000);
  1619. }
  1620. });
  1621. }
  1622. public static void Stop()
  1623. {
  1624. isClosing = true;
  1625. }
  1626. public class FetchInfo
  1627. {
  1628. public string license;
  1629. public int parkingRecordsID;
  1630. public int remoteParkingRecordsID;
  1631. public int fee;
  1632. public int receiptNum;
  1633. public FetchInfo(string license, int parkingRecordsID, int remoteParkingRecordsID, int fee, int receiptNum)
  1634. {
  1635. this.license = license;
  1636. this.parkingRecordsID = parkingRecordsID;
  1637. this.remoteParkingRecordsID = remoteParkingRecordsID;
  1638. this.fee = fee;
  1639. this.receiptNum = receiptNum;
  1640. }
  1641. }
  1642. }
  1643. }