Esempio n. 1
0
    protected void buttonUpdateCourse_OnClick(object sender, EventArgs e)
    {
        if (String.IsNullOrEmpty(textBoxCourseTitleUpd.Text) || ddCourses.SelectedValue == Guid.Empty.ToString())
        {
            Utils.displayStatus(ref labelStatusEdit, Color.Red, "Mangler informasjon");
            return;
        }

        try
        {
            Database.Interface.open();

            Database.Course course = new Database.Course();
            if (!course.select_all_where_ID(new Guid(ddCourses.SelectedValue)))
            {
                Utils.displayStatus(ref labelStatusEdit, Color.Red, "Kurs '" + ddCourses.SelectedItem.Text + "' ikke funnet");
                return;
            }

            course.Title       = textBoxCourseTitleUpd.Text;
            course.Description = textBoxCourseDescriptionUpd.Text;
            course.Comment     = textBoxCourseCommentUpd.Text;
            course.Completed   = checkBoxCourseCompleteUpd.Checked;

            if (!course.update_all_by_ID())
            {
                Utils.displayStatus(ref labelStatusEdit, Color.Red, "Oppdatering av kurs feilet");
                return;
            }

            Utils.displayStatus(ref labelStatusEdit, Color.SeaGreen, "Kurs '" + textBoxCourseTitleUpd.Text + "' oppdatert");

            textBoxCourseTitleUpd.Text        = "";
            textBoxCourseDescriptionUpd.Text  = "";
            textBoxCourseCommentUpd.Text      = "";
            checkBoxCourseCompleteUpd.Checked = false;
            lbMembers.Items.Clear();

            ddCourses.DataBind();
            gridShowCourses.DataBind();
        }
        catch (Exception ex)
        {
            Utils.displayStatus(ref labelStatusEdit, Color.Red, ex.Message);
        }
        finally
        {
            Database.Interface.close();
        }
    }