/// <summary> /// 创建店铺分类 /// </summary> /// <param name="shopcategoryinfo">店铺分类信息</param> /// <param name="targetshopcategoryinfo">要加入的目标分类信息</param> /// <param name="addtype">添加方式(1:作为同级分类 2:作为子分类 其它:根结店)</param> /// <returns>创建店铺分类id</returns> public static int CreateShopCategory(Shopcategoryinfo shopCategoryInfo, Shopcategoryinfo targetShopCategoryInfo, int addType) { switch(addType) { case 1: //作为同级分类 { shopCategoryInfo.Parentid = targetShopCategoryInfo.Parentid; shopCategoryInfo.Parentidlist = targetShopCategoryInfo.Parentidlist; shopCategoryInfo.Layer = targetShopCategoryInfo.Layer; break; } case 2: //作为子分类 { shopCategoryInfo.Parentid = targetShopCategoryInfo.Categoryid; shopCategoryInfo.Parentidlist = targetShopCategoryInfo.Parentidlist == "0" ? targetShopCategoryInfo.Categoryid.ToString() : targetShopCategoryInfo.Parentidlist + "," + targetShopCategoryInfo.Categoryid; shopCategoryInfo.Layer = targetShopCategoryInfo.Layer + 1; break; } default: { shopCategoryInfo.Parentid = 0; shopCategoryInfo.Parentidlist = "0"; shopCategoryInfo.Layer = 0; break; } } return CreateShopCategory(shopCategoryInfo); }
/// <summary> /// 创建店铺分类 /// </summary> /// <param name="shopcategoryinfo">店铺分类信息</param> /// <returns>创建店铺分类id</returns> public static int CreateShopCategory(Shopcategoryinfo shopCategoryInfo) { int returnval = DbProvider.GetInstance().CreateShopCategory(shopCategoryInfo); SetShopCategoryDispalyorder(shopCategoryInfo.Shopid); return returnval; }
/// <summary> /// 获得店铺分类信息(DTO) /// </summary> /// <param name="__idatareader">要转换的数据表</param> /// <returns>返回店铺分类信息</returns> public static Shopcategoryinfo[] GetShopCategoryArray(DataTable dt) { if (dt == null || dt.Rows.Count == 0) return null; Shopcategoryinfo[] shopcategoryinfoarray = new Shopcategoryinfo[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { shopcategoryinfoarray[i] = new Shopcategoryinfo(); shopcategoryinfoarray[i].Categoryid = TypeConverter.ObjectToInt(dt.Rows[i]["categoryid"]); shopcategoryinfoarray[i].Parentid = TypeConverter.ObjectToInt(dt.Rows[i]["parentid"]); shopcategoryinfoarray[i].Parentidlist = dt.Rows[i]["parentidlist"].ToString().Trim(); shopcategoryinfoarray[i].Layer = TypeConverter.ObjectToInt(dt.Rows[i]["layer"]); shopcategoryinfoarray[i].Childcount = TypeConverter.ObjectToInt(dt.Rows[i]["childcount"]); shopcategoryinfoarray[i].Syscategoryid = TypeConverter.ObjectToInt(dt.Rows[i]["syscategoryid"]); shopcategoryinfoarray[i].Name = dt.Rows[i]["name"].ToString(); shopcategoryinfoarray[i].Categorypic = dt.Rows[i]["categorypic"].ToString(); shopcategoryinfoarray[i].Shopid = TypeConverter.ObjectToInt(dt.Rows[i]["shopid"]); shopcategoryinfoarray[i].Displayorder = TypeConverter.ObjectToInt(dt.Rows[i]["displayorder"]); } dt.Dispose(); return shopcategoryinfoarray; }
/// <summary> /// 获得店铺分类信息(DTO) /// </summary> /// <param name="__idatareader">要转换的数据</param> /// <returns>返回店铺分类信息</returns> public static Shopcategoryinfo GetShopCategoryInfo(IDataReader reader) { Shopcategoryinfo shopCategoryInfo = null; if (reader.Read()) { shopCategoryInfo = new Shopcategoryinfo(); shopCategoryInfo.Categoryid = TypeConverter.ObjectToInt(reader["categoryid"]); shopCategoryInfo.Parentid = TypeConverter.ObjectToInt(reader["parentid"]); shopCategoryInfo.Parentidlist = reader["parentidlist"].ToString().Trim(); shopCategoryInfo.Layer = TypeConverter.ObjectToInt(reader["layer"]); shopCategoryInfo.Childcount = TypeConverter.ObjectToInt(reader["childcount"]); shopCategoryInfo.Syscategoryid = TypeConverter.ObjectToInt(reader["syscategoryid"]); shopCategoryInfo.Name = reader["name"].ToString().Trim(); shopCategoryInfo.Categorypic = reader["categorypic"].ToString().Trim(); shopCategoryInfo.Shopid = TypeConverter.ObjectToInt(reader["shopid"]); shopCategoryInfo.Displayorder = TypeConverter.ObjectToInt(reader["displayorder"]); reader.Close(); } return shopCategoryInfo; }
/// <summary> /// 移动商品分类 /// </summary> /// <param name="shopcategoryinfo">源店铺商品分类</param> /// <param name="targetshopcategoryinfo">目标店铺商品分类</param> /// <param name="isaschildnode">是否作为子节点</param> /// <returns>是否移动成功</returns> public static bool MoveShopCategory(Shopcategoryinfo shopCategoryInfo, Shopcategoryinfo targetShopCategoryInfo, bool isAsChildNode) { DbProvider.GetInstance().MovingShopCategoryPos(shopCategoryInfo, targetShopCategoryInfo, isAsChildNode); SetShopCategoryDispalyorder(targetShopCategoryInfo.Shopid); return true; }
/// <summary> /// 更新店铺分类 /// </summary> /// <param name="shopcategoryinfo">店铺分类信息</param> /// <returns>是否更新成功</returns> public static bool UpdateShopCategory(Shopcategoryinfo shopCategoryInfo) { return DbProvider.GetInstance().UpdateShopCategory(shopCategoryInfo); }
/// <summary> /// 移动商品分类 /// </summary> /// <param name="shopcategoryinfo">源分类</param> /// <param name="targetshopcategoryinfo">目标分类</param> /// <param name="isaschildnode">是否作为子节点</param> public void MovingShopCategoryPos(Shopcategoryinfo shopCategoryInfo, Shopcategoryinfo targetShopCategoryInfo, bool isAsChildNode) { SqlConnection conn = new SqlConnection(DbHelper.ConnectionString); conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //当前商品分类带子分类时 if (DbHelper.ExecuteDataset(CommandType.Text, string.Format("SELECT TOP 1 [categoryid] FROM [{0}shopcategories] WHERE [parentid]={1}", BaseConfigs.GetTablePrefix, shopCategoryInfo.Categoryid)).Tables[0].Rows.Count > 0) { #region string commandText = ""; if (isAsChildNode) //作为商品分类子分类插入 { //让位于当前商品分类(分类)显示顺序之后的商品分类全部加1(为新加入的商品分类让位结果) commandText = string.Format("UPDATE [{0}shopcategories] SET [displayorder]=[displayorder]+1 WHERE [displayorder]>={1} AND [shopid] = {2}", BaseConfigs.GetTablePrefix, targetShopCategoryInfo.Displayorder + 1, targetShopCategoryInfo.Shopid); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); //更新当前商品分类的相关信息 commandText = string.Format("UPDATE [{0}shopcategories] SET [parentid]={1},[displayorder]={2} WHERE [categoryid]={3}", BaseConfigs.GetTablePrefix, targetShopCategoryInfo.Categoryid, targetShopCategoryInfo.Displayorder + 1, shopCategoryInfo.Categoryid); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); } else //作为同级商品分类,在目标商品分类之前插入 { //让位于包括当前商品分类显示顺序之后的商品分类全部加1(为新加入的商品分类让位结果) commandText = string.Format("UPDATE [{3}shopcategories] SET [displayorder]=[displayorder]+1 WHERE ([displayorder]>={0} AND [shopid] = {1}) OR [categoryid]={2}", targetShopCategoryInfo.Shopid, targetShopCategoryInfo.Displayorder, targetShopCategoryInfo.Categoryid, BaseConfigs.GetTablePrefix); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); //更新当前商品分类的相关信息 commandText = string.Format("UPDATE [{3}shopcategories] SET [parentid]={1},[displayorder]={2} WHERE [categoryid]={0}", shopCategoryInfo.Categoryid, targetShopCategoryInfo.Parentid, targetShopCategoryInfo.Displayorder, BaseConfigs.GetTablePrefix); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); } #endregion } else //当前商品分类不带子分类 { #region //让位于当前节点显示顺序之后的节点全部减1 [起到删除节点的效果] if (isAsChildNode) //作为子分类插入 { //让位于当前商品分类显示顺序之后的商品分类全部加1(为新加入的商品分类让位结果) string commandText = string.Format("UPDATE [{2}shopcategories] SET [displayorder]=[displayorder]+1 WHERE [displayorder]>={0} AND [shopid] = {1}", targetShopCategoryInfo.Displayorder + 1, targetShopCategoryInfo.Shopid, BaseConfigs.GetTablePrefix); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); string parentidlist = null; if (targetShopCategoryInfo.Parentidlist == "0") parentidlist = targetShopCategoryInfo.Categoryid.ToString(); else parentidlist = targetShopCategoryInfo.Parentidlist.Trim() + "," + targetShopCategoryInfo.Categoryid; //更新当前商品分类的相关信息 commandText = string.Format("UPDATE [{5}shopcategories] SET [parentid]={1},[layer]={2},[parentidlist]='{3}',[displayorder]={4} WHERE [categoryid]={0}", shopCategoryInfo.Categoryid, targetShopCategoryInfo.Categoryid, parentidlist.Split(',').Length, parentidlist, targetShopCategoryInfo.Displayorder + 1, BaseConfigs.GetTablePrefix ); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); } else //作为同级商品分类,在目标商品分类之前插入 { //让位于包括当前商品分类显示顺序之后的商品分类全部加1(为新加入的商品分类让位结果) string commandText = string.Format("UPDATE [{3}shopcategories] SET [displayorder]=[displayorder]+1 WHERE ([displayorder]>={0} AND [shopid] = {1}) OR [categoryid]={2}", targetShopCategoryInfo.Displayorder + 1, targetShopCategoryInfo.Shopid, targetShopCategoryInfo.Categoryid, BaseConfigs.GetTablePrefix); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); //更新当前商品分类的相关信息 commandText = string.Format("UPDATE [{5}shopcategories] SET [parentid]={1},[layer]={2},[parentidlist]='{3}',[displayorder]={4} WHERE [categoryid]={0}", shopCategoryInfo.Categoryid, targetShopCategoryInfo.Parentid, targetShopCategoryInfo.Parentidlist.Trim().Split(',').Length, targetShopCategoryInfo.Parentidlist.Trim(), targetShopCategoryInfo.Displayorder, BaseConfigs.GetTablePrefix ); DbHelper.ExecuteDataset(trans, CommandType.Text, commandText); } #endregion } trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw ex; } conn.Close(); } }
/// <summary> /// 删除指定的店铺商品分类 /// </summary> /// <param name="categoryid">要删除的店铺商品分类id</param> /// <returns>是否删除成功</returns> public static bool DeleteCategoryByCategoryId(Shopcategoryinfo shopCategoryInfo) { if (DbProvider.GetInstance().IsExistSubShopCategory(shopCategoryInfo)) return false; DbProvider.GetInstance().DeleteShopCategory(shopCategoryInfo); return true; }
/// <summary> /// 删除指定的商品分类信息 /// </summary> /// <param name="shopcategoryinfo"></param> /// <returns></returns> public bool DeleteShopCategory(Shopcategoryinfo shopCategoryInfo) { bool result = false; SqlConnection conn = new SqlConnection(DbHelper.ConnectionString); conn.Open(); using (SqlTransaction trans = conn.BeginTransaction()) { try { //调整在当前节点排序位置之后的节点,做减1操作 DbHelper.ExecuteNonQuery(trans, CommandType.Text, string.Format("UPDATE [{0}shopcategories] SET [displayorder]=[displayorder]-1 WHERE [displayorder]>{1}", BaseConfigs.GetTablePrefix, shopCategoryInfo.Displayorder)); DbHelper.ExecuteNonQuery(trans, CommandType.Text, string.Format("UPDATE [{0}goods] SET [shopcategorylist] = REPLACE([shopcategorylist], ',{1},', ',') WHERE CHARINDEX(',{1},', RTRIM([shopcategorylist])) > 0", BaseConfigs.GetTablePrefix, shopCategoryInfo.Categoryid)); DbHelper.ExecuteNonQuery(trans, CommandType.Text, string.Format("DELETE FROM [{0}shopcategories] WHERE [categoryid] = {1}", BaseConfigs.GetTablePrefix, shopCategoryInfo.Categoryid)); trans.Commit(); result = true; } catch { trans.Rollback(); } } conn.Close(); return result; }
/// <summary> /// 指定的商品分类下有无子分类 /// </summary> /// <param name="shopcategoryinfo">指定的商品分类</param> /// <returns></returns> public bool IsExistSubShopCategory(Shopcategoryinfo shopCategoryInfo) { DbParameter[] parms = { DbHelper.MakeInParam("@categoryid", (DbType)SqlDbType.Int, 4, shopCategoryInfo.Categoryid) }; return DbHelper.ExecuteDataset(CommandType.Text, string.Format("SELECT TOP 1 * FROM [{0}shopcategories] WHERE [parentid]=@categoryid", BaseConfigs.GetTablePrefix), parms).Tables[0].Rows.Count > 0; }
/// <summary> /// 更新店铺分类 /// </summary> /// <param name="shopcategoryinfo">店铺分类信息</param> /// <returns></returns> public bool UpdateShopCategory(Shopcategoryinfo shopCategoryInfo) { DbParameter[] parms = { DbHelper.MakeInParam("@parentid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Parentid), DbHelper.MakeInParam("@parentidlist", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Parentidlist), DbHelper.MakeInParam("@layer", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Layer), DbHelper.MakeInParam("@childcount", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Childcount), DbHelper.MakeInParam("@syscategoryid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Syscategoryid), DbHelper.MakeInParam("@name", (DbType)SqlDbType.NChar, 50,shopCategoryInfo.Name), DbHelper.MakeInParam("@categorypic", (DbType)SqlDbType.NVarChar, 100,shopCategoryInfo.Categorypic), DbHelper.MakeInParam("@shopid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Shopid), DbHelper.MakeInParam("@displayorder", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Displayorder), DbHelper.MakeInParam("@categoryid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Categoryid) }; string commandText = String.Format("Update [{0}shopcategories] Set [parentid] = @parentid, [parentidlist] = @parentidlist, [layer] = @layer, [childcount] = @childcount, [syscategoryid] = @syscategoryid, [name] = @name, [categorypic] = @categorypic, [shopid] = @shopid, [displayorder] = @displayorder WHERE [categoryid] = @categoryid", BaseConfigs.GetTablePrefix); DbHelper.ExecuteNonQuery(CommandType.Text, commandText, parms); return true; }
/// <summary> /// 创建店铺分类 /// </summary> /// <param name="shopcategoryinfo">店铺分类信息</param> /// <returns></returns> public int CreateShopCategory(Shopcategoryinfo shopCategoryInfo) { DbParameter[] parms = { DbHelper.MakeInParam("@parentid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Parentid), DbHelper.MakeInParam("@parentidlist", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Parentidlist), DbHelper.MakeInParam("@layer", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Layer), DbHelper.MakeInParam("@childcount", (DbType)SqlDbType.Char, 300,shopCategoryInfo.Childcount), DbHelper.MakeInParam("@syscategoryid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Syscategoryid), DbHelper.MakeInParam("@name", (DbType)SqlDbType.NChar, 50,shopCategoryInfo.Name), DbHelper.MakeInParam("@categorypic", (DbType)SqlDbType.NVarChar, 100,shopCategoryInfo.Categorypic), DbHelper.MakeInParam("@shopid", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Shopid), DbHelper.MakeInParam("@displayorder", (DbType)SqlDbType.Int, 4,shopCategoryInfo.Displayorder) }; string commandText = String.Format("INSERT INTO [{0}shopcategories] ( [parentid], [parentidlist], [layer], [childcount], [syscategoryid], [name], [categorypic], [shopid], [displayorder]) VALUES (@parentid, @parentidlist, @layer, @childcount, @syscategoryid, @name, @categorypic, @shopid, @displayorder);SELECT SCOPE_IDENTITY() AS 'id'", BaseConfigs.GetTablePrefix); return TypeConverter.ObjectToInt(DbHelper.ExecuteDataset(CommandType.Text, commandText, parms).Tables[0].Rows[0][0], -1); }
protected override void ShowPage() { if (userid == -1) { AddErrLine("你尚未登录"); return; } if (config.Enablemall <2) { AddErrLine("当前操作只有在开启商城(高级)模式时才可以使用!"); return; } user = Users.GetUserInfo(userid); shopinfo = Shops.GetShopByUserId(user.Uid); if (!DNTRequest.IsPost()) { shopcategorydt = ShopCategories.GetShopCategoryTable(shopinfo.Shopid); shopcategorydt_count = shopcategorydt.Rows.Count; shopcategorydata = ShopCategories.GetShopCategoryJson(shopcategorydt); categoryoptions = ShopCategories.GetShopCategoryOption(shopcategorydt, false); } else { if (ForumUtils.IsCrossSitePost()) { AddErrLine("您的请求来路不正确,无法提交。如果您安装了某种默认屏蔽来路信息的个人防火墙软件(如 Norton Internet Security),请设置其不要禁止来路信息后再试。"); return; } string operation = DNTRequest.GetFormString("operation"); if (operation != "add") { int shopcategoryid = DNTRequest.GetFormInt("categoryid", 0); if (shopcategoryid <= 0) { AddErrLine("店铺商品分类参数无效<br />"); return; } shopcategoryinfo = ShopCategories.GetShopCategoryByCategoryId(shopcategoryid); } shopid = 0; item = DNTRequest.GetString("item"); switch (operation) { case "delete": //删除分类 { if (shopcategoryinfo == null || shopcategoryinfo.Categoryid <= 0) { AddErrLine("要删除的店铺商品分类参数无效<br />"); return; } if (!ShopCategories.DeleteCategoryByCategoryId(shopcategoryinfo)) { AddErrLine("对不起,当前节点下面还有子结点,因此不能删除<br />"); return; } break; } case "edit": //编辑分类名称 { if (shopcategoryinfo == null || shopcategoryinfo.Categoryid <=0) { AddErrLine("要修改的店铺商品分类参数无效<br />"); return; } string editname = DNTRequest.GetString("editcategoryname"); if (editname == "") { AddErrLine("店铺商品分类名称未变更或不能为空<br />"); return; } shopcategoryinfo.Name = editname; ShopCategories.UpdateShopCategory(shopcategoryinfo); break; } case "add": //添加分类 { shopcategoryinfo = new Shopcategoryinfo(); shopcategoryinfo.Name = DNTRequest.GetFormString("addcategoryname"); shopcategoryinfo.Shopid = shopinfo.Shopid; int addtype = DNTRequest.GetInt("addtype", 0); if (addtype > 0 && addtype <= 2) { int targetcategoryid = DNTRequest.GetFormInt("selectcategoryid", 0); if (targetcategoryid <= 0) { AddErrLine("要添加到的目标分类参数无效<br />"); return; } targetshopcategoryinfo = ShopCategories.GetShopCategoryByCategoryId(targetcategoryid); if (targetshopcategoryinfo == null || targetshopcategoryinfo.Categoryid <= 0) { AddErrLine("要添加到的目标分类参数无效<br />"); return; } } ShopCategories.CreateShopCategory(shopcategoryinfo, targetshopcategoryinfo, addtype); break; } case "move": //移动分类 { int targetcategoryid = DNTRequest.GetFormInt("targetcategoryid", 0); if (targetcategoryid <= 0) { AddErrLine("要移动到的目标分类参数无效<br />"); return; } targetshopcategoryinfo = ShopCategories.GetShopCategoryByCategoryId(targetcategoryid); if (targetshopcategoryinfo == null || targetshopcategoryinfo.Categoryid <= 0) { AddErrLine("要移动到的目标分类参数无效<br />"); return; } string target_parentidlist = "," + targetshopcategoryinfo.Parentidlist.Trim() + ","; if (target_parentidlist.IndexOf("," + shopcategoryinfo.Categoryid.ToString() + ",") > 0) { AddErrLine("不能将当前分类移动到其子分类<br />"); return; } ShopCategories.MoveShopCategory(shopcategoryinfo, targetshopcategoryinfo, DNTRequest.GetInt("isaschildnode",0) == 1 ? true : false); break; } } SetUrl("usercpshopcategory.aspx?item=" + item); SetMetaRefresh(); AddMsgLine("操作成功. <br />(<a href=\"usercpmygoods.aspx?item=" + item + "\">点击这里返回</a>)<br />"); } }