Example #1
0
        private void DgUserDataBind()
        {
            PageQueryInput <InvestigationRecordQueryConditions> conditions = new PageQueryInput <InvestigationRecordQueryConditions>()
            {
                PageSize        = myPager.PageSize,
                PageIndex       = myPager.PageIndex,
                QueryConditions = condition
            };

            try
            {
                INRMainService myMainService = BusinessStaticInstances.GetSingleMainServiceInstance();
                var            result        = myMainService.QueryInvestigationRecordListByConditions(conditions);
                myPager.TotalCount    = result.TotalCount;
                dg_Record.DataContext = result.QueryResult;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                ReturnMainPage();
            }
        }
        public PageQueryOutput <InvestigationRecordViewDto> QueryInvestigationRecordListByConditions(PageQueryInput <InvestigationRecordQueryConditions> conditions)
        {
            PageQueryOutput <InvestigationRecordViewDto> result = new PageQueryOutput <InvestigationRecordViewDto>();

            using (NutritionalResearchDatabaseEntities mydb = new NutritionalResearchDatabaseEntities())
            {
                bool queryTimeFlag = (conditions.QueryConditions.QueryStartTime == null || conditions.QueryConditions.QueryEndTime == null) ? false : true;
                bool pageFlag      = (conditions.PageIndex != null && conditions.PageSize != null) ? true : false;
                var  _result       = from nObj in mydb.InvestigationRecord
                                     where nObj.Name.Contains(conditions.QueryConditions.Name) &&
                                     nObj.QueueId.Contains(conditions.QueryConditions.QueueId) &&
                                     nObj.HealthBookId.Contains(conditions.QueryConditions.HealthBookId)
                                     select nObj;
                if (queryTimeFlag)
                {
                    _result = _result.Where(nObj => nObj.CreationTime >= conditions.QueryConditions.QueryStartTime && nObj.CreationTime <= conditions.QueryConditions.QueryEndTime);
                }
                result.TotalCount = _result.Count();
                if (pageFlag)
                {
                    result.PageIndex   = conditions.PageIndex.Value;
                    result.PageCount   = PageComputer.ComputePageCount(result.TotalCount, conditions.PageSize.Value);
                    result.QueryResult = _result.OrderByDescending(nObj => nObj.CreationTime)
                                         .Select(nObj => new InvestigationRecordViewDto()
                    {
                        AuditorName          = nObj.AuditorName,
                        BeforeBMI            = nObj.BeforeBMI,
                        BeforeWeight         = nObj.BeforeWeight,
                        Birthday             = nObj.Birthday,
                        CurrentWeight        = nObj.CurrentWeight,
                        HealthBookId         = nObj.HealthBookId,
                        Height               = nObj.Height,
                        Id                   = nObj.Id,
                        InvestigatorName     = nObj.InvestigatorName,
                        InvestionTime        = nObj.CreationTime,
                        LastFinishQuestionSN = nObj.InvestigationAnswer.OrderByDescending(a => a.QuestionSerialNumber).Select(a => a.QuestionSerialNumber).FirstOrDefault(),
                        Name                 = nObj.Name,
                        QueueId              = nObj.QueueId,
                        State                = (InvestigationRecordStateType)nObj.State,
                        Week                 = nObj.Week
                    })
                                         .Skip(conditions.PageSize.Value * (conditions.PageIndex.Value - 1))
                                         .Take(conditions.PageSize.Value)
                                         .ToList();
                }
                else
                {
                    result.QueryResult = _result.OrderByDescending(nObj => nObj.CreationTime)
                                         .Select(nObj => new InvestigationRecordViewDto()
                    {
                        AuditorName          = nObj.AuditorName,
                        BeforeBMI            = nObj.BeforeBMI,
                        BeforeWeight         = nObj.BeforeWeight,
                        Birthday             = nObj.Birthday,
                        CurrentWeight        = nObj.CurrentWeight,
                        HealthBookId         = nObj.HealthBookId,
                        Height               = nObj.Height,
                        Id                   = nObj.Id,
                        InvestigatorName     = nObj.InvestigatorName,
                        InvestionTime        = nObj.CreationTime,
                        LastFinishQuestionSN = nObj.InvestigationAnswer.OrderByDescending(a => a.QuestionSerialNumber).Select(a => a.QuestionSerialNumber).FirstOrDefault(),
                        Name                 = nObj.Name,
                        QueueId              = nObj.QueueId,
                        State                = (InvestigationRecordStateType)nObj.State,
                        Week                 = nObj.Week
                    }).ToList();
                }
            }
            return(result);
        }