예제 #1
0
        public Plant AddPlant(Plant plant, Planter planter)
        {
            int id = Database.AddPlant(plant, planter);

            RefreshPlants();
            return(AssignPlant(id));
            //int t = Database.GetPlantsForPlanters(User.Id).Count;
            //User.RefreshPlanters(Database.GetPlantsForPlanters(User.Id));
        }
예제 #2
0
        public void UpdateScore(Plant plant, Planter planter)
        {
            string     query = "UPDATE [Owned_Plant] SET [Score] = @score WHERE [Planter] = @planter AND [Plant] = @plant AND [Date_added] = @date;";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@score", plant.Score);
            cmd.Parameters.AddWithValue("@planter", planter.Id);
            cmd.Parameters.AddWithValue("@plant", plant.Id);
            cmd.Parameters.AddWithValue("@date", plant.DateAdded);
            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
        }
예제 #3
0
        public void AddPlanter(Planter planter, User user)
        {
            string     query = "INSERT INTO [Planter] ([Name], [Type], [Current_plant]) VALUES (@name, @type, 0); SELECT SCOPE_IDENTITY();";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@name", planter.Name);
            cmd.Parameters.AddWithValue("@type", planter.Type);
            conn.Open();
            int id = Convert.ToInt32(cmd.ExecuteScalar());

            conn.Close();
            AssignPlanter(id, user);
        }
예제 #4
0
        public int AddPlant(Plant plant, Planter planter)
        {
            string     query = "INSERT INTO [Plant] ([Name], [Type], [Description]) VALUES (@name, @type, @description); SELECT SCOPE_IDENTITY();";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@name", plant.Name);
            cmd.Parameters.AddWithValue("@type", plant.Type);
            cmd.Parameters.AddWithValue("@description", plant.Description);
            conn.Open();
            int id = Convert.ToInt32(cmd.ExecuteScalar());

            conn.Close();
            return(AssignPlant(id, planter));
        }
예제 #5
0
        public List <int> GetPlanterUsers(Planter planter)
        {
            List <int> value = new List <int>();
            string     query = "SELECT [User] FROM [Owned_planter] WHERE Planter = @planter;";
            SqlCommand cmd   = new SqlCommand(query, conn);

            cmd.Parameters.AddWithValue("@planter", planter.Id);
            conn.Open();
            SqlDataReader result = cmd.ExecuteReader();

            if (result.HasRows)
            {
                while (result.Read())
                {
                    value.Add(result.GetInt32(0));
                }
            }
            conn.Close();
            return(value);
        }
예제 #6
0
 public int AssignPlant(int plant, Planter planter)
 {
     foreach (var user in GetPlanterUsers(planter))
     {
         string     query = "INSERT INTO [Owned_plant] ([Planter], [Plant], [Date_added]) VALUES (@planter, @plant, @dateadded);";
         SqlCommand cmd   = new SqlCommand(query, conn);
         cmd.Parameters.AddWithValue("@plant", plant);
         cmd.Parameters.AddWithValue("@planter", planter.Id);
         cmd.Parameters.AddWithValue("@dateadded", DateTime.Now);
         conn.Open();
         cmd.ExecuteNonQuery();
         conn.Close();
         query = "UPDATE [Planter] SET [Current_plant] = @plant WHERE [Planter_ID] = @planter;";
         cmd   = new SqlCommand(query, conn);
         cmd.Parameters.AddWithValue("@plant", plant);
         cmd.Parameters.AddWithValue("@planter", planter.Id);
         conn.Open();
         cmd.ExecuteNonQuery();
         conn.Close();
     }
     return(plant);
 }
예제 #7
0
 public void AddPlanter(Planter planter)
 {
     Database.AddPlanter(planter, User);
     RefreshPlanters();
 }
예제 #8
0
        public void UpdateScore(Plant plant, Planter planter, int score, int Type)
        {
            plant.AddScore(score);
            Situation ideal = Database.GetSituation(0, Situation.SituationType.Ideal);

            Situation desired = Database.GetSituation(0, Situation.SituationType.Desired);

            /*switch (Type)
             * {
             *
             *  case 0:  //temperatuur is veranderd
             *
             *      var change = Math.Abs(ideal.Temperature - desired.Temperature);
             *
             *      if (change < 5)
             *      {
             *          plant.AddScore((100 * (5 - change)) / 4);
             *      }
             *      else
             *      {
             *          plant.AddScore(( -100 * change) / 4);
             *      }
             *
             *      break;
             *
             *  case 1:  //luchtvochtighied is veranderd
             *
             *      var change1 = Math.Abs(ideal.Humidity - desired.Humidity);
             *
             *      if (change1 < 20)
             *      {
             *          plant.AddScore((100 * (20 - change1)) / 4);
             *      }
             *      else
             *      {
             *          plant.AddScore((-100 * change1) / 4);
             *      }
             *          break;
             *
             *  case 2:  //luchtkwaliteit is veranderd
             *
             *      var change2 = Math.Abs(ideal.AirQuality - desired.AirQuality);
             *
             *      if (change2 < 20)
             *      {
             *          plant.AddScore((100 * (20 - change2)) / 4);
             *      }
             *      else
             *      {
             *          plant.AddScore((-100 * change2) / 4);
             *      }
             *
             *      break;
             *  case 3:  //lichtsterkte is veranderd
             *
             *      var change3 = Math.Abs(ideal.LightLevel - desired.LightLevel);
             *
             *      if (change3 < 20)
             *      {
             *          plant.AddScore((100 * (20 - change3)) / 4);
             *      }
             *      else
             *      {
             *          plant.AddScore((-100 * change3) / 4);
             *      }
             *
             *      break;
             *
             * }*/

            Database.UpdateScore(plant, planter);
            User.RefreshPlants(Database.GetPlants(User.Id));
            //int t = Database.GetPlantsForPlanters(User.Id).Count;
            //User.RefreshPlanters(Database.GetPlantsForPlanters(User.Id));
        }