예제 #1
0
        /// <summary>
        /// 将读到的数据写入sql
        /// </summary>
        private void WriteSQL()
        {
            bool isRevalueSearchFrom = false;

            if (_SearchFrom.CompareTo(Convert.ToDateTime("1900-1-1 00:00:00")) == 0)
            {
                isRevalueSearchFrom = true;
                _SearchFrom         = Convert.ToDateTime("2999-12-31 00:00:00");
            }
            for (int i = 0; i < EmployeeList.Count; i++)
            {
                List <AttendanceInAndOutRecord> attendanceInAndOutRecordList =
                    EmployeeList[i].EmployeeAttendance.AttendanceInAndOutRecordList;
                if (attendanceInAndOutRecordList.Count > 0)
                {
                    NewEmployeeList.Add(EmployeeList[i]);
                    //如果之前没有读过数据,则找出读到数据中最早的时间
                    if (isRevalueSearchFrom)
                    {
                        for (int k = 0; k < attendanceInAndOutRecordList.Count; k++)
                        {
                            if (DateTime.Compare(_SearchFrom, attendanceInAndOutRecordList[k].IOTime) > 0)
                            {
                                _SearchFrom = attendanceInAndOutRecordList[k].IOTime;
                            }
                        }
                    }
                }
                //如果员工有考勤规则
                if (EmployeeList[i].EmployeeAttendance.PlanDutyDetailList != null &&
                    EmployeeList[i].EmployeeAttendance.PlanDutyDetailList.Count != 0)
                {
                    AllEmployeeList.Add(EmployeeList[i]);
                }
            }
            if (NewEmployeeList.Count > 0)
            {
                _DalRecord.InsertAttendanceInAndOutRecordList(NewEmployeeList);
            }
        }
예제 #2
0
        private int ImportDate(DataTable dt)
        {
            List <Employee> employeeList = new List <Employee>();
            DateTime        dt_Now       = DateTime.Now;

            //Employee employee
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                _Name = GetItem(dt, i, _NameColumn);
                if (string.IsNullOrEmpty(_Name))
                {
                    continue;
                }
                Employee employee = employeeList.Find(FindEmployee);
                if (employee == null)
                {
                    Account account = _IAccountBll.GetAccountByName(_Name);
                    //如果系统里没有该员工或者该员工在系统中没有门禁卡卡号
                    if (account == null)
                    {
                        continue;
                    }
                    employee = getEmployee.GetEmployeeAttendenceInfoByAccountID(account.Id);
                    if (employee == null)
                    {
                        continue;
                    }
                    if (string.IsNullOrEmpty(employee.EmployeeAttendance.DoorCardNo))
                    {
                        continue;
                    }
                    employee.EmployeeAttendance.AttendanceInAndOutRecordList = new List <AttendanceInAndOutRecord>();
                    employeeList.Add(employee);
                }
                AttendanceInAndOutRecord attendanceInAndOutRecord = new AttendanceInAndOutRecord();
                attendanceInAndOutRecord.IOStatus = GetInOutStatusByInOutName(GetItem(dt, i, _InOutColumn));
                try
                {
                    var      date = Convert.ToDateTime(GetItem(dt, i, _DateColumn));
                    DateTime time;
                    if (DateTime.TryParse(GetItem(dt, i, _TimeColumn), out time))
                    {
                        attendanceInAndOutRecord.IOTime = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);
                    }
                    else
                    {
                        attendanceInAndOutRecord.IOTime = Convert.ToDateTime(date.ToString("yyyy-MM-dd") + " " + GetItem(dt, i, _TimeColumn));
                    }
                }
                catch
                {
                    continue;
                }
                attendanceInAndOutRecord.OperateStatus = OutInRecordOperateStatusEnum.ImportByOperator;
                attendanceInAndOutRecord.OperateTime   = dt_Now;
                //判断读取中是否有重复记录 add by liudan 2009-09-19
                List <AttendanceInAndOutRecord> sqlRecords =
                    attendanceInAndOutRecordDal.GetAttendanceInAndOutRecordByCondition(employee.Account.Id,
                                                                                       employee.EmployeeAttendance.
                                                                                       DoorCardNo,
                                                                                       Convert.ToDateTime("1900-12-31"),
                                                                                       Convert.ToDateTime("2999-12-31"),
                                                                                       InOutStatusEnum.All,
                                                                                       OutInRecordOperateStatusEnum.All,
                                                                                       Convert.ToDateTime("1900-12-31"),
                                                                                       Convert.ToDateTime("2999-12-31"));
                bool isFind = false;
                foreach (AttendanceInAndOutRecord records in sqlRecords)
                {
                    if (attendanceInAndOutRecord.IOStatus.Equals(records.IOStatus) &&
                        attendanceInAndOutRecord.IOTime.Equals(records.IOTime))
                    {
                        isFind = true;
                    }
                }
                if (!isFind)
                {
                    employee.EmployeeAttendance.AttendanceInAndOutRecordList.Add(attendanceInAndOutRecord);
                    count = count + 1;
                }
            }
            attendanceInAndOutRecordDal.InsertAttendanceInAndOutRecordList(employeeList);
            return(employeeList.Count);
        }