Beispiel #1
0
    /// <summary>
    /// Validates form data and returns TRUE if succeeded, otherwise returns FALSE.
    /// </summary>
    public bool ValidateData()
    {
        if (plcSKUControls.Visible)
        {
            string error = "";

            if (!SKUInfoProvider.LicenseVersionCheck(URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce, VersionActionEnum.Insert))
            {
                error = GetString("ecommerceproduct.versioncheck");
            }

            // If global meta files should be stored in filesystem
            if ((error == "") && ucMetaFile.Visible && (ucMetaFile.PostedFile != null) && MetaFileInfoProvider.StoreFilesInFileSystem(null))
            {
                // Get product image path
                string path = MetaFileInfoProvider.GetFilesFolderPath(null);

                // Check permission for image folder
                if (!DirectoryHelper.CheckPermissions(path))
                {
                    error = String.Format(GetString("com.newproduct.accessdeniedtopath"), path);
                }
            }


            // Validate SKU name
            if ((error == "") && (txtSKUName.Visible) && (txtSKUName.Text.Trim() == ""))
            {
                // SKU name not entered
                error = GetString("com.newproduct.skunameempty");
            }


            if (error == "")
            {
                // Validate SKU price
                if (txtSKUPrice.Visible)
                {
                    error = txtSKUPrice.ValidatePrice(false);
                }
            }

            // Show error message
            if (error != "")
            {
                lblError.Visible = true;
                lblError.Text    = error;
                return(false);
            }
        }
        return(true);
    }
    /// <summary>
    /// Validates user input data and returns the result.
    /// </summary>
    /// <param name="codeName">A code name of the media library.</param>
    private bool ValidateForm(string codeName)
    {
        bool result = true;

        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtDescription.Text = txtDescription.Text.Trim();
        txtFolder.Text      = URLHelper.GetSafeFileName(txtFolder.Text.Trim(), CMSContext.CurrentSiteName);

        List <Validator> validators = new List <Validator>(7);

        validators.Add(new Validator().NotEmpty(txtDisplayName.Text, GetString("general.requiresdisplayname")));
        validators.Add(new Validator().NotEmpty(codeName, GetString("general.requirescodename")).IsCodeName(codeName, GetString("general.invalidcodename")).MatchesCondition(codeName, x => IsCodeNameUnique(x), GetString("general.codenameexists")));
        if (txtFolder.Enabled)
        {
            validators.Add(new Validator().NotEmpty(txtFolder.Text, GetString("media.error.FolderNameIsEmpty")).IsFolderName(txtFolder.Text, GetString("media.error.FolderNameIsNotValid")).MatchesCondition(txtFolder.Text, x => x != "." && x != "..", GetString("media.error.FolderNameIsRelative")).MatchesCondition(txtFolder.Text, x => IsFolderNameUnique(x), GetString("media.error.FolderExists")));
        }
        Validator teaserValidator = new Validator().MatchesCondition(ucMetaFile.IsValid(), x => x, ucMetaFile.ValidationError);

        if (!teaserValidator.IsValid && (ucMetaFile.PostedFile != null) && MetaFileInfoProvider.StoreFilesInFileSystem(CMSContext.CurrentSiteName))
        {
            string path = MetaFileInfoProvider.GetFilesFolderPath(CMSContext.CurrentSiteName);
            teaserValidator = teaserValidator.MatchesCondition(path, x => CanStoreTeaser(path), String.Format(GetString("media.AccessDeniedToPath"), path));
        }
        validators.Add(teaserValidator);

        foreach (Validator validator in validators)
        {
            if (!validator.IsValid)
            {
                AddError(HTMLHelper.HTMLEncode(validator.Result), null);
                result = false;
            }
        }

        return(result);
    }
Beispiel #3
0
    private bool Validate()
    {
        string errorMessage = String.Empty;

        // Validate name
        errorMessage = new Validator().NotEmpty(this.txtSKUName.Text.Trim(), this.rfvSKUName.ErrorMessage).Result;

        if (!String.IsNullOrEmpty(errorMessage))
        {
            this.ErrorMessage = errorMessage;
            return(false);
        }

        // Validate price
        errorMessage = this.txtSKUPrice.ValidatePrice(this.OptionCategoryID > 0);

        if (!String.IsNullOrEmpty(errorMessage))
        {
            this.ErrorMessage = errorMessage;
            return(false);
        }

        // If global meta files should be stored in filesystem
        if (this.ucMetaFile.Visible && (this.ucMetaFile.PostedFile != null) && MetaFileInfoProvider.StoreFilesInFileSystem(null))
        {
            // Get product image path
            string path = MetaFileInfoProvider.GetFilesFolderPath(null);

            // Check permission for image folder
            if (!DirectoryHelper.CheckPermissions(path))
            {
                this.ErrorMessage = String.Format(this.GetString("com.newproduct.accessdeniedtopath"), path);
                return(false);
            }
        }

        // Validate product type specific properties
        switch (SKUInfoProvider.GetSKUProductTypeEnum((string)this.selectProductTypeElem.Value))
        {
        case SKUProductTypeEnum.Membership:
            errorMessage = this.membershipElem.Validate();
            break;

        case SKUProductTypeEnum.EProduct:
            errorMessage = this.eProductElem.Validate();
            break;

        case SKUProductTypeEnum.Donation:
            errorMessage = this.donationElem.Validate();

            // If price does not fall into the range specified by minimum and maximum donation amount
            if (((this.donationElem.MinimumDonationAmount > 0.0) && (this.txtSKUPrice.Value < this.donationElem.MinimumDonationAmount)) ||
                ((this.donationElem.MaximumDonationAmount > 0.0) && (this.txtSKUPrice.Value > this.donationElem.MaximumDonationAmount)))
            {
                this.ErrorMessage = this.GetString("com.productedit.donationpriceinvalid");
                return(false);
            }
            break;

        case SKUProductTypeEnum.Bundle:
            errorMessage = this.bundleElem.Validate();
            break;
        }

        if (!String.IsNullOrEmpty(errorMessage))
        {
            this.ErrorMessage = errorMessage;
            return(false);
        }

        string temp = String.Empty;

        // Validate weight
        temp = this.txtSKUWeight.Text.Trim();
        if (!String.IsNullOrEmpty(temp))
        {
            double skuWeight = ValidationHelper.GetDouble(temp, 0);

            if ((skuWeight == 0) || (!ValidationHelper.IsPositiveNumber(temp)))
            {
                this.ErrorMessage = this.GetString("com.productedit.packageweightinvalid");
                return(false);
            }
        }

        // Validate height
        temp = this.txtSKUHeight.Text.Trim();
        if (!String.IsNullOrEmpty(temp))
        {
            double skuHeight = ValidationHelper.GetDouble(temp, 0);

            if ((skuHeight == 0) || (!ValidationHelper.IsPositiveNumber(temp)))
            {
                this.ErrorMessage = this.GetString("com.productedit.packageheightinvalid");
                return(false);
            }
        }

        // Validate width
        temp = this.txtSKUWidth.Text.Trim();
        if (!String.IsNullOrEmpty(temp))
        {
            double skuWidth = ValidationHelper.GetDouble(temp, 0);

            if ((skuWidth == 0) || (!ValidationHelper.IsPositiveNumber(temp)))
            {
                this.ErrorMessage = this.GetString("com.productedit.packagewidthinvalid");
                return(false);
            }
        }

        // Validate depth
        temp = this.txtSKUDepth.Text.Trim();
        if (!String.IsNullOrEmpty(temp))
        {
            double skuDepth = ValidationHelper.GetDouble(temp, 0);

            if ((skuDepth == 0) || (!ValidationHelper.IsPositiveNumber(temp)))
            {
                this.ErrorMessage = this.GetString("com.productedit.packagedepthinvalid");
                return(false);
            }
        }

        // Validate available items
        temp = this.txtSKUAvailableItems.Text.Trim();
        if (!String.IsNullOrEmpty(temp) && !ValidationHelper.IsInteger(temp))
        {
            this.ErrorMessage = this.GetString("com.productedit.availableitemsinvalid");
            return(false);
        }

        // Validate availability
        temp = this.txtSKUAvailableInDays.Text.Trim();
        if (!String.IsNullOrEmpty(temp) && !ValidationHelper.IsInteger(temp))
        {
            this.ErrorMessage = this.GetString("com.productedit.availabilityinvalid");
            return(false);
        }

        // Validate max items in one order
        temp = this.txtMaxOrderItems.Text.Trim();
        if (!String.IsNullOrEmpty(temp) && (!ValidationHelper.IsInteger(temp) || (ValidationHelper.GetInteger(temp, 0) <= 0)))
        {
            this.ErrorMessage = this.GetString("com.productedit.maxorderitemsinvalid");
            return(false);
        }

        // Validate conversion name
        if (!ucConversion.IsValid())
        {
            this.ErrorMessage = GetString("conversion.validcodename");
            return(false);
        }

        // Form is valid
        return(true);
    }
Beispiel #4
0
    /// <summary>
    /// Validates input data and returns true if input is valid.
    /// </summary>
    /// <param name="codeName">Code name</param>
    protected bool ValidateForm(string codeName)
    {
        txtDisplayName.Text = txtDisplayName.Text.Trim();
        txtDescription.Text = txtDescription.Text.Trim();
        txtFolder.Text      = URLHelper.GetSafeFileName(txtFolder.Text.Trim(), CMSContext.CurrentSiteName);

        string result = new Validator().NotEmpty(txtDisplayName.Text, rfvDisplayName.ErrorMessage)
                        .NotEmpty(txtDisplayName.Text, rfvCodeName.ErrorMessage)
                        .IsCodeName(codeName, GetString("general.invalidcodename")).Result;

        // Folder name is enabled check it
        if ((String.IsNullOrEmpty(result)) && (this.txtFolder.Enabled))
        {
            result = new Validator().NotEmpty(txtFolder.Text, rfvFolder.ErrorMessage)
                     .IsFolderName(txtFolder.Text, GetString("media.invalidfoldername")).Result;

            if (String.IsNullOrEmpty(result))
            {
                // Check special folder names
                if ((this.txtFolder.Text == ".") || (this.txtFolder.Text == ".."))
                {
                    result = GetString("media.folder.foldernameerror");
                }
            }
        }

        // Check for duplicit records within current site
        MediaLibraryInfo mli = null;

        if (this.MediaLibraryGroupID > 0)
        {
            mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteID, this.MediaLibraryGroupID);
        }
        else
        {
            mli = MediaLibraryInfoProvider.GetMediaLibraryInfo(codeName, CMSContext.CurrentSiteName);
        }
        if ((mli != null) && (mli.LibraryID != this.MediaLibraryID))
        {
            result = GetString("general.codenameexists");
        }

        // Check for duplicit library root folder
        DataSet ds = MediaLibraryInfoProvider.GetMediaLibraries("LibraryFolder = '" + txtFolder.Text.Trim().Replace("'", "''") + "' AND LibrarySiteID = " + CMSContext.CurrentSiteID, null);

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            int libraryId = ValidationHelper.GetInteger(ds.Tables[0].Rows[0]["LibraryID"], 0);
            if (this.MediaLibraryID != libraryId)
            {
                result = GetString("media.folderexists");
            }
        }

        // If meta files should be stored in filesystem for given site
        if ((ucMetaFile.PostedFile != null) && MetaFileInfoProvider.StoreFilesInFileSystem(CMSContext.CurrentSiteName))
        {
            // Get image path for site
            string path = MetaFileInfoProvider.GetFilesFolderPath(CMSContext.CurrentSiteName);

            // Ensure meta files folder
            if (!Directory.Exists(path))
            {
                DirectoryHelper.EnsureDiskPath(path, SettingsKeyProvider.WebApplicationPhysicalPath);
            }

            // Check permission for image folder
            if (!DirectoryHelper.CheckPermissions(path))
            {
                result = String.Format(GetString("media.AccessDeniedToPath"), path);
            }
        }

        if (result != String.Empty)
        {
            lblError.Visible = true;
            lblError.Text    = HTMLHelper.HTMLEncode(result);
            return(false);
        }

        return(true);
    }