public static void SelectByID(object obj) { lock (locker) { int id = (int)obj; if (checkId(id) == true) { Console.Clear(); ConsoleShow.Green("Id\t\tFirstname\t\tSecondname\t\tBalance"); Client tempClient = clients[id - 1]; System.Console.Write(tempClient.Id); for (int i = 0; i < 9 - tempClient.Firstname.Length; i++) { System.Console.Write(" "); } System.Console.Write("\t\t" + tempClient.Firstname); for (int i = 0; i < 10 - tempClient.Secondname.Length; i++) { System.Console.Write(" "); } System.Console.Write("\t\t" + tempClient.Secondname); String t = tempClient.Balance.ToString(); for (int i = 0; i < Math.Abs(10 - t.Length); i++) { System.Console.Write(" "); } System.Console.WriteLine("\t\t" + tempClient.Balance); } else { Console.Clear(); ConsoleShow.Red("Error: No such ID found"); } } }
public static void Select() { lock (locker) { Console.Clear(); if (clients.Count == 0) { ConsoleShow.Red("No clients info"); } else { ConsoleShow.Green("Id\t\tFirstname\t\tSecondname\t\tBalance"); foreach (var client in clients) { System.Console.Write(client.Id); for (int i = 0; i < 9 - client.Firstname.Length; i++) { System.Console.Write(" "); } System.Console.Write("\t\t" + client.Firstname); for (int i = 0; i < 10 - client.Secondname.Length; i++) { System.Console.Write(" "); } System.Console.Write("\t\t" + client.Secondname); String t = client.Balance.ToString(); for (int i = 0; i < Math.Abs(10 - t.Length); i++) { System.Console.Write(" "); } System.Console.WriteLine("\t\t" + client.Balance); } } } }
public static void Insert(object obj) { Console.Clear(); Client client = (Client)obj; clients.Add(client); ConsoleShow.Green <string>($"{client.Firstname} has been added"); }
public static void DeleteByID(object obj) { int id = (int)obj; if (checkId(id) == true) { //int index = 0; foreach (var client in clients) { if (client.Id == id) { clients.Remove(client); break; } //index++; } Console.Clear(); ConsoleShow.Green <string>($"Client #{id} has been deleted"); } }
//! Develop public static void Update(object obj) { int id = (int)obj; if (checkId(id) == false) { Console.Clear(); ConsoleShow.Red <string>("No such id found"); } else { Client tempClient = clients[id - 1]; bool working = true; while (working) { Console.Clear(); System.Console.Write("What you want to change?: \n1.Firstname\n2.Secondname\n3.Balance\n4.Exit\nYour choice: "); int choice; if (int.TryParse(Console.ReadLine(), out choice)) { if (choice > 0 && choice <= 4) { switch (choice) { case 1: { System.Console.Write("Firstname: "); clients[id - 1].Firstname = Console.ReadLine(); ConsoleShow.Green <String>("Updated"); Thread.Sleep(500); } break; case 2: { System.Console.Write("Secondname: "); clients[id - 1].Secondname = Console.ReadLine(); ConsoleShow.Green <String>("Updated"); Thread.Sleep(500); } break; case 3: { System.Console.Write("Balance: "); decimal tempBalance; if (decimal.TryParse(Console.ReadLine(), out tempBalance)) { decimal last = clients[id - 1].Balance; clients[id - 1].Balance = tempBalance; ConsoleShow.Green <String>("Updated"); Balance balance = new Balance(id, last, tempBalance); TimerCallback changeInClientBalance = new TimerCallback(BalanceChecking); Timer checkBalance = new Timer(changeInClientBalance, balance, 0, -1); } } break; case 4: { working = false; } break; } } } } } }