/// <summary> /// 更新计划 /// </summary> /// <param name="NewPlanHistory"></param> private void UpdatePlan(PlanHistory NewPlanHistory) { if (NewPlanHistory.PlanID != null) { Plan OriginPlan = this._FE.Plans.Where(q => q.PlanID == NewPlanHistory.PlanID).FirstOrDefault(); if (OriginPlan == null) { Plan NewPlan = new Plan(); NewPlan.PlanID = NewPlanHistory.PlanID; NewPlan.AirlinesID = NewPlanHistory.AirlinesID; if (NewPlanHistory.Annual != null) { NewPlan.AnnualID = NewPlanHistory.Annual.AnnualID; } else { Annual annual = this._FE.Annuals.Where(p => p.Year == DateTime.Today.Year).FirstOrDefault(); NewPlan.AnnualID = annual.AnnualID; } //增加计划历史 this._FE.Plans.Add(NewPlan); } } }
/// <summary> ///同步下一年度计划 /// </summary> /// <param name="dbContext"></param> /// <param name="currentPlanHisotry"></param> /// <param name="currentOpenAnnual"></param> private static void SynOperationNextYearPlan(FleetEntities dbContext, PlanHistory currentPlanHisotry, Annual currentOpenAnnual) { //找到大于当前年度的计划,补上当前计划运营历史或者商业数据 //大于当前有效计划的集合 var exceedAnnual = dbContext.Annuals.Where(p => p.Year > currentOpenAnnual.Year); //需要同步的计划历史 var searchNextPlanHistories = from t in dbContext.Plans from a in dbContext.PlanHistories from r in dbContext.PlanAircrafts from f in exceedAnnual where t.AnnualID == f.AnnualID && t.PlanID == a.PlanID && r.PlanAircraftID == a.PlanAircraftID && r.PlanAircraftID == currentPlanHisotry.PlanAircraftID select a; searchNextPlanHistories.ToList().ForEach ( f => { if (currentPlanHisotry.GetType() == typeof(OperationPlan) && f.GetType() == typeof(OperationPlan) && (f as OperationPlan).OperationHistory == null) { var operationPlan = f as OperationPlan; if (operationPlan != null) { var plan = currentPlanHisotry as OperationPlan; if (plan != null) operationPlan.OperationHistoryID = plan.OperationHistoryID; } } if (currentPlanHisotry.GetType() != typeof(ChangePlan) || f.GetType() != typeof(ChangePlan) || (f as ChangePlan).AircraftBusiness != null) return; var changePlan = f as ChangePlan; if (changePlan != null) { var plan = currentPlanHisotry as ChangePlan; if (plan != null) changePlan.AircraftBusinessID = plan.AircraftBusinessID; } } ); }
/// <summary> /// 同步上一年度计划 /// </summary> /// <param name="dbContext"></param> /// <param name="currentPlanHisotry"></param> /// <param name="StartDate"></param> /// <param name="currentOpenAnnual"></param> private static void SynOperationLastYearPlan(FleetEntities dbContext, PlanHistory currentPlanHisotry, DateTime StartDate, Annual currentOpenAnnual) { //找到上个年度的有效计划,补上当前计划运营历史或者商业数据 //上个年度有效的打开的年度 var lastOpenAnnual = dbContext.Annuals.FirstOrDefault(p => p.Year == currentOpenAnnual.Year - 1); //需要同步的计划历史 var needSyncPlanHisotry = from t in dbContext.Plans from a in dbContext.PlanHistories from r in dbContext.PlanAircrafts where t.IsValid == true && t.AnnualID == lastOpenAnnual.AnnualID && t.PlanID == a.PlanID && r.PlanAircraftID == a.PlanAircraftID && r.PlanAircraftID == currentPlanHisotry.PlanAircraftID select a; var searchPlanHistory = needSyncPlanHisotry.FirstOrDefault(); if (searchPlanHistory != null) { //如果运营日期在上一执行年度,则需要反向同步 if (lastOpenAnnual != null && StartDate.Year <= lastOpenAnnual.Year) { if (currentPlanHisotry != null && (currentPlanHisotry.GetType() == typeof(OperationPlan) && searchPlanHistory.GetType() == typeof(OperationPlan) && (searchPlanHistory as OperationPlan).OperationHistory == null)) { var operationPlan = searchPlanHistory as OperationPlan; if (operationPlan != null) operationPlan.OperationHistoryID = (currentPlanHisotry as OperationPlan).OperationHistoryID; } if (currentPlanHisotry.GetType() == typeof(ChangePlan) && searchPlanHistory.GetType() == typeof(ChangePlan) && (searchPlanHistory as ChangePlan).AircraftBusiness == null) { var changePlan = searchPlanHistory as ChangePlan; if (changePlan != null) changePlan.AircraftBusinessID = (currentPlanHisotry as ChangePlan).AircraftBusinessID; } } else //如果不需要反向同步的需要,要将可能由于运营时间得改动,有做过反向同步的给取消掉 { if (currentPlanHisotry.GetType() == typeof(OperationPlan) && searchPlanHistory.GetType() == typeof(OperationPlan) && (searchPlanHistory as OperationPlan).OperationHistory != null) { var operationPlan = searchPlanHistory as OperationPlan; if (operationPlan != null) operationPlan.OperationHistoryID = null; } if (currentPlanHisotry.GetType() == typeof(ChangePlan) && searchPlanHistory.GetType() == typeof(ChangePlan) && (searchPlanHistory as ChangePlan).AircraftBusiness != null) { var changePlan = searchPlanHistory as ChangePlan; if (changePlan != null) changePlan.AircraftBusinessID = null; } } } }
/// <summary> /// 创建新的运营历史 /// </summary> /// <param name="approvalHistory">批文明细</param> /// <param name="aircraft">飞机</param> /// <param name="service"></param> private static void CreateOperationHistory(PlanHistory planDetail, Aircraft aircraft, IFleetService service) { var operationHistory = new OperationHistory { ApprovalHistory = planDetail.ApprovalHistory, Airlines = service.CurrentAirlines, Aircraft = aircraft, ImportCategory = planDetail.ApprovalHistory.ImportCategory, Status = (int)OpStatus.Draft, }; if (planDetail is OperationPlan) (planDetail as OperationPlan).OperationHistory = operationHistory; service.EntityContainer.GetEntitySet<OperationHistory>().Add(operationHistory); // 更改运营历史状态 operationHistory.Status = (int)OpStatus.Draft; }
/// <summary> /// 创建新的商业数据历史 /// </summary> /// <param name="aircraft">飞机</param> /// <param name="service"></param> private static void CreateAircraftBusiness(PlanHistory planDetail, Aircraft aircraft, IFleetService service) { var aircraftBusiness = new AircraftBusiness { AircraftBusinessID = Guid.NewGuid(), Aircraft = aircraft, AircraftType = aircraft.AircraftType, ImportCategory = aircraft.ImportCategory, SeatingCapacity = aircraft.SeatingCapacity, CarryingCapacity = aircraft.CarryingCapacity, Status = (int)OpStatus.Draft, }; if (planDetail is ChangePlan) (planDetail as ChangePlan).AircraftBusiness = aircraftBusiness; service.EntityContainer.GetEntitySet<AircraftBusiness>().Add(aircraftBusiness); // 更改商业数据历史状态 aircraftBusiness.Status = (int)OpStatus.Draft; }
/// <summary> /// 创建新飞机 /// </summary> /// <param name="planDetail">计划明细</param> /// <param name="service"></param> private static void CreateAircraft(PlanHistory planDetail, IFleetService service) { var aircraft = new Aircraft { AircraftID = Guid.NewGuid(), AircraftType = planDetail.PlanAircraft.AircraftType, Airlines = service.CurrentAirlines, CreateDate = DateTime.Now, IsOperation = true, SeatingCapacity = planDetail.SeatingCapacity, CarryingCapacity = planDetail.CarryingCapacity, }; planDetail.PlanAircraft.Aircraft = aircraft; service.EntityContainer.GetEntitySet<Aircraft>().Add(aircraft); CreateOperationHistory(planDetail, aircraft, service); CreateAircraftBusiness(planDetail, aircraft, service); }
/// <summary> /// 移除计划明细项 /// </summary> /// <param name="planDetail"></param> /// <param name="service"></param> internal void RemovePlanDetail(PlanHistory planDetail, IFleetService service) { if (planDetail != null) { // 获取计划飞机 var planAircraft = planDetail.PlanAircraft; // 获取计划飞机的明细项集合 var planAircraftHistories = planAircraft.PlanHistories; // 获取计划飞机在当前计划中的明细项集合 var planDetails = planAircraft.PlanHistories.Where(ph => ph.Plan == service.CurrentPlan).ToList(); // 1、已有飞机(只有变更与退出计划) if (planAircraft.Aircraft != null) { // 1.1、计划飞机在当前计划中只有一条明细项 if (planDetails.Count == 1) planAircraft.Status = (int)ManageStatus.Operation; // 1.2、计划飞机在当前计划中超过一条明细项,即一条变更、一条退出 else { // 移除的是变更计划,计划飞机改为运营状态(可能之前也是运营状态) if (planDetail.ActionType == "变更") planAircraft.Status = (int)ManageStatus.Operation; // 移除的是退出计划,不做任何改变 } } // 2、没有飞机(只有引进与退出计划) // 2.1、计划飞机相关的明细项数量为1 // 删除相关计划飞机。 else if (planAircraftHistories.Count == 1) { service.EntityContainer.GetEntitySet<PlanAircraft>().Remove(planAircraft); } // 2.2、计划飞机相关的计划历史数量不为1(即超过1) // 2.2.1、计划飞机在当前计划中只有一条明细项 // 计划飞机的管理状态改为预备 else if (planDetails.Count == 1) { planAircraft.Status = (int)ManageStatus.Prepare; } // 2.2.2、计划飞机在当前计划中超过一条明细项,即一条引进、一条退出 // 不改变计划飞机状态 service.EntityContainer.GetEntitySet<PlanHistory>().Remove(planDetail); } }
/// <summary> /// 同步计划的运营历史操作 /// </summary> /// <param name="planHistory">当前计划</param> /// <param name="tag"></param> public void SyncOperationHistroy(DateTime startDate, PlanHistory planHistory, OperationType tag) { switch (tag) { case OperationType.OperationLastYearPlan: //找到上个年度的计划,补上当前计划运营历史或者商业数据 var searchPlanHistory = planHistory.PlanAircraft.PlanHistories .Where(p => p.Plan.Annual.Year == planHistory.Plan.Annual.Year - 1 && p.PlanAircraft == planHistory.PlanAircraft).FirstOrDefault(); if (searchPlanHistory != null) { //如果运营日期在上一执行年度,则需要反向同步 if (startDate.Year <= planHistory.Plan.Annual.Year - 1) { if (planHistory.GetType() == typeof(OperationPlan) && searchPlanHistory.GetType() == typeof(OperationPlan) && (searchPlanHistory as OperationPlan).OperationHistory == null) { (searchPlanHistory as OperationPlan).OperationHistoryID = (planHistory as OperationPlan).OperationHistoryID; } if (planHistory.GetType() == typeof(ChangePlan) && searchPlanHistory.GetType() == typeof(ChangePlan) && (searchPlanHistory as ChangePlan).AircraftBusiness == null) { (searchPlanHistory as ChangePlan).AircraftBusinessID = (planHistory as ChangePlan).AircraftBusinessID; } } else //如果不需要反向同步的需要,要将可能由于运营时间得改动,有做过反向同步的给取消掉 { if (planHistory.GetType() == typeof(OperationPlan) && searchPlanHistory.GetType() == typeof(OperationPlan) && (searchPlanHistory as OperationPlan).OperationHistory != null) { (searchPlanHistory as OperationPlan).OperationHistoryID = null; } if (planHistory.GetType() == typeof(ChangePlan) && searchPlanHistory.GetType() == typeof(ChangePlan) && (searchPlanHistory as ChangePlan).AircraftBusiness != null) { (searchPlanHistory as ChangePlan).AircraftBusinessID = null; } } } break; case OperationType.OperationNextYearPlan: //找到大于当前年度的计划,补上当前计划运营历史或者商业数据 var searchNextPlanHistories = planHistory.PlanAircraft.PlanHistories .Where(p => p.Plan.Annual.Year > planHistory.Plan.Annual.Year && p.PlanAircraft == planHistory.PlanAircraft); if (searchNextPlanHistories.Any()) { searchNextPlanHistories.ToList().ForEach ( f => { if (planHistory.GetType() == typeof(OperationPlan) && f.GetType() == typeof(OperationPlan) && (f as OperationPlan).OperationHistory == null) { (f as OperationPlan).OperationHistoryID = (planHistory as OperationPlan).OperationHistoryID; } if (planHistory.GetType() == typeof(ChangePlan) && f.GetType() == typeof(ChangePlan) && (f as ChangePlan).AircraftBusiness == null) { (f as ChangePlan).AircraftBusinessID = (planHistory as ChangePlan).AircraftBusinessID; } } ); } break; default: break; } }
/// <summary> /// 创建新申请明细 /// </summary> /// <param name="request"></param> /// <param name="planHistory"></param> /// <param name="service"></param> /// <returns></returns> internal ApprovalHistory CreateNewRequestDetail(Request request, PlanHistory planHistory, IFleetService service) { // 创建新的申请明细 var requestDetail = new ApprovalHistory { ApprovalHistoryID = Guid.NewGuid(), Request = request, PlanAircraft = planHistory.PlanAircraft, ImportCategory = planHistory.TargetCategory, Airlines = planHistory.Airlines, Annual = planHistory.Annual, RequestDeliverMonth = planHistory.PerformMonth, SeatingCapacity = planHistory.SeatingCapacity, CarryingCapacity = planHistory.CarryingCapacity, }; // 把申请明细赋给关联的计划明细 planHistory.ApprovalHistory = requestDetail; // 计划飞机管理状态修改为申请 requestDetail.PlanAircraft.Status = (int)ManageStatus.Request; service.EntityContainer.GetEntitySet<ApprovalHistory>().Add(requestDetail); return requestDetail; }
private void ShowEditDialog(PlanHistory existDetail, PlanDetailCreateSource source) { switch (source) { case PlanDetailCreateSource.New: this.IsPlanTypeVisible = Visibility.Collapsed; this._operationPlan = this.service.CreateOperationPlan(this.CurrentPlan, this._planAircraft, "引进"); this.PlanDetail = this._operationPlan; this.IsChangeable = true; break; case PlanDetailCreateSource.PlanAircraft: this.IsPlanTypeVisible = Visibility.Collapsed; // 计划飞机已有的明细项肯定是引进计划,只能添加退出计划 this._operationPlan = this.service.CreateOperationPlan(this.CurrentPlan, this._planAircraft, existDetail != null ? "退出" : "引进"); this.PlanDetail = this._operationPlan; //这时不能修改机型和座机 this.IsChangeable = false; break; case PlanDetailCreateSource.Aircraft: this.IsPlanTypeVisible = Visibility.Visible; // 1、计划飞机已有明细项 if (existDetail != null) { // 已有的是变更计划,只能添加退出计划 if (existDetail.ActionType == "变更") { this.IsChangeEnabled = false; this.IsOperation = true; this.IsChange = false; this.OnOperation(); } // 已有的是退出计划,只能添加变更计划 else { this.IsOperationEnabled = false; this.IsOperation = false; this.IsChange = true; this.OnOperation();//生成之后,不让用户编辑,起到保存原计划历史的机型的作用,在取消时,能够用来恢复计划飞机数据 this.OnChange(); } } // 2、计划飞机没有明细项 else { this.IsChangeEnabled = true; this.IsOperationEnabled = true; if (!this.IsOperation) this.IsOperation = true; this.OnOperation(); } break; default: throw new ArgumentOutOfRangeException("source"); } this.editDialog.ShowDialog(); }
private void UpdatePlanHistoryRelativeHistory(PlanHistory NewPlanHistory) { //处理批文历史 UpdateApprovalHistoryForPlanHistory(NewPlanHistory); //处理运营计划历史 UpdateOperationHistoryForPlanHistory(NewPlanHistory); //处理变更计划历史 UpdateChangeHistoryForPlanHistory(NewPlanHistory); }
private void UpdateOperationHistoryForPlanHistory(PlanHistory NewPlanHistory) { //处理运营计划历史 if (NewPlanHistory is OperationPlan) { OperationPlan OperationPlan = NewPlanHistory as OperationPlan; if (OperationPlan.OperationHistoryID != null && !this._FE.OperationHistories.Any(p => p.OperationHistoryID == OperationPlan.OperationHistoryID)) { OperationPlan.OperationHistoryID = null; } OperationPlan.OperationHistory = null; } }
private void UpdateChangeHistoryForPlanHistory(PlanHistory NewPlanHistory) { //处理变更计划历史 if (NewPlanHistory is ChangePlan) { ChangePlan ChangePlan = NewPlanHistory as ChangePlan; if (ChangePlan.AircraftBusinessID != null && !this._FE.AircraftBusinesses.Any(p => p.AircraftBusinessID == ChangePlan.AircraftBusinessID)) { ChangePlan.AircraftBusinessID = null; } ChangePlan.AircraftBusiness = null; } }
private void UpdateApprovalHistoryForPlanHistory(PlanHistory NewPlanHistory) { //处理批文历史 if (NewPlanHistory.ApprovalHistoryID != null && !this._FE.ApprovalHistories.Any(p => p.ApprovalHistoryID == NewPlanHistory.ApprovalHistoryID)) { NewPlanHistory.ApprovalHistoryID = null; } NewPlanHistory.ApprovalHistory = null; }
private void DeletePlanHistoryRelation(PlanHistory OriginPlanHistory) { //if (OriginPlanHistory != null) //{ // //计划飞机处理 // if (OriginPlanHistory.PlanAircraftID != null) // { // } //} }
internal void AddNewRequestDetail(PlanHistory planHistory) { this.service.CreateNewRequestDetail(this.SelRequest, planHistory); this._needReFreshViewApprovalHistory = true; RaiseViewApprovalHistory(); this._needReFreshViewPlanHistory = true; RaiseViewPlanHistory(); }
/// <summary> /// 完成计划项 /// </summary> /// <param name="planDetail"></param> /// <param name="service"></param> /// <returns></returns> internal Aircraft CompletePlan(PlanHistory planDetail, IFleetService service) { Aircraft aircraft; OperationHistory operationHistory; if (planDetail == null) { throw new ArgumentNullException("planDetail"); } var actionName = planDetail.ActionCategory.ActionName; if (actionName == null) { return null; } // 根据引进方式调用不同的操作 switch (actionName) { case "购买": // 创建新飞机 CreateAircraft(planDetail, service); break; case "融资租赁": // 创建新飞机 CreateAircraft(planDetail, service); break; case "经营租赁": // 创建新飞机 CreateAircraft(planDetail, service); break; case "湿租": // 创建新飞机 CreateAircraft(planDetail, service); break; case "经营租赁续租": // 创建新运营历史 CreateOperationHistory(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "湿租续租": // 创建新运营历史 CreateOperationHistory(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "出售": // 更改运营历史状态 aircraft = planDetail.PlanAircraft.Aircraft; operationHistory = aircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null); if (operationHistory != null) { operationHistory.Status = (int)OpStatus.Draft; operationHistory.ExportCategory = service.AllActionCategories.FirstOrDefault(ac => ac.ActionName == "出售"); if (planDetail is OperationPlan) (planDetail as OperationPlan).OperationHistory = operationHistory; } break; case "出租": // 更改运营历史状态 aircraft = planDetail.PlanAircraft.Aircraft; operationHistory = aircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null); if (operationHistory != null) { operationHistory.Status = (int)OpStatus.Draft; operationHistory.ExportCategory = service.AllActionCategories.FirstOrDefault(ac => ac.ActionName == "出租"); if (planDetail is OperationPlan) (planDetail as OperationPlan).OperationHistory = operationHistory; } break; case "退租": // 更改运营历史状态 aircraft = planDetail.PlanAircraft.Aircraft; operationHistory = aircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null); if (operationHistory != null) { operationHistory.Status = (int)OpStatus.Draft; operationHistory.ExportCategory = service.AllActionCategories.FirstOrDefault(ac => ac.ActionName == "退租"); if (planDetail is OperationPlan) (planDetail as OperationPlan).OperationHistory = operationHistory; } break; case "退役": // 更改运营历史状态 aircraft = planDetail.PlanAircraft.Aircraft; operationHistory = aircraft.OperationHistories.LastOrDefault(oh => oh.EndDate == null); if (operationHistory != null) { operationHistory.Status = (int)OpStatus.Draft; operationHistory.ExportCategory = service.AllActionCategories.FirstOrDefault(ac => ac.ActionName == "退役"); if (planDetail is OperationPlan) (planDetail as OperationPlan).OperationHistory = operationHistory; } break; case "货改客": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "客改货": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "售后经营租赁": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "售后融资租赁": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "一般改装": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; case "租转购": // 创建商业数据历史 CreateAircraftBusiness(planDetail, planDetail.PlanAircraft.Aircraft, service); break; } // 更改计划飞机状态 planDetail.PlanAircraft.Status = (int)ManageStatus.Operation; // 刷新计划完成状态 RaisePropertyChanged(() => planDetail.CompleteStatus); return planDetail.PlanAircraft.Aircraft; }
/// <summary> /// 打开子窗体之前先设置好子窗体中的编辑属性 /// </summary> /// <param name="planHistory">计划明细</param> internal void OpenEditDialog(PlanHistory planHistory) { this.ShowEditDialog(); }