protected void GrdRegistration_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("Insert"))
        {
            DropDownList ddlReferrer           = (DropDownList)GrdRegistration.FooterRow.FindControl("ddlNewReferrer");
            TextBox      txtProviderNumber     = (TextBox)GrdRegistration.FooterRow.FindControl("txtNewProviderNumber");
            DropDownList ddlIsClinic           = (DropDownList)GrdRegistration.FooterRow.FindControl("ddlNewIsClinic");
            CheckBox     chkIsReportEveryVisit = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIsReportEveryVisit");
            CheckBox     chkIsBatchSendAllPatientsTreatmentNotes = (CheckBox)GrdRegistration.FooterRow.FindControl("chkNewIsBatchSendAllPatientsTreatmentNotes");

            Organisation org = OrganisationDB.GetByID(GetFormID());
            if (org == null)
            {
                HideTableAndSetErrorMessage("");
                return;
            }

            try
            {
                RegisterReferrerDB.Insert(org.OrganisationID, Convert.ToInt32(ddlReferrer.SelectedValue), txtProviderNumber.Text, chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);
            }
            catch (UniqueConstraintException)
            {
                // happens when 2 forms allow adding - do nothing and let form re-update
            }
            FillGrid();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        // need to be able to roll back .. so keep id's same as invoice

        int  person_id      = -1;
        int  referrer_id    = -1;
        int  new_org_id     = 0;
        bool referrer_added = false;

        int  address_id     = -1;
        int  phone_id1      = -1;
        int  phone_id2      = -1;
        int  email_id       = -1;
        bool contacts_added = false;

        try
        {
            // add referrer
            if (lblId.Text == "-1") // add new referrer
            {
                Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"]));
                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));
                referrer_id = ReferrerDB.Insert(person_id);
            }
            else  // set existing referrer
            {
                referrer_id = Convert.ToInt32(lblId.Text);
            }


            // get org (or add new org)
            int org_id = 0;
            if (orgsListRow.Visible)
            {
                org_id = Convert.ToInt32(ddlOrgsList.SelectedValue);
            }
            else
            {
                org_id = new_org_id = OrganisationDB.InsertExtOrg(191, txtOrgName.Text, txtOrgACN.Text, txtOrgABN.Text, false, false, "", txtOrgComments.Text);

                // add contact info

                Organisation org = OrganisationDB.GetByID(org_id);

                if (Utilities.GetAddressType().ToString() == "Contact")
                {
                    if (txtAddressAddrLine1.Text.Trim().Length > 0 || txtAddressAddrLine2.Text.Trim().Length > 0)
                    {
                        address_id = ContactDB.Insert(org.EntityID,
                                                      Convert.ToInt32(ddlAddressContactType.SelectedValue),
                                                      txtAddressFreeText.Text,
                                                      txtAddressAddrLine1.Text,
                                                      txtAddressAddrLine2.Text,
                                                      Convert.ToInt32(ddlAddressAddressChannel.SelectedValue),
                                                      //Convert.ToInt32(ddlAddressSuburb.SelectedValue),
                                                      Convert.ToInt32(suburbID.Value),
                                                      Convert.ToInt32(ddlAddressCountry.SelectedValue),
                                                      Convert.ToInt32(Session["SiteID"]),
                                                      true,
                                                      true);
                    }

                    if (txtPhoneNumber1.Text.Trim().Length > 0)
                    {
                        phone_id1 = ContactDB.Insert(org.EntityID,
                                                     Convert.ToInt32(ddlPhoneNumber1.SelectedValue),
                                                     txtPhoneNumber1FreeText.Text,
                                                     System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber1.Text, "[^0-9]", ""),
                                                     string.Empty,
                                                     -1,
                                                     -1,
                                                     -1,
                                                     Convert.ToInt32(Session["SiteID"]),
                                                     true,
                                                     true);
                    }

                    if (txtPhoneNumber2.Text.Trim().Length > 0)
                    {
                        phone_id2 = ContactDB.Insert(org.EntityID,
                                                     Convert.ToInt32(ddlPhoneNumber2.SelectedValue),
                                                     txtPhoneNumber2FreeText.Text,
                                                     System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber2.Text, "[^0-9]", ""),
                                                     string.Empty,
                                                     -1,
                                                     -1,
                                                     -1,
                                                     Convert.ToInt32(Session["SiteID"]),
                                                     true,
                                                     true);
                    }

                    if (txtEmailAddrLine1.Text.Trim().Length > 0)
                    {
                        email_id = ContactDB.Insert(org.EntityID,
                                                    Convert.ToInt32(ddlEmailContactType.SelectedValue),
                                                    "",
                                                    txtEmailAddrLine1.Text,
                                                    string.Empty,
                                                    -1,
                                                    -1,
                                                    -1,
                                                    Convert.ToInt32(Session["SiteID"]),
                                                    true,
                                                    true);
                    }
                }
                else if (Utilities.GetAddressType().ToString() == "ContactAus")
                {
                    if (txtAddressAddrLine1.Text.Trim().Length > 0 || txtAddressAddrLine2.Text.Trim().Length > 0)
                    {
                        address_id = ContactAusDB.Insert(org.EntityID,
                                                         Convert.ToInt32(ddlAddressContactType.SelectedValue),
                                                         txtAddressFreeText.Text,
                                                         txtAddressAddrLine1.Text,
                                                         txtAddressAddrLine2.Text,
                                                         txtStreet.Text,
                                                         Convert.ToInt32(ddlAddressAddressChannelType.SelectedValue),
                                                         //Convert.ToInt32(ddlAddressSuburb.SelctedValue),
                                                         Convert.ToInt32(suburbID.Value),
                                                         Convert.ToInt32(ddlAddressCountry.SelectedValue),
                                                         Convert.ToInt32(Session["SiteID"]),
                                                         true,
                                                         true);
                    }

                    if (txtPhoneNumber1.Text.Trim().Length > 0)
                    {
                        phone_id1 = ContactAusDB.Insert(org.EntityID,
                                                        Convert.ToInt32(ddlPhoneNumber1.SelectedValue),
                                                        txtPhoneNumber1FreeText.Text,
                                                        System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber1.Text, "[^0-9]", ""),
                                                        string.Empty,
                                                        string.Empty,
                                                        -1,
                                                        -1,
                                                        -1,
                                                        Convert.ToInt32(Session["SiteID"]),
                                                        true,
                                                        true);
                    }

                    if (txtPhoneNumber2.Text.Trim().Length > 0)
                    {
                        phone_id2 = ContactAusDB.Insert(org.EntityID,
                                                        Convert.ToInt32(ddlPhoneNumber2.SelectedValue),
                                                        txtPhoneNumber2FreeText.Text,
                                                        System.Text.RegularExpressions.Regex.Replace(txtPhoneNumber2.Text, "[^0-9]", ""),
                                                        string.Empty,
                                                        string.Empty,
                                                        -1,
                                                        -1,
                                                        -1,
                                                        Convert.ToInt32(Session["SiteID"]),
                                                        true,
                                                        true);
                    }

                    if (txtEmailAddrLine1.Text.Trim().Length > 0)
                    {
                        email_id = ContactAusDB.Insert(org.EntityID,
                                                       Convert.ToInt32(ddlEmailContactType.SelectedValue),
                                                       "",
                                                       txtEmailAddrLine1.Text,
                                                       string.Empty,
                                                       string.Empty,
                                                       -1,
                                                       -1,
                                                       -1,
                                                       Convert.ToInt32(Session["SiteID"]),
                                                       true,
                                                       true);
                    }
                }
                else
                {
                    throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
                }
            }

            contacts_added = true;

            // join association
            RegisterReferrerDB.Insert(org_id, referrer_id, txtProviderNumber.Text, chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);
            referrer_added = true;


            if (GetUrlIsPopup())
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
            else
            {
                Response.Redirect("~/ReferrerList_DoctorClinicV2.aspx?surname_search=" + Utilities.FormatName(txtSurname.Text) + "&surname_starts_with=1", false);
                return;
            }
        }
        catch (Exception)
        {
            // roll back - backwards of creation order

            if (Utilities.GetAddressType().ToString() == "Contact")
            {
                ContactDB.Delete(address_id);
                ContactDB.Delete(phone_id1);
                ContactDB.Delete(phone_id2);
                ContactDB.Delete(email_id);
            }
            else if (Utilities.GetAddressType().ToString() == "ContactAus")
            {
                ContactAusDB.Delete(address_id);
                ContactAusDB.Delete(phone_id1);
                ContactAusDB.Delete(phone_id2);
                ContactAusDB.Delete(email_id);
            }
            else
            {
                throw new Exception("Unknown AddressType in config: " + Utilities.GetAddressType().ToString().ToString());
            }

            OrganisationDB.Delete(new_org_id);
            ReferrerDB.Delete(referrer_id);
            PersonDB.Delete(person_id);

            throw;
        }
    }
Example #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);
            }
        }
    }
    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");

            TextBox txtName = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewName");
            TextBox txtABN  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewABN");
            TextBox txtACN  = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewACN");

            TextBox      txtProviderNumber     = (TextBox)GrdReferrer.FooterRow.FindControl("txtNewProviderNumber");
            DropDownList ddlIsClinic           = (DropDownList)GrdReferrer.FooterRow.FindControl("ddlNewIsClinic");
            CheckBox     chkIsReportEveryVisit = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsReportEveryVisit");
            CheckBox     chkIsBatchSendAllPatientsTreatmentNotes = (CheckBox)GrdReferrer.FooterRow.FindControl("chkNewIsBatchSendAllPatientsTreatmentNotes");


            int person_id            = -1;
            int referrer_id          = -1;
            int organisation_id      = 0;
            int register_referrer_id = -1;

            try
            {
                Staff loggedInStaff = StaffDB.GetByID(Convert.ToInt32(Session["StaffID"]));
                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));
                referrer_id          = ReferrerDB.Insert(person_id);
                organisation_id      = OrganisationDB.InsertExtOrg(191, txtName.Text, txtACN.Text, txtABN.Text, false, false, "", "");
                register_referrer_id = RegisterReferrerDB.Insert(organisation_id, referrer_id, txtProviderNumber.Text, chkIsReportEveryVisit.Checked, chkIsBatchSendAllPatientsTreatmentNotes.Checked);

                FillGrid();
            }
            catch (Exception)
            {
                // roll back - backwards of creation order
                RegisterReferrerDB.Delete(register_referrer_id);
                OrganisationDB.Delete(organisation_id);
                ReferrerDB.Delete(referrer_id);
                PersonDB.Delete(person_id);
            }
        }

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

            try
            {
                if (e.CommandName.Equals("_Delete"))
                {
                    RegisterReferrerDB.UpdateInactive(register_referrer_id);
                }
                else
                {
                    RegisterReferrerDB.UpdateActive(register_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();
        }
    }