private void button1_Click(object sender, EventArgs e)// Creating of task or reminding { if (tabControl1.SelectedIndex == 0) { DialogResult dialog = MessageBox.Show("Create Task?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { Task newTask = new Task() { Name = textBox1.Text, Description = richTextBox1.Text, Done = false }; Serialisation.Serialise <Task>(newTask, Application.StartupPath + @"\tasks.json"); MessageBox.Show("Task created!"); } } if (tabControl1.SelectedIndex == 1) { DialogResult dialog = MessageBox.Show("Create Reminding?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { Reminding newReminding = new Reminding() { Name = textBox2.Text, Description = richTextBox2.Text, Date = dateTimePicker1.Value, Done = false }; Serialisation.Serialise <Reminding>(newReminding, Application.StartupPath + @"\remindings.json"); MessageBox.Show("Reminding created! Press 'Refresh' button."); } } }
private void button2_Click(object sender, EventArgs e)//Deleting button { if (tabControl1.SelectedIndex == 0) { if (dataGridView1.SelectedCells[0].Value != null) { DialogResult dialog = MessageBox.Show("Delete Task?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { int selectedRowIndex = dataGridView1.SelectedCells[0].RowIndex; tasksList.RemoveAt(selectedRowIndex); Serialisation.Serialise <Task>(tasksList, Application.StartupPath + @"\tasks.json"); dataGridView1.Rows.RemoveAt(selectedRowIndex); MessageBox.Show("Task deleted! Press 'Refresh' button."); } } } if (tabControl1.SelectedIndex == 1) { if (dataGridView2.SelectedCells[0].Value != null) { DialogResult dialog = MessageBox.Show("Delete Reminding?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { int selectedRowIndex = dataGridView2.SelectedCells[0].RowIndex; remindingsList.RemoveAt(selectedRowIndex); Serialisation.Serialise <Reminding>(remindingsList, Application.StartupPath + @"\remindings.json"); dataGridView2.Rows.RemoveAt(selectedRowIndex); MessageBox.Show("Reminding deleted! Press 'Refresh' button."); } } } }
public void DataGrindLoad()//Loading tasks and remindings into datagrinds { tasksList = Serialisation.GetList <Task>(Application.StartupPath + @"\tasks.json"); remindingsList = Serialisation.GetList <Reminding>(Application.StartupPath + @"\remindings.json"); for (int i = 0; i < tasksList.Count; i++) { dataGridView1.Rows.Add(tasksList[i].Name, tasksList[i].Done); } for (int i = 0; i < remindingsList.Count; i++) { dataGridView2.Rows.Add(remindingsList[i].Date, remindingsList[i].Name, remindingsList[i].Done); } }
private void button3_Click(object sender, EventArgs e)//Update button { if (tabControl1.SelectedIndex == 0) { if (dataGridView1.SelectedCells[0].Value != null) { DialogResult dialog = MessageBox.Show("Update Task?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { int selectedRowIndex = dataGridView1.SelectedCells[0].RowIndex; tasksList[selectedRowIndex].Name = Convert.ToString(dataGridView1[0, selectedRowIndex].Value); tasksList[selectedRowIndex].Description = richTextBox1.Text; tasksList[selectedRowIndex].Done = Convert.ToBoolean(dataGridView1[1, selectedRowIndex].Value); Serialisation.Serialise <Task>(tasksList, Application.StartupPath + @"\tasks.json"); MessageBox.Show("Task updated!"); } } } if (tabControl1.SelectedIndex == 1) { if (dataGridView2.SelectedCells[0].Value != null) { DialogResult dialog = MessageBox.Show("Update Reminding?", "", MessageBoxButtons.OKCancel); if (dialog == DialogResult.OK) { int selectedRowIndex = dataGridView2.SelectedCells[0].RowIndex; remindingsList[selectedRowIndex].Name = Convert.ToString(dataGridView2[1, selectedRowIndex].Value); remindingsList[selectedRowIndex].Description = richTextBox1.Text; remindingsList[selectedRowIndex].Date = Convert.ToDateTime(Convert.ToString(dataGridView2[0, selectedRowIndex].Value)); remindingsList[selectedRowIndex].Done = Convert.ToBoolean(dataGridView2[2, selectedRowIndex].Value); Serialisation.Serialise <Reminding>(remindingsList, Application.StartupPath + @"\remindings.json"); MessageBox.Show("Reminding updated!"); } } } }