public List <BookCate> getBookCateList(String name) { List <BookCate> list = new List <BookCate>(); String sql = String.Format("select Id, ParentId, Name from BookCate where Name like '%{0}%';", name); try { using (DbDataReader reader = conn.execReader(sql)) { while (reader.Read()) { BookCate bc = new BookCate(); bc.Id = Convert.ToInt32(reader[0]); bc.ParentId = Convert.ToInt32(reader[1]); bc.Name = reader[2].ToString(); list.Add(bc); } } } catch (DbException) { //输出日志 } return(list); }
public String getFullPahtForName() { String path = Name; BookCate temp = this.next; while (null != temp) { path += "\\" + temp.Name; temp = temp.next; } return(path); }
//暂时没有用到 public String getFullPahtForId() { String path = Id.ToString(); BookCate temp = this.next; while (null != temp) { path += temp.Id.ToString(); temp = temp.next; } return(path); }
public String getFullPath(BookCate b) { String fullPath = ""; //0是最上级 //fullPath = b.Name; BookCate tmp = b; while (0 != tmp.Id) { fullPath = fullPath.Insert(0, "\\" + tmp.Name); tmp = getBookCate(tmp.ParentId); } //fullPath.Insert(0, tmp.Name); return(fullPath); }
public BookCate makeBookCateTree(String cateIds) { //双向链表 BookCate Cate = getBookCate(Convert.ToInt32(cateIds[0])); BookCate temp = null; BookCate prev = null; temp = Cate; for (int i = 1; i < cateIds.Length; i++) { temp.next = getBookCate(Convert.ToInt32(cateIds[i])); temp.next.prev = temp; prev = temp; temp = temp.next; } return(Cate); }
public bool delBookCate(BookCate b) { String sql = String.Format("delete from BookCate where Id={0}", b.Id); int ret = 0; try { ret = conn.execNonSQL(sql); if (ret == 1) { return(true); } } catch (DbException) { return(false); } return(false); }
public bool upBookCate(BookCate b) { String sql = String.Format("Update BookCate set Name='{0}', ParentId={1} where Id={2}", b.Name, b.ParentId, b.Id); int ret = 0; try { ret = conn.execNonSQL(sql); if (ret == 1) { return(true); } } catch (DbException) { return(false); } return(false); }
public bool addBookCate(BookCate b) { String sql = String.Format("insert into BookCate values(null,{0},'{1}')", b.ParentId, b.Name); int ret = 0; try { ret = conn.execNonSQL(sql); if (ret == 1) { return(true); } } catch (DbException) { return(false); } return(false); }
public BookCate getBookCate(int cateId) { BookCate cate = new BookCate(); String sql = String.Format("SELECT * FROM BookCate " + "where Id = {0}", cateId); try { using (DbDataReader reader = conn.execReader(sql)) { if (reader.Read()) { cate.Id = Convert.ToInt32(reader[0]); cate.ParentId = Convert.ToInt32(reader[1]); cate.Name = reader[2].ToString(); } } } catch (DbException) { //输出日志 } return(cate); }