コード例 #1
0
ファイル: StregsystemCLI.cs プロジェクト: FlunkyHD/sem3
        public void DisplayUserInfo(User user)
        {
            List <Transaction> transactions = (List <Transaction>)IS.GetTransactions(user, 10);

            Console.WriteLine($"{user}: Balance: {user.Balance}");
            DisplayUserTransactions(transactions);
        }
コード例 #2
0
 /// <summary>
 /// Prints to the console the latest 10 transactions a user has made
 /// </summary>
 /// <param name="user"></param>
 public void DisplayPastTransactions(User user)
 {
     foreach (Transaction transaction in _stregsystem.GetTransactions(user, 10))
     {
         Console.WriteLine(transaction);
     }
 }
コード例 #3
0
 /// <summary>
 /// Display information about a user
 /// </summary>
 /// <param name="user"></param>
 public void DisplayUserInfo(User user)
 {
     Console.WriteLine($"---\nUser: {user} Balance: {user.Balance}\n---");
     _stregsystem.GetTransactions(user, 10).ToList().ForEach(Console.WriteLine);
     if (user.Balance < 50)
     {
         DisplayUserBalanceWarning(user, user.Balance);
     }
 }
コード例 #4
0
        public void BodyText()
        {
            Console.SetCursorPosition(0, 9);

            IEnumerable <Transaction> transactions = _stregsystem.GetTransactions(User, 10).ToList();

            foreach (Transaction transaction in transactions)
            {
                Console.SetCursorPosition((Console.WindowWidth - _lineLength + 10) / 2, Console.CursorTop);
                Console.WriteLine(((BuyTransaction)transaction).Product.ToString());
            }
        }
コード例 #5
0
 private void ShowAllTransactions <AdminMethod>(string nula, string nulb, string nulc)
 {
     try
     {
         List <Transaction> transactions = Stregsystem.GetTransactions(null, 0);
         UI.DisplayTransactions(transactions);
     }
     catch (ArgumentNullException)
     {
         UI.DisplayProducts(Stregsystem.ActiveProducts);
     }
     catch (Exception e)
     {
         UI.DisplayGeneralError(e.Message);
     }
 }
コード例 #6
0
 void HandleUserCommand(string username)
 {
     try
     {
         User user = _stregsystem.GetUserByUsername(username);
         IEnumerable <Transaction> transactions = _stregsystem.GetTransactions(user, 10);
         _stregsystemUI.DisplayUserInfo(user.ToString() + $"Saldo: {user.Balance * 0.01f}");
         foreach (Transaction t in transactions)
         {
             _stregsystemUI.DisplayTransaction(t);
         }
     }
     catch (UserNotFoundException)
     {
         _stregsystemUI.DisplayUserNotFound(username);
     }
 }
コード例 #7
0
        private void FindUserInfo(string username)
        {
            User user = _stregsystem.GetUserByUsername(username);

            if (user != null)
            {
                _ui.DisplayUserInfo(user);
                // maks 10 tranaktioner må vises i følge opg beskrivelsen
                IEnumerable <Transaction> userTransactions = _stregsystem.GetTransactions(user, 10);
                foreach (Transaction transaction in userTransactions)
                {
                    _ui.DisplayTransaction(transaction);
                }
                if (user.Balance < 50)
                {
                    _ui.DisplayUserBalanceWarning(user, user.Balance);
                }
            }
            else
            {
                _ui.DisplayUserNotFound(username);
            }
        }
コード例 #8
0
        public void ParseCommand()
        {
            _command = Console.ReadLine();
            string[] command = _command.Split(" ");

            if (command[0].StartsWith(":"))
            {
                bool success = false;
                if (_adminCommands.ContainsKey(command[0]))
                {
                    _adminCommands[command[0]].Invoke();
                    success = true;
                }
                if (success == false)
                {
                    ui.DisplayAdminCommandNotFoundMessage(_command);
                }
            }
            else if (command.Length == 2)
            {
                try
                {
                    string user      = command[0];
                    int    productID = int.Parse(command[1]);
                    if (ProductSuccess(productID) && UserSucess(user))
                    {
                        BuyTransaction buy = ss.BuyProduct(ss.GetUserByUsername(user), ss.GetProductByID(productID));
                        ss.LogTransaction(buy, @"C:\Users\T-Phamz\Desktop\test.txt");
                        ui.DisplayUserBuysProduct(buy);
                        ss.OnUserBalanceWarning(ss.GetUserByUsername(user));
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine($"{(command[1])} is not a positive integer");
                }
                catch (InsufficientCreditsException)
                {
                    ui.DisplayInsufficientCash(ss.GetUserByUsername(command[0]), ss.GetProductByID(int.Parse(command[1])));
                }
                catch (ProductNotActiveException ex)
                {
                    ui.DisplayGeneralError(ex.Message);
                }
            }
            else if (command.Length == 3)
            {
                try
                {
                    string user          = command[0];
                    int    numberOfItems = int.Parse(command[1]);
                    int    productID     = int.Parse(command[2]);
                    if (ProductSuccess(productID) && UserSucess(user) && numberOfItems > 0)
                    {
                        BuyTransaction buy = null;
                        for (int i = 0; i < numberOfItems; i++)
                        {
                            buy = ss.BuyProduct(ss.GetUserByUsername(user), ss.GetProductByID(productID));
                            ss.LogTransaction(buy, @"C:\Users\T-Phamz\Desktop\test.txt");
                        }
                        ui.DisplayUserBuysProduct(numberOfItems, buy);
                        ss.OnUserBalanceWarning(ss.GetUserByUsername(user));
                    }
                    else
                    {
                        ui.DisplayGeneralError($"Number of items bought ({command[1]}) can not be under 1");
                    }
                }
                catch (FormatException)
                {
                    Console.WriteLine($"{(command[1])} or {(command[2])} " +
                                      $"is not a number");
                }
                catch (InsufficientCreditsException)
                {
                    ui.DisplayInsufficientCash(ss.GetUserByUsername(command[0]), ss.GetProductByID(int.Parse(command[1])));
                }
                catch (ProductNotActiveException ex)
                {
                    ui.DisplayGeneralError(ex.Message);
                }
            }
            else if (command.Length == 1)
            {
                if (UserSucess(command[0]))
                {
                    User u = ss.GetUserByUsername(command[0]);
                    ui.DisplayUserInfo(u);
                    foreach (Transaction item in ss.GetTransactions(u, 10))
                    {
                        ui.DisplayTransactions(item);
                    }
                    ss.OnUserBalanceWarning(u);
                }
            }
            else
            {
                ui.DisplayTooManyArgumentsError($"\"{_command}\"");
            }
            Console.WriteLine();
        }