public List <Model.CategoryInfo> GetCategoryByTitle(string title) { List <Model.CategoryInfo> list = null; SqlParameter parm = new SqlParameter("@Title", SqlDbType.NVarChar, 10); parm.Value = title; using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.StoredProcedure, "Pro_GetCategoryByTitle", parm)) { if (reader != null && reader.HasRows) { list = new List <Model.CategoryInfo>(); while (reader.Read()) { Model.CategoryInfo model = new Model.CategoryInfo(); model.NumberID = reader.GetString(0); model.CategoryName = reader.GetString(1); model.ParentID = reader.GetString(2); list.Add(model); } } } return(list); }
/// <summary> /// 绑定分类 /// </summary> private void BindCategory() { string sRelativePath = VirtualPathUtility.MakeRelative(Request.AppRelativeCurrentExecutionFilePath, "~/Shares/SearchProduct.aspx"); string categoryAppend = string.Empty; List <Model.CategoryInfo> list = WebHelper.CategoryDataProxy.GetList(); if (list != null && list.Count > 0) { Model.CategoryInfo rootItem = list.Find(delegate(Model.CategoryInfo model) { return(model.CategoryName == "所有分类"); }); if (rootItem != null) { List <Model.CategoryInfo> list1 = list.FindAll(delegate(Model.CategoryInfo model) { return(model.ParentID == rootItem.NumberID); }); if (list1 != null && list1.Count > 0) { foreach (Model.CategoryInfo model1 in list1) { categoryAppend += string.Format("<a href=\"" + sRelativePath + "?c={1}\" class=\"ad ad-1\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></a>", model1.CategoryName, model1.NumberID); List <Model.CategoryInfo> list2 = list.FindAll(delegate(Model.CategoryInfo model2) { return(model2.ParentID == model1.NumberID); }); if (list2 != null && list2.Count > 0) { foreach (Model.CategoryInfo model2 in list2) { categoryAppend += string.Format("<a href=\"" + sRelativePath + "?c={1}\" class=\"ad ad-2\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></a>", model2.CategoryName, model2.NumberID); } } } } } } ltrCategory.Text = categoryAppend; }
public IList <Model.CategoryInfo> GetListInParentIds(string parentIdsAppend) { IList <Model.CategoryInfo> list = null; SqlParameter parm = new SqlParameter("@ParentIds", parentIdsAppend); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.StoredProcedure, "Pro_GetCategoryInParentIds", parm)) { if (reader.HasRows) { list = new List <Model.CategoryInfo>(); while (reader.Read()) { Model.CategoryInfo model = new Model.CategoryInfo(); model.NumberID = reader["NumberID"].ToString(); model.CategoryName = reader["CategoryName"].ToString(); model.ParentID = reader["ParentID"].ToString(); model.Remark = reader["Remark"].ToString(); list.Add(model); } } } return(list); }
public List <Model.CategoryInfo> GetList() { List <Model.CategoryInfo> list = new List <Model.CategoryInfo>(); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.StoredProcedure, "Pro_GetCategories")) { if (reader.HasRows) { while (reader.Read()) { Model.CategoryInfo model = new Model.CategoryInfo(); model.NumberID = reader.GetString(0); model.CategoryName = reader.GetString(1); model.ParentID = reader.GetString(2); model.Sort = reader.GetInt32(3); model.Remark = reader.GetString(4); model.Title = reader.GetString(5); model.CreateDate = reader.GetDateTime(6); list.Add(model); } } } return(list); }
public int Update(Model.CategoryInfo model) { if (model == null) { return(-1); } if (IsExist(model.CategoryName, model.ParentID, model.NumberID)) { return(110); } string cmdText = "update Category set CategoryName = @CategoryName,ParentID = @ParentID,Sort = @Sort,Remark = @Remark,Title = @Title where NumberID = @NumberID"; SqlParameter[] parms = { new SqlParameter("@NumberID", SqlDbType.VarChar, 50), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 256), new SqlParameter("@ParentID", SqlDbType.VarChar, 50), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@Remark", SqlDbType.VarChar, 300), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@Title", SqlDbType.NVarChar, 20) }; parms[0].Value = model.NumberID; parms[1].Value = model.CategoryName; parms[2].Value = model.ParentID; parms[3].Value = model.Sort; parms[4].Value = model.Remark; parms[5].Value = model.CreateDate; parms[6].Value = model.Title; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms)); }
public Model.CategoryInfo GetModel(string numberId) { Model.CategoryInfo model = null; string cmdText = "select top 1 * from Category where NumberID = @NumberID order by CreateDate desc"; SqlParameter parm = new SqlParameter("@NumberID", numberId); using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parm)) { if (reader != null) { while (reader.Read()) { model = new Model.CategoryInfo(); model.NumberID = reader["NumberID"].ToString(); model.CategoryName = reader["CategoryName"].ToString(); model.ParentID = reader["ParentID"].ToString(); model.Sort = int.Parse(reader["Sort"].ToString()); model.Remark = reader["Remark"].ToString(); model.CreateDate = DateTime.Parse(reader["CreateDate"].ToString()); } } } return(model); }
/// <summary> /// 检索当前分类节点的所有子级节点,并返回检索到的项集合 /// </summary> /// <param name="list"></param> /// <param name="currentModel"></param> /// <param name="newList"></param> private void GetChild(List <Model.CategoryInfo> list, Model.CategoryInfo currentModel, ref List <Model.CategoryInfo> newList) { if (list == null || currentModel == null) { return; } newList = list.FindAll(delegate(Model.CategoryInfo model) { return(model.ParentID == currentModel.NumberID); }); }
/// <summary> /// 检索当前分类节点的所有父级节点,并返回检索到的项集合 /// </summary> /// <param name="list"></param> /// <param name="currentModel"></param> /// <param name="newList"></param> private void GetParent(List <Model.CategoryInfo> list, Model.CategoryInfo currentModel, ref List <Model.CategoryInfo> newList) { if (list == null || currentModel == null) { return; } if (currentModel.ParentID != "0") { Model.CategoryInfo parent = list.Find(delegate(Model.CategoryInfo model) { return(model.NumberID == currentModel.ParentID); }); if (parent != null) { newList.Add(parent); GetParent(list, parent, ref newList); } } }
/// <summary> /// 绑定分类 /// </summary> private void BindCategory() { string sRelativePath = VirtualPathUtility.MakeRelative(Request.AppRelativeCurrentExecutionFilePath, "~/Shares/SearchProduct.aspx"); string categoryAppend = string.Empty; List <Model.CategoryInfo> list = WebHelper.CategoryDataProxy.GetList(); if (list != null && list.Count > 0) { Model.CategoryInfo rootItem = list.Find(delegate(Model.CategoryInfo model) { return(model.CategoryName == "所有分类"); }); if (rootItem != null) { List <Model.CategoryInfo> list1 = list.FindAll(delegate(Model.CategoryInfo model) { return(model.ParentID == rootItem.NumberID); }); if (list1 != null && list1.Count > 0) { int n = 0; foreach (Model.CategoryInfo model1 in list1) { n++; string shide_bt = string.Empty; if (n == 1) { shide_bt = "hide_bt"; } categoryAppend += string.Format("<div class=\"item " + shide_bt + "\"><span><h3><a href=\"{1}\">{0}</a></h3><s></s></span>", model1.CategoryName, sRelativePath + "?c=" + model1.NumberID + ""); categoryAppend += "<div class=\"i-mc\" style=\"top:3px;\">"; categoryAppend += "<div onclick=\"$(this).parent().parent().removeClass('hover')\" class=\"close\"></div>"; categoryAppend += "<div class=\"subitem\">"; List <Model.CategoryInfo> list2 = list.FindAll(delegate(Model.CategoryInfo model2) { return(model2.ParentID == model1.NumberID); }); if (list2 != null && list2.Count > 0) { foreach (Model.CategoryInfo model2 in list2) { categoryAppend += string.Format("<dl><dt><a href=\"{1}\">{0}</a></dt><dd><em><a href=\"{1}\">{0}</a></em></dd></dl>", model2.CategoryName, sRelativePath + "?c=" + model2.NumberID + ""); } } categoryAppend += "</div></div></div>"; } } } } ltrCategory.Text = categoryAppend; }
/// <summary> /// 检索当前分类节点的所有子级节点,并返回检索到的项集合 /// </summary> /// <param name="list"></param> /// <param name="currentModel"></param> /// <param name="newList"></param> private void GetLastChildAll(List <Model.CategoryInfo> list, Model.CategoryInfo currentModel, ref List <Model.CategoryInfo> newList) { if (list == null || currentModel == null) { return; } List <Model.CategoryInfo> childList = list.FindAll(delegate(Model.CategoryInfo model) { return(model.ParentID == currentModel.NumberID); }); if (childList != null && childList.Count > 0) { foreach (Model.CategoryInfo model in childList) { GetLastChildAll(list, model, ref newList); } } else { newList.Add(currentModel); } }
public ActionResult EditCate(int isfirst, int parentid, string catename) { string errorType = ""; string msg = "OK"; //用来返回刚插入的记录的ID string insertID = ""; // 验证参数 if (isfirst == 1 && string.IsNullOrWhiteSpace(catename)) { errorType = "FirstName"; msg = "请输入一级名称"; } if (isfirst == 0 && string.IsNullOrWhiteSpace(catename)) { errorType = "SecondName"; msg = "请输入二级名称"; } else if (BLL.CategoryInfoBll.GetCountByCateName(catename)) { errorType = isfirst == 1 ? "FirstName" : "SecondName"; msg = "已存在该分类"; } else { // 添加用户 Model.CategoryInfo cateInfo = new Model.CategoryInfo() { CategoryName = catename, ParentId = parentid, IsDelete = 0 }; bool result = BLL.CategoryInfoBll.Add(cateInfo); if (!result) { errorType = "alert"; msg = "添加失败,请重试"; } } return(Json(new { Message = msg, ErrorType = errorType, InsertID = insertID }, JsonRequestBehavior.AllowGet)); }
public static bool Add(Model.CategoryInfo entity) { var sql = @" INSERT INTO [CategoryInfo] ( CategoryName ,ParentId ,IsDelete ) VALUES ( @CategoryName ,@ParentId ,@IsDelete )"; var parameters = new List <SqlParameter>(); parameters.Add(new SqlParameter() { ParameterName = "@CategoryName", Value = entity.CategoryName }); parameters.Add(new SqlParameter() { ParameterName = "@ParentId", Value = entity.ParentId }); parameters.Add(new SqlParameter() { ParameterName = "@IsDelete", Value = 0 }); try { return(SqlHelper.ExecuteNonQuery(sql, parameters.ToArray()) > 0); } catch { return(false); } }
/// <summary> /// 绑定数据 /// </summary> private void Bind() { //如果当前是编辑进入页面,择执行修改操作 if (!string.IsNullOrEmpty(cId)) { if (cBll == null) { cBll = new BLL.Category(); } Model.CategoryInfo model = cBll.GetModel(cId); ListItem li = null; if (model != null) { txtCategoryname.Value = model.CategoryName; li = ddlCategory.Items.FindByValue(model.ParentID); if (li != null) { li.Selected = true; } txtRemark.Value = model.Remark; } } }
public int Insert(Model.CategoryInfo model) { if (model == null) { return(-1); } if (IsExist(model.CategoryName, model.ParentID, "")) { return(110); } //定义查询命令 string cmdText = "insert into Category (NumberID,CategoryName,ParentID,Sort,Remark,Title,CreateDate) values (@NumberID,@CategoryName,@ParentID,@Sort,@Remark,@Title,@CreateDate)"; //创建查询命令参数集 SqlParameter[] parms = { new SqlParameter("@NumberID", SqlDbType.VarChar, 50), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 256), new SqlParameter("@ParentID", SqlDbType.VarChar, 50), new SqlParameter("@Sort", SqlDbType.Int), new SqlParameter("@Remark", SqlDbType.NVarChar, 300), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@Title", SqlDbType.NVarChar, 20), }; parms[0].Value = NumberID.GetNumberID("c"); parms[1].Value = model.CategoryName; parms[2].Value = model.ParentID; parms[3].Value = model.Sort; parms[4].Value = model.Remark; parms[5].Value = model.CreateDate; parms[6].Value = model.Title; return(SqlHelper.ExecuteNonQuery(SqlHelper.SqlProviderConnString, CommandType.Text, cmdText, parms)); }
/// <summary> /// 保存数据 /// </summary> private void OnSave() { hBackToN.Value = (int.Parse(hBackToN.Value) + 1).ToString();; #region 获取输入并验证 string sName = txtCategoryname.Value.Trim(); string sParentID = "0"; string sRemark = txtCategoryname.Value.Trim(); if (ddlCategory.SelectedIndex > -1) { sParentID = ddlCategory.SelectedValue; } if (string.IsNullOrEmpty(sName)) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "分类名称不能为空", "操作错误", "error"); return; } #endregion if (cBll == null) { cBll = new BLL.Category(); } Model.CategoryInfo model = new Model.CategoryInfo(); model.CategoryName = sName; model.ParentID = sParentID; model.Remark = sRemark; model.Sort = 0; model.CreateDate = DateTime.Now; model.Title = title; int result = -1; if (!string.IsNullOrEmpty(cId)) { model.NumberID = cId; result = cBll.Update(model); } else { result = cBll.Insert(model); } if (result == 110) { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "分类名称已存在,请换一个再重试!"); return; } if (result > 0) { WebHelper.MessageBox.MessagerShow(this.Page, lbtnSave, "提交成功!"); //重新加载所属分类 InitCategoryList(ddlCategory); } else { WebHelper.MessageBox.Messager(this.Page, lbtnSave, "提交失败,系统异常!", "系统提示"); } }
public static bool Add(Model.CategoryInfo entity) { return(DAL.CategoryInfoDal.Add(entity)); }
///// <summary> ///// 获取列表查询条件项,并构建查询参数集 ///// </summary> //private void GetSearchItem() //{ // if (parms == null) parms = new ParamsHelper(); // if (!string.IsNullOrEmpty(keyword)) // { // string productName = keyword; // hKw.Value = productName; // sqlWhere += "and ProductName like @ProductName "; // SqlParameter parm = new SqlParameter("@ProductName", SqlDbType.NVarChar, 256); // parm.Value = "%" + productName + "%"; // parms.Add(parm); // } // string sSPrice = txtSPrice.Value.Trim(); // if (!string.IsNullOrEmpty(sSPrice)) // { // decimal minPrice = 0; // if (decimal.TryParse(sSPrice, out minPrice)) // { // sqlWhere += "and ProductPrice >= @MinPrice "; // SqlParameter parm = new SqlParameter("@MinPrice", SqlDbType.Decimal); // parm.Value = minPrice; // parms.Add(parm); // } // } // string sEPrice = txtEPrice.Value.Trim(); // if (!string.IsNullOrEmpty(sEPrice)) // { // decimal maxPrice = 0; // if (decimal.TryParse(sEPrice, out maxPrice)) // { // sqlWhere += "and ProductPrice <= @MaxPrice "; // SqlParameter parm = new SqlParameter("@MaxPrice", SqlDbType.Decimal); // parm.Value = maxPrice; // parms.Add(parm); // } // } //} /// <summary> /// 绑定分类 /// </summary> private void BindCategory() { string categoryAppend = string.Empty; List <Model.CategoryInfo> list = WebHelper.CategoryDataProxy.GetList(); if (list != null && list.Count > 0) { //获取当前分类 Model.CategoryInfo currentItem = null; if (!string.IsNullOrEmpty(categoryId)) { currentItem = list.Find(delegate(Model.CategoryInfo model) { return(model.NumberID == categoryId); }); } if ((currentItem != null)) { string navMap = currentItem.CategoryName; List <Model.CategoryInfo> parentList = new List <Model.CategoryInfo>(); List <Model.CategoryInfo> lastChildList = new List <Model.CategoryInfo>(); List <Model.CategoryInfo> childList = new List <Model.CategoryInfo>(); GetParent(list, currentItem, ref parentList); GetLastChildAll(list, currentItem, ref lastChildList); GetChild(list, currentItem, ref childList); int parentCount = 0; if (parentList != null && parentList.Count > 0) { parentCount = parentList.Count; int n = 0; foreach (Model.CategoryInfo model in parentList) { if (model != null) { n++; navMap = string.Format("<a href='/Shares/SearchProduct.aspx?c={1}'>{0}</a>", model.CategoryName, model.NumberID) + " > " + navMap; if (parentCount == 2) { if (n == 2) { categoryAppend = string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ab\"><i class=\"aba\"></i><span class=\"abb\">{0}</span></a>", model.CategoryName, model.NumberID) + categoryAppend; } else { categoryAppend = string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ad ad-1\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></a>", model.CategoryName, model.NumberID); } } else { categoryAppend = string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ab\"><i class=\"aba\"></i><span class=\"abb\">{0}</span></a>", model.CategoryName, model.NumberID); } } } } if (parentCount == 0) { categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ab\"><i class=\"aba\"></i><span class=\"abb\">{0}</span></a>", currentItem.CategoryName, currentItem.NumberID); } else if (parentCount == 1) { categoryAppend += string.Format("<div class=\"ad ad-current ad-1\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></div>", currentItem.CategoryName); } else { categoryAppend += string.Format("<div class=\"ad ad-current ad-2\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></div>", currentItem.CategoryName); } cad.InnerHtml = navMap; if (childList != null && childList.Count > 0) { foreach (Model.CategoryInfo model in childList) { if (parentCount == 0) { categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ad ad-1\"><i class=\"ada\"></i><span class=\"adb\">{0}<span class=\"adc\"></span></span></a>", model.CategoryName, model.NumberID); } else if (parentCount == 1) { categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ad ad-2\"><i class=\"ada\"></i><span class=\"adb\">{0}<span class=\"adc\">(19.5万)</span></span></a>", model.CategoryName, model.NumberID); } } } if (lastChildList != null && lastChildList.Count() > 0) { foreach (Model.CategoryInfo model in lastChildList) { if (model != null) { cIdAppend += string.Format("'{0}',", model.NumberID); } } cIdAppend = cIdAppend.Trim(','); } } else { Model.CategoryInfo rootItem = list.Find(delegate(Model.CategoryInfo model) { return(model.CategoryName == "所有分类"); }); if (rootItem != null) { cad.InnerHtml = string.Format("<a href='/Shares/SearchProduct.aspx?c={1}'>{0}</a>", rootItem.CategoryName, rootItem.NumberID); categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={0}\" class=\"ab\"><i class=\"aba\"></i><span class=\"abb\">所有分类</span></a>", rootItem.NumberID); List <Model.CategoryInfo> list1 = list.FindAll(delegate(Model.CategoryInfo model) { return(model.ParentID == rootItem.NumberID); }); if (list1 != null && list1.Count > 0) { foreach (Model.CategoryInfo model1 in list1) { categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ad ad-1\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></a>", model1.CategoryName, model1.NumberID); List <Model.CategoryInfo> list2 = list.FindAll(delegate(Model.CategoryInfo model2) { return(model2.ParentID == model1.NumberID); }); if (list2 != null && list2.Count > 0) { foreach (Model.CategoryInfo model2 in list2) { categoryAppend += string.Format("<a href=\"/Shares/SearchProduct.aspx?c={1}\" class=\"ad ad-2\"><i class=\"ada\"></i><span class=\"adb\">{0}</span></a>", model2.CategoryName, model2.NumberID); } } } } } } } ltrCategory.Text = categoryAppend; }