コード例 #1
0
        public override void AdjustAccount(AccountType usage)
        {
            if (usage is MessageAccountUsage)
            {
                MessageAccountUsage callUsage = usage as MessageAccountUsage;

                if (_AvaliableUnits - _UsedUnit >= callUsage.Usage)
                {
                    _UsedUnit   = _UsedUnit + callUsage.Usage;
                    _UsedCredit = _UsedCredit + _UsedUnit * _UsagePerUnit;
                }
            }
        }
コード例 #2
0
ファイル: Account.cs プロジェクト: mcinnes/University-Work
        public bool Record(string description, AccountType usage, out ServiceItem item)
        {
            bool status = true;
            double numberOfRecordUsage = DEFAULT_USAGE;
            item = null;

            if (usage is CallAccountUsage)
            {
                CallAccountUsage Usage = usage as CallAccountUsage;
                numberOfRecordUsage = Math.Ceiling(Usage.Usage);
            } else if (usage is MessageAccountUsage) {
                MessageAccountUsage Usage = usage as MessageAccountUsage;
                numberOfRecordUsage = Convert.ToDouble(Usage.Usage);
            }
                
            _UsedUnit += numberOfRecordUsage;
            _UsedCredit += (numberOfRecordUsage * _UsagePerUnit);
            item = new ServiceItem(numberOfRecordUsage, description, _UsagePerUnit);

            Console.WriteLine(description);
            Console.WriteLine("NRU: "+numberOfRecordUsage);
            Console.WriteLine("Av: {0}, UU: {1}, UC: {2}, UPU:{3}", _AvaliableUnit, _UsedUnit, _UsedCredit, _UsagePerUnit);
            if (_AvaliableUnit - _UsedUnit >= numberOfRecordUsage)
            {
                            Console.WriteLine("1");

                _UsedUnit += numberOfRecordUsage;
                _UsedCredit += _UsedUnit * _UsagePerUnit;
                item = null;
            }
            if (numberOfRecordUsage > _AvaliableUnit - _UsedUnit)
            {
                            Console.WriteLine("2");

                numberOfRecordUsage = _AvaliableUnit - _UsedUnit;
                item = null;
            }
            if (numberOfRecordUsage < 0)
            {
                Console.WriteLine("3");
               status = false;
                item = null;
            }
            Console.WriteLine("NRU: "+numberOfRecordUsage);
            Console.WriteLine("Av: {0}, UU: {1}, UC: {2}, UPU:{3}", _AvaliableUnit, _UsedUnit, _UsedCredit, _UsagePerUnit);
            Console.WriteLine("\n\n");
            return status;
        }
コード例 #3
0
ファイル: Account.cs プロジェクト: mcinnes/University-Work
 public void AdjustAccount(AccountType usage)
 {
     double _avaliableUnit = 0;
     
     if (usage != null){
     
         _UsagePerUnit = AccountUsage.AccountType(usage);
         
         if (usage is CallAccountUsage)
         {
             CallAccountUsage Usage = usage as CallAccountUsage;
             _avaliableUnit = Usage.Usage;
         } else {
             MessageAccountUsage Usage = usage as MessageAccountUsage;
             _avaliableUnit = Usage.Usage;
         }           
     }
     
     if ((_AvaliableUnit - _UsedUnit) > _avaliableUnit){
         _UsedUnit = _UsedUnit + _avaliableUnit;
     }
     _UsedCredit = _UsedCredit + (_avaliableUnit * _UsagePerUnit);
 }
コード例 #4
0
        public override bool Record(string description, AccountType usage, out ServiceItem item)
        {
            bool status = true;
            int  numberOfRecordUsage = DEFAULT_USAGE;

            item = null;
            if (usage is MessageAccountUsage)
            {
                MessageAccountUsage messageUsage = usage as MessageAccountUsage;


                _UsedUnit   = _UsedUnit + numberOfRecordUsage;
                _UsedCredit = _UsedCredit + (numberOfRecordUsage * _UsagePerUnit);

                if (_AvaliableUnits - _UsedUnit >= messageUsage.Usage)
                {
                    _UsedUnit   = _UsedUnit + messageUsage.Usage;
                    _UsedCredit = _UsedCredit + _UsedUnit * _UsagePerUnit;
                    //item = null;
                }
                else if (numberOfRecordUsage > _AvaliableUnits - _UsedUnit)
                {
                    numberOfRecordUsage = _AvaliableUnits - _UsedUnit;
                    // item = null;
                }
                else if (numberOfRecordUsage <= 0)
                {
                    status = false;
                    item   = null;
                }
            }
            item = new ServiceItem(numberOfRecordUsage, description, _UsagePerUnit);


            return(status);
        }