public void addPomodoro(Pomodoro pomo) { List.Add(pomo); if (List.Count % 4 == 0) { pomo.Long_pause = true; } root.DataContext = new ObservableCollection <Pomodoro>(List); }
private void Button_Add_Pomodoro(object sender, RoutedEventArgs e) { string pomo_name = tbPomoName.Text.Trim(); if (pomo_name == "") { cpt_pomo += 1; pomo_name = "Pomodoro n°" + cpt_pomo; } // Nouvelle connexion MySqlConnection conn = new MySqlConnection(connString); conn.Open(); MySqlCommand cmd = conn.CreateCommand(); // Insetion du pomodoro cmd.CommandText = "INSERT INTO pomodoro (name) VALUES (?name)"; cmd.Parameters.Add("?name", MySqlDbType.VarChar).Value = pomo_name; cmd.ExecuteNonQuery(); long pomo_id = cmd.LastInsertedId; // Insetion des tags cmd.CommandText = "INSERT INTO pomodoro_tags (id_pomo, id_tag) VALUES (?id_pomo, ?id_tag)"; cmd.Prepare(); cmd.Parameters.AddWithValue("?id_pomo", pomo_id); cmd.Parameters.AddWithValue("?id_tag", 0); tmpTags.List.ForEach(delegate(Controleur.Tag tag) { cmd.Parameters["?id_tag"].Value = tag.Id; cmd.ExecuteNonQuery(); }); conn.Close(); Controleur.Pomodoro pomo = new Controleur.Pomodoro(pomo_id, pomo_name); pomo.setTags(tmpTags.List); listPomos.addPomodoro(pomo); tmpTags.clear(); tbPomoName.Text = ""; }