-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
98 lines (81 loc) · 3.18 KB
/
MainWindow.xaml.cs
File metadata and controls
98 lines (81 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace TASKIFY
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private TodoDataAccess todoDataAccess;
public MainWindow()
{
InitializeComponent();
todoDataAccess = new TodoDataAccess();
List<TodoItem> tasks = todoDataAccess.GetAllTasks();
taskListBox.ItemsSource = tasks;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
AddTask addTask= new AddTask();
addTask.Show();
Console.WriteLine("add task open");
this.Close();
}
private void TaskListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (taskListBox.SelectedItem != null)
{
var selectedTask = (TodoItem)taskListBox.SelectedItem;
selectedTask.is_complete = !selectedTask.is_complete; // Mark the task as complete
todoDataAccess.UpdateTask(selectedTask); // Update the task in the database
// After updating the task, refresh the ListBox to show the updated tasks.
List<TodoItem> tasks = todoDataAccess.GetAllTasks();
taskListBox.ItemsSource = tasks;
}
}
private void Delete_Button_Click(object sender, RoutedEventArgs e)
{
if (sender is Button deleteButton && deleteButton.Tag is int taskId)
{
MessageBoxResult result = MessageBox.Show("Are you sure you want to delete this task?", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);
if (result == MessageBoxResult.Yes)
{
todoDataAccess.DeleteTask(taskId);
// After deleting the task, you might want to refresh the ListBox to show the updated tasks.
List<TodoItem> tasks = todoDataAccess.GetAllTasks();
taskListBox.ItemsSource = tasks;
}
}
}
private void Open_Update_Window(object sender, RoutedEventArgs e)
{
if (taskListBox.SelectedItem != null)
{
var selectedTask = (TodoItem)taskListBox.SelectedItem;
Update_task updateTaskWindow = new Update_task(selectedTask);
updateTaskWindow.ShowDialog();
this.Hide();
// After updating the task, refresh the ListBox to show the updated tasks.
//List<TodoItem> tasks = todoDataAccess.GetAllTasks();
//taskListBox.ItemsSource = tasks;
}
else
{
MessageBox.Show("Please select a task to update.");
}
}
}
}