/// <summary> /// 获得数据列表 /// </summary> public List <DTcms.Model.Category> DataTableToList(DataTable dt) { List <DTcms.Model.Category> modelList = new List <DTcms.Model.Category>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DTcms.Model.Category model; for (int n = 0; n < rowsCount; n++) { model = new DTcms.Model.Category(); if (dt.Rows[n]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString()); } model.FullName = dt.Rows[n]["FullName"].ToString(); if (dt.Rows[n]["ParentId"].ToString() != "") { model.ParentId = int.Parse(dt.Rows[n]["ParentId"].ToString()); } if (dt.Rows[n]["Layer"].ToString() != "") { model.Layer = int.Parse(dt.Rows[n]["Layer"].ToString()); } if (dt.Rows[n]["DeleteMark"].ToString() != "") { model.DeleteMark = int.Parse(dt.Rows[n]["DeleteMark"].ToString()); } if (dt.Rows[n]["Enable"].ToString() != "") { model.Enable = int.Parse(dt.Rows[n]["Enable"].ToString()); } if (dt.Rows[n]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(dt.Rows[n]["CreateDate"].ToString()); } model.CreateUserName = dt.Rows[n]["CreateUserName"].ToString(); if (dt.Rows[n]["ModifyDate"].ToString() != "") { model.ModifyDate = DateTime.Parse(dt.Rows[n]["ModifyDate"].ToString()); } model.ModifyUserName = dt.Rows[n]["ModifyUserName"].ToString(); modelList.Add(model); } } return(modelList); }
/// <summary> /// 得到一个对象实体 /// </summary> public DTcms.Model.Category GetModel(int CategoryId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select CategoryId, FullName, ParentId, Layer, DeleteMark, Enable, CreateDate, CreateUserName, ModifyDate, ModifyUserName "); strSql.Append(" from " + databaseprefix + "Category "); strSql.Append(" where CategoryId=@CategoryId"); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.Int, 4) }; parameters[0].Value = CategoryId; DTcms.Model.Category model = new DTcms.Model.Category(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString()); } model.FullName = ds.Tables[0].Rows[0]["FullName"].ToString(); if (ds.Tables[0].Rows[0]["ParentId"].ToString() != "") { model.ParentId = int.Parse(ds.Tables[0].Rows[0]["ParentId"].ToString()); } if (ds.Tables[0].Rows[0]["Layer"].ToString() != "") { model.Layer = int.Parse(ds.Tables[0].Rows[0]["Layer"].ToString()); } if (ds.Tables[0].Rows[0]["DeleteMark"].ToString() != "") { model.DeleteMark = int.Parse(ds.Tables[0].Rows[0]["DeleteMark"].ToString()); } if (ds.Tables[0].Rows[0]["Enable"].ToString() != "") { model.Enable = int.Parse(ds.Tables[0].Rows[0]["Enable"].ToString()); } if (ds.Tables[0].Rows[0]["CreateDate"].ToString() != "") { model.CreateDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString()); } model.CreateUserName = ds.Tables[0].Rows[0]["CreateUserName"].ToString(); if (ds.Tables[0].Rows[0]["ModifyDate"].ToString() != "") { model.ModifyDate = DateTime.Parse(ds.Tables[0].Rows[0]["ModifyDate"].ToString()); } model.ModifyUserName = ds.Tables[0].Rows[0]["ModifyUserName"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update " + databaseprefix + "Category set "); strSql.Append(" FullName = @FullName , "); strSql.Append(" ParentId = @ParentId , "); strSql.Append(" Layer = @Layer , "); strSql.Append(" DeleteMark = @DeleteMark , "); strSql.Append(" Enable = @Enable , "); strSql.Append(" CreateDate = @CreateDate , "); strSql.Append(" CreateUserName = @CreateUserName , "); strSql.Append(" ModifyDate = @ModifyDate , "); strSql.Append(" ModifyUserName = @ModifyUserName "); strSql.Append(" where CategoryId=@CategoryId "); SqlParameter[] parameters = { new SqlParameter("@CategoryId", SqlDbType.Int, 4), new SqlParameter("@FullName", SqlDbType.VarChar, 50), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@Layer", SqlDbType.Int, 4), new SqlParameter("@DeleteMark", SqlDbType.Int, 4), new SqlParameter("@Enable", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@CreateUserName", SqlDbType.VarChar, 50), new SqlParameter("@ModifyDate", SqlDbType.DateTime), new SqlParameter("@ModifyUserName", SqlDbType.VarChar, 50) }; parameters[0].Value = model.CategoryId; parameters[1].Value = model.FullName; parameters[2].Value = model.ParentId; parameters[3].Value = model.Layer; parameters[4].Value = model.DeleteMark; parameters[5].Value = model.Enable; parameters[6].Value = model.CreateDate; parameters[7].Value = model.CreateUserName; parameters[8].Value = model.ModifyDate; parameters[9].Value = model.ModifyUserName; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into " + databaseprefix + "Category("); strSql.Append("FullName,ParentId,Layer,DeleteMark,Enable,CreateDate,CreateUserName,ModifyDate,ModifyUserName"); strSql.Append(") values ("); strSql.Append("@FullName,@ParentId,@Layer,@DeleteMark,@Enable,@CreateDate,@CreateUserName,@ModifyDate,@ModifyUserName"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@FullName", SqlDbType.VarChar, 50), new SqlParameter("@ParentId", SqlDbType.Int, 4), new SqlParameter("@Layer", SqlDbType.Int, 4), new SqlParameter("@DeleteMark", SqlDbType.Int, 4), new SqlParameter("@Enable", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime), new SqlParameter("@CreateUserName", SqlDbType.VarChar, 50), new SqlParameter("@ModifyDate", SqlDbType.DateTime), new SqlParameter("@ModifyUserName", SqlDbType.VarChar, 50) }; parameters[0].Value = model.FullName; parameters[1].Value = model.ParentId; parameters[2].Value = model.Layer; parameters[3].Value = model.DeleteMark; parameters[4].Value = model.Enable; parameters[5].Value = model.CreateDate; parameters[6].Value = model.CreateUserName; parameters[7].Value = model.ModifyDate; parameters[8].Value = model.ModifyUserName; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DTcms.Model.Category model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DTcms.Model.Category model) { return(dal.Add(model)); }