Преглед изворни кода

界面提示长度限制,数据库dll提供返回插入记录ID功能,预约车辆非注册用户停车则改为普通用户停车。预约审核机制debug,增加中间步骤提示与记录

yc_t пре 6 година
родитељ
комит
2bf73d5b88

+ 1 - 1
PLCLinker/centralController/App.config

@@ -9,7 +9,7 @@
     <!--<add key="remoteDBConnStr" value="Data Source=59.175.148.85;port=3306;uid=root;pooling=true;max pool size=1024;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;"/>-->
     <!--<add key="remoteDBConnStr" value="Data Source=192.168.111.61;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>-->
     <!--<add key="remoteDBConnStr" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;max pool size=1024;pwd=yct;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>-->
-    <add key="remoteDBConnStr" value="Data Source=192.168.0.121;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>
+    <add key="remoteDBConnStr" value="Data Source=192.168.0.106;port=3306;uid=remote;pooling=true;max pool size=1024;pwd=x5;database=zxpark_cloud_2;CharSet=utf8;Allow Zero Datetime=true;"/>
     <add key="localDBConnStr" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;max pool size=1024;pwd=yct;database=zxpark_local;CharSet=utf8;Allow Zero Datetime=true;"/>
     <add key="DBtimeout" value="3"/>
     <!--号牌机信息-->

+ 14 - 4
PLCLinker/centralController/FormCentralController.cs

@@ -509,8 +509,20 @@ namespace centralController
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        public void UpdateText(string str, TextColor tc)
+        public void UpdateText(string str, TextColor tc, int maxlines)
         {
+            if (!rtb_notification.Focused)
+                rtb_notification.ScrollToCaret();
+            string[] strs = rtb_notification.Text.Split('\n');
+            //Console.WriteLine(strs.ToString());
+            if (strs.Length > maxlines*2)
+            {
+                string[] newStrs = new string[maxlines];
+                Array.Copy(strs, strs.Length - maxlines, newStrs, 0, maxlines);
+                string temp = String.Join("\n", newStrs);
+                rtb_notification.Text = temp;
+            }
+
             if (str == "clear")
             {
                 rtb_notification.Clear();
@@ -545,10 +557,8 @@ namespace centralController
                 }
                 rtb_notification.Select(index + appendingText.Length - 1, 0);
             }
-
             //rtb_notification.Text = Monitor.Monitor.ins.GetNotification();
-            if (!rtb_notification.Focused)
-                rtb_notification.ScrollToCaret();
+
         }
 
         /// <summary>

+ 13 - 8
PLCLinker/centralController/Monitor/Monitor.cs

@@ -96,7 +96,7 @@ namespace Monitor
         /// 将显示在界面的提示字符串
         /// </summary>
         private static Queue<string> notificationQueue = new Queue<string>();
-        private const int MAXLINES = 50;
+        private const int MAXLINES = 80;
 
         private void PLCUpdate()
         {
@@ -344,7 +344,7 @@ namespace Monitor
                 if (mainWin != null)
                 {
                     mainWin.Invoke(new Action(() => {
-                        mainWin.UpdateText(notification, textColor);
+                        mainWin.UpdateText(notification, textColor,MAXLINES);
                     }));
                 }
                 return;
@@ -365,7 +365,7 @@ namespace Monitor
                 if (mainWin != null)
                 {
                     mainWin.Invoke(new Action(() => {
-                        mainWin.UpdateText(notificationStr, textColor);
+                        mainWin.UpdateText(notificationStr, textColor, MAXLINES);
                     }));
                 }
             }
@@ -513,7 +513,8 @@ namespace Monitor
         public int GetFreeSpaceCount(int state)
         {
             int freeSpaceCount = 0;
-            int reservedSpaceCount = 0;
+            int bookableSpaceCount = 0;
+            int bookedSpaceCount = 0;
             if(state == 3)
             {
                 return mainBlockInfo.reserveTotalSpace;
@@ -524,11 +525,13 @@ namespace Monitor
                 {
                     foreach (ParkingSpaceStru psStru in parkingSpaceInfo)
                     {
+                        if (psStru.spaceStatus == 3)
+                            bookedSpaceCount++;
                         if (psStru.spaceStatus != 1 && psStru.spaceStatus != 3)
                         {
                             freeSpaceCount++;
                             if (psStru.spaceStatus == 2)
-                                reservedSpaceCount++;
+                                bookableSpaceCount++;
                         }
                     }
                 }
@@ -537,11 +540,13 @@ namespace Monitor
             switch (state)
             {
                 case 0:
-                    return freeSpaceCount;
+                    return freeSpaceCount;//0+2
                 case 1:
-                    return freeSpaceCount - reservedSpaceCount;
+                    return freeSpaceCount - bookableSpaceCount;//0
                 case 2:
-                    return reservedSpaceCount;
+                    return bookableSpaceCount;//2
+                case 4:
+                    return bookedSpaceCount + bookableSpaceCount;//2+3
                 default:
                     return freeSpaceCount;
             }

+ 77 - 64
PLCLinker/centralController/Terminal/Terminal.cs

@@ -76,51 +76,57 @@ namespace Terminal
             string province = header.Substring(0, 2);
             string provinceIndex = header.Substring(2);
             string provinceQuerySql = "select NumberPlateHeader from numberplatemapping where mappedString = " + province + ";";
-            lock (Monitor.Monitor.localDBOper)
+            if (province != "/0/0")
             {
-                //object[] result = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
-                MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
-                try
+                lock (Monitor.Monitor.localDBOper)
                 {
-                    if (reader != null && reader.Read() && reader.HasRows)
+                    //object[] result = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
+                    MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(provinceQuerySql);
+                    try
                     {
-                        province = reader.GetString("NumberPlateHeader");
-                        //Console.WriteLine(province);
+                        if (reader != null && reader.Read() && reader.HasRows)
+                        {
+                            province = reader.GetString("NumberPlateHeader");
+                            //Console.WriteLine(province);
+                        }
                     }
-                }
-                catch { }
-                try
-                {
-                    //if (result!=null && result.Length > 0) { province = (string)result[0]; }
-                    if (reader != null)
+                    catch { }
+                    try
                     {
-                        reader.Close();
-                        reader.Dispose();
+                        //if (result!=null && result.Length > 0) { province = (string)result[0]; }
+                        if (reader != null)
+                        {
+                            reader.Close();
+                            reader.Dispose();
+                        }
                     }
-                }
-                catch { }
+                    catch { }
 
+                }
+                return province + provinceIndex + identityA + identityB;
             }
-            return province + provinceIndex + identityA + identityB;
+            else
+                return "";
         }
         /// <summary>
         /// 更新所有车位信息
         /// </summary>
-        private static void UpdateAllParkingSpace()
+        private static void UpdateAllParkingSpace(bool remote)
         {
             string findParkingSpace = "select parkingSpaceID from parkingspace;";
             HashSet<int> recordsIDSet = new HashSet<int>();
-            lock (Monitor.Monitor.localDBOper)
+            DBOperation dbHandle = null;
+            if (!remote)
             {
-                //object[] result = Monitor.Monitor.localDBOper.Query(findParkingSpace);
-                //if(result!=null && result.Length > 0)
-                //{
-                //    for (int i = 0; i < result.Length; i++)
-                //    {
-                //        recordsIDSet.Add((int)result[i]);
-                //    }
-                //}
-                MySqlDataReader reader = Monitor.Monitor.localDBOper.Query(findParkingSpace);
+                dbHandle = Monitor.Monitor.localDBOper;
+            }
+            else
+            {
+                dbHandle = Monitor.Monitor.remoteDBOper;
+            }
+            lock (dbHandle)
+            {
+                MySqlDataReader reader = dbHandle.Query(findParkingSpace);
                 if (reader != null)
                 {
                     try
@@ -163,10 +169,10 @@ namespace Terminal
             }
             try
             {
-                lock (Monitor.Monitor.localDBOper)
+                lock (dbHandle)
                 {
-                    Monitor.Monitor.localDBOper.UpdateTransaction(updateSpaceList);
-                    Monitor.Monitor.localDBOper.Insert(insertSpaceList);
+                    dbHandle.UpdateTransaction(updateSpaceList);
+                    dbHandle.Insert(insertSpaceList, out int id);
                 }
             }
             catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "更新本地所有车位异常"); Console.WriteLine("更新本地所有车位异常" + e.Message); }
@@ -266,11 +272,11 @@ namespace Terminal
                         list.Add(insertVehicleWithState);
                         if (!remote)
                         {
-                            Monitor.Monitor.localDBOper.Insert(list);
+                            Monitor.Monitor.localDBOper.Insert(list, out int id);
                         }
                         else
                         {
-                            Monitor.Monitor.remoteDBOper.Insert(list);
+                            Monitor.Monitor.remoteDBOper.Insert(list, out int id);
                         }
                     }
                     try
@@ -431,7 +437,7 @@ namespace Terminal
                         //判断之前是否已拍摄号牌
                         if (!idLicMap.ContainsKey(terminalInfo[i].terminalID))
                         {
-                            license = "桂K88888"; //Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
+                            license = "";// "桂K88888"; //Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[i].terminalID);
                             Monitor.Monitor.SetNotification("启动" + terminalInfo[i].terminalID + "号号牌机,号牌:" + license, parkMonitor.model.TextColor.Info);
                         }
                         else
@@ -493,15 +499,23 @@ namespace Terminal
                             {
                                 int userID = term.licenseCodeA;
                                 string userLicense = GetLicenseFromTerm(term);
-                                //与云端数据比对
-                                ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
-                                if (numReceivedStatus == 2)
+                                //注册用户缺ID信息,转为普通用户停车
+                                if (userID == 0)
+                                {
+                                    term.btnStatus = 1;
+                                }
+                                else
                                 {
-                                    idLicMap.Remove(terminalInfo[i].terminalID);
+                                    //与云端数据比对
+                                    ValidateUserInfo(ts, userID, userLicense, out numReceivedStatus);
+                                    if (numReceivedStatus == 2)
+                                    {
+                                        idLicMap.Remove(terminalInfo[i].terminalID);
+                                    }
                                 }
                             }
                             //非注册用户
-                            else if (term.btnStatus == (short)1 || term.btnStatus == (short)4)
+                            if (term.btnStatus == (short)1 || term.btnStatus == (short)4)
                             {
                                 numReceivedStatus = 1;
                                 ts.licVerification = 1;
@@ -527,7 +541,7 @@ namespace Terminal
                                 Monitor.Monitor.SetNotification("号牌机启动指令已被清零", parkMonitor.model.TextColor.Info); break;
                             }
                             else
-                                Thread.Sleep(1000);
+                                Thread.Sleep(500);
                         }
 
                     }
@@ -535,10 +549,6 @@ namespace Terminal
             }
         }
         #endregion
-        //private static void ParkNumSubProcess()
-        //{
-
-        //}
         /// <summary>
         /// 停车流程,收到PLC停车完成信号后操作过程
         /// </summary>
@@ -598,21 +608,16 @@ namespace Terminal
                     }
                     List<string> list = new List<string>();
                     list.Add(parkingRecordsSql);
-                    Monitor.Monitor.localDBOper.Insert(list);
-                    Monitor.Monitor.remoteDBOper.Insert(list);
+
+                    Monitor.Monitor.localDBOper.Insert(list, out int parkingRecordsID);
+                    Monitor.Monitor.remoteDBOper.Insert(list, out int remoteParkingRecordsID);
                     Log.WriteLog(LogType.process, LogFile.INFO, "停车记录已插入," + license + "停在" + parkingSpaceID + ",凭证号:" + term.receiptNum);
                     Monitor.Monitor.SetNotification("停车记录已插入", parkMonitor.model.TextColor.Info);
-                    ////注册用户记录插入云端
-                    //if (term.btnStatus == 0)
-                    //{
-                    //Monitor.Monitor.remoteDBOper.Insert(list);
-                    //}
+
                     //查询记录ID号
-                    string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
-                    int parkingRecordsID = 0;
-                    int remoteParkingRecordsID = 0;
-                    QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
-                    QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
+                    //string findRecordSql = "select parkingRecordsID from parkingrecords where receiptNum = " + term.receiptNum + ";";
+                    //QueryParkingRecordsID(findRecordSql, out parkingRecordsID, false);
+                    //QueryParkingRecordsID(findRecordSql, out remoteParkingRecordsID, true);
                     //更新车辆表
                     if (parkingRecordsID != 0)
                     {
@@ -623,8 +628,8 @@ namespace Terminal
                         UpdateVehicle(license, 1, remoteParkingRecordsID, true, true, parkingSpaceID);
                     }
                     Log.WriteLog(LogType.process, LogFile.INFO, "停车记录表已更新");
-                    //更新本地车位
-                    UpdateAllParkingSpace();
+                    //更新车位
+                    UpdateAllParkingSpace(false);
                     //Monitor.Monitor.AddNotification("停车数据库已更新,等待流程结束状态清零。");
                     //while (Monitor.Monitor.mainBlockInfo.processCompleted != 0)
                     //{
@@ -672,7 +677,7 @@ namespace Terminal
                 short registered = 4;
                 while (license == "" && countdown-- > 0)
                 {
-                    license = "桂K88888"; //Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
+                    license = "";//"桂K88888"; //Monitor.Monitor.numMachineLinker.GetLicensePlate(terminalInfo[index].terminalID);
                 }
                 Monitor.Monitor.SetNotification(terminalInfo[index].terminalID + "号车位收到地感,拍到" + license, parkMonitor.model.TextColor.Log);
                 if (license != "")
@@ -811,7 +816,7 @@ namespace Terminal
                 }
                 else
                 {
-                    Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败");
+                    Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号"+ receipt + "查询停车记录失败");
                     Monitor.Monitor.SetNotification("取车流程, 根据凭证号查询停车记录失败", parkMonitor.model.TextColor.Error);
                     result = false;
                 }
@@ -821,7 +826,7 @@ namespace Terminal
                 //    reader.Dispose();
                 //}
             }
-            catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
+            catch (Exception e) { Log.WriteLog(LogType.process, LogFile.ERROR, "根据凭证号" + receipt + "查询停车记录失败"); Console.WriteLine(e.Message); result = false; }
             try
             {
                 if (reader != null)
@@ -1099,7 +1104,7 @@ namespace Terminal
                     }
                     catch { failed = true; }
                     int fee = 32767;
-                    if (failed) { monthCardType = -2; }
+                    if (failed) { monthCardType = 0; }
                     if (PaymentScheme.ins != null)
                     {
                         if (monthCardTimeLength.TotalHours > 0)
@@ -1200,7 +1205,7 @@ namespace Terminal
                                     }
                                     Log.WriteLog(LogType.process, LogFile.INFO, "检测到凭证号已被清除");
                                     FetchInfo fi = null;
-                                    UpdateAllParkingSpace();
+                                    UpdateAllParkingSpace(false);
                                     ClearTerminal(terminalInfo[termIndex].terminalID);
                                     if (fetchInfoMap.ContainsKey(terminalInfo[termIndex].terminalID))
                                     {
@@ -1286,6 +1291,14 @@ namespace Terminal
             }
             ParkProcess();
             FetchProcess();
+            //定时更新云端车位,5min
+            Task.Factory.StartNew(()=> {
+                while (!isClosing)
+                {
+                    UpdateAllParkingSpace(true);
+                    Thread.Sleep(300000);
+                }
+            });
         }
 
         public static void Stop()

+ 1 - 1
PLCLinker/centralController/WebServer/CentralForWebSocketServer.cs

@@ -197,7 +197,7 @@ namespace centralController.WebServer
             string insertSql = "";
             List<string> strs = new List<string>();
             strs.Add(insertSql);
-            Monitor.Monitor.localDBOper.Insert(strs);
+            Monitor.Monitor.localDBOper.Insert(strs, out int id);
         }
         private void DownloadAds()
         {

+ 93 - 71
PLCLinker/centralController/WebServer/WebServer.cs

@@ -1,5 +1,7 @@
 using centralController.model;
+using db;
 using nettyCommunication;
+using parkMonitor.LOG;
 using PLCS7;
 using System;
 using System.Collections.Generic;
@@ -81,28 +83,19 @@ namespace centralController.WebServer
             List<string> vehicleInsertList = new List<string>();
             vehicleUpdateList.Add(vehicleUpdateSql);
             vehicleInsertList.Add(vehicleInsertSql);
+            DBOperation dbHandle = null;
             if (localDB)
-            {
-                if (!Monitor.Monitor.localDBOper.Insert(vehicleInsertList))
-                {
-                    if (!Monitor.Monitor.localDBOper.UpdateTransaction(vehicleUpdateList))
-                        return false;
-                    else
-                        return true;
-                }
-                else return true;
-            }
+                dbHandle = Monitor.Monitor.localDBOper;
             else
+                dbHandle = Monitor.Monitor.remoteDBOper;
+            if (!dbHandle.UpdateTransaction(vehicleUpdateList))
             {
-                if (!Monitor.Monitor.remoteDBOper.Insert(vehicleInsertList))
-                {
-                    if (!Monitor.Monitor.remoteDBOper.UpdateTransaction(vehicleUpdateList))
-                        return false;
-                    else
-                        return true;
-                }
-                else return true;
+                if (!dbHandle.Insert(vehicleInsertList, out int id))
+                    return false;
+                else
+                    return true;
             }
+            else return true;
         }
         /// <summary>
         /// 插入预约记录
@@ -114,7 +107,7 @@ namespace centralController.WebServer
         /// <param name="orderTime"></param>
         /// <param name="orderLength"></param>
         /// <returns></returns>
-        private bool InsertOrderRecord(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength)
+        private bool InsertOrderRecord(bool localDB, string userID, bool parking, string license, string orderTime, int orderLength, out int id)
         {
             bool result = false;
             string orderRecordInsertSql;
@@ -131,13 +124,13 @@ namespace centralController.WebServer
             List<string> orderList = new List<string>();
             orderList.Add(orderRecordInsertSql);
             if (localDB)
-                result = Monitor.Monitor.localDBOper.Insert(orderList);
+                result = Monitor.Monitor.localDBOper.Insert(orderList, out id);
             else
-                result = Monitor.Monitor.remoteDBOper.Insert(orderList);
+                result = Monitor.Monitor.remoteDBOper.Insert(orderList, out id);
             return result;
         }
         /// <summary>
-        /// 找到当前预约记录ID
+        /// 找到当前预约记录ID,暂未使用
         /// </summary>
         /// <param name="localDB"></param>
         /// <param name="license"></param>
@@ -146,14 +139,18 @@ namespace centralController.WebServer
         private int FindCurrentOrderRecordID(bool localDB, string license, int latestIndex = 1)
         {
             int currentID = 0;
-            List<object[]> orderRecords = Monitor.Monitor.GetOrderRecords(localDB, license, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
-            if (orderRecords.Count != 0)
+            int count = 10;
+            while (count-- > 0 && currentID == 0)
             {
-                try
+                List<object[]> orderRecords = Monitor.Monitor.GetOrderRecords(localDB, license, DateTime.Now.ToString("yyyy-MM-dd"), DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));
+                if (orderRecords.Count != 0)
                 {
-                    currentID = (int)(UInt32)orderRecords[latestIndex - 1][0];
+                    try
+                    {
+                        currentID = (int)(UInt32)orderRecords[latestIndex - 1][0];
+                    }
+                    catch { }
                 }
-                catch { }
             }
             return currentID;
         }
@@ -171,9 +168,9 @@ namespace centralController.WebServer
         {
             UpdateVehicleState(localDB, parking ? 4 : 5, 0, license);
             //预约记录插入db
-            InsertOrderRecord(localDB, userID, parking, license, orderTime, orderLength);
-            //查询预约记录id号
-            int currentID = FindCurrentOrderRecordID(localDB, license);
+            InsertOrderRecord(localDB, userID, parking, license, orderTime, orderLength, out int currentID);
+            ////查询预约记录id号
+            //int currentID = FindCurrentOrderRecordID(localDB, license);
             if (currentID == 0) { /*反馈web,预约失败*/ return false; }
             //更新车辆状态
             UpdateVehicleState(localDB, parking ? 4 : 5, currentID, license);
@@ -190,15 +187,16 @@ namespace centralController.WebServer
             lock (waitToReserveLock)
             {
                 //可预约车位总数
-                allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(3);
+                allBookableSpace = Monitor.Monitor.ins.GetFreeSpaceCount(4);
                 count = 0;
                 DateTime start, end;
                 try
                 {
                     start = DateTime.Parse(msg.bookTime);
                     end = start.AddHours(msg.bookLength);
+                    //Console.WriteLine("--------"+msg.bookTime+","+msg.bookLength);
                 }
-                catch { return false; }
+                catch { Console.WriteLine("时间解析异常1"); return false; }
 
                 Queue<MessageUTF8>.Enumerator enumer = waitToReserveQueue.GetEnumerator();
                 while (enumer.MoveNext())
@@ -207,13 +205,31 @@ namespace centralController.WebServer
                     try
                     {
                         tempStart = DateTime.Parse(enumer.Current.bookTime);
-                        tempEnd = start.AddHours(enumer.Current.bookLength);
+                        tempEnd = tempStart.AddHours(enumer.Current.bookLength);
+                        //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
                     }
-                    catch { return false; }
+                    catch { Console.WriteLine("时间解析异常2"); return false; }
+                    //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
+                    //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
+                    if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
+                }
+                Queue<MessageUTF8>.Enumerator enumer2 = reservedQueue.GetEnumerator();
+                while (enumer2.MoveNext())
+                {
+                    DateTime tempStart, tempEnd;
+                    try
+                    {
+                        tempStart = DateTime.Parse(enumer2.Current.bookTime);
+                        tempEnd = tempStart.AddHours(enumer2.Current.bookLength);
+                        //Console.WriteLine("#########" + enumer.Current.bookTime + "," + enumer.Current.bookLength);
+                    }
+                    catch { Console.WriteLine("时间解析异常2"); return false; }
+                    //Console.WriteLine("**********" + start.ToString() + "," + end.ToString() + "," + tempStart.ToString() + "," + tempEnd.ToString());
+                    //Console.WriteLine("**********" + ((tempStart - end).TotalMinutes > 0)+","+ ((start - tempEnd).TotalMinutes > 0));
                     if (!((tempStart - end).TotalMinutes > 0 || (start - tempEnd).TotalMinutes > 0)) { count += 1; }
                 }
             }
-            Console.WriteLine(msg.context+":"+allBookableSpace+","+count);
+            Console.WriteLine("----------" + msg.context + ":" + allBookableSpace + "," + count);
             if (allBookableSpace > count)
                 return true;
             else
@@ -245,14 +261,17 @@ namespace centralController.WebServer
                             }
                             else
                             {
+                                bool DBOperResult = true;
                                 lock (waitToReserveLock)
                                 {
                                     waitToReserveQueue.Enqueue(msg);
                                 }
                                 //预约记录与车辆状态写入数据库
-                                ReserveDBOperation(true, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
-                                ReserveDBOperation(false, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
+                                DBOperResult = DBOperResult && ReserveDBOperation(true, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
+                                DBOperResult = DBOperResult && ReserveDBOperation(false, msg.sender, true, msg.context, msg.bookTime, msg.bookLength);
                                 //回复成功给web
+                                if (!DBOperResult)
+                                    Log.WriteLog(LogType.process, LogFile.WARNING, "预约数据库操作未获得记录ID");
                                 returnMsg.cmd = "OK";
                                 returnMsg.garageID = Monitor.Monitor.garageID;
                                 returnMsg.context = msg.context;
@@ -261,6 +280,12 @@ namespace centralController.WebServer
                             }
                         }
                         break;
+
+                    case "CANCELRESERVE":
+                        //IEqualityComparer<MessageUTF8> comparer ; 
+                        //if(waitToReserveQueue.Contains(msg, )
+
+                        break;
                     //预约取
                     case "PREFETCH":
                         break;
@@ -313,34 +338,35 @@ namespace centralController.WebServer
             int countdown = 5;
             while (countdown-- > 0)
             {
-                if (Monitor.Monitor.mainBlockInfo.bookParkCmd != 0)
-                    Thread.Sleep(300);
-                else
+                if (Monitor.Monitor.mainBlockInfo.bookParkCmd != 0 && countdown>1)
                 {
-                    MainBlockStru mb = new MainBlockStru
+                    Thread.Sleep(300);
+                    if (countdown == 2)
                     {
-                        centralHearbeat = -1,
-                        bookParkCmd = parking ? (short)state : (short)-1,
-                        bookFetchCmd = !parking ? (short)state : (short)-1,
-                        licenseReceived = -1
-                    };
-                    Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
-                    Monitor.Monitor.SetNotification(mb.bookParkCmd + "," + mb.bookFetchCmd + "预约停车指令写入PLC", parkMonitor.model.TextColor.Log);
-                    break;
+                        Monitor.Monitor.SetNotification("未能获取预约指令位0状态,尝试手动清除", parkMonitor.model.TextColor.Warning);
+                        MainBlockStru mbs = new MainBlockStru
+                        {
+                            centralHearbeat = -1,
+                            bookParkCmd = parking ? (short)0 : (short)-1,
+                            bookFetchCmd = !parking ? (short)0 : (short)-1,
+                            licenseReceived = -1
+                        };
+                        Monitor.Monitor.PLC.WriteToPLC(mbs, PLCDataType.central);
+                        Thread.Sleep(500);
+                    }
+                    continue;
                 }
-                if (countdown == 2)
+                MainBlockStru mb = new MainBlockStru
                 {
-                    Monitor.Monitor.SetNotification("未能获取预约指令位0状态,尝试手动清除", parkMonitor.model.TextColor.Warning);
-                    MainBlockStru mb = new MainBlockStru
-                    {
-                        centralHearbeat = -1,
-                        bookParkCmd = parking ? (short)0 : (short)-1,
-                        bookFetchCmd = !parking ? (short)0 : (short)-1,
-                        licenseReceived = -1
-                    };
-                    Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
-                    Thread.Sleep(500);
-                }
+                    centralHearbeat = -1,
+                    bookParkCmd = parking ? (short)state : (short)-1,
+                    bookFetchCmd = !parking ? (short)state : (short)-1,
+                    licenseReceived = -1
+                };
+                Monitor.Monitor.PLC.WriteToPLC(mb, PLCDataType.central);
+                Monitor.Monitor.SetNotification(mb.bookParkCmd + "," + mb.bookFetchCmd + "; 预约停车指令写入PLC", parkMonitor.model.TextColor.Log);
+                Log.WriteLog(LogType.process, LogFile.INFO, mb.bookParkCmd + "," + mb.bookFetchCmd + "预约停车指令写入PLC");
+                break;
             }
         }
         /// <summary>
@@ -364,7 +390,6 @@ namespace centralController.WebServer
                             Console.WriteLine("当前时间差:" + ts.TotalMinutes + ",指令类型:" + msg.cmd);
                             if (ts.TotalMinutes >= 0)
                             {
-                                Console.WriteLine();
                                 //如果是预约停车,通知PLC减少一个可预约车位数
                                 if (msg.cmd == "RESERVE")
                                 {
@@ -395,6 +420,7 @@ namespace centralController.WebServer
                             if (ts.TotalMinutes > msg.bookLength * 60)
                             {
                                 Monitor.Monitor.SetNotification(msg.context + " 预约已超时", parkMonitor.model.TextColor.Warning);
+                                Log.WriteLog(LogType.process, LogFile.INFO, msg.context + " 预约已超时");
                                 //通知PLC将可预约车位数恢复一个
                                 SendBookCmd(true, 2);
                                 //恢复车辆状态
@@ -461,13 +487,9 @@ namespace centralController.WebServer
                         {
                             byte[] bytes = new byte[256];
                             MessageUTF8 msg = ((MessageUTF8)comm.ReceiveMessage(out bytes));
-                            string str = "";
-                            //for (int i = 0; i < bytes.Length &&bytes[i]!=0x00; i++)
-                            //{
-                            //    str += bytes[i] + " ";
-                            //}
-                            str = Encoding.Default.GetString(bytes);
-                            Console.WriteLine(str);
+                            //string str = "";
+                            //str = Encoding.Default.GetString(bytes);
+                            //Console.WriteLine(str);
                             if (msg != null)
                             {
                                 MsgHandling(msg);
@@ -544,8 +566,8 @@ namespace centralController.WebServer
                 int count = 12;
                 while (!isClosing)
                 {
-                    if (receiveMsg != null)
-                        Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
+                    //if (receiveMsg != null)
+                    //    Console.WriteLine(Connections.isAlive() + ", " + receiveMsg.ThreadState.ToString());
                     if (Connections.isAlive())
                     {
                         if (!connected)

BIN
PLCLinker/centralController/sdk/mysql/db.dll


+ 1 - 1
PLCLinker/centralController/serversettings.json

@@ -1,7 +1,7 @@
 {
 
   "ssl": "false",
-  "host": "192.168.0.121",
+  "host": "192.168.0.106",
   "garageID":"2",
   "port": "9000",
   "size": "1024"