Browse Source

优化考勤程序

章政 7 years ago
parent
commit
dc66d4b23c
3 changed files with 62 additions and 64 deletions
  1. 22 20
      UAS_CheckWork/Form1.Designer.cs
  2. 38 36
      UAS_CheckWork/Form1.cs
  3. 2 8
      UAS_CheckWork/Form1.resx

+ 22 - 20
UAS_CheckWork/Form1.Designer.cs

@@ -36,11 +36,11 @@
             this.btnConnect = new System.Windows.Forms.Button();
             this.btnConnect = new System.Windows.Forms.Button();
             this.lblState = new System.Windows.Forms.Label();
             this.lblState = new System.Windows.Forms.Label();
             this.showDataGrid = new System.Windows.Forms.DataGridView();
             this.showDataGrid = new System.Windows.Forms.DataGridView();
-            this.人员编号 = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.考勤时间 = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.getAllData = new System.Windows.Forms.Button();
             this.getAllData = new System.Windows.Forms.Button();
             this.allData = new System.Windows.Forms.BindingSource(this.components);
             this.allData = new System.Windows.Forms.BindingSource(this.components);
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
+            this.cl_cardcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
+            this.cl_time = new System.Windows.Forms.DataGridViewTextBoxColumn();
             ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).BeginInit();
             this.SuspendLayout();
             this.SuspendLayout();
@@ -112,8 +112,8 @@
             this.showDataGrid.AllowUserToDeleteRows = false;
             this.showDataGrid.AllowUserToDeleteRows = false;
             this.showDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.showDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
             this.showDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
             this.showDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
-            this.人员编号,
-            this.考勤时间});
+            this.cl_cardcode,
+            this.cl_time});
             this.showDataGrid.Enabled = false;
             this.showDataGrid.Enabled = false;
             this.showDataGrid.Location = new System.Drawing.Point(17, 59);
             this.showDataGrid.Location = new System.Drawing.Point(17, 59);
             this.showDataGrid.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
             this.showDataGrid.Margin = new System.Windows.Forms.Padding(2, 1, 2, 1);
@@ -121,20 +121,7 @@
             this.showDataGrid.RowTemplate.Height = 30;
             this.showDataGrid.RowTemplate.Height = 30;
             this.showDataGrid.Size = new System.Drawing.Size(795, 377);
             this.showDataGrid.Size = new System.Drawing.Size(795, 377);
             this.showDataGrid.TabIndex = 16;
             this.showDataGrid.TabIndex = 16;
-            // 
-            // 人员编号
-            // 
-            this.人员编号.DataPropertyName = "cl_emcode";
-            this.人员编号.HeaderText = "人员编号";
-            this.人员编号.Name = "人员编号";
-            this.人员编号.Width = 150;
-            // 
-            // 考勤时间
-            // 
-            this.考勤时间.DataPropertyName = "cl_time";
-            this.考勤时间.HeaderText = "考勤时间";
-            this.考勤时间.Name = "考勤时间";
-            this.考勤时间.Width = 200;
+            this.showDataGrid.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.showDataGrid_DataError);
             // 
             // 
             // getAllData
             // getAllData
             // 
             // 
@@ -153,6 +140,21 @@
             this.dataGridViewCheckBoxColumn1.HeaderText = "勾选";
             this.dataGridViewCheckBoxColumn1.HeaderText = "勾选";
             this.dataGridViewCheckBoxColumn1.Name = "dataGridViewCheckBoxColumn1";
             this.dataGridViewCheckBoxColumn1.Name = "dataGridViewCheckBoxColumn1";
             // 
             // 
+            // cl_cardcode
+            // 
+            this.cl_cardcode.DataPropertyName = "cl_cardcode";
+            this.cl_cardcode.HeaderText = "卡号";
+            this.cl_cardcode.Name = "cl_cardcode";
+            this.cl_cardcode.Width = 200;
+            // 
+            // cl_time
+            // 
+            this.cl_time.DataPropertyName = "cl_time";
+            this.cl_time.HeaderText = "打卡时间";
+            this.cl_time.MinimumWidth = 250;
+            this.cl_time.Name = "cl_time";
+            this.cl_time.Width = 250;
+            // 
             // Form1
             // Form1
             // 
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
@@ -189,8 +191,8 @@
         private System.Windows.Forms.Button getAllData;
         private System.Windows.Forms.Button getAllData;
         private System.Windows.Forms.BindingSource allData;
         private System.Windows.Forms.BindingSource allData;
         private System.Windows.Forms.DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1;
         private System.Windows.Forms.DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn 人员编号;
-        private System.Windows.Forms.DataGridViewTextBoxColumn 考勤时间;
+        private System.Windows.Forms.DataGridViewTextBoxColumn cl_cardcode;
+        private System.Windows.Forms.DataGridViewTextBoxColumn cl_time;
     }
     }
 }
 }
 
 

+ 38 - 36
UAS_CheckWork/Form1.cs

@@ -2,6 +2,8 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Data;
 using System.Data;
+using System.Globalization;
+using System.Linq;
 using System.Text;
 using System.Text;
 using System.Threading;
 using System.Threading;
 using System.Windows.Forms;
 using System.Windows.Forms;
@@ -80,11 +82,11 @@ namespace UAS_CheckWork
                 MessageBox.Show("请先连接设备", "Error");
                 MessageBox.Show("请先连接设备", "Error");
                 return;
                 return;
             }
             }
-       
             InitGetInfo = new Thread(InPrint);
             InitGetInfo = new Thread(InPrint);
             SetLoadingWindow stw = new SetLoadingWindow(InitGetInfo, "正在同步数据...");
             SetLoadingWindow stw = new SetLoadingWindow(InitGetInfo, "正在同步数据...");
             stw.StartPosition = FormStartPosition.CenterParent;
             stw.StartPosition = FormStartPosition.CenterParent;
             stw.ShowDialog();
             stw.ShowDialog();
+
         }
         }
 
 
         private void InPrint()
         private void InPrint()
@@ -95,8 +97,13 @@ namespace UAS_CheckWork
             {
             {
                 //循环获取
                 //循环获取
                 DataTable dt = new DataTable();
                 DataTable dt = new DataTable();
-                dt.Columns.Add("cl_emcode");
+                string LastDate = dh.getFieldDataByCondition("cardlog", "to_char(max(cl_time),'yyyy-MM-dd HH24:mi:ss')", "cl_address='考勤机数据导入'").ToString();
+                dt.Columns.Add("cl_cardcode");
                 dt.Columns.Add("cl_time");
                 dt.Columns.Add("cl_time");
+                if (LastDate == "")
+                {
+                    LastDate = "1990-01-01 00:00:00";
+                }
                 string enrollNumber = "";//记录用户ID
                 string enrollNumber = "";//记录用户ID
                 int verifyCode = 0;//记录用户验证方式  0 为密码验证,1 为指纹验证,2 为卡验证 
                 int verifyCode = 0;//记录用户验证方式  0 为密码验证,1 为指纹验证,2 为卡验证 
                 int inoutMode = 0;//考勤状态,具体含义如下: 默认 0—Check-In 1—Check-Out 2—Break-Out 3—Break-In 4—OT-In 5—OT-Out 
                 int inoutMode = 0;//考勤状态,具体含义如下: 默认 0—Check-In 1—Check-Out 2—Break-Out 3—Break-In 4—OT-In 5—OT-Out 
@@ -110,28 +117,41 @@ namespace UAS_CheckWork
                 List<string> cl_cardcode = new List<string>();
                 List<string> cl_cardcode = new List<string>();
                 List<string> cl_time = new List<string>();
                 List<string> cl_time = new List<string>();
                 StringBuilder sql = new StringBuilder();
                 StringBuilder sql = new StringBuilder();
-                sql.Append("insert into cardlog (cl_id,cl_cardcode,cl_time) values (cardlog_seq.nextval,:cl_emcode,TO_DATE(:cl_time,'yyyy-MM-dd hh24:mi:ss'))");
+                sql.Append("insert into cardlog (cl_id,cl_cardcode,cl_time,cl_address) values (cardlog_seq.nextval,:cl_emcode,TO_DATE(:cl_time,'yyyy-MM-dd hh24:mi:ss'),'考勤机数据导入')");
                 int count = 0;
                 int count = 0;
                 while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out enrollNumber, out verifyCode, out inoutMode, out year, out month, out day, out hour, out minute, out second, ref workCode))
                 while (axCZKEM1.SSR_GetGeneralLogData(iMachineNumber, out enrollNumber, out verifyCode, out inoutMode, out year, out month, out day, out hour, out minute, out second, ref workCode))
                 {
                 {
-                    cl_cardcode.Add(enrollNumber);
-                    cl_time.Add(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
-                    if (count % 1000 == 0)
+                    string logtime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
+                    if (Convert.ToDateTime(logtime) > Convert.ToDateTime(LastDate))
                     {
                     {
-                        dh.BatchInsert(sql.ToString(), new string[] { "cl_cardcode", "cl_time" }, cl_cardcode.ToArray(), cl_time.ToArray());
-                        cl_cardcode.Clear();
-                        cl_time.Clear();
+                        cl_cardcode.Add(enrollNumber);
+                        cl_time.Add(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
+                        if (count % 1000 == 0)
+                        {
+                            dh.BatchInsert(sql.ToString(), new string[] { "cl_cardcode", "cl_time" }, cl_cardcode.ToArray(), cl_time.ToArray());
+                            cl_cardcode.Clear();
+                            cl_time.Clear();
+                        }
+                        count = count + 1;
+                        //将数据加入DataTable中
+                        DataRow dr = dt.NewRow();
+                        dr["cl_cardcode"] = enrollNumber;
+                        dr["cl_time"] = logtime;
+                        dt.Rows.Add(dr);
                     }
                     }
-                    count = count + 1;
-                    //将数据加入DataTable中
-                    DataRow dr = dt.NewRow();
-                    dr["cl_emcode"] = enrollNumber;
-                    dr["cl_time"] = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
-                    dt.Rows.Add(dr);
                 }
                 }
-                dh.BatchInsert(sql.ToString(), new string[] { "cl_cardcode", "cl_time" }, cl_cardcode.ToArray(), cl_time.ToArray());
+                if (cl_time.Count > 0)
+                    dh.BatchInsert(sql.ToString(), new string[] { "cl_cardcode", "cl_time" }, cl_cardcode.ToArray(), cl_time.ToArray());
                 allData.DataSource = dt;
                 allData.DataSource = dt;
                 showDataGrid.DataSource = (DataTable)allData.DataSource;
                 showDataGrid.DataSource = (DataTable)allData.DataSource;
+                if (dt.Rows.Count > 0)
+                {
+                    MessageBox.Show("数据同步成功");
+                }
+                else
+                {
+                    MessageBox.Show("没有需要同步的数据");
+                }
             }
             }
             else
             else
             {
             {
@@ -140,27 +160,9 @@ namespace UAS_CheckWork
             }
             }
         }
         }
 
 
-    
-
-        private void saveData_Click(object sender, EventArgs e)
+        private void showDataGrid_DataError(object sender, DataGridViewDataErrorEventArgs e)
         {
         {
-            //点击保存数据
-            string lastTime = dh.getFieldDataByCondition("cardlog", "TO_CHAR(max(wl_indate),'yyyy-MM-dd hh24:mi:ss')", "1=1").ToString();
-            //筛选数据
-            DataTable fd = dh.filterDataTable((DataTable)allData.DataSource, "cl_time > '" + lastTime + "'");
-            //插入数据库
-            //新增的数据
-            List<string> cl_emcode = new List<string>();
-            List<string> cl_time = new List<string>();
-            for (int i = 0; i < fd.Rows.Count; i++)
-            {
-                cl_emcode.Add(fd.Rows[i]["cl_emcode"].ToString());
-                cl_time.Add(fd.Rows[i]["cl_time"].ToString());
-            }
-            //批量插入
-            StringBuilder sql = new StringBuilder();
-            sql.Append("insert into cardlog (cl_id,cl_emcode,cl_time) values (cardlog_seq.nextval,:cl_emcode,TO_DATE(:cl_time,'yyyy-MM-dd hh24:mi:ss'))");
-            dh.BatchInsert(sql.ToString(), new string[] { "cl_emcode", "cl_time" }, cl_emcode.ToArray(), cl_time.ToArray());
+
         }
         }
     }
     }
 }
 }

+ 2 - 8
UAS_CheckWork/Form1.resx

@@ -117,16 +117,10 @@
   <resheader name="writer">
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   </resheader>
-  <metadata name="人员编号.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="cl_cardcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
     <value>True</value>
   </metadata>
   </metadata>
-  <metadata name="考勤时间.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="人员编号.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="考勤时间.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="cl_time.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
     <value>True</value>
   </metadata>
   </metadata>
   <metadata name="allData.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
   <metadata name="allData.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">