Browse Source

加实时事件

shim 7 years ago
parent
commit
a164d075e2
3 changed files with 473 additions and 0 deletions
  1. 195 0
      UAS_CheckWork/Form2.Designer.cs
  2. 143 0
      UAS_CheckWork/Form2.cs
  3. 135 0
      UAS_CheckWork/Form2.resx

+ 195 - 0
UAS_CheckWork/Form2.Designer.cs

@@ -0,0 +1,195 @@
+namespace UAS_CheckWork
+{
+    partial class Form2
+    {
+        /// <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.lblState = new System.Windows.Forms.Label();
+            this.label2 = new System.Windows.Forms.Label();
+            this.label1 = new System.Windows.Forms.Label();
+            this.txtPort = new System.Windows.Forms.TextBox();
+            this.txtIP = new System.Windows.Forms.TextBox();
+            this.btnConnect = new System.Windows.Forms.Button();
+            this.startListening = new System.Windows.Forms.Button();
+            this.logInfo = new System.Windows.Forms.DataGridView();
+            this.UserID = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.AttState = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.VerifyMethod = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.Time = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.WorkCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            ((System.ComponentModel.ISupportInitialize)(this.logInfo)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // lblState
+            // 
+            this.lblState.AutoSize = true;
+            this.lblState.ForeColor = System.Drawing.Color.Crimson;
+            this.lblState.Location = new System.Drawing.Point(540, 35);
+            this.lblState.Name = "lblState";
+            this.lblState.Size = new System.Drawing.Size(107, 18);
+            this.lblState.TabIndex = 21;
+            this.lblState.Text = "状态:未连接";
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label2.Location = new System.Drawing.Point(252, 28);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(62, 31);
+            this.label2.TabIndex = 20;
+            this.label2.Text = "Port";
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.label1.Location = new System.Drawing.Point(38, 26);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(36, 31);
+            this.label1.TabIndex = 19;
+            this.label1.Text = "IP";
+            // 
+            // txtPort
+            // 
+            this.txtPort.Location = new System.Drawing.Point(324, 28);
+            this.txtPort.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.txtPort.Name = "txtPort";
+            this.txtPort.Size = new System.Drawing.Size(54, 28);
+            this.txtPort.TabIndex = 18;
+            this.txtPort.Text = "4370";
+            // 
+            // txtIP
+            // 
+            this.txtIP.Location = new System.Drawing.Point(89, 28);
+            this.txtIP.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.txtIP.Name = "txtIP";
+            this.txtIP.Size = new System.Drawing.Size(146, 28);
+            this.txtIP.TabIndex = 17;
+            this.txtIP.Text = "192.168.253.201";
+            // 
+            // btnConnect
+            // 
+            this.btnConnect.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
+            this.btnConnect.Location = new System.Drawing.Point(420, 24);
+            this.btnConnect.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
+            this.btnConnect.Name = "btnConnect";
+            this.btnConnect.Size = new System.Drawing.Size(75, 38);
+            this.btnConnect.TabIndex = 16;
+            this.btnConnect.Text = "连接";
+            this.btnConnect.UseVisualStyleBackColor = true;
+            this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
+            // 
+            // startListening
+            // 
+            this.startListening.BackColor = System.Drawing.SystemColors.ControlLightLight;
+            this.startListening.Location = new System.Drawing.Point(677, 27);
+            this.startListening.Name = "startListening";
+            this.startListening.Size = new System.Drawing.Size(127, 36);
+            this.startListening.TabIndex = 22;
+            this.startListening.Text = "开始实时事件";
+            this.startListening.UseVisualStyleBackColor = false;
+            this.startListening.Click += new System.EventHandler(this.startListening_Click);
+            // 
+            // logInfo
+            // 
+            this.logInfo.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+            this.logInfo.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+            this.UserID,
+            this.AttState,
+            this.VerifyMethod,
+            this.Time,
+            this.WorkCode});
+            this.logInfo.Location = new System.Drawing.Point(44, 98);
+            this.logInfo.Name = "logInfo";
+            this.logInfo.RowTemplate.Height = 30;
+            this.logInfo.Size = new System.Drawing.Size(760, 381);
+            this.logInfo.TabIndex = 23;
+            // 
+            // UserID
+            // 
+            this.UserID.HeaderText = "用户ID";
+            this.UserID.Name = "UserID";
+            // 
+            // AttState
+            // 
+            this.AttState.HeaderText = "考勤状态";
+            this.AttState.Name = "AttState";
+            // 
+            // VerifyMethod
+            // 
+            this.VerifyMethod.HeaderText = "验证方式";
+            this.VerifyMethod.Name = "VerifyMethod";
+            // 
+            // Time
+            // 
+            this.Time.HeaderText = "考勤时间";
+            this.Time.Name = "Time";
+            // 
+            // WorkCode
+            // 
+            this.WorkCode.HeaderText = "WorkCode";
+            this.WorkCode.Name = "WorkCode";
+            // 
+            // Form2
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(846, 507);
+            this.Controls.Add(this.logInfo);
+            this.Controls.Add(this.startListening);
+            this.Controls.Add(this.lblState);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.txtPort);
+            this.Controls.Add(this.txtIP);
+            this.Controls.Add(this.btnConnect);
+            this.Name = "Form2";
+            this.Text = "实时获取考勤";
+            ((System.ComponentModel.ISupportInitialize)(this.logInfo)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label lblState;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.TextBox txtPort;
+        private System.Windows.Forms.TextBox txtIP;
+        private System.Windows.Forms.Button btnConnect;
+        private System.Windows.Forms.Button startListening;
+        private System.Windows.Forms.DataGridView logInfo;
+        private System.Windows.Forms.DataGridViewTextBoxColumn UserID;
+        private System.Windows.Forms.DataGridViewTextBoxColumn AttState;
+        private System.Windows.Forms.DataGridViewTextBoxColumn VerifyMethod;
+        private System.Windows.Forms.DataGridViewTextBoxColumn Time;
+        private System.Windows.Forms.DataGridViewTextBoxColumn WorkCode;
+    }
+}

+ 143 - 0
UAS_CheckWork/Form2.cs

@@ -0,0 +1,143 @@
+using Check.DataOperate;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace UAS_CheckWork
+{
+    public partial class Form2 : Form
+    {
+        public Form2()
+        {
+            InitializeComponent();
+            //new Thread(() =>
+            //{
+            //    while (true)
+            //    {
+            //        try { label1.BeginInvoke(new MethodInvoker(() => label1.Text = DateTime.Now.ToString())); }
+            //        catch { }
+            //        Thread.Sleep(1000);
+            //    }
+            //})
+            //{ IsBackground = true }.Start();
+        }
+        DataHelper dh;
+        //Create Standalone SDK class dynamicly.
+        public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
+        private bool bIsConnected = false;//the boolean value identifies whether the device is connected
+        private int iMachineNumber = 1;//the serial number of the device.After connecting the device ,this value will be changed.
+
+        private void btnConnect_Click(object sender, EventArgs e)
+        {
+            if (txtIP.Text.Trim() == "" || txtPort.Text.Trim() == "")
+            {
+                MessageBox.Show("请先输入IP和端口", "Error");
+                return;
+            }
+            int idwErrorCode = 0;
+
+            Cursor = Cursors.WaitCursor;
+            if (btnConnect.Text == "断开连接")
+            {
+                axCZKEM1.Disconnect();
+                bIsConnected = false;
+                btnConnect.Text = "连接";
+                lblState.Text = "状态:未连接";
+                Cursor = Cursors.Default;
+                return;
+            }
+            bIsConnected = axCZKEM1.Connect_Net(txtIP.Text, Convert.ToInt32(txtPort.Text));
+            if (bIsConnected)
+            {
+                btnConnect.Text = "断开连接";
+                btnConnect.Refresh();
+                lblState.Text = "状态:已连接";
+                iMachineNumber = 1;//In fact,when you are using the tcp/ip communication,this parameter will be ignored,that is any integer will all right.Here we use 1.
+                axCZKEM1.RegEvent(iMachineNumber, 65535);//Here you can register the realtime events that you want to be triggered(the parameters 65535 means registering all)
+            }
+            else
+            {
+                axCZKEM1.GetLastError(ref idwErrorCode);
+                MessageBox.Show("无法连接设备,ErrorCode=" + idwErrorCode.ToString(), "Error");
+            }
+            Cursor = Cursors.Default;
+        }
+
+        private void startListening_Click(object sender, EventArgs e)
+        {
+            if (!bIsConnected)
+            {
+                MessageBox.Show("请先连接设备", "Error");
+                return;
+            }
+            int idwErrorCode = 0;
+            //开始注册考勤机的监听事件
+            if (axCZKEM1.RegEvent(iMachineNumber, 1))//65535表示注册所有的事件
+            {
+                //注册事件
+                this.axCZKEM1.OnAttTransactionEx += new zkemkeeper._IZKEMEvents_OnAttTransactionExEventHandler(axCZKEM1_OnAttTransactionEx);
+            }
+            else
+            {
+                axCZKEM1.GetLastError(ref idwErrorCode);
+                MessageBox.Show("注册监听事件失败,ErrorCode=" + idwErrorCode.ToString(), "Error");
+            }
+        }
+        /// <summary>
+        /// 考勤机验证通过
+        /// </summary>
+        /// <param name="sEnrollNumber">UserID</param>
+        /// <param name="iIsInValid">1 为无效记录,0 为有效记录</param>
+        /// <param name="iAttState">0—Check-In   1—Check-Out  2—Break-Out  3—Break-In   4—OT-In   5—OT-Out </param>
+        /// <param name="iVerifyMethod">:0 为密码验证,1 为指纹验证,2 为卡验证 </param>
+        /// <param name="iYear"></param>
+        /// <param name="iMonth"></param>
+        /// <param name="iDay"></param>
+        /// <param name="iHour"></param>
+        /// <param name="iMinute"></param>
+        /// <param name="iSecond"></param>
+        /// <param name="iWorkCode">WorkCode 返回验证时 WorkCode 值,当机器无 Workcode 功能时,该值返回 0</param>
+        private void axCZKEM1_OnAttTransactionEx(string sEnrollNumber, int iIsInValid, int iAttState, int iVerifyMethod, int iYear, int iMonth, int iDay, int iHour, int iMinute, int iSecond, int iWorkCode)
+        {
+            //实现实时获取考勤,取有效记录
+            if (iIsInValid == 0)
+            {
+                //显示
+                DataTable dt = (DataTable)logInfo.DataSource;
+                DataRow dr = dt.NewRow();//新建行
+                dr["UserID"] = sEnrollNumber;
+                switch (iVerifyMethod)
+                {
+                    case 0:
+                        dr["VerifyMethod"] = "密码";
+                        break;
+                    case 1:
+                        dr["VerifyMethod"] = "指纹";
+                        break;
+                    case 2:
+                        dr["VerifyMethod"] = "卡";
+                        break;
+                    default:
+                        break;
+                }
+                dr["Time"] = iYear + "-" + iMonth + "-" + iDay + " " + iHour + ":" + iMinute + ":" + iSecond;
+                dr["WorkCode"] = iWorkCode;
+                logInfo.DataSource = dt;
+                //更新数据库
+                dh.ExecuteSql("insert into cardlog (cl_id,cl_cardcode,cl_time) values (cardlog_seq.nextval,'"+sEnrollNumber+"',TO_DATE('"+ dr["Time"] + "','yyyy-MM-dd hh24:mi:ss'))","insert");
+            }
+            else
+            {
+                //记录验证无效
+            }
+        }
+    }
+}

+ 135 - 0
UAS_CheckWork/Form2.resx

@@ -0,0 +1,135 @@
+<?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>
+  <metadata name="UserID.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="AttState.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="VerifyMethod.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="Time.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+  <metadata name="WorkCode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>True</value>
+  </metadata>
+</root>