/// <summary>
        /// 创建新的运营历史
        /// </summary>
        /// <param name="planDetail">计划明细</param>
        /// <param name="aircraft">飞机</param>
        private static void CreateOperationHistory(PlanHistoryDTO planDetail, ref AircraftDTO aircraft)
        {
            var id = planDetail.ApprovalHistoryId == null ? Guid.Empty : Guid.Parse(planDetail.ApprovalHistoryId.ToString());
            var operationHistory = new OperationHistoryDTO
            {
                OperationHistoryId = id,

                AirlinesId = planDetail.AirlinesId,
                AirlinesName = planDetail.AirlinesName,
                AircraftId = aircraft.AircraftId,
                RegNumber = "B-",
                ImportCategoryId = aircraft.ImportCategoryId,
                ImportActionType = aircraft.ImportCategoryName,
                Status = (int)OperationStatus.草稿,
            };
            if (planDetail.PlanType == 1) planDetail.RelatedGuid = operationHistory.OperationHistoryId;
            aircraft.OperationHistories.Add(operationHistory);
            // 更改运营历史状态
            operationHistory.Status = (int)OperationStatus.草稿;
        }
 /// <summary>
 /// 创建新飞机
 /// </summary>
 /// <param name="planDetail">计划明细</param>
 private static AircraftDTO CreateAircraft(PlanHistoryDTO planDetail)
 {
     var aircraft = new AircraftDTO
     {
         AircraftId = Guid.NewGuid(),
         AircraftTypeId = planDetail.AircraftTypeId,
         AircraftTypeName = planDetail.AircraftTypeName,
         AirlinesId = planDetail.AirlinesId,
         AirlinesName = planDetail.AirlinesName,
         CreateDate = DateTime.Now,
         IsOperation = true,
         RegNumber = "B-",
         SeatingCapacity = planDetail.SeatingCapacity,
         CarryingCapacity = planDetail.CarryingCapacity,
         ImportCategoryId = planDetail.ActionCategoryId,
         ImportCategoryName = planDetail.ActionType + "-" + planDetail.ActionName,
     };
     planDetail.AircraftId = aircraft.AircraftId;
     CreateOperationHistory(planDetail, ref aircraft);
     CreateAircraftBusiness(planDetail, ref aircraft);
     return aircraft;
 }
        /// <summary>
        /// 创建新的商业数据历史
        /// </summary>
        /// <param name="planDetail"></param>
        /// <param name="aircraft">飞机</param>
        private static void CreateAircraftBusiness(PlanHistoryDTO planDetail, ref AircraftDTO aircraft)
        {
            var aircraftBusiness = new AircraftBusinessDTO
            {
                AircraftBusinessId = Guid.NewGuid(),
                AircraftId = aircraft.AircraftId,
                AircraftTypeId = aircraft.AircraftTypeId,
                ImportCategoryId = aircraft.ImportCategoryId,
                SeatingCapacity = aircraft.SeatingCapacity,
                CarryingCapacity = aircraft.CarryingCapacity,
                Status = (int)OperationStatus.草稿,
                Regional = planDetail.Regional,
                StartDate = DateTime.Now,
            };

            if (planDetail.PlanType == 2) planDetail.RelatedGuid = aircraftBusiness.AircraftBusinessId;
            aircraft.AircraftBusinesses.Add(aircraftBusiness);
            // 更改商业数据历史状态
            aircraftBusiness.Status = (int)OperationStatus.草稿;
        }
        /// <summary>
        /// 创建运营计划明细
        /// 同一架计划飞机在一份计划中的明细项不得超过两条,且两条不得为同种操作类型(含运营计划与变更计划)
        /// </summary>
        /// <param name="plan"></param>
        /// <param name="allPlanHistories"></param>
        /// <param name="planAircraft"></param>
        /// <param name="aircraft"></param>
        /// <param name="actionType"></param>
        /// <param name="planType"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        internal PlanHistoryDTO CreatePlanHistory(PlanDTO plan, QueryableDataServiceCollectionView<PlanHistoryDTO> allPlanHistories, ref PlanAircraftDTO planAircraft, AircraftDTO aircraft, string actionType, int planType, IFleetPlanService service)
        {
            if (plan == null) return null;
            // 创建新的计划历史
            var planDetail = new PlanHistoryDTO
            {
                Id = Guid.NewGuid(),
                PlanId = plan.Id,
                AirlinesId = plan.AirlinesId,
                AirlinesName = plan.AirlinesName,
                PerformAnnualId = plan.AnnualId,
                PerformMonth = 1,
                PlanType = planType,
                ActionType = actionType,
                ManageStatus = (int)ManageStatus.计划,
                CanRequest = (int)CanRequest.未报计划,
                CanDeliver = (int)CanDeliver.未申请,
            };

            planDetail.ActionCategories = service.GetActionCategoriesForPlanHistory(planDetail);
            planDetail.AircraftCategories = service.GetAircraftCategoriesForPlanHistory(planDetail);
            planDetail.AircraftTypes = service.GetAircraftTypesForPlanHistory(planDetail);

            // 1、计划飞机为空
            if (planAircraft == null)
            {
                planAircraft = new PlanAircraftDTO
                {
                    Id = Guid.NewGuid(),
                    AirlinesId = plan.AirlinesId,
                    AirlinesName = plan.AirlinesName,
                    Status = (int)ManageStatus.计划,
                    IsOwn = true
                };
                planDetail.PlanAircraftId = planAircraft.Id;
            }
            // 2、计划飞机非空
            else
            {
                // 获取计划飞机的所有计划明细集合
                Guid planAcId = planAircraft.Id;
                var planAcPhs = allPlanHistories.Where(p => p.PlanAircraftId == planAcId).ToList();
                // 获取计划飞机在当前计划中的计划明细集合
                PlanAircraftDTO dto = planAircraft;
                var currentPhs = allPlanHistories.Where(p => p.PlanId == plan.Id).ToList();
                var planDetails = currentPhs.Where(ph => ph.PlanAircraftId == dto.Id).ToList();
                // 2.1、不是针对现有飞机的计划明细
                if (planAircraft.AircraftId == null && aircraft == null)
                {
                    if (planAcPhs.Any())
                    {
                        // 获取计划飞机的最后一条计划明细,用于复制数据
                        var planHistory =
                            planAcPhs.OrderBy(ph => ph.Year)
                               .ThenBy(ph => ph.PerformMonth)
                               .LastOrDefault();
                        if (planHistory != null)
                        {
                            // 1、计划飞机在当前计划中没有明细项,(20140106补充)是预备状态的计划飞机
                            if (!planDetails.Any())
                            {
                                planDetail.AircraftTypeId = planAircraft.AircraftTypeId;
                                planDetail.ActionCategoryId = planHistory.ActionCategoryId;
                                planDetail.ActionType = planHistory.ActionType;
                                planDetail.TargetCategoryId = planHistory.TargetCategoryId;
                                planDetail.TargetType = planHistory.TargetType;
                                planDetail.SeatingCapacity = planHistory.SeatingCapacity;
                                planDetail.CarryingCapacity = planHistory.CarryingCapacity;
                                if (planHistory.NeedRequest)
                                {
                                    planDetail.CanRequest = (int)CanRequest.未报计划;
                                    planDetail.CanDeliver = (int)CanDeliver.未申请;
                                }
                                else
                                {
                                    planDetail.CanRequest = (int)CanRequest.无需申请;
                                    planDetail.CanDeliver = (int)CanDeliver.可交付;
                                }
                                planAircraft.Status = (int)ManageStatus.计划;
                            }
                            // 2、计划飞机在当前计划中已有明细项
                            else
                            {
                                planDetail.Regional = planAircraft.Regional;
                                planDetail.AircraftTypeName = planAircraft.AircraftTypeName;
                                planDetail.CaacAircraftTypeName = planAircraft.AircraftTypeName;
                                planDetail.AircraftTypeId = planAircraft.AircraftTypeId;
                                planDetail.SeatingCapacity = -planHistory.SeatingCapacity;
                                planDetail.CarryingCapacity = -planHistory.CarryingCapacity;
                                planDetail.CanRequest = (int)CanRequest.无需申请;
                                planDetail.CanDeliver = (int)CanDeliver.可交付;
                            }
                        }
                    }
                }
                // 2.2、是针对现有飞机的计划明细,退出或变更计划,无需改变计划飞机管理状态
                else
                {
                    if (planType == 1) //为退出计划
                    {
                        planDetail.Regional = aircraft.Regional;
                        planDetail.RegNumber = aircraft.RegNumber;
                        planDetail.AircraftTypeId = planAircraft.AircraftTypeId;
                        planDetail.AircraftTypeName = planAircraft.AircraftTypeName;
                        planDetail.CaacAircraftTypeName = planAircraft.AircraftTypeName;
                        planDetail.SeatingCapacity = -aircraft.SeatingCapacity;
                        planDetail.CarryingCapacity = -aircraft.CarryingCapacity;
                        planDetail.AircraftId = aircraft.AircraftId;
                        planDetail.CanRequest = (int)CanRequest.无需申请;
                        planDetail.CanDeliver = (int)CanDeliver.可交付;
                        planDetail.ManageStatus = (int)ManageStatus.运营;
                    }
                    else if (planType == 2) //为变更计划
                    {
                        // 获取飞机的当前商业数据,赋予新创建的变更计划明细
                        var abs = aircraft.AircraftBusinesses;
                        if (abs.Any())
                        {
                            var aircraftBusiness = abs.FirstOrDefault(a => a.EndDate == null);
                            if (aircraftBusiness != null)
                            {
                                planDetail.Regional = aircraft.Regional;
                                planDetail.RegNumber = aircraft.RegNumber;
                                planDetail.TargetCategoryId = aircraftBusiness.ImportCategoryId;
                                planDetail.SeatingCapacity = aircraftBusiness.SeatingCapacity;
                                planDetail.CarryingCapacity = aircraftBusiness.CarryingCapacity;
                                planDetail.AircraftId = aircraft.AircraftId;
                                planDetail.ManageStatus = (int)ManageStatus.运营;
                            }
                        }
                    }
                }
                planDetail.PlanAircraftId = planAircraft.Id;
            }
            return planDetail;
        }
        /// <summary>
        /// 完成计划项
        /// </summary>
        /// <param name="planDetail"></param>
        /// <param name="aircraft"></param>
        /// <param name="editAircraft"></param>
        /// <param name="service"></param>
        /// <returns></returns>
        internal void CompletePlan(PlanHistoryDTO planDetail, AircraftDTO aircraft, ref AircraftDTO editAircraft, IFleetPlanService service)
        {
            OperationHistoryDTO operationHistory;
            if (planDetail == null)
            {
                throw new ArgumentNullException("planDetail");
            }
            var actionName = planDetail.ActionName;
            if (actionName == null)
            {
                return;
            }
            // 根据引进方式调用不同的操作
            switch (actionName)
            {
                case "购买":
                    // 创建新飞机
                    editAircraft = CreateAircraft(planDetail);
                    break;
                case "融资租赁":
                    // 创建新飞机
                    editAircraft = CreateAircraft(planDetail);
                    break;
                case "经营租赁":
                    // 创建新飞机
                    editAircraft = CreateAircraft(planDetail);
                    break;
                case "湿租":
                    // 创建新飞机
                    editAircraft = CreateAircraft(planDetail);
                    break;
                case "经营租赁续租":
                    // 创建新运营历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateOperationHistory(planDetail, ref editAircraft);
                    }
                    break;
                case "湿租续租":
                    // 创建新运营历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateOperationHistory(planDetail, ref editAircraft);
                    }
                    break;
                case "出售":
                    // 更改运营历史状态
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        operationHistory = editAircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null);
                        if (operationHistory != null)
                        {
                            operationHistory.Status = (int)OperationStatus.草稿;
                            var actionCategoryDto =
                                service.GetActionCategories(null)
                                    .SourceCollection.Cast<ActionCategoryDTO>()
                                    .FirstOrDefault(ac => ac.ActionName == "出售");
                            if (actionCategoryDto != null)
                                operationHistory.ExportCategoryId = actionCategoryDto.Id;

                            if (planDetail.PlanType == 1) planDetail.RelatedGuid = operationHistory.OperationHistoryId;
                        }
                    }
                    break;
                case "出租":
                    // 更改运营历史状态
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        operationHistory = editAircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null);
                        if (operationHistory != null)
                        {
                            operationHistory.Status = (int)OperationStatus.草稿;
                            var actionCategoryDto =
                                service.GetActionCategories(null)
                                    .SourceCollection.Cast<ActionCategoryDTO>()
                                    .FirstOrDefault(ac => ac.ActionName == "出租");
                            if (actionCategoryDto != null)
                                operationHistory.ExportCategoryId = actionCategoryDto.Id;

                            if (planDetail.PlanType == 1) planDetail.RelatedGuid = operationHistory.OperationHistoryId;
                        }
                    }
                    break;
                case "退租":
                    // 更改运营历史状态
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        operationHistory = editAircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null);
                        if (operationHistory != null)
                        {
                            operationHistory.Status = (int)OperationStatus.草稿;
                            var actionCategoryDto =
                                service.GetActionCategories(null)
                                    .SourceCollection.Cast<ActionCategoryDTO>()
                                    .FirstOrDefault(ac => ac.ActionName == "退租");
                            if (actionCategoryDto != null)
                                operationHistory.ExportCategoryId = actionCategoryDto.Id;

                            if (planDetail.PlanType == 1) planDetail.RelatedGuid = operationHistory.OperationHistoryId;
                        }
                    }
                    break;
                case "退役":
                    // 更改运营历史状态
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        operationHistory = editAircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null);
                        if (operationHistory != null)
                        {
                            operationHistory.Status = (int)OperationStatus.草稿;
                            var actionCategoryDto =
                                service.GetActionCategories(null)
                                    .SourceCollection.Cast<ActionCategoryDTO>()
                                    .FirstOrDefault(ac => ac.ActionName == "退役");
                            if (actionCategoryDto != null)
                                operationHistory.ExportCategoryId = actionCategoryDto.Id;

                            if (planDetail.PlanType == 1) planDetail.RelatedGuid = operationHistory.OperationHistoryId;
                        }
                    }
                    break;
                case "货改客":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
                case "客改货":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
                case "售后经营租赁":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
                case "售后融资租赁":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
                case "一般改装":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
                case "租转购":
                    // 创建商业数据历史
                    if (aircraft != null)
                    {
                        editAircraft = aircraft;
                        CreateAircraftBusiness(planDetail, ref editAircraft);
                    }
                    break;
            }
            //更改计划飞机状态
            planDetail.ManageStatus = (int)ManageStatus.运营; //TODO 修改计划飞机的状态(前台或后台处理)
        }
 /// <summary>
 /// 创建新的所有权历史记录
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="service"></param>
 /// <returns></returns>
 internal OwnershipHistoryDTO CreateNewOwnership(AircraftDTO aircraft, IFleetPlanService service)
 {
     //var ownership = new OwnershipHistory
     //{
     //    OwnershipHistoryID = Guid.NewGuid(),
     //    Aircraft = aircraft,
     //    Owner = service.CurrentAirlines,
     //    StartDate = DateTime.Now,
     //    Status = (int)OpStatus.Draft,
     //};
     //service.EntityContainer.GetEntitySet<OwnershipHistory>().Add(ownership);
     //return ownership;
     return null;
 }
Exemple #7
0
 /// <summary>
 ///     完成运力增减计划
 /// </summary>
 /// <param name="planDetail">计划明细</param>
 /// <param name="aircraft">飞机</param>
 /// <param name="editAircraft">飞机</param>
 /// <returns>
 ///     <see cref="IFleetPlanService" />
 /// </returns>
 public void CompletePlan(PlanHistoryDTO planDetail, AircraftDTO aircraft, ref AircraftDTO editAircraft)
 {
     using (var pb = new FleetPlanServiceHelper())
     {
         pb.CompletePlan(planDetail, aircraft, ref editAircraft, this);
     }
 }
Exemple #8
0
 /// <summary>
 ///     创建运力增减计划明细
 /// </summary>
 /// <param name="plan">计划</param>
 /// <param name="allPlanHistories"></param>
 /// <param name="planAircraft">计划飞机</param>
 /// <param name="aircraft">计划飞机</param>
 /// <param name="actionType">活动类型</param>
 /// <param name="planType">判断是否运营\变更计划</param>
 /// <returns></returns>
 public PlanHistoryDTO CreatePlanHistory(PlanDTO plan,
     QueryableDataServiceCollectionView<PlanHistoryDTO> allPlanHistories, ref PlanAircraftDTO planAircraft,
     AircraftDTO aircraft, string actionType, int planType)
 {
     using (var pb = new FleetPlanServiceHelper())
     {
         return pb.CreatePlanHistory(plan, allPlanHistories, ref planAircraft, aircraft, actionType, planType,
             this);
     }
 }
Exemple #9
0
 /// <summary>
 ///     创建所有权历史
 /// </summary>
 /// <param name="aircraft">
 ///     <see cref="IFleetPlanService" />
 /// </param>
 /// <returns>
 ///     <see cref="IFleetPlanService" />
 /// </returns>
 public OwnershipHistoryDTO CreateNewOwnership(AircraftDTO aircraft)
 {
     using (var pb = new FleetPlanServiceHelper())
     {
         return pb.CreateNewOwnership(aircraft, this);
     }
 }
Exemple #10
0
        private void OnComplete(object obj)
        {
            _editAircraft = new AircraftDTO();
            var aircraft = new AircraftDTO();
            //获取计划明细对应的飞机,可能为空
            if (SelPlanHistory != null)
            {
                aircraft = Aircrafts.SourceCollection.Cast<AircraftDTO>().Any(pa => pa.AircraftId == SelPlanHistory.AircraftId) ? Aircrafts.SourceCollection.Cast<AircraftDTO>().FirstOrDefault(p => p.AircraftId == SelPlanHistory.AircraftId) : null;
                SelPlanHistory.CanDeliver = (int)CanDeliver.交付中;
                var planAircraft =
                    PlanAircrafts.SourceCollection.Cast<PlanAircraftDTO>()
                        .FirstOrDefault(p => p.Id == SelPlanHistory.PlanAircraftId);
                if (planAircraft != null) planAircraft.Status = (int) ManageStatus.运营;
            }
            // 调用完成计划的操作
            _service.CompletePlan(SelPlanHistory, aircraft, ref  _editAircraft);

            if (_editAircraft == null) return;
            if (Aircrafts.SourceCollection.Cast<AircraftDTO>().All(p => p != _editAircraft))
            {
                Aircrafts.AddNew(_editAircraft);
                var planAircraft = PlanAircrafts.SourceCollection.Cast<PlanAircraftDTO>().FirstOrDefault(p => p.Id == SelPlanHistory.PlanAircraftId);
                if (planAircraft != null)
                {
                    planAircraft.AircraftId = _editAircraft.AircraftId;
                }
                if(SelPlanHistory!=null)
                {
                    SelPlanHistory.AircraftId = _editAircraft.AircraftId;
                }
            }
            // 定位选中的飞机,并确保运营历史、商业数据历史刷新
            if (SelAircraft != null && SelAircraft != _editAircraft)
            {
                SelAircraft = _editAircraft;
            }
            OpenEditDialog(SelPlanHistory);
        }