Exemplo n.º 1
0
 public override bool Equals(object obj)
 {
     if (obj == null)
     {
         return(false);
     }
     if (!(obj is TariffBase))
     {
         return(false);
     }
     if (object.ReferenceEquals(this, obj))
     {
         return(true);
     }
     else
     {
         TariffBase tb = obj as TariffBase;
         return(this.CalculateFee(new DateTime(2011, 1, 1), new DateTime(2011, 1, 2)) == tb.CalculateFee(new DateTime(2011, 1, 1), new DateTime(2011, 1, 2)));
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 计算卡片的应收停车费用,如果之前已经多次收费,则费用会扣除相应的收费金额
        /// </summary>
        /// <param name="card">卡片</param>
        /// <param name="freeTimeAfterPay">卡片收费后允许免费停留多少分钟</param>
        /// <param name="carType">卡片收费车型</param>
        /// <returns>停车收费信息</returns>
        public ParkAccountsInfo CalculateCardParkFee(CardInfo card, Byte carType, DateTime chargeDateTime)
        {
            ParkAccountsInfo parkAccounts = new ParkAccountsInfo();

            parkAccounts.CarType = carType;

            decimal fee = 0;

            //以卡片的入场时间计算
            DateTime beginning = GetMyDateTime(card.LastDateTime);

            //如果启用了酒店应用
            if (card.EnableHotelApp)
            {
                if (card.IsInFreeTime(chargeDateTime))
                {
                    //处于免费时间点内,费用为0
                    return(parkAccounts);
                }
                else if (card.FreeDateTime.HasValue)
                {
                    //过了免费时间点的,以免费时间点为开始时间计算费用
                    beginning = GetMyDateTime(card.FreeDateTime.Value);
                }
            }

            DateTime ending    = GetMyDateTime(chargeDateTime);
            TimeSpan ts        = new TimeSpan(ending.Ticks - beginning.Ticks);
            double   totalMins = Math.Ceiling(ts.TotalMinutes);

            if (totalMins < 0)
            {
                return(parkAccounts);                //入场时间大于出场时间
            }
            DateTime   begin  = beginning;
            DateTime   end    = beginning;
            TariffBase tariff = null;

            while (begin < ending)
            {
                tariff = GetCalculateTariff(card.CardType.ID, carType, card.ParkingStatus, begin);
                while (end.Date < ending.Date)
                {
                    end = end.AddDays(1);
                    TariffBase tb = GetCalculateTariff(card.CardType.ID, carType, card.ParkingStatus, end);
                    if (
                        (tariff == null && tb == null) ||
                        (tariff != null && tariff.Equals(tb))
                        )
                    {
                        //donothing
                    }
                    else
                    {
                        end = end.Date;
                        if (tariff != null)
                        {
                            decimal temp = tariff.CalculateFee(begin, end);
                            fee += tariff.FeeOfMax > 0 && tariff.FeeOfMax < temp ? tariff.FeeOfMax : temp;
                            parkAccounts.TariffType = tariff.TariffType;
                        }
                        tariff = tb;
                        begin  = end <= ending ? end : ending;
                        end    = begin;
                        break;
                    }
                }
                if (end.Date == ending.Date)
                {
                    break;
                }
            }
            if (tariff != null && begin < ending)
            {
                decimal temp = tariff.CalculateFee(begin, ending);
                fee += tariff.FeeOfMax > 0 && tariff.FeeOfMax < temp ? tariff.FeeOfMax : temp;
            }
            parkAccounts.ParkFee = fee;
            decimal accounts = fee - card.TotalPaidFee;//已缴费用=停车费用-已收费用

            if (card.IsCompletedPaid)
            {
                //已完成缴费,判断是否已过收费后免费时间
                if (IsInFreeTime(card.PaidDateTime.Value, chargeDateTime))
                {
                    accounts = 0;
                    //还处于免费时间,车场费用为卡片中的停车费用
                    parkAccounts.ParkFee = card.ParkFee;
                }
            }
            parkAccounts.Accounts = accounts > 0 ? accounts : 0;
            return(parkAccounts);
        }