private void SaveDataInForm() { if (VerifyData()) { Assignment temp = new Assignment(); temp.name = TextBoxName.Text; temp.catIndex = GetCatIndex(ComboBoxCats.Text); temp.points = Convert.ToDouble(TextBoxPoints.Text); temp.outOf = Convert.ToDouble(TextBoxOutOf.Text); temp.real = RadioButtonReal.Checked; temp.active = CheckBoxActive.Checked; temp.meanPoints = 0.0; if (ErrorChecking.TextIsType("double", TextBoxMeanPoints.Text)) { temp.meanPoints = Convert.ToDouble(TextBoxMeanPoints.Text); } //simple edit of the same assignment if (_currentAssignment != null && _currentAssignment.name.Equals(temp.name)) { XMLHandler.SaveAssignmentToFile(_schoolClass, temp, false); } else { //this assignment name already exists, and it is NOT the one we are editing if (XMLHandler.AssignmentFileExists(_schoolClass, temp)) { XMLHandler.SaveAssignmentToFile(_schoolClass, temp); var result = DialogResult.Yes; if (!Settings.AlwaysDeleteOldAssignment) { result = MessageBox.Show("Would you like to delete the assignment with the old name?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); } if (result == DialogResult.Yes) { XMLHandler.DeleteAssignment(_schoolClass, _currentAssignment); } } else { XMLHandler.SaveAssignmentToFile(_schoolClass, temp, warning: false); } } _currentAssignment = temp; FillDataView(); DisplayCellDataInEdit(temp); } }
private void ButtonDelete_Click(object sender, EventArgs e) { Assignment temp = new Assignment(); temp.name = TextBoxName.Text; if (XMLHandler.AssignmentFileExists(_schoolClass, temp)) { var result = MessageBox.Show("Would you like to delete the assignment " + temp.name + "?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { XMLHandler.DeleteAssignment(_schoolClass, temp); if (Settings.WarningLevel > 1) { MessageBox.Show("File deleted!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } FillDataView(); } } }