C# 批量修改考勤设备时间
自己工作中用到的小程序,每次远行后批量改一次
如下:
其中的zkemkeeper是中控的相关组件,因是系统组件,须要先注册相关文件后才有效
using System;
using System.Collections.Generic;
using System.Text;
using zkemkeeper;
using System.Threading;
using System.Runtime.InteropServices;
using System.IO;
namespace zktime
{
class Program
{
static void Main(string[] args)
{
System.Console.Title = "考勤设备时间批量同步V2";
StreamReader sr = new StreamReader("DeviceIP.txt");
string line;
while ((line = sr.ReadLine()) != null)
{
Program open = new Program();
open.Connect(line);
open.set_DeviceTime(line);
open.disconnectkc(line);
}
if (sr != null) sr.Close();
}
#region 考勤连接与修改
public zkemkeeper.CZKEMClass axCZKEM1 = new zkemkeeper.CZKEMClass();
private bool bIsConnected = false;//布尔值确定设备是否连接
;//设备的序列号。连接设备后,此值将更改。
private void disconnectkc(string ip )
{
if (bIsConnected == true)
{
axCZKEM1.Disconnect();//断开连接
Console.WriteLine("已断开" + ip + "的连接! \r\n");
}
return;
}
private void Connect(string ip)
{
)
{
Console.WriteLine("连接设备" + ip + "错误,错误代码! \r\n");
return;
}
;
bIsConnected = axCZKEM1.Connect_Net(ip, );
if (bIsConnected == true)
{
Console.Write("连接" + ip + "成功 \r\n");
iMachineNumber = ;//实际上,当您使用tcp / ip通信时,这个参数将被忽略,任何整数都是正确的。在这里我们使用1。
axCZKEM1.RegEvent(iMachineNumber, );//在这里,您可以注册要触发的realtime事件(参数65535意味着注册全部)
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
Console.Write("连接"+ip+"设备错误,错误代码=" + idwErrorCode.ToString()+"\r\n");
}
}
#region 修改设备时间
private void set_DeviceTime (string ip)
{
if (bIsConnected == false)
{
Console.Write("设备"+ip+"未连接 \r\n");
return;
}
;
int idwYear = Convert.ToInt32(System.DateTime.Now.Year.ToString().Trim());
int idwMonth = Convert.ToInt32(System.DateTime.Now.Month.ToString().Trim());
int idwDay = Convert.ToInt32(System.DateTime.Now.Day.ToString().Trim());
int idwHour = Convert.ToInt32(System.DateTime.Now.Hour.ToString().Trim());
int idwMinute = Convert.ToInt32(System.DateTime.Now.Minute.ToString().Trim());
int idwSecond = Convert.ToInt32(System.DateTime.Now.Second.ToString().Trim());
if (axCZKEM1.SetDeviceTime2(iMachineNumber, idwYear, idwMonth, idwDay, idwHour, idwMinute, idwSecond))
{
axCZKEM1.RefreshData(iMachineNumber);//设备中的数据应该刷新
Console.Write("设置"+ip+"时间"+idwYear.ToString()+"-"+ idwMonth.ToString() + "-" + idwDay.ToString() + " " + idwHour.ToString() + ":" + idwMinute.ToString() + ":" + idwSecond.ToString()+"成功!\r\n");
}
else
{
axCZKEM1.GetLastError(ref idwErrorCode);
Console.Write("操作"+ip+"失败了,错误代码=" + idwErrorCode.ToString()+" \r\n");
}
return;
}
#endregion
#endregion
#region 重写console
static class Console
{
public static string ReadLine()
{
return System.Console.ReadLine();
}
public static ConsoleKeyInfo ReadKey()
{
return System.Console.ReadKey();
}
public static string Title { get
; set; }
public static ConsoleKeyInfo ReadKey(bool intercept)
{
return System.Console.ReadKey(intercept);
}
public static void WriteLine(int value, bool isLog = true)
{
System.Console.WriteLine(value);
if (isLog)
{
WriteFile(value.ToString() + "\r\n");
}
}
public static void WriteLine(string value, bool isLog = true)
{
System.Console.WriteLine(value);
if (isLog)
{
WriteFile(value + "\r\n");
}
}
public static void WriteLine(string format, params object[] arg)
{
System.Console.WriteLine(format, arg);
WriteFile(string.Format(format, arg) + "\r\n");
}
public static void Write(int value, bool isLog = true)
{
System.Console.Write(value);
if (isLog)
{
WriteFile(value.ToString());
}
}
public static void Write(string value, bool isLog = true)
{
System.Console.Write(value);
if (isLog)
{
WriteFile(value);
}
}
public static void Write(string format, params object[] arg)
{
System.Console.Write(format, arg);
WriteFile(string.Format(format, arg));
}
private static bool IsFirst = true;
private static void WriteFile(string value)
{
System.IO.File.AppendAllText(System.IO.Path.Combine(Environment.CurrentDirectory,
"log"+ System.DateTime.Now.Year.ToString()+System.DateTime.Now.Month.ToString()+".txt"), value, Encoding.Default);
}
}
#endregion
}
}
C# 批量修改考勤设备时间的更多相关文章
- Sql批量修改帝国cms文章发布时间(需unix时间,否则会变为1970-01-01)
在迁移网站时,有时我们需要将帝国cms文章发表时间批量修改为当前时间,在帝国cms后台→系统设置→备份与恢复数据→执行sql语句: update phome_ecms_news set newstim ...
- sql批量修改wordpress文章发布时间
有时为了体现wordpress文章的更新程度,会在后台那边重新设置发布时间,有没更简单的方法呢?用sql批量修改wordpress文章发布时间怎么操作呢? UPDATE `wp_posts` SET ...
- node实现文件属性批量修改(时间属性)
前言 在默认情况下,一个文件的创建时间和修改时间是系统自己设定的,我们不能修改该的.但我们有时为了某种特殊需要,为了不让别人一眼看出文件已经给修改了,我们又需要修改文件的创建时间和修改时间.那么如何修 ...
- nodejs 批量修改、删除
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQhCAIAAABDaAVHAAAgAElEQVR4nOydeXxU5aH359733vd9b/ ...
- ansible非root用户批量修改root密码
前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...
- Unix时间戳转换怎样在Excel批量修改?
最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...
- 如何将北京时间批量转为Unix时间?用Excel!
前面我们说过Unix时间戳转换怎样在Excel批量修改,有些人就想如果有特殊需求,那能不能批量将北京时间批量转成unix时间呢?能!用Excel就可以实现!跟ytkah一起试试吧. 将unix时间戳转 ...
- Git批量修改提交历史
有些时候我们可能需要批量修改提交历史,当然了,最近一次的提交历史很简单我们可以利用 git commit --amend 来进行最近一次提交的修改,如果你此时想要更新作者提交时间等也可以在amend之 ...
- python批量修改linux主机密码
+++++++++++++++++++++++++++++++++++++++++++标题:python批量修改Linux服务器密码时间:2019年2月24日内容:基于python实现批量修改linu ...
随机推荐
- flutter中的表单使用
Flutter 中常见的表单有 TextField 单行文本框,TextField 多行文本框.CheckBox.Radio.Switch.CheckboxListTile.RadioListTile ...
- 一个最最简单的 log4j 的 入门级使用案例
看了比较多的文档和博客,感觉这篇博客写得比较好,比较容易懂,先 mark 一下,回头做一个记录. 文章1:http://www.cnblogs.com/rushoooooo/archive/2011/ ...
- 阿里云服务器 Ubuntu 安装 LNMP
1.设定实例化服务器IP密码. 2.设定安全组件端口 80 和 3306 系统默认提供端口 22. //阿里云需要设定安全组件端口必须设定. 3.安装一键lnmp系统. 教程地址 https://ln ...
- http预请求 options
问题 使用axios请求接口时,出现了发出两次请求的情况:一个是请求OPTIONS,一个是正常的POST请求:查资料发现与跨域请求有关. 概念 MDN中有提到: 出于安全原因,浏览器限制从脚本内发起的 ...
- 修改oracle数据库字段类型,处理ORA-01439错误
修改表PTLOG的列TYPE的char(1)为varchar(2)类型? 在PTLOG 表新增一列 TYPE_2:ALTER TABLE PTLOG ADD TYPE_2 VARCHAR2(2) de ...
- 【Visual Studio】 使用EF、 Linq2Sql快速创建数据交互层(一)
项目伊始,创建数据库交互层代码是底层框架的首要任务.常用的做法包括手动编码.Hibernate或者动软之类的代码生成器,而多数人忽略了.Net环境下VS提供的两套非常好用的数据层工具. EF和Linq ...
- 解决Win7部分便笺的元数据已被损坏的方法
Win7部分便笺的元数据已被损坏的方法 我们使用键盘上"Win+F"组合键搜索功能,直接找到"inkobj.dll"这个文件,一般会搜索出来好多,先随便选一个. ...
- 001/Nginx高可用模式下的负载均衡与动静分离(笔记)
Nginx高可用模式下的负载均衡与动静分离 Nginx(engine x)是一个高性能的HTTP和反向代理服务器,具有内存少,并发能力强特点. 1.处理静态文件.索引文件以及自动索引:打开文件描述符缓 ...
- Test Case Design Method - OATS
[转载] OATS:即Orthogonal Array Testing Strategy,正交表测试策略. 1 OATS的概念: 次数(Runs):简单的说,就是次数是多少,就有多少个用例. ...
- nodejs基础-nvm和npm
nvm npm 更新 npm install npm@latest -g 本地安装 npm install 包名称 require(”包名“) 全局安装 npm install 包名 -g 可以直接作 ...