Monitor.cs 30 KB

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