Browse Source

Merge remote-tracking branch 'jin's_repo_in_jin's_remote/master' into dev

yc_t 7 years ago
parent
commit
83b5523828

+ 1 - 1
parkMonitor/App.config

@@ -16,7 +16,7 @@
   </Equipments>
   <appSettings>
     <!--数据库连接配置文件-->
-    <add key="SqlConnectionLocation" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;pwd=yct;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
+    <add key="SqlConnectionLocation" value="Data Source=127.0.0.1;port=20000;uid=root;pooling=true;pwd=jingwang1995;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
     <!--<add key="SqlConnectionStr" value="Data Source=52.77.33.102;port=3306;uid=Ubuntu1;pooling=true;pwd=12345678;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->
     <add key="SqlConnectionStr" value="Data Source=59.175.148.85;port=3306;uid=root;pooling=true;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />
     <add key="localGarageId" value="1"/>

+ 32 - 1
parkMonitor/DataBase/DBOperation.cs

@@ -30,7 +30,7 @@ namespace parkMonitor.DataBase
             return garageFreeSpace;
         }
 
-        //查询车位位置及状态,返回list
+        //查询空闲车位位置
         public Dictionary<int, Parking_Space> GetParkingSpace(string connectionStr, int garageID)
         {
             Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
@@ -60,6 +60,37 @@ namespace parkMonitor.DataBase
             return lps;
         }
 
+        //查询所有车位位置及状态
+        public Dictionary<int, Parking_Space> GetAllParkingSpace(string connectionStr, int garageID)
+        {
+            Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where garageID = '" + garageID + "' ";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0 && reader.Read())
+            {
+                for (int i = 1; i <= count; i++)
+                {
+                    Parking_Space ps = new Parking_Space();
+                    ps.parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                    ps.parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                    ps.parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                    ps.parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
+                    ps.parkingSpaceState = reader.GetInt32("parkingSpaceState");
+                    ps.garageID = garageID;
+                    lps.Add(i, ps);
+                }
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return lps;
+        }
+
         //数据插入云记录表,并返回停车记录id
         public int InsertToParkingRecords(string connectionStr, int userID, string numberPlate, int parkingSpaceID, int garageID, int parkingRecordsState, string realParkTime)
         {

+ 1 - 0
parkMonitor/DataBase/Parking_Space.cs

@@ -16,5 +16,6 @@ namespace parkMonitor.DataBase
         public int parkingSpaceX { get; set; }
         public int parkingSpaceY { get; set; }
         public int parkingSpaceZ { get; set; }
+        public int parkingSpaceState { get; set; }
     }
 }

+ 28 - 29
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -120,35 +120,34 @@ namespace parkMonitor.server.CoreThread
             });
 
             //同步数据库
-            //Task.Factory.StartNew(() =>
-            //{
-            //    while (true)
-            //    {
-            //        try
-            //        {
-            //            //更新车库表车位数
-            //            int freeSpaceCount = locationOper.getGarageFreeSpace(localGarageId);
-            //            oper.UpdateGarageFreeSpace(freeSpaceCount, localGarageId);
-            //            //更新车位状态                       
-            //            int[] parkingSpace = locationOper.GetAllParkingSpaceID(localGarageId);
-            //            if (parkingSpace != null)
-            //            {
-            //                //两种解决方法:
-            //                //1.加配置文件,每个车库的起始车位ID
-            //                //2.Dictionary<>
-            //                for (int i = 0; i < parkingSpace.Length; i++)
-            //                {
-            //                    oper.UpdateParkingSpaceState(i, parkingSpace[i]);
-            //                }
-            //            }
-            //        }
-            //        catch (Exception)
-            //        {
-            //            Console.WriteLine("无同步数据");
-            //        }
-            //        Thread.Sleep(8000);
-            //    }
-            //});
+            Task.Factory.StartNew(() =>
+            {
+                while (true)
+                {
+                    try
+                    {
+                        //更新车库表车位数
+                        int freeSpaceCount = oper.getGarageFreeSpace("SqlConnectionLocation",localGarageId);
+                        oper.UpdateGarageFreeSpace("SqlConnectionStr",freeSpaceCount, localGarageId);
+                        //更新车位状态                       
+                        //int[] parkingSpace = oper.GetAllParkingSpaceID(localGarageId);
+                        Dictionary<int, Parking_Space> lps = oper.GetAllParkingSpace("SqlConnectionLocation", localGarageId);
+                        if (lps != null)
+                        {
+                            //Dictionary<>
+                            for (int i = 0; i < lps.Count; i++)
+                            {
+                                oper.UpdateParkingSpaceState("SqlConnectionStr", lps[i].parkingSpaceID,lps[i].parkingSpaceState);
+                            }
+                        }
+                    }
+                    catch (Exception)
+                    {
+                        Console.WriteLine("无同步数据");
+                    }
+                    Thread.Sleep(8000);
+                }
+            });
         }
 
         /// <summary>挂起</summary>