public ReturnType RemoveSellerCat(string sellercatCode) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { /*List<SellerCat> list = alading.SellerCat.Where(p => p.SellerCatID == sellercatID).ToList();*/ List <SellerCat> list = alading.SellerCat.Where(p => p.SellerCatCode == sellercatCode).ToList(); if (list.Count == 0) { return(ReturnType.NotExisted); } else { SellerCat sy = list.First(); alading.DeleteObject(sy); alading.SaveChanges(); return(ReturnType.Success); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (System.Exception ex) { return(ReturnType.OthersError); } }
public ReturnType IsSellercatExisted(string nick, string cid) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { SellerCat result = alading.SellerCat.Where(p => p.SellerNick == nick && p.cid == cid).FirstOrDefault(); if (result == null) { return(ReturnType.NotExisted); } else { return(ReturnType.PropertyExisted); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (Exception ex) { return(ReturnType.OthersError); } }
private TreeNode GetNodeByCategory(SellerCat category) { TreeNode node = new TreeNode(); node.Text = category.Name; node.Value = category.Cid; return(node); }
private void AddCategory(List <SellerCat> categoryList, SellerCat category, TreeNode parentNode) { TreeNode node = GetNodeByCategory(category); parentNode.ChildNodes.Add(node); List <SellerCat> currentList = GetCatListByParent(categoryList, category == null ? "0" : category.Cid); foreach (SellerCat children in currentList) { AddCategory(categoryList, children, node); } }
public ReturnType UpdateSellerCat(string sellercatCode, SellerCat sellercat) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { /*var result = alading.SellerCat.Where(p => p.SellerCatID == sellercatID).ToList();*/ var result = alading.SellerCat.Where(p => p.SellerCatCode == sellercatCode).ToList(); if (result.Count == 0) { return(ReturnType.NotExisted); } SellerCat ob = result.First(); ob.cid = sellercat.cid; ob.parent_cid = sellercat.parent_cid; ob.name = sellercat.name; ob.pic_url = sellercat.pic_url; ob.sort_order = sellercat.sort_order; if (alading.SaveChanges() == 1) { return(ReturnType.Success); } else { return(ReturnType.OthersError); } } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (System.Exception ex) { return(ReturnType.OthersError); } }
public ReturnType UpdateSellerCat(SellerCat sellercat) { try { using (AladingEntities alading = new AladingEntities(AppSettings.GetConnectionString())) { SellerCat result = alading.SellerCat.Where(p => p.SellerNick == sellercat.SellerNick && p.cid == sellercat.cid).FirstOrDefault(); if (result == null) { return(ReturnType.NotExisted); } result.parent_cid = sellercat.parent_cid; result.name = sellercat.name; result.pic_url = sellercat.pic_url; result.sort_order = sellercat.sort_order; result.num = sellercat.num; if (alading.SaveChanges() == 1) { return(ReturnType.Success); } return(ReturnType.OthersError); } } catch (SqlException sex) { return(ReturnType.ConnFailed); } catch (Exception ex) { return(ReturnType.OthersError); } }
public static ReturnType UpdateSellerCat(string sellercatCode, SellerCat sellercat) { return(DataProviderClass.Instance().UpdateSellerCat(sellercatCode, sellercat)); }
/// <summary> /// 存在更新,不存在添加 /// </summary> /// <param name="sellercat"></param> /// <returns></returns> public static ReturnType AddSellerCat(SellerCat sellercat) { return(DataProviderClass.Instance().AddSellerCat(sellercat)); }
private TreeNode GetNodeByCategory(SellerCat category) { TreeNode node = new TreeNode(); node.Text = category.Name; node.Value = category.Cid; return node; }
private void AddCategory(List<SellerCat> categoryList, SellerCat category, TreeNode parentNode) { TreeNode node = GetNodeByCategory(category); parentNode.ChildNodes.Add(node); List<SellerCat> currentList = GetCatListByParent(categoryList, category == null ? "0" : category.Cid); foreach (SellerCat children in currentList) { AddCategory(categoryList, children, node); } }
/// <summary> /// 获取商品所属的店铺类目列表 /// </summary> /// <param name="sellerCats">卖家的类目列表</param> /// <param name="parentSellCatName">店铺的父组类目</param> /// <param name="childSellCatsNames">子类目列表</param> public string GetSellerCids(List <SellerCat> sellerCats, string parentSellCatName, params string[] childSellCatsNames) { if (string.IsNullOrEmpty(parentSellCatName)) { throw new Exception( Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat( new StackTrace().ToString())); } // 获取父节点 SellerCat parentSellerCat = sellerCats.FirstOrDefault(s => s.Name.ToUpper() == parentSellCatName); if (parentSellerCat == null) { throw new Exception( Resource.ExceptionTemplate_MethedParameterIsNullorEmpty.StringFormat( new StackTrace().ToString())); } //如果用户数据有误,将子节点放到了父结点中,如果发现是子节点,就直接返回CID if (parentSellerCat.ParentCid != 0) { return(parentSellerCat.Cid.ToString(CultureInfo.InvariantCulture)); } //如果子结点为空,直接返回父亲结点CID // ReSharper disable AssignNullToNotNullAttribute if (childSellCatsNames == null && !childSellCatsNames.Any()) // ReSharper restore AssignNullToNotNullAttribute { return(parentSellerCat.Cid.ToString(CultureInfo.InvariantCulture)); } #region 原始版 //1, 获取该parentName对应的Cid // var parentCid = sellerCats.FirstOrDefault(s=>s.Name == parentSellCatName); // // if (parentCid == null) // return null; //2,根据父CID和各类别名查找相应的子类别用逗号分开 //string result = null; //foreach (var cat in childSellCatsNames) //{ // var sellerCat = sellerCats.FirstOrDefault(s => s.ParentCid == parentCid.Cid && s.Name == cat); // if (sellerCat != null) // { // if (!string.IsNullOrEmpty(result)) // result += "," + sellerCat.Cid; // else // result += sellerCat.Cid; // } //} //return result; //等同于下面表达式 #endregion string result = null; foreach ( SellerCat sellerCat in childSellCatsNames.Select( cat => sellerCats.FirstOrDefault(s => s.ParentCid == parentSellerCat.Cid && s.Name.Contains(cat))) .Where(sellerCat => sellerCat != null)) { if (!string.IsNullOrEmpty(result)) { result += "," + sellerCat.Cid; } else { result += sellerCat.Cid; } } return(result); }