protected void GrdReferrer_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblId = (Label)GrdReferrer.Rows[e.RowIndex].FindControl("lblId");

        try
        {
            ReferrerDB.UpdateInactive(Convert.ToInt32(lblId.Text));
        }
        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();
    }
    protected void GrdReferrer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            DropDownList ddlTitle      = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewTitle");
            TextBox      txtFirstname  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewFirstname");
            TextBox      txtMiddlename = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewMiddlename");
            TextBox      txtSurname    = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewSurname");
            DropDownList ddlGender     = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewGender");

            txtFirstname.Text  = txtFirstname.Text.Trim();
            txtMiddlename.Text = txtMiddlename.Text.Trim();
            txtSurname.Text    = txtSurname.Text.Trim();

            if (txtSurname.Text.Length == 0)
            {
                SetErrorMessage("Surname can not be empty");
                return;
            }
            if (txtSurname.Text.Length == 0)
            {
                SetErrorMessage("Firstname can not be empty");
                return;
            }

            Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"]));
            int   person_id     = PersonDB.Insert(loggedInStaff.Person.PersonID, Convert.ToInt32(ddlTitle.SelectedValue), Utilities.FormatName(txtFirstname.Text), Utilities.FormatName(txtMiddlename.Text), Utilities.FormatName(txtSurname.Text), "", ddlGender.SelectedValue, new DateTime(1900, 1, 1));
            ReferrerDB.Insert(person_id);

            FillGrid();

            SetErrorMessage("Added.");
        }

        if (e.CommandName.Equals("_Delete") || e.CommandName.Equals("_UnDelete"))
        {
            try
            {
                // if getting referers of an org, set the reg-ref relationship as active/inactive
                if (Request.QueryString["org"] != null)
                {
                    int reg_ref_id = Convert.ToInt32(e.CommandArgument);

                    if (e.CommandName.Equals("_Delete"))
                    {
                        RegisterReferrerDB.UpdateInactive(reg_ref_id);
                    }
                    else
                    {
                        RegisterReferrerDB.UpdateActive(reg_ref_id);
                    }
                }

                // if getting all referrers, set the ref as active/inactive
                else
                {
                    int referrer_id = Convert.ToInt32(e.CommandArgument);

                    if (e.CommandName.Equals("_Delete"))
                    {
                        ReferrerDB.UpdateInactive(referrer_id);
                    }
                    else
                    {
                        ReferrerDB.UpdateActive(referrer_id);
                    }
                }
            }
            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();
        }

        if (e.CommandName.Equals("ViewPatients"))
        {
            int id = Convert.ToInt32(e.CommandArgument);

            if (Request.QueryString["org"] == null)
            {
                FillGrid_Patients(typeof(Referrer), id);
            }
            else
            {
                FillGrid_Patients(typeof(RegisterReferrer), id);
            }
        }
    }
예제 #3
0
    protected void GrdReferrer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            DropDownList ddlRefs               = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewRefs");
            TextBox      txtProviderNumber     = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewProviderNumber");
            CheckBox     chkIsReportEveryVisit = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsReportEveryVisit");
            CheckBox     chkIsBatchSendAllPatientsTreatmentNotes = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsBatchSendAllPatientsTreatmentNotes");

            if (RegisterReferrerDB.Exists(Convert.ToInt32(Request.QueryString["org"]), Convert.ToInt32(ddlRefs.SelectedValue)))
            {
                SetErrorMessage("Clinic is already linked to " + ddlRefs.SelectedItem.Text + ". If it is not visible, use the 'show deleted' checkbox and un-delete it.");
                return;
            }

            RegisterReferrerDB.Insert(Convert.ToInt32(Request.QueryString["org"]), Convert.ToInt32(ddlRefs.SelectedValue), txtProviderNumber.Text.Trim(), chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);

            FillGrid();
        }

        if (e.CommandName.Equals("_Delete") || e.CommandName.Equals("_UnDelete"))
        {
            try
            {
                // if getting referers of an org, set the reg-ref relationship as active/inactive
                if (Request.QueryString["org"] != null)
                {
                    int reg_ref_id = Convert.ToInt32(e.CommandArgument);

                    if (e.CommandName.Equals("_Delete"))
                    {
                        RegisterReferrerDB.UpdateInactive(reg_ref_id);
                    }
                    else
                    {
                        RegisterReferrerDB.UpdateActive(reg_ref_id);
                    }
                }

                // if getting all referrers, set the ref as active/inactive
                else
                {
                    int referrer_id = Convert.ToInt32(e.CommandArgument);

                    if (e.CommandName.Equals("_Delete"))
                    {
                        ReferrerDB.UpdateInactive(referrer_id);
                    }
                    else
                    {
                        ReferrerDB.UpdateActive(referrer_id);
                    }
                }
            }
            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();
        }

        if (e.CommandName.Equals("ViewPatients"))
        {
            int id = Convert.ToInt32(e.CommandArgument);

            if (Request.QueryString["org"] == null)
            {
                FillGrid_Patients(typeof(Referrer), id);
            }
            else
            {
                FillGrid_Patients(typeof(RegisterReferrer), id);
            }
        }
    }