Ejemplo n.º 1
0
 private void cbFeedr_SelectedIndexChanged(object sender, EventArgs e)
 {
     currentFeedr = owner.Feedrs.Find(x => x.id == Convert.ToInt32(cbFeedr.Text));
     if (currentFeedr.dog != null)
     {
         cbDog.SelectedItem = currentFeedr.dog.Name;
     }
 }
Ejemplo n.º 2
0
        public Account GetAcountInfo(int id)
        {
            //get account table
            string       Query        = $"SELECT * FROM Account WHERE ID = {id}";
            MySqlCommand mySqlCommand = new MySqlCommand(Query, con);

            con.Open();
            MySqlDataReader myReader = mySqlCommand.ExecuteReader();

            myReader.Read();
            //myReader.Close();
            int    Account_id = myReader.GetInt32("Id");
            string name       = myReader.GetString("Name");
            string email      = String.Empty;

            try
            {
                email = myReader.GetString("Email");
            }
            catch
            {
            }
            string  password = myReader.GetString("Password");
            Account account  = new Account(Account_id, name, password, email);



            myReader.Close();
            //get dogs info
            string DogQuery = $"SELECT * FROM Dog WHERE accountId = {id}";

            mySqlCommand = new MySqlCommand(DogQuery, con);

            myReader = mySqlCommand.ExecuteReader();

            while (myReader.Read())
            {
                int      dogId       = myReader.GetInt32("Id");
                string   dogName     = myReader.GetString("Name");
                int      weight      = myReader.GetInt32("Weight");
                int      stageOfLife = myReader.GetInt32("StageOfLife");
                DateTime dateOfBirth = Convert.ToDateTime(myReader.GetString("DateOfBirth"));


                account.addDog(new Dog(dogId, dogName, dateOfBirth, stageOfLife, weight));
            }
            myReader.Close();

            //get foods
            string foodQuery = $"SELECT * FROM Food Where accountId = {id}";

            mySqlCommand = new MySqlCommand(foodQuery, con);

            myReader = mySqlCommand.ExecuteReader();

            while (myReader.Read())
            {
                int    foodid   = myReader.GetInt32("Id");
                string foodName = myReader.GetString("Name");
                int    energy   = myReader.GetInt32("Energy");
                account.addFood(new Food(foodid, foodName, energy));
            }
            myReader.Close();

            //get feedrs
            string feedrQuery = $"SELECT * FROM Feedr Where accountId = {id}";

            mySqlCommand = new MySqlCommand(feedrQuery, con);
            myReader     = mySqlCommand.ExecuteReader();


            while (myReader.Read())
            {
                int feedrId = 0;
                try
                {
                    feedrId = myReader.GetInt32("Id");
                }
                catch
                {
                }


                int dogId    = myReader.GetInt32("DogId");
                Dog feedrDog = new Dog();
                foreach (Dog dog in account.Dogs)
                {
                    if (dog.Id == dogId)
                    {
                        feedrDog = dog;
                    }
                }
                int  foodId    = myReader.GetInt32("FoodId");
                Food feedrFood = new Food();
                foreach (Food accountFood in account.Foods)
                {
                    if (accountFood.Id == foodId)
                    {
                        feedrFood = accountFood;
                    }
                }
                int             foodPerMeal = myReader.GetInt32("FoodPerMeal");
                int             puzzle      = myReader.GetInt32("Puzzle");
                int             level       = myReader.GetInt32("level");
                bool            active      = myReader.GetBoolean("active");
                List <DateTime> mealtimes   = new List <DateTime>();
                Feedr           feedr       = new Feedr(feedrId, level, mealtimes, feedrDog, feedrFood, puzzle, active);
                account.addFeedr(feedr);
            }



            con.Close();
            return(account);
        }
Ejemplo n.º 3
0
 public void addFeedr(Feedr feedr)
 {
     Feedrs.Add(feedr);
 }