Browse Source

本地注册

kingwang1995 7 years ago
parent
commit
cdff948149

+ 1 - 1
parkMonitor/App.config

@@ -16,7 +16,7 @@
   </Equipments>
   <appSettings>
     <!--数据库连接配置文件-->
-    <!--<add key="SqlConnectionStr" value="Data Source=127.0.0.1;port=3306;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=3306;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=192.168.0.55;port=3306;uid=root;pooling=true;pwd=x5;database=zxpark;CharSet=utf8;Allow Zero Datetime=true;" />-->  
     <!--日志写入地址配置文件-->

+ 2 - 1
parkMonitor/DB/DBOperation.cs

@@ -465,7 +465,7 @@ namespace parkMonitor.DB
             con.Close();
             return v;
         }
-
+        
         //根据车位id获得x,y,z
         public Fetching_Space GetFetchingSpace(int parkingSpaceID)
         {
@@ -505,5 +505,6 @@ namespace parkMonitor.DB
             con.Close();
             return fs;
         }
+    
     }
 }

+ 66 - 0
parkMonitor/DBLocation/DBLocation.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MySql.Data.MySqlClient;
+
+namespace parkMonitor.DBLocation
+{
+    public class DBLocationOperator
+    {
+        private static MySqlConnection con;
+        private static MySqlCommand cmd;
+        IDBLocation oper = new Operator();
+
+        //查询手机号是否被注册
+        public bool IsTelRegister(string tel)
+        {
+            bool isTelRegister = false;
+            string sql1 = "select count(*) from user where userTelephone = '" + tel + "'";
+            string sql = "select * from user where userTelephone = '" + tel + "'";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+                cmd = oper.getComm(sql, con);
+                int count = (int)cmd.ExecuteScalar();
+                if (count > 0)
+                {
+                    isTelRegister = true;
+                }
+                else
+                {
+                    isTelRegister = false;
+                }
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+            con.Close();
+            return isTelRegister;
+        }
+        
+        //注册信息写入数据库,返回注册成功信息
+        public int InsertUser(string tel, string password)
+        {
+            string sql = "insert into user(userTelephone,userPassword,userLevel) values('" + tel + "','" + password + "',1)";
+            con = oper.getConn();
+            try
+            {
+                con.Open();
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.Message);
+            }
+            cmd = oper.getComm(sql, con);
+            oper.getInsert(cmd);
+            int userID = Convert.ToInt32(cmd.LastInsertedId);
+            con.Close();
+            return userID;
+        }
+
+    }
+}

+ 75 - 0
parkMonitor/DBLocation/IDBLocation.cs

@@ -0,0 +1,75 @@
+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 = cmd.ExecuteReader();
+            return reader;
+        }
+
+        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 getDelete(MySqlCommand cmd)
+        {
+            try
+            {
+                cmd.ExecuteNonQuery();
+            }
+            catch (Exception ex)
+            {
+                Console.WriteLine(ex.ToString());
+            }
+        }
+    }
+}

+ 127 - 0
parkMonitor/manualParking/Register.Designer.cs

@@ -0,0 +1,127 @@
+namespace parkMonitor.manualParking
+{
+    partial class Register
+    {
+        /// <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.label2 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.textBox2 = new System.Windows.Forms.TextBox();
+            this.textBox3 = new System.Windows.Forms.TextBox();
+            this.register_now = new System.Windows.Forms.Button();
+            this.SuspendLayout();
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(38, 33);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(41, 12);
+            this.label1.TabIndex = 0;
+            this.label1.Text = "电话:";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(38, 92);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(41, 12);
+            this.label2.TabIndex = 1;
+            this.label2.Text = "密码:";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(38, 153);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(65, 12);
+            this.label3.TabIndex = 2;
+            this.label3.Text = "确认密码:";
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(150, 33);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(100, 21);
+            this.textBox1.TabIndex = 3;
+            // 
+            // textBox2
+            // 
+            this.textBox2.Location = new System.Drawing.Point(150, 92);
+            this.textBox2.Name = "textBox2";
+            this.textBox2.Size = new System.Drawing.Size(100, 21);
+            this.textBox2.TabIndex = 4;
+            // 
+            // textBox3
+            // 
+            this.textBox3.Location = new System.Drawing.Point(150, 153);
+            this.textBox3.Name = "textBox3";
+            this.textBox3.Size = new System.Drawing.Size(100, 21);
+            this.textBox3.TabIndex = 5;
+            // 
+            // register_now
+            // 
+            this.register_now.Location = new System.Drawing.Point(121, 243);
+            this.register_now.Name = "register_now";
+            this.register_now.Size = new System.Drawing.Size(75, 23);
+            this.register_now.TabIndex = 6;
+            this.register_now.Text = "注册";
+            this.register_now.UseVisualStyleBackColor = true;
+            this.register_now.Click += new System.EventHandler(this.register_now_Click);
+            // 
+            // Register
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(396, 313);
+            this.Controls.Add(this.register_now);
+            this.Controls.Add(this.textBox3);
+            this.Controls.Add(this.textBox2);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Name = "Register";
+            this.Text = "Register";
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.TextBox textBox2;
+        private System.Windows.Forms.TextBox textBox3;
+        private System.Windows.Forms.Button register_now;
+    }
+}

+ 74 - 0
parkMonitor/manualParking/Register.cs

@@ -0,0 +1,74 @@
+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;
+using System.Security.Cryptography;
+using parkMonitor.DBLocation;
+
+namespace parkMonitor.manualParking
+{
+    public partial class Register : Form
+    {
+        public Register()
+        {
+            InitializeComponent();           
+        }
+
+        private void register_now_Click(object sender, EventArgs e)
+        {
+            int flag = 0;
+            string tel = this.textBox1.Text;
+            if (tel.Length != 11)
+            {
+                MessageBox.Show("电话号码不合法");
+            }
+            else
+            {
+                flag = flag + 1;
+            }
+            byte[] passwordText = Encoding.Default.GetBytes(this.textBox2.Text.Trim());
+            MD5 md5 = new MD5CryptoServiceProvider();
+            byte[] passwordMD5 = md5.ComputeHash(passwordText);
+            string password = BitConverter.ToString(passwordMD5).Replace("-", "");
+            if ((passwordText.Length < 6 || passwordText.Length > 20) && flag >= 1)
+            {
+                MessageBox.Show("密码格式不正确,请填写6-20位数字或字母");
+            }
+            else
+            {
+                flag = flag + 1;
+            }
+            byte[] passwordSureText = Encoding.Default.GetBytes(this.textBox3.Text.Trim());
+            byte[] passwordSureMD5 = md5.ComputeHash(passwordSureText);
+            string passwordSure = BitConverter.ToString(passwordSureMD5).Replace("-", "");
+            if (!password.Equals(passwordSure) && flag >= 2)
+            {
+                MessageBox.Show("两次密码不一样");
+            }
+            else
+            {
+                flag = flag + 1;
+            }
+            DBLocationOperator locationOper = new DBLocationOperator();
+            bool isTelRegister = locationOper.IsTelRegister(tel);
+            if (isTelRegister&&flag >= 3)
+            {
+                MessageBox.Show("此电话号码已被注册");
+            }
+            else
+            {
+                flag = flag + 1;               
+            }
+            int userID = locationOper.InsertUser(tel, password);
+            if (userID!=0&&flag >= 4)
+            {
+                MessageBox.Show("注册成功");
+            }
+        }
+    }
+}

+ 120 - 0
parkMonitor/manualParking/Register.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>

+ 11 - 0
parkMonitor/parkMonitor.csproj

@@ -85,6 +85,8 @@
       <SubType>Designer</SubType>
     </ApplicationDefinition>
     <Compile Include="bll\MainBll.cs" />
+    <Compile Include="DBLocation\DBLocation.cs" />
+    <Compile Include="DBLocation\IDBLocation.cs" />
     <Compile Include="DB\DBOperation.cs" />
     <Compile Include="DB\DBTest.cs" />
     <Compile Include="DB\Garage.cs" />
@@ -106,6 +108,12 @@
     <Compile Include="manualParking\ManualParking.Designer.cs">
       <DependentUpon>ManualParking.cs</DependentUpon>
     </Compile>
+    <Compile Include="manualParking\Register.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="manualParking\Register.Designer.cs">
+      <DependentUpon>Register.cs</DependentUpon>
+    </Compile>
     <Compile Include="model\EquipmentName.cs" />
     <Compile Include="model\EquipmentsSection.cs" />
     <Compile Include="sdk\superscene\TimeTest.cs" />
@@ -451,6 +459,9 @@
     <EmbeddedResource Include="manualParking\ManualParking.resx">
       <DependentUpon>ManualParking.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="manualParking\Register.resx">
+      <DependentUpon>Register.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>

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

@@ -120,6 +120,7 @@ namespace parkMonitor.server.CoreThread
 
             ParkingMessage pm = new ParkingMessage();
             pm.status = status;
+            pm.address = queueCmd.garageID;//启动对应激光
             PLC.SetMessage(pm);
             Console.WriteLine("停车,开激光:" + queueCmd.LicenseNum);
             Log.WriteLog("停车,开激光:" + queueCmd.LicenseNum);
@@ -174,19 +175,6 @@ namespace parkMonitor.server.CoreThread
                                 length = lm.data.length;
                                 width = lm.data.width;
                                 height = lm.data.height;
-                                status = 2;
-                                pm.status = status;
-                                pm.centerX = Convert.ToString(centerX);
-                                pm.centerY = Convert.ToString(centerY);
-                                pm.angleA = Convert.ToString(angleA);
-                                pm.length = Convert.ToString(length);
-                                pm.width = Convert.ToString(width);
-                                pm.height = Convert.ToString(height);
-                                pm.parkingSpaceID = Convert.ToString(parkingSpaceID);
-                                pm.parkingSpaceX = Convert.ToString(parkingSpaceX);
-                                pm.parkingSpaceY = Convert.ToString(parkingSpaceY);
-                                pm.parkingSpaceZ = Convert.ToString(parkingSpaceZ);
-                                PLC.SetMessage(pm);
                                 jumpOut = true;
                                 break;
                             }
@@ -248,7 +236,7 @@ namespace parkMonitor.server.CoreThread
 
             status = 2;
             pm.status = status;
-            pm.address = Convert.ToInt32(queueCmd.ip);//启动对应激光
+            pm.address = Convert.ToInt32(queueCmd.ip);//启动对应机械手
             pm.centerX = Convert.ToString(centerX);
             pm.centerY = Convert.ToString(centerY);
             pm.angleA = Convert.ToString(angleA);
@@ -381,7 +369,7 @@ namespace parkMonitor.server.CoreThread
             });
             robotFree.Wait();
             pm.status = status;
-            pm.fetchAddress = 1;
+            pm.fetchAddress = 1;    //放置地址
             pm.parkingSpaceID = Convert.ToString(parkingSpaceID);
             pm.parkingSpaceX = Convert.ToString(parkingSpaceX);
             pm.parkingSpaceY = Convert.ToString(parkingSpaceY);

+ 2 - 0
parkMonitor/view/menuBox/MenuBox.xaml.cs

@@ -81,6 +81,8 @@ namespace parkMonitor.view.util {
 
 		/// <summary>菜单-启动Web服务器</summary>
 		private void muRunWebServer_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {
+            Register register = new Register();
+            register.ShowDialog();
             ManualParking mp = new ManualParking();
             mp.ShowDialog();
         }