/// <summary> /// 判断是否存在子类别 /// </summary> /// <returns></returns> public int GetGoodsCategory(int id) { string CompId = Request.QueryString["hidCompID"].ToString(); var list = new Hi.BLL.BD_GoodsCategory().GetList("", "parentid=" + id + " and ISNULL(dr,0)=0 and compid in(" + CompId + ")", "");//判断是否存在下级类别 return(list.Count); }
/// <summary> /// 编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEdit_Click(object sender, EventArgs e) { string Typename = Common.NoHTML(txtTypeNames.Value.Trim()); string id = Common.NoHTML(hideTypeIds.Value.Trim()); string sortid = Common.NoHTML(txtSortIndexs.Value.Trim()); //string typecode = txtTypecodes.Value.Trim(); int Result = 0; if (string.IsNullOrEmpty(Typename)) { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称不能为空!', IconOption.哭脸, 2000);</script>"); return; } Hi.Model.BD_GoodsCategory model = new Hi.BLL.BD_GoodsCategory().GetModel(Convert.ToInt32(id)); if (model != null) { if (IsExistsType("CategoryName", Typename, id, model.ParentId.ToString())) { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称已存在!', IconOption.哭脸, 2000);</script>"); return; } if (model.Deep == 1) { if (this.hid_txtGtype2.Value == "0") { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('请选择大类!', IconOption.哭脸, 2000);</script>"); return; } } } if (int.TryParse(id, out Result)) { //Hi.Model.BD_GoodsCategory DisType = categoryList.Find(p=>p.ID ==Result); Hi.Model.BD_GoodsCategory DisType = new Hi.BLL.BD_GoodsCategory().GetModel(Result); if (DisType != null) { DisType.CategoryName = Typename; DisType.SortIndex = sortid; //DisType.TypeCode = typecode; DisType.GoodsTypeID = Convert.ToInt32(this.hid_txtGtype2.Value); DisType.ts = DateTime.Now; DisType.modifyuser = 0; if (new Hi.BLL.BD_GoodsCategory().Update(DisType)) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('编辑成功!', IconOption.笑脸, 2000);location.href=location.href;</script>"); } } else { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('编辑失败!', IconOption.哭脸, 2000);</script>"); return; } } else { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.alert('分类异常!', IconOption.错误, 2000);</script>"); return; } }
/// <summary> /// 获取最大Code /// </summary> /// <param name="deep"></param> /// <returns></returns> public string NewCategoryCode(string deep) { string NewCode = string.Empty; List <Hi.Model.BD_GoodsCategory> oneList = new Hi.BLL.BD_GoodsCategory().GetList("", "deep = '" + deep + "'", "ID desc"); if (oneList != null && oneList.Count > 0) { if (deep == "1") { NewCode = oneList[0].Code.Substring(0, 4); } else if (deep == "2") { NewCode = oneList[0].Code.Substring(5, 4); } else { NewCode = oneList[0].Code.Substring(10, 4); } } else { NewCode = "999"; } return((Convert.ToInt32(NewCode) + 1).ToString()); }
/// <summary> /// 商品类别 /// </summary> /// <param name="id"></param> /// <returns></returns> public string GoodsCategory(string id) { var lsit = new Hi.BLL.BD_GoodsCategory().GetList("", " isnull(dr,0)=0 and isenabled=1 and compid=" + this.CompID + " and id=" + id, ""); if (lsit.Count > 0) { return(lsit[0].CategoryName); } return(""); }
/// <summary> /// 获取最底层的分类 /// </summary> /// <returns></returns> public string GetMinCategory(int id) { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=" + id, ""); if (ll.Count > 0) { return("y"); } return(""); }
/// <summary> /// 商品类别 /// </summary> public void GetGoodsCategory() { List <Hi.Model.BD_GoodsCategory> l = new Hi.BLL.BD_GoodsCategory().GetList("", " ISNULL(dr,0)=0 and compid=" + CompId, "sortindex, parentid"); if (l.Count > 0) { foreach (Hi.Model.BD_GoodsCategory goodsCate in l) { goodsCategory.Add(goodsCate); } } }
/// <summary> /// 绑定商品分类 /// </summary> /// <param name="CompId"></param> /// <returns></returns> public string GoodsCategory(int CompId) { StringBuilder sb = new StringBuilder(); List <Hi.Model.BD_GoodsCategory> cl = new Hi.BLL.BD_GoodsCategory().GetList("", "CompID=" + CompId + " and Isnull(dr,0)=0 and Isnull(IsEnabled,0)=1", ""); if (cl != null && cl.Count > 0) { //商品分类一级 List <Hi.Model.BD_GoodsCategory> cl1 = cl.FindAll(p => p.Deep == 1 && p.ParentId == 0); if (cl1 != null && cl1.Count > 0) { sb.Append("<div class=\"sorts\">"); sb.AppendFormat("<div class=\"sorts1\"><i class=\"arrow2\"></i><a href=\"javascript:;\" class=\"a1\" tip=\"\">{0}</a></div>", "全部"); sb.Append("</div>"); foreach (var item in cl1) { sb.Append("<div class=\"sorts\">"); sb.AppendFormat("<div class=\"sorts1\"><i class=\"arrow2\"></i><a href=\"javascript:;\" class=\"a1\" tip=\"{1}\">{0}</a></div>", item.CategoryName, item.ID); //商品分类二级 List <Hi.Model.BD_GoodsCategory> cl2 = cl.FindAll(p => p.Deep == 2 && p.ParentId == item.ID); if (cl2 != null && cl2.Count > 0) { sb.Append("<ul class=\"sorts2\" tipdis=\"no\" style=\"display:none;\">"); foreach (var item2 in cl2) { sb.Append("<li>"); sb.AppendFormat("<i class=\"arrow3\"></i><a href=\"javascript:;\" tip=\"{1}\">{0}</a>", item2.CategoryName, item2.ID); //商品分类三级 List <Hi.Model.BD_GoodsCategory> cl3 = cl.FindAll(p => p.Deep == 3 && p.ParentId == item2.ID); if (cl3 != null && cl3.Count > 0) { sb.Append("<ul class=\"sorts3\" tipdis=\"no\" style=\"display:none;\">"); foreach (var item3 in cl3) { sb.AppendFormat("<li tip=\"{1}\"><a href=\"javascript:;\" tip=\"{1}\">{0}</a></li>", item3.CategoryName, item3.ID); } sb.Append("</ul>"); } sb.Append("</li>"); } sb.Append("</ul>"); } sb.Append("</div>"); } } } return(sb.ToString()); }
/// <summary> /// 商品类别 /// </summary> public void GetGoodsCategory() { string CompId = Request.QueryString["hidCompID"].ToString(); List <Hi.Model.BD_GoodsCategory> l = new Hi.BLL.BD_GoodsCategory().GetList("", " ISNULL(dr,0)=0 and compid in(" + CompId + ")", "sortindex, parentid"); if (l.Count > 0) { foreach (Hi.Model.BD_GoodsCategory goodsCate in l) { goodsCategory.Add(goodsCate); } } }
/// <summary> /// 判断属性值是否存在 /// </summary> /// <param name="name"></param> /// <returns></returns> public bool IsExistsType(string name, string value, string id, string ParentId) { bool bfg = false; if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(value)) { List <Hi.Model.BD_GoodsCategory> List = new Hi.BLL.BD_GoodsCategory().GetList("ID", name + "='" + value + "' and id<>'" + id + "' and CompID=" + CompID + " and isnull(dr,0)=0 and ParentId=" + ParentId, ""); if (List != null && List.Count > 0) { bfg = true; } } return(bfg); }
protected string GetDeep(object obj) { string res = "1"; if (obj != null) { Hi.Model.BD_GoodsCategory l = new Hi.BLL.BD_GoodsCategory().GetModel(Convert.ToInt32(obj)); if (l != null) { res = l.Deep.ToString(); } } return(res); }
/// <summary> /// 最新 的排序号 /// </summary> /// <returns></returns> public static int NewCateId() { List <int> intList = new List <int>(); List <Hi.Model.BD_GoodsCategory> goodsCategoryList = new Hi.BLL.BD_GoodsCategory().GetAllList(); if (goodsCategoryList != null && goodsCategoryList.Count > 0) { intList.AddRange(goodsCategoryList.Select(item => Convert.ToInt32(string.IsNullOrEmpty(item.SortIndex) ? "0" : item.SortIndex))); return(intList.Max() != 0 ? intList.Max() + 1 : 1000); } else { return(1000); } }
public void BindGoodsCategory() { List <Hi.Model.BD_GoodsCategory> ClassList = new Hi.BLL.BD_GoodsCategory().GetList(" id,CategoryName ", " dr=0 and IsEnabled=1 and Parentid=0 and Compid='" + ViewState["Compid"] + "' ", " createdate "); string.Join(",", ClassList.Select(p => p.ID)); if (ClassList.Count > 0) { Hi.Model.BD_GoodsCategory DefaultClass = new Hi.Model.BD_GoodsCategory(); DefaultClass.CategoryName = "全 部"; DefaultClass.ID = 0; DefaultClass.CompID = ClassList[0].CompID; DefaultClass.ParentId = 0; DefaultClass.IsEnabled = 1; ClassList.Insert(0, DefaultClass); } Rpt_GoodsClass.DataSource = ClassList; Rpt_GoodsClass.DataBind(); }
/// <summary> /// 删除分类 /// </summary> /// <param name="id"></param> /// <returns></returns> public string DelType(string id) { string json = string.Empty; if (!string.IsNullOrEmpty(id)) { categoryList = new Hi.BLL.BD_GoodsCategory().GetList("", " ParentId = '" + id + "' and CompID=" + this.CompID + " and isnull(dr,0)=0 ", ""); List <Hi.Model.BD_GoodsCategory> List = categoryList != null && categoryList.Count > 0 ? categoryList.Where(p => p.ParentId.ToString() == id).ToList() : null; if (List != null && List.Count > 0) { return("{\"result\":false,\"code\":\"此类别下还有子级类别,请先删除子级类别!\"}"); } List <Hi.Model.BD_Goods> Dis = new Hi.BLL.BD_Goods().GetList(null, " CompID=" + CompID + " and isnull(dr,0)=0 and CategoryID=" + id, null); if (Dis != null && Dis.Count > 0) { return("{\"result\":false,\"code\":\"此分类已被使用,不允许删除!\"}"); } Hi.Model.BD_GoodsCategory type = new Hi.BLL.BD_GoodsCategory().GetModel(id.ToInt(0)); if (type != null && type.dr == 0) { type.dr = 1; type.ts = DateTime.Now; type.modifyuser = UserID; if (new Hi.BLL.BD_GoodsCategory().Update(type)) { categoryList = new Hi.BLL.BD_GoodsCategory().GetList("", "CompID=" + this.CompID + " and IsEnabled = 1 and isnull(dr,0)=0 ", ""); return("{\"result\":true,\"code\":\"操作成功\"}"); } } else { return("{\"result\":false,\"code\":\"类别已删除!\"}"); } } return(json); }
/// <summary> /// 获取分类名称 /// </summary> /// <returns></returns> public string GoodsCategory(string id) { if (!Util.IsEmpty(id)) { Hi.Model.BD_Goods mode = new Hi.BLL.BD_Goods().GetModel(Convert.ToInt32(id)); if (mode != null) { var lsit = new Hi.BLL.BD_GoodsCategory().GetList("", " isnull(dr,0)=0 and isenabled=1 and compid=" + this.CompID + " and id=" + mode.CategoryID, ""); if (lsit.Count > 0) { return(lsit[0].CategoryName); } return(""); } else { return(""); } } else { return(""); } }
/// <summary> /// 验证商品大类下是否包含这个商品一级分类 /// </summary> /// <returns></returns> public string CheckGoodsCate(string value, string str, int index, SqlTransaction Tran) { string catestr = string.Empty; string[] catelist = value.Split('/');//根据/分隔商品分类 for (int i = 0; i < catelist.Length; i++) { if (i == 0) {//一级 List <Hi.Model.BD_GoodsCategory> l = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=0 and categoryname='" + catelist[i] + "' and compid=" + this.CompID, "", Tran); if (l.Count == 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + TitleIndex + 1) + "</i> 的数据有误。没有【" + catelist[i] + "】这个一级分类!请修改后重新导入。<br/>"); } else { catestr = catelist[i] + "@" + l[0].ID; if (catelist.Length == 1)//只有一级分类情况 { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=" + l[0].ID + " and compid=" + this.CompID, "", Tran); if (ll.Count > 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + TitleIndex + 1) + "</i> 的数据有误。【" + catelist[i] + "】一级分类下还有二级分类,必须选择最小的分类!请修改后重新导入。<br/>"); } else { break; } } } } else if (i == 1) {//二级 string goodsCateId = string.Empty; if (catestr.IndexOf("@") != -1) { goodsCateId = catestr.Split('@')[1]; catestr = catestr.Split('@')[0]; } else { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=0 and categoryname='" + catestr + "' and compid=" + this.CompID, "", Tran); if (ll.Count > 0) { goodsCateId = ll[0].ID.ToString(); } } List <Hi.Model.BD_GoodsCategory> l = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and categoryname='" + catelist[i] + "' and compid=" + this.CompID + " and parentid=" + goodsCateId, "", Tran); if (l.Count == 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + TitleIndex + 1) + "</i> 的数据有误。【" + catestr + "】一级分类下没有【" + catelist[i] + "】这个二级分类!请修改后重新导入。<br/>"); } else { catestr = catelist[i] + "@" + l[0].ID; if (catelist.Length == 2)//只有二级分类情况 { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=" + l[0].ID + " and compid=" + this.CompID, "", Tran); if (ll.Count > 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + TitleIndex + 1) + "</i> 的数据有误。【" + catelist[i] + "】二级分类下还有三级分类,必须选择最小的分类!请修改后重新导入。<br/>"); } else { break; } } } } else if (i == 2) { //三级 string goodsCateId = string.Empty; if (catestr.IndexOf("@") != -1) { goodsCateId = catestr.Split('@')[1]; catestr = catestr.Split('@')[0]; } else { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid!=0 and categoryname='" + catestr + "' and compid=" + this.CompID, "", Tran); if (ll.Count > 0) { goodsCateId = ll[0].ID.ToString(); } } List <Hi.Model.BD_GoodsCategory> l = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and parentid=" + goodsCateId + " and categoryname='" + catelist[i] + "' and compid=" + this.CompID, "", Tran); if (l.Count == 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + TitleIndex + 1) + "</i> 的数据有误。【" + catestr + "】二级分类下没有【" + catelist[i] + "】这个三级分类!请修改后重新导入。<br/>"); } else { catestr = catelist[i] + "@" + l[0].ID; if (catelist.Length == 3)//只有二级分类情况 { break; } } } } return(catestr); }
/// <summary> /// 判断是否存在子类别 /// </summary> /// <returns></returns> public int GetGoodsCategory(int id) { var list = new Hi.BLL.BD_GoodsCategory().GetList("", "parentid=" + id + " and ISNULL(dr,0)=0 and compid=" + CompId, "");//判断是否存在下级类别 return(list.Count); }
/// <summary> /// 验证规格属性是否存在一、二、三级分类 /// </summary> /// <returns></returns> public string CheckGoodsAttr(string goodsTypeId, string goodsCate3, string value, string str, int index, SqlTransaction Tran) { string goodsCateId = string.Empty; if (goodsCate3.IndexOf("@") != -1) { categoryId = goodsCate3.Split('@')[1]; goodsCateId = goodsCate3.Split('@')[1]; goodsCate3 = goodsCate3.Split('@')[0]; } else { List <Hi.Model.BD_GoodsCategory> ll = new Hi.BLL.BD_GoodsCategory().GetList("", "isnull(dr,0)=0 and isenabled=1 and goodstypeid=" + goodsTypeId + " and categoryname='" + goodsCate3 + "' and compid=" + this.CompID, "", Tran); if (ll.Count > 0) { goodsCateId = ll[0].ID.ToString(); } } string[] valueList = value.Split(','); //规格属性以逗号分隔 bool bol = false; //如果有不存在的规格属性,则跳出for string strValue = string.Empty; //保存属性 string listId = string.Empty; //attrId for (int i = 0; i < valueList.Length; i++) { if (!Util.IsEmpty(valueList[i])) { List <Hi.Model.BD_Attribute> l = new Hi.BLL.BD_Attribute().GetList("", "isnull(dr,0)=0 and isenabled=1 and compId=" + this.CompID + " and attributename='" + valueList[i] + "'", "", Tran); if (l.Count == 0) { strValue = valueList[i]; bol = true; break; } else { foreach (Hi.Model.BD_Attribute item in l) { listId += item.ID + ","; // strValue += item.AttributeName + ","; } } } } if (bol) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + 3) + " </i> 的数据有误。" + str + "不存在" + strValue + ",请修改后重新导入。"); } else { if (!Util.IsEmpty(listId)) { listId = listId.Substring(0, listId.Length - 1); strValue = value.Replace(',', ','); } List <Hi.Model.BD_CategoryAttribute> lll = new Hi.BLL.BD_CategoryAttribute().GetList("", "isnull(dr,0)=0 and compid=" + this.CompID + " and attributeid in(" + listId + ") and categoryId=" + goodsCateId, "", Tran); if (lll.Count == 0) { Eroor = true; throw new ApplicationException("Excel行号为: <i error>" + (index + 3) + " </i> 的数据有误。" + str + "不存在" + strValue + ",请修改后重新导入。"); } else { string liststr = string.Empty; foreach (Hi.Model.BD_CategoryAttribute item in lll) { liststr += item.ID + ","; } if (!Util.IsEmpty(liststr)) { liststr = liststr.Substring(0, liststr.Length - 1); } return(listId + "@" + liststr); } } return(listId); }
/// <summary> /// 绑定产品信息 /// </summary> /// <param name="id"></param> public void Bind(int id, int goodsInfoId, int compId) { Hi.Model.BD_Goods model = new Hi.BLL.BD_Goods().GetModel(id); if (model != null && model.dr == 0 && model.IsEnabled == 1) { Hi.Model.BD_GoodsInfo model2 = new Hi.BLL.BD_GoodsInfo().GetModel(goodsInfoId); if (model2 != null) { this.lblCode.InnerText = model2.BarCode.Trim(); //商品编号 this.lblInventory.InnerText = model2.Inventory.ToString(); //库存 } Hi.Model.BD_GoodsCategory model3 = new Hi.BLL.BD_GoodsCategory().GetModel(model.CategoryID); if (model3 != null) { this.lblCategory.InnerText = model3.CategoryName.Trim(); //分类 } GetZiDingYi(model); //自定义字段 this.divTitle.InnerText = model.GoodsName.Trim(); //biaot this.divMemo.InnerHtml = model.Title.Trim(); //描述 this.lblHideInfo1.InnerText = model.HideInfo1; this.lblHideInfo2.InnerText = model.HideInfo2; //描述 this.lblUnit.InnerText = model.Unit.Trim(); //计量单位 if (model.Details == "") { this.DivShow.InnerHtml = "<p style=\"padding-top: 20px; line-height: 40px; padding-left: 20px\">暂无数据</p>"; } else { this.DivShow.InnerHtml = model.Details; } if (!string.IsNullOrEmpty(model.Pic))//有图片 { this.imgPic.Src = Common.GetPicURL(model.Pic, "resize400"); this.imgPic.Attributes.Add("jqimg", Common.GetPicURL(model.Pic)); this.imgPic2.Src = Common.GetPicURL(model.Pic, "resize400"); this.imgPic2.Attributes.Add("bimg", Common.GetPicURL(model.Pic)); } else { this.imgPic.Src = "../../images/havenopicmax.gif"; //无图片 this.imgPic2.Src = "../../images/havenopicmax.gif"; //无图片 this.imgPic2.Attributes.Add("bimg", "../../images/havenopicmax.gif"); this.imgPic.Attributes.Add("jqimg", "../../images/havenopicmax.gif"); } //add by hgh 设置商品是否首页显示 this.labText.Text = model.IsFirstShow == true ? "是" : "否"; } else { JScript.AlertMsg(this, "商品不存在或者已经被删除", "GoodsInfoList.aspx"); return; } string html = string.Empty; List <Hi.Model.BD_GoodsAttrs> ll = new Hi.BLL.BD_GoodsAttrs().GetList("", "isnull(dr,0)=0 and compId=" + compId + " and goodsId=" + id.ToString(), ""); if (ll.Count > 0) { int xy = 0; foreach (Hi.Model.BD_GoodsAttrs item in ll) { List <Hi.Model.BD_GoodsAttrsInfo> lll = new Hi.BLL.BD_GoodsAttrsInfo().GetList("", "isnull(dr,0)=0 and compId=" + compId + " and attrsId=" + item.ID, ""); if (lll.Count > 0) { html += "<div class=\"li\"><i class=\"bt2\" tip=\"" + item.AttrsName + "\">" + item.AttrsName + ":</i><div class=\"fun\">"; foreach (Hi.Model.BD_GoodsAttrsInfo item2 in lll) { Hi.Model.BD_GoodsInfo model4 = new Hi.BLL.BD_GoodsInfo().GetModel(goodsInfoId); if (xy == 0) { html += "<a href=\"javascript:;\" class=\"" + (model4.Value1 == item2.AttrsInfoName.Trim() ? "hover" : "") + "\" tip=\"" + item2.AttrsInfoName + "\">" + item2.AttrsInfoName + "</a>"; } else if (xy == 1) { html += "<a href=\"javascript:;\" class=\"" + (model4.Value2 == item2.AttrsInfoName.Trim() ? "hover" : "") + "\" tip=\"" + item2.AttrsInfoName + "\">" + item2.AttrsInfoName + "</a>"; } else if (xy == 2) { html += "<a href=\"javascript:;\" class=\"" + (model4.Value3 == item2.AttrsInfoName.Trim() ? "hover" : "") + "\" tip=\"" + item2.AttrsInfoName + "\">" + item2.AttrsInfoName + "</a>"; } } html += "</div></div>"; } xy++; } } litAttrVaue.Text = html; }
/// <summary> /// 新增子类 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAdd_Click(object sender, EventArgs e) { string Typename = Common.NoHTML(txtTypeName.Value.Trim()); string Parentid = Common.NoHTML(hideTypeId.Value.Trim()); string Typecode = string.Empty; string ParentIds = "0";//父元素ID 用于判断是否存在重复子元素 Hi.Model.BD_GoodsCategory DisType = new Hi.Model.BD_GoodsCategory(); if (Parentid != "0" && Parentid != "") { Hi.Model.BD_GoodsCategory one = new Hi.BLL.BD_GoodsCategory().GetModel(Convert.ToInt32(Parentid)); if (one != null) { Typecode = one.GoodsTypeID.ToString(); //商品大类 DisType.Code = one.Code + "-" + NewCategoryCode((one.Deep + 1).ToString()); DisType.Deep = one.Deep + 1; DisType.ParCode = one.Code; ParentIds = one.ID.ToString(); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('添加失败!', IconOption.哭脸, 2000);</script>"); return; } if (DisType.Deep == 4) { Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('最多只能三级!', IconOption.哭脸, 2000);</script>"); return; } } else//一级大类 { Typecode = hid_txtGtype.Value;;//商品大类 DisType.Code = NewCategoryCode("1"); DisType.Deep = 1; DisType.ParCode = ""; ParentIds = "0"; } int Result = 0; if (string.IsNullOrEmpty(Typecode) || Typecode == "0") { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('商品大类不能为空!', IconOption.哭脸, 2000);</script>"); return; } else if (Parentid == "0") { Hi.Model.SYS_GType gtype = new Hi.BLL.SYS_GType().GetModel(Convert.ToInt32(Typecode)); if (gtype.Deep != 3) { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('请选择三级商品大类!', IconOption.哭脸, 2000);</script>"); return; } } if (string.IsNullOrEmpty(Typename)) { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称不能为空!', IconOption.哭脸, 2000);</script>"); return; } if (IsExistsType("CategoryName", Typename, ParentIds)) { ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('分类名称已存在!', IconOption.哭脸, 2000);</script>"); return; } if (string.IsNullOrEmpty(Parentid) || !int.TryParse(Parentid, out Result)) { DisType.ParentId = 0; } else { DisType.ParentId = Result; } DisType.CompID = CompID; DisType.CategoryName = Typename; DisType.GoodsTypeID = Convert.ToInt32(Typecode); DisType.SortIndex = NewCateId().ToString(); DisType.CreateDate = DateTime.Now; DisType.CreateUserID = 0; DisType.IsEnabled = 1; DisType.ts = DateTime.Now; DisType.modifyuser = 0; SqlTransaction trans = SqlHelper.CreateStoreTranSaction(); try { int countID = 0; if ((countID = new Hi.BLL.BD_GoodsCategory().Add(DisType, trans)) > 0) { List <Hi.Model.BD_Goods> gList = new Hi.BLL.BD_Goods().GetList("", " CategoryID='" + Parentid + "'", ""); if (gList != null && gList.Count > 0) { foreach (var bdGoodse in gList) { bdGoodse.CategoryID = countID; new Hi.BLL.BD_Goods().Update(bdGoodse, trans); } } trans.Commit(); Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('新增成功!', IconOption.笑脸, 2000);location.href='GoodsCategory.aspx?type=" + Request["type"].ToString() + "';</script>"); } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('添加失败!', IconOption.哭脸, 2000);</script>"); } } catch (Exception ex) { if (trans != null) { if (trans.Connection != null) { trans.Rollback(); } } ClientScript.RegisterStartupScript(this.GetType(), "Result", "<script>layerCommon.msg('" + ex.Message + "', IconOption.哭脸, 2000);</script>"); return; } finally { SqlHelper.ConnectionClose(); if (trans != null) { if (trans.Connection != null) { trans.Connection.Close(); } } } }