/// <summary>
        /// 修改品牌信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateBrandsitem(BrandsInfoModel model)
        {
            string sqltxt = @"UPDATE  A WITH ( ROWLOCK )
SET     A.NAME = @name ,
        A.BelongsCategoryID = @blongcateid ,
        A.isshow = @isshow ,
        A.IsRecommend = @IsRecommend ,
        A.MainCategoryID = B.parentid
FROM    ShoppingStore.dbo.bsp_brands A
        LEFT JOIN ShoppingStore.dbo.bsp_categories B WITH ( NOLOCK ) ON A.BelongsCategoryID = B.cateid
                                                              AND B.cateid = @blongcateid
WHERE   A.brandid = @id ";

            SqlParameter[] paramter =
            {
                new SqlParameter("@name",        SqlDbType.NVarChar),
                new SqlParameter("@blongcateid", SqlDbType.Int),
                new SqlParameter("@isshow",      SqlDbType.Int),
                new SqlParameter("@IsRecommend", SqlDbType.Int),
                new SqlParameter("@id",          SqlDbType.Int)
            };
            paramter[0].Value = model.name;
            paramter[1].Value = model.BelongsCategoryID;
            paramter[2].Value = model.isshow;
            paramter[3].Value = model.IsRecommend;
            paramter[4].Value = model.brandid;
            return(helper.ExecuteSql(sqltxt, paramter));
        }
        /// <summary>
        /// 得到品牌信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetAllBrands()
        {
            BrandsInfoModel model = new BrandsInfoModel();

            model.PageSize  = Convert.ToInt32(Request.Params["pagesize"]);
            model.PageIndex = Convert.ToInt32(Request.Params["page"]);
            DataTable brandstable             = categoryandproduct.GetAllBrands(model);
            List <BrandsInfoModel> brandslist = new List <BrandsInfoModel>();

            foreach (DataRow item in brandstable.Rows)
            {
                BrandsInfoModel brandmodel = new BrandsInfoModel();
                brandmodel.brandid           = int.Parse(item["brandid"].ToString());
                brandmodel.name              = item["brandname"].ToString();
                brandmodel.IsUsed            = item["isused"].ToString();
                brandmodel.IsRecommended     = item["IsRecommend"].ToString();
                brandmodel.logo              = item["logopath"].ToString();
                brandmodel.MainCategoryName  = item["maincatename"].ToString();
                brandmodel.MainCategoryID    = int.Parse(item["MainCategoryID"].ToString());
                brandmodel.BlongCategoryName = item["blongcatename"].ToString();
                brandmodel.BelongsCategoryID = int.Parse(item["BelongsCategoryID"].ToString());
                brandslist.Add(brandmodel);
            }
            var griddata = new
            {
                Rows  = brandslist,
                Total = int.Parse(brandstable.Rows[0]["tco"].ToString())
            };

            return(Json(griddata, JsonRequestBehavior.AllowGet));
        }
        public ActionResult AddBrands(FormCollection form)
        {
            BrandsInfoModel model = new BrandsInfoModel();

            model.name              = form["addbrands"].ToString();
            model.isshow            = form["addcheckuse"] == null ? 0 : 1;
            model.IsRecommend       = form["addcheckRecommended"] == null ? 0 : 1;
            model.BelongsCategoryID = int.Parse(form["addhidden"].ToString());
            int k = categoryandproduct.Addbranditem(model);

            return(RedirectToAction("Brands"));
        }
        public ActionResult Updatebrands(BrandsInfoModel model)
        {
            int k = categoryandproduct.UpdateBrandsitem(model);

            if (k > 0)
            {
                return(Json("1", JsonRequestBehavior.DenyGet));
            }
            else
            {
                return(Json("0", JsonRequestBehavior.DenyGet));
            }
        }
        /// <summary>
        /// 得到品牌数据
        /// </summary>
        /// <param name="cateid"></param>
        /// <returns></returns>
        public List <BrandsInfoModel> GetbrandBycateid(int cateid)
        {
            List <BrandsInfoModel> models = new List <BrandsInfoModel>();
            DataTable dt = dal.GetbrandsByCateid(cateid);

            foreach (DataRow item in dt.Rows)
            {
                BrandsInfoModel model = new BrandsInfoModel();
                model.name    = item["name"].ToString();
                model.brandid = item["brandid"].ToString().ToInt(0);
                models.Add(model);
            }
            return(models);
        }
        /// <summary>
        /// 查询所有的品牌
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DataTable GetAllBrands(BrandsInfoModel model)
        {
            string sqltxt = @"SELECT  IDENTITY( INT,1,1 ) AS rowid ,
        brandid * 1 AS brandid
INTO    #t
FROM    ShoppingStore.dbo.bsp_brands WITH ( NOLOCK )
DECLARE @totalco INT = @@ROWCOUNT

SELECT  @totalco AS tco ,
        A.brandid ,
        CASE A.isshow
          WHEN 1 THEN '启用'
          ELSE '未启用'
        END AS isused ,
        A.displayorder ,
        A.name AS brandname ,
        ISNULL(A.logo, '(无)') AS logopath ,
        A.BelongsCategoryID ,
        CASE  A.IsRecommend WHEN 1 THEN '是' ELSE '否' END  AS IsRecommend,
        A.MainCategoryID ,
        B.name AS blongcatename ,
        C.name AS maincatename
FROM    #t D
        INNER JOIN ShoppingStore.dbo.bsp_brands A WITH ( NOLOCK ) ON D.brandid = A.brandid
                                                              AND D.rowid > ( @pageindex
                                                              - 1 )
                                                              * @pagesize
                                                              AND D.rowid <= ( @pageindex
                                                              * @pagesize )
        INNER JOIN ShoppingStore.dbo.bsp_categories B WITH ( NOLOCK ) ON A.BelongsCategoryID = B.cateid
        INNER JOIN ShoppingStore.dbo.bsp_Categories C WITH ( NOLOCK ) ON A.MainCategoryID = C.cateid";

            SqlParameter[] paramter =
            {
                new SqlParameter("@pageindex", SqlDbType.Int),
                new SqlParameter("@pagesize",  SqlDbType.Int)
            };
            paramter[0].Value = model.PageIndex;
            paramter[1].Value = model.PageSize;
            return(helper.Query(sqltxt, paramter).Tables[0]);
        }
        /// <summary>
        /// 添加品牌信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Addbranditem(BrandsInfoModel model)
        {
            string sqltxt = @"INSERT  INTO ShoppingStore.dbo.bsp_brands
        ( isshow ,
          displayorder ,
          name ,
          logo ,
          BelongsCategoryID ,
          IsRecommend ,
          MainCategoryID
        )
        SELECT  @isshow ,
                0 ,
                @name ,
                @logo ,
                @belongscategoryid ,
                @isrecommend ,
                parentid
        FROM    ShoppingStore.dbo.bsp_categories WITH ( NOLOCK )
        WHERE   cateid = @belongscategoryid";

            SqlParameter[] paramter =
            {
                new SqlParameter("@isshow",            SqlDbType.Int),
                new SqlParameter("@name",              SqlDbType.NVarChar),
                new SqlParameter("@logo",              SqlDbType.NVarChar),
                new SqlParameter("@belongscategoryid", SqlDbType.Int),
                new SqlParameter("@isrecommend",       SqlDbType.Int)
            };
            paramter[0].Value = model.isshow;
            paramter[1].Value = model.name;
            paramter[2].Value = model.logo;
            paramter[3].Value = model.BelongsCategoryID;
            paramter[4].Value = model.IsRecommend;
            return(helper.ExecuteSql(sqltxt, paramter));
        }
 /// <summary>
 /// 修改品牌信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int UpdateBrandsitem(BrandsInfoModel model)
 {
     return(dal.UpdateBrandsitem(model));
 }
 /// <summary>
 /// 添加品牌信息
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public int Addbranditem(BrandsInfoModel model)
 {
     return(dal.Addbranditem(model));
 }
 /// <summary>
 /// 查询所有的品牌
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public DataTable GetAllBrands(BrandsInfoModel model)
 {
     return(dal.GetAllBrands(model));
 }