예제 #1
0
 // Create wallet with non-zero balance
 public Wallet(string str, Currency val, decimal sum, InputPurpose pur)
 {
     if (str == null || str.Length < 1)
     {
         throw new ArgumentException("Such name can't be used");
     }
     name     = str;
     currency = val;
     if (sum <= 0)
     {
         throw new ArgumentException("Amount of your wallet can't be less than 0");
     }
     amount  = sum;
     history = new List <Payment>();
     history.Add(new InputPayment(sum, pur));
     // Add events
     if (SuccesOperation == null)
     {
         SuccesOperation += new OperationHandler(DisplaySucces);
     }
     if (ErrorMessage == null)
     {
         ErrorMessage += new OperationHandler(DisplayError);
     }
     // Show succes
     SuccesOperation?.Invoke($"Wallet \"{this.name}\" has been created \n" +
                             "Amount of this wallet is: ", amount);
 }
예제 #2
0
 // Operation to get money from the wallet
 public void Withdrawal(decimal sum, OutputPurpose pur)
 {
     if (sum > this.amount)                                             // If sum to withdraw is greater than the amount of this wallet
     {
         ErrorMessage?.Invoke("You hane not enought money to do it\n" + // Show error
                              $"Amount of \"{this.name}\" is: ", this.amount);
     }
     else
     {
         amount -= sum;                                                                  // Withdraw this sum
         history.Add(new OutputPayment(sum, pur));                                       // Add withdrawal payment into history
         SuccesOperation?.Invoke($"Amount of \"{this.name}\" wallet is: ", this.amount); // Show succes
     }
 }
예제 #3
0
 // Operation to transfer sum FROM wallet to wallet
 public void TransferFrom(decimal sum, Wallet direction)
 {
     if (sum > this.amount) // If sum to transfer is greater than the amount of this wallet
     {
         ErrorMessage?.Invoke($"You hane not enought money to do it\n" +
                              $"Amount of \"{this.name}\" wallet is: ", this.amount);
     }
     else
     {
         this.amount -= sum;
         Transfer transfer = new Transfer(sum, this, direction);
         this.history.Add(transfer);
         Metrics metr    = new Metrics();
         decimal tempSum = metr.metrics[(int)this.currency, (int)direction.currency] * sum;
         direction.amount += tempSum;
         transfer          = new Transfer(tempSum, this, direction);
         direction.history.Add(transfer);
         SuccesOperation?.Invoke($"Amount of \"{this.name}\" wallet is: {this.amount}\n" +
                                 $"Amount of \"{direction.name}\" wallet is: ", direction.amount);
     }
 }
예제 #4
0
        }                                                  // history of all payments of this wallet
        #endregion

        // Create zero-balance wallet
        public Wallet(string str, Currency val)
        {
            if (str == null || str.Length < 1)
            {
                throw new ArgumentException("Such name can't be used");
            }
            name     = str;
            currency = val;
            amount   = 0;
            history  = new List <Payment>();
            // Add events
            if (SuccesOperation == null)
            {
                SuccesOperation += new OperationHandler(DisplaySucces);
            }
            if (ErrorMessage == null)
            {
                ErrorMessage += new OperationHandler(DisplayError);
            }
            // Show succes
            SuccesOperation?.Invoke($"Wallet \"{this.name}\" has been created \n" +
                                    "Amount of this wallet is: ", amount);
        }
예제 #5
0
 // Operation to put money on the wallet
 public void Deposit(decimal sum, InputPurpose pur)
 {
     amount += sum;                                                                  // Add money to amount
     history.Add(new InputPayment(sum, pur));                                        // Add deposit payment into history
     SuccesOperation?.Invoke($"Amount of \"{this.name}\" wallet is: ", this.amount); // Show succes
 }