예제 #1
0
        public static ParkGrant QueryByCardIdAndParkingId(string cardId, string parkingId)
        {
            if (cardId.IsEmpty())
            {
                throw new ArgumentNullException("cardId");
            }
            if (parkingId.IsEmpty())
            {
                throw new ArgumentNullException("parkingId");
            }

            IParkGrant factory = ParkGrantFactory.GetFactory();

            return(factory.QueryByCardIdAndParkingId(cardId, parkingId));
        }
예제 #2
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));
            }
        }