Пример #1
0
        public bool ImportTimeSheet(out string message, DateTime dateJobExcute)
        {
            message = "error";
            DateTime     yesterday = dateJobExcute.AddDays(-1).Date;
            TMSDbContext DbContext = new TMSDbContext();

            try
            {
                var listTimeSheet = DbContext.CHECKINOUT.Where(x => x.CHECKTIME >= yesterday && x.CHECKTIME < dateJobExcute).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();
                    //import to table finger timesheet
                    int countSuccess = 0;
                    List <FingerTimeSheetTmpErrorModel> listModel = new List <FingerTimeSheetTmpErrorModel>();
                    if (_fingerTSService.ImportTimeSheet(out countSuccess, DbContext, out listModel))
                    {
                        message = "Success";
                        log.Info("Job Time Sheet Run Success :" + DateTime.Now.ToString("dd'/'MM'/'yyyy HH:mm:ss"));
                        return(true);
                    }
                    else
                    {
                        message = "";
                        StringBuilder sb = new StringBuilder();
                        foreach (var item in listModel)
                        {
                            sb.AppendLine(item.Error);
                        }
                        message = sb.ToString();
                        return(false);
                    }
                }
                else
                {
                    message = "FingerTimeSheetTmp table has no data !";
                    return(true);
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                log.Error(ex.Message);
                if (ex.StackTrace != null)
                {
                    log.Info(ex.StackTrace);
                }
                return(false);
            }
        }
Пример #2
0
 public FingerTimeSheetTmp Add(FingerTimeSheetTmp fingerTimeSheetTmp)
 {
     return(_fingerTimeSheetTmpRepository.Add(fingerTimeSheetTmp));
 }