-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTodolistMain.cs
133 lines (110 loc) · 4.29 KB
/
TodolistMain.cs
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Todolist
{
public partial class TodolistMain : Form
{
private List<Todo> todoList = new List<Todo>();
public TodolistMain()
{
InitializeComponent();
todolist_grid_view.Columns.Clear();
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "Finished";
checkBoxColumn.Name = "checkBoxColumn";
todolist_grid_view.RowHeadersVisible = false;
todolist_grid_view.Columns.Add(checkBoxColumn);
todolist_grid_view.Columns.Add("todo", "To do");
loadTodoListFromFile(todoList, "..\\..\\data\\todolist_data.txt");
}
void loadTodoListFromFile(List<Todo> todoList, string filePath)
{
try
{
// 파일에서 한 줄씩 읽어와서 파싱하여 Todo 객체 생성
using (StreamReader sr = new StreamReader(filePath))
{
string line;
while ((line = sr.ReadLine()) != null)
{
string[] parts = line.Split('/');
if (parts.Length == 2)
{
string todoItem = parts[0];
bool finished;
Console.WriteLine($"parsed: {parts[1]}, {parts[1].Length}");
finished = Convert.ToBoolean(Convert.ToInt32(parts[1])); // 체크 여부를 int변환 후 bool 변환
Todo todo = new Todo(todoItem, finished);
todoList.Add(todo);
/*
finished 여부 대신, 체크박스를 넣음.
*/
}
}
}
// DataGridView에 데이터 출력
foreach (Todo todo in todoList)
{
/*
// DataGridView에 행 추가
int rowIndex = todolist_grid_view.Rows.Add();
// DataGridView의 체크박스에 값 설정
todolist_grid_view.Rows[rowIndex].Cells["checkBoxColumn"].Value = todo.Finished;
Console.WriteLine($"value: {todo.Finished}");
// DataGridView의 할 일 컬럼에 값 설정
todolist_grid_view.Rows[rowIndex].Cells["todo"].Value = todo.TodoItem;
*/
Add_todo_to_gridview(todo);
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
}
/*
* function: button1_click
버튼을 누르면 todo 하나를 추가한다.
*/
private void button1_Click(object sender, EventArgs e)
{
//btn_load_todolist.Text = "clicked";
string todoItem = "";
bool finished = false;
Todo todo = new Todo(todoItem, finished);
todoList.Add(todo);
Add_todo_to_gridview(todo);
}
private void Add_todo_to_gridview(Todo todo)
{
// DataGridView에 행 추가
int rowIndex = todolist_grid_view.Rows.Add();
// DataGridView의 체크박스에 값 설정
todolist_grid_view.Rows[rowIndex].Cells["checkBoxColumn"].Value = todo.Finished;
Console.WriteLine($"value: {todo.Finished}");
// DataGridView의 할 일 컬럼에 값 설정
todolist_grid_view.Rows[rowIndex].Cells["todo"].Value = todo.TodoItem;
}
private void todolist_grid_view_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
class Todo
{
public string TodoItem { get; set; }
public bool Finished { get; set; }
public Todo(string todoItem, bool finished)
{
TodoItem = todoItem;
Finished = finished;
}
}
}