/// <summary>
 /// 同步计划的运营历史操作
 /// </summary>
 /// <param name="StartDate">开始时间</param>
 /// <param name="planHistoryID">计划明细ID</param>
 /// <param name="tag">标志</param>
 /// <param name="dbContext">域上下文</param>
 public static void SyncOperationHistroy(FleetEntities dbContext, Guid planHistoryID, OperationType tag)
 {
     //当前计划历史
     var currentPlanHisotry = dbContext.PlanHistories.FirstOrDefault(p => p.PlanHistoryID == planHistoryID);
     if (currentPlanHisotry == null || currentPlanHisotry.ApprovalHistoryID == null) return;
     //运行日期
     DateTime? StartDate = GetOperationDateByApprovalHistory(currentPlanHisotry.ApprovalHistoryID, dbContext);
     if (StartDate == null) return;
     //当前有效的年度
     var currentOpenAnnual = (from t in dbContext.Plans.Include("Annuals")
                              from r in dbContext.PlanHistories
                              where
                                  t.PlanID == r.PlanID &&
                                  r.PlanHistoryID == currentPlanHisotry.PlanHistoryID
                              select t.Annual).FirstOrDefault();
     if (currentOpenAnnual == null) return;
     switch (tag)
     {
         case OperationType.OperationLastYearPlan:
             SynOperationLastYearPlan(dbContext, currentPlanHisotry, (DateTime)StartDate, currentOpenAnnual);
             break;
         case OperationType.OperationNextYearPlan:
             SynOperationNextYearPlan(dbContext, currentPlanHisotry, currentOpenAnnual);
             break;
         default:
             break;
     }
 }
Exemple #2
0
 private static BaseMailAccount InitAccountSetting(Guid account, FleetEntities fe)
 {
     if (fe != null && fe.MailAddresses.Any(p => p.OwnerID == account))
     {
         var addr = fe.MailAddresses.FirstOrDefault(p => p.OwnerID == account);
         return InitAccountSetting(addr);
     }
     return InitAccountSetting(null);
 }
Exemple #3
0
 public XmlConfigService(string conn)
 {
     _service = new FleetEntities(conn);
     _XmlConfigCollection = new List<object>();
     //载入生成所有XmlConfig的所有相关数据
     this.GetAllRelativeData();
     //注册所有XmlConfig类型
     this.RegisterXmlConfig();
 }
Exemple #4
0
 public XmlConfigService(FleetEntities fleetEntityes, bool isAirlines)
 {
     _IsAirlines = isAirlines;
     _service = fleetEntityes;
     _XmlConfigCollection = new List<object>();
     //载入生成所有XmlConfig的所有相关数据
     this.GetAllRelativeData();
     //注册所有XmlConfig类型
     this.RegisterXmlConfig();
 }
Exemple #5
0
 /// <summary>
 /// 清除申请明细和所有对应的计划明细之间的关系
 /// </summary>
 /// <param name="planHistoryID">需要操作计划明细ID</param>
 /// <param name="dbContext">域上下文</param>
 public static void RemoveApprovalRelation(Guid approvalHisotryID, FleetEntities dbContext)
 {
     //需要清除关系的计划明细
     var planhistories =
         dbContext.PlanHistories.Where(p => p.ApprovalHistoryID == approvalHisotryID);
        planhistories.ToList().ForEach(p =>
         {
            p.ApprovalHistoryID = null;
         });
      var currentApprovalHisotry = dbContext.ApprovalHistories.FirstOrDefault(p => p.ApprovalHistoryID ==approvalHisotryID);
      dbContext.ApprovalHistories.Remove(currentApprovalHisotry);
 }
Exemple #6
0
 /// <summary>
 /// 通过邮件发送数据文件的方法
 /// </summary>
 /// <param name="obj">发送的对象</param>
 /// <param name="mailSubject">发送邮件的主题</param>
 /// <param name="attName">附件的名称</param>
 public int SendEntity(string Conn, Guid Sender, Guid Receiver, object obj, string mailSubject, string attName)
 {
     try
     {
         FleetEntities FE = new FleetEntities(Conn);
         //接收账号
         BaseMailAccount _ReceiverAccount = MailAccountHelper.GetMailAccount(Receiver, FE);
         //发送账号
         BaseMailAccount _SenderAccount = MailAccountHelper.GetMailAccount(Sender, FE);
         //发送对象
         return SendEntity(_SenderAccount, _ReceiverAccount, obj, mailSubject, attName);
     }
     catch( Exception ex)
     {
         return -4;
     }
 }
Exemple #7
0
 /// <summary>
 /// 判断是否要发送当前所有权历史的前一条记录
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="currentOwnershipHistory"></param>
 /// <returns></returns>
 public static OwnershipHistory GetOwnershipHistory(Aircraft aircraft, OwnershipHistory currentOwnershipHistory, FleetEntities dbContext)
 {
     if (aircraft == null || aircraft.OwnershipHistorys.Count <= 1)
     {
         return null;
     }
     else
     {
         //当前飞机所有权人历史的前一条记录
         var oh = dbContext.OwnershipHistories.Where(
                 o => o.OwnershipHistoryID != currentOwnershipHistory.OwnershipHistoryID && o.AircraftID == aircraft.AircraftID).OrderByDescending(
                     o => o.StartDate).FirstOrDefault();
         if (oh != null && currentOwnershipHistory.StartDate != null)
         {
             return oh;
         }
         else
         {
             return null;
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// 判断是否要发送当前商业数据的前一条记录
        /// </summary>
        /// <param name="aircraft"></param>
        /// <param name="currentAircraftBusiness"></param>
        /// <returns></returns>
        public static AircraftBusiness GetAircraftBusiness(Aircraft aircraft, AircraftBusiness currentAircraftBusiness, FleetEntities dbContext)
        {
            if (aircraft == null || aircraft.AircraftBusinesses.Count <= 1)
            {
                return null;
            }
            else
            {
                //当前商业数据的前一条记录
                var ab = dbContext.AircraftBusinesses.Where(
                        o => o.AircraftBusinessID != currentAircraftBusiness.AircraftBusinessID && o.AircraftID == aircraft.AircraftID).OrderByDescending(
                            o => o.StartDate).FirstOrDefault();

                if (ab != null && currentAircraftBusiness.StartDate != null)
                {
                    return ab;
                }
                else
                {
                    return null;
                }
            }
        }
Exemple #9
0
 public TestData()
 {
     _FE = new FleetEntities();
 }
Exemple #10
0
 /// <summary>
 /// 通过批文历史获取运营时间
 /// </summary>
 /// <param name="ApprovalHistoryID"></param>
 /// <param name="dbContext"></param>
 /// <returns></returns>
 private static DateTime? GetOperationDateByApprovalHistory(Guid? ApprovalHistoryID, FleetEntities dbContext)
 {
     var OperationHistory = dbContext.OperationHistories.Where(p => p.OperationHistoryID == ApprovalHistoryID).FirstOrDefault();
     if (OperationHistory != null)
     {
         return OperationHistory.StartDate;
     }
     else
     {
         return null;
     }
 }
Exemple #11
0
 public static BaseMailAccount GetMailAccount(Guid account, FleetEntities fe)
 {
     return InitAccountSetting(account, fe);
 }
Exemple #12
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;
                        }
                    }
                );
        }
Exemple #13
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;
             }
         }
     }
 }
Exemple #14
0
 private bool SubmitChange(FleetEntities fe)
 {
     //保存数据
      if (_DataChanged)
     {
         try
         {
             fe.SaveChanges();
             return true;
         }
         catch(Exception ex)
         {
             UniCloud.Log.WindowsLog.Write(ex.Message);
             return false;
         }
     }
     return true;
 }
Exemple #15
0
 /// <summary>
 /// 设置前一条的商业数据的结束时间为当前商业数据的开始时间减去一天
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="currentAircraftBusiness"></param>
 public static void SetPreviousrAircraftBusiness(Aircraft aircraft, AircraftBusiness currentAircraftBusiness, FleetEntities dbContext)
 {
     if (currentAircraftBusiness != null && currentAircraftBusiness.StartDate != null)
     {
         //获取前一条商业数据
         var formerAircraftBusiness = GetAircraftBusiness(aircraft, currentAircraftBusiness, dbContext);
         if (formerAircraftBusiness == null) return;
         //设置前一条商业数据的结束时间为当前商业数据的开始时间减去一天
         formerAircraftBusiness.EndDate = currentAircraftBusiness.StartDate.Value.AddDays(-1);
     }
 }
Exemple #16
0
 /// <summary>
 /// 设置前一条的商业数据的结束时间为当前商业数据的开始时间减去一天
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="currentOperationHistory"> </param>
 public static void SetPreviousOperationHistory(Aircraft aircraft, OperationHistory currentOperationHistory, FleetEntities dbContext)
 {
     if (currentOperationHistory != null && currentOperationHistory.StartDate != null)
     {
         //获取前一条商业数据
         var formerOperationHistory = GetOperationHistory(aircraft, currentOperationHistory, dbContext);
         if (formerOperationHistory == null) return;
         //设置前一条商业数据的结束时间为当前商业数据的开始时间减去一天
         formerOperationHistory.EndDate = currentOperationHistory.StartDate.Value.AddDays(-1);
     }
 }
Exemple #17
0
 public EncodeModel(string conn)
 {
     _FE = new FleetEntities(conn);
 }
Exemple #18
0
 public MailModel()
 {
     _FE = new FleetEntities();
     _DataChanged = false;
 }
Exemple #19
0
 /// <summary>
 /// 同步申请明细到计划历史
 /// </summary>
 /// <param name="planHistoryID">需要操作计划明细ID</param>
 /// <param name="dbContext">域上下文</param>
 public static void SyncApprovalToPlanHisotry(Guid planHistoryID, FleetEntities dbContext)
 {
     //对上个年度的发布计划进行同步申请的操作
     //当前计划历史
     var currentPlanHisotry =
         dbContext.PlanHistories.FirstOrDefault(p => p.PlanHistoryID == planHistoryID);
     //当前有效的年度
     var currentOpenAnnual = (from t in dbContext.Plans.Include("Annuals")
                              from r in dbContext.PlanHistories
                              where
                                  t.PlanID == r.PlanID &&
                                  r.PlanHistoryID == currentPlanHisotry.PlanHistoryID
                              select t.Annual).FirstOrDefault();
     //上个年度有效的打开的年度
     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 && currentPlanHisotry != null)
     {
         searchPlanHistory.ApprovalHistoryID = currentPlanHisotry.ApprovalHistoryID;
     }
 }
Exemple #20
0
 public TestData(string conn)
 {
     _FE = new FleetEntities(conn);
 }
Exemple #21
0
 private static BaseMailAccount InitAccountSetting(Guid account, string conn)
 {
     var fe = new FleetEntities(conn);
     return InitAccountSetting(account, fe);
 }
Exemple #22
0
 public EncodeModel()
 {
     _FE = new FleetEntities();
 }
Exemple #23
0
 /// <summary>
 /// 设置前一条的所有权历史的结束时间为当前所有权历史的开始时间减去一天
 /// </summary>
 /// <param name="aircraft"></param>
 /// <param name="currentOwnershipHistory"></param>
 public static void SetPreviousOwershipHistory(Aircraft aircraft, OwnershipHistory currentOwnershipHistory, FleetEntities dbContext)
 {
     if (currentOwnershipHistory != null && currentOwnershipHistory.StartDate != null)
     {
         //获取前一条所有权历史
         var formerOwershipHistory = GetOwnershipHistory(aircraft, currentOwnershipHistory, dbContext);
         if (formerOwershipHistory == null) return;
         //设置前一条所有权历史的结束时间为当前所有权历史的开始时间减去一天
         formerOwershipHistory.EndDate = currentOwnershipHistory.StartDate.Value.AddDays(-1);
     }
 }