Example #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (GetUrlParamType() == UrlParamType.View)
        {
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it redirects
            Response.Redirect(UrlParamModifier.AddEdit(Request.RawUrl, "type", "edit"));
        }
        else if (GetUrlParamType() == UrlParamType.Edit)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }
            ContactAus contact = ContactAusDB.GetByID(GetFormID());
            if (contact == null)
            {
                HideTableAndSetErrorMessage("Invalid contact ID");
                return;
            }

            bool isAddress  = contact.ContactType.ContactTypeGroup.ID == 1;
            bool isTelecoms = contact.ContactType.ContactTypeGroup.ID == 2;
            bool isBedroom  = contact.ContactType.ContactTypeGroup.ID == 3;
            bool isWeb      = contact.ContactType.ContactTypeGroup.ID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }



            ContactAusDB.Update(Convert.ToInt32(lblId.Text),
                                Convert.ToInt32(ddlContactType.SelectedValue),
                                txtFreeText.Text,
                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                txtAddrLine2.Text,
                                txtStreet.Text,
                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : (contact.AddressChannelType == null ? -1 : contact.AddressChannelType.ID),
                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)             : (contact.Suburb             == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(suburbID.Value) : (contact.Suburb == null ? -1 : contact.Suburb.SuburbID),
                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : (contact.Country == null ? -1 : contact.Country.ID),
                                contact.Site == null ? Convert.ToInt32(Session["SiteID"]) : contact.Site.SiteID,
                                isAddress || isWeb ? chkIsBilling.Checked    : contact.IsBilling,
                                isAddress || isWeb ? chkIsNonBilling.Checked : contact.IsNonBilling);



            //close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else if (GetUrlParamType() == UrlParamType.Add)
        {
            if (!IsValidFormID())
            {
                HideTableAndSetErrorMessage();
                return;
            }

            int entityID = GetFormID();
            if (!EntityDB.IDExists(entityID))
            {
                HideTableAndSetErrorMessage("Invalid entity ID");
                return;
            }


            int contactTypeGroupID = -1;
            UrlParamContactTypeGroup urlParamContactTypeGroup = GetUrlParamContactTypeGroup();
            if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Mailing)
            {
                contactTypeGroupID = 1;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Telecoms)
            {
                contactTypeGroupID = 2;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Bedroom)
            {
                contactTypeGroupID = 3;
            }
            else if (urlParamContactTypeGroup == UrlParamContactTypeGroup.Internet)
            {
                contactTypeGroupID = 4;
            }
            else
            {
                HideTableAndSetErrorMessage("Invalid contact_group_type ID");
                return;
            }


            bool isAddress  = contactTypeGroupID == 1;
            bool isTelecoms = contactTypeGroupID == 2;
            bool isBedroom  = contactTypeGroupID == 3;
            bool isWeb      = contactTypeGroupID == 4;
            bool isMobile   = Convert.ToInt32(ddlContactType.SelectedValue) == 30;
            bool isPOBox    = Convert.ToInt32(ddlContactType.SelectedValue) == 37 || Convert.ToInt32(ddlContactType.SelectedValue) == 262;

            bool isEmail   = Convert.ToInt32(ddlContactType.SelectedValue) == 27;
            bool isWebsite = Convert.ToInt32(ddlContactType.SelectedValue) == 28;

            txtAddrLine1.Text = txtAddrLine1.Text.Trim();
            if (isMobile && !System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").StartsWith("0"))
            {
                SetErrorMessage("Mobile number must start with 0");
                return;
            }
            if (isTelecoms && System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "").Length > 13)
            {
                SetErrorMessage("Phone number can not be more than 13 digits");
                return;
            }
            if (isEmail && !Utilities.IsValidEmailAddress(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid email address");
                return;
            }
            if (isWebsite && !Utilities.IsValidWebURL(txtAddrLine1.Text))
            {
                SetErrorMessage("Invalid website");
                return;
            }
            if (isPOBox && !Regex.IsMatch(txtAddrLine1.Text, "PO Box", RegexOptions.IgnoreCase) && !Regex.IsMatch(txtAddrLine2.Text, "PO Box", RegexOptions.IgnoreCase))
            {
                SetErrorMessage("The address text must contain \"PO Box\"");
                return;
            }

            int contactID = ContactAusDB.Insert(entityID,
                                                Convert.ToInt32(ddlContactType.SelectedValue),
                                                txtFreeText.Text,
                                                isTelecoms ? System.Text.RegularExpressions.Regex.Replace(txtAddrLine1.Text, "[^0-9]", "") : txtAddrLine1.Text,
                                                txtAddrLine2.Text,
                                                txtStreet.Text,
                                                isAddress ? Convert.ToInt32(ddlAddressChannelType.SelectedValue) : -1,
                                                //isAddress ? Convert.ToInt32(ddlSuburb.SelectedValue)           : -1,
                                                isAddress ? Convert.ToInt32(suburbID.Value) : -1,
                                                isAddress ? Convert.ToInt32(ddlCountry.SelectedValue) : -1,
                                                Convert.ToInt32(Session["SiteID"]),
                                                isAddress || isWeb ? chkIsBilling.Checked    : true,
                                                isAddress || isWeb ? chkIsNonBilling.Checked : true);


            // close this window
            maintable.Visible = false; // hide this so that we don't send all the page data (all suburbs, etc) to display before it closes

            bool refresh_on_close = Request.QueryString["refresh_on_close"] != null && Request.QueryString["refresh_on_close"] == "1";

            if (refresh_on_close)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.opener.location.href=window.opener.location.href;self.close();</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script language=javascript>window.returnValue=false;self.close();</script>");
            }
        }
        else
        {
            HideTableAndSetErrorMessage("", "Invalid URL Parameters");
        }
    }
Example #2
0
    private void FillEditViewForm(bool isEditMode)
    {
        ContactAus contact = ContactAusDB.GetByID(GetFormID());

        if (contact == null)
        {
            HideTableAndSetErrorMessage("Invalid Contact ID");
            return;
        }

        DataTable addrTypes = ContactTypeDB.GetDataTable(contact.ContactType.ContactTypeGroup.ID);

        ddlContactType.DataSource = addrTypes;
        ddlContactType.DataBind();

        string type = "ContactAus";

        if (contact.ContactType.ContactTypeGroup.ID == 1)
        {
            type = "Address";
            lblLine1Descr.Text = "Line 1";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 2)
        {
            type = "Phone Number";
            lblLine1Descr.Text = "Phone Number";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 3)
        {
            type = "Bedroom";
            lblLine1Descr.Text = "Bedroom";
        }
        if (contact.ContactType.ContactTypeGroup.ID == 4)
        {
            type = "Email/Website";
            lblLine1Descr.Text = "Email/Website";
        }
        lblHeading.Text = isEditMode ? "Edit " + type : "View " + type;

        if (contact.ContactType.ContactTypeGroup.ID != 1)
        {
            line2Row.Visible   = false;
            streetRow.Visible  = false;
            suburbRow.Visible  = false;
            countryRow.Visible = false;
            if (contact.ContactType.ContactTypeGroup.ID != 4)
            {
                billingRow.Visible    = false;
                nonbillingRow.Visible = false;
            }
        }

        lblId.Text    = contact.ContactID.ToString();
        idRow.Visible = Utilities.IsDev();


        if (isEditMode)
        {
            ddlContactType.SelectedValue = contact.ContactType.ContactTypeID.ToString();
            txtFreeText.Text             = contact.FreeText;
            txtAddrLine1.Text            = contact.ContactType.ContactTypeGroup.ID == 2 ? Utilities.FormatPhoneNumber(contact.AddrLine1) : contact.AddrLine1;
            txtAddrLine2.Text            = contact.AddrLine2;

            txtStreet.Text = contact.StreetName;
            ddlAddressChannelType.SelectedValue = contact.AddressChannelType == null ? "-1" : contact.AddressChannelType.ID.ToString();
            suburbID.Value           = contact.Suburb == null ? "-1" : contact.Suburb.SuburbID.ToString();
            lblSuburbText.Text       = contact.Suburb == null ? "--" : contact.Suburb.Name + ", " + contact.Suburb.State + " (" + contact.Suburb.Postcode + ")";
            ddlCountry.SelectedValue = contact.Country == null ? "-1" : contact.Country.ID.ToString();
            chkIsBilling.Checked     = contact.IsBilling;
            chkIsNonBilling.Checked  = contact.IsNonBilling;

            lblContactType.Visible        = false;
            lblAddrLine1.Visible          = false;
            lblAddrLine2.Visible          = false;
            lblAddressChannelType.Visible = false;
            lblCountry.Visible            = false;
            lblIsBilling.Visible          = false;
            lblIsNonBilling.Visible       = false;
        }
        else
        {
            lblContactType.Text        = contact.ContactType.Descr;
            lblAddrLine1.Text          = contact.ContactType.ContactTypeGroup.ID == 2 ? Utilities.FormatPhoneNumber(contact.AddrLine1) : contact.AddrLine1;
            lblAddrLine2.Text          = contact.AddrLine2;
            lblStreet.Text             = contact.StreetName;
            lblAddressChannelType.Text = contact.AddressChannelType == null ? string.Empty : contact.AddressChannelType.Descr;
            suburbID.Value             = contact.Suburb == null ? "-1" : contact.Suburb.SuburbID.ToString();
            lblSuburbText.Text         = contact.Suburb == null ? "--" : contact.Suburb.Name + ", " + contact.Suburb.State + " (" + contact.Suburb.Postcode + ")";
            lblSuburbText.Font.Bold    = true;
            lblCountry.Text            = contact.Country == null ? string.Empty : contact.Country.Descr;
            lblIsBilling.Text          = contact.IsBilling ? "Yes" : "No";
            lblIsNonBilling.Text       = contact.IsNonBilling ? "Yes" : "No";

            lnkUpdateType.Visible = false;
            txtValidateAddrLine1Required.Visible = false;

            ddlContactType.Visible        = false;
            txtFreeText.Visible           = false;
            txtAddrLine1.Visible          = false;
            txtAddrLine2.Visible          = false;
            txtStreet.Visible             = false;
            ddlAddressChannelType.Visible = false;
            lnkGetSuburb.Visible          = false;
            lnkClearSuburb.Visible        = false;
            ddlCountry.Visible            = false;
            chkIsBilling.Visible          = false;
            chkIsNonBilling.Visible       = false;
        }



        if (isEditMode)
        {
            btnSubmit.Text = "Update Details";
        }
        else // is view mode
        {
            btnSubmit.Visible = false;
            btnCancel.Text    = "Close";
        }
    }