コード例 #1
0
        public static WorkReportViewModel GetAllUserWorkReports(int year, int month, string sortField = null, ESortDirection sortDirection = ESortDirection.Ascending, string filterUser = null)
        {
            List <WorkReport> workReports = null;

            using (MyDbContext db = new MyDbContext())
            {
                var query = db.WorkReports.Include("User").Where(r => r.AsOfDate.Year == year && r.AsOfDate.Month == month);
                if (!string.IsNullOrWhiteSpace(filterUser))
                {
                    query = query.Where(r => r.User.ChineseName.Contains(filterUser) || r.User.EnglishName.Contains(filterUser) || r.User.FullName.Contains(filterUser));
                }
                workReports = query.ToList();
            }
            var       workReportsNormal = workReports.Where(r => !r.User.IsWorkingAtHome);
            var       workReportsAtHome = workReports.Where(r => r.User.IsWorkingAtHome);
            DataTable dtNormal          = BuildWorkReportDataTable(workReportsNormal, year, month);
            DataTable dtAtHome          = BuildWorkReportDataTable(workReportsAtHome, year, month);
            DataView  dvNormal          = dtNormal.DefaultView;

            if (!string.IsNullOrWhiteSpace(sortField))
            {
                dvNormal.Sort = sortField + " " + sortDirection.GetDescription();
            }
            return(new WorkReportViewModel
            {
                Month = new DateTime(year, month, 1).ToString("MM/yyyy"),
                SortField = sortField,
                SortDirection = sortDirection,
                Filter = filterUser,
                WorkReportDataView = dvNormal,
                WorkReportAtHomeDataView = dtAtHome.DefaultView,
                UploadProperty = WorkReportPropertyService.GetWorkReportProperty(year, month),
                UserAutoCompletionSource = UserService.GetUserAutoCompletionSourceData()
            });
        }
コード例 #2
0
        public static WorkReportViewModel GetWorkReports(int userId, int year, int month)
        {
            List <WorkReport> workReports = null;

            using (MyDbContext db = new MyDbContext())
            {
                workReports = db.WorkReports.Include("User").Where(r => r.UserId == userId && r.AsOfDate.Year == year && r.AsOfDate.Month == month).ToList();
            }
            var       workReportsNormal = workReports.Where(r => !r.User.IsWorkingAtHome);
            var       workReportsAtHome = workReports.Where(r => r.User.IsWorkingAtHome);
            DataTable dtNormal          = BuildWorkReportDataTable(workReportsNormal, year, month);
            DataTable dtAtHome          = BuildWorkReportDataTable(workReportsAtHome, year, month);

            return(new WorkReportViewModel
            {
                Month = new DateTime(year, month, 1).ToString("MM/yyyy"),
                UploadProperty = WorkReportPropertyService.GetWorkReportProperty(year, month),
                WorkReportDataView = dtNormal.DefaultView,
                WorkReportAtHomeDataView = dtAtHome.DefaultView
            });
        }