7-8 task

考勤记录读取与解析

using System;
using System.Collections.Generic;
using System.Text;

namespace Attendance.Common
{
    /// <summary>
    /// 用户ID| 日期时间|设备ID|考勤状态|验证模式|工号
    /// </summary>
    public struct AttLogDataStruct
    {
        public int NumInDevice;

        public DateTime LogDateTime;

        public string DeviceId;

        /// <summary>
        /// 0 上班 1 下班 2 外出 3 外出返回 4.加班签到 5 加班签退
        /// </summary>
        public string InOutMode;

        /// <summary>
        /// 1为指纹,0为密码
        /// </summary>
        public string VerifyMode;

    }

    public class USB_AttLog
    {
        public static List<TemplateDataStruct> ReadFromUSB()
        {
            List<TemplateDataStruct> rtn = null;
            int size = 608;
            //Find usb driver
            string filename = string.Empty;
            foreach (System.IO.DriveInfo di in System.IO.DriveInfo.GetDrives())
            {
                if (di.DriveType == DriveType.Removable && di.IsReady)
                {
                    if (System.IO.File.Exists(di.RootDirectory.FullName + "user.dat"))
                    {
                        filename = di.RootDirectory.FullName + "template.dat";
                        break;
                    }
                }
            }

            if (filename.Length > 0)
            {
                rtn = new List<TemplateDataStruct>();
                using (FileStream fs = File.Open(filename, FileMode.Open))
                {
                    System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
                    byte[] buf = new byte[fs.Length];
                    br.Read(buf, 0, (int)fs.Length);

                    for (int i = 0; i < buf.Length; i = (i + 1) * size)
                    {
                        IntPtr ptr = Marshal.AllocHGlobal(size);
                        Marshal.Copy(buf, i, ptr, size);
                        TemplateDataStruct ud = (TemplateDataStruct)Marshal.PtrToStructure(ptr, typeof(TemplateDataStruct));

                        rtn.Add(ud);
                    }
                    br.Close();
                }

            }

            return rtn;

        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值