Browse Source

一次可以获取所有的考勤机IP数据

callm 3 years ago
parent
commit
f23ab3fec7
4 changed files with 96 additions and 145 deletions
  1. 43 73
      UAS_CheckWork/Form1.Designer.cs
  2. 41 54
      UAS_CheckWork/Form1.cs
  3. 0 12
      UAS_CheckWork/Form1.resx
  4. 12 6
      UAS_CheckWork/UAS_CheckWork.csproj

+ 43 - 73
UAS_CheckWork/Form1.Designer.cs

@@ -32,12 +32,7 @@
             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.lblState = new System.Windows.Forms.Label();
-            this.showDataGrid = new System.Windows.Forms.DataGridView();
-            this.cl_cardcode = new System.Windows.Forms.DataGridViewTextBoxColumn();
-            this.cl_time = new System.Windows.Forms.DataGridViewTextBoxColumn();
             this.getAllData = new System.Windows.Forms.Button();
             this.allData = new System.Windows.Forms.BindingSource(this.components);
             this.dataGridViewCheckBoxColumn1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();
@@ -45,7 +40,8 @@
             this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
             this.Master = new System.Windows.Forms.ComboBox();
             this.label3 = new System.Windows.Forms.Label();
-            ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).BeginInit();
+            this.OperateResult = new System.Windows.Forms.RichTextBox();
+            this.IP = new System.Windows.Forms.ComboBox();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).BeginInit();
             this.SuspendLayout();
             // 
@@ -53,7 +49,7 @@
             // 
             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(334, 34);
+            this.label2.Location = new System.Drawing.Point(386, 38);
             this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(82, 41);
@@ -64,7 +60,7 @@
             // 
             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(48, 32);
+            this.label1.Location = new System.Drawing.Point(48, 38);
             this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label1.Name = "label1";
             this.label1.Size = new System.Drawing.Size(47, 41);
@@ -73,75 +69,24 @@
             // 
             // txtPort
             // 
-            this.txtPort.Location = new System.Drawing.Point(430, 34);
+            this.txtPort.Location = new System.Drawing.Point(476, 38);
             this.txtPort.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.txtPort.Name = "txtPort";
             this.txtPort.Size = new System.Drawing.Size(70, 35);
             this.txtPort.TabIndex = 12;
-            // 
-            // txtIP
-            // 
-            this.txtIP.Location = new System.Drawing.Point(116, 34);
-            this.txtIP.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
-            this.txtIP.Name = "txtIP";
-            this.txtIP.Size = new System.Drawing.Size(194, 35);
-            this.txtIP.TabIndex = 11;
-            // 
-            // 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(558, 30);
-            this.btnConnect.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
-            this.btnConnect.Name = "btnConnect";
-            this.btnConnect.Size = new System.Drawing.Size(100, 50);
-            this.btnConnect.TabIndex = 10;
-            this.btnConnect.Text = "连接";
-            this.btnConnect.UseVisualStyleBackColor = true;
-            this.btnConnect.Click += new System.EventHandler(this.btnConnect_Click);
+            this.txtPort.Text = "4370";
             // 
             // lblState
             // 
             this.lblState.AutoSize = true;
             this.lblState.ForeColor = System.Drawing.Color.Crimson;
-            this.lblState.Location = new System.Drawing.Point(718, 44);
+            this.lblState.Location = new System.Drawing.Point(613, 49);
             this.lblState.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.lblState.Name = "lblState";
             this.lblState.Size = new System.Drawing.Size(142, 24);
             this.lblState.TabIndex = 15;
             this.lblState.Text = "状态:未连接";
             // 
-            // showDataGrid
-            // 
-            this.showDataGrid.AllowUserToAddRows = false;
-            this.showDataGrid.AllowUserToDeleteRows = false;
-            this.showDataGrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
-            this.showDataGrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
-            this.cl_cardcode,
-            this.cl_time});
-            this.showDataGrid.Enabled = false;
-            this.showDataGrid.Location = new System.Drawing.Point(34, 116);
-            this.showDataGrid.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
-            this.showDataGrid.Name = "showDataGrid";
-            this.showDataGrid.RowTemplate.Height = 30;
-            this.showDataGrid.Size = new System.Drawing.Size(1734, 756);
-            this.showDataGrid.TabIndex = 16;
-            this.showDataGrid.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.showDataGrid_DataError);
-            // 
-            // 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;
-            // 
             // getAllData
             // 
             this.getAllData.BackColor = System.Drawing.SystemColors.ControlLightLight;
@@ -175,7 +120,7 @@
             // 
             this.Master.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
             this.Master.FormattingEnabled = true;
-            this.Master.Location = new System.Drawing.Point(1018, 41);
+            this.Master.Location = new System.Drawing.Point(929, 52);
             this.Master.Name = "Master";
             this.Master.Size = new System.Drawing.Size(480, 32);
             this.Master.TabIndex = 19;
@@ -184,35 +129,63 @@
             // 
             this.label3.AutoSize = true;
             this.label3.ForeColor = System.Drawing.Color.Black;
-            this.label3.Location = new System.Drawing.Point(905, 44);
+            this.label3.Location = new System.Drawing.Point(816, 55);
             this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
             this.label3.Name = "label3";
             this.label3.Size = new System.Drawing.Size(106, 24);
             this.label3.TabIndex = 20;
             this.label3.Text = "选择账套";
             // 
+            // OperateResult
+            // 
+            this.OperateResult.Location = new System.Drawing.Point(55, 136);
+            this.OperateResult.Name = "OperateResult";
+            this.OperateResult.Size = new System.Drawing.Size(1693, 734);
+            this.OperateResult.TabIndex = 21;
+            this.OperateResult.Text = "";
+            // 
+            // IP
+            // 
+            this.IP.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.IP.FormattingEnabled = true;
+            this.IP.Items.AddRange(new object[] {
+            "192.168.2.230",
+            "192.168.2.231",
+            "192.168.2.232",
+            "192.168.1.4",
+            "192.168.1.241",
+            "192.168.1.153",
+            "192.168.1.182",
+            "192.168.1.183",
+            "192.168.1.75",
+            "192.168.1.181",
+            "192.168.1.219",
+            "192.168.1.244"});
+            this.IP.Location = new System.Drawing.Point(111, 44);
+            this.IP.Name = "IP";
+            this.IP.Size = new System.Drawing.Size(268, 32);
+            this.IP.TabIndex = 22;
+            // 
             // Form1
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(12F, 24F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(1781, 902);
+            this.Controls.Add(this.IP);
+            this.Controls.Add(this.OperateResult);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.Master);
             this.Controls.Add(this.ExportEmp);
             this.Controls.Add(this.getAllData);
-            this.Controls.Add(this.showDataGrid);
             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.Margin = new System.Windows.Forms.Padding(4, 2, 4, 2);
             this.Name = "Form1";
             this.Text = "Form1";
             this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
             this.Load += new System.EventHandler(this.Form1_Load);
-            ((System.ComponentModel.ISupportInitialize)(this.showDataGrid)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.allData)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
@@ -224,19 +197,16 @@
         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.Label lblState;
-        private System.Windows.Forms.DataGridView showDataGrid;
         private System.Windows.Forms.Button getAllData;
         private System.Windows.Forms.BindingSource allData;
         private System.Windows.Forms.DataGridViewCheckBoxColumn dataGridViewCheckBoxColumn1;
-        private System.Windows.Forms.DataGridViewTextBoxColumn cl_cardcode;
-        private System.Windows.Forms.DataGridViewTextBoxColumn cl_time;
         private System.Windows.Forms.Button ExportEmp;
         private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
         private System.Windows.Forms.ComboBox Master;
         private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.RichTextBox OperateResult;
+        private System.Windows.Forms.ComboBox IP;
     }
 }
 

+ 41 - 54
UAS_CheckWork/Form1.cs

@@ -22,6 +22,8 @@ namespace UAS_CheckWork
         //开启线程
         Thread InitGetInfo;
 
+        List<string> IPAddress = new List<string>();
+
         public Form1()
         {
             InitializeComponent();
@@ -30,8 +32,20 @@ namespace UAS_CheckWork
 
         private void Form1_Load(object sender, EventArgs e)
         {
+            IPAddress.Add("192.168.2.230");
+            IPAddress.Add("192.168.2.231");
+            IPAddress.Add("192.168.2.232");
+            IPAddress.Add("192.168.1.4");
+            IPAddress.Add("192.168.1.241");
+            IPAddress.Add("192.168.1.153");
+            IPAddress.Add("192.168.1.182");
+            IPAddress.Add("192.168.1.183");
+            IPAddress.Add("192.168.1.75");
+            IPAddress.Add("192.168.1.181");
+            IPAddress.Add("192.168.1.219");
+            IPAddress.Add("192.168.1.244");
+
             CheckForIllegalCrossThreadCalls = false;//可跨线程
-            txtIP.Text = Properties.Settings.Default.IP;
             txtPort.Text = Properties.Settings.Default.Port;
             dh = new DataHelper();
             DataTable dt = (DataTable)dh.ExecuteSql("select ma_user,ma_function from master", "select");
@@ -40,59 +54,31 @@ namespace UAS_CheckWork
             Master.ValueMember = "ma_user";
         }
 
-        private void btnConnect_Click(object sender, EventArgs e)
-        {
-            Properties.Settings.Default.IP = txtIP.Text;
-            Properties.Settings.Default.Port = txtPort.Text;
-            Properties.Settings.Default.Save();
-            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 getAllData_Click(object sender, EventArgs e)
         {
             string master = Master.SelectedValue.ToString();
-            DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID="+master+";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=yitoadt.wicp.io)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
+            DataHelper.DBConnectionString = "Connection Timeout=0;Pooling=false;Password=select!#%*(;User ID=" + master + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=yitoadt.wicp.io)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
             dh = new DataHelper();
-            if (!bIsConnected)
+            int idwErrorCode = 0;
+            for (int i = 0; i < IPAddress.Count; i++)
             {
-                MessageBox.Show("请先连接设备", "Error");
-                return;
+                bIsConnected = axCZKEM1.Connect_Net(IPAddress.ToArray()[i], Convert.ToInt32(txtPort.Text));
+                if (bIsConnected)
+                {
+                    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)
+                    InitGetInfo = new Thread(InPrint);
+                    SetLoadingWindow stw = new SetLoadingWindow(InitGetInfo, "正在同步数据...");
+                    stw.StartPosition = FormStartPosition.CenterParent;
+                    stw.ShowDialog();
+                }
+                else
+                {
+                    axCZKEM1.GetLastError(ref idwErrorCode);
+                    OperateResult.AppendText("无法连接设备,"+ IPAddress.ToArray()[i] + "ErrorCode=" + idwErrorCode.ToString() + "\n");
+                }
             }
-            InitGetInfo = new Thread(InPrint);
-            SetLoadingWindow stw = new SetLoadingWindow(InitGetInfo, "正在同步数据...");
-            stw.StartPosition = FormStartPosition.CenterParent;
-            stw.ShowDialog();
         }
 
         private void InPrint()
@@ -105,7 +91,7 @@ namespace UAS_CheckWork
                 DataTable dt = new DataTable();
                 dt.Columns.Add("cl_cardcode");
                 dt.Columns.Add("cl_time");
-                showDataGrid.DataSource = dt;
+
                 string SerialNum = "";
                 axCZKEM1.GetSerialNumber(axCZKEM1.MachineNumber, out SerialNum);
                 string LastDate = dh.getFieldDataByCondition("cardlog", "to_char(max(cl_time),'yyyy-MM-dd HH24:mi:ss')", "cl_address='考勤机数据导入' and cl_code='" + SerialNum + "'").ToString();
@@ -155,20 +141,21 @@ namespace UAS_CheckWork
                 }
                 if (cl_time.Count > 0)
                     dh.BatchInsert(sql.ToString(), new string[] { "cl_cardcode", "cl_time", "cl_machinenum" }, cl_cardcode.ToArray(), cl_time.ToArray(), cl_machinenum.ToArray());
-                showDataGrid.DataSource = dt;
                 if (dt.Rows.Count > 0)
                 {
-                    MessageBox.Show("数据同步成功");
+                    OperateResult.AppendText(SerialNum + "数据同步成功\n");
                 }
                 else
                 {
-                    MessageBox.Show("没有需要同步的数据");
+                    OperateResult.AppendText(SerialNum + "没有需要同步的数据\n");
                 }
+                axCZKEM1.Disconnect();
+                bIsConnected = false;
             }
             else
             {
                 axCZKEM1.GetLastError(ref idwErrorCode);
-                MessageBox.Show("Unable to get data,ErrorCode=" + idwErrorCode.ToString(), "Error");
+                OperateResult.AppendText("Unable to get data,ErrorCode=" + idwErrorCode.ToString() + "\n");
             }
         }
 
@@ -181,7 +168,7 @@ namespace UAS_CheckWork
         {
             if (!bIsConnected)
             {
-                MessageBox.Show("请先连接设备", "Error");
+                OperateResult.AppendText("请先连接设备\n");
                 return;
             }
             folderBrowserDialog1.Description = "选择导出的路径";

+ 0 - 12
UAS_CheckWork/Form1.resx

@@ -117,18 +117,6 @@
   <resheader name="writer">
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
-  <metadata name="cl_cardcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="cl_time.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="cl_cardcode.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
-  <metadata name="cl_time.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
-    <value>True</value>
-  </metadata>
   <metadata name="allData.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
     <value>17, 17</value>
   </metadata>

+ 12 - 6
UAS_CheckWork/UAS_CheckWork.csproj

@@ -30,7 +30,7 @@
     <BootstrapperEnabled>true</BootstrapperEnabled>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
+    <PlatformTarget>x64</PlatformTarget>
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
@@ -56,11 +56,6 @@
     <NoWin32Manifest>true</NoWin32Manifest>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Interop.zkemkeeper, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <EmbedInteropTypes>False</EmbedInteropTypes>
-      <HintPath>bin\Debug\Interop.zkemkeeper.dll</HintPath>
-    </Reference>
     <Reference Include="NPOI">
       <HintPath>tool\NPOI.dll</HintPath>
     </Reference>
@@ -158,6 +153,17 @@
       <Install>false</Install>
     </BootstrapperPackage>
   </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="zkemkeeper">
+      <Guid>{FE9DED34-E159-408E-8490-B720A5E632C7}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>0</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>tlbimp</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>False</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.