Beispiel #1
0
 public Pet(int id, string name, Breed breed, Spieces spieces, Sanctuary sanctuary, int age, int gender, double weight, double bills, DateTime rescueD, string picturePath)
 {
     this.id = id;
     this.name = name;
     this.breed = breed;
     this.spieces = spieces;
     this.sanctuary = sanctuary;
     this.age = age;
     this.gender = gender;
     this.weight = weight;
     this.bills = bills;
     this.rescueD = rescueD;
     this.picturePath = picturePath;
 }
Beispiel #2
0
        // Method that returns a list of Breeds objects with the details from the DB
        public static List<Breed> LoadBreeds(string by = "", string id = "")
        {
            List<Breed> breeds = new List<Breed>();
            OleDbConnection myConnection = GetConnection();

            string myQuery = "";
            OleDbCommand myCommand;

            // Deciding how to load breeds
            switch (by)
            {
                case "spieces":
                    myQuery = "SELECT * FROM breeds WHERE spieces_id = ?";
                    myCommand = new OleDbCommand(myQuery, myConnection);
                    myCommand.Parameters.Add("@spieces_id", OleDbType.Integer, 5).Value = id;
                    break;
                default:
                    myQuery = "SELECT * FROM breeds";
                    myCommand = new OleDbCommand(myQuery, myConnection);
                    break;
            }

            try
            {
                myConnection.Open();
                OleDbDataReader myReader = myCommand.ExecuteReader();

                List<Spieces> spieces = LoadSpieces();

                while (myReader.Read())
                {
                    Spieces spiece = FindSpieces(spieces, int.Parse(myReader["spieces_id"].ToString()));
                    Breed breed = new Breed(int.Parse(myReader["id"].ToString()), myReader["name"].ToString(), spiece, double.Parse(myReader["food_cost"].ToString()), double.Parse(myReader["housing_cost"].ToString()));
                    breeds.Add(breed);
                }
                return breeds;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in DBHandler", ex);
                return null;
            }
            finally
            {
                myConnection.Close();
            }
        }