public static void AddBoat(Boats personboat) { Console.WriteLine("Would you like to add a new boat, Y/N?"); string response1 = Console.ReadLine(); if (response1 == "y" || response1 == "Y") { Console.WriteLine("Enter boatname"); string boat = Console.ReadLine(); Console.WriteLine("Enter boatnumber"); int boatnumber = int.Parse(Console.ReadLine()); using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal("sailingDB"))) { try { var boat1 = connection.Query <Boats>("call returnboat(@name)", new { name = personboat.name }).First(); if (boat1.boat1 == "") { SQLAddboat(personboat.name, 0, boat, boatnumber); } else if (boat1.boat2 == "") { SQLAddboat(personboat.name, 1, boat, boatnumber); } else if (boat1.boat3 == "") { SQLAddboat(personboat.name, 2, boat, boatnumber); } else if (boat1.boat4 == "") { SQLAddboat(personboat.name, 3, boat, boatnumber); } else if (boat1.boat5 == "") { SQLAddboat(personboat.name, 4, boat, boatnumber); } else { Console.WriteLine("You have the max number of boats(5), would you like to remove one?"); Console.WriteLine("Here are your 5 boats"); displayboats(personboat); if (Console.ReadLine() == "Y" || Console.ReadLine() == "y") { BoatsRacing boatsracing = new BoatsRacing(); Console.WriteLine("Which boat would you like to remove?"); var answer = Console.ReadLine(); if (answer == personboat.boat1) { boatsracing.name = personboat.name; boatsracing.boatName = personboat.boat1; boatsracing.boatNumber = personboat.boatNumber1; LoadFullSQL.SQLremoveboat(personboat, boatsracing); } else if (answer == personboat.boat2) { boatsracing.name = personboat.name; boatsracing.boatName = personboat.boat2; boatsracing.boatNumber = personboat.boatNumber2; LoadFullSQL.SQLremoveboat(personboat, boatsracing); } else if (answer == personboat.boat3) { boatsracing.name = personboat.name; boatsracing.boatName = personboat.boat3; boatsracing.boatNumber = personboat.boatNumber3; LoadFullSQL.SQLremoveboat(personboat, boatsracing); } else if (answer == personboat.boat4) { boatsracing.name = personboat.name; boatsracing.boatName = personboat.boat4; boatsracing.boatNumber = personboat.boatNumber4; LoadFullSQL.SQLremoveboat(personboat, boatsracing); } else if (answer == personboat.boat5) { boatsracing.name = personboat.name; boatsracing.boatName = personboat.boat5; boatsracing.boatNumber = personboat.boatNumber5; LoadFullSQL.SQLremoveboat(personboat, boatsracing); } else { Console.WriteLine("That is not one of the boats."); } } } } catch { Console.WriteLine("Your name is not in my database"); } } } }
public static Dictionary <string, Boats> loadFullFile(string path) //public static string LoadFullFile() { StreamReader reader = System.IO.File.OpenText(@path + @"Full List.txt"); string line; Dictionary <int, BoatsFromExcel> BoatDictionaryInterim = new Dictionary <int, BoatsFromExcel>(); Dictionary <string, Boats> BoatDictionary = new Dictionary <string, Boats>(); int count1 = 0; while ((line = reader.ReadLine()) != null) { string[] items = line.Split(char.Parse("\n")); while ((line = reader.ReadLine()) != null) { string[] items1 = line.Split('\t'); BoatsFromExcel boat1 = new BoatsFromExcel(items1[0], int.Parse(items1[1]), items1[2]); BoatDictionaryInterim.Add(count1, boat1); count1++; } } List <string> keys = new List <string>(); int m = 0; foreach (KeyValuePair <int, BoatsFromExcel> Boat in BoatDictionaryInterim) { if (keys.Contains(BoatDictionaryInterim[m].name)) { if (BoatDictionary[BoatDictionaryInterim[m].name].boat2 == null) { Boats boat1 = new Boats(BoatDictionaryInterim[m].name, BoatDictionary[BoatDictionaryInterim[m].name].boat1, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber1, BoatDictionaryInterim[m].boat, BoatDictionaryInterim[m].boatNumber); BoatDictionary.Remove(BoatDictionaryInterim[m].name); BoatDictionary.Add(boat1.name, boat1); } else if (BoatDictionary[BoatDictionaryInterim[m].name].boat3 == null) { Boats boat1 = new Boats(BoatDictionaryInterim[m].name, BoatDictionary[BoatDictionaryInterim[m].name].boat1, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber1, BoatDictionary[BoatDictionaryInterim[m].name].boat2, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber2, BoatDictionaryInterim[m].boat, BoatDictionaryInterim[m].boatNumber); BoatDictionary.Remove(BoatDictionaryInterim[m].name); BoatDictionary.Add(boat1.name, boat1); } else if (BoatDictionary[BoatDictionaryInterim[m].name].boat4 == null) { Boats boat1 = new Boats(BoatDictionaryInterim[m].name, BoatDictionary[BoatDictionaryInterim[m].name].boat1, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber1, BoatDictionary[BoatDictionaryInterim[m].name].boat2, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber2, BoatDictionary[BoatDictionaryInterim[m].name].boat3, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber3, BoatDictionaryInterim[m].boat, BoatDictionaryInterim[m].boatNumber); BoatDictionary.Remove(BoatDictionaryInterim[m].name); BoatDictionary.Add(boat1.name, boat1); } else if (BoatDictionary[BoatDictionaryInterim[m].name].boat5 == null) { Boats boat1 = new Boats(BoatDictionaryInterim[m].name, BoatDictionary[BoatDictionaryInterim[m].name].boat1, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber1, BoatDictionary[BoatDictionaryInterim[m].name].boat2, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber2, BoatDictionary[BoatDictionaryInterim[m].name].boat3, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber3, BoatDictionary[BoatDictionaryInterim[m].name].boat4, BoatDictionary[BoatDictionaryInterim[m].name].boatNumber4, BoatDictionaryInterim[m].boat, BoatDictionaryInterim[m].boatNumber); BoatDictionary.Remove(BoatDictionaryInterim[m].name); BoatDictionary.Add(boat1.name, boat1); } } else { Boats boat3 = new Boats(BoatDictionaryInterim[m].name, BoatDictionaryInterim[m].boat, BoatDictionaryInterim[m].boatNumber); BoatDictionary.Add(boat3.name, boat3); keys.Add(BoatDictionaryInterim[m].name); } m++; } reader.Close(); return(BoatDictionary); }
public static void SQLremoveboat(Boats boats, BoatsRacing boat) { if (boats.name == boat.name) { boats.noOfBoats = boats.noOfBoats - 1; LoadFullSQL.SQLremove(false, boats.name); if (boats.boat1 == boat.boatName) { if (boats.noOfBoats == 1) { boats.boat1 = ""; boats.boatNumber1 = 0; } else if (boats.noOfBoats == 2) { boats.boat1 = boats.boat2; boats.boat2 = ""; boats.boatNumber1 = boats.boatNumber2; boats.boatNumber2 = 0; } else if (boats.noOfBoats == 3) { boats.boat1 = boats.boat3; boats.boat3 = ""; boats.boatNumber1 = boats.boatNumber3; boats.boatNumber3 = 0; } else if (boats.noOfBoats == 4) { boats.boat1 = boats.boat4; boats.boat4 = ""; boats.boatNumber1 = boats.boatNumber4; boats.boatNumber4 = 0; } else if (boats.noOfBoats == 5) { boats.boat1 = boats.boat5; boats.boat5 = ""; boats.boatNumber1 = boats.boatNumber5; boats.boatNumber5 = 0; } } else if (boats.boat2 == boat.boatName) { if (boats.noOfBoats == 2) { boats.boat2 = ""; boats.boatNumber2 = 0; } else if (boats.noOfBoats == 3) { boats.boat2 = boats.boat3; boats.boat3 = ""; boats.boatNumber2 = boats.boatNumber3; boats.boatNumber3 = 0; } else if (boats.noOfBoats == 4) { boats.boat2 = boats.boat4; boats.boat4 = ""; boats.boatNumber2 = boats.boatNumber4; boats.boatNumber4 = 0; } else if (boats.noOfBoats == 5) { boats.boat2 = boats.boat5; boats.boat5 = ""; boats.boatNumber2 = boats.boatNumber5; boats.boatNumber5 = 0; } } else if (boats.boat3 == boat.boatName) { if (boats.noOfBoats == 3) { boats.boat3 = ""; boats.boatNumber3 = 0; } else if (boats.noOfBoats == 4) { boats.boat3 = boats.boat4; boats.boat4 = ""; boats.boatNumber3 = boats.boatNumber4; boats.boatNumber4 = 0; } else if (boats.noOfBoats == 5) { boats.boat3 = boats.boat5; boats.boat5 = ""; boats.boatNumber3 = boats.boatNumber5; boats.boatNumber5 = 0; } } else if (boats.boat4 == boat.boatName) { if (boats.noOfBoats == 4) { boats.boat4 = ""; boats.boatNumber4 = 0; } else if (boats.noOfBoats == 5) { boats.boat4 = boats.boat5; boats.boat5 = ""; boats.boatNumber4 = boats.boatNumber5; boats.boatNumber5 = 0; } } else if (boats.boat5 == boat.boatName) { boats.boat5 = ""; boats.boatNumber5 = 0; } LoadFullSQL.SQLAddboat(boats.name, boats.noOfBoats, boats.boat1, boats.boatNumber1); LoadFullSQL.SQLAddboat(boats.name, boats.noOfBoats, boats.boat2, boats.boatNumber2); LoadFullSQL.SQLAddboat(boats.name, boats.noOfBoats, boats.boat3, boats.boatNumber3); LoadFullSQL.SQLAddboat(boats.name, boats.noOfBoats, boats.boat4, boats.boatNumber4); LoadFullSQL.SQLAddboat(boats.name, boats.noOfBoats, boats.boat5, boats.boatNumber5); } }