Example #1
0
        private static void GetDataTimeSheetFromListDate(List <DateTime> lstDate)
        {
            TMSDbContext                  DbContext                   = new TMSDbContext();
            IDbFactory                    dbFactory                   = new DbFactory();
            IAppUserRepository            appUserRepository           = new AppUserRepository(dbFactory);
            IChildcareLeaveRepository     childcareLeaveRepository    = new ChildcareLeaveRepository(dbFactory);
            IFingerTimeSheetRepository    fingerTimeSheetRepository   = new FingerTimeSheetRepository(dbFactory);
            ITimeDayRepository            timeDayRepository           = new TimeDayRepository(dbFactory);
            IFingerTimeSheetTmpRepository tmpTimeSheetRepository      = new FingerTimeSheetTmpRepository(dbFactory);
            IOTRequestRepository          OTRequestRepository         = new OTRequestRepository(dbFactory);
            IFingerMachineUserRepository  fingerMachineUserRepository = new FingerMachineUserRepository(dbFactory);
            IOTRequestUserRepository      otrequestUserRepository     = new OTRequestUserRepository(dbFactory);
            IReportRepository             reportRepository            = new ReportRepository(dbFactory);
            UnitOfWork                    unitOfWork                  = new UnitOfWork(dbFactory);
            IRequestRepository            requestRepository           = new RequestRepository(dbFactory);
            IExplanationRequestRepository explanationRepository       = new ExplanationRequestRepository(dbFactory);
            IAbnormalCaseRepository       abnormalRepository          = new AbnormalCaseRepository(dbFactory);
            IEntitleDayAppUserRepository  entitledayRepository        = new EntitleDayAppUserRepository(dbFactory);
            IUserOnsiteRepository         userOnsiteRepository        = new UserOnsiteRepository(dbFactory);
            ISystemService                systemService               = new SystemService();
            ISystemConfigRepository       systemConfigRepository      = new SystemConfigRepository(dbFactory);
            IHolidayRepository            holidayRepository           = new HolidayRepository(dbFactory);
            ICommonService                commonService               = new CommonService(systemConfigRepository, timeDayRepository, holidayRepository, unitOfWork);
            FingerTimeSheetService        fingerTimeSheetService      = new FingerTimeSheetService(fingerTimeSheetRepository, tmpTimeSheetRepository, timeDayRepository, OTRequestRepository,
                                                                                                   fingerMachineUserRepository, otrequestUserRepository,
                                                                                                   appUserRepository, childcareLeaveRepository, reportRepository, unitOfWork,
                                                                                                   requestRepository, explanationRepository, abnormalRepository, entitledayRepository, userOnsiteRepository, systemService, commonService);
            var listDateImportTimeSheet = new List <DateTime>();

            try
            {
                foreach (var datetime in lstDate)
                {
                    var date = datetime.Date;
                    if (DbContext.FingerTimeSheets.Where(x => x.DayOfCheck == date).FirstOrDefault() == null)
                    {
                        listDateImportTimeSheet.Add(datetime);
                    }
                }
                foreach (var datetime in listDateImportTimeSheet)
                {
                    var date          = datetime.Date;
                    var date1         = datetime.AddDays(1).Date;
                    var listTimeSheet = DbContext.CHECKINOUT.Where(x => x.CHECKTIME >= date && x.CHECKTIME < date1).ToList();
                    if (listTimeSheet.Count > 0)
                    {
                        tmpTimeSheetRepository.RemoveAllData();
                        List <FingerTimeSheetTmp> listTmp = new List <FingerTimeSheetTmp>();
                        foreach (var item in listTimeSheet)
                        {
                            FingerTimeSheetTmp tmp = new FingerTimeSheetTmp();
                            var user = DbContext.USERINFO.FirstOrDefault(x => x.USERID == item.USERID);
                            if (user == null)
                            {
                                continue;
                            }
                            tmp.UserNo  = user.Badgenumber;
                            tmp.Date    = item.CHECKTIME;
                            tmp.AccName = DbContext.USERINFO.Where(x => x.USERID == item.USERID).Select(x => x.Name).FirstOrDefault();
                            tmpTimeSheetRepository.Add(tmp);
                            listTmp.Add(tmp);
                        }
                        unitOfWork.Commit();
                        int count = 0;
                        List <FingerTimeSheetTmpErrorModel> listModel = new List <FingerTimeSheetTmpErrorModel>();
                        var result = fingerTimeSheetService.ImportTimeSheet(out count, DbContext, out listModel);
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("ExData:" + e.Data);
                log.Error("ExMess:" + e.Message);
            }
        }
Example #2
0
        private static void GetDataTimeSheetFromListDateOnePerson(List <DateTime> lstDate, string username)
        {
            TMSDbContext                  DbContext                   = new TMSDbContext();
            IDbFactory                    dbFactory                   = new DbFactory();
            IAppUserRepository            appUserRepository           = new AppUserRepository(dbFactory);
            IChildcareLeaveRepository     childcareLeaveRepository    = new ChildcareLeaveRepository(dbFactory);
            IFingerTimeSheetRepository    fingerTimeSheetRepository   = new FingerTimeSheetRepository(dbFactory);
            ITimeDayRepository            timeDayRepository           = new TimeDayRepository(dbFactory);
            IFingerTimeSheetTmpRepository tmpTimeSheetRepository      = new FingerTimeSheetTmpRepository(dbFactory);
            IOTRequestRepository          OTRequestRepository         = new OTRequestRepository(dbFactory);
            IFingerMachineUserRepository  fingerMachineUserRepository = new FingerMachineUserRepository(dbFactory);
            IOTRequestUserRepository      otrequestUserRepository     = new OTRequestUserRepository(dbFactory);
            IReportRepository             reportRepository            = new ReportRepository(dbFactory);
            UnitOfWork                    unitOfWork                  = new UnitOfWork(dbFactory);
            IRequestRepository            requestRepository           = new RequestRepository(dbFactory);
            IExplanationRequestRepository explanationRepository       = new ExplanationRequestRepository(dbFactory);
            IAbnormalCaseRepository       abnormalRepository          = new AbnormalCaseRepository(dbFactory);
            IEntitleDayAppUserRepository  entitledayRepository        = new EntitleDayAppUserRepository(dbFactory);
            IUserOnsiteRepository         userOnsiteRepository        = new UserOnsiteRepository(dbFactory);
            ISystemConfigRepository       systemConfigRepository      = new SystemConfigRepository(dbFactory);
            IHolidayRepository            holidayRepository           = new HolidayRepository(dbFactory);
            ICommonService                commonService               = new CommonService(systemConfigRepository, timeDayRepository, holidayRepository, unitOfWork);
            ISystemService                systemService               = new SystemService();
            FingerTimeSheetService        fingerTimeSheetService      = new FingerTimeSheetService(fingerTimeSheetRepository, tmpTimeSheetRepository, timeDayRepository,
                                                                                                   OTRequestRepository, fingerMachineUserRepository, otrequestUserRepository, appUserRepository, childcareLeaveRepository, reportRepository, unitOfWork, requestRepository,
                                                                                                   explanationRepository, abnormalRepository, entitledayRepository, userOnsiteRepository, systemService, commonService);
            var userId    = DbContext.Users.Where(x => x.UserName.Equals(username)).Select(x => x.Id).FirstOrDefault();
            var lstUserNo = DbContext.FingerMachineUsers.Where(x => x.UserId.Equals(userId)).Select(x => x.ID);
            var userInfo  = DbContext.USERINFO.Where(x => lstUserNo.Contains(x.Badgenumber)).FirstOrDefault();

            foreach (var datetime in lstDate)
            {
                var date          = datetime.Date;
                var date1         = datetime.AddDays(1).Date;
                var listTimeSheet = DbContext.CHECKINOUT.Where(x => x.CHECKTIME >= date && x.CHECKTIME < date1 && x.USERID.Equals(userInfo.USERID)).ToList();
                if (listTimeSheet.Count > 0)
                {
                    var timeSheetId = DbContext.FingerTimeSheets.Where(x => x.DayOfCheck == datetime && lstUserNo.Contains(x.UserNo)).Select(x => x.ID).AsEnumerable();
                    if ((DbContext.ExplanationRequests.Where(x => timeSheetId.Contains(x.TimeSheetId)).FirstOrDefault() != null))
                    {
                        explanationRepository.DeleteExplanation(timeSheetId.FirstOrDefault());
                    }
                    if ((DbContext.AbnormalCases.Where(x => timeSheetId.Contains(x.TimeSheetID)).FirstOrDefault() != null))
                    {
                        abnormalRepository.DeleteAbnormalCase(timeSheetId.FirstOrDefault());
                    }
                    if ((DbContext.FingerTimeSheets.Where(x => timeSheetId.Contains(x.ID)).FirstOrDefault() != null))
                    {
                        fingerTimeSheetRepository.DeleteFingerTimeSheet(timeSheetId.FirstOrDefault());
                    }
                    tmpTimeSheetRepository.RemoveAllData();
                    foreach (var item in listTimeSheet)
                    {
                        FingerTimeSheetTmp tmp = new FingerTimeSheetTmp();
                        var user = DbContext.USERINFO.FirstOrDefault(x => x.USERID == item.USERID);
                        if (user == null)
                        {
                            continue;
                        }
                        tmp.UserNo  = user.Badgenumber;
                        tmp.Date    = item.CHECKTIME;
                        tmp.AccName = DbContext.USERINFO.Where(x => x.USERID == item.USERID).Select(x => x.Name).FirstOrDefault();
                        tmpTimeSheetRepository.Add(tmp);
                    }
                    unitOfWork.Commit();
                    int count = 0;
                    List <FingerTimeSheetTmpErrorModel> listModel = new List <FingerTimeSheetTmpErrorModel>();
                    var result = fingerTimeSheetService.ReImportTimeSheet(out count, DbContext, out listModel);
                    if (result)
                    {
                        log.Info("reimport success");
                    }
                    else
                    {
                        log.Info("reimport fail");
                    }
                }
            }
        }