示例#1
0
文件: Program.cs 项目: thducng/CSharp
        static void Main(string[] args)
        {
            //Took from assignment - was to good to create one for myself :)
            Stregsystem              stregsystem = new Stregsystem();
            StregsystemCLI           cli         = new StregsystemCLI(stregsystem);
            StregsystemCommandParser parser      = new StregsystemCommandParser(stregsystem, cli);

            cli.Start(parser);
        }
示例#2
0
        public override bool Execute(Stregsystem CS)
        {
            TransactionsList transactionList = new TransactionsList(CS);
            UsersList        usersList       = new UsersList();

            User.Balance = User.Balance + Amount * 100;
            Date         = DateTime.Now;

            if (transactionList.AddCashTransaction(this))
            {
                if (usersList.UpdateUser(User))
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
示例#3
0
        //Algorithm for Execute, just that it filled to much - seems unreadable
        private bool SaveTransaction(BuyTransaction transaction, Stregsystem CS)
        {
            TransactionsList transactionList = new TransactionsList(CS);
            UsersList        usersList       = new UsersList();

            User.Balance = User.Balance - Product.Price;
            Price        = Product.Price;
            Date         = DateTime.Now;

            if (transactionList.AddBuyTransaction(transaction))
            {
                if (usersList.UpdateUser(User))
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
示例#4
0
        public override bool Execute(Stregsystem CS)
        {
            double newBalance = 0.0;

            newBalance = User.Balance - Product.Price;

            if (newBalance < 0 && !Product.CanBeBoughtOnCredit)
            {
                throw new InsufficientCreditsException();
            }
            else
            {
                if (SaveTransaction(this, CS))
                {
                    return(true);
                }
                return(false);
            }
        }
示例#5
0
 public StregsystemCLI(Stregsystem _stregsystem)
 {
     stregsystem = _stregsystem;
 }
示例#6
0
 //Virtual, can be changed but does not have to be
 public virtual bool Execute(Stregsystem CS)
 {
     return(false);
 }
 public StregsystemCommandParser(Stregsystem _stregsystem, StregsystemCLI _cli)
 {
     stregsystem = _stregsystem;
     cli         = _cli;
 }
示例#8
0
 public TransactionsList(Stregsystem _CS)
 {
     filePath = GetPath("TransactionsList.csv");
     CS       = _CS;
 }