自己工作中用到的小程序,每次远行后批量改一次

如下:

其中的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# 批量修改考勤设备时间的更多相关文章

  1. Sql批量修改帝国cms文章发布时间(需unix时间,否则会变为1970-01-01)

    在迁移网站时,有时我们需要将帝国cms文章发表时间批量修改为当前时间,在帝国cms后台→系统设置→备份与恢复数据→执行sql语句: update phome_ecms_news set newstim ...

  2. sql批量修改wordpress文章发布时间

    有时为了体现wordpress文章的更新程度,会在后台那边重新设置发布时间,有没更简单的方法呢?用sql批量修改wordpress文章发布时间怎么操作呢? UPDATE `wp_posts` SET ...

  3. node实现文件属性批量修改(时间属性)

    前言 在默认情况下,一个文件的创建时间和修改时间是系统自己设定的,我们不能修改该的.但我们有时为了某种特殊需要,为了不让别人一眼看出文件已经给修改了,我们又需要修改文件的创建时间和修改时间.那么如何修 ...

  4. nodejs 批量修改、删除

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB4AAAAQhCAIAAABDaAVHAAAgAElEQVR4nOydeXxU5aH359733vd9b/ ...

  5. ansible非root用户批量修改root密码

    前言: 由于线上服务器密码长久没有更新,现领导要求批量更换密码.线上的之前部署过salt,但由于各种因素没有正常使用. 使用自动化工具批量修改的计划搁浅了,后来领导给了个python多线程修改密码脚本 ...

  6. Unix时间戳转换怎样在Excel批量修改?

    最近在操作项目的时候碰到一个Unix时间戳转换的问题."date_time":1393031347这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来.但我们本着科普的 ...

  7. 如何将北京时间批量转为Unix时间?用Excel!

    前面我们说过Unix时间戳转换怎样在Excel批量修改,有些人就想如果有特殊需求,那能不能批量将北京时间批量转成unix时间呢?能!用Excel就可以实现!跟ytkah一起试试吧. 将unix时间戳转 ...

  8. Git批量修改提交历史

    有些时候我们可能需要批量修改提交历史,当然了,最近一次的提交历史很简单我们可以利用 git commit --amend 来进行最近一次提交的修改,如果你此时想要更新作者提交时间等也可以在amend之 ...

  9. python批量修改linux主机密码

    +++++++++++++++++++++++++++++++++++++++++++标题:python批量修改Linux服务器密码时间:2019年2月24日内容:基于python实现批量修改linu ...

随机推荐

  1. 【Java】ApplicationContext应用上下文工具类

    @Slf4j @Service public class SpringContextHolder implements ApplicationContextAware, DisposableBean ...

  2. apache如何发布地图服务

    svg jpg Tomcat和apache是什么关系呢?:https://www.cnblogs.com/zangdalei/p/8057325.html geoserver又是怎么来的呢? Tomc ...

  3. CodeForces - 35D

    题目:https://vjudge.net/contest/326867#problem/A 题意:有一个农场,自己有m斤粮食,有n天,每天动物吃的量不同,那个动物的食量的是由他是从那天开始进这个农场 ...

  4. Uva 12563 Jin Ge Jin Qu hao(01背包)

    题意: 假定你在唱KTV,还剩下t秒时间.你决定接下来唱你最喜爱的n首歌(不包含劲歌金曲)中的一些歌曲.在时间结束之前再唱一个劲歌金曲.使得唱的歌的总曲目尽量多以及时间总长度. 输入保证所有n+1曲子 ...

  5. 连接超时(connect timed out)和读取超时(Read timed out)

    设置连接超时和读取超时方法: RequestConfig config=RequestConfig.custom() .setConnectTimeout(10000) // 设置连接超时时间 10秒 ...

  6. 纯文本编辑语言markdown

    Markdown的主要目的是生成可以复制到网页或写入平台的HTML代码.但你不必那样使用它.Markdown也可以作为强大记笔记的基础,许多Markdown编辑可以将您的写作导出为其他格式,如Word ...

  7. 学院-成就学院:Academy of Achievement

    ylbtech-学院-成就学院:Academy of Achievement 1.返回顶部 1. https://www.achievement.org/ 2. https://www.achieve ...

  8. Webhook到底是个啥?

    参照: https://segmentfault.com/a/1190000015437514

  9. Jenkins使用六:搭建流水线任务

    流水线可以把多个任务串起来,比如发布版本的一系列流程 配置流水线任务 构建语法为Groovy,执行3次test(job名) node { stage("test") { echo ...

  10. 彻底理解 Linux 的搜索工具: grep 和 awk

    grep 官方手册 awk 官方手册, awk 学习资料 1. grep grep 用于打印匹配指定模式的行. 1.1 介绍 grep 命令从输入文件中查找匹配到给定模式列表的行.发现匹配到的行后,默 ...