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 ...
随机推荐
- 人脸对比微信小程序
https://cloud.tencent.com/document/product/867/17584 测试数据: 图片1: 图片2:
- RESTful再理解
目录 目录 前言 RESTful的目的 REST的含义 表现层 状态转化 无状态协议HTTP 最后 前言 这是在经过一段时间的积累后,对RESTFul框架的再一次更深入的理解.希望能够将零散的知识点连 ...
- PHP安装-centos7
下载地址:https://www.php.net/downloads.php 1.wget下载php源码至/usr/local/src 下 wget https://www.php.net/distr ...
- vue-wacth监听事件
2019-08-05 0:20 Vue.js 监听属性 watch,我们可以通过 watch 来响应数据的变化. 以下实例通过使用 watch 实现计数器:(此时我就想了一下,好像绑定点击事件,也 ...
- postman的下载和使用
postman的下载 官网:https://www.getpostman.com/downloads/ 创建账号或者用谷歌浏览器账号登录 登录之后,进行接口测试,这里请求百度为例,然后点击send,就 ...
- 剑指offer第二版面试题5:从尾到头打印链表(JAVA版)
题目描述: 输入一个链表,从尾到头打印链表每个节点的值.返回新链表. import java.util.Stack; //定义链表结构 class ListNode { int value; List ...
- ios overflow:scroll不顺畅解决办法
是要在其样式里面添加这段代码就行 -webkit-overflow-scrolling: touch;
- kmp(暴力匹配)
http://poj.org/problem?id=3080 Blue Jeans Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- Manacher(最长镜面回文串)
I - O'My! Gym - 101350I Note: this is a harder version of Mirrored string I. The gorillas have recen ...
- angularjs calling order
Here's the calling order: app.config()app.run()directive's compile functions (if they are found in t ...