Jelajahi Sumber

手动停取车

kingwang1995 7 tahun lalu
induk
melakukan
333ecf0ff4

+ 1 - 1
parkMonitor/DB/DBOperation.cs

@@ -539,7 +539,7 @@ namespace parkMonitor.DB
             // List<Vehicle> lVehicle = new List<Vehicle>();
             Vehicle v = new Vehicle();
             MySqlDataReader reader = null;
-            string sql = "select * from vehicle where numberPlate = '" + numberPlate + "'";
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "'";
             con = oper.getConn();
             try
             {

+ 113 - 6
parkMonitor/DBLocation/DBLocation.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using MySql.Data.MySqlClient;
+using parkMonitor.DB;
 
 namespace parkMonitor.DBLocation
 {
@@ -198,10 +199,10 @@ namespace parkMonitor.DBLocation
         }
 
         //车库有无此车
-        public bool IsNumberPlate(string numberPlate)
+        public bool IsNumberPlate(string numberPlate,int garageID)
         {
             bool isNumberPlate = true;
-            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3";
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '"+garageID+"'";
             con = oper.getConn();
             try
             {
@@ -230,9 +231,9 @@ namespace parkMonitor.DBLocation
         }
 
         //数据插入记录表,并返回停车记录id
-        public int InsertToParkingRecords(int parkingStatus, int userID, string numberPlate, int parkingSpaceID, int garageID, int parkingRecordsState, string realParkTime)
+        public int InsertToParkingRecords(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) values('" + parkingStatus + "','" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "')";
+            string sql = "insert into parkingrecords(parkingStatus,userID,numberPlate,parkingSpaceID,garageID,parkingRecordsState,realParkTime,frontWheelbase,rearWheelbase) values('" + parkingStatus + "','" + userID + "','" + numberPlate + "','" + parkingSpaceID + "','" + garageID + "','" + parkingRecordsState + "','" + realParkTime + "','" + frontWheelbase + "','" + rearWheelbase + "')";
             con = oper.getConn();
             int parkingRecordsID = 0;
             try
@@ -339,7 +340,7 @@ namespace parkMonitor.DBLocation
         //更新停车记录表
         public void UpdateParkingRecords(int parkingStatus, int parkingRecordsState, string realGetTime, int parkingRecordsID)
         {
-            string sql = "update parkingrecords set parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
+            string sql = "update parkingrecords set parkingStatus = '"+parkingStatus+"', parkingRecordsState = '" + parkingRecordsState + "',realGetTime = '" + realGetTime + "'where parkingRecordsID = '" + parkingRecordsID + "'";
             con = oper.getConn();
             try
             {
@@ -447,7 +448,7 @@ namespace parkMonitor.DBLocation
         }
 
         //查询手动停车的车位ID
-        public int[] GetParkingSpaceID()
+        public int[] GetAllParkingSpaceID()
         {
             int parkingSpaceID = 0;
             List<int> listID = new List<int>();
@@ -487,5 +488,111 @@ namespace parkMonitor.DBLocation
             listID.Add(parkingSpaceID);
             return listID.ToArray();
         }
+
+        //查询车位位置及状态,返回list
+        public List<Parking_Space> GetParkingSpace()
+        {
+            List<Parking_Space> lps = new List<Parking_Space>();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingspace where parkingSpaceState = 0 ";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                reader = oper.getResultSet(cmd);
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        int parkingSpaceID = reader.GetInt32("parkingSpaceID");
+                        //float parkingSpaceWeight = reader.GetFloat("parkingSpaceWeight");
+                        //int parkingSpaceStatement = reader.GetInt32("parkingSpaceState");
+                        int garageID = reader.GetInt32("garageID");
+                        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.parkingSpaceWeight = parkingSpaceWeight;
+                        //ps.parkingSpaceStatement = parkingSpaceStatement;
+                        ps.parkingSpaceX = parkingSpaceX;
+                        ps.parkingSpaceY = parkingSpaceY;
+                        ps.parkingSpaceZ = parkingSpaceZ;
+
+                        lps.Add(ps);
+                    }
+                }
+                if (reader != null)
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+                if (cmd != null)
+                {
+                    cmd.Dispose();
+                }
+                if (con != null)
+                {
+                    con.Close();
+                    con.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return lps;
+        }
+
+        //根据车牌查询得到车库id和车位id以及轮距
+        public Vehicle GetVehicle(string numberPlate, int garageID)
+        {
+            // List<Vehicle> lVehicle = new List<Vehicle>();
+            Vehicle v = new Vehicle();
+            MySqlDataReader reader = null;
+            string sql = "select * from parkingrecords where numberPlate = '" + numberPlate + "' and parkingRecordsState = 3 and garageID = '" + garageID + "'";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                reader = oper.getResultSet(cmd);
+                while (reader.Read())
+                {
+                    if (reader.HasRows)
+                    {
+                        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;
+                    }
+                }
+                if (reader != null)
+                {
+                    reader.Close();
+                    reader.Dispose();
+                }
+                if (cmd != null)
+                {
+                    cmd.Dispose();
+                }
+                if (con != null)
+                {
+                    con.Close();
+                    con.Dispose();
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            return v;
+        }
+
     }
 }

+ 4 - 3
parkMonitor/manualParking/ManualParking.cs

@@ -69,12 +69,13 @@ namespace parkMonitor.manualParking
             storeCmd.userID = locationOper.GetUserID(tel.Text).ToString();
             storeCmd.LicenseNum = numberPlate.Text;
             storeCmd.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+            storeCmd.garageID = Convert.ToInt32(selectGarage.Text);
             bool isTelRegister = locationOper.IsTelRegister(tel.Text);
-            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum);
+            bool isNumberPlate = locationOper.IsNumberPlate(storeCmd.LicenseNum, storeCmd.garageID);
             if (isTelRegister == false)
             {
                 MessageBox.Show("该号码未被注册,请先注册");
-            }           
+            }
             else if (isNumberPlate == false)
             {
                 MessageBox.Show("车库中查无此车");
@@ -82,7 +83,7 @@ namespace parkMonitor.manualParking
             else
             {
                 storeCmd.parkingRecordsID = locationOper.GetParkingRecordsID(storeCmd.LicenseNum);
-                if (storeCmd.userID != "" && storeCmd.LicenseNum != "")
+                if (storeCmd.userID != "" && storeCmd.LicenseNum != "" && storeCmd.parkingRecordsID != 0)
                 {
                     qt.SetMessage((Command)storeCmd.Clone());
                     MessageBox.Show("发送成功");

+ 23 - 15
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -480,18 +480,18 @@ namespace parkMonitor.server.CoreThread
                 else
                 {
                     //插入停车记录表
-                    int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime);
-                    //判断车辆表是否存在车辆
-                    bool isNumberPlateFromVehicle = locationOper.IsNumberPlateFromVehicle(numberPlate);
-                    if (isNumberPlateFromVehicle == false)
-                    {
-                        //车辆表更新车辆信息
-                        locationOper.InsertVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
-                    }
-                    else
-                    {
-                        locationOper.UpdateVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
-                    }
+                    int parkingRecordsID = locationOper.InsertToParkingRecords(1, userID, numberPlate, parkingSpaceID, garageID, 3, realParkTime, frontWheelbase, rearWheelbase);
+                    ////判断车辆表是否存在车辆
+                    //bool isNumberPlateFromVehicle = locationOper.IsNumberPlateFromVehicle(numberPlate);
+                    //if (isNumberPlateFromVehicle == false)
+                    //{
+                    //    //车辆表更新车辆信息
+                    //    locationOper.InsertVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
+                    //}
+                    //else
+                    //{
+                    //    locationOper.UpdateVehicle(numberPlate, 1, parkingRecordsID, parkingSpaceID, 1);
+                    //}
                     //更新车库表剩余车位数
                     int freeSpaceCount = locationOper.getGarageFreeSpace(garageID);
                     freeSpaceCount = freeSpaceCount - 1;
@@ -520,7 +520,15 @@ namespace parkMonitor.server.CoreThread
         public override void executeCmd(Command queueCmd)
         {
             PLCMessage PLCMsg = null;
-            Vehicle vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
+            Vehicle vehiclelist = null;
+            if (queueCmd.manual)
+            {
+                vehiclelist = locationOper.GetVehicle(queueCmd.LicenseNum, queueCmd.garageID);
+            }
+            else
+            {
+                vehiclelist = oper.GetVehicle(queueCmd.LicenseNum);
+            }
             int parkingSpaceID = vehiclelist.parkingSpaceID;
             int garageID = vehiclelist.garageID;
             int frontwheelbase = vehiclelist.frontwheelbase;
@@ -615,8 +623,8 @@ namespace parkMonitor.server.CoreThread
                 locationOper.UpdateGarageFreeSpace(freeSpaceCount, garageID);
                 //更新车位表车位状态
                 locationOper.UpdateParkingSpaceState(parkingSpaceID, 0);
-                //更新车辆表车辆停车状态
-                locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
+                ////更新车辆表车辆停车状态
+                //locationOper.UpdateVehicleParkState(queueCmd.LicenseNum, 0);
                 //更新停车记录表
                 locationOper.UpdateParkingRecords(0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
             }

+ 13 - 2
parkMonitor/server/CoreThread/AllotParkingSpace.cs

@@ -4,6 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using parkMonitor.DB;
+using parkMonitor.DBLocation;
 using System.Configuration;
 
 namespace parkMonitor.server.CoreThread
@@ -13,8 +14,18 @@ namespace parkMonitor.server.CoreThread
         //根据车位位置及状态分配目标车位,返回Parking Space的ID
         public Parking_Space MallocParkingSpace(CEntrance pt_Ent,object c)
         {
-            DBOperation o = new DBOperation();
-            List<Parking_Space> lps = o.GetParkingSpace();
+            //DBOperation o = new DBOperation();
+            List<Parking_Space> lps = null;
+            if (c.GetType() == typeof(DBOperation))
+            {
+                DBOperation oper = (DBOperation)c;
+                lps = oper.GetParkingSpace();
+            }
+            else
+            {
+                DBLocationOperator locationOper = (DBLocationOperator)c;
+                lps = locationOper.GetParkingSpace();
+            }
             double xWeight = Convert.ToDouble(ConfigurationManager.AppSettings["xWeight"]);
             double yWeight = Convert.ToDouble(ConfigurationManager.AppSettings["yWeight"]);
             double zWeight = Convert.ToDouble(ConfigurationManager.AppSettings["zWeight"]);

+ 2 - 2
parkMonitor/server/CoreThread/QueuingThread.cs

@@ -349,8 +349,8 @@ namespace parkMonitor.server.CoreThread
             else if (message.GetType().Equals(typeof(Command)))
             {
                 Command command = (Command)message;
-                command.garageID = 0;
-                command.parkingRecordsID = 0;
+                //command.garageID = 0;
+                //command.parkingRecordsID = 0;
                 command.TimeRecord = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                 //input user command
                 if (command != null)