public void racerwritetofile(BoatsRacing racer, string path) { using (StreamWriter sw = System.IO.File.AppendText(@path + @"\Race List.txt")) { sw.WriteLine("{0}, {1}, {2}", racer.name, racer.boatName, racer.boatNumber); } }
public static Dictionary <string, BoatsRacing> loadRaceFile(Dictionary <string, BoatsRacing> raceDictionary, string path) { StreamReader reader = System.IO.File.OpenText(@path + @"\Race List.txt"); string line; while ((line = reader.ReadLine()) != null) { string[] items = line.Split(char.Parse(", ")); Console.WriteLine("{0}, {1}, {2}", items[0], items[1], items[2]); BoatsRacing boat1 = new BoatsRacing(items[0], items[1], int.Parse(items[2])); raceDictionary.Add(items[0], boat1); } reader.Close(); return(raceDictionary); }
public static void SQLaddnewracer(Boats personboat, BoatsRacing BoatRacing) { try { using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal("sailingDB"))) { //connection.Query("call enterraceperson('" + BoatRacing.name + "', '" + BoatRacing.boatName + "', '" + //BoatRacing.boatNumber + "')"); connection.Query("call enterraceperson(@name, @boatname, @boatnumber)", new { name = BoatRacing.name, boatname = BoatRacing.boatName, boatnumber = BoatRacing.boatNumber }); } Console.WriteLine(personboat.name + " is racing a(n) " + BoatRacing.boatName); } catch { Console.WriteLine("Your name has already been added to the race, would you like to remove it?"); if (Console.ReadLine() == "y" || Console.ReadLine() == "Y") { SQLremove(true, BoatRacing.name); } } }
public static BoatsRacing converter5(Boats boat) { BoatsRacing racer1 = new BoatsRacing(boat.name, boat.boat5, boat.boatNumber5); return(racer1); }
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); * */ }
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 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); } }