public void CheckStopAddNewPerson(string consoleline) { //checking if user is typing command while creating new persons account to avoid this mistake : "Name:/(command)" string firstchar = consoleline.Substring(0, 1); if (firstchar == "/") { commands commands = new commands(); commands.ErrorMessage("add.new_person() process exited and stoped!"); ExtraLineProblem(consoleline); } }
public void view(string codeline, string listelements) { if (codeline == "/view.personsdata[all]") { foreach (var person in persons) { person.PersonInfo(false); } } else if (codeline == "/view.accountsdata[all]") { foreach (var account in accounts) { account.BankAccountInfo(false); } } else if (codeline == "/view.fullprofiledata[all]") { for (int f = 0; f < persons.Count; f++) { persons[f].PersonInfo(true); accounts[f].BankAccountInfo(true); } } else { commands commands = new commands(); int stringLength = codeline.Length; int numberLength = stringLength - listelements.Length - 12; string char19 = codeline.Substring((listelements.Length + 11), numberLength); int Int; if (Int32.TryParse(char19, out Int)) { Int32.TryParse(char19, out Int); if (Int > persons.Count) { commands.ErrorMessage_ToLargeNum(listelements, persons.Count); } else if (Int < 0) { commands.ErrorMessage("[index] cannot be negative!"); } for (int i = 0; i < persons.Count + 1; i++) { if (codeline == $"/view.personsdata[{i}]") { persons[i - 1].PersonInfo(false); } else if (codeline == $"/view.accountsdata[{i}]") { accounts[i - 1].BankAccountInfo(false); } else if (codeline == $"/view.fullprofiledata[{i}]") { persons[i - 1].PersonInfo(true); accounts[i - 1].BankAccountInfo(true); } } } else { //checking if realy in char19 is some string or if just char19 is so big number, it cannot even store in Int32 bool numbertolarge = true; for (int c = 0; c < char19.Length; c++) { string checknumber = char19.Substring(c, 1); int Ichecknumber; if (!Int32.TryParse(checknumber, out Ichecknumber)) { numbertolarge = false; break; } } if (numbertolarge == true) { commands.ErrorMessage_ToLargeNum(listelements, persons.Count); } else { commands.ErrorMessage("[index] must be a number!"); } } } ExtraLineProblem(""); }
public void AddNewPerson() { Program p = new Program(); commands commands = new commands(); string name = null; string surname = null; string ageinput = null; int age2; string eyecolor = null; bool End = false; while (End == false) { commands.WriteLine("new person.age:"); ageinput = Console.ReadLine(); CheckStopAddNewPerson(ageinput); if (Int32.TryParse(ageinput, out age2)) { Int32.TryParse(ageinput, out age2); commands.WriteLine("new person.name:"); name = Console.ReadLine(); CheckStopAddNewPerson(name); commands.WriteLine("new person.surname:"); surname = Console.ReadLine(); CheckStopAddNewPerson(surname); commands.WriteLine("new person.eyecolor:"); eyecolor = Console.ReadLine(); CheckStopAddNewPerson(eyecolor); persons.Add(new Human(name, surname, age2, eyecolor)); commands.WriteLine($"{name} {surname} bank account:"); commands.WriteLine("Balance:"); string balance = null; string Currency = null; bool stop = false; int Ibalance; while (stop == false) { balance = Console.ReadLine(); if (Int32.TryParse(balance, out Ibalance)) { Int32.TryParse(balance, out Ibalance); commands.WriteLine("Currnecy:"); Currency = Console.ReadLine(); accounts.Add(new BankAccount($"{persons[accounts.Count].Name} {persons[accounts.Count].Surname}", Ibalance, Currency, 12, accounts.Count)); stop = true; } else { commands.ErrorMessage("balance must be a number!"); } } commands.WriteLine("view " + name + " profile together (Y/N)"); bool End2 = false; while (End2 == false) { string answer2 = Console.ReadLine(); CheckStopAddNewPerson(answer2); if (answer2 == "Y") { persons[persons.Count - 1].PersonInfo(true); accounts[persons.Count - 1].BankAccountInfo(true); End2 = true; End = true; ExtraLineProblem("");; } else if (answer2 == "N") { End2 = true; End = true; ExtraLineProblem("");; } else { commands.ErrorMessage("this is Y/N n question!"); End2 = false; } } } else { commands.ErrorMessage("age must be a number!"); } } }