浏览代码

数据库结构调整

yc_t 7 年之前
父节点
当前提交
ecb1d3ac21

+ 6 - 2
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"/>
@@ -66,7 +66,7 @@
     <add key="licenseTime" value="30" />
     <add key="userTime" value="30" />
     <!--上位机(Web线程)IP地址及配置serverScoket的端口-->
-    <add key="WebConfig" value="192.168.111.254:9000" />
+    <add key="WebConfig" value="192.168.111.84:9000" />
     <!--<add key ="WebConfig" value="127.0.0.1:9000"/>-->
 
     <!--车库入口-->
@@ -81,6 +81,10 @@
     <!--位置编号;基点横坐标;车位宽度;宽度补偿-->
     <add key="192.168.0.20" value="1" />
     <add key="192.168.0.21" value="2" />
+    <!--车库权重-->
+    <add key="xWeight" value="1"/>
+    <add key="yWeight" value="1"/>
+    <add key="zWeight" value="1"/>
     
   </appSettings>
   

文件差异内容过多而无法显示
+ 619 - 619
parkMonitor/DB/DBOperation.cs


+ 14 - 14
parkMonitor/DB/Garage.cs

@@ -1,15 +1,15 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
 
-namespace parkMonitor.DB
-{
-    public class Garage
-    {
-        public int xweight { get; set; }
-        public int yweight { get; set; }
-        public int zweight { get; set; }
-    }
-}
+//namespace parkMonitor.DB
+//{
+//    public class Garage
+//    {
+//        public int xweight { get; set; }
+//        public int yweight { get; set; }
+//        public int zweight { get; set; }
+//    }
+//}

+ 78 - 78
parkMonitor/DB/IDBOperator.cs

@@ -1,83 +1,83 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MySql.Data.MySqlClient;
-using System.Configuration;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
+//using MySql.Data.MySqlClient;
+//using System.Configuration;
 
-namespace parkMonitor.DB
-{
-    interface IDBOperator
-    {
-        MySqlConnection getConn();
-        MySqlCommand getComm(string sql, MySqlConnection con);
-        MySqlDataReader getResultSet(MySqlCommand cmd);
-        void getInsert(MySqlCommand cmd);
-        void getUpdate(MySqlCommand cmd);
-        void getDelete(MySqlCommand cmd);
-    }
-    class Operator : IDBOperator
-    {
-        public MySqlConnection getConn()
-        {
-            string sqlConnectionStr = ConfigurationManager.AppSettings["SqlConnectionStr"];
-            MySqlConnection con = new MySqlConnection(sqlConnectionStr);
-            return con;
-        }
-        public MySqlCommand getComm(string sql, MySqlConnection con)
-        {
-            MySqlCommand cmd = new MySqlCommand(sql, con);
-            return cmd;
-        }
-        public MySqlDataReader getResultSet(MySqlCommand cmd)
-        {
-            MySqlDataReader reader = null;
-            try
-            {
-                reader = cmd.ExecuteReader();
-            }
-            catch
-            {
+//namespace parkMonitor.DB
+//{
+//    interface IDBOperator
+//    {
+//        MySqlConnection getConn();
+//        MySqlCommand getComm(string sql, MySqlConnection con);
+//        MySqlDataReader getResultSet(MySqlCommand cmd);
+//        void getInsert(MySqlCommand cmd);
+//        void getUpdate(MySqlCommand cmd);
+//        void getDelete(MySqlCommand cmd);
+//    }
+//    class Operator : IDBOperator
+//    {
+//        public MySqlConnection getConn()
+//        {
+//            string sqlConnectionStr = ConfigurationManager.AppSettings["SqlConnectionStr"];
+//            MySqlConnection con = new MySqlConnection(sqlConnectionStr);
+//            return con;
+//        }
+//        public MySqlCommand getComm(string sql, MySqlConnection con)
+//        {
+//            MySqlCommand cmd = new MySqlCommand(sql, con);
+//            return cmd;
+//        }
+//        public MySqlDataReader getResultSet(MySqlCommand cmd)
+//        {
+//            MySqlDataReader reader = null;
+//            try
+//            {
+//                reader = cmd.ExecuteReader();
+//            }
+//            catch
+//            {
 
-            }
-            return reader;
-        }
+//            }
+//            return reader;
+//        }
 
-        public void getInsert(MySqlCommand cmd) 
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
+//        public void getInsert(MySqlCommand cmd) 
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
 
-        public void getUpdate(MySqlCommand cmd)
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
+//        public void getUpdate(MySqlCommand cmd)
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
 
-        public void getDelete(MySqlCommand cmd)
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
-    }
-}
+//        public void getDelete(MySqlCommand cmd)
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
+//    }
+//}

+ 24 - 24
parkMonitor/DB/Parking_Space.cs

@@ -1,26 +1,26 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
 
-namespace parkMonitor.DB
-{
-    public class Parking_Space
-    {
-        public int parkingSpaceID { get; set; }
-        //public float parkingSpaceWeight { get; set; }
-        public int garageID { get; set; }
-        //public int parkingSpaceStatement { get; set; }
-        public int parkingSpaceX { get; set; }
-        public int parkingSpaceY { get; set; }
-        public int parkingSpaceZ { get; set; }
-    }
+//namespace parkMonitor.DB
+//{
+//    public class Parking_Space
+//    {
+//        public int parkingSpaceID { get; set; }
+//        //public float parkingSpaceWeight { get; set; }
+//        public int garageID { get; set; }
+//        //public int parkingSpaceStatement { get; set; }
+//        public int parkingSpaceX { get; set; }
+//        public int parkingSpaceY { get; set; }
+//        public int parkingSpaceZ { get; set; }
+//    }
 
-    public class Fetching_Space
-    {
-        public int parkingSpaceX { get; set; }
-        public int parkingSpaceY { get; set; }
-        public int parkingSpaceZ { get; set; }
-    }
-}
+//    public class Fetching_Space
+//    {
+//        public int parkingSpaceX { get; set; }
+//        public int parkingSpaceY { get; set; }
+//        public int parkingSpaceZ { get; set; }
+//    }
+//}

+ 15 - 15
parkMonitor/DB/Vehicle.cs

@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
 
-namespace parkMonitor.DB
-{
-    public class Vehicle
-    {
-        public int parkingSpaceID { get; set; }
-        public int garageID { get; set; }
-        public int frontwheelbase { get; set; }
-        public int rearwheelbase { get; set; }
-    }
-}
+//namespace parkMonitor.DB
+//{
+//    public class Vehicle
+//    {
+//        public int parkingSpaceID { get; set; }
+//        public int garageID { get; set; }
+//        public int frontwheelbase { get; set; }
+//        public int rearwheelbase { get; set; }
+//    }
+//}

文件差异内容过多而无法显示
+ 624 - 624
parkMonitor/DBLocation/DBLocation.cs


+ 78 - 78
parkMonitor/DBLocation/IDBLocation.cs

@@ -1,83 +1,83 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using MySql.Data.MySqlClient;
-using System.Configuration;
+//using System;
+//using System.Collections.Generic;
+//using System.Linq;
+//using System.Text;
+//using System.Threading.Tasks;
+//using MySql.Data.MySqlClient;
+//using System.Configuration;
 
-namespace parkMonitor.DBLocation
-{
-    interface IDBLocation
-    {
-        MySqlConnection getConn();
-        MySqlCommand getComm(string sql, MySqlConnection con);
-        MySqlDataReader getResultSet(MySqlCommand cmd);
-        void getInsert(MySqlCommand cmd);
-        void getUpdate(MySqlCommand cmd);
-        void getDelete(MySqlCommand cmd);
-    }
-    class Operator : IDBLocation
-    {
-        public MySqlConnection getConn()
-        {
-            string sqlConnectionStr = ConfigurationManager.AppSettings["SqlConnectionLocation"];
-            MySqlConnection con = new MySqlConnection(sqlConnectionStr);
-            return con;
-        }
-        public MySqlCommand getComm(string sql, MySqlConnection con)
-        {
-            MySqlCommand cmd = new MySqlCommand(sql, con);
-            return cmd;
-        }
-        public MySqlDataReader getResultSet(MySqlCommand cmd)
-        {
-            MySqlDataReader reader = null;
-            try
-            {
-                reader = cmd.ExecuteReader();
-            }
-            catch
-            {
+//namespace parkMonitor.DBLocation
+//{
+//    interface IDBLocation
+//    {
+//        MySqlConnection getConn();
+//        MySqlCommand getComm(string sql, MySqlConnection con);
+//        MySqlDataReader getResultSet(MySqlCommand cmd);
+//        void getInsert(MySqlCommand cmd);
+//        void getUpdate(MySqlCommand cmd);
+//        void getDelete(MySqlCommand cmd);
+//    }
+//    class Operator : IDBLocation
+//    {
+//        public MySqlConnection getConn()
+//        {
+//            string sqlConnectionStr = ConfigurationManager.AppSettings["SqlConnectionLocation"];
+//            MySqlConnection con = new MySqlConnection(sqlConnectionStr);
+//            return con;
+//        }
+//        public MySqlCommand getComm(string sql, MySqlConnection con)
+//        {
+//            MySqlCommand cmd = new MySqlCommand(sql, con);
+//            return cmd;
+//        }
+//        public MySqlDataReader getResultSet(MySqlCommand cmd)
+//        {
+//            MySqlDataReader reader = null;
+//            try
+//            {
+//                reader = cmd.ExecuteReader();
+//            }
+//            catch
+//            {
 
-            }
-            return reader;
-        }
+//            }
+//            return reader;
+//        }
 
-        public void getInsert(MySqlCommand cmd)
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
+//        public void getInsert(MySqlCommand cmd)
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
 
-        public void getUpdate(MySqlCommand cmd)
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
+//        public void getUpdate(MySqlCommand cmd)
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
 
-        public void getDelete(MySqlCommand cmd)
-        {
-            try
-            {
-                cmd.ExecuteNonQuery();
-            }
-            catch (Exception ex)
-            {
-                Console.WriteLine(ex.ToString());
-            }
-        }
-    }
-}
+//        public void getDelete(MySqlCommand cmd)
+//        {
+//            try
+//            {
+//                cmd.ExecuteNonQuery();
+//            }
+//            catch (Exception ex)
+//            {
+//                Console.WriteLine(ex.ToString());
+//            }
+//        }
+//    }
+//}

+ 44 - 0
parkMonitor/DataBase/DBConnection.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
+using System.Configuration;
+
+namespace parkMonitor.DataBase
+{
+    public class DBConnection
+    {
+        public MySqlConnection getConn(string connectionStr)
+        {
+            MySqlConnection con = null;
+            try
+            {
+                con = new MySqlConnection(ConfigurationManager.AppSettings[connectionStr]);
+            }
+            catch
+            {
+                Console.WriteLine("配置文件有误");
+            }
+            return con;
+        }
+        public MySqlCommand getComm(string sql, MySqlConnection con)
+        {
+            MySqlCommand cmd = null;
+            try
+            {
+                cmd = new MySqlCommand(sql, con);
+            }
+            catch(MySqlException)
+            {
+                Console.WriteLine("数据库连接异常");
+            }
+            catch
+            {
+                Console.WriteLine("sql语句异常");
+            }
+            return cmd;
+        }
+    }
+}

+ 371 - 0
parkMonitor/DataBase/DBOperation.cs

@@ -0,0 +1,371 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
+
+namespace parkMonitor.DataBase
+{
+    public class DBOperation
+    {
+        //查询车库表获得剩余车位数
+        public int getGarageFreeSpace(string connectionStr, int garageID)
+        {
+            MySqlDataReader reader = null;
+            int garageFreeSpace = 0;
+            string sql = "select * from garage where garageID = '" + garageID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                garageFreeSpace = reader.GetInt32("garageFreeSpace");
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return garageFreeSpace;
+        }
+
+        //查询车位位置及状态,返回list
+        public Dictionary<int, Parking_Space> GetParkingSpace(string connectionStr, int garageID)
+        {
+            Dictionary<int, Parking_Space> lps = new Dictionary<int, Parking_Space>();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where parkingSpaceState = 0 and garageID = '" + garageID + "' ";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                for (int i = 1; i <= count; i++)
+                {
+                    int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                    int parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                    int parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                    int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
+                    Parking_Space ps = new Parking_Space();
+                    ps.parkingSpaceID = parkingSpaceID;
+                    ps.garageID = garageID;
+                    ps.parkingSpaceX = parkingSpaceX;
+                    ps.parkingSpaceY = parkingSpaceY;
+                    ps.parkingSpaceZ = parkingSpaceZ;
+                    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)
+        {
+            string sql = "insert into parkingrecords(userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime) values('" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "')";
+            int parkingRecordsID = 0;
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getInsert();
+            parkingRecordsID = oper.getInsertId();
+            oper.DBClose();
+            return parkingRecordsID;
+        }
+
+        //根据车牌号更新车辆表
+        public void UpdateVehicle(string connectionStr, string numberPlate, int vehiclepParkState, string scanEntryTime, int parkingRecordsID, int parkingSpaceID, int vehicleTypeConfirm, int frontWheelbase, int rearWheelbase)
+        {
+            string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "',scanEntryTime = '" + scanEntryTime + "',parkingRecordsID = '" + parkingRecordsID + "',parkingSpaceID = '" + parkingSpaceID + "',vehicleTypeConfirm = '" + vehicleTypeConfirm + "',frontwheelbase = '" + frontWheelbase + "',rearwheelbase = '" + rearWheelbase + "' where numberPlate = '" + numberPlate + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //更新车库表剩余车位数
+        public void UpdateGarageFreeSpace(string connectionStr, int garageFreeSpace, int garageID)
+        {
+            string sql = "update garage set garageFreeSpace = '" + garageFreeSpace + "' where garageID = '" + garageID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //根据车牌号更新车辆状态
+        public void UpdateVehicleParkState(string connectionStr, string numberPlate, int vehiclepParkState)
+        {
+            string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "'where numberPlate = '" + numberPlate + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //更新车位状态
+        public void UpdateParkingSpaceState(string connectionStr, int parkingSpaceID, int parkingSpaceState)
+        {
+            string sql = "update parkingspace set parkingSpaceState = '" + parkingSpaceState + "'where parkingSpaceID = '" + parkingSpaceID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //更新停车记录表
+        public void UpdateParkingRecords(string connectionStr, int parkingRecordsState, string realGetTime, int parkingRecordsID)
+        {
+            string sql = "update parkingrecords set parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //插入消息推送表
+        public void InsertToMessageQueue(string connectionStr, int userID, string context, int messageType)
+        {
+            string sql = "insert into messagequeue(userID,context,messageType) values('" + userID + "','" + context + "','" + messageType + "')";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getInsert();
+            oper.DBClose();
+        }
+
+        //根据车牌查询得到车库id和车位id以及轮距
+        public Vehicle GetVehicle(string connectionStr, string numberPlate)
+        {
+            Vehicle v = new Vehicle();
+            MySqlDataReader reader = null;
+            string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                int garageID = reader.GetInt32("garageID");
+                int frontwheelbase = reader.GetInt32("frontwheelbase");
+                int rearwheelbase = reader.GetInt32("rearwheelbase");
+                v.parkingSpaceID = parkingSpaceID;
+                v.garageID = garageID;
+                v.frontwheelbase = frontwheelbase;
+                v.rearwheelbase = rearwheelbase;
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return v;
+        }
+
+        //根据车位id获得x,y,z
+        public Fetching_Space GetFetchingSpace(string connectionStr, int parkingSpaceID)
+        {
+            Fetching_Space fs = new Fetching_Space();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where parkingSpaceID = '" + parkingSpaceID + " '";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                int parkingSpaceX = reader.GetInt32("parkingSpaceX");
+                int parkingSpaceY = reader.GetInt32("parkingSpaceY");
+                int parkingSpaceZ = reader.GetInt32("parkingSpaceZ");
+                fs.parkingSpaceX = parkingSpaceX;
+                fs.parkingSpaceY = parkingSpaceY;
+                fs.parkingSpaceZ = parkingSpaceZ;
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return fs;
+        }
+
+        //查询手机号是否被注册
+        public bool IsTelRegister(string connectionStr, string tel)
+        {
+            bool isTelRegister = false;
+            MySqlDataReader reader = null;
+            string sql = "select * from user where userTelephone = '" + tel + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                isTelRegister = true;
+            }
+            else
+            {
+                isTelRegister = false;
+            }
+            oper.DBClose();
+            return isTelRegister;
+        }
+
+        //注册信息写入数据库,返回注册成功信息
+        public int InsertUser(string connectionStr, string tel, string password)
+        {
+            string sql = "insert into user(userTelephone,userPassword,userLevel) values('" + tel + "','" + password + "',1)";
+            int userID = 0;
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getInsert();
+            userID = oper.getInsertId();
+            oper.DBClose();
+            return userID;
+        }
+
+        //根据电话号码查询userID
+        public int GetUserID(string connectionStr, string tel)
+        {
+            int userID = 0;
+            MySqlDataReader reader = null;
+            string sql = "select userID from user where userTelephone = '" + tel + "'";
+            int count = 0;
+            Operation oper = new Operation(connectionStr, sql);
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                userID = reader.GetInt32("userID");
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return userID;
+        }
+
+        //查询停车记录id
+        public int GetParkingRecordsID(string connectionStr, string numberPlate)
+        {
+            int parkingRecordsID = 0;
+            MySqlDataReader reader = null;
+            string sql = "select parkingRecordsID from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
+            int count = 0;
+            Operation oper = new Operation(connectionStr, sql);
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                parkingRecordsID = reader.GetInt32("parkingRecordsID");
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return parkingRecordsID;
+        }
+
+        //车库有无此车
+        public bool IsNumberPlate(string connectionStr, string numberPlate, int garageID)
+        {
+            bool isNumberPlate = true;
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                isNumberPlate = true;
+            }
+            else
+            {
+                isNumberPlate = false;
+            }
+            oper.DBClose();
+            return isNumberPlate;
+        }
+
+        //数据插入本地记录表,并返回停车记录id
+        public int InsertToLocalParkingRecords(string connectionStr, int parkingStatus, int userID, string numberPlate, int parkingSpaceID, int garageID, int parkingRecordsState, string realParkTime, int frontWheelbase, int rearWheelbase)
+        {
+            string sql = "insert into parkingrecords(parkingStatus,userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,frontWheelbase,rearWheelbase) values('" + parkingStatus + "','" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "','" + frontWheelbase + "','" + rearWheelbase + "')";
+            int parkingRecordsID = 0;
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getInsert();
+            parkingRecordsID = oper.getInsertId();
+            oper.DBClose();
+            return parkingRecordsID;
+        }
+
+        //更新本地停车记录表
+        public void UpdateParkingRecords(string connectionStr, int parkingStatus, int parkingRecordsState, string realGetTime, int parkingRecordsID)
+        {
+            string sql = "update parkingrecords set parkingStatus = '" + parkingStatus + "', parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //插入车辆表
+        public void InsertVehicle(string connectionStr, string numberPlate, int vehiclepParkState, int parkingRecordsID, int parkingSpaceID, int vehicleTypeConfirm)
+        {
+            string sql = "insert into vehicle(numberPlate,vehiclepParkState,parkingRecordsID,parkingSpaceID,vehicleTypeConfirm) values('" + numberPlate + "','" + vehiclepParkState + "','" + parkingRecordsID + "','" + parkingSpaceID + "','" + vehicleTypeConfirm + "')";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getInsert();
+            oper.DBClose();
+        }
+
+        //判断车辆表中是否存在该车辆号牌
+        public bool IsNumberPlateFromVehicle(string connectionStr, string numberPlate)
+        {
+            bool isNumberPlateFromVehicle = true;
+            string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
+            MySqlDataReader reader = null;
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                isNumberPlateFromVehicle = true;
+            }
+            else
+            {
+                isNumberPlateFromVehicle = false;
+            }
+            oper.DBClose();
+            return isNumberPlateFromVehicle;
+        }
+
+        //根据车牌号更新车辆表
+        public void UpdateVehicle(string connectionStr, string numberPlate, int vehiclepParkState, int parkingRecordsID, int parkingSpaceID, int vehicleTypeConfirm)
+        {
+            string sql = "update vehicle set vehiclepParkState = '" + vehiclepParkState + "',parkingRecordsID = '" + parkingRecordsID + "',parkingSpaceID = '" + parkingSpaceID + "',vehicleTypeConfirm = '" + vehicleTypeConfirm + "' where numberPlate = '" + numberPlate + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            oper.getUpdate();
+            oper.DBClose();
+        }
+
+        //根据车牌查询得到车库id和车位id以及轮距
+        public Vehicle GetLocalVehicle(string connectionStr, string numberPlate, int garageID)
+        {
+            Vehicle v = new Vehicle();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
+            Operation oper = new Operation(connectionStr, sql);
+            int count = 0;
+            reader = oper.getResultSet(ref count);
+            if (count > 0)
+            {
+                int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                int frontwheelbase = reader.GetInt32("frontwheelbase");
+                int rearwheelbase = reader.GetInt32("rearwheelbase");
+                v.parkingSpaceID = parkingSpaceID;
+                v.garageID = garageID;
+                v.frontwheelbase = frontwheelbase;
+                v.rearwheelbase = rearwheelbase;
+            }
+            else
+            {
+                Console.WriteLine("查无结果");
+            }
+            oper.DBClose();
+            return v;
+        }
+
+    }
+}

+ 126 - 0
parkMonitor/DataBase/IDBOperation.cs

@@ -0,0 +1,126 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
+
+namespace parkMonitor.DataBase
+{
+    interface IDBOperation
+    {
+        MySqlDataReader getResultSet(ref int count);
+        void getInsert();
+        void getUpdate();
+        void getDelete();
+    }
+    class Operation : IDBOperation
+    {
+        DBConnection connection = null;
+        MySqlConnection con = null;
+        MySqlCommand cmd = null;
+        MySqlDataReader reader = null;
+        public Operation(string connectionStr, string sql)
+        {
+            connection = new DBConnection();
+            con = connection.getConn(connectionStr);
+            cmd = connection.getComm(sql, con);
+        }
+        /// <summary>
+        /// 数据库查询
+        /// </summary>
+        /// <param name="sql"></param>
+        /// <returns></returns>
+        public MySqlDataReader getResultSet(ref int count)
+        {
+            try
+            {
+                con.Open();
+                reader = cmd.ExecuteReader();
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        count++;
+                        //return reader;
+                    }                 
+                }               
+            }
+            catch
+            {
+                Console.WriteLine("数据库异常");
+            }
+            return reader;
+        }
+
+        public void getInsert()
+        {
+            try
+            {
+                con.Open();
+                cmd.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                Console.WriteLine("插入异常");
+            }
+        }
+
+        public void getUpdate()
+        {
+            try
+            {
+                con.Open();
+                cmd.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                Console.WriteLine("更新异常");
+            }
+        }
+
+        public void getDelete()
+        {
+            try
+            {
+                con.Open();
+                cmd.ExecuteNonQuery();
+            }
+            catch (Exception)
+            {
+                Console.WriteLine("删除异常");
+            }
+        }
+        public int getInsertId()
+        {
+            int insertID = 0;
+            try
+            {
+                insertID = Convert.ToInt32(cmd.LastInsertedId);
+            }
+            catch
+            {
+                Console.WriteLine("插入数据库失败");
+            }
+            return insertID;
+        }
+
+        public void DBClose()
+        {
+            if (reader != null)
+            {
+                reader.Close();
+                reader.Dispose();
+            }
+            if (cmd != null)
+            {
+                cmd.Dispose();
+            }
+            if (con != null)
+            {
+                con.Close();
+                con.Dispose();
+            }
+        }
+    }
+}

+ 26 - 0
parkMonitor/DataBase/Parking_Space.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace parkMonitor.DataBase
+{
+    public class Parking_Space
+    {
+        public int parkingSpaceID { get; set; }
+        //public float parkingSpaceWeight { get; set; }
+        public int garageID { get; set; }
+        //public int parkingSpaceStatement { get; set; }
+        public int parkingSpaceX { get; set; }
+        public int parkingSpaceY { get; set; }
+        public int parkingSpaceZ { get; set; }
+    }
+
+    public class Fetching_Space
+    {
+        public int parkingSpaceX { get; set; }
+        public int parkingSpaceY { get; set; }
+        public int parkingSpaceZ { get; set; }
+    }
+}

+ 16 - 0
parkMonitor/DataBase/Vehicle.cs

@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace parkMonitor.DataBase
+{
+    public class Vehicle
+    {
+        public int parkingSpaceID { get; set; }
+        public int garageID { get; set; }
+        public int frontwheelbase { get; set; }
+        public int rearwheelbase { get; set; }
+    }
+}

+ 1 - 2
parkMonitor/bll/MainBll.cs

@@ -1,5 +1,4 @@
-using parkMonitor.DB;
-using parkMonitor.entity;
+using parkMonitor.entity;
 using parkMonitor.model;
 using parkMonitor.server;
 using parkMonitor.server.CoreThread;

+ 10 - 9
parkMonitor/manualParking/ManualParking.cs

@@ -9,8 +9,8 @@ using System.Threading.Tasks;
 using System.Windows.Forms;
 using parkMonitor.entity;
 using parkMonitor.server.CoreThread;
-using parkMonitor.DBLocation;
 using parkMonitor.model;
+using parkMonitor.DataBase;
 
 namespace parkMonitor.manualParking
 {
@@ -18,9 +18,10 @@ namespace parkMonitor.manualParking
     {
         Command storeCmd = new Command();
         IEquipments qt = EquipmentSimpleFactory.ins.FindEquipment(EquipmentName.Queue);
-        DBLocationOperator locationOper = new DBLocationOperator();
+        DBOperation oper = new DBOperation();
 
         string numberRecord = "";
+        string connectionStr = "SqlConnectionLocation";
         public ManualParking()
         {
             InitializeComponent();
@@ -30,7 +31,7 @@ namespace parkMonitor.manualParking
         {
             storeCmd.manual = true;
             storeCmd.commandType = 's';
-            storeCmd.userID = locationOper.GetUserID(tel.Text).ToString();
+            storeCmd.userID = oper.GetUserID(connectionStr,tel.Text).ToString();
             storeCmd.LicenseNum = numberPlate.Text;
             try
             {
@@ -38,14 +39,14 @@ namespace parkMonitor.manualParking
             }
             catch { MessageBox.Show("非法车库号,请重新输入"); return; }
             int garageFreeSpace = 0;
-            bool isTelRegister = locationOper.IsTelRegister(tel.Text);
+            bool isTelRegister = oper.IsTelRegister(connectionStr,tel.Text);
             if (isTelRegister == false)
             {
                 MessageBox.Show("该号码未被注册,请先注册");
             }
             else if (storeCmd.garageID != 0)
             {
-                garageFreeSpace = locationOper.getGarageFreeSpace(storeCmd.garageID);
+                garageFreeSpace = oper.getGarageFreeSpace(connectionStr,storeCmd.garageID);
                 if (garageFreeSpace > 0)
                 {
                     if (storeCmd.userID != "" && storeCmd.LicenseNum != numberRecord)
@@ -70,7 +71,7 @@ namespace parkMonitor.manualParking
         {
             storeCmd.manual = true;
             storeCmd.commandType = 'f';
-            storeCmd.userID = locationOper.GetUserID(tel.Text).ToString();
+            storeCmd.userID = oper.GetUserID(connectionStr,tel.Text).ToString();
             storeCmd.LicenseNum = numberPlate.Text;
             storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             try
@@ -78,8 +79,8 @@ namespace parkMonitor.manualParking
                 storeCmd.garageID = Convert.ToInt32(selectGarage.Text);
             }
             catch { MessageBox.Show("非法车库号,请重新输入"); return; }
-            bool isTelRegister = locationOper.IsTelRegister(tel.Text);
-            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum, storeCmd.garageID);
+            bool isTelRegister = oper.IsTelRegister(connectionStr,tel.Text);
+            bool isNumberPlate = oper.IsNumberPlate(connectionStr,storeCmd.LicenseNum, storeCmd.garageID);
             if (isTelRegister == false)
             {
                 MessageBox.Show("该号码未被注册,请先注册");
@@ -90,7 +91,7 @@ namespace parkMonitor.manualParking
             }
             else
             {
-                storeCmd.parkingRecordsID = locationOper.GetParkingRecordsID(storeCmd.LicenseNum);
+                storeCmd.parkingRecordsID = oper.GetParkingRecordsID(connectionStr,storeCmd.LicenseNum);
                 if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
                 {
                     qt.SetMessage((Command)storeCmd.Clone());

+ 12 - 10
parkMonitor/manualParking/ManualParkingSimul.cs

@@ -1,5 +1,4 @@
-using parkMonitor.DBLocation;
-using parkMonitor.entity;
+using parkMonitor.entity;
 using parkMonitor.model;
 using parkMonitor.server.uiLogServer;
 using System;
@@ -8,6 +7,7 @@ using System.Linq;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
+using parkMonitor.DataBase;
 
 namespace parkMonitor
 {
@@ -22,7 +22,7 @@ namespace parkMonitor
         private Dictionary<int, CarStatusStru> numStatusMap = new Dictionary<int, CarStatusStru>();
         Command storeCmd = new Command();
         IEquipments queue;
-        DBLocationOperator locationOper = new DBLocationOperator();
+        DBOperation oper = new DBOperation();
 
         public ManualParkingSimul()
         {
@@ -45,9 +45,10 @@ namespace parkMonitor
 
         public void Store(string lic)
         {
+            string connectionStr = "SqlConnectionLocation";
             storeCmd.manual = true;
             storeCmd.commandType = 's';
-            storeCmd.userID = locationOper.GetUserID(userId).ToString();
+            storeCmd.userID = oper.GetUserID(connectionStr,userId).ToString();
             storeCmd.LicenseNum = lic;
             try
             {
@@ -55,14 +56,14 @@ namespace parkMonitor
             }
             catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
             int garageFreeSpace = 0;
-            bool isTelRegister = locationOper.IsTelRegister(userId);
+            bool isTelRegister = oper.IsTelRegister(connectionStr,userId);
             if (isTelRegister == false)
             {
                 UILogServer.ins.error("该号码未被注册,请先注册");
             }
             else if (storeCmd.garageID != 0)
             {
-                garageFreeSpace = locationOper.getGarageFreeSpace(storeCmd.garageID);
+                garageFreeSpace = oper.getGarageFreeSpace(connectionStr,storeCmd.garageID);
                 if (garageFreeSpace > 0)
                 {
                     if (storeCmd.userID != "" && storeCmd.LicenseNum != "")
@@ -80,9 +81,10 @@ namespace parkMonitor
 
         public void Fetch(string lic)
         {
+            string connectionStr = "SqlConnectionLocation";
             storeCmd.manual = true;
             storeCmd.commandType = 'f';
-            storeCmd.userID = locationOper.GetUserID(userId).ToString();
+            storeCmd.userID = oper.GetUserID(connectionStr,userId).ToString();
             storeCmd.LicenseNum = lic;
             storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
             try
@@ -90,8 +92,8 @@ namespace parkMonitor
                 storeCmd.garageID = Convert.ToInt32(garageId);
             }
             catch { UILogServer.ins.error("非法车库号,请重新输入"); return; }
-            bool isTelRegister = locationOper.IsTelRegister(userId);
-            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum, storeCmd.garageID);
+            bool isTelRegister = oper.IsTelRegister(connectionStr,userId);
+            bool isNumberPlate = oper.IsNumberPlate(connectionStr,storeCmd.LicenseNum, storeCmd.garageID);
             if (isTelRegister == false)
             {
                 UILogServer.ins.error("该号码未被注册,请先注册");
@@ -102,7 +104,7 @@ namespace parkMonitor
             }
             else
             {
-                storeCmd.parkingRecordsID = locationOper.GetParkingRecordsID(storeCmd.LicenseNum);
+                storeCmd.parkingRecordsID = oper.GetParkingRecordsID(connectionStr,storeCmd.LicenseNum);
                 if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
                 {
                     queue.SetMessage((Command)storeCmd.Clone());

+ 6 - 4
parkMonitor/manualParking/Register.cs

@@ -8,7 +8,7 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Security.Cryptography;
-using parkMonitor.DBLocation;
+using parkMonitor.DataBase;
 
 namespace parkMonitor.manualParking
 {
@@ -54,8 +54,10 @@ namespace parkMonitor.manualParking
             {
                 flag = flag + 1;
             }
-            DBLocationOperator locationOper = new DBLocationOperator();
-            bool isTelRegister = locationOper.IsTelRegister(tel);
+            //DBLocationOperator locationOper = new DBLocationOperator();
+            DBOperation oper = new DBOperation();
+            string connectionStr = "SqlConnectionLocation";
+            bool isTelRegister = oper.IsTelRegister(connectionStr,tel);
             if (isTelRegister&&flag >= 3)
             {
                 MessageBox.Show("此电话号码已被注册");
@@ -64,7 +66,7 @@ namespace parkMonitor.manualParking
             {
                 flag = flag + 1;               
             }
-            int userID = locationOper.InsertUser(tel, password);
+            int userID = oper.InsertUser(connectionStr,tel, password);
             if (userID!=0&&flag >= 4)
             {
                 MessageBox.Show("注册成功");

+ 5 - 0
parkMonitor/parkMonitor.csproj

@@ -87,6 +87,11 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="bll\MainBll.cs" />
+    <Compile Include="DataBase\DBConnection.cs" />
+    <Compile Include="DataBase\DBOperation.cs" />
+    <Compile Include="DataBase\IDBOperation.cs" />
+    <Compile Include="DataBase\Parking_Space.cs" />
+    <Compile Include="DataBase\Vehicle.cs" />
     <Compile Include="DBLocation\DBLocation.cs" />
     <Compile Include="DBLocation\IDBLocation.cs" />
     <Compile Include="DB\DBOperation.cs" />

+ 78 - 52
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -3,15 +3,14 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using parkMonitor.DB;
 using parkMonitor.LOG;
 using parkMonitor.entity;
 using parkMonitor.model;
 using System.Configuration;
 using System.Threading;
 using parkMonitor.server.uiLogServer;
-using parkMonitor.DBLocation;
 using parkMonitor.tools;
+using parkMonitor.DataBase;
 
 namespace parkMonitor.server.CoreThread
 {
@@ -37,7 +36,7 @@ namespace parkMonitor.server.CoreThread
         public int rearWheelbase_address { get; set; }
 
         //instances
-        public DBLocationOperator locationOper { get; set; }
+        //public DBLocationOperator locationOper { get; set; }
         public IEquipments PLC { set; get; }
         public IEquipments queuingThread { set; get; }
         public DBOperation oper { set; get; }
@@ -73,7 +72,7 @@ namespace parkMonitor.server.CoreThread
             aps = new AllotParkingSpace();
             Robot.robot1.parking_start_addr = parking_startRobot_address;
             Robot.robot1.fetching_start_addr = fetching_startRobot_address;
-            locationOper = new DBLocationOperator();
+            //locationOper = new DBLocationOperator();
         }
         public abstract void executeCmd(Command queueCmd);
         public bool WaitForRobotResource(int robotID)
@@ -147,6 +146,7 @@ namespace parkMonitor.server.CoreThread
         /// <param name="isParking"></param>
         public void Rollback(Command queueCmd, int parkingSpaceID, bool parkingSpaceUpdated, bool isParking)
         {
+            string connectionStr = null;
             //命令回退
             queueCmd.returnedCount += 1;
             queuingThread.SetMessage(queueCmd);
@@ -154,44 +154,46 @@ namespace parkMonitor.server.CoreThread
             //复位车辆状态;若已更新过车位则还需复位总车位数,车位状态
             if (!queueCmd.manual)
             {
-                int freeSpaceCount = oper.getGarageFreeSpace(queueCmd.garageID);
+                connectionStr = "SqlConnectionStr";
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,queueCmd.garageID);
                 if (isParking)
                 {
-                    oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                     if (parkingSpaceUpdated)
                     {
                         freeSpaceCount = freeSpaceCount + 1;
-                        oper.UpdateGarageFreeSpace(freeSpaceCount, queueCmd.garageID);
-                        oper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, queueCmd.garageID);
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                 }
                 else
-                {
-                    oper.UpdateVehicleParkState(queueCmd.LicenseNum, 1);
+                {                   
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 1);
                     if (parkingSpaceUpdated)
                     {
                         freeSpaceCount = freeSpaceCount - 1;
-                        oper.UpdateGarageFreeSpace(freeSpaceCount, queueCmd.garageID);
-                        oper.UpdateParkingSpaceState(parkingSpaceID, 1);
+                        oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, queueCmd.garageID);
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
                     }
                 }
             }
             else
             {
+                connectionStr = "SqlConnectionLocation";
                 if (isParking)
                 {
-                    locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                     if (parkingSpaceUpdated)
                     {
-                        locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                 }
                 else
                 {
-                    locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 1);
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 1);
                     if (parkingSpaceUpdated)
                     {
-                        locationOper.UpdateParkingSpaceState(parkingSpaceID, 1);
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
                     }
                 }
             }
@@ -254,6 +256,7 @@ namespace parkMonitor.server.CoreThread
         /// <returns></returns>
         private Parking_Space WaitForParkingSpaceResource(Command queueCmd)
         {
+            string connectionStr = null;
             //中心点
             cEntrance.parkingEntX = parkingEntX;
             cEntrance.parkingEntY = parkingEntY;
@@ -265,11 +268,13 @@ namespace parkMonitor.server.CoreThread
             {
                 if (!queueCmd.manual)
                 {
-                    ppp = aps.MallocParkingSpace(cEntrance, oper, queueCmd);//自动 
+                    connectionStr = "SqlConnectionStr";
+                    ppp = aps.MallocParkingSpace(cEntrance, connectionStr, queueCmd);//自动 
                 }
                 else
                 {
-                    ppp = aps.MallocParkingSpace(cEntrance, locationOper, queueCmd);//手动
+                    connectionStr = "SqlConnectionLocation";
+                    ppp = aps.MallocParkingSpace(cEntrance, connectionStr, queueCmd);//手动
                 }
                 if (ppp != null)
                 {
@@ -390,6 +395,7 @@ namespace parkMonitor.server.CoreThread
         /// </summary>
         private bool WaitForStoreCompletionSignal(Command queueCmd, ref int parkingSpaceID, ref bool robotError, int status)
         {
+            string connectionStr = null;
             PLCMessage PLCMsg = null;
             MyTimer mt = new MyTimer();
             mt.StartTiming();
@@ -411,11 +417,13 @@ namespace parkMonitor.server.CoreThread
                     queuingThread.SetMessage(queueCmd);
                     if (!queueCmd.manual)
                     {
-                        oper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        connectionStr = "SqlConnectionStr";
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                     else
                     {
-                        locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        connectionStr = "SqlConnectionLocation";
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                     break;
                 }
@@ -484,6 +492,7 @@ namespace parkMonitor.server.CoreThread
         /// <param name="queueCmd"></param>
         public override void executeCmd(Command queueCmd)
         {
+            string connectionStr = null;
             bool disappeared = false;
             bool stopChecking = false;
             bool robotError = false;
@@ -557,21 +566,23 @@ namespace parkMonitor.server.CoreThread
             int parkingSpaceZ = ppp.parkingSpaceZ;
             if (!queueCmd.manual)
             {
+                connectionStr = "SqlConnectionStr";
                 //更新云端车位表车位状态
-                oper.UpdateParkingSpaceState(parkingSpaceID, 1);
+                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
                 //更新车库表剩余车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr, garageID);
                 freeSpaceCount = freeSpaceCount - 1;
-                oper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr, freeSpaceCount, garageID);
             }
             else
             {
+                connectionStr = "SqlConnectionLocation";
                 //更新本地车位表车位状态
-                locationOper.UpdateParkingSpaceState(parkingSpaceID, 1);
+                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 1);
                 //更新车库表剩余车位数
-                int freeSpaceCount = locationOper.getGarageFreeSpace(garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
                 freeSpaceCount = freeSpaceCount - 1;
-                locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
             }
             //号牌失效,数据库回滚
             if (disappeared)
@@ -579,11 +590,13 @@ namespace parkMonitor.server.CoreThread
                 NumReset(queueCmd);
                 if (!queueCmd.manual)
                 {
-                    oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                    connectionStr = "SqlConnectionStr";
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                 }
                 else
                 {
-                    locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                    connectionStr = "SqlConnectionLocation";
+                    oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                 }
                 return;
             }
@@ -659,20 +672,22 @@ namespace parkMonitor.server.CoreThread
             //正常写入数据库
             if (userID != 0)
             {
-                if (queueCmd.manual == false)
+                if (!queueCmd.manual)
                 {
+                    connectionStr = "SqlConnectionStr";
                     //更新云端数据库
                     //插入停车记录表
-                    int parkingRecordsID = oper.InsertToParkingRecords(userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
+                    int parkingRecordsID = oper.InsertToParkingRecords(connectionStr,userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
                     //车辆表更新车辆信息
-                    oper.UpdateVehicle(numberPlate, 1, realParkTime, parkingRecordsID, parkingSpaceID, 1, frontWheelbase, rearWheelbase);
+                    oper.UpdateVehicle(connectionStr,numberPlate, 1, realParkTime, parkingRecordsID, parkingSpaceID, 1, frontWheelbase, rearWheelbase);
                     //插入消息队列表
-                    oper.InsertToMessageQueue(userID, "停车成功", 1);
+                    oper.InsertToMessageQueue(connectionStr,userID, "停车成功", 1);
                 }
                 else
                 {
+                    connectionStr = "SqlConnectionLocation";
                     //插入停车记录表
-                    int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
+                    int parkingRecordsID = oper.InsertToLocalParkingRecords(connectionStr,1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
                 }
             }
             //异常写入日志文件
@@ -697,6 +712,7 @@ namespace parkMonitor.server.CoreThread
     {
         private bool waitForFetchCompletionSignal(Command queueCmd, ref int parkingSpaceID, ref bool robotError, int status)
         {
+            string connectionStr = null;
             PLCMessage PLCMsg = null;
             MyTimer mt = new MyTimer();
             mt.StartTiming();
@@ -719,11 +735,13 @@ namespace parkMonitor.server.CoreThread
                     queuingThread.SetMessage(queueCmd);
                     if (!queueCmd.manual)
                     {
-                        oper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        connectionStr = "SqlConnectionStr";
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                     else
                     {
-                        locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                        connectionStr = "SqlConnectionLocation";
+                        oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                     }
                     break;
                 }
@@ -748,15 +766,18 @@ namespace parkMonitor.server.CoreThread
 
         public override void executeCmd(Command queueCmd)
         {
+            string connectionStr = null;
             PLCMessage PLCMsg = null;
             Vehicle vehiclelist = null;
             if (queueCmd.manual)
             {
-                vehiclelist = locationOper.GetVehicle(queueCmd.LicenseNum, queueCmd.garageID);
+                connectionStr = "SqlConnectionLocation";
+                vehiclelist = oper.GetLocalVehicle(connectionStr,queueCmd.LicenseNum, queueCmd.garageID);
             }
             else
-            {
-                vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
+            {             
+                connectionStr = "SqlConnectionStr";
+                vehiclelist = oper.GetVehicle(connectionStr,queueCmd.LicenseNum);
             }
             int parkingSpaceID = vehiclelist.parkingSpaceID;
             int garageID = vehiclelist.garageID;
@@ -766,11 +787,13 @@ namespace parkMonitor.server.CoreThread
             Fetching_Space fslist = null;
             if (queueCmd.manual)
             {
-                fslist = locationOper.GetFetchingSpace(parkingSpaceID);
+                connectionStr = "SqlConnectionLocation";
+                fslist = oper.GetFetchingSpace(connectionStr,parkingSpaceID);
             }
             else
             {
-                fslist = oper.GetFetchingSpace(parkingSpaceID);
+                connectionStr = "SqlConnectionStr";
+                fslist = oper.GetFetchingSpace(connectionStr,parkingSpaceID);
             }
             int parkingSpaceX = fslist.parkingSpaceX;
             int parkingSpaceY = fslist.parkingSpaceY;
@@ -827,19 +850,20 @@ namespace parkMonitor.server.CoreThread
             ManualParkingSimul.ins.Update(Int32.Parse(queueCmd.LicenseNum.Substring(2,1)));
 
             //数据库更新
-            if (queueCmd.manual == false)
+            if (!queueCmd.manual)
             {
+                connectionStr = "SqlConnectionStr";
                 //云端数据库更新
                 //更新车库表车位数
-                int freeSpaceCount = oper.getGarageFreeSpace(garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
                 freeSpaceCount = freeSpaceCount + 1;
-                oper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
                 //更新车位表车位状态
-                oper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                 //更新车辆表车辆停车状态
-                oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                 //更新停车记录表
-                oper.UpdateParkingRecords(6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
+                oper.UpdateParkingRecords(connectionStr,6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
 
                 ////本地数据库更新
                 //locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
@@ -852,16 +876,17 @@ namespace parkMonitor.server.CoreThread
             }
             else
             {
+                connectionStr = "SqlConnectionLocation";
                 //更新车库表车位数
-                int freeSpaceCount = locationOper.getGarageFreeSpace(garageID);
+                int freeSpaceCount = oper.getGarageFreeSpace(connectionStr,garageID);
                 freeSpaceCount = freeSpaceCount + 1;
-                locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
+                oper.UpdateGarageFreeSpace(connectionStr,freeSpaceCount, garageID);
                 //更新车位表车位状态
-                locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
+                oper.UpdateParkingSpaceState(connectionStr,parkingSpaceID, 0);
                 ////更新车辆表车辆停车状态
                 //locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
                 //更新停车记录表
-                locationOper.UpdateParkingRecords(0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
+                oper.UpdateParkingRecords(connectionStr,0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
             }
         }
     }
@@ -873,13 +898,14 @@ namespace parkMonitor.server.CoreThread
     {
         public override void executeCmd(Command queueCmd)
         {
+            string connectionStr = "SqlConnectionLocation";
             if (queueCmd.commandType == 'e')
             {
                 int userId = Convert.ToInt32(queueCmd.userID);
                 //过期用户指令
-                oper.InsertToMessageQueue(userId, "停车异常,请联系管理员!", 2);
+                oper.InsertToMessageQueue(connectionStr,userId, "停车异常,请联系管理员!", 2);
                 //未能停车,将车辆状态复位
-                oper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                oper.UpdateVehicleParkState(connectionStr,queueCmd.LicenseNum, 0);
                 LogFile logFile = LogFile.ERROR_NUMBERPLATE;
                 Log.WriteLog(logFile, "过期用户指令,车牌号:" + queueCmd.LicenseNum);
                 UILogServer.ins.error("过期用户指令,车牌号:" + queueCmd.LicenseNum);

+ 7 - 16
parkMonitor/server/CoreThread/AllotParkingSpace.cs

@@ -3,30 +3,21 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using parkMonitor.DB;
-using parkMonitor.DBLocation;
+using parkMonitor.DataBase;
 using System.Configuration;
 using parkMonitor.entity;
+using System.Configuration;
 
 namespace parkMonitor.server.CoreThread
 {
     public class AllotParkingSpace
     {
         //根据车位位置及状态分配目标车位,返回Parking Space的ID
-        public Parking_Space MallocParkingSpace(CEntrance pt_Ent,object c,Command queueCmd)
+        public Parking_Space MallocParkingSpace(CEntrance pt_Ent, string connectionStr, Command queueCmd)
         {
-            //DBOperation o = new DBOperation();
-            List<Parking_Space> lps = null;
-            if (c.GetType() == typeof(DBOperation))
-            {
-                DBOperation oper = (DBOperation)c;
-                lps = oper.GetParkingSpace(queueCmd.garageID);
-            }
-            else
-            {
-                DBLocationOperator locationOper = (DBLocationOperator)c;
-                lps = locationOper.GetParkingSpace(queueCmd.garageID);
-            }
+            DBOperation oper = new DBOperation();
+            Dictionary<int, Parking_Space> lps = null;
+            lps = oper.GetParkingSpace(connectionStr,queueCmd.garageID);
             double xWeight = Convert.ToDouble(ConfigurationManager.AppSettings["xWeight"]);
             double yWeight = Convert.ToDouble(ConfigurationManager.AppSettings["yWeight"]);
             double zWeight = Convert.ToDouble(ConfigurationManager.AppSettings["zWeight"]);
@@ -34,7 +25,7 @@ namespace parkMonitor.server.CoreThread
             Parking_Space rps = new Parking_Space();
 
             float min_dis = 10000;
-            for (int i = 0; i < lps.Count(); i++)
+            for (int i = 1; i <= lps.Count(); i++)
             {
                 float deltaX = (lps[i].parkingSpaceX - pt_Ent.parkingEntX) * (float)xWeight;
                 float deltaY = (lps[i].parkingSpaceY - pt_Ent.parkingEntY) * (float)yWeight;

+ 0 - 1
parkMonitor/server/CoreThread/CoreThread.cs

@@ -6,7 +6,6 @@ using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using parkMonitor.DB;
 using parkMonitor.LOG;
 using parkMonitor.server.WebThread;
 using System.Windows;

+ 1 - 4
parkMonitor/server/CoreThread/CoreThreadTest2.cs

@@ -3,15 +3,14 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
-using parkMonitor.DB;
 using parkMonitor.LOG;
 using parkMonitor.entity;
 using parkMonitor.model;
 using System.Configuration;
 using System.Threading;
 using parkMonitor.server.uiLogServer;
-using parkMonitor.DBLocation;
 using parkMonitor.tools;
+using parkMonitor.DataBase;
 
 namespace parkMonitor.server.CoreThread
 {
@@ -26,7 +25,6 @@ namespace parkMonitor.server.CoreThread
         //获取号牌句柄
         IEquipments NumMachine;
         //
-        DBLocationOperator locationOper;
         DBOperation oper;
         int localGarageId = 0;
         bool isClosing;
@@ -39,7 +37,6 @@ namespace parkMonitor.server.CoreThread
             {
                 equipmentStatus_address = Convert.ToInt32(ConfigurationManager.AppSettings["equipmentStatus_address"]);
                 localGarageId = Convert.ToInt32(ConfigurationManager.AppSettings["localGarageId"]);
-                locationOper = new DBLocationOperator();
                 oper = new DBOperation();
             }
             catch (Exception) { }

+ 1 - 1
parkMonitor/server/NumMachine/NumMachineSimul.cs

@@ -165,7 +165,7 @@ namespace parkMonitor.server
             });
             Task.Factory.StartNew(() =>
             {
-                ManualParkingSimul.ins = new ManualParkingSimul();
+                //ManualParkingSimul.ins = new ManualParkingSimul();
             });
            
         }

+ 2 - 2
parkMonitor/server/PLCLinker/PLCLinker.cs

@@ -732,9 +732,9 @@ namespace parkMonitor.server
                             {
                                 laserWorking = false;
                                 SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "254");
-                                Thread.Sleep(2000);
+                                Thread.Sleep(1000);
                                 SendtoPLC(laserMgmtList[0].laser_status_address.ToString(), "255");
-                                Thread.Sleep(2000);
+                                Thread.Sleep(1000);
                             }
                             //模拟测量
                             else