Monitor.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. using BroadcastModule;
  2. using centralController.advert;
  3. using centralController.WebServer;
  4. using db;
  5. using Monitor;
  6. using MySql.Data.MySqlClient;
  7. using NumMachine;
  8. using parkMonitor.language;
  9. using parkMonitor.LOG;
  10. using parkMonitor.model;
  11. using PLCS7;
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.Management;
  17. using System.Net;
  18. using System.Text;
  19. using System.Threading;
  20. using System.Threading.Tasks;
  21. using System.Windows.Forms;
  22. namespace Monitor
  23. {
  24. public class Monitor : IMonitor
  25. {
  26. /// <summary>
  27. /// 监控模块单例
  28. /// </summary>
  29. public static Monitor ins { get; set; }
  30. /// <summary>
  31. /// 中控系统总状态
  32. /// </summary>
  33. public static bool globalStatus = false;
  34. /// <summary>
  35. /// 初始化步骤
  36. /// </summary>
  37. public static int initializeState = 0;
  38. /// <summary>
  39. /// PLC对象句柄
  40. /// </summary>
  41. public static AbstractPLCLinker PLC = null;
  42. public static string plcIPAddr { get; set; }
  43. public static int plcRack { get; set; }
  44. public static int plcSlot { get; set; }
  45. public static string[] plcDatablockConfig { get; set; }
  46. public static int plcTerminalCount { get; set; }
  47. public static int plcParkingSpaceCount { get; set; }
  48. public static int plcRefreshInterval { get; set; }
  49. public static MainBlockStru mainBlockInfo { get; set; }
  50. public static List<ParkingSpaceStru> parkingSpaceInfo { get; set; }
  51. public static ErrorInfoStru PLCErrorInfo { get; set; }
  52. public static ScanInfoStru PLCScanInfo { get;set; }
  53. /// <summary>
  54. /// 远程数据库操作句柄
  55. /// </summary>
  56. public static DBOperation remoteDBOper;
  57. /// <summary>
  58. /// 本地数据库操作句柄
  59. /// </summary>
  60. public static DBOperation localDBOper;
  61. /// <summary>
  62. /// 显示板操作对象句柄
  63. /// </summary>
  64. public static BroadcastBoardManager allInOneMachine;
  65. public static string[] allInOneMachineIP { get; set; }
  66. public static int[] allInOneMachinePort { get; set; }
  67. /// <summary>
  68. /// 号牌机操作句柄
  69. /// </summary>
  70. public static NumMachineLinker numMachineLinker;
  71. public static IntPtr flpHandle;
  72. /// <summary>
  73. /// 本地web操作句柄
  74. /// </summary>
  75. public static IWebServer webServer;
  76. public static int webPort { get; set; }
  77. /// <summary>
  78. /// 广告路径
  79. /// </summary>
  80. public static string advertPath { get; set; }
  81. public static AdvertManager advertMgr;
  82. public static centralController.centralController mainWin { get; set; }
  83. public static string defaultLic{get;set;}
  84. /// <summary>
  85. /// 车库层数
  86. /// </summary>
  87. public static int floors { get; set; }
  88. /// <summary>
  89. /// 每层分块数
  90. /// </summary>
  91. public static int rows { get; set; }
  92. /// <summary>
  93. /// 每块车位数
  94. /// </summary>
  95. public static int spacesInRow { get; set; }
  96. /// <summary>
  97. /// 系统初始化器句柄
  98. /// </summary>
  99. internal static SystemInitializer sysInitializer;
  100. /// <summary>
  101. /// 系统关闭状态
  102. /// </summary>
  103. public static bool isClosing;
  104. /// <summary>
  105. /// 车库ID
  106. /// </summary>
  107. public static int garageID;
  108. /// <summary>
  109. /// PLC读取锁
  110. /// </summary>
  111. public static object PLCReadLock = new object();
  112. /// <summary>
  113. /// 是否初始化PLC数据更新次数的计数,重连PLC后初始化该值以刷新车位
  114. /// </summary>
  115. public static bool updateCount = false;
  116. /// <summary>
  117. /// 将显示在界面的提示字符串
  118. /// </summary>
  119. private static Queue<string> notificationQueue = new Queue<string>();
  120. private const int MAXLINES = 80;
  121. private void PLCUpdate()
  122. {
  123. int linkCount = 0;
  124. int count = 0;
  125. bool disconnected = false;
  126. while (!isClosing)
  127. {
  128. if (updateCount)
  129. {
  130. count = 0;
  131. updateCount = false;
  132. }
  133. if (count > 50)
  134. count = 3;
  135. count++;
  136. if (PLC != null)
  137. {
  138. if (PLC.isConnected)
  139. {
  140. if (disconnected) {disconnected = false; SetNotification("PLC已重新连接",TextColor.Info); }
  141. linkCount = 0;
  142. lock (PLCReadLock)
  143. {
  144. List<object> received = PLC.ReadFromPLC(PLCDataType.terminal, 0);
  145. //首先获取所有终端信息
  146. try
  147. {
  148. //终端总数相同
  149. if (Terminal.Terminal.terminalInfo.Count == plcTerminalCount)
  150. {
  151. for (int i = 0; i < plcTerminalCount; i++)
  152. {
  153. //一旦发现差异立刻更新
  154. if (!Terminal.Terminal.terminalInfo[i].Equals(received[i]))
  155. {
  156. Terminal.Terminal.terminalInfo[i] = (TerminalStru)received[i];
  157. }
  158. }
  159. }
  160. else
  161. {
  162. //初始化终端信息列表
  163. Terminal.Terminal.terminalInfo.Clear();
  164. for (int i = 0; i < plcTerminalCount; i++)
  165. {
  166. Terminal.Terminal.terminalInfo.Add((TerminalStru)received[i]);
  167. if (!Terminal.Terminal.termCalcMap.ContainsKey(((TerminalStru)received[i]).terminalID))
  168. Terminal.Terminal.termCalcMap.Add(((TerminalStru)received[i]).terminalID, false);
  169. else
  170. Terminal.Terminal.termCalcMap[((TerminalStru)received[i]).terminalID] = false;
  171. }
  172. }
  173. }
  174. catch (Exception ex) { Console.WriteLine("PLC监控终端数据," + ex.Message); }
  175. //接下来获取中控监控信息
  176. try
  177. {
  178. received = PLC.ReadFromPLC(PLCDataType.central, 0);
  179. if (received.Count > 0 && !mainBlockInfo.Equals(received[0]))
  180. {
  181. mainBlockInfo = (MainBlockStru)received[0];
  182. }
  183. }
  184. catch (Exception ex) { Console.WriteLine("PLC监控中控数据," + ex.Message); }
  185. //接下来获取错误监控信息
  186. try
  187. {
  188. received = PLC.ReadFromPLC(PLCDataType.errorInfo, 0);
  189. if (received.Count > 0 && !PLCErrorInfo.Equals(received[0]))
  190. {
  191. PLCErrorInfo = (ErrorInfoStru)received[0];
  192. }
  193. }
  194. catch (Exception ex) { Console.WriteLine("PLC监控错误信息数据," + ex.Message); }
  195. //接下来获取电子围栏扫描信息
  196. try
  197. {
  198. received = PLC.ReadFromPLC(PLCDataType.scanInfo, 0);
  199. if (received.Count > 0 && !PLCScanInfo.Equals(received[0]))
  200. {
  201. PLCScanInfo = (ScanInfoStru)received[0];
  202. }
  203. }
  204. catch (Exception ex) { Console.WriteLine("PLC监控扫描信息数据," + ex.Message); }
  205. //最后获得所有车位信息
  206. if (count < 10 && count % 5 == 0)
  207. {
  208. try
  209. {
  210. received = PLC.ReadFromPLC(PLCDataType.parkingSpace, 0);
  211. //Console.WriteLine(parkingSpaceInfo.Count+","+ plcParkingSpaceCount);
  212. //车位总数相同
  213. if (parkingSpaceInfo.Count == plcParkingSpaceCount)
  214. {
  215. for (int i = 0; i < plcParkingSpaceCount; i++)
  216. {
  217. //一旦发现差异立刻更新
  218. if (!parkingSpaceInfo[i].Equals(received[i]))
  219. {
  220. parkingSpaceInfo[i] = (ParkingSpaceStru)received[i];
  221. }
  222. }
  223. }
  224. else
  225. {
  226. parkingSpaceInfo.Clear();
  227. for (int i = 0; i < plcParkingSpaceCount; i++)
  228. {
  229. parkingSpaceInfo.Add((ParkingSpaceStru)received[i]);
  230. }
  231. }
  232. }
  233. catch (Exception ex) { Console.WriteLine("PLC监控车位数据," + ex.Message); }
  234. }
  235. }
  236. }
  237. else
  238. {
  239. linkCount += 1;
  240. if (linkCount == 1)
  241. {
  242. disconnected = true;
  243. SetNotification("PLC掉线,请检查连接",TextColor.Warning);
  244. }else if (linkCount == 5)
  245. {
  246. Terminal.Terminal.terminalInfo.Clear();
  247. parkingSpaceInfo.Clear();
  248. mainBlockInfo = new MainBlockStru();
  249. }
  250. }
  251. }
  252. Thread.Sleep(300);
  253. }
  254. }
  255. /// <summary>
  256. /// CPU名
  257. /// </summary>
  258. /// <returns></returns>
  259. private static string getCPUName()
  260. {
  261. try
  262. {
  263. string str = string.Empty;
  264. ManagementClass mcCPU = new ManagementClass("Win32_Processor");
  265. ManagementObjectCollection mocCPU = mcCPU.GetInstances();
  266. foreach (ManagementObject m in mocCPU)
  267. {
  268. string name = m["Name"].ToString();
  269. return name;
  270. }
  271. }
  272. catch { }
  273. return "";
  274. }
  275. /// <summary>
  276. /// 操作系统版本
  277. /// </summary>
  278. private static string getOsVersion()
  279. {
  280. string str = "Windows 10";
  281. try
  282. {
  283. string hdId = string.Empty;
  284. ManagementClass hardDisk = new ManagementClass("Win32_OperatingSystem");
  285. ManagementObjectCollection hardDiskC = hardDisk.GetInstances();
  286. foreach (ManagementObject m in hardDiskC)
  287. {
  288. str = m["Name"].ToString().Split('|')[0].Replace("Microsoft", "").Trim();
  289. break;
  290. }
  291. }
  292. catch
  293. {
  294. }
  295. return str;
  296. }
  297. /// <summary>
  298. /// 显卡名
  299. /// </summary>
  300. private static string getGPUName()
  301. {
  302. string result = "";
  303. try
  304. {
  305. ManagementClass hardDisk = new ManagementClass("Win32_VideoController");
  306. ManagementObjectCollection hardDiskC = hardDisk.GetInstances();
  307. foreach (ManagementObject m in hardDiskC)
  308. {
  309. result = m["VideoProcessor"].ToString();
  310. break;
  311. }
  312. }
  313. catch
  314. {
  315. }
  316. return result;
  317. }
  318. /// <summary>
  319. /// 获取系统内存大小
  320. /// </summary>
  321. private static string getMenSize()
  322. {
  323. ManagementObjectSearcher searcher = new ManagementObjectSearcher(); //用于查询一些如系统信息的管理对象
  324. searcher.Query = new SelectQuery("Win32_PhysicalMemory", "", new string[] { "Capacity" });//设置查询条件
  325. ManagementObjectCollection collection = searcher.Get(); //获取内存容量
  326. ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();
  327. long capacity = 0;
  328. while (em.MoveNext())
  329. {
  330. ManagementBaseObject baseObj = em.Current;
  331. if (baseObj.Properties["Capacity"].Value != null)
  332. {
  333. try
  334. {
  335. capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
  336. }
  337. catch
  338. {
  339. return "-GB";
  340. }
  341. }
  342. }
  343. int gb = 1024 * 1024 * 1024;
  344. return ((double)capacity / gb).ToString("0.0") + "GB";
  345. }
  346. //************************************ 公有方法 **********************************
  347. public Monitor(centralController.centralController mainWin, IntPtr flpHandle)
  348. {
  349. Monitor.mainWin = mainWin;
  350. Monitor.flpHandle = flpHandle;
  351. parkingSpaceInfo = new List<ParkingSpaceStru>();
  352. mainBlockInfo = new MainBlockStru();
  353. }
  354. ///// <summary>
  355. ///// 获取提示信息
  356. ///// </summary>
  357. ///// <returns></returns>
  358. //public string GetNotification()
  359. //{
  360. // StringBuilder notificationStr = new StringBuilder();
  361. // lock (notificationQueue)
  362. // {
  363. // string[] strs = notificationQueue.ToArray();
  364. // Array.Reverse(strs);
  365. // for (int i = 0; i < strs.Length; i++)
  366. // {
  367. // notificationStr.Append(strs[i]);
  368. // }
  369. // //Queue<string>.Enumerator notiEnumer = notificationQueue.GetEnumerator();
  370. // //while (notiEnumer.MoveNext())
  371. // //{
  372. // // notificationStr.Append(notiEnumer.Current);
  373. // //}
  374. // }
  375. // return notificationStr.ToString();
  376. //}
  377. /// <summary>
  378. /// 添加提示信息
  379. /// </summary>
  380. /// <param name="notification"></param>
  381. public static void SetNotification(string notification, TextColor textColor=TextColor.Log)
  382. {
  383. if (notification == "clear")
  384. {
  385. //lock (notificationQueue)
  386. //{
  387. // notificationQueue.Clear();
  388. //}
  389. if (mainWin != null)
  390. {
  391. mainWin.Invoke(new Action(() => {
  392. mainWin.UpdateText(notification, textColor,MAXLINES);
  393. }));
  394. }
  395. return;
  396. }
  397. else
  398. {
  399. string time = DateTime.Now + "\r\n";
  400. string notificationStr = time + notification + "\r\n";
  401. //lock (notificationQueue)
  402. //{
  403. // int count = notificationQueue.Count;
  404. // if (count >= MAXLINES)
  405. // {
  406. // notificationQueue.Dequeue();
  407. // }
  408. // notificationQueue.Enqueue(notificationStr);
  409. //}
  410. if (mainWin != null)
  411. {
  412. mainWin.Invoke(new Action(() => {
  413. mainWin.UpdateText(notificationStr, textColor, MAXLINES);
  414. }));
  415. }
  416. }
  417. }
  418. /// <summary>
  419. /// 返回系统信息字符串
  420. /// </summary>
  421. /// <returns></returns>
  422. public static string GetSysInfo()
  423. {
  424. string info = "";
  425. Language lng = Language.ins;
  426. try
  427. {
  428. string endl = "\r\n";
  429. info += endl + lng.autoPackSys + " " + lng.centralPort + endl + endl;
  430. info += lng.version + ":" + SysConst.version() + endl + endl;
  431. info += lng.hostNmae + ":" + Dns.GetHostName() + endl + endl;
  432. info += lng.os + ":" + getOsVersion() + endl + endl;
  433. info += lng.cpu + ":" + getCPUName() + endl + endl;
  434. info += lng.mem + ":" + getMenSize() + endl + endl;
  435. info += lng.gpu + ":" + getGPUName() + endl + endl;
  436. }
  437. catch (Exception) { }
  438. return info;
  439. }
  440. /// <summary>
  441. /// 返回关于我们信息字符串
  442. /// </summary>
  443. /// <returns></returns>
  444. public static string GetAboutInfo()
  445. {
  446. return Language.ins.aboutWinText;
  447. }
  448. /// <summary>
  449. /// 返回停车记录信息
  450. /// </summary>
  451. /// <returns></returns>
  452. public static List<object[]> GetParkingRecords(string license = "", string startTime = "", string endTime = "")
  453. {
  454. DateTime now = DateTime.Now;
  455. List<object[]> result = new List<object[]>();
  456. string getParkingRecordsSql = "";
  457. if (startTime == "" || endTime == "")
  458. {
  459. DateTime yesterday = DateTime.Now - (new TimeSpan(1, 0, 0, 0));
  460. DateTime twoDaysAgo = DateTime.Now - (new TimeSpan(2, 0, 0, 0));
  461. getParkingRecordsSql = "select parkingRecordsID,userID,numberPlate,parkingSpaceID,realParkTime,realGetTime,receiptNum,parkingPrice,paymentStatus " +
  462. "from parkingrecords where numberPlate " + (license == "" ? "like '%" : "= '" + license) + "' and (realParkTime like '" + now.ToString("yyyy-MM-dd") + "%' or realParkTime like '" + yesterday.ToString("yyyy-MM-dd") + "%' or realParkTime like '" + twoDaysAgo.ToString("yyyy-MM-dd") + "%');";
  463. }
  464. else
  465. {
  466. getParkingRecordsSql = "select parkingRecordsID,userID,numberPlate,parkingSpaceID,realParkTime,realGetTime,receiptNum,parkingPrice,paymentStatus " +
  467. "from parkingrecords where numberPlate " + (license == "" ? "like '%" : "= '" + license) + "' and realParkTime >= '" + startTime + "' and realParkTime <= '" + endTime + "';";
  468. }
  469. if (localDBOper != null)
  470. {
  471. lock (localDBOper)
  472. {
  473. MySqlDataReader reader = localDBOper.Query(getParkingRecordsSql);
  474. try
  475. {
  476. while (reader != null && reader.Read())
  477. {
  478. if (reader.HasRows)
  479. {
  480. object[] temp = new object[reader.FieldCount];
  481. reader.GetValues(temp);
  482. result.Add(temp);
  483. }
  484. }
  485. }
  486. catch (Exception e) { Console.WriteLine(e.Message); }
  487. try
  488. {
  489. if (reader != null)
  490. {
  491. reader.Close();
  492. reader.Dispose();
  493. }
  494. }
  495. catch (Exception e) { Console.WriteLine(e.Message); }
  496. }
  497. }
  498. result.Reverse();
  499. return result;
  500. }
  501. /// <summary>
  502. /// 返回预约记录信息
  503. /// </summary>
  504. /// <returns></returns>
  505. public static List<object[]> GetOrderRecords(bool localDB, string license="", string startTime = "", string endTime = "")
  506. {
  507. DateTime now = DateTime.Now;
  508. List<object[]> result = new List<object[]>();
  509. string getOrderRecordsSql = "";
  510. if (startTime == "" || endTime == "")
  511. {
  512. DateTime yesterday = DateTime.Now - (new TimeSpan(1, 0, 0, 0));
  513. DateTime twoDaysAgo = DateTime.Now - (new TimeSpan(2, 0, 0, 0));
  514. getOrderRecordsSql = "select orderRecordsID,userID,numberPlate,bookParkTime,cancelBookTime,bookFetchTime,bookHour,bookPrice,bookState " +
  515. "from orderrecords where numberPlate " + (license == "" ? "like '%" : "= '" + license) + "' and (bookParkTime like '" + now.ToString("yyyy-MM-dd") +
  516. "%' or bookParkTime like '" + yesterday.ToString("yyyy-MM-dd") + "%' or bookFetchTime like '" + now.ToString("yyyy-MM-dd") + "%' or bookFetchTime like '" + yesterday.ToString("yyyy-MM-dd") + "%');";
  517. }
  518. else
  519. {
  520. getOrderRecordsSql = "select orderRecordsID,userID,numberPlate,bookParkTime,cancelBookTime,bookFetchTime,bookHour,bookPrice,bookState " +
  521. "from orderrecords where numberPlate " + (license == "" ? "like '%" : "= '" + license) + "' and ((bookParkTime >= '" + startTime + "' and bookParkTime <= '" + endTime + "') or (bookFetchTime >= '" + startTime + "' and bookFetchTime <= '" + endTime + "'));";
  522. }
  523. if (localDBOper != null)
  524. {
  525. lock (localDBOper)
  526. {
  527. MySqlDataReader reader;
  528. if (localDB)
  529. reader = localDBOper.Query(getOrderRecordsSql);
  530. else
  531. reader = remoteDBOper.Query(getOrderRecordsSql);
  532. try
  533. {
  534. while (reader != null && reader.Read())
  535. {
  536. if (reader.HasRows)
  537. {
  538. object[] temp = new object[reader.FieldCount];
  539. reader.GetValues(temp);
  540. result.Add(temp);
  541. }
  542. }
  543. }
  544. catch (Exception e) { Console.WriteLine(e.Message); }
  545. try
  546. {
  547. if (reader != null)
  548. {
  549. reader.Close();
  550. reader.Dispose();
  551. }
  552. }
  553. catch (Exception e) { Console.WriteLine(e.Message); }
  554. }
  555. }
  556. result.Reverse();
  557. return result;
  558. }
  559. /// <summary>
  560. /// 更新停车记录关于支付的信息
  561. /// </summary>
  562. /// <param name="license"></param>
  563. /// <param name="receiptNum"></param>
  564. /// <param name="parkingFee"></param>
  565. /// <param name="paymentStatus"></param>
  566. /// <returns></returns>
  567. public static bool UpdateParkingRecords(string license, string receiptNum, string parkingFee, string paymentStatus, bool local)
  568. {
  569. bool result = false;
  570. string updateRecordsSql = "update parkingrecords set parkingPrice = " + parkingFee + " ,paymentStatus = " + paymentStatus + " where numberPlate = '" + license + "' and receiptNum = " + receiptNum+";";
  571. List<string> updateList = new List<string>();
  572. updateList.Add(updateRecordsSql);
  573. if (local && localDBOper != null)
  574. {
  575. lock (localDBOper)
  576. {
  577. try
  578. {
  579. result = localDBOper.UpdateTransaction(updateList);
  580. }
  581. catch { Log.WriteLog(LogType.database, "更新本地停车记录中支付信息出现异常。\n" + updateRecordsSql); return false; }
  582. }
  583. }else if(!local && remoteDBOper != null)
  584. {
  585. lock (remoteDBOper)
  586. {
  587. try
  588. {
  589. result = remoteDBOper.UpdateTransaction(updateList);
  590. }
  591. catch { Log.WriteLog(LogType.database, "更新云端记录中支付信息出现异常。\n" + updateRecordsSql); return false; }
  592. }
  593. }
  594. return result;
  595. }
  596. /// <summary>
  597. /// 更新终端停车费用,便于车辆放行
  598. /// </summary>
  599. /// <returns></returns>
  600. public static bool UpdateTermFeeStatus(string receiptNum)
  601. {
  602. for (int i = 0; i < Terminal.Terminal.terminalInfo.Count; i++)
  603. {
  604. if(Terminal.Terminal.terminalInfo[i].receiptNum.ToString() == receiptNum)
  605. {
  606. if(Terminal.Terminal.terminalInfo[i].terminalStatus==2 && Terminal.Terminal.terminalInfo[i].paymentStatus == 3)
  607. {
  608. TerminalStru tsFromCentral = new TerminalStru
  609. {
  610. terminalID = (short)Terminal.Terminal.terminalInfo[i].terminalID,
  611. parkingFee = (short)-1,
  612. receiptNum = -1,
  613. paymentStatus = 3,
  614. };
  615. PLC.WriteToPLC(tsFromCentral, PLCDataType.central);
  616. return true;
  617. }
  618. else
  619. {
  620. SetNotification((Terminal.Terminal.terminalInfo[i].terminalStatus == 1 ? "停车" : "非取车状态")+"终端,支付状态:"+ Terminal.Terminal.terminalInfo[i].paymentStatus+",不进行修改",TextColor.Warning);
  621. Log.WriteLog(LogType.process,LogFile.ERROR, (Terminal.Terminal.terminalInfo[i].terminalStatus == 1 ? "停车" : "非取车状态") + "终端,支付状态:" + Terminal.Terminal.terminalInfo[i].paymentStatus + ",不进行修改");
  622. return false;
  623. }
  624. }
  625. }
  626. SetNotification("未找到待修改终端", TextColor.Warning);
  627. Log.WriteLog(LogType.process, LogFile.ERROR, "未找到待修改终端");
  628. return false;
  629. }
  630. /// <summary>
  631. /// 返回空闲正常车位数
  632. /// </summary>
  633. /// <param name="state">状态:0.空闲与保留,1.空闲,2.保留,3.预约车位总数</param>
  634. /// <returns></returns>
  635. public int GetFreeSpaceCount(int state)
  636. {
  637. int freeSpaceCount = 0;
  638. int bookableSpaceCount = 0;
  639. int bookedSpaceCount = 0;
  640. if(state == 3)
  641. {
  642. return mainBlockInfo.reserveTotalSpace;
  643. }
  644. try
  645. {
  646. if (parkingSpaceInfo != null)
  647. {
  648. foreach (ParkingSpaceStru psStru in parkingSpaceInfo)
  649. {
  650. if (psStru.spaceStatus == 3)
  651. bookedSpaceCount++;
  652. if (psStru.spaceStatus != 1 && psStru.spaceStatus != 3)
  653. {
  654. freeSpaceCount++;
  655. if (psStru.spaceStatus == 2)
  656. bookableSpaceCount++;
  657. }
  658. }
  659. }
  660. }
  661. catch { Console.WriteLine("空闲车位数,计数异常");return 0; }
  662. switch (state)
  663. {
  664. case 0:
  665. return freeSpaceCount;//0+2
  666. case 1:
  667. return freeSpaceCount - bookableSpaceCount;//0
  668. case 2:
  669. return bookableSpaceCount;//2
  670. case 4:
  671. return bookedSpaceCount + bookableSpaceCount;//2+3
  672. default:
  673. return freeSpaceCount;
  674. }
  675. }
  676. /// <summary>
  677. /// 暂未使用,查询本地数据库返回可预约车位数
  678. /// </summary>
  679. /// <returns></returns>
  680. //public int GetBookableSpaceCount()
  681. //{
  682. // int bookableSpaceCount = 0;
  683. // string bookableSpaceSql = "select currentBookableSpace from garageproperties where garageID = " + garageID + ";";
  684. // if (localDBOper != null)
  685. // {
  686. // MySqlDataReader reader = localDBOper.Query(bookableSpaceSql);
  687. // if (reader != null)
  688. // {
  689. // try
  690. // {
  691. // if (reader.Read() && reader.HasRows)
  692. // {
  693. // bookableSpaceCount = reader.GetInt32("currentBookableSpace");
  694. // }
  695. // }
  696. // catch { }
  697. // try
  698. // {
  699. // reader.Close();
  700. // reader.Dispose();
  701. // }
  702. // catch { }
  703. // }
  704. // }
  705. // return bookableSpaceCount;
  706. //}
  707. /// <summary>
  708. /// 系统初始化,启动plc监控
  709. /// </summary>
  710. public void Start()
  711. {
  712. if (flpHandle != IntPtr.Zero)
  713. {
  714. //初始化系统
  715. if (sysInitializer == null)
  716. {
  717. sysInitializer = new SystemInitializer();
  718. }
  719. Task.Factory.StartNew(() =>
  720. {
  721. sysInitializer.Init(flpHandle);
  722. });
  723. //更新PLC数据
  724. Thread PLCUpdateThread = new Thread(PLCUpdate);
  725. PLCUpdateThread.Start();
  726. //System.Windows.Forms.Timer PLCUpdateTimer = new System.Windows.Forms.Timer();
  727. //PLCUpdateTimer.Interval = 300;
  728. //PLCUpdateTimer.Tick += new EventHandler(PLCUpdate);
  729. //PLCUpdateTimer.Start();
  730. }
  731. }
  732. /// <summary>
  733. /// 系统停止
  734. /// </summary>
  735. public void Stop()
  736. {
  737. sysInitializer.Stop();
  738. System.Environment.Exit(0);
  739. }
  740. }
  741. //public class ParkingRecord
  742. //{
  743. // int parkingRecordsID;
  744. // int userID;
  745. // string numberPlate;
  746. // int parkingSpaceID;
  747. //}
  748. }