Exemplo n.º 1
0
    /// <summary>
    /// Sets the data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check module permissions
        bool global = (editedSiteId <= 0);

        if (!ECommerceContext.IsUserAuthorizedToModifySupplier(global))
        {
            if (global)
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
            else
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
            }
        }

        string errorMessage = new Validator().NotEmpty(txtSupplierDisplayName.Text.Trim(), GetString("supplier_Edit.errorEmptyDisplayName")).Result;

        // Validate email format if not empty
        if (errorMessage == "")
        {
            if ((txtSupplierEmail.Text.Trim() != "") && (!ValidationHelper.IsEmail(txtSupplierEmail.Text.Trim())))
            {
                errorMessage = GetString("supplier_Edit.errorEmailFormat");
            }
        }

        if (errorMessage == "")
        {
            SupplierInfo supplierObj = SupplierInfoProvider.GetSupplierInfo(mSupplierId);

            if (supplierObj == null)
            {
                supplierObj = new SupplierInfo();
                // Assign site ID
                supplierObj.SupplierSiteID = ConfiguredSiteID;
            }

            supplierObj.SupplierFax         = txtSupplierFax.Text.Trim();
            supplierObj.SupplierEmail       = txtSupplierEmail.Text.Trim();
            supplierObj.SupplierPhone       = txtSupplierPhone.Text.Trim();
            supplierObj.SupplierDisplayName = txtSupplierDisplayName.Text.Trim();
            supplierObj.SupplierEnabled     = chkSupplierEnabled.Checked;

            // Save changes
            SupplierInfoProvider.SetSupplierInfo(supplierObj);

            URLHelper.Redirect("Supplier_Edit.aspx?supplierid=" + Convert.ToString(supplierObj.SupplierID) + "&saved=1&siteId=" + SiteID);
        }
        else
        {
            lblError.Visible = true;
            lblError.Text    = errorMessage;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Sets the data to database.
    /// </summary>
    protected void btnOK_Click(object sender, EventArgs e)
    {
        // Check module permissions
        bool global = (editedSiteId <= 0);

        if (!ECommerceContext.IsUserAuthorizedToModifySupplier(global))
        {
            if (global)
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceGlobalModify");
            }
            else
            {
                RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifySuppliers");
            }
        }

        string errorMessage = new Validator().
                              NotEmpty(txtSupplierDisplayName.Text.Trim(), GetString("supplier_Edit.errorEmptyDisplayName")).
                              IsCodeName(txtSupplierName.Text.Trim(), GetString("general.invalidcodename")).Result;

        // Validate email format if not empty
        if (errorMessage == "")
        {
            if ((txtSupplierEmail.Text.Trim() != "") && (!ValidationHelper.IsEmail(txtSupplierEmail.Text.Trim())))
            {
                errorMessage = GetString("supplier_Edit.errorEmailFormat");
            }
        }

        if (errorMessage == "")
        {
            SupplierInfo supplierObj = null;

            // Supplier code name must be unique
            string  siteWhere = (ConfiguredSiteID > 0) ? " AND (SupplierSiteID = " + ConfiguredSiteID + " OR SupplierSiteID IS NULL)" : "";
            DataSet ds        = SupplierInfoProvider.GetSuppliers("SupplierName = N'" + SqlHelperClass.GetSafeQueryString(txtSupplierName.Text.Trim(), false) + "'" + siteWhere, null, 1, null);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                supplierObj = new SupplierInfo(ds.Tables[0].Rows[0]);
            }

            if ((supplierObj == null) || (supplierObj.SupplierID == mSupplierId))
            {
                if (supplierObj == null)
                {
                    supplierObj = SupplierInfoProvider.GetSupplierInfo(mSupplierId);
                    if (supplierObj == null)
                    {
                        // Create new supplier
                        supplierObj = new SupplierInfo();
                        supplierObj.SupplierSiteID = ConfiguredSiteID;
                    }
                }

                supplierObj.SupplierFax         = txtSupplierFax.Text.Trim();
                supplierObj.SupplierEmail       = txtSupplierEmail.Text.Trim();
                supplierObj.SupplierPhone       = txtSupplierPhone.Text.Trim();
                supplierObj.SupplierDisplayName = txtSupplierDisplayName.Text.Trim();
                supplierObj.SupplierName        = txtSupplierName.Text.Trim();
                supplierObj.SupplierEnabled     = chkSupplierEnabled.Checked;

                // Save changes
                SupplierInfoProvider.SetSupplierInfo(supplierObj);

                URLHelper.Redirect("Supplier_Edit.aspx?supplierid=" + Convert.ToString(supplierObj.SupplierID) + "&saved=1&siteId=" + SiteID);
            }
            else
            {
                // Show error message
                ShowError(GetString("com.suppliernameexists"));
            }
        }
        else
        {
            // Show error message
            ShowError(errorMessage);
        }
    }