/// <summary> /// Adds the task specified in the textboxes for the date specified in the comboboxes into the database /// </summary> private void cmdConfirm_Click(object sender, EventArgs e) { // If the app native language is set on French if (dbConn.ReadSetting(1) == 2) { // Use French resxFile resxFile = @".\\stringsFR.resx"; } else { // By default use English resxFile resxFile = @".\\stringsEN.resx"; } using (ResXResourceSet resourceManager = new ResXResourceSet(resxFile)) { // Checks if the task's title is empty if (txtTitle.Text == "") { MessageBox.Show(resourceManager.GetString("youMustGiveATitleToYourTask"), resourceManager.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // Escapes single quotes by doubling them to prevent the SQL insert from crashing the app if (txtTitle.Text.Contains("'")) { txtTitle.Text = txtTitle.Text.Replace("'", "''"); } // Gets the value of the date time picker and affects it to the deadline string variable // in the format used by the database string deadline = dtpDeadline.Value.ToString("yyyy-MM-dd"); // Gets the selected topic from the combo box Lists currentTopic = cboTopics.SelectedItem as Lists; // Status is set to 1, which means "To Do" dbConn.InsertTask(txtTitle.Text, txtDescription.Text, deadline, chkImportant.Checked ? 1 : 0, currentTopic.Id, 1); // Reloads topics in the main form mainForm.LoadTasks(); // Closes the window this.Close(); } } }
/// <summary> /// Edits the task in the database /// </summary> private void cmdConfirm_Click(object sender, EventArgs e) { // If the app native language is set on French if (dbConn.ReadSetting(1) == 2) { // Use French resxFile resxFile = @".\\stringsFR.resx"; } else { // By default use English resxFile resxFile = @".\\stringsEN.resx"; } using (ResXResourceSet resourceManager = new ResXResourceSet(resxFile)) { // Checks if the task's title is empty if (txtTitle.Text == "") { MessageBox.Show(resourceManager.GetString("youMustGiveATitleToYourTask"), resourceManager.GetString("error"), MessageBoxButtons.OK, MessageBoxIcon.Error); } else { // Gets the value of the date time picker and affects it to the deadline string variable // in the format used by the database string deadline = dtpDeadline.Value.ToString("yyyy-MM-dd"); // Gets the selected topic Lists currentTopic = cboTopics.SelectedItem as Lists; // Status is automatically set to 1 which refers to "A faire" dbConn.EditTask(task.Id, txtTitle.Text, txtDescription.Text, deadline, chkImportant.Checked ? 1 : 0, currentTopic.Id); // Reloads tasks in the main form mainForm.LoadTasks(); // Closes the window this.Close(); } } }