private void removeBtn_Click(object sender, RoutedEventArgs e) { if (tasksListBox.SelectedIndex == -1) { outputBox.Background = Brushes.Red; outputBox.Text = "Nie zaznaczono elementu"; } else { int tmpID = tasksList[tasksListBox.SelectedIndex].ID; outputBox.Background = Brushes.Green; outputBox.Text = "Usunięto"; using (var ctx = new JTTTdbcontext()) { JTTTdb tmp = new JTTTdb() { ID = tmpID }; ctx.task.Attach(tmp); ctx.task.Remove(tmp); ctx.SaveChanges(); } updateList(); } }
private void clearBtn_Click(object sender, RoutedEventArgs e) { Window1 win1 = new Window1(); this.IsEnabled = false; win1.ShowDialog(); if (Window1.agreed == true) { Window1.agreed = false; using (var ctx = new JTTTdbcontext()) { ctx.Database.ExecuteSqlCommand("TRUNCATE TABLE [JTTTdbs]"); ctx.SaveChanges(); } updateList(); } win1.Close(); this.IsEnabled = true; }
public void addTask() { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { JTTT newTask = new JTTT(); newTask.url = urlBox.Text; newTask.text = textBox.Text; newTask.mail = mailBox.Text; newTask.city = urlBox.Text; if (numberTextBox.Text != "" && numberTextBox.Text != "Podaj warunek temperaturowy") { newTask.tempCase = Int32.Parse(numberTextBox.Text); } else { newTask.tempCase = 0; } if (taskComboBox.SelectedItem == item4) { newTask.tasktype = "find"; } if (taskComboBox.SelectedItem == item5) { newTask.tasktype = "weather"; } if (responseComboBox.SelectedItem == item1) { newTask.responsetype = "mail"; } if (responseComboBox.SelectedItem == item2) { newTask.responsetype = "saveas"; } if (responseComboBox.SelectedItem == item3) { newTask.responsetype = "display"; } if ((taskComboBox.SelectedItem == item4 && (urlBox.Text == "" || urlBox.Text == "Wprowadź URL strony" || textBox.Text == "" || textBox.Text == "Podaj tekst do wyszukania")) || (taskComboBox.SelectedItem == item5 && (urlBox.Text == "" || urlBox.Text == "Wprowadź nazwę miasta" || numberTextBox.Text == "" || numberTextBox.Text == "Podaj warunek temperaturowy")) || (responseComboBox.SelectedItem == item1 && (mailBox.Text == "" || mailBox.Text == "Podaj mail do wysłania obrazka" || mailBox.Text == "Podaj mail do wysłania pogody"))) { outputBox.Background = Brushes.Red; outputBox.Text = "Wypełnij wszystkie pola"; return; } else { using (var ctx = new JTTTdbcontext()) { JTTTdb tmpTask = new JTTTdb { URL = newTask.url, mail = newTask.mail, text = newTask.text, city = newTask.city, tasktype = newTask.tasktype, responsetype = newTask.responsetype, tempCase = newTask.tempCase }; ctx.task.Add(tmpTask); ctx.SaveChanges(); } updateList(); } })); }