Procházet zdrojové kódy

机械手释放调整,加入手动初始化功能,加入数据库自定义连接关闭方法

yc_t před 7 roky
rodič
revize
0bdf52372f

+ 2 - 2
parkMonitor/DataBase/DBOperation.cs

@@ -253,7 +253,7 @@ namespace parkMonitor.DataBase
             }
             else
             {
-                Console.WriteLine("云端轮距查无结果");
+                Console.WriteLine("云端车辆查无结果");
             }
             oper.DBClose(reader);
             return null;
@@ -543,7 +543,7 @@ namespace parkMonitor.DataBase
             }
             else
             {
-                Console.WriteLine("本地轮距查无结果");
+                Console.WriteLine("本地车辆查无结果");
             }
             oper.DBClose(reader);
             return null;

+ 14 - 7
parkMonitor/DataBase/IDBOperation.cs

@@ -171,6 +171,8 @@ namespace parkMonitor.DataBase
                 }
                 catch { return false; }
                 UILogServer.ins.error("数据库操作失败,事务回滚");
+                if (cmd != null) { cmd.Dispose(); }
+                if (conn != null) { conn.Close();conn.Dispose(); }
             }
             return false;
         }
@@ -240,10 +242,7 @@ namespace parkMonitor.DataBase
             }
         }
 
-        /// <summary>
-        /// 关闭连接
-        /// </summary>
-        public void DBClose()
+        public static void DBClose(MySqlConnection conn, MySqlCommand cmd, MySqlDataReader reader)
         {
             if (reader != null)
             {
@@ -254,13 +253,21 @@ namespace parkMonitor.DataBase
             {
                 cmd.Dispose();
             }
-            if (con != null)
+            if (conn != null)
             {
-                con.Close();
-                con.Dispose();
+                conn.Close();
+                conn.Dispose();
             }
         }
 
+        /// <summary>
+        /// 关闭连接
+        /// </summary>
+        public void DBClose()
+        {
+            DBClose(con, cmd, reader);
+        }
+
         /// <summary>
         /// 关闭连接
         /// </summary>

+ 16 - 3
parkMonitor/controlPanel/ControlPanel.Designer.cs

@@ -34,6 +34,7 @@
             this.flp_buffer = new System.Windows.Forms.FlowLayoutPanel();
             this.btn_remoteDB = new System.Windows.Forms.Button();
             this.btn_localDB = new System.Windows.Forms.Button();
+            this.btn_reInit = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // btn_buffer_confirm
@@ -76,7 +77,7 @@
             // 
             // btn_remoteDB
             // 
-            this.btn_remoteDB.Location = new System.Drawing.Point(151, 34);
+            this.btn_remoteDB.Location = new System.Drawing.Point(250, 79);
             this.btn_remoteDB.Name = "btn_remoteDB";
             this.btn_remoteDB.Size = new System.Drawing.Size(98, 23);
             this.btn_remoteDB.TabIndex = 6;
@@ -86,7 +87,7 @@
             // 
             // btn_localDB
             // 
-            this.btn_localDB.Location = new System.Drawing.Point(151, 74);
+            this.btn_localDB.Location = new System.Drawing.Point(250, 34);
             this.btn_localDB.Name = "btn_localDB";
             this.btn_localDB.Size = new System.Drawing.Size(98, 23);
             this.btn_localDB.TabIndex = 7;
@@ -94,11 +95,22 @@
             this.btn_localDB.UseVisualStyleBackColor = true;
             this.btn_localDB.Click += new System.EventHandler(this.btn_localDB_Click);
             // 
+            // btn_reInit
+            // 
+            this.btn_reInit.Location = new System.Drawing.Point(151, 34);
+            this.btn_reInit.Name = "btn_reInit";
+            this.btn_reInit.Size = new System.Drawing.Size(75, 23);
+            this.btn_reInit.TabIndex = 8;
+            this.btn_reInit.Text = "手动初始化";
+            this.btn_reInit.UseVisualStyleBackColor = true;
+            this.btn_reInit.Click += new System.EventHandler(this.btn_reInit_Click);
+            // 
             // ControlPanel
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(356, 230);
+            this.ClientSize = new System.Drawing.Size(369, 242);
+            this.Controls.Add(this.btn_reInit);
             this.Controls.Add(this.btn_localDB);
             this.Controls.Add(this.btn_remoteDB);
             this.Controls.Add(this.flp_buffer);
@@ -119,5 +131,6 @@
         private System.Windows.Forms.FlowLayoutPanel flp_buffer;
         private System.Windows.Forms.Button btn_remoteDB;
         private System.Windows.Forms.Button btn_localDB;
+        private System.Windows.Forms.Button btn_reInit;
     }
 }

+ 9 - 0
parkMonitor/controlPanel/ControlPanel.cs

@@ -1,5 +1,6 @@
 using MySql.Data.MySqlClient;
 using parkMonitor.DataBase;
+using parkMonitor.entity;
 using parkMonitor.server.CoreThread;
 using System;
 using System.Collections.Generic;
@@ -108,6 +109,7 @@ namespace parkMonitor.controlPanel
                 {
                     Operation.TryOpen(conn);
                     initState = conn.Ping();
+                    Operation.DBClose(conn,null,null);
                 }
                 if (initState)
                 {
@@ -126,6 +128,7 @@ namespace parkMonitor.controlPanel
                 {
                     Operation.TryOpen(conn);
                     initState = conn.Ping();
+                    Operation.DBClose(conn, null, null);
                 }
                 if (initState)
                 {
@@ -134,5 +137,11 @@ namespace parkMonitor.controlPanel
                 }
             }
         }
+
+        private void btn_reInit_Click(object sender, EventArgs e)
+        {
+            InitWin iw = new InitWin();
+            iw.ShowDialog();
+        }
     }
 }

+ 131 - 0
parkMonitor/controlPanel/InitWin.Designer.cs

@@ -0,0 +1,131 @@
+namespace parkMonitor.controlPanel
+{
+    partial class InitWin
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.label1 = new System.Windows.Forms.Label();
+            this.rbtn_1 = new System.Windows.Forms.RadioButton();
+            this.rbtn_2 = new System.Windows.Forms.RadioButton();
+            this.rbtn_3 = new System.Windows.Forms.RadioButton();
+            this.gb1 = new System.Windows.Forms.GroupBox();
+            this.btn_confirm = new System.Windows.Forms.Button();
+            this.gb1.SuspendLayout();
+            this.SuspendLayout();
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("宋体", 11F);
+            this.label1.Location = new System.Drawing.Point(32, 25);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(247, 15);
+            this.label1.TabIndex = 0;
+            this.label1.Text = "请选择需要初始化的数据库连接配置";
+            // 
+            // rbtn_1
+            // 
+            this.rbtn_1.AutoSize = true;
+            this.rbtn_1.Location = new System.Drawing.Point(6, 20);
+            this.rbtn_1.Name = "rbtn_1";
+            this.rbtn_1.Size = new System.Drawing.Size(203, 16);
+            this.rbtn_1.TabIndex = 1;
+            this.rbtn_1.TabStop = true;
+            this.rbtn_1.Text = "默认,检查远端与本地数据库连接";
+            this.rbtn_1.UseVisualStyleBackColor = true;
+            // 
+            // rbtn_2
+            // 
+            this.rbtn_2.AutoSize = true;
+            this.rbtn_2.Location = new System.Drawing.Point(6, 56);
+            this.rbtn_2.Name = "rbtn_2";
+            this.rbtn_2.Size = new System.Drawing.Size(143, 16);
+            this.rbtn_2.TabIndex = 2;
+            this.rbtn_2.TabStop = true;
+            this.rbtn_2.Text = "仅检查远端数据库连接";
+            this.rbtn_2.UseVisualStyleBackColor = true;
+            // 
+            // rbtn_3
+            // 
+            this.rbtn_3.AutoSize = true;
+            this.rbtn_3.Location = new System.Drawing.Point(6, 95);
+            this.rbtn_3.Name = "rbtn_3";
+            this.rbtn_3.Size = new System.Drawing.Size(143, 16);
+            this.rbtn_3.TabIndex = 3;
+            this.rbtn_3.TabStop = true;
+            this.rbtn_3.Text = "仅检查本地数据库连接";
+            this.rbtn_3.UseVisualStyleBackColor = true;
+            // 
+            // gb1
+            // 
+            this.gb1.Controls.Add(this.rbtn_1);
+            this.gb1.Controls.Add(this.rbtn_3);
+            this.gb1.Controls.Add(this.rbtn_2);
+            this.gb1.Location = new System.Drawing.Point(35, 54);
+            this.gb1.Name = "gb1";
+            this.gb1.Size = new System.Drawing.Size(239, 136);
+            this.gb1.TabIndex = 4;
+            this.gb1.TabStop = false;
+            this.gb1.Text = "选项";
+            // 
+            // btn_confirm
+            // 
+            this.btn_confirm.Location = new System.Drawing.Point(109, 196);
+            this.btn_confirm.Name = "btn_confirm";
+            this.btn_confirm.Size = new System.Drawing.Size(75, 23);
+            this.btn_confirm.TabIndex = 5;
+            this.btn_confirm.Text = "确认";
+            this.btn_confirm.UseVisualStyleBackColor = true;
+            this.btn_confirm.Click += new System.EventHandler(this.btn_confirm_Click);
+            // 
+            // InitWin
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(333, 238);
+            this.Controls.Add(this.btn_confirm);
+            this.Controls.Add(this.gb1);
+            this.Controls.Add(this.label1);
+            this.Name = "InitWin";
+            this.Text = "InitWin";
+            this.gb1.ResumeLayout(false);
+            this.gb1.PerformLayout();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.RadioButton rbtn_1;
+        private System.Windows.Forms.RadioButton rbtn_2;
+        private System.Windows.Forms.RadioButton rbtn_3;
+        private System.Windows.Forms.GroupBox gb1;
+        private System.Windows.Forms.Button btn_confirm;
+    }
+}

+ 37 - 0
parkMonitor/controlPanel/InitWin.cs

@@ -0,0 +1,37 @@
+using parkMonitor.entity;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace parkMonitor.controlPanel
+{
+    public partial class InitWin : Form
+    {
+        public InitWin()
+        {
+            InitializeComponent();
+        }
+
+        private void btn_confirm_Click(object sender, EventArgs e)
+        {
+            if (rbtn_1.Enabled)
+            {
+                EntityForCore.ins.globalStatus = EntityForCore.ins.ReInit(0);
+            }
+            else if (rbtn_2.Enabled)
+            {
+                EntityForCore.ins.globalStatus = EntityForCore.ins.ReInit(1);
+            }
+            else if (rbtn_3.Enabled)
+            {
+                EntityForCore.ins.globalStatus = EntityForCore.ins.ReInit(2);
+            }
+        }
+    }
+}

+ 120 - 0
parkMonitor/controlPanel/InitWin.resx

@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>

+ 45 - 1
parkMonitor/entity/EntityForCore.cs

@@ -60,7 +60,7 @@ namespace parkMonitor.entity
         /// <returns></returns>
         public bool Init()
         {
-            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "******************************** 新的开始 ********************************");
+            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "******************************************* 新的开始 *******************************************");
             bool initState = true;
             //数据库连接参数初始化及连接测试
             Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "数据库初始配置");
@@ -89,5 +89,49 @@ namespace parkMonitor.entity
             initState = initState && ParkingBufferManager.ins.InitParkingBuffers();
             return initState;
         }
+
+        /// <summary>
+        /// 中控系统初始化
+        /// </summary>
+        /// <param name="DBmode">0 默认检查所有DB;1 远端;2 本地</param>
+        /// <returns></returns>
+        public bool ReInit(int DBmode)
+        {
+            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "******************************************* 系统重新初始化 *******************************************");
+            UILogServer.ins.info("系统初始化中......");
+            bool initState = true;
+            //数据库连接参数初始化及连接测试
+            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "数据库初始配置");
+            DBConnection.Init();
+            //远端连接测试
+            if (DBmode == 0 || DBmode == 1)
+            {
+                using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
+                {
+                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "远端数据库连接测试");
+                    Operation.TryOpen(conn);
+                    initState = conn.Ping();
+                }
+            }
+            //本地连接测试
+            if (DBmode == 0 || DBmode == 1)
+            {
+                using (MySqlConnection conn = new MySqlConnection(DBConnection.localConf))
+                {
+                    Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "本地数据库连接测试");
+                    Operation.TryOpen(conn);
+                    initState = initState && conn.Ping();
+                }
+            }
+            //车位管理初始化
+            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "初始化车位");
+            ParkingSpaceManager.ins = new ParkingSpaceManager();
+            initState = initState && ParkingSpaceManager.ins.InitParkingSpace();
+            //缓冲位初始化
+            Log.WriteLog(LogType.NOT_DATABASE, LogFile.LOG, "初始化缓冲位");
+            ParkingBufferManager.ins = new ParkingBufferManager();
+            initState = initState && ParkingBufferManager.ins.InitParkingBuffers();
+            return initState;
+        }
     }
 }

+ 9 - 0
parkMonitor/parkMonitor.csproj

@@ -93,6 +93,12 @@
     <Compile Include="controlPanel\ControlPanel.Designer.cs">
       <DependentUpon>ControlPanel.cs</DependentUpon>
     </Compile>
+    <Compile Include="controlPanel\InitWin.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="controlPanel\InitWin.Designer.cs">
+      <DependentUpon>InitWin.cs</DependentUpon>
+    </Compile>
     <Compile Include="DataBase\DBConnection.cs" />
     <Compile Include="DataBase\DBOperation.cs" />
     <Compile Include="DataBase\IDBOperation.cs" />
@@ -475,6 +481,9 @@
     <EmbeddedResource Include="controlPanel\ControlPanel.resx">
       <DependentUpon>ControlPanel.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="controlPanel\InitWin.resx">
+      <DependentUpon>InitWin.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="manualParking\ManualParking.resx">
       <DependentUpon>ManualParking.cs</DependentUpon>
     </EmbeddedResource>

+ 51 - 25
parkMonitor/server/CoreThread/AbstractCmd.cs

@@ -177,6 +177,7 @@ namespace parkMonitor.server.CoreThread
                         if (MyTimer.restart && !mt.rolledBack)
                         {
                             mt.rolledBack = true;
+                            Robot.robot1.occupied = false;
                             UILogServer.ins.error("启动机械手资源超时,已启动回滚");
                             Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "启动机械手资源超时,已启动回滚");
                             return false;
@@ -201,8 +202,7 @@ namespace parkMonitor.server.CoreThread
             //命令回退
             queueCmd.returnedCount += 1;
             queuingThread.SetMessage(queueCmd);
-            //释放机械手
-            Robot.robot1.occupied = false;
+            //线程计数调整
             Robot.robot1.waitCount -= 1;
             //释放激光
             if (lm != null)
@@ -315,15 +315,6 @@ namespace parkMonitor.server.CoreThread
                 }
             }
         }
-
-        public void sqlRecord(string sql)
-        {
-
-        }
-        public void sqlRecord(List<string> sqls)
-        {
-
-        }
     }
 
     /// <summary>
@@ -665,7 +656,7 @@ namespace parkMonitor.server.CoreThread
             LaserMessage lmToBeReleased;          //激光
             int freeSpaceCount = 0;                    //剩余空闲车位
             dataReal = WaitForLaserResource(queueCmd, disappeared, out lmToBeReleased);
-            //判断激光资源有效性,无效则回滚
+            //判断激光资源有效性,无效代表超时且已点击回滚按钮
             if (dataReal == null)
             {
                 Rollback(queueCmd, 0, false, true, lmToBeReleased);
@@ -674,8 +665,8 @@ namespace parkMonitor.server.CoreThread
             //车位分配锁
             lock (Parking_Space.spaceLock)
             {
-                //获取缓冲位资源
                 bool displayed = false;
+                //等待获取缓冲位资源
                 while (pb == null && !MyTimer.restart)
                 {
                     pb = ParkingBufferManager.ins.MallocParkingBuffer(queueCmd.id);
@@ -683,10 +674,11 @@ namespace parkMonitor.server.CoreThread
                     {
                         Log.WriteLog(LogType.NOT_DATABASE, LogFile.INFO, queueCmd.LicenseNum + "分配缓冲位:" + pb.bufferID);
                         break;
-                    }else if (!displayed)
+                    }
+                    else if (!displayed)
                     {
                         UILogServer.ins.error(queueCmd.LicenseNum + "缓冲位已满");
-                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, queueCmd.LicenseNum + "缓冲位分配失败");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.WARNING, queueCmd.LicenseNum + "缓冲位分配失败");
                         displayed = true;
                     }
                     Thread.Sleep(2000);
@@ -768,14 +760,22 @@ namespace parkMonitor.server.CoreThread
                             List<string> strs = new List<string>();
                             strs.Add(updateParkingSpaceSql);
                             strs.Add(updateFreeSpaceSql);
-                            while (!Operation.MyTransaction(conn, strs, out temp))
+                            if (!Operation.MyTransaction(conn, strs, out temp))
                             {
-                                //此处为关键步骤,不记入日志
-                                Thread.Sleep(5000);
-                                if (MyTimer.restart)
+                                //此处为关键步骤,不记入日志,设置全局状态异常
+                                EntityForCore.ins.globalStatus = false;
+                                int count = 0;
+                                while (!MyTimer.restart)
                                 {
-                                    Rollback(queueCmd, ppp.parkingSpaceID,false,true, lmToBeReleased);
+                                    count++;
+                                    if (count == 1)
+                                    {
+                                        UILogServer.ins.error("数据库操作异常");
+                                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "缓冲位分配失败,流程已回滚");
+                                    }
+                                    Thread.Sleep(5000);
                                 }
+                                Rollback(queueCmd, ppp.parkingSpaceID, false, true, lmToBeReleased);
                                 ////数据库操作失败写日志
                                 //Log.WriteLog(LogType.DATABASE, "0",updateParkingSpaceSql);
                                 //Log.WriteLog(LogType.DATABASE, "0",updateFreeSpaceSql);
@@ -923,7 +923,7 @@ namespace parkMonitor.server.CoreThread
                                 if (!Operation.MyTransaction(conn, insertRecordSql, out parkingRecordsID))
                                 {
                                     //数据库操作失败写日志
-                                    Log.WriteLog(LogType.DATABASE, "1",insertRecordSql);
+                                    Log.WriteLog(LogType.DATABASE, "1", insertRecordSql);
                                 }
                             }
                             using (MySqlConnection conn = new MySqlConnection(DBConnection.remoteConf))
@@ -934,7 +934,7 @@ namespace parkMonitor.server.CoreThread
                                 if (!Operation.MyTransaction(conn, updateVehicleSql, out temp))
                                 {
                                     //数据库操作失败写日志
-                                    Log.WriteLog(LogType.DATABASE,"0", updateVehicleSql);
+                                    Log.WriteLog(LogType.DATABASE, "0", updateVehicleSql);
                                 }
                             }
                         }
@@ -1062,6 +1062,19 @@ namespace parkMonitor.server.CoreThread
             }
             if (vehiclelist == null)
             {
+                //无法获取车辆信息,流程中止
+                EntityForCore.ins.globalStatus = false;
+                int count = 0;
+                while (!MyTimer.restart)
+                {
+                    count++;
+                    if (count == 1)
+                    {
+                        UILogServer.ins.error("无法获取车辆信息");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "无法从数据库获取车辆信息,流程中止");
+                    }
+                    Thread.Sleep(5000);
+                }
                 Rollback(queueCmd, 0, false, false, null);
                 return;
             }
@@ -1069,7 +1082,7 @@ namespace parkMonitor.server.CoreThread
             garageID = vehiclelist.garageID;
             frontwheelbase = vehiclelist.frontwheelbase;
             rearwheelbase = vehiclelist.rearwheelbase;
-            queueCmd.parkingRecordsID = vehiclelist.parkingRecordsID;         
+            queueCmd.parkingRecordsID = vehiclelist.parkingRecordsID;
             //获取车位表中车辆具体的车位信息
             //if (queueCmd.manual)
             //{
@@ -1083,6 +1096,18 @@ namespace parkMonitor.server.CoreThread
             //}
             if (!ParkingSpaceManager.ins.parkingSpaceStatusMap.TryGetValue(parkingSpaceID, out ps) || ps == null)
             {
+                EntityForCore.ins.globalStatus = false;
+                int count = 0;
+                while (!MyTimer.restart)
+                {
+                    count++;
+                    if (count == 1)
+                    {
+                        UILogServer.ins.error("车位分配出现异常!!!");
+                        Log.WriteLog(LogType.NOT_DATABASE, LogFile.ERROR, "车位分配出现异常!!!");
+                    }
+                    Thread.Sleep(5000);
+                }
                 Rollback(queueCmd, parkingSpaceID, false, false, null);
                 return;
             }
@@ -1186,8 +1211,8 @@ namespace parkMonitor.server.CoreThread
                                 {
                                     Log.WriteLog(LogType.NOT_DATABASE, "数据库操作出错,记录sql语句等待流程回滚");
                                     //写日志记录sql,以待之后处理
-                                    Log.WriteLog(LogType.DATABASE, "0",updateParkingSpaceStateSql);
-                                    Log.WriteLog(LogType.DATABASE, "0",updateFreeSpaceSql);
+                                    Log.WriteLog(LogType.DATABASE, "0", updateParkingSpaceStateSql);
+                                    Log.WriteLog(LogType.DATABASE, "0", updateFreeSpaceSql);
                                     Log.WriteLog(LogType.DATABASE, "0", updateVehicleStateSql);
                                     Log.WriteLog(LogType.DATABASE, "0", updateParkingRecordsSql);
                                 }
@@ -1213,6 +1238,7 @@ namespace parkMonitor.server.CoreThread
                         oper.UpdateParkingRecords(connectionStr, 0, 6, queueCmd.TimeRecord, queueCmd.parkingRecordsID);
                     }
                 }
+                Thread.Sleep(1000);
             }
         }
     }

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

@@ -354,9 +354,9 @@ namespace parkMonitor.server.CoreThread
                         FetchCmdQueue.Enqueue(cmd);
                     }else
                     {
-                        ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                         UILogServer.ins.info("任务:取出号牌为 " + cmd.LicenseNum + " 的车辆,开始排队");
                         Log.WriteLog(LogType.NOT_DATABASE, "取车命令:" + cmd.LicenseNum + "已进入可执行队列");
+                        ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                     }
                 }
             }
@@ -371,9 +371,9 @@ namespace parkMonitor.server.CoreThread
                     }
                     else
                     {
-                        ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                         UILogServer.ins.info("任务:存入号牌为 " + cmd.LicenseNum + " 的车辆,开始排队");
                         Log.WriteLog(LogType.NOT_DATABASE, "停车命令:" + cmd.LicenseNum + "已进入可执行队列");
+                        ExecutableCmdQueue.Enqueue((Command)cmd.Clone());
                     }
                 }
             }

+ 2 - 2
parkMonitor/server/NumMachine/ParkingSimul.cs

@@ -17,12 +17,12 @@ namespace parkMonitor.server.NumMachine
     class ParkingSimul
     {
         public static ParkingSimul ins;
-        private const string hostname = "119.96.206.151";
+        private const string hostname = "127.0.0.1";
         private const int port = 9000;
         private const string userId = "18202736439";
         private const string garageId = "1";
         private const string header = "鄂A";
-        private const int licInterval = 30000;//30秒
+        private const int licInterval = 5000;//30秒
         private Random rnd;
         private Dictionary<int, CarStatusStru> numStatusMap = new Dictionary<int, CarStatusStru>();
         MessageUTF8 msgToWeb = new MessageUTF8();