|
|
|
@ -1,4 +1,5 @@ |
|
|
|
|
using System; |
|
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Text; |
|
|
|
@ -13,8 +14,10 @@ using System.Windows.Media.Imaging; |
|
|
|
|
using System.Windows.Navigation; |
|
|
|
|
using System.Windows.Shapes; |
|
|
|
|
using ToDoApp.Context; |
|
|
|
|
using ToDoApp.Controller; |
|
|
|
|
using ToDoApp.Model; |
|
|
|
|
using ToDoApp.Service; |
|
|
|
|
using ToDoApp.SubControl; |
|
|
|
|
using ToDoApp.SubWindow; |
|
|
|
|
|
|
|
|
|
namespace ToDoApp |
|
|
|
|
{ |
|
|
|
@ -23,6 +26,9 @@ namespace ToDoApp |
|
|
|
|
/// </summary> |
|
|
|
|
public partial class MainWindow : Window |
|
|
|
|
{ |
|
|
|
|
private User _user; |
|
|
|
|
private Item _selectedItem; |
|
|
|
|
|
|
|
|
|
public MainWindow() |
|
|
|
|
{ |
|
|
|
|
InitializeComponent(); |
|
|
|
@ -32,13 +38,28 @@ namespace ToDoApp |
|
|
|
|
MessageBox.Show("데이터베이스가 정상적이지 않아 프로그램을 종료합니다."); |
|
|
|
|
Application.Current.Shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (CheckLogin() != true) |
|
|
|
|
{ |
|
|
|
|
Application.Current.Shutdown(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
InitInstance(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void InitInstance() |
|
|
|
|
{ |
|
|
|
|
tbName.Text = _user.Name; |
|
|
|
|
tbEmail.Text = _user.Email; |
|
|
|
|
|
|
|
|
|
RefreshList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private bool CheckDB() |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
ToDoController.Instance.EnsureCreated(); |
|
|
|
|
DbService.Instance.EnsureCreated(); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
@ -47,5 +68,123 @@ namespace ToDoApp |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private bool? CheckLogin() |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
LoginWindow dlg = new LoginWindow(); |
|
|
|
|
bool? isOk = dlg.ShowDialog(); |
|
|
|
|
_user = dlg.User; |
|
|
|
|
|
|
|
|
|
return isOk; |
|
|
|
|
} |
|
|
|
|
catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void RefreshList() |
|
|
|
|
{ |
|
|
|
|
List<Item> items = GetAllItems(); |
|
|
|
|
SetToDoList(items); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private List<Item> GetAllItems() |
|
|
|
|
{ |
|
|
|
|
return ItemService.Instance.FindAllNotCompletedItems(_user.Id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void SetToDoList(List<Item> items) |
|
|
|
|
{ |
|
|
|
|
List<ToDoListItem> list = new List<ToDoListItem>(); |
|
|
|
|
foreach (Item item in items) |
|
|
|
|
{ |
|
|
|
|
list.Add(new ToDoListItem(item)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
lbxContent.ItemsSource = list; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void SetSelectedItem(Item item) |
|
|
|
|
{ |
|
|
|
|
_selectedItem = item; |
|
|
|
|
|
|
|
|
|
tbxItemName.Text = _selectedItem.Title; |
|
|
|
|
tbItemCreatedAt.Text = _selectedItem.CreateDate.ToString("yyyy년 MM월 dd일 ddd 생성됨"); |
|
|
|
|
|
|
|
|
|
if (_selectedItem.DueDate != null) |
|
|
|
|
dpItemDueDate.SelectedDate = _selectedItem.DueDate; |
|
|
|
|
|
|
|
|
|
if (_selectedItem.Description != null) |
|
|
|
|
tbxItemDescription.Text = _selectedItem.Description; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void ClearSelectedItem() |
|
|
|
|
{ |
|
|
|
|
_selectedItem = null; |
|
|
|
|
|
|
|
|
|
tbxItemName.Text = ""; |
|
|
|
|
tbItemCreatedAt.Text = ""; |
|
|
|
|
dpItemDueDate.SelectedDate = null; |
|
|
|
|
tbxItemDescription.Text = ""; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void tbxNewItemName_KeyDown(object sender, KeyEventArgs e) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void tbxSearch_KeyDown(object sender, KeyEventArgs e) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void btnUpdate_Click(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void btnDelete_Click(object sender, RoutedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (_selectedItem == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
ItemService.Instance.RemoveItem(_selectedItem.Id); |
|
|
|
|
|
|
|
|
|
ClearSelectedItem(); |
|
|
|
|
RefreshList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void tbxNewItem_KeyDown(object sender, KeyEventArgs e) |
|
|
|
|
{ |
|
|
|
|
if (e.Key != Key.Enter) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
PlaceholderTextBox textBox = sender as PlaceholderTextBox; |
|
|
|
|
if (textBox == null || string.IsNullOrEmpty(textBox.Text)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Item newItem = new Item() |
|
|
|
|
{ |
|
|
|
|
UserId = _user.Id, |
|
|
|
|
Title = textBox.Text, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
ItemService.Instance.CreateItem(newItem); |
|
|
|
|
textBox.Text = ""; |
|
|
|
|
|
|
|
|
|
RefreshList(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void lbxContent_SelectionChanged(object sender, SelectionChangedEventArgs e) |
|
|
|
|
{ |
|
|
|
|
ToDoListItem toDoListItem = lbxContent.SelectedItem as ToDoListItem; |
|
|
|
|
if (toDoListItem == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
SetSelectedItem(toDoListItem.Item); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|