public static void ExportToFile(List <BoatsFromExcel> fulllist, string path)
        {
            BoatsFromExcel tempboat = new BoatsFromExcel();

            //using (StreamWriter sw = File.AppendText(@path + @"\FullDump.csv"))
            //{
            foreach (var entry in fulllist)
            {
                LoadFullSQL.SQLAddboat(entry.name, entry.boat, entry.boatNumber);
            }
            //sw.WriteLine("{0},{1},{2}", tempboat.name,
            //tempboat.boat, tempboat.boatNumber);
            //}
        }
 public static void AddBoat(BoatsFromExcel personboat)
 {
     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");
          *  }
          */
     }
 }
Exemple #3
0
        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);
        }