コード例 #1
0
ファイル: FleetPlanSendVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            CurAnnuals = new QueryableDataServiceCollectionView<AnnualDTO>(_context, _context.Annuals);
            _annualDescriptor = new FilterDescriptor("IsOpen", FilterOperator.IsEqualTo, true);
            CurAnnuals.FilterDescriptors.Add(_annualDescriptor);
            CurAnnuals.LoadedData += (sender, e) =>
            {
                if (CurAnnuals.Count != 0)
                {
                    _curAnnual = CurAnnuals.First();
                    _planDescriptor.Value = _curAnnual.Year;
                    if (!Plans.AutoLoad)
                        Plans.AutoLoad = true;
                    else
                        Plans.Load(true);
                    RefreshCommandState();
                }
            };

            Plans = _service.CreateCollection(_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) =>
            {
                CurPlan = new ObservableCollection<PlanDTO> {Plans.OrderBy(p => p.VersionNumber).LastOrDefault()};
                SelPlan = CurPlan.FirstOrDefault();
                if (SelPlan != null)
                {
                    _planHistoryDescriptor.Value = SelPlan.Id;
                    if (!CurPlanHistories.AutoLoad)
                        CurPlanHistories.AutoLoad = true;
                    else
                        CurPlanHistories.Load(true);
                }
                RefreshCommandState();
            };
            _service.RegisterCollectionView(Plans); //注册查询集合

            CurPlanHistories = _service.CreateCollection(_context.PlanHistories);
            _planHistoryDescriptor = new FilterDescriptor("PlanId", FilterOperator.IsEqualTo, Guid.Empty);
            CurPlanHistories.FilterDescriptors.Add(_planHistoryDescriptor);
            CurPlanHistories.LoadedData += (o, e) =>
            {
                foreach (var ph in CurPlanHistories.SourceCollection.Cast<PlanHistoryDTO>())
                {
                    ph.ActionCategories.AddRange(ph.ActionCategories);
                    ph.AircraftCategories.AddRange(_service.GetAircraftCategoriesForPlanHistory(ph));
                    ph.AircraftTypes.AddRange(_service.GetAircraftTypesForPlanHistory(ph));
                    _context.ChangeState(ph, EntityStates.Unchanged);
                }
            };
            _service.RegisterCollectionView(CurPlanHistories); //注册查询集合
        }
コード例 #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
ファイル: FleetPlanPublishVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            CurAnnuals = _service.CreateCollection(_context.Annuals);
            _annualDescriptor = new FilterDescriptor("IsOpen", FilterOperator.IsEqualTo, true);
            CurAnnuals.FilterDescriptors.Add(_annualDescriptor);
            CurAnnuals.LoadedData += (sender, e) =>
            {
                if (e.HasError)
                {
                    e.MarkErrorAsHandled();
                    return;
                }
                if (CurAnnuals.Count != 0)
                {
                    _curAnnual = CurAnnuals.First();
                }
                if (!Plans.AutoLoad)
                    Plans.AutoLoad = true;
                else
                    Plans.Load(true);
                RefreshCommandState();
            };
            _service.RegisterCollectionView(CurAnnuals); //注册查询集合

            Plans = _service.CreateCollection(_context.Plans);
            Plans.LoadedData += (sender, e) =>
            {
                if (e.HasError)
                {
                    e.MarkErrorAsHandled();
                    return;
                }
                ViewPlans = new ObservableCollection<PlanDTO>();
                ViewPlans.AddRange(
                    e.Entities.Cast<PlanDTO>().Where(p => p.Year == _curAnnual.Year).OrderBy(p => p.VersionNumber));
                PublishingPlan = ViewPlans.Where(p =>
                    p.PublishStatus > (int) PlanPublishStatus.待发布 &&
                    p.PublishStatus < (int) PlanPublishStatus.已发布);
                SelPlan = ViewPlans.OrderBy(p => p.VersionNumber).LastOrDefault();
                LastPublishedPlan =
                    ViewPlans.OrderBy(p => p.VersionNumber)
                        .LastOrDefault(p => p.PlanPublishStatus == PlanPublishStatus.已发布);
                RefreshCommandState();
            };
            _service.RegisterCollectionView(Plans); //注册查询集合

            PlanHistories = new QueryableDataServiceCollectionView<PlanHistoryDTO>(_context, _context.PlanHistories);
            _planHistoryDescriptor = new FilterDescriptor("PlanId", FilterOperator.IsEqualTo, Guid.Empty);
            PlanHistories.FilterDescriptors.Add(_planHistoryDescriptor);
        }
コード例 #4
0
        /// <summary>
        /// 创建新年度计划
        /// </summary>
        /// <param name="lastPlan"></param>
        /// <param name="allPlanHistories"></param>
        /// <param name="newAnnual"></param>
        /// <returns></returns>
        internal PlanDTO CreateNewYearPlan(PlanDTO lastPlan, QueryableDataServiceCollectionView<PlanHistoryDTO> allPlanHistories, AnnualDTO newAnnual)
        {
            var title = newAnnual.Year + "年度运力规划";
            // 从当前计划复制生成新年度计划
            var newPlan = new PlanDTO
            {
                Id = Guid.NewGuid(),
                Title = title,
                CreateDate = DateTime.Now,
                AnnualId = newAnnual.Id,
                Year = newAnnual.Year,
                AirlinesId = lastPlan.AirlinesId,
                AirlinesName = lastPlan.AirlinesName,
                VersionNumber = 1,
                Status = (int)PlanStatus.草稿,
                IsValid = false,
                IsFinished = false,
                PublishStatus = (int)PlanPublishStatus.待发布,
            };
            // 获取需要滚动到下一年度的计划明细项(可再次申请的计划明细不滚动到下一年度,并将对应的计划飞机置为预备状态)
            var lastPhs = allPlanHistories.Where(p => p.PlanId == lastPlan.Id).ToList();
            var planHistories = (lastPhs == null) ? null : lastPhs.Where(o => o.PlanAircraftId == null ||
                                           (o.PlanAircraftId != null && (o.ManageStatus != (int)ManageStatus.预备
                                                                       && o.ManageStatus != (int)ManageStatus.运营
                                                                       && o.ManageStatus != (int)ManageStatus.退役))).ToList();

            var resultphs = new List<PlanHistoryDTO>();
            if (planHistories != null)
                // 从当前计划往新版本计划复制运营计划
                resultphs = planHistories.Where(ph => ph.RelatedGuid == null || ph.RelatedEndDate == null)
                      .Select(q => new PlanHistoryDTO
                      {
                          PlanId = newPlan.Id,
                          Id = Guid.NewGuid(),
                          ActionCategoryId = q.ActionCategoryId,
                          AircraftTypeId = q.AircraftTypeId,
                          AirlinesId = q.AirlinesId,
                          CarryingCapacity = q.CarryingCapacity,
                          SeatingCapacity = q.SeatingCapacity,
                          RelatedGuid = q.RelatedGuid,
                          RelatedEndDate = q.RelatedEndDate,
                          IsSubmit = q.IsSubmit,
                          IsValid = q.IsValid,
                          Note = q.Note,
                          PerformAnnualId = q.PerformAnnualId,
                          PerformMonth = q.PerformMonth,
                          PlanAircraftId = q.PlanAircraftId,
                          PlanType = q.PlanType,
                          TargetCategoryId = q.TargetCategoryId,
                          AirlinesName = q.AirlinesName,
                          Regional = q.Regional,
                          AircraftTypeName = q.AircraftTypeName,
                          CaacAircraftTypeName = q.CaacAircraftTypeName,
                          ActionType = q.ActionType,
                          ActionName = q.ActionName,
                          TargetType = q.TargetType,
                          Year = q.Year,
                          ManageStatus = q.ManageStatus,
                      }).ToList();
            resultphs.ForEach(allPlanHistories.AddNew);
            return newPlan;
        }
コード例 #5
0
ファイル: FleetPlanPrepareVM.cs プロジェクト: unicloud/FRP
        private void OnUnLock(object obj)
        {
            var newAnnual = Annuals.SourceCollection.Cast<AnnualDTO>()
                .FirstOrDefault(a => a.Year == _curAnnual.Year + 1);
            if (newAnnual == null || _curAnnual == null)
            {
                MessageAlert("年度不能为空!");
                return;
            }
            //获取当前计划作为创建新版本计划的上一版本计划
            var lastPlan = AllPlans.Where(p => p.Year == _curAnnual.Year).OrderBy(p => p.VersionNumber).LastOrDefault();

            //设置当前打开年度
            newAnnual.IsOpen = true;
            _curAnnual.IsOpen = false;

            //刷新_service中的静态属性CurrentAnnual
            _curAnnual = Annuals.SourceCollection.Cast<AnnualDTO>().SingleOrDefault(p => p.IsOpen);

            //将上年度的最后一个版本中可再次申请的计划明细对应的计划飞机置为预备状态
            if (lastPlan != null)
            {
                var lastPlanHistories = AllPlanHistories.Where(p => p.PlanId == lastPlan.Id);
                foreach (var lastPlanHistory in lastPlanHistories)
                {
                    if (lastPlanHistory != null && lastPlanHistory.CanRequest == (int) CanRequest.可再次申请)
                    {
                        lastPlanHistory.ManageStatus = (int) ManageStatus.预备;
                        var planAircraft = PlanAircrafts.FirstOrDefault(p => p.Id == lastPlanHistory.PlanAircraftId);
                        if (planAircraft != null) planAircraft.Status = (int) ManageStatus.预备;
                    }
                }
                //创建新年度的第一版本计划
                AllPlans.AddNew(_service.CreateNewYearPlan(lastPlan, AllPlanHistories, newAnnual));
            }

            SelAnnual = _curAnnual;

            RefreshCommandState();
        }
コード例 #6
0
ファイル: FleetPlanPrepareVM.cs プロジェクト: unicloud/FRP
        /// <summary>
        ///     初始化ViewModel
        ///     <remarks>
        ///         统一在此处创建并注册CollectionView集合。
        ///     </remarks>
        /// </summary>
        private void InitializeVM()
        {
            Annuals = _service.CreateCollection(_context.Annuals);
            var sort = new SortDescriptor {Member = "Year", SortDirection = ListSortDirection.Descending};
            Annuals.SortDescriptors.Add(sort);
            var group = new GroupDescriptor {Member = "ProgrammingName", SortDirection = ListSortDirection.Descending};
            Annuals.GroupDescriptors.Add(group);
            Annuals.LoadedData += (sender, e) =>
            {
                _curAnnual = e.Entities.Cast<AnnualDTO>().FirstOrDefault(p => p.IsOpen);
                _loadedAnnuals = true;
                SetSelAnnual();
                RefreshCommandState();
            };
            _service.RegisterCollectionView(Annuals); //注册查询集合

            AllPlans = _service.CreateCollection(_context.Plans);
            AllPlans.LoadedData += (sender, e) =>
            {
                _loadedPlans = true;
                SetSelAnnual();
            };
            _service.RegisterCollectionView(AllPlans);

            AllPlanHistories = _service.CreateCollection(_context.PlanHistories);
            AllPlanHistories.LoadedData += (sender, e) =>
            {
                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));
                    _context.ChangeState(ph, EntityStates.Unchanged);
                }
                RaisePropertyChanged(() => SelPlan);
            };
            _service.RegisterCollectionView(AllPlanHistories);

            PlanAircrafts = _service.CreateCollection(_context.PlanAircrafts);
            PlanAircrafts.FilterDescriptors.Add(new FilterDescriptor("AircraftId", FilterOperator.IsEqualTo, null));
            _service.RegisterCollectionView(PlanAircrafts);
        }
コード例 #7
0
ファイル: FleetPlanService.cs プロジェクト: unicloud/FRP
 /// <summary>
 ///     创建新年度的初始化计划
 /// </summary>
 /// <param name="lastPlan"></param>
 /// <param name="allPlanHistories"></param>
 /// <param name="newAnnual"></param>
 /// <returns>
 ///     <see cref="IFleetPlanService" />
 /// </returns>
 public PlanDTO CreateNewYearPlan(PlanDTO lastPlan,
     QueryableDataServiceCollectionView<PlanHistoryDTO> allPlanHistories, AnnualDTO newAnnual)
 {
     using (var pb = new FleetPlanServiceHelper())
     {
         return pb.CreateNewYearPlan(lastPlan, allPlanHistories, newAnnual);
     }
 }