コード例 #1
0
ファイル: RequestVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            Requests = _service.CreateCollection(_context.Requests.Expand(p => p.RelatedDocs), o => o.ApprovalHistories,
                o => o.RelatedDocs);
            var cfd = new CompositeFilterDescriptor {LogicalOperator = FilterCompositionLogicalOperator.And};
            var requestDescriptor = new FilterDescriptor("Title", FilterOperator.IsNotEqualTo, "指标飞机申请(系统添加)");
            cfd.FilterDescriptors.Add(requestDescriptor);
            var statusDateDescriptor = new FilterDescriptor("Status", FilterOperator.IsLessThan, (int) RequestStatus.已审批);
            cfd.FilterDescriptors.Add(statusDateDescriptor);
            Requests.FilterDescriptors.Add(cfd);
            Requests.LoadedData += (o, e) =>
            {
                if (SelRequest == null)
                    SelRequest = Requests.FirstOrDefault();
            };
            _service.RegisterCollectionView(Requests);

            Annuals = new QueryableDataServiceCollectionView<AnnualDTO>(_context, _context.Annuals);
            Annuals.LoadedData += (sender, e) =>
            {
                if (Annuals.Count != 0 && Annuals.FirstOrDefault(p => p.IsOpen) != null)
                {
                    _planDescriptor.Value = Annuals.First(p => p.IsOpen).Year;
                    if (!Plans.AutoLoad)
                        Plans.AutoLoad = true;
                    else
                        Plans.Load(true);
                    RefreshCommandState();
                }
            };

            Plans = new QueryableDataServiceCollectionView<PlanDTO>(_context, _context.Plans);
            _planDescriptor = new FilterDescriptor("Year", FilterOperator.IsEqualTo, -1);
            var sort = new SortDescriptor {Member = "VersionNumber", SortDirection = ListSortDirection.Ascending};
            Plans.SortDescriptors.Add(sort);
            Plans.FilterDescriptors.Add(_planDescriptor);
            Plans.LoadedData += (sender, e) =>
            {
                var curPlan = Plans.OrderBy(p => p.VersionNumber).LastOrDefault();
                if (curPlan != null)
                {
                    _planHistoryDescriptor.Value = curPlan.Id;
                    if (!CurPlanHistories.AutoLoad)
                        CurPlanHistories.AutoLoad = true;
                    else
                        CurPlanHistories.Load(true);
                }
                RefreshCommandState();
                _approvalHistoryCaches = new List<ApprovalHistoryCache>();
            };

            CurPlanHistories = _service.CreateCollection(_context.PlanHistories);
            _planHistoryDescriptor = new FilterDescriptor("PlanId", FilterOperator.IsEqualTo, Guid.Empty);
            var group = new GroupDescriptor {Member = "CanRequest", SortDirection = ListSortDirection.Ascending};
            CurPlanHistories.GroupDescriptors.Add(group);
            CurPlanHistories.FilterDescriptors.Add(_planHistoryDescriptor);
            _service.RegisterCollectionView(CurPlanHistories);

            PlanAircrafts = _service.CreateCollection(_context.PlanAircrafts);
            _service.RegisterCollectionView(PlanAircrafts);
        }
コード例 #2
0
ファイル: FleetPlanLayVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            Annuals = new QueryableDataServiceCollectionView<AnnualDTO>(_context, _context.Annuals);
            _annualDescriptor = new FilterDescriptor("Year", FilterOperator.IsGreaterThanOrEqualTo,
                DateTime.Now.Year - 2);
            Annuals.FilterDescriptors.Add(_annualDescriptor);
            Annuals.OrderBy(p => p.Year);
            Annuals.LoadedData += (sender, e) =>
            {
                if (Annuals.Count != 0)
                {
                    _curAnnual = e.Entities.Cast<AnnualDTO>().SingleOrDefault(p => p.IsOpen);
                    if (!Plans.AutoLoad)
                        Plans.AutoLoad = true;
                    else
                        Plans.Load(true);
                }
                RefreshCommandState();
            }; //获取年度集合,同时得到当前计划年度,再获取计划集合,同时得到当前计划

            Plans = _service.CreateCollection(_context.Plans);
            Plans.LoadedData += (sender, e) =>
            {
                CurPlan =
                    e.Entities.Cast<PlanDTO>()
                        .Where(p => p.Year == _curAnnual.Year)
                        .OrderBy(p => p.VersionNumber)
                        .LastOrDefault();
                if (!AllPlanHistories.AutoLoad)
                    AllPlanHistories.AutoLoad = true;
                else
                    AllPlanHistories.Load(true);
            };
            _service.RegisterCollectionView(Plans); //注册查询集合,获取计划集合,同时得到当前计划

            AllPlanHistories = _service.CreateCollection(_context.PlanHistories);
            AllPlanHistories.LoadedData += (o, e) =>
            {
                ViewPlanHistories = new ObservableCollection<PlanHistoryDTO>();
                if (CurPlan != null)
                {
                    foreach (var ph in AllPlanHistories.SourceCollection.Cast<PlanHistoryDTO>())
                    {
                        ph.ActionCategories.AddRange(_service.GetActionCategoriesForPlanHistory(ph));
                        ph.AircraftCategories.AddRange(_service.GetAircraftCategoriesForPlanHistory(ph));
                        ph.AircraftTypes.AddRange(_service.GetAircraftTypesForPlanHistory(ph));
                        if (ph.PlanId == CurPlan.Id)
                            ViewPlanHistories.Add(ph);
                        _context.ChangeState(ph, EntityStates.Unchanged);
                    }
                    RaisePropertyChanged(() => ViewPlanHistories);
                }
            };
            _service.RegisterCollectionView(AllPlanHistories); //注册查询集合,获取计划集合,同时得到当前计划

            ViewPlanAircrafts = _service.CreateCollection(_context.PlanAircrafts);
            _planAcDescriptor = new FilterDescriptor("AircraftId", FilterOperator.IsEqualTo, null);
            ViewPlanAircrafts.FilterDescriptors.Add(_planAcDescriptor);
            _service.RegisterCollectionView(ViewPlanAircrafts); //注册查询集合,获取所有还没飞机的计划飞机集合,用户界面展示

            Aircrafts = new QueryableDataServiceCollectionView<AircraftDTO>(_context, _context.Aircrafts);
            //获取所有运营飞机的集合,TODO:判断是否必要筛选掉已退出运营的飞机

            AllPlanAircrafts = new QueryableDataServiceCollectionView<PlanAircraftDTO>(_context, _context.PlanAircrafts);
            //获取所有的计划飞机,用于关联到运营飞机,用于从运营飞机编制计划时使用

            AllActionCategories = new QueryableDataServiceCollectionView<ActionCategoryDTO>(_context,
                _context.ActionCategories); //获取所有的计划飞机,用于关联到运营飞机,用于从运营飞机编制计划时使用
        }
コード例 #3
0
ファイル: SpareEnginePlanLayVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            EnginePlans = _service.CreateCollection(_context.EnginePlans, o => o.EnginePlanHistories);
            EnginePlans.LoadedData += (o, e) =>
            {
                if (SelEnginePlan == null)
                    SelEnginePlan = EnginePlans.FirstOrDefault();
            };
            _service.RegisterCollectionView(EnginePlans); //注册查询集合

            PlanEngines = _service.CreateCollection(_context.PlanEngines);
            _service.RegisterCollectionView(PlanEngines); //注册查询集合

            Annuals = new QueryableDataServiceCollectionView<AnnualDTO>(_context, _context.Annuals);
            var annualDescriptor = new FilterDescriptor("Year", FilterOperator.IsGreaterThanOrEqualTo,
                DateTime.Now.Year - 1);
            Annuals.FilterDescriptors.Add(annualDescriptor);
            Annuals.OrderBy(p => p.Year);

            EngineTypes = new QueryableDataServiceCollectionView<EngineTypeDTO>(_context, _context.EngineTypes);

            ActionCategories = new QueryableDataServiceCollectionView<ActionCategoryDTO>(_context,
                _context.ActionCategories);
            var actionDescriptor = new FilterDescriptor("ActionType", FilterOperator.IsGreaterThanOrEqualTo, "引进");
            ActionCategories.FilterDescriptors.Add(actionDescriptor);

            //TODO:初始化当前航空公司
            _curAirlines = new AirlinesDTO
            {
                Id = Guid.Parse("1978ADFC-A2FD-40CC-9A26-6DEDB55C335F"),
                CnName = "四川航空股份有限公司",
                CnShortName = "川航",
            };
        }