C#舒特二次开发采集考勤记录并同步设备时间-创新互联
1、准备
本文标题:C#舒特二次开发采集考勤记录并同步设备时间-创新互联
URL链接:http://ybzwz.com/article/dodiph.html
采集考勤记录需要准备的dll文件:borlndmm.dll、w_kqrec.dll。
创新互联专注于企业网络营销推广、网站重做改版、盘州网站定制设计、自适应品牌网站建设、H5响应式网站、成都做商城网站、集团公司官网建设、成都外贸网站建设公司、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为盘州等各大城市提供网站开发制作服务。将文件放在项目根目录,属性复制到输出目录设置为始终复制或如果较新则复制,生成操作设置为内容。
2、从非托管DLL中导入函数using System.Runtime.InteropServices;
namespace STCollection
{
public class STApi
{
#region 引用方法
//脱机记录下载
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDOWNLOAD", CharSet = CharSet.Ansi)]
public static extern int _LANDOWNLOAD(string ipaddress);
//返回成功下载脱机记录数
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDOWNLOADS", CharSet = CharSet.Ansi)]
public static extern int _LANDOWNLOADS(string ipaddress);
//实时下载
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANREALDOWNLOAD", CharSet = CharSet.Ansi)]
public static extern string _LANREALDOWNLOAD(string IPAddr);
//禁用所有卡号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDISABLEALL", CharSet = CharSet.Ansi)]
public static extern int _LANDISABLEALL(string ipaddr);
//允许所有卡号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANENABLEALL", CharSet = CharSet.Ansi)]
public static extern int _LANENABLEALL(string ipaddr);
//禁止某张卡
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDISABLEPERSON", CharSet = CharSet.Ansi)]
public static extern int _LANDISABLEPERSON(string ipaddr, uint id);
//允许某张卡
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANENABLEPERSON", CharSet = CharSet.Ansi)]
public static extern int _LANENABLEPERSON(string ipaddr, uint id);
//下传卡号 + 姓名
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSENDNAME", CharSet = CharSet.Ansi)]
public static extern int _LANSENDNAME(string ipaddr, uint id, string name);
//删除所有姓名
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELETEALLNAME", CharSet = CharSet.Ansi)]
public static extern int _LANDELETEALLNAME(string ipaddr);
//删除所有记录
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELETE", CharSet = CharSet.Ansi)]
public static extern int _LANDELETE(string ipaddr);
//设置日期时间
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETTIME", CharSet = CharSet.Ansi)]
public static extern int _LANSETTIME(string ipaddress, int year, int month, int day, int hour, int minute, int second, int week);
//设置编号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETSN", CharSet = CharSet.Ansi)]
public static extern int _LANSETSN(string ipaddr, uint id, uint sn);
//删除编号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELSN", CharSet = CharSet.Ansi)]
public static extern int _LANDELSN(string ipaddr, uint sn);
//更换卡号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANCHANGENAMEID", CharSet = CharSet.Ansi)]
public static extern int _LANCHANGENAMEID(string ipaddr, uint id, int id1);
//设置留言
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSENDVOICE", CharSet = CharSet.Ansi)]
public static extern int _LANSENDVOICE(string ipaddr, int allorone, uint sn, uint id, int spmode, int ttl, int bmon, int bday, int bhour, int bminute, int emon, int eday, int ehour, int eminute, string voice);
//删除留言
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELVOICE", CharSet = CharSet.Ansi)]
public static extern int _LANDELVOICE(string IPAddr, uint sn);
//设置主画面显示信息
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETMAINMSG", CharSet = CharSet.Ansi)]
public static extern int _LANSETMAINMSG(string IPAddr, string aMsg);
//设置未注册卡提示信息
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETUNREGMSG", CharSet = CharSet.Ansi)]
public static extern int _LANSETUNREGMSG(string IPAddr, string aMsg);
//设置机号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETMACHINEID", CharSet = CharSet.Ansi)]
public static extern int _LANSETMACHINEID(string IPAddr, int IDH);
//设置卡位组成字节
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETCARDBIT", CharSet = CharSet.Ansi)]
public static extern int _LANSETCARDBIT(string IPAddr, int aSetVal);
//设置考勤模式
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETKQMODE", CharSet = CharSet.Ansi)]
public static extern int _LANSETKQMODE(string IPAddr, int aSetVal);
//设置打铃
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETBELL", CharSet = CharSet.Ansi)]
public static extern int _LANSETBELL(string IPAddr, int What, int bHour, int bMinute);
//删除打铃
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELBELL", CharSet = CharSet.Ansi)]
public static extern int _LANDELBELL(string IPAddr, int SN);
//设置用户代码
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETUSERCODE", CharSet = CharSet.Ansi)]
public static extern int _LANSETUSERCODE(string IPAddr, string aSetVal);
//获取用户代码
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANGETUSERCODE", CharSet = CharSet.Ansi)]
public static extern int _LANGETUSERCODE(string IPAddr);
//设置是否发送实时记录
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSENDREAL", CharSet = CharSet.Ansi)]
public static extern int _LANSENDREAL(string IPAddr, int aSetVal);
//设置验证方式
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETCHECKMODE", CharSet = CharSet.Ansi)]
public static extern int _LANSETCHECKMODE(string IPAddr, int aSetVal);
//设置刷卡模式
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETBRUSHCARDMode", CharSet = CharSet.Ansi)]
public static extern int _LANSETBRUSHCARDMode(string IPAddr, int aSetVal);
//设置是否使用上下班键
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETDOWNUPKEY", CharSet = CharSet.Ansi)]
public static extern int _LANSETDOWNUPKEY(string IPAddr, int aSetVal);
//设置考勤是否OEM
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETMACHINEMODE", CharSet = CharSet.Ansi)]
public static extern int _LANSETMACHINEMODE(string IPAddr, int aSetVal);
//设置警报模式
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETALERTMODE", CharSet = CharSet.Ansi)]
public static extern int _LANSETALERTMODE(string IPAddr, int aSetVal);
//设置是否输出继电信号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETOUTSIGNAL", CharSet = CharSet.Ansi)]
public static extern int _LANSETOUTSIGNAL(string IPAddr, int aSetVal1, int aSetVal2);
//设置刷卡次数及间隔时间
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETBRUSHNUMBER", CharSet = CharSet.Ansi)]
public static extern int _LANSETBRUSHNUMBER(string IPAddr, int aSetVal1, int aSetVal2);
//网络设置
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANSETNETWORK", CharSet = CharSet.Ansi)]
public static extern int _LANSETNETWORK(string IPAddr, string aIp, string aGate, string aMake, string aDecIP, string aPort);
//删除所有卡
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELALLCARD", CharSet = CharSet.Ansi)]
public static extern int _LANDELALLCARD(string IPAddr);
//删除一张卡
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELCARD", CharSet = CharSet.Ansi)]
public static extern int _LANDELCARD(string IPAddr, uint Id);
//删除一个姓名
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELNAME", CharSet = CharSet.Ansi)]
public static extern int _LANDELNAME(string IPAddr, uint Id);
//删除所有留言
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDELALLVOICE", CharSet = CharSet.Ansi)]
public static extern int _LANDELALLVOICE(string IPAddr);
//下载所有脱机记录
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDOWNALLDATA", CharSet = CharSet.Ansi)]
public static extern int _LANDOWNALLDATA(string IPAddr, int aType = 0);
//请求实时下载成功返回Socket
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANREALINI", CharSet = CharSet.Ansi)]
public static extern int _LANREALINI(string IPAddr);
//接收实时记录
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANREALDATA", CharSet = CharSet.Ansi)]
public static extern string _LANREALDATA(int Soct);
//关闭句柄
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANCLOSESOCK", CharSet = CharSet.Ansi)]
public static extern int _LANCLOSESOCK(int Soct);
//打开串口
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_STARTCOMM", CharSet = CharSet.Ansi)]
public static extern int _STARTCOMM(int PortNo);
//关闭串口
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_STOPCOMM", CharSet = CharSet.Ansi)]
public static extern int _STOPCOMM(int hComm);
//接收实时刷卡记录返回一条刷卡数据
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_RECEIVEDATA", CharSet = CharSet.Ansi)]
public static extern string _RECEIVEDATA(int Address, int hComm);
//初始化并返回Socket(开始下传)
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANBEGINTRAN", CharSet = CharSet.Ansi)]
public static extern int _LANBEGINTRAN(string IPAddr, int OpType, int isOver);
//关闭,并发送覆盖指令(结束下传)
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANENDTRAN", CharSet = CharSet.Ansi)]
public static extern int _LANENDTRAN(int Sock, int OpType);
//循环下传卡号
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANTRANCARD", CharSet = CharSet.Ansi)]
public static extern int _LANTRANCARD(int sock, uint ID);
//循环下传卡号 + 姓名
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANTRANCARDNAME", CharSet = CharSet.Ansi)]
public static extern int _LANTRANCARDNAME(int sock, uint ID, string name);
//从已经通讯的端口下载数据库
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANDOWNLOADSOCK", CharSet = CharSet.Ansi)]
public static extern int _LANDOWNLOADSOCK(string IPAddr, int aSockHandle);
//考勤DAT,BIN文件转换为txt文件
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_CONVERFILE", CharSet = CharSet.Ansi)]
public static extern int _CONVERFILE(string Dir, string FileName);
//COM型判断新旧机器
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_ISNEWOLD", CharSet = CharSet.Ansi)]
public static extern int _ISNEWOLD(int Address, int PortNo);
//IP型判断新旧机器
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANISNEWOLD", CharSet = CharSet.Ansi)]
public static extern int _LANISNEWOLD(string IPAddr);
//导出卡号到文件,若文件存在则追加
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_COPYCARDX", CharSet = CharSet.Ansi)]
public static extern int _COPYCARDX(string Dir, uint ID, int Version = 3);
//导出卡号+姓名到文件,若文件存在则追加
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_COPYNAMEX", CharSet = CharSet.Ansi)]
public static extern int _COPYNAMEX(string Dir, uint ID, string name, int Version = 3);
//获取最后的错误代码
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_GETLASTERROR", CharSet = CharSet.Ansi)]
public static extern int _GETLASTERROR();
//获取代码对应的信息
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_GETLASTERRORMSG", CharSet = CharSet.Ansi)]
public static extern string _GETLASTERRORMSG(int ErrCode);
//IP机是否通讯
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_FNPING", CharSet = CharSet.Ansi)]
public static extern int _FNPING(string IPAddr);
//设置IC卡读写扇区和密码
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_RWKEY", CharSet = CharSet.Ansi)]
public static extern int _RWKEY(int Address, int PortNo, int P1, int P2, int P3, int P4, int P5, int P6, int Sec, int Block, int Addr, int ByteLen);
//IP机设置IC卡读写扇区和密码
[DllImport("w_kqrec.dll", CallingConvention = CallingConvention.StdCall, EntryPoint = "_LANRWKEY", CharSet = CharSet.Ansi)]
public static extern int _LANRWKEY(string IPAddr, int P1, int P2, int P3, int P4, int P5, int P6, int Sec, int Block, int Addr, int ByteLen);
#endregion
}
}
3、调用方法采集考勤记录int len = STApi._LANDOWNLOADS("192.168.0.2");//调用DLL函数,脱机记录下载至程序所在目录
4、调用方法同步时间同步时间:
STUtils._LANSETTIME("192.168.0.2",
DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
DateTime.Now.Hour,
DateTime.Now.Minute,
DateTime.Now.Second,
GetWeek(DateTime.Now.DayOfWeek));
获取星期(忘记为什么这么写了):
public int GetWeek(DayOfWeek week)
{
switch (week)
{
case DayOfWeek.Monday:
return 1;
case DayOfWeek.Tuesday:
return 2;
case DayOfWeek.Wednesday:
return 3;
case DayOfWeek.Thursday:
return 4;
case DayOfWeek.Friday:
return 5;
case DayOfWeek.Saturday:
return 6;
case DayOfWeek.Sunday:
return 7;
default:
return -1;
}
}
5、遇到的问题实际使用过程中发现非托管dll存在闪退和卡死的现象,建议写个小程序,用其他程序调用使用,有其他解决方法也可以告诉我==。
////// 运行采集
/// ////// private bool RunCollection(string ip)
{
using (Process p = new Process())
{
p.StartInfo.FileName = Application.StartupPath + "/STCollection.exe";//可执行程序路径
p.StartInfo.Arguments = ip;
p.StartInfo.UseShellExecute = false;//是否使用操作系统shell启动
p.Start();
p.WaitForExit(60000);//等待时间自己设定
if (!p.HasExited)
{
p.Kill();
}
if (p.ExitCode == 1)
{
return true;
}
else
{
return false;
}
}
}
static void Main(string[] args)
{
if (args.Length == 0)
{
return;
}
if (!IPAddress.TryParse(args[0], out IPAddress address))
{
return;
}
if (STApi._LANDOWNLOADS(args[0])< 0)
{
return;
}
STApi._LANSETTIME(args[0],
DateTime.Now.Year,
DateTime.Now.Month,
DateTime.Now.Day,
DateTime.Now.Hour,
DateTime.Now.Minute,
DateTime.Now.Second,
GetWeek(DateTime.Now.DayOfWeek));
Environment.ExitCode = 1;
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
本文标题:C#舒特二次开发采集考勤记录并同步设备时间-创新互联
URL链接:http://ybzwz.com/article/dodiph.html