private void btnCreate_Click(object sender, EventArgs e)
 {
     if (this.txtName.Text.Trim().Length > 15)
     {
         string str = string.Format("ShowMsg(\"{0}\", {1});", "属性名称限制在15个字符以内", "false");
         this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str + "},300);</script>");
     }
     else
     {
         AttributeInfo target = new AttributeInfo
         {
             TypeId        = this.typeId,
             AttributeName = Globals.HtmlEncode(this.txtName.Text.Trim())
         };
         if (this.chkMulti.Checked)
         {
             target.UsageMode = AttributeUseageMode.MultiView;
         }
         else
         {
             target.UsageMode = AttributeUseageMode.View;
         }
         if (!string.IsNullOrEmpty(this.txtValues.Text.Trim()))
         {
             string[] strArray = this.txtValues.Text.Trim().Replace(",", ",").Split(new char[] { ',' });
             for (int i = 0; i < strArray.Length; i++)
             {
                 if (strArray[i].Length > 100)
                 {
                     break;
                 }
                 AttributeValueInfo item = new AttributeValueInfo();
                 if (strArray[i].Length > 15)
                 {
                     string str3 = string.Format("ShowMsg(\"{0}\", {1});", "扩展属性的值,每个值的字符数最多15个字符", "false");
                     this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str3 + "},300);</script>");
                     return;
                 }
                 item.ValueStr = Globals.HtmlEncode(strArray[i]);
                 target.AttributeValues.Add(item);
             }
         }
         ValidationResults results = Hishop.Components.Validation.Validation.Validate <AttributeInfo>(target, new string[] { "ValAttribute" });
         string            str4    = string.Empty;
         if (!results.IsValid)
         {
             foreach (ValidationResult result in (IEnumerable <ValidationResult>)results)
             {
                 str4 = str4 + Formatter.FormatErrorMessage(result.Message);
             }
         }
         else if (ProductTypeHelper.AddAttribute(target))
         {
             this.txtName.Text   = string.Empty;
             this.txtValues.Text = string.Empty;
             base.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
         }
     }
 }
Example #2
0
 private void btnCreate_Click(object sender, EventArgs e)
 {
     if (this.txtName.Text.Trim().Length > 15)
     {
         string str = string.Format("ShowMsg(\"{0}\", {1});", "属性名称不合规范", "false");
         this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str + "},300);</script>");
     }
     else
     {
         AttributeInfo attributeInfo = new AttributeInfo();
         attributeInfo.TypeId        = this.typeId;
         attributeInfo.AttributeName = Globals.HtmlEncode(Globals.StripScriptTags(this.txtName.Text.Trim()).Replace("\\", ""));
         if (this.chkMulti.Checked)
         {
             attributeInfo.UsageMode = AttributeUseageMode.MultiView;
         }
         else
         {
             attributeInfo.UsageMode = AttributeUseageMode.View;
         }
         if (!string.IsNullOrEmpty(this.txtValues.Text.Trim()))
         {
             string   text  = Globals.StripHtmlXmlTags(Globals.StripScriptTags(this.txtValues.Text.Trim()).Replace(",", ",").Replace("\\", ""));
             string[] array = text.Split(',');
             for (int i = 0; i < array.Length && array[i].Length <= 100; i++)
             {
                 AttributeValueInfo attributeValueInfo = new AttributeValueInfo();
                 if (array[i].Length > 15)
                 {
                     string str2 = string.Format("ShowMsg(\"{0}\", {1});", "属性值不合规范", "false");
                     this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str2 + "},300);</script>");
                     return;
                 }
                 attributeValueInfo.ValueStr = array[i];
                 attributeInfo.AttributeValues.Add(attributeValueInfo);
             }
         }
         ValidationResults validationResults = Validation.Validate(attributeInfo, "ValAttribute");
         string            str3 = string.Empty;
         if (!validationResults.IsValid)
         {
             foreach (ValidationResult item in (IEnumerable <ValidationResult>)validationResults)
             {
                 str3 += Formatter.FormatErrorMessage(item.Message);
             }
         }
         else if (ProductTypeHelper.AddAttribute(attributeInfo))
         {
             this.txtName.Text   = string.Empty;
             this.txtValues.Text = string.Empty;
             base.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
         }
     }
 }
Example #3
0
        private void btnCreate_Click(object sender, System.EventArgs e)
        {
            if (this.txtName.Text.Trim().Length > 15)
            {
                string str = string.Format("ShowMsg(\"{0}\", {1});", "属性名称限制在15个字符以内,不允许包含脚本标签,HTML标签和\\,系统会自动过滤", "false");
                this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str + "},300);</script>");
                return;
            }
            AttributeInfo attributeInfo = new AttributeInfo();

            attributeInfo.TypeId        = this.typeId;
            attributeInfo.AttributeName = Globals.HtmlEncode(Globals.StripScriptTags(this.txtName.Text.Trim()).Replace("\\", ""));
            if (this.chkMulti.Checked)
            {
                attributeInfo.UsageMode = AttributeUseageMode.MultiView;
            }
            else
            {
                attributeInfo.UsageMode = AttributeUseageMode.View;
            }
            if (!string.IsNullOrEmpty(this.txtValues.Text.Trim()))
            {
                string   text  = Globals.StripHtmlXmlTags(Globals.StripScriptTags(this.txtValues.Text.Trim()).Replace(",", ",").Replace("\\", ""));
                string[] array = text.Split(new char[]
                {
                    ','
                });
                int num = 0;
                while (num < array.Length && array[num].Length <= 100)
                {
                    AttributeValueInfo attributeValueInfo = new AttributeValueInfo();
                    if (array[num].Length > 15)
                    {
                        string str2 = string.Format("ShowMsg(\"{0}\", {1});", "属性值限制在15个字符以内,不允许包含脚本标签,HTML标签和\\,系统会自动过滤", "false");
                        this.Page.ClientScript.RegisterStartupScript(base.GetType(), "ServerMessageScript2", "<script language='JavaScript' defer='defer'>setTimeout(function(){" + str2 + "},300);</script>");
                        return;
                    }
                    attributeValueInfo.ValueStr = array[num];
                    attributeInfo.AttributeValues.Add(attributeValueInfo);
                    num++;
                }
            }
            ValidationResults validationResults = Validation.Validate <AttributeInfo>(attributeInfo, new string[]
            {
                "ValAttribute"
            });
            string str3 = string.Empty;

            if (!validationResults.IsValid)
            {
                foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults)
                {
                    str3 += Formatter.FormatErrorMessage(current.Message);
                }
                return;
            }
            if (ProductTypeHelper.AddAttribute(attributeInfo))
            {
                this.txtName.Text   = string.Empty;
                this.txtValues.Text = string.Empty;
                base.Response.Redirect(System.Web.HttpContext.Current.Request.Url.ToString(), true);
            }
        }