using System; using System.Data; using System.Text; using System.Data.SqlClient; namespace Mtxfw.DAL { /// /// 数据访问类:forum /// public partial class forum : Mtxfw.Utility.Myabstract { public forum() : base("forum") { } /// /// 增加一条数据 /// public int Add(Mtxfw.Model.forum model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into forum("); strSql.Append("B_ForumName,B_ForumManager,B_ForumPicture,B_linkid,B_pid,B_pids,B_Layer,B_seef,B_FUrl,B_Intro)"); strSql.Append(" values ("); strSql.Append("@B_ForumName,@B_ForumManager,@B_ForumPicture,@B_linkid,@B_pid,@B_pids,@B_Layer,@B_seef,@B_FUrl,@B_Intro)"); SqlParameter[] parameters = { new SqlParameter("@B_ForumName", SqlDbType.VarChar,250), new SqlParameter("@B_ForumManager", SqlDbType.VarChar,255), new SqlParameter("@B_ForumPicture", SqlDbType.VarChar,250), new SqlParameter("@B_linkid", SqlDbType.Int), new SqlParameter("@B_pid", SqlDbType.Int), new SqlParameter("@B_pids", SqlDbType.VarChar,250), new SqlParameter("@B_Layer", SqlDbType.Int), new SqlParameter("@B_seef", SqlDbType.Int), new SqlParameter("@B_FUrl", SqlDbType.VarChar,250), new SqlParameter("@B_Intro", SqlDbType.Text)}; parameters[0].Value = model.B_ForumName; parameters[1].Value = model.B_ForumManager; parameters[2].Value = model.B_ForumPicture; parameters[3].Value = model.B_linkid; parameters[4].Value = model.B_pid; parameters[5].Value = model.B_pids; parameters[6].Value = model.B_Layer; parameters[7].Value = model.B_seef; parameters[8].Value = model.B_FUrl; parameters[9].Value = model.B_Intro; object obj = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 增加一条数据 /// public int Update(Mtxfw.Model.forum model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update forum set B_ForumName=@B_ForumName,B_ForumManager=@B_ForumManager,B_ForumPicture=@B_ForumPicture,B_linkid=@B_linkid,B_pid=@B_pid,B_pids=@B_pids,B_Layer=@B_Layer,B_FUrl=@B_FUrl,B_Intro=@B_Intro where B_Id=@B_Id"); SqlParameter[] parameters = { new SqlParameter("@B_ForumName", SqlDbType.VarChar,250), new SqlParameter("@B_ForumManager", SqlDbType.VarChar,255), new SqlParameter("@B_ForumPicture", SqlDbType.VarChar,250), new SqlParameter("@B_linkid", SqlDbType.Int), new SqlParameter("@B_pid", SqlDbType.Int), new SqlParameter("@B_pids", SqlDbType.VarChar,250), new SqlParameter("@B_Layer", SqlDbType.Int), new SqlParameter("@B_FUrl", SqlDbType.VarChar,250), new SqlParameter("@B_Intro", SqlDbType.Text), new SqlParameter("@B_Id", SqlDbType.Int)}; parameters[0].Value = model.B_ForumName; parameters[1].Value = model.B_ForumManager; parameters[2].Value = model.B_ForumPicture; parameters[3].Value = model.B_linkid; parameters[4].Value = model.B_pid; parameters[5].Value = model.B_pids; parameters[6].Value = model.B_Layer; parameters[7].Value = model.B_FUrl; parameters[8].Value = model.B_Intro; parameters[9].Value = model.B_Id; object obj = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); if (obj == null) { return 0; } else { return Convert.ToInt32(obj); } } /// /// 更新一条数据 /// public int Update(int strID, string Sel, int SelValue) { StringBuilder strSql = new StringBuilder(); strSql.Append("update forum set " + Sel + "=@SelValue where B_Id=@B_Id"); SqlParameter[] parameters = { new SqlParameter("@SelValue", SqlDbType.Int,4), new SqlParameter("@B_Id", SqlDbType.Int,4) }; parameters[0].Value = SelValue; parameters[1].Value = strID; return Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); } /// /// 删除一条数据 /// public bool Delete(Int64 Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from forum "); int rows = 0; if (Id > 0) { strSql.Append(" where B_Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int)}; parameters[0].Value = Id; rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); } else { rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString()); } if (rows > 0) { return true; } else { return false; } } /// /// 删除一条数据 /// public bool Delete2(Int64 Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("delete from forum "); int rows = 0; if (Id > 0) { strSql.Append(" where B_Id=@Id Or B_pids like '%," + Id + ",%'"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int)}; parameters[0].Value = Id; rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString(), parameters); } else { rows = Mtxfw.Utility.SqlDbHelper_U.ExecuteCmd(strSql.ToString()); } if (rows > 0) { return true; } else { return false; } } /// /// 得到一个对象实体 /// public Mtxfw.Model.forum GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from forum "); strSql.Append(" where B_Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; Mtxfw.Model.forum model = new Mtxfw.Model.forum(); DataSet ds = Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["B_Id"].ToString() != "") { model.B_Id = int.Parse(ds.Tables[0].Rows[0]["B_Id"].ToString()); } model.B_ForumName = ds.Tables[0].Rows[0]["B_ForumName"].ToString(); if (ds.Tables[0].Rows[0]["B_ForumCount"].ToString() != "") { model.B_ForumCount = Convert.ToInt32(ds.Tables[0].Rows[0]["B_ForumCount"].ToString()); } model.B_ForumManager = ds.Tables[0].Rows[0]["B_ForumManager"].ToString(); model.B_ForumPicture = ds.Tables[0].Rows[0]["B_ForumPicture"].ToString(); if (ds.Tables[0].Rows[0]["B_linkid"].ToString() != "") { model.B_linkid = Convert.ToInt32(ds.Tables[0].Rows[0]["B_linkid"].ToString()); } if (ds.Tables[0].Rows[0]["B_pid"].ToString() != "") { model.B_pid = Convert.ToInt32(ds.Tables[0].Rows[0]["B_pid"].ToString()); } model.B_pids = ds.Tables[0].Rows[0]["B_pids"].ToString(); if (ds.Tables[0].Rows[0]["B_Layer"].ToString() != "") { model.B_Layer = Convert.ToInt32(ds.Tables[0].Rows[0]["B_Layer"].ToString()); } if (ds.Tables[0].Rows[0]["B_seef"].ToString() != "") { model.B_seef = Convert.ToInt32(ds.Tables[0].Rows[0]["B_seef"].ToString()); } if (ds.Tables[0].Rows[0]["B_SJ"].ToString() != "") { model.B_SJ = Convert.ToDateTime(ds.Tables[0].Rows[0]["B_SJ"].ToString()); } model.B_FUrl = ds.Tables[0].Rows[0]["B_FUrl"].ToString(); model.B_Intro = ds.Tables[0].Rows[0]["B_Intro"].ToString(); return model; } else { return null; } } /// /// 获得数据列表 /// public DataSet GetList(string strWhere) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * "); strSql.Append(" FROM forum "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public DataSet GetList(int Top, string strWhere, string filedOrder) { StringBuilder strSql = new StringBuilder(); strSql.Append("select "); if (Top > 0) { strSql.Append(" top " + Top.ToString()); } strSql.Append(" * "); strSql.Append(" FROM forum "); if (strWhere.Trim() != "") { strSql.Append(" where " + strWhere); } strSql.Append(" order by " + filedOrder); return Mtxfw.Utility.SqlDbHelper_U.GetDataSet(strSql.ToString()); } /// /// 获得前几行数据 /// public bool IFForumManager(int ForumId, string UserID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Count(B_ID) FROM forum where B_Id=" + ForumId + " And ',' + B_ForumManager + ',' Like '%," + UserID + ",%'"); if (Mtxfw.Utility.SqlDbHelper_U.ExecuteScalar(strSql.ToString()) > 0) { return true; } else { return false; } } public bool IsForumManager(int ForumId, string UserID) { bool b = false; int B_Layer = 0, B_pid = 0; DataSet ds = GetList1("B_Layer,B_pid", "B_ID=" + ForumId); if (ds.Tables[0].Rows.Count > 0) { B_Layer = Convert.ToInt32(ds.Tables[0].Rows[0]["B_Layer"].ToString()); B_pid = Convert.ToInt32(ds.Tables[0].Rows[0]["B_pid"].ToString()); } ds.Clear(); if (B_Layer == 2) { if (IFForumManager(ForumId, UserID)) { b = true; } else { if (IFForumManager(B_pid, UserID)) { b = true; } else { b = false; } } } else { if (IFForumManager(ForumId, UserID)) { b = true; } else { b = false; } } return b; } } }