コード例 #1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            if ((int)comboBoxAcademicYear.SelectedValue == -1)
            {
                AcademicYear year = new AcademicYear {
                    Year = dateTimePicker1.Value.ToString("yyyy"), IsCurrent = checkBoxIsCurrent.Checked
                };
                if (CheckAcademicYearExists(year.Year))
                {
                    ProcessInvalid(labelAcademicYear);
                    MessageBox.Show("Academic year already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (_settingService.AddAcademicYear(year))
                {
                    LoadData();
                    ProcessValid(labelAcademicYear);
                    comboBoxAcademicYear.SelectedValue = year.YearId;
                    MessageBox.Show("Data Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("error");
                }
            }
            else
            {
                AcademicYear year = new AcademicYear {
                    YearId = (int)comboBoxAcademicYear.SelectedValue, Year = dateTimePicker1.Value.ToString("yyyy"), IsCurrent = checkBoxIsCurrent.Checked
                };
                if (CheckAcademicYearExistsForUpdate())
                {
                    ProcessInvalid(labelAcademicYear);
                    MessageBox.Show("Academic year already exists!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                else if (!year.IsCurrent && _settingService.CheckAtLeastOneCurrentYear(year.YearId))
                {
                    ProcessInvalid(labelCurrent);
                    MessageBox.Show("System must have at least one current academic year", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (_settingService.UpdateAcademicYear(year))
                {
                    LoadData();
                    ProcessValid(labelAcademicYear);
                    ProcessValid(labelCurrent);
                    comboBoxAcademicYear.SelectedValue = year.YearId;
                    MessageBox.Show("Data Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("error");
                }
            }
        }