public InvoiceManager() { listOfInvoice = new ListOfInvoice(); listOfProducts = new ListOfProducts(); listOfCustomers = new ListOfCustomers(); listOfInvoice.Load(listOfCustomers, listOfProducts); }
public IEnumerable <Customer> GetCustomers(string nameOrCity) { var result = ListOfCustomers.Where(x => x.Name.ToLower().Contains(nameOrCity.ToLower()) || x.City.ToLower() == nameOrCity.ToLower()); return(result); }
public Customer RunToGetCustomer() { bool exit = false; ListOfCustomers listOfCustomers = new ListOfCustomers(); separator = new string('-', Console.WindowWidth); do { Console.Clear(); ShowHeader(); ShowOtherFooter(); WriteCustomer(listOfCustomers, currentRecord); // Update clock if no key is pressed while (!Console.KeyAvailable) { Thread.Sleep(200); EnhancedConsole.ShowClock(); } switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: case ConsoleKey.NumPad1: case ConsoleKey.D1: //Previus if (currentRecord != 0) { currentRecord--; } break; case ConsoleKey.RightArrow: case ConsoleKey.NumPad2: case ConsoleKey.D2: //Next if (currentRecord != listOfCustomers.Amount - 1) { currentRecord++; } break; case ConsoleKey.NumPad3: case ConsoleKey.D3: //Search by number SearchByText(listOfCustomers, ref currentRecord); break; case ConsoleKey.Enter: exit = true; break; } } while (!exit); return(listOfCustomers.Get(currentRecord)); }
private static void WriteCustomer(ListOfCustomers listOfCustomers, int count) { int y = 5; EnhancedConsole.WriteAt(0, y, "KEY: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetKey(), "white"); y++; EnhancedConsole.WriteAt(0, y, "NAME: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetName(), "white"); y++; EnhancedConsole.WriteAt(0, y, "ID: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetID(), "white"); y++; EnhancedConsole.WriteAt(0, y, "RESIDENCE: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetResidence(), "white"); y++; EnhancedConsole.WriteAt(0, y, "CITY: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetCity(), "white"); y++; EnhancedConsole.WriteAt(0, y, "POSTAL CODE: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetPostalCode(), "white"); y++; EnhancedConsole.WriteAt(0, y, "COUNTRY: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetCountry(), "white"); y++; EnhancedConsole.WriteAt(0, y, "PHONE NUMBER: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetPhoneNumber().ToString(), "white"); y++; EnhancedConsole.WriteAt(0, y, "eMAIL: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetEMail(), "white"); y++; EnhancedConsole.WriteAt(0, y, "CONTACT: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetContact(), "white"); y++; EnhancedConsole.WriteAt(0, y, "COMMENTS: ", "gray"); EnhancedConsole.WriteAt(15, y, listOfCustomers.Get(count).GetComments(), "white"); y++; }
public void DeleteCustomer(Customer customer) { var checkSumOfAccounts = ListOfAccounts.Where(x => x.CustomerId == customer.Id).Select(y => y.Balance).Sum(); if (checkSumOfAccounts == 0) { ListOfAccounts.Remove(customer.Accounts.FirstOrDefault()); ListOfCustomers.Remove(customer); Output.GreenColor($"Borttaget kundnummer: {customer.Id}"); } else { Output.RedColor("Det går inte att ta bort en kund som har saldo större en noll på något av sina konton."); } }
public void HelpMenuAndControl(ListOfCustomers listOfCustomers, int countCustomers, string separator) { string[] help = { "This text gives help", "This one helps too", "This one its even longer, so we need to check if the " + "string its too long" }; int count = 0; bool exit = false; do { Console.BackgroundColor = ConsoleColor.Red; EnhancedConsole.DrawWindow(Console.WindowWidth / 4, Console.WindowHeight / 4, help[count]); Console.BackgroundColor = ConsoleColor.DarkBlue; switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: if (count != 0) { count--; } break; case ConsoleKey.RightArrow: if (count != help.Length - 1) { count++; } break; case ConsoleKey.Escape: exit = true; break; } } while (!exit); }
public void AddNewCustomer(Customer customer) { ListOfCustomers.Add(new Customer(this) { Name = customer.Name, Adress = customer.Adress, City = customer.City, Country = customer.Country, ZipCode = customer.ZipCode, Region = customer.Region, OrganisationNumber = customer.OrganisationNumber, Telephone = customer.Telephone, }); // Add account to new customer AddNewAccount(ListOfCustomers.Last()); Console.WriteLine($"Ny kund skapad med kundnummer: {ListOfCustomers.Last().Id}"); Console.WriteLine($"Nytt kontonummer: {ListOfAccounts.Last().Id}"); }
public void DeleteAccount(Account account) { // Check sum of accounts var checkSumOfAccounts = ListOfAccounts.Where(x => x.Id == account.Id).Select(y => y.Balance).Sum(); // Count accounts var countAccounts = ListOfAccounts.Count(x => x.CustomerId == account.CustomerId); var customer = ListOfCustomers.FirstOrDefault(x => x.Id == account.CustomerId); // Can not delete account if sum is not zero or there is only one account // (customer always need an account) if (checkSumOfAccounts == 0 && countAccounts > 1) { ListOfAccounts.Remove(account); customer.Accounts.Remove(account); Output.GreenColor($"Borttaget kontonummer: {account.Id}"); } else { Output.RedColor("Kan ej ta bort kontot om:\n- det finns saldo\n- det är kundens enda konto"); } }
public void SearchByNumber(ListOfCustomers list, ref int count) { string numberSTR; ushort number; do { Console.Clear(); Console.SetCursorPosition(0, 10); EnhancedConsole.WriteAt(0, 10, "Enter the number you are looking for", "white"); numberSTR = EnhancedConsole.GetAt(0, 11, 3); }while (!UInt16.TryParse(numberSTR, out number)); if (number > 0 && number <= list.Amount) { count = number - 1; } else { EnhancedConsole.WriteAt(0, 10, "Wrong Number!", "white"); Console.ReadLine(); } }
public void Load(ListOfCustomers customers, ListOfProducts products) { DirectoryInfo d = new DirectoryInfo("invoices/"); foreach (FileInfo f in d.GetFiles("*.dat")) { StreamReader invoicesInput = new StreamReader(f.FullName); string line; string[] invoicessAux; int invoiceMax = 1; try { do { line = invoicesInput.ReadLine(); if (line != null) { invoicessAux = line.Split(';'); int invoiceNumber = Int32.Parse(invoicessAux[0]); if (invoiceNumber > invoiceMax) { invoiceMax = invoiceNumber; } Invoice.invoiceCount = invoiceMax; string[] dateAux = invoicessAux[1].Split('/'); DateTime date = new DateTime(Int32.Parse(dateAux[2]), Int32.Parse(dateAux[1]), Int32.Parse(dateAux[0])); string key = invoicessAux[2]; int countCustomers = 0; bool found = false; do { if (key == customers.Get(countCustomers).GetKey()) { found = true; countCustomers--; } countCustomers++; }while (countCustomers < customers.Amount && !found); myInvoices.Add(new Invoice(invoiceNumber, date, customers.Get(countCustomers))); Product p; string code; double price; int amount; int countProduct; if (invoicessAux.Length > 3) { for (int i = 3; i < invoicessAux.Length; i += 3) //We start at 1, to not get out of the array size { countProduct = 0; found = false; code = invoicessAux[i]; do { if (code == products.Get(countProduct).GetCode()) { found = true; countProduct--; } countProduct++; }while (countProduct < products.Amount && !found); p = products.Get(countProduct); amount = Int32.Parse(invoicessAux[i + 1]); price = Double.Parse(invoicessAux[i + 2]); myInvoices.Last().AddLine(p, amount, price); } } } }while (line != null); invoicesInput.Close(); } catch (PathTooLongException) { Console.WriteLine("Error: Path Too Long."); throw; } catch (FileNotFoundException) { Console.WriteLine("Error: File not found."); throw; } catch (IOException e) { Console.WriteLine("I/O error: " + e); throw; } catch (Exception e) { Console.WriteLine("Error: " + e); throw; } } }
public Customer GetSingleCustomer(int id) { var selected = ListOfCustomers.SingleOrDefault(x => x.Id == id); return(selected); }
public void Modify(ListOfCustomers listOfCustomers, int count) { int y = 5; Console.Clear(); Console.SetCursorPosition(0, Console.WindowHeight - 2); Console.WriteLine("To not change something, just press Enter"); Console.SetCursorPosition(0, 5); string aux; aux = listOfCustomers.Get(count).GetName(); EnhancedConsole.WriteAt(1, y, "Name: ", "white"); string name = EnhancedConsole.GetAt(10, y, aux, 20); listOfCustomers.Get(count).SetName(name); y++; aux = listOfCustomers.Get(count).GetID(); EnhancedConsole.WriteAt(0, y, "ID: " + listOfCustomers.Get(count).GetID() .ToString(), "white"); y++; string iD = EnhancedConsole.GetAt(0, y, 10); if (iD == "") { iD = aux; } listOfCustomers.Get(count).SetID(iD); y++; aux = listOfCustomers.Get(count).GetResidence(); EnhancedConsole.WriteAt(0, y, "Residence: " + listOfCustomers.Get(count).GetResidence() .ToString(), "white"); y++; string residence = EnhancedConsole.GetAt(0, y, 10); if (residence == "") { residence = aux; } listOfCustomers.Get(count).SetResidence(residence); y++; aux = listOfCustomers.Get(count).GetCity(); EnhancedConsole.WriteAt(0, y, "City: " + listOfCustomers.Get(count).GetCity() .ToString(), "white"); y++; string city = EnhancedConsole.GetAt(0, y, 15); if (city == "") { city = aux; } listOfCustomers.Get(count).SetCity(city); y++; aux = listOfCustomers.Get(count).GetPostalCode(); EnhancedConsole.WriteAt(0, y, "Postal Code: " + listOfCustomers.Get(count).GetPostalCode() .ToString(), "white"); y++; string postalCode = EnhancedConsole.GetAt(0, y, 10); if (postalCode == "") { postalCode = aux; } listOfCustomers.Get(count).SetPostalCode(postalCode); y++; aux = listOfCustomers.Get(count).GetCountry(); EnhancedConsole.WriteAt(0, y, "Country: " + listOfCustomers.Get(count).GetCountry() .ToString(), "white"); y++; string country = EnhancedConsole.GetAt(0, y, 12); if (country == "") { country = aux; } listOfCustomers.Get(count).SetCountry(country); y++; uint auxUINT = listOfCustomers.Get(count).GetPhoneNumber(); EnhancedConsole.WriteAt(0, y, "Phone Number: " + listOfCustomers.Get(count).GetPhoneNumber() .ToString(), "white"); y++; string phoneSTR; uint phone; do { phoneSTR = EnhancedConsole.GetAt(0, y, 9); } while ((!UInt32.TryParse(phoneSTR, out phone)) && phoneSTR != ""); if (phoneSTR == "") { phone = auxUINT; } listOfCustomers.Get(count).SetPhoneNumber(phone); y++; aux = listOfCustomers.Get(count).GetEMail(); EnhancedConsole.WriteAt(0, y, "eMail: " + listOfCustomers.Get(count).GetEMail() .ToString(), "white"); y++; string eMail = EnhancedConsole.GetAt(0, y, 25); if (eMail == "") { eMail = aux; } listOfCustomers.Get(count).SetEMail(eMail); y++; aux = listOfCustomers.Get(count).GetContact(); EnhancedConsole.WriteAt(0, y, "Contact: " + listOfCustomers.Get(count).GetContact() .ToString(), "white"); y++; string contact = EnhancedConsole.GetAt(0, y, 20); if (contact == "") { contact = aux; } listOfCustomers.Get(count).SetContact(contact); y++; aux = listOfCustomers.Get(count).GetComments(); EnhancedConsole.WriteAt(0, y, "Comments: " + listOfCustomers.Get(count).GetComments() .ToString(), "white"); y++; string comments = EnhancedConsole.GetAt(0, y, 40); if (comments == "") { comments = aux; } listOfCustomers.Get(count).SetComments(comments); y++; }
public void SearchByText(ListOfCustomers listOfCustomers, ref int count) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "What are you looking for?", "white"); string search = EnhancedConsole.GetAt(0, 11, 15); search = search.ToLower(); bool found = false; do { if (listOfCustomers.Get(count).GetName().ToLower(). Contains(search) || listOfCustomers.Get(count).GetID().ToLower(). Contains(search) || listOfCustomers.Get(count).GetResidence().ToLower(). Contains(search) || listOfCustomers.Get(count).GetCity().ToLower(). Contains(search) || listOfCustomers.Get(count).GetPostalCode().ToLower(). Contains(search) || listOfCustomers.Get(count).GetCountry().ToLower(). Contains(search) || listOfCustomers.Get(count).GetEMail().ToLower(). Contains(search) || listOfCustomers.Get(count).GetContact().ToLower(). Contains(search) || listOfCustomers.Get(count).GetComments().ToLower(). Contains(search) || listOfCustomers.Get(count).GetKey().ToLower(). Contains(search) || listOfCustomers.Get(count).GetPhoneNumber().ToString(). Contains(search)) { found = true; Console.Clear(); ShowHeader(); WriteCustomer(listOfCustomers, currentRecord); EnhancedConsole.WriteAt(1, 20, "Found on the record " + (count + 1).ToString("000"), "yellow"); Console.ReadLine(); count--; } count++; }while (!found && count < listOfCustomers.Amount - 1); if (!found) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Not Found!", "red"); EnhancedConsole.WriteAt(0, 12, "Do you want to search from the first record?", "white"); count = 0; if (Console.ReadKey().Key == ConsoleKey.Y) { do { if (listOfCustomers.Get(count).GetName().ToLower(). Contains(search) || listOfCustomers.Get(count).GetID().ToLower(). Contains(search) || listOfCustomers.Get(count).GetResidence().ToLower(). Contains(search) || listOfCustomers.Get(count).GetCity().ToLower(). Contains(search) || listOfCustomers.Get(count).GetPostalCode().ToLower(). Contains(search) || listOfCustomers.Get(count).GetCountry().ToLower(). Contains(search) || listOfCustomers.Get(count).GetEMail().ToLower(). Contains(search) || listOfCustomers.Get(count).GetContact().ToLower(). Contains(search) || listOfCustomers.Get(count).GetComments().ToLower(). Contains(search) || listOfCustomers.Get(count).GetKey().ToLower(). Contains(search) || listOfCustomers.Get(count).GetPhoneNumber().ToString(). Contains(search)) { found = true; Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Found on the record " + (count + 1).ToString("000"), "yellow"); Console.ReadLine(); count--; } count++; }while (!found && count < listOfCustomers.Amount - 1); if (!found) { Console.Clear(); EnhancedConsole.WriteAt(0, 10, "Not Found!", "red"); Console.ReadLine(); count = 0; } } } }
public void Run() { bool exit = false; ListOfCustomers listOfCustomers = new ListOfCustomers(); separator = new string('-', Console.WindowWidth); do { Console.Clear(); ShowHeader(); ShowFooter(); WriteCustomer(listOfCustomers, currentRecord); // Update clock if no key is pressed while (!Console.KeyAvailable) { Thread.Sleep(200); EnhancedConsole.ShowClock(); } switch (Console.ReadKey().Key) { case ConsoleKey.LeftArrow: case ConsoleKey.NumPad1: case ConsoleKey.D1: //Previus if (currentRecord != 0) { currentRecord--; } break; case ConsoleKey.RightArrow: case ConsoleKey.NumPad2: case ConsoleKey.D2: //Next if (currentRecord != listOfCustomers.Amount - 1) { currentRecord++; } break; case ConsoleKey.NumPad3: case ConsoleKey.D3: //Search by number SearchByNumber(listOfCustomers, ref currentRecord); break; case ConsoleKey.NumPad4: case ConsoleKey.D4: //Search by text SearchByText(listOfCustomers, ref currentRecord); break; case ConsoleKey.NumPad5: case ConsoleKey.D5: //Add Customer Console.Clear(); listOfCustomers.Add(GetDataToCreateCustomer()); break; case ConsoleKey.NumPad6: case ConsoleKey.D6: //EDIT Modify(listOfCustomers, currentRecord); break; case ConsoleKey.D: //Delete EnhancedConsole.WriteAt(0, Console.WindowHeight - 5, "Delete this Record ? Y / N", "white"); if (Console.ReadKey().Key == ConsoleKey.Y) { listOfCustomers.Get(currentRecord).SetDeleted(true); } break; case ConsoleKey.A: AdvancedMenu(); break; case ConsoleKey.F1: HelpMenuAndControl(listOfCustomers, currentRecord, separator); break; case ConsoleKey.NumPad0: case ConsoleKey.D0: //EXIT exit = true; break; } } while (!exit); }
public CustomerManager() { listOfCustomers = new ListOfCustomers(); currentRecord = 0; }