/// <summary> /// 分类列表 /// </summary> /// <returns></returns> public List<Maticsoft.Model.Tao.Categories> GetCate(int parentCategoryId) { List<Maticsoft.Model.Tao.Categories> modelList = new List<Maticsoft.Model.Tao.Categories>(); DataRow[] rowArray = dal.GetCate().Tables[0].Select("ParentCategoryId=" + parentCategoryId); Maticsoft.Model.Tao.Categories model; for (int i = 0; i < rowArray.Length; i++) { model = new Maticsoft.Model.Tao.Categories(); if (rowArray[i]["CategoryId"] != null && rowArray[i]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(rowArray[i]["CategoryId"].ToString()); } if (rowArray[i]["Name"] != null && rowArray[i]["Name"].ToString() != "") { model.Name = rowArray[i]["Name"].ToString(); } if (rowArray[i]["Sequence"] != null && rowArray[i]["Sequence"].ToString() != "") { model.Sequence = int.Parse(rowArray[i]["Sequence"].ToString()); } if (rowArray[i]["ParentCategoryId"] != null && rowArray[i]["ParentCategoryId"].ToString() != "") { model.ParentCategoryId = int.Parse(rowArray[i]["ParentCategoryId"].ToString()); } if (rowArray[i]["Depth"] != null && rowArray[i]["Depth"].ToString() != "") { model.Depth = int.Parse(rowArray[i]["Depth"].ToString()); } if (rowArray[i]["Path"] != null && rowArray[i]["Path"].ToString() != "") { model.Path = rowArray[i]["Path"].ToString(); } if (rowArray[i]["Description"] != null && rowArray[i]["Description"].ToString() != "") { model.Description = rowArray[i]["Description"].ToString(); } if (rowArray[i]["IconUrl"] != null && rowArray[i]["IconUrl"].ToString() != "") { model.IconUrl = rowArray[i]["IconUrl"].ToString(); } if (rowArray[i]["Status"] != null && rowArray[i]["Status"].ToString() != "") { model.Status = int.Parse(rowArray[i]["Status"].ToString()); } if (rowArray[i]["CreatedDate"] != null && rowArray[i]["CreatedDate"].ToString() != "") { model.CreatedDate = DateTime.Parse(rowArray[i]["CreatedDate"].ToString()); } if (rowArray[i]["CreatedUserID"] != null && rowArray[i]["CreatedUserID"].ToString() != "") { model.CreatedUserID = int.Parse(rowArray[i]["CreatedUserID"].ToString()); } if (rowArray[i]["RewriteName"] != null && rowArray[i]["RewriteName"].ToString() != "") { model.RewriteName = rowArray[i]["RewriteName"].ToString(); } modelList.Add(model); } return modelList; }
/// <summary> /// 根据参数数组 执行 查询任务,并返回查询到的泛型集合 /// </summary> /// <param name="paras">参数</param> /// <returns></returns> private List<Maticsoft.Model.Tao.Categories> GetListByCondition(int? parentId) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT * FROM Tao_Categories "); if (parentId.HasValue) { strSql.Append(" Where ParentCategoryId=" + parentId.Value); } else { strSql.Append(" Where ParentCategoryId =0 "); } strSql.Append(" ORDER BY Sequence "); DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0]; List<Maticsoft.Model.Tao.Categories> list = null; if (dt.Rows.Count > 0) { list = new List<Maticsoft.Model.Tao.Categories>(); //循环将 数据表 中的 所有行 转成 实体对象 并 添加到泛型集合中 foreach (DataRow dr in dt.Rows) { Maticsoft.Model.Tao.Categories model = new Maticsoft.Model.Tao.Categories(); LoadEntityData(ref model, dr); list.Add(model); } } return list; }
/// <summary> /// 获得数据列表 /// </summary> public List<Maticsoft.Model.Tao.Categories> DataTableToList(DataTable dt) { List<Maticsoft.Model.Tao.Categories> modelList = new List<Maticsoft.Model.Tao.Categories>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Maticsoft.Model.Tao.Categories model; for (int n = 0; n < rowsCount; n++) { model = new Maticsoft.Model.Tao.Categories(); if (dt.Rows[n]["CategoryId"] != null && dt.Rows[n]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString()); } if (dt.Rows[n]["Name"] != null && dt.Rows[n]["Name"].ToString() != "") { model.Name = dt.Rows[n]["Name"].ToString(); } if (dt.Rows[n]["Sequence"] != null && dt.Rows[n]["Sequence"].ToString() != "") { model.Sequence = int.Parse(dt.Rows[n]["Sequence"].ToString()); } if (dt.Rows[n]["ParentCategoryId"] != null && dt.Rows[n]["ParentCategoryId"].ToString() != "") { model.ParentCategoryId = int.Parse(dt.Rows[n]["ParentCategoryId"].ToString()); } if (dt.Rows[n]["Depth"] != null && dt.Rows[n]["Depth"].ToString() != "") { model.Depth = int.Parse(dt.Rows[n]["Depth"].ToString()); } if (dt.Rows[n]["Path"] != null && dt.Rows[n]["Path"].ToString() != "") { model.Path = dt.Rows[n]["Path"].ToString(); } if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "") { model.Description = dt.Rows[n]["Description"].ToString(); } if (dt.Rows[n]["IconUrl"] != null && dt.Rows[n]["IconUrl"].ToString() != "") { model.IconUrl = dt.Rows[n]["IconUrl"].ToString(); } if (dt.Rows[n]["Status"] != null && dt.Rows[n]["Status"].ToString() != "") { model.Status = int.Parse(dt.Rows[n]["Status"].ToString()); } if (dt.Rows[n]["CreatedDate"] != null && dt.Rows[n]["CreatedDate"].ToString() != "") { model.CreatedDate = DateTime.Parse(dt.Rows[n]["CreatedDate"].ToString()); } if (dt.Rows[n]["CreatedUserID"] != null && dt.Rows[n]["CreatedUserID"].ToString() != "") { model.CreatedUserID = int.Parse(dt.Rows[n]["CreatedUserID"].ToString()); } if (dt.Rows[n]["RewriteName"] != null && dt.Rows[n]["RewriteName"].ToString() != "") { model.RewriteName = dt.Rows[n]["RewriteName"].ToString(); } modelList.Add(model); } } return modelList; }
/// <summary> /// 根据父级类别得到一个对象实体 /// </summary> public Maticsoft.Model.Tao.Categories GetModelByParentCategoryId(int ParentCategoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CategoryId,Name,Sequence,ParentCategoryId,Depth,Path,Description,IconUrl,Status,CreatedDate,CreatedUserID,RewriteName from Tao_Categories "); strSql.Append(" where CategoryId=@ParentCategoryId"); SqlParameter[] parameters = { new SqlParameter("@ParentCategoryId", SqlDbType.Int,4) }; parameters[0].Value = ParentCategoryId; Maticsoft.Model.Tao.Categories model = new Maticsoft.Model.Tao.Categories(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CategoryId"] != null && ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString()); } if (ds.Tables[0].Rows[0]["Name"] != null && ds.Tables[0].Rows[0]["Name"].ToString() != "") { model.Name = ds.Tables[0].Rows[0]["Name"].ToString(); } if (ds.Tables[0].Rows[0]["Sequence"] != null && ds.Tables[0].Rows[0]["Sequence"].ToString() != "") { model.Sequence = int.Parse(ds.Tables[0].Rows[0]["Sequence"].ToString()); } if (ds.Tables[0].Rows[0]["ParentCategoryId"] != null && ds.Tables[0].Rows[0]["ParentCategoryId"].ToString() != "") { model.ParentCategoryId = int.Parse(ds.Tables[0].Rows[0]["ParentCategoryId"].ToString()); } if (ds.Tables[0].Rows[0]["Depth"] != null && ds.Tables[0].Rows[0]["Depth"].ToString() != "") { model.Depth = int.Parse(ds.Tables[0].Rows[0]["Depth"].ToString()); } if (ds.Tables[0].Rows[0]["Path"] != null && ds.Tables[0].Rows[0]["Path"].ToString() != "") { model.Path = ds.Tables[0].Rows[0]["Path"].ToString(); } if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "") { model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); } if (ds.Tables[0].Rows[0]["IconUrl"] != null && ds.Tables[0].Rows[0]["IconUrl"].ToString() != "") { model.IconUrl = ds.Tables[0].Rows[0]["IconUrl"].ToString(); } if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "") { model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString()); } if (ds.Tables[0].Rows[0]["CreatedDate"] != null && ds.Tables[0].Rows[0]["CreatedDate"].ToString() != "") { model.CreatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString()); } if (ds.Tables[0].Rows[0]["CreatedUserID"] != null && ds.Tables[0].Rows[0]["CreatedUserID"].ToString() != "") { model.CreatedUserID = int.Parse(ds.Tables[0].Rows[0]["CreatedUserID"].ToString()); } if (ds.Tables[0].Rows[0]["RewriteName"] != null && ds.Tables[0].Rows[0]["RewriteName"].ToString() != "") { model.RewriteName = ds.Tables[0].Rows[0]["RewriteName"].ToString(); } return model; } else { return null; } }