/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebApi_Model.T_Forum_Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_Forum_Category set "); strSql.Append("Level=@Level,"); strSql.Append("CategoryName=@CategoryName,"); strSql.Append("CategoryICO=@CategoryICO,"); strSql.Append("ParentID=@ParentID"); strSql.Append(" where ForumCategoryID=@ForumCategoryID"); SqlParameter[] parameters = { new SqlParameter("@Level", SqlDbType.Int, 4), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryICO", SqlDbType.NVarChar, 50), new SqlParameter("@ParentID", SqlDbType.Int, 4), new SqlParameter("@ForumCategoryID", SqlDbType.Int, 4) }; parameters[0].Value = model.Level; parameters[1].Value = model.CategoryName; parameters[2].Value = model.CategoryICO; parameters[3].Value = model.ParentID; parameters[4].Value = model.ForumCategoryID; int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forum_Category DataRowToModel(DataRow row) { WebApi_Model.T_Forum_Category model = new WebApi_Model.T_Forum_Category(); if (row != null) { if (row["ForumCategoryID"] != null && row["ForumCategoryID"].ToString() != "") { model.ForumCategoryID = int.Parse(row["ForumCategoryID"].ToString()); } if (row["Level"] != null && row["Level"].ToString() != "") { model.Level = int.Parse(row["Level"].ToString()); } if (row["CategoryName"] != null) { model.CategoryName = row["CategoryName"].ToString(); } if (row["CategoryICO"] != null) { model.CategoryICO = row["CategoryICO"].ToString(); } if (row["ParentID"] != null && row["ParentID"].ToString() != "") { model.ParentID = int.Parse(row["ParentID"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(WebApi_Model.T_Forum_Category model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_Forum_Category("); strSql.Append("Level,CategoryName,CategoryICO,ParentID)"); strSql.Append(" values ("); strSql.Append("@Level,@CategoryName,@CategoryICO,@ParentID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Level", SqlDbType.Int, 4), new SqlParameter("@CategoryName", SqlDbType.NVarChar, 50), new SqlParameter("@CategoryICO", SqlDbType.NVarChar, 50), new SqlParameter("@ParentID", SqlDbType.Int, 4) }; parameters[0].Value = model.Level; parameters[1].Value = model.CategoryName; parameters[2].Value = model.CategoryICO; parameters[3].Value = model.ParentID; object obj = DBHelper.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebApi_Model.T_Forum_Category GetModel(int ForumCategoryID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ForumCategoryID,Level,CategoryName,CategoryICO,ParentID from T_Forum_Category "); strSql.Append(" where ForumCategoryID=@ForumCategoryID"); SqlParameter[] parameters = { new SqlParameter("@ForumCategoryID", SqlDbType.Int, 4) }; parameters[0].Value = ForumCategoryID; WebApi_Model.T_Forum_Category model = new WebApi_Model.T_Forum_Category(); DataSet ds = DBHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }