コード例 #1
0
    protected void GrdRegistration_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblId = (Label)GrdRegistration.FooterRow.FindControl("lblId");

        RegisterStaff registerStaff = RegisterStaffDB.GetByID(Convert.ToInt32(lblId.Text));

        if (BookingDB.GetCountByProviderAndOrg(registerStaff.Staff.StaffID, registerStaff.Organisation.OrganisationID) > 0)
        {
            SetErrorMessage("Can not remove registration of '" + registerStaff.Staff.Person.FullnameWithoutMiddlename + "' to '" + registerStaff.Organisation.Name + "' because there exists a booking for this provider there.");
            return;
        }

        try
        {
            RegisterStaffDB.UpdateInactive(Convert.ToInt32(lblId.Text), false);
        }
        catch (ForeignKeyConstraintException fkcEx)
        {
            if (Utilities.IsDev())
            {
                HideTableAndSetErrorMessage("Can not delete because other records depend on this : " + fkcEx.Message);
            }
            else
            {
                HideTableAndSetErrorMessage("Can not delete because other records depend on this");
            }
        }

        FillGrid();
    }
コード例 #2
0
    protected void GrdRegistration_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            DropDownList ddlOrganisation   = (DropDownList)GrdRegistration.FooterRow.FindControl("ddlNewOrganisation");
            TextBox      txtProviderNumber = (TextBox)GrdRegistration.FooterRow.FindControl("txtNewProviderNumber");
            CheckBox     chkMainProvider   = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewMainProvider");
            CheckBox     chkIncMondays     = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncMondays");
            CheckBox     chkIncTuesdays    = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncTuesdays");
            CheckBox     chkIncWednesdays  = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncWednesdays");
            CheckBox     chkIncThursdays   = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncThursdays");
            CheckBox     chkIncFridays     = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncFridays");
            CheckBox     chkIncSaturdays   = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncSaturdays");
            CheckBox     chkIncSundays     = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIncSundays");


            Staff staff = StaffDB.GetByID(GetFormID());
            if (staff == null)
            {
                HideTableAndSetErrorMessage("");
                return;
            }

            try
            {
                RegisterStaffDB.Insert(Convert.ToInt32(ddlOrganisation.SelectedValue), staff.StaffID, txtProviderNumber.Text, chkMainProvider.Checked,
                                       !chkIncSundays.Checked, !chkIncMondays.Checked, !chkIncTuesdays.Checked, !chkIncWednesdays.Checked, !chkIncThursdays.Checked, !chkIncFridays.Checked, !chkIncSaturdays.Checked);
                if (chkMainProvider.Checked)
                {
                    RegisterStaffDB.UpdateAllOtherStaffAsNotMainProviders(Convert.ToInt32(ddlOrganisation.SelectedValue), staff.StaffID);
                }
            }
            catch (UniqueConstraintException)
            {
                // happens when 2 forms allow adding - do nothing and let form re-update
            }
            FillGrid();
        }

        if (e.CommandName.Equals("_Delete") || e.CommandName.Equals("_UnDelete"))
        {
            int register_staff_id = Convert.ToInt32(e.CommandArgument);

            try
            {
                if (e.CommandName.Equals("_Delete"))
                {
                    RegisterStaffDB.UpdateInactive(register_staff_id);
                }
                else
                {
                    RegisterStaffDB.UpdateActive(register_staff_id);
                }
            }
            catch (CustomMessageException cmEx)
            {
                SetErrorMessage(cmEx.Message);
            }
            catch (ForeignKeyConstraintException fkcEx)
            {
                if (Utilities.IsDev())
                {
                    SetErrorMessage("Can not delete because other records depend on this : " + fkcEx.Message);
                }
                else
                {
                    SetErrorMessage("Can not delete because other records depend on this");
                }
            }

            FillGrid();
        }
    }