Пример #1
0
 /// <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;
             }
         }
     }
 }
Пример #2
0
        /// <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;
                        }
                    }
                );
        }
Пример #3
0
 /// <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;
     }
 }