protected void GrdRegistration_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label lblId = (Label)GrdRegistration.Rows[e.RowIndex].FindControl("lblId"); DropDownList ddlOrganisation = (DropDownList)GrdRegistration.Rows[e.RowIndex].FindControl("ddlOrganisation"); TextBox txtProviderNumber = (TextBox)GrdRegistration.Rows[e.RowIndex].FindControl("txtProviderNumber"); CheckBox chkMainProvider = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkMainProvider"); CheckBox chkIncMondays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncMondays"); CheckBox chkIncTuesdays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncTuesdays"); CheckBox chkIncWednesdays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncWednesdays"); CheckBox chkIncThursdays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncThursdays"); CheckBox chkIncFridays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncFridays"); CheckBox chkIncSaturdays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncSaturdays"); CheckBox chkIncSundays = (CheckBox)GrdRegistration.Rows[e.RowIndex].FindControl("chkIncSundays"); Staff staff = StaffDB.GetByID(GetFormID()); if (staff == null) { HideTableAndSetErrorMessage(""); return; } RegisterStaffDB.Update(Convert.ToInt32(lblId.Text), 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); } GrdRegistration.EditIndex = -1; FillGrid(); }
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(); } }