private void Tasks_Load(object sender, EventArgs e) { String FileName = Directory.GetCurrentDirectory() + "\\" + Uname + "-Tasks-" + dt + ".txt"; if (!File.Exists(FileName)) { ChLsBxTaskList.Items.Clear(); MessageBox.Show("You have no tasks for " + dt); } else { String[] Tasks = System.IO.File.ReadAllLines(FileName); int l = Tasks.Length; int j; for (int i = 0; i < l; i++) { j = Tasks[i].Length - 5; ChLsBxTaskList.Items.Add(Tasks[i].Substring(5, (Tasks[i].Length - 5))); if (Tasks[i].Substring(0, 2) == "cd") { ChLsBxTaskList.SetItemCheckState(i, CheckState.Checked); } else if (Tasks[i].Substring(0, 2) == "ip") { ChLsBxTaskList.SetItemCheckState(i, CheckState.Indeterminate); } else if (Tasks[i].Substring(0, 2) == "uc") { ChLsBxTaskList.SetItemCheckState(i, CheckState.Unchecked); } } } }
private void BtnAddTsk_Click(object sender, EventArgs e) { String tk = TxtBoxAddTask.Text.ToString(); if (tk == null || tk == "") { MessageBox.Show("Please enter the name of the task to be added to your list."); } else { try { String FileName = Directory.GetCurrentDirectory() + Uname + "-Tasks-" + dt + ".txt"; ChLsBxTaskList.Items.Add(tk); int i = ChLsBxTaskList.Items.IndexOf(tk); ChLsBxTaskList.SetItemCheckState(i, CheckState.Unchecked); System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName, true); sw.WriteLine("uc - " + tk); TxtBoxAddTask.Clear(); //sw.Close(); } catch (Exception er) { MessageBox.Show(er.Message + " Occurred"); } } }
private void BtnTskComp_Click(object sender, EventArgs e) { int tk = ChLsBxTaskList.SelectedIndex; if (tk == -1) { MessageBox.Show("No task selected. Please select a task and try again."); ChLsBxTaskList.Focus(); } else { String FileName = Directory.GetCurrentDirectory() + Uname + "-Tasks-" + dt + ".txt"; ChLsBxTaskList.SetItemCheckState(tk, CheckState.Checked); String[] list = System.IO.File.ReadAllLines(FileName); System.IO.StreamWriter sw = new System.IO.StreamWriter(FileName); for (int i = 0; i < list.Length; i++) { if (i == tk) { sw.WriteLine("cd - " + list[i].Substring(5, (list[i].Length - 5)).ToString()); } else { sw.WriteLine(list[i].ToString()); } } sw.Close(); } }