Пример #1
0
        /// <summary>
        /// 月租车恢复使用
        /// </summary>
        /// <param name="cardGrantId"></param>
        /// <returns></returns>
        public static bool CarRestoreUse(string grantId)
        {
            IParkGrant factory = ParkGrantFactory.GetFactory();
            ParkGrant  grant   = factory.QueryByGrantId(grantId);

            if (grant == null)
            {
                throw new MyException("获取授权信息失败");
            }
            if (grant.State == ParkGrantState.Normal)
            {
                return(true);
            }

            ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);

            if (carType == null)
            {
                throw new MyException("获取车型类型失败");
            }

            IParkCardSuspendPlan planFactory = ParkCardSuspendPlanFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    ParkCardSuspendPlan plan       = planFactory.QueryByGrantId(grantId);
                    DateTime            newEndDate = ComputeParkGrantNewEndDate(grant, plan);
                    grant.BeginDate = grant.BeginDate == null ? DateTime.Now.Date : grant.BeginDate;
                    bool result = factory.RestoreUse(grantId, grant.BeginDate, newEndDate, dbOperator);
                    if (!result)
                    {
                        throw new MyException("恢复暂停失败");
                    }

                    result = planFactory.Delete(grantId, dbOperator);
                    if (!result)
                    {
                        throw new MyException("取消暂停计划失败");
                    }
                    dbOperator.CommitTransaction();

                    ParkGrant dbGrant = factory.QueryByGrantId(grantId);
                    if (dbGrant != null)
                    {
                        OperateLogServices.AddOperateLog <ParkGrant>(dbGrant, OperateType.Update);
                    }
                    OperateLogServices.AddOperateLog(OperateType.Update, string.Format("CarRestore.GrantID:{0}", grantId));
                    return(result);
                }
                catch (Exception ex)
                {
                    dbOperator.RollbackTransaction();
                    throw ex;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 车辆停用
        /// </summary>
        /// <param name="grantId"></param>
        /// <returns></returns>
        public static bool CarStopUse(string grantId)
        {
            IParkGrant factory = ParkGrantFactory.GetFactory();
            ParkGrant  grant   = factory.QueryByGrantId(grantId);

            if (grant == null)
            {
                throw new MyException("获取授权信息失败");
            }

            if (grant.State != ParkGrantState.Normal)
            {
                throw new MyException("状态不正确:只有正在使用状态才能停用");
            }

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                bool result = factory.Update(grantId, ParkGrantState.Stop, dbOperator);
                if (result)
                {
                    OperateLogServices.AddOperateLog(OperateType.Update, string.Format("grantId:{0},State:{1}", grantId, (int)ParkGrantState.Stop));
                }
                return(result);
            }
        }
Пример #3
0
        public static ParkGrant QueryByGrantId(string grantId)
        {
            if (grantId.IsEmpty())
            {
                throw new ArgumentNullException("grantId");
            }

            IParkGrant factory = ParkGrantFactory.GetFactory();

            return(factory.QueryByGrantId(grantId));
        }
Пример #4
0
        public static bool CancelParkGrant(string grantId)
        {
            if (grantId.IsEmpty())
            {
                throw new ArgumentNullException("grantId");
            }

            IParkGrant     factory      = ParkGrantFactory.GetFactory();
            IBaseCard      cardFactory  = BaseCardFactory.GetFactory();
            IEmployeePlate plateFactory = EmployeePlateFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    ParkGrant grant = factory.QueryByGrantId(grantId);

                    dbOperator.BeginTransaction();
                    bool result = plateFactory.Delete(grant.PlateID, dbOperator);
                    if (!result)
                    {
                        throw new MyException("删除车牌失败");
                    }

                    result = cardFactory.Delete(grant.CardID, dbOperator);
                    if (!result)
                    {
                        throw new MyException("删除卡失败");
                    }

                    result = factory.Delete(grantId, dbOperator);
                    if (!result)
                    {
                        throw new MyException("删除授权失败");
                    }
                    dbOperator.CommitTransaction();
                    if (result)
                    {
                        OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("grantId:{0}", grantId));
                    }
                    return(result);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Пример #5
0
        /// <summary>
        /// 月租车暂停使用
        /// </summary>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="grantId"></param>
        /// <returns></returns>
        public static bool CarSuspendUse(DateTime start, DateTime end, string grantId)
        {
            IParkGrant factory = ParkGrantFactory.GetFactory();
            ParkGrant  grant   = factory.QueryByGrantId(grantId);

            if (grant == null)
            {
                throw new MyException("获取授权信息失败");
            }

            if (grant.State == ParkGrantState.Stop)
            {
                throw new MyException("停止状态不能设置,如需设置请先启用");
            }
            if (grant.State == ParkGrantState.Pause)
            {
                throw new MyException("暂停状态不能设置,请先恢复使用后重新设置");
            }

            ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);

            if (carType == null)
            {
                throw new MyException("获取车型类型失败");
            }
            //if (carType.BaseTypeID != BaseCarType.MonthlyRent && carType.BaseTypeID != BaseCarType.WorkCar
            //   && carType.BaseTypeID != BaseCarType.VIPCar) throw new MyException("该车辆不能使用此功能");

            IParkCardSuspendPlan planFactory = ParkCardSuspendPlanFactory.GetFactory();

            ParkCardSuspendPlan plan = planFactory.QueryByGrantId(grantId);

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    if (plan != null)
                    {
                        if (start.Date < DateTime.Now.Date)
                        {
                            throw new MyException("开始时间不能小于系统当前时间");
                        }

                        bool result = planFactory.Update(start, end, grantId, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存暂停计划失败");
                        }

                        if (start.Date == DateTime.Now.Date)
                        {
                            result = factory.Update(grantId, ParkGrantState.Pause, dbOperator);
                            if (!result)
                            {
                                throw new MyException("修改使用状态失败");
                            }
                        }
                    }
                    else
                    {
                        if (start.Date < DateTime.Now.Date)
                        {
                            throw new MyException("开始时间不能小于系统当前时间");
                        }

                        ParkCardSuspendPlan model = new ParkCardSuspendPlan();
                        model.RecordId  = GuidGenerator.GetGuidString();
                        model.StartDate = start;
                        model.EndDate   = end;
                        model.GrantID   = grantId;
                        bool result = planFactory.Add(model, dbOperator);
                        if (!result)
                        {
                            throw new MyException("保存暂停计划失败");
                        }
                        if (start.Date == DateTime.Now.Date)
                        {
                            result = factory.Update(grantId, ParkGrantState.Pause, dbOperator);
                            if (!result)
                            {
                                throw new MyException("修改使用状态失败");
                            }
                        }
                    }
                    dbOperator.CommitTransaction();
                    string endDate = end == DateTime.MinValue ? end.ToString("yyyy-MM-dd") : string.Empty;
                    OperateLogServices.AddOperateLog(OperateType.Update, string.Format("grantId:{0},startDate:{1},endDate:{2}", grantId, start.ToString("yyyy-MM-dd"), endDate));
                    return(true);
                }
                catch (Exception ex)
                {
                    dbOperator.RollbackTransaction();
                    throw ex;
                }
            }
        }