/// <summary>
        /// 合并属性和属性记录,得到完整的商品属性
        /// </summary>
        public static List <ProductTypeAttributeInfo> JoinAttribute(int productTypeId, int productId)
        {
            var attributeRecordList = ProductTypeAttributeRecordBLL.ReadList(productId);
            var attributeList       = ProductTypeAttributeBLL.ReadList(productTypeId);
            List <ProductTypeAttributeInfo> result = new List <ProductTypeAttributeInfo>();

            foreach (var attribute in attributeList)
            {
                bool isFind = false;
                foreach (var attributeRecord in attributeRecordList)
                {
                    if (attribute.Id == attributeRecord.AttributeId)
                    {
                        ProductTypeAttributeInfo temp = new ProductTypeAttributeInfo();
                        temp = (ProductTypeAttributeInfo)ServerHelper.CopyClass(attribute);
                        temp.AttributeRecord = attributeRecord;
                        isFind = true;
                        result.Add(temp);
                        break;
                    }
                }
                if (!isFind)
                {
                    result.Add(attribute);
                }
            }
            return(result);
        }
        public void Update(ProductTypeAttributeInfo entity)
        {
            using (var conn = new SqlConnection(connectString))
            {
                string sql = @"UPDATE ProductTypeAttribute SET ProductTypeId = @ProductTypeId, Name = @Name, InputType = @InputType, InputValue = @InputValue, OrderId = @OrderId
                            where Id=@Id";

                conn.Execute(sql, entity);
            }
        }
        public int Add(ProductTypeAttributeInfo entity)
        {
            using (var conn = new SqlConnection(connectString))
            {
                string sql = @"INSERT INTO ProductTypeAttribute(ProductTypeId,Name,InputType,InputValue,OrderId) VALUES(@ProductTypeId,@Name,@InputType,@InputValue,@OrderId);
                            select SCOPE_IDENTITY()";

                return(conn.Query <int>(sql, entity).Single());
            }
        }
        /// <summary>
        /// 显示属性列表并判断已选
        /// </summary>
        /// <param name="attribute"></param>
        /// <returns></returns>
        protected string ShowAttributeSelect(ProductTypeAttributeInfo attribute)
        {
            string selectStr = string.Empty;


            if (attribute.InputType == 5)
            {
                selectStr = "<select name=\"" + attribute.Id + "Value\" style=\"width: 200px;\" class=\"select\">";
                if (attribute.InputValue != "")
                {
                    foreach (string inputValue in attribute.InputValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        selectStr += "<option value=\"" + inputValue + "\"";
                        if (attribute.AttributeRecord.Value == inputValue)
                        {
                            selectStr += " selected=\"selected\"";
                        }
                        selectStr += ">" + inputValue + "</option>";
                    }
                }
                selectStr += "</select>";
            }
            else
            {
                foreach (string inputValue in attribute.InputValue.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if ((";" + attribute.AttributeRecord.Value + ";").IndexOf(";" + inputValue + ";") > -1)
                    {
                        selectStr += "<label class=\"ig-checkbox checked\">";
                    }
                    else
                    {
                        selectStr += "<label class=\"ig-checkbox\">";
                    }
                    selectStr += "<input name=\"" + attribute.Id + "Value\" type=\"checkbox\"";
                    if ((";" + attribute.AttributeRecord.Value + ";").IndexOf(";" + inputValue + ";") > -1)
                    {
                        selectStr += "checked=\"checked\"";
                    }
                    selectStr += " value=\"" + inputValue + "\" />";
                    selectStr += inputValue + "</label> &nbsp;&nbsp;";
                }
            }

            return(selectStr);
        }
        /// <summary>
        /// 提交按钮点击方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            #region
            //添加属性组,即产品类型
            int             productTypeID = 0;
            ProductTypeInfo productType   = new ProductTypeInfo();
            productType.Id   = RequestHelper.GetQueryString <int>("ID");
            productType.Name = Name.Text;
            //productType.BrandIds = RequestHelper.GetForm<string>("proBrand").Replace(",",";");
            productType.BrandIds = RequestHelper.GetForm <string>("choosedBrnadIds").Replace(";;", ";");

            string alertMessage = ShopLanguage.ReadLanguage("AddOK");
            if (productType.Id == int.MinValue)
            {
                CheckAdminPower("AddProductType", PowerCheckType.Single);
                productTypeID = ProductTypeBLL.Add(productType);
                AdminLogBLL.Add(ShopLanguage.ReadLanguage("AddRecord"), ShopLanguage.ReadLanguage("ProductType"), productTypeID);

                #region
                //添加相关属性
                string[] namelist  = RequestHelper.GetForm <string>("NameList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] valuelist = RequestHelper.GetForm <string>("ValueList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] typelist  = RequestHelper.GetForm <string>("TypeList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (namelist.Length > 0)
                {
                    for (int t = 0; t < namelist.Length; t++)
                    {
                        ProductTypeAttributeInfo attribute = new ProductTypeAttributeInfo();
                        attribute.Name = namelist[t];
                        var _attribute = ProductTypeAttributeBLL.Read(attribute.Name, productTypeID);
                        if (_attribute.Id > 0)
                        {
                            ScriptHelper.Alert("该属性已存在,请重新输入", RequestHelper.RawUrl);
                        }
                        else
                        {
                            attribute.ProductTypeId = productTypeID;
                            int typeNum = 0;
                            int.TryParse(typelist[t], out typeNum);

                            attribute.InputType  = typeNum;
                            attribute.InputValue = valuelist[t].Replace('|', ';');
                            attribute.OrderId    = 0;

                            ProductTypeAttributeBLL.Add(attribute);
                        }
                    }
                }
                #endregion
                #region
                //添加相关规格
                string[] snamelist  = RequestHelper.GetForm <string>("SNameList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] svaluelist = RequestHelper.GetForm <string>("SValueList").Split(',');
                string[] stypelist  = RequestHelper.GetForm <string>("STypeList").Split(',');
                if (snamelist.Length > 0)
                {
                    for (int t = 0; t < snamelist.Length; t++)
                    {
                        ProductTypeStandardInfo standard = new ProductTypeStandardInfo();
                        standard.Name = snamelist[t];
                        var _standard = ProductTypeStandardBLL.Read(standard.Name, productTypeID);
                        if (_standard.Id > 0)
                        {
                            ScriptHelper.Alert("该规格已存在,请重新输入", RequestHelper.RawUrl);
                        }
                        else
                        {
                            standard.ProductTypeId = productTypeID;
                            int typeNum = 0;
                            int.TryParse(stypelist[t], out typeNum);

                            standard.ValueList = svaluelist[t].Replace('|', ';');

                            ProductTypeStandardBLL.Add(standard);
                        }
                    }
                }
                #endregion
            }
            else
            {
                CheckAdminPower("UpdateProductType", PowerCheckType.Single);
                ProductTypeBLL.Update(productType);
                AdminLogBLL.Add(ShopLanguage.ReadLanguage("UpdateRecord"), ShopLanguage.ReadLanguage("ProductType"), productType.Id);
                alertMessage = ShopLanguage.ReadLanguage("UpdateOK");

                #region
                //删除原有属性
                //ProductTypeAttributeBLL.DeleteList(productType.Id);

                //添加相关属性
                string[] namelist  = RequestHelper.GetForm <string>("NameList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] valuelist = RequestHelper.GetForm <string>("ValueList").Split(',');
                string[] typelist  = RequestHelper.GetForm <string>("TypeList").Split(',');
                string[] idList    = RequestHelper.GetForm <string>("IdList").Split(',');

                if (namelist.Length > 0)
                {
                    List <ProductTypeAttributeInfo> productTypeAttrList = ProductTypeAttributeBLL.ReadList(productType.Id);
                    for (int t = 0; t < namelist.Length; t++)
                    {
                        if (idList[t] != "0")
                        {
                            ProductTypeAttributeInfo attribute = ProductTypeAttributeBLL.Read(Convert.ToInt32(idList[t]));
                            attribute.Name = namelist[t];
                            var _attribute = ProductTypeAttributeBLL.Read(attribute.Name, productType.Id);
                            if (_attribute.Id != attribute.Id && _attribute.Id > 0)
                            {
                                ScriptHelper.Alert("该属性已存在,请重新输入", RequestHelper.RawUrl);
                            }
                            else
                            {
                                attribute.ProductTypeId = productType.Id;
                                int typeNum = 0;
                                int.TryParse(typelist[t], out typeNum);

                                attribute.InputType  = typeNum;
                                attribute.InputValue = valuelist[t].Replace('|', ';');
                                attribute.OrderId    = 0;

                                ProductTypeAttributeBLL.Update(attribute);
                            }
                        }
                        else
                        {
                            ProductTypeAttributeInfo attribute = new ProductTypeAttributeInfo();
                            attribute.Name = namelist[t];
                            var _attribute = ProductTypeAttributeBLL.Read(attribute.Name, productType.Id);
                            if (_attribute.Id > 0)
                            {
                                ScriptHelper.Alert("该属性已存在,请重新输入", RequestHelper.RawUrl);
                            }
                            else
                            {
                                attribute.ProductTypeId = productType.Id;
                                int typeNum = 0;
                                int.TryParse(typelist[t], out typeNum);

                                attribute.InputType  = typeNum;
                                attribute.InputValue = valuelist[t].Replace('|', ';');
                                attribute.OrderId    = 0;

                                ProductTypeAttributeBLL.Add(attribute);
                            }
                        }
                    }
                }
                #endregion
                #region
                //删除原有规格
                //ProductTypeStandardBLL.DeleteList(productType.Id);
                //添加相关规格
                string[] snamelist  = RequestHelper.GetForm <string>("SNameList").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] svaluelist = RequestHelper.GetForm <string>("SValueList").Split(',');
                string[] stypelist  = RequestHelper.GetForm <string>("STypeList").Split(',');
                string[] sidList    = RequestHelper.GetForm <string>("SIdList").Split(',');

                if (snamelist.Length > 0)
                {
                    List <ProductTypeStandardInfo> productTypeStandardList = ProductTypeStandardBLL.ReadList(productType.Id);
                    for (int t = 0; t < snamelist.Length; t++)
                    {
                        if (sidList[t] != "0")
                        {
                            ProductTypeStandardInfo standard = ProductTypeStandardBLL.Read(Convert.ToInt32(sidList[t]));
                            standard.Name = snamelist[t];
                            var _standard = ProductTypeStandardBLL.Read(standard.Name, productType.Id);
                            if (_standard.Id != standard.Id && _standard.Id > 0)
                            {
                                ScriptHelper.Alert("该规格已存在,请重新输入", RequestHelper.RawUrl);
                            }
                            else
                            {
                                standard.ProductTypeId = productType.Id;
                                standard.ValueList     = svaluelist[t].Replace('|', ';');

                                ProductTypeStandardBLL.Update(standard);
                            }
                        }
                        else
                        {
                            ProductTypeStandardInfo standard = new ProductTypeStandardInfo();
                            standard.Name = snamelist[t];
                            var _standard = ProductTypeStandardBLL.Read(standard.Name, productType.Id);
                            if (_standard.Id > 0)
                            {
                                ScriptHelper.Alert("该规格已存在,请重新输入", RequestHelper.RawUrl);
                            }
                            else
                            {
                                standard.ProductTypeId = productType.Id;
                                standard.ValueList     = svaluelist[t].Replace('|', ';');

                                ProductTypeStandardBLL.Add(standard);
                            }
                        }
                    }
                }
                #endregion
            }
            #endregion


            ScriptHelper.Alert(alertMessage, RequestHelper.RawUrl);
        }
 public static void Update(ProductTypeAttributeInfo entity)
 {
     dal.Update(entity);
     CacheHelper.Remove(cacheKey);
 }
 public static int Add(ProductTypeAttributeInfo entity)
 {
     entity.Id = dal.Add(entity);
     CacheHelper.Remove(cacheKey);
     return(entity.Id);
 }