Example #1
0
 public bool Update(ParkGrant model)
 {
     using (DbOperator dbOperator = ConnectionManager.CreateConnection())
     {
         return(Update(model, dbOperator));
     }
 }
Example #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);
            }
        }
Example #3
0
        public List <ParkGrant> QueryByParkingAndLotAndCarType(string parkingId, string lots, BaseCarType carType, string excludeGrantId)
        {
            List <ParkGrant> models = new List <ParkGrant>();

            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                string[] strLots = lots.TrimEnd(',').Split(',');
                for (int i = 0; i < strLots.Length; i++)
                {
                    dbOperator.ClearParameters();
                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("SELECT G.* FROM ParkGrant G INNER JOIN ParkCarType P");
                    strSql.AppendFormat(" ON G.CarTypeID=P.CarTypeID WHERE g.GID!='{0}' AND G.PKID='{1}'", excludeGrantId, parkingId);
                    strSql.AppendFormat("  AND ','+G.PKLot+',' like '%,{0},%' AND P.BaseTypeID={1}", strLots[i], (int)carType);
                    strSql.AppendFormat("  AND G.DataStatus!={0} AND P.DataStatus!={0}", (int)DataStatus.Delete);

                    using (DbDataReader reader = dbOperator.ExecuteReader(strSql.ToString()))
                    {
                        while (reader.Read())
                        {
                            ParkGrant model = DataReaderToModel <ParkGrant> .ToModel(reader);

                            if (models.FirstOrDefault(p => p.GID == model.GID) == null)
                            {
                                models.Add(model);
                            }
                        }
                    }
                }
                return(models);
            }
        }
Example #4
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="grantlist"></param>
        /// <param name="Amout"></param>
        /// <param name="EndTime"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool RefundCardAmout(ParkGrant grantmodel, DateTime EndTime, ParkOrder model)
        {
            if (grantmodel == null || model == null)
            {
                throw new ArgumentNullException("models");
            }
            model.RecordID = GuidGenerator.GetGuidString();
            IParkGrant       factory = ParkGrantFactory.GetFactory();
            List <ParkGrant> list    = new List <ParkGrant>();

            if (grantmodel.PKLot == null || grantmodel.PKLot.Trim() == "")
            {
                list.Add(grantmodel);
            }
            else
            {
                string mesg = "";
                list = factory.GetCardgrantsByLot(grantmodel.PKID, grantmodel.PKLot, out mesg);
            }

            bool result = factory.RefundCardAmout(list, EndTime, model);

            if (result)
            {
                foreach (var item in list)
                {
                    OperateLogServices.AddOperateLog <ParkGrant>(item, OperateType.Update);
                }
                OperateLogServices.AddOperateLog <ParkOrder>(model, OperateType.Add);
            }
            return(result);
        }
Example #5
0
        public bool Update(ParkGrant model, DbOperator dbOperator)
        {
            model.DataStatus     = DataStatus.Normal;
            model.LastUpdateTime = DateTime.Now;
            model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ParkGrant set CardID=@CardID,PKID=@PKID,BeginDate=@BeginDate,EndDate=@EndDate,CarTypeID=@CarTypeID,CarModelID=@CarModelID,PKLot=@PKLot,");
            strSql.Append(" PlateID=@PlateID,ComdState=@ComdState,AreaIDS=@AreaIDS,GateID=@GateID,State=@State,LastUpdateTime=@LastUpdateTime,HaveUpdate=@HaveUpdate");
            strSql.Append(" where GID=@GID");
            dbOperator.ClearParameters();
            dbOperator.AddParameter("GID", model.GID);
            dbOperator.AddParameter("CardID", model.CardID);
            dbOperator.AddParameter("PKID", model.PKID);
            dbOperator.AddParameter("BeginDate", model.BeginDate);
            dbOperator.AddParameter("EndDate", model.EndDate);
            dbOperator.AddParameter("CarTypeID", model.CarTypeID);
            dbOperator.AddParameter("CarModelID", model.CarModelID);
            dbOperator.AddParameter("PKLot", model.PKLot);
            dbOperator.AddParameter("PlateID", model.PlateID);
            dbOperator.AddParameter("ComdState", (int)model.ComdState);
            dbOperator.AddParameter("AreaIDS", model.AreaIDS);
            dbOperator.AddParameter("GateID", model.GateID);
            dbOperator.AddParameter("State", (int)model.State);
            dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
            dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
            return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
        }
Example #6
0
        public bool Add(ParkGrant model, DbOperator dbOperator)
        {
            model.DataStatus     = DataStatus.Normal;
            model.LastUpdateTime = DateTime.Now;
            model.HaveUpdate     = SystemDefaultConfig.DataUpdateFlag;

            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ParkGrant(GID,CardID,PKID,BeginDate,EndDate,CarTypeID,CarModelID,PKLot,PlateID,ComdState,AreaIDS,GateID,State,LastUpdateTime,HaveUpdate,DataStatus)");
            strSql.Append(" values(@GID,@CardID,@PKID,@BeginDate,@EndDate,@CarTypeID,@CarModelID,@PKLot,@PlateID,@ComdState,@AreaIDS,@GateID,@State,@LastUpdateTime,@HaveUpdate,@DataStatus)");
            dbOperator.ClearParameters();
            dbOperator.AddParameter("GID", model.GID);
            dbOperator.AddParameter("CardID", model.CardID);
            dbOperator.AddParameter("PKID", model.PKID);
            dbOperator.AddParameter("BeginDate", model.BeginDate);
            dbOperator.AddParameter("EndDate", model.EndDate);
            dbOperator.AddParameter("CarTypeID", model.CarTypeID);
            dbOperator.AddParameter("CarModelID", model.CarModelID);
            dbOperator.AddParameter("PKLot", model.PKLot);
            dbOperator.AddParameter("PlateID", model.PlateID);
            dbOperator.AddParameter("ComdState", (int)model.ComdState);
            dbOperator.AddParameter("AreaIDS", model.AreaIDS);
            dbOperator.AddParameter("GateID", model.GateID);
            dbOperator.AddParameter("State", (int)model.State);
            dbOperator.AddParameter("LastUpdateTime", model.LastUpdateTime);
            dbOperator.AddParameter("HaveUpdate", model.HaveUpdate);
            dbOperator.AddParameter("DataStatus", (int)model.DataStatus);
            return(dbOperator.ExecuteNonQuery(strSql.ToString()) > 0);
        }
Example #7
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;
                }
            }
        }
Example #8
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;
                }
            }
        }
Example #9
0
        public static bool Add(ParkGrant model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            model.GID = GuidGenerator.GetGuidString();
            IParkGrant factory = ParkGrantFactory.GetFactory();
            bool       result  = factory.Add(model);

            if (result)
            {
                OperateLogServices.AddOperateLog <ParkGrant>(model, OperateType.Add);
            }
            return(result);
        }
Example #10
0
        public static bool Update(ParkGrant model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (model.GID.IsEmpty())
            {
                throw new ArgumentNullException("GID");
            }

            IParkGrant factory = ParkGrantFactory.GetFactory();
            bool       result  = factory.Update(model);

            if (result)
            {
                OperateLogServices.AddOperateLog <ParkGrant>(model, OperateType.Update);
            }
            return(result);
        }
Example #11
0
        public static ParkGrant GenerateParkGrantModel(string PKID, EmployeePlate plate, BaseCard card, string pkLot, string carModelId, string carTypeId, string AreaIDS, string GateID)
        {
            ParkGrant model = new ParkGrant();

            model.PKID     = PKID;
            model.CardID   = card.CardID;
            model.PlateID  = plate.PlateID;
            model.PlateNo  = plate.PlateNo;
            model.PKLot    = pkLot;
            model.PKLotNum = 0;

            ParkCarModel carModel = ParkCarModelServices.QueryByRecordId(carModelId);

            if (carModel == null)
            {
                throw new MyException("选择的车型不存在");
            }
            model.CarModelID = carModel.CarModelID;

            ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(carTypeId);

            if (carType == null)
            {
                throw new MyException("选择的车类不存在");
            }
            model.CarTypeID = carType.CarTypeID;

            if (string.IsNullOrWhiteSpace(AreaIDS))
            {
                throw new MyException("获取选择的车场区域失败");
            }
            model.AreaIDS = AreaIDS == "-1" ? string.Empty : AreaIDS;

            if (string.IsNullOrWhiteSpace(GateID))
            {
                throw new MyException("获取选择的车场通道失败");
            }
            model.GateID = GateID == "-1" ? string.Empty : GateID;
            return(model);
        }
Example #12
0
        private static DateTime ComputeParkGrantNewEndDate(ParkGrant grant, ParkCardSuspendPlan plan)
        {
            int suspendDays = (DateTime.Now - plan.StartDate).Days;

            if (suspendDays <= 0)
            {
                if (grant.EndDate == null)
                {
                    return(DateTime.Now);
                }
                else
                {
                    return(grant.EndDate);
                }
            }

            if (grant.EndDate.Date < DateTime.Now.Date)
            {
                return(DateTime.Now.Date.AddDays(suspendDays));
            }
            return(grant.EndDate.Date.AddDays(suspendDays));
        }
Example #13
0
        /// <summary>
        /// 续期或续费
        /// </summary>
        /// <param name="grantId"></param>
        /// <param name="renewalMonth"></param>
        /// <param name="payTotalMoney"></param>
        /// <param name="operatorId"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <returns></returns>
        public static bool RenewalsOrRecharge(string grantId, int renewalMonth, decimal payTotalMoney, string operatorId, DateTime startDate, DateTime endDate)
        {
            lock (parkGrant_lock)
            {
                ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId);
                if (grant == null)
                {
                    throw new MyException("获取授权信息失败");
                }

                if (endDate != null && endDate != DateTime.MinValue)
                {
                    endDate = endDate.Date.AddDays(1).AddSeconds(-1);
                }
                string   errorMsg = string.Empty;
                BaseCard card     = BaseCardServices.GetBaseCard(grant.CardID, out errorMsg);
                if (card == null || !string.IsNullOrWhiteSpace(errorMsg))
                {
                    throw new MyException("获取卡失败");
                }

                ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);
                if (carType == null)
                {
                    throw new MyException("获取卡类失败");
                }

                List <ParkGrant> operateTargets = new List <ParkGrant>();
                List <string>    ioRecords      = new List <string>();

                using (DbOperator dbOperator = ConnectionManager.CreateConnection())
                {
                    try
                    {
                        bool renewalsResult = false;
                        dbOperator.BeginTransaction();
                        switch (carType.BaseTypeID)
                        {
                        case BaseCarType.StoredValueCar:
                        {
                            IBaseCard factory = BaseCardFactory.GetFactory();
                            if (payTotalMoney > 0)
                            {
                                ParkOrder order = ParkOrderServices.AddStoredValueCarOrder(grant.PKID, payTotalMoney, card, operatorId, dbOperator);
                                if (order == null)
                                {
                                    throw new MyException("创建充值订单失败");
                                }

                                decimal cardtotalmoney = card.Balance + payTotalMoney;
                                if (order.NewMoney != cardtotalmoney)
                                {
                                    throw new MyException("充值金额计算错误");
                                }
                                renewalsResult = factory.Recharge(card.CardID, payTotalMoney, dbOperator);
                                if (!renewalsResult)
                                {
                                    throw new MyException("卡充值失败【更改卡余额失败】");
                                }
                            }
                            renewalsResult = factory.SetEndDate(card.CardID, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("卡充值失败【更改有效期失败】");
                            }
                            break;
                        }

                        case BaseCarType.VIPCar:
                        {
                            ParkOrder order = ParkOrderServices.AddVipCardOrder(grant.PKID, grantId, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, operatorId, dbOperator);
                            if (order == null)
                            {
                                throw new MyException("充值失败【创建充值订单失败】");
                            }

                            IParkGrant factory = ParkGrantFactory.GetFactory();
                            renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("修改车辆有效期失败");
                            }
                            break;
                        }

                        case BaseCarType.MonthlyRent:
                        {
                            int pkLotQuantity = 1;
                            if (!string.IsNullOrWhiteSpace(grant.PKLot))
                            {
                                pkLotQuantity = grant.PKLot.TrimEnd(',').Split(',').Length;
                            }
                            decimal amount = ParkOrderServices.CalculateMonthlyRentExpiredWaitPayAmount(startDate, grantId);

                            //if (payTotalMoney != ((carType.Amount * renewalMonth * pkLotQuantity) + amount))
                            //    throw new MyException("凭证续期金额计算有误");



                            List <ParkGrant> shareCardGrants = new List <ParkGrant>();
                            if (!string.IsNullOrWhiteSpace(grant.PKLot))
                            {
                                shareCardGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID);
                            }
                            IParkGrant factory = ParkGrantFactory.GetFactory();
                            renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                            if (!renewalsResult)
                            {
                                throw new MyException("修改车辆有效期失败");
                            }


                            //修改多车多位的有效期
                            foreach (var item in shareCardGrants)
                            {
                                if (string.IsNullOrWhiteSpace(item.PKLot))
                                {
                                    continue;
                                }

                                int len1 = item.PKLot.TrimEnd(',').Split(',').Length;
                                int len2 = grant.PKLot.TrimEnd(',').Split(',').Length;
                                if (len1 != len2)
                                {
                                    continue;
                                }

                                item.BeginDate = startDate;
                                item.EndDate   = endDate;
                                factory.Update(item, dbOperator);
                                operateTargets.Add(item);
                            }
                            //过期转临停订单处理
                            if (grant.EndDate.Date < DateTime.Now.Date)
                            {
                                List <string> plateNos = new List <string>();
                                EmployeePlate plate    = EmployeePlateServices.Query(grant.PlateID);
                                if (plate == null)
                                {
                                    throw new MyException("授权车牌信息不存在");
                                }

                                plateNos.Add(plate.PlateNo);

                                foreach (var item in shareCardGrants)
                                {
                                    if (string.IsNullOrWhiteSpace(item.PKLot))
                                    {
                                        continue;
                                    }

                                    int len1 = item.PKLot.TrimEnd(',').Split(',').Length;
                                    int len2 = grant.PKLot.TrimEnd(',').Split(',').Length;
                                    if (len1 != len2)
                                    {
                                        continue;
                                    }

                                    EmployeePlate otherplate = EmployeePlateServices.Query(item.PlateID);
                                    if (otherplate == null)
                                    {
                                        throw new MyException("多车多位存在无效的车牌");
                                    }
                                    plateNos.Add(otherplate.PlateNo);
                                }

                                if (plateNos.Count > 0 && grant.EndDate != DateTime.MinValue)
                                {
                                    IParkIORecord ioRecord = ParkIORecordFactory.GetFactory();
                                    ioRecords = ioRecord.QueryMonthExpiredNotPayAmountIORecordIds(grant.EndDate.AddDays(1).Date, startDate, grant.PKID, plateNos);
                                    if (ioRecords.Count > 0)
                                    {
                                        bool result = ioRecord.UpdateIORecordEnterType(ioRecords, 0, dbOperator);
                                        if (!result)
                                        {
                                            throw new MyException("修改进出记录类型失败");
                                        }
                                        result = ParkOrderServices.AddExpiredToProStopOrder(ioRecords, operatorId, dbOperator);
                                        if (!result)
                                        {
                                            throw new MyException("创建月卡转临停订单失败");
                                        }
                                    }
                                }
                            }
                            ParkOrder order = ParkOrderServices.AddMonthlyRentOrderCS(grant.PKID, carType.CarTypeID, grant.GID, grant.BeginDate, grant.EndDate, startDate, endDate, renewalMonth, pkLotQuantity, operatorId, payTotalMoney, dbOperator);
                            if (order == null)
                            {
                                throw new MyException("续期失败【创建续期订单失败】");
                            }
                            break;
                        }

                        //case BaseCarType.WorkCar:
                        //    {
                        //        IParkGrant factory = ParkGrantFactory.GetFactory();
                        //        renewalsResult = factory.Renewals(grant.GID, startDate, endDate, dbOperator);
                        //        if (!renewalsResult) throw new MyException("修改卡结束时间错误");
                        //        break;
                        //    }
                        default: throw new MyException("选择的车辆不能续期和充值");
                        }
                        dbOperator.CommitTransaction();

                        string remark = string.Format("grantId:{0};renewalMonth:{1};payTotalMoney:{2};operatorId:{3};startDate:{4};endDate:{5}", grantId, renewalMonth, payTotalMoney, operatorId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
                        OperateLogServices.AddOperateLog(OperateType.Update, remark);
                        if (ioRecords.Count > 0)
                        {
                            string updateIORecord = string.Format("修改IORecord表,RecordIDs:{0},EnterType:0", string.Join(",", ioRecords));
                            OperateLogServices.AddOperateLog(OperateType.Update, updateIORecord);
                        }
                        return(renewalsResult);
                    }
                    catch (Exception ex)
                    {
                        dbOperator.RollbackTransaction();
                        throw ex;
                    }
                }
            }
        }
Example #14
0
        private static bool AddOrderUpdateParkGrant(ParkGrant parkGrant, DbOperator dbOperator)
        {
            IParkGrant grantFactory = ParkGrantFactory.GetFactory();
            ParkGrant  oldGrant     = grantFactory.QueryByCardIdAndParkingId(parkGrant.CardID, parkGrant.PKID);

            if (oldGrant != null)
            {
                parkGrant.GID = oldGrant.GID;

                parkGrant.BeginDate = oldGrant.BeginDate;

                parkGrant.EndDate = oldGrant.EndDate;
            }
            else
            {
                parkGrant.GID = GuidGenerator.GetGuidString();
            }
            //检查车位号是否有效
            if (!string.IsNullOrWhiteSpace(parkGrant.PKLot))
            {
                List <ParkGrant> oldGrants = grantFactory.QueryByParkingAndLotAndCarType(parkGrant.PKID, parkGrant.PKLot, BaseCarType.MonthlyRent, parkGrant.GID);
                foreach (var item in oldGrants)
                {
                    int oldLotLen = item.PKLot.Split(',').Length;
                    int newLotLen = parkGrant.PKLot.Split(',').Length;
                    if (oldLotLen != newLotLen)
                    {
                        throw new MyException(string.Format("车位号无效:车位号[{0}]与已存在的车位号[{1}]不完全一致", parkGrant.PKLot, item.PKLot));
                    }
                    parkGrant.BeginDate = item.BeginDate;
                    parkGrant.EndDate   = item.EndDate;
                }
            }
            //临停转月卡 并且车位号存在完全一致的情况 给开始日期和结束日期赋值
            if (oldGrant != null && !string.IsNullOrWhiteSpace(parkGrant.PKLot))
            {
                ParkCarType newCarType = ParkCarTypeServices.QueryParkCarTypeByRecordId(parkGrant.CarTypeID);
                ParkCarType oldCarType = ParkCarTypeServices.QueryParkCarTypeByRecordId(oldGrant.CarTypeID);
                if (newCarType == null || oldCarType == null)
                {
                    throw new MyException("车类不存在");
                }

                if (newCarType.BaseTypeID == BaseCarType.MonthlyRent && oldCarType.BaseTypeID == BaseCarType.TempCar)
                {
                    List <ParkGrant> oldGrants = grantFactory.QueryByParkingAndLotAndCarType(parkGrant.PKID, parkGrant.PKLot, BaseCarType.MonthlyRent, parkGrant.GID);
                    foreach (var item in oldGrants)
                    {
                        int oldLotLen = item.PKLot.Split(',').Length;
                        int newLotLen = parkGrant.PKLot.Split(',').Length;
                        if (oldLotLen == newLotLen)
                        {
                            parkGrant.BeginDate = item.BeginDate;
                            parkGrant.EndDate   = item.EndDate;
                            break;
                        }
                    }
                }
            }
            if (oldGrant != null)
            {
                return(grantFactory.Update(parkGrant, dbOperator));
            }
            else
            {
                return(grantFactory.Add(parkGrant, dbOperator));
            }
        }
Example #15
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;
                }
            }
        }
Example #16
0
        /// <summary>
        /// 审核通过
        /// </summary>
        /// <param name="recordId"></param>
        /// <returns></returns>
        public static bool Passed(string RecordID, string AuditRemark, string CarTypeID, string CarModelID, string AreaIDS, string GateID, string OperatorId)
        {
            if (string.IsNullOrWhiteSpace(CarTypeID))
            {
                throw new MyException("获取车类失败");
            }
            if (string.IsNullOrWhiteSpace(CarModelID))
            {
                throw new MyException("获取车型失败");
            }

            ParkMonthlyCarApply monthlyCarApply = ParkMonthlyCarApplyServices.QueryByRecordID(RecordID);

            if (monthlyCarApply == null)
            {
                throw new MyException("该申请不存在");
            }
            if (monthlyCarApply.ApplyStatus != MonthlyCarApplyStatus.Applying)
            {
                throw new MyException("该申请是申请中状态");
            }
            monthlyCarApply.CarModelID  = CarModelID;
            monthlyCarApply.CarTypeID   = CarTypeID;
            monthlyCarApply.AuditRemark = AuditRemark;

            BaseParkinfo parking = ParkingServices.QueryParkingByParkingID(monthlyCarApply.PKID);

            if (parking == null)
            {
                throw new MyException("车场信息不存在");
            }

            BaseEmployee  employee  = GenerateBaseEmployeeModel(parking.VID, monthlyCarApply.ApplyName, monthlyCarApply.ApplyMoblie, monthlyCarApply.FamilyAddress);
            EmployeePlate plate     = GenerateEmployeePlateModel(employee, parking.VID, monthlyCarApply.PlateNo);
            BaseCard      card      = GenerateCardModel(parking, employee, plate, OperatorId);
            ParkGrant     parkGrant = GenerateParkGrantModel(parking, plate, card, monthlyCarApply.PKLot, monthlyCarApply.CarModelID, monthlyCarApply.CarTypeID, AreaIDS, GateID);

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = ParkGrantServices.Add(employee, plate, card, parkGrant, dbOperator);
                    if (!result)
                    {
                        throw new MyException("保存车辆信息失败");
                    }

                    IParkMonthlyCarApply factory = ParkMonthlyCarApplyFactory.GetFactory();
                    result = factory.Passed(monthlyCarApply, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改申请状态失败");
                    }

                    dbOperator.CommitTransaction();
                    monthlyCarApply = ParkMonthlyCarApplyServices.QueryByRecordID(monthlyCarApply.RecordID);
                    OperateLogServices.AddOperateLog <ParkMonthlyCarApply>(monthlyCarApply, OperateType.Update);
                    return(result);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }
Example #17
0
 public static bool Add(BaseEmployee employee, EmployeePlate plate, BaseCard card, ParkGrant parkGrant)
 {
     using (DbOperator dbOperator = ConnectionManager.CreateConnection())
     {
         try
         {
             dbOperator.BeginTransaction();
             bool result = Add(employee, plate, card, parkGrant, dbOperator);
             if (!result)
             {
                 throw new MyException("保存车辆信息失败");
             }
             dbOperator.CommitTransaction();
             return(result);
         }
         catch
         {
             dbOperator.RollbackTransaction();
             throw;
         }
     }
 }
Example #18
0
        public static decimal CalculateMonthlyRentExpiredWaitPayAmount(DateTime start, string grantId)
        {
            ParkGrant grant = ParkGrantServices.QueryByGrantId(grantId);

            if (grant == null)
            {
                throw new MyException("获取授权失败");
            }
            if (grant.BeginDate == DateTime.MinValue || grant.EndDate == DateTime.MinValue || (grant.EndDate != DateTime.MinValue && grant.EndDate.Date >= DateTime.Now.Date))
            {
                return(0);
            }
            ParkCarType carType = ParkCarTypeServices.QueryParkCarTypeByRecordId(grant.CarTypeID);

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

            if (carType.BaseTypeID != BaseCarType.MonthlyRent)
            {
                return(0);
            }

            DateTime startDate = grant.EndDate.AddDays(1).Date;
            DateTime endDate   = start.Date;

            List <string> plateNos = new List <string>();
            EmployeePlate plate    = EmployeePlateServices.Query(grant.PlateID);

            if (plate == null)
            {
                throw new MyException("获取车牌号失败");
            }

            plateNos.Add(plate.PlateNo);

            if (!string.IsNullOrWhiteSpace(grant.PKLot))
            {
                List <ParkGrant> sameGrants = ParkGrantServices.QueryByParkingAndLotAndCarType(grant.PKID, grant.PKLot, BaseCarType.MonthlyRent, grant.GID);
                foreach (var item in sameGrants)
                {
                    int lot1 = grant.PKLot.Split(',').Length;
                    int lot2 = item.PKLot.Split(',').Length;
                    if (lot1 != lot2)
                    {
                        continue;
                    }

                    EmployeePlate plate1 = EmployeePlateServices.Query(item.PlateID);
                    if (plate1 == null)
                    {
                        throw new MyException("获取车牌号失败");
                    }
                    plateNos.Add(plate1.PlateNo);
                }
            }
            IParkOrder factory = ParkOrderFactory.GetFactory();

            return(factory.QueryMonthExpiredNotPayAmount(startDate, endDate, grant.PKID, plateNos));
        }
Example #19
0
        public static bool Add(BaseEmployee employee, EmployeePlate plate, BaseCard card, ParkGrant parkGrant, DbOperator dbOperator)
        {
            if (employee == null)
            {
                throw new ArgumentNullException("employee");
            }
            if (plate == null)
            {
                throw new ArgumentNullException("plate");
            }
            if (card == null)
            {
                throw new ArgumentNullException("card");
            }
            if (parkGrant == null)
            {
                throw new ArgumentNullException("parkGrant");
            }

            bool result = BaseEmployeeServices.AddOrUpdateBaseEmployee(employee, dbOperator);

            if (!result)
            {
                throw new MyException("保存人员信息失败");
            }

            result = BaseCardServices.AddOrUpdateCard(card, dbOperator);
            if (!result)
            {
                throw new MyException("保存卡信息失败");
            }

            result = EmployeePlateServices.AddOrUpdateEmployeePlate(plate, dbOperator);
            if (!result)
            {
                throw new MyException("保存车牌信息失败");
            }

            parkGrant.PlateID = plate.PlateID;
            parkGrant.CardID  = card.CardID;
            result            = AddOrderUpdateParkGrant(parkGrant, dbOperator);
            if (!result)
            {
                throw new MyException("保存授权失败");
            }
            if (result)
            {
                OperateLogServices.AddOperateLog <BaseEmployee>(employee, OperateType.Add);
                OperateLogServices.AddOperateLog <EmployeePlate>(plate, OperateType.Add);
                OperateLogServices.AddOperateLog <BaseCard>(card, OperateType.Add);
                OperateLogServices.AddOperateLog <ParkGrant>(parkGrant, OperateType.Add);
            }
            return(result);
        }