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)); }
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(); }
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); }
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)); }
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); }
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); }
public void AddPlanter(Planter planter) { Database.AddPlanter(planter, User); RefreshPlanters(); }
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)); }