Ejemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(bbs.Model.Topic model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_topic set ");
            strSql.Append("content=@content,");
            strSql.Append("modifytime=@modifytime,");
            strSql.Append("publishtime=@publishtime,");
            strSql.Append("title=@title,");
            strSql.Append("good=@good,");
            strSql.Append("[top]=@top");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@content",     SqlDbType.VarChar,   1000),
                new SqlParameter("@modifytime",  SqlDbType.DateTime),
                new SqlParameter("@publishtime", SqlDbType.DateTime),
                new SqlParameter("@title",       SqlDbType.VarChar,    200),
                new SqlParameter("@good",        SqlDbType.VarChar,     10),
                new SqlParameter("@top",         SqlDbType.VarChar,     10),
                new SqlParameter("@id",          SqlDbType.Int,          4),
                new SqlParameter("@t_u_id",      SqlDbType.Int,          4),
                new SqlParameter("@t_s_id",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.content;
            parameters[1].Value = model.modifytime;
            parameters[2].Value = model.publishtime;
            parameters[3].Value = model.title;
            parameters[4].Value = model.good;
            parameters[5].Value = model.top;
            parameters[6].Value = model.id;
            parameters[7].Value = model.t_u_id;
            parameters[8].Value = model.t_s_id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public bbs.Model.Topic DataRowToModel(DataRow row)
 {
     bbs.Model.Topic model = new bbs.Model.Topic();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["t_u_id"] != null && row["t_u_id"].ToString() != "")
         {
             model.t_u_id = int.Parse(row["t_u_id"].ToString());
         }
         if (row["t_s_id"] != null && row["t_s_id"].ToString() != "")
         {
             model.t_s_id = int.Parse(row["t_s_id"].ToString());
         }
         if (row["content"] != null)
         {
             model.content = row["content"].ToString();
         }
         if (row["modifytime"] != null && row["modifytime"].ToString() != "")
         {
             model.modifytime = DateTime.Parse(row["modifytime"].ToString());
         }
         if (row["publishtime"] != null && row["publishtime"].ToString() != "")
         {
             model.publishtime = DateTime.Parse(row["publishtime"].ToString());
         }
         if (row["title"] != null)
         {
             model.title = row["title"].ToString();
         }
         if (row["good"] != null)
         {
             model.good = row["good"].ToString();
         }
         if (row["top"] != null)
         {
             model.top = row["top"].ToString();
         }
     }
     return(model);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(bbs.Model.Topic model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_topic(");
            strSql.Append("t_u_id,t_s_id,content,modifytime,publishtime,title,good,[top])");
            strSql.Append(" values (");
            strSql.Append("@t_u_id,@t_s_id,@content,@modifytime,@publishtime,@title,@good,@top)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@t_u_id",      SqlDbType.Int,          4),
                new SqlParameter("@t_s_id",      SqlDbType.Int,          4),
                new SqlParameter("@content",     SqlDbType.VarChar,   1000),
                new SqlParameter("@modifytime",  SqlDbType.DateTime),
                new SqlParameter("@publishtime", SqlDbType.DateTime),
                new SqlParameter("@title",       SqlDbType.VarChar,    200),
                new SqlParameter("@good",        SqlDbType.VarChar,     10),
                new SqlParameter("@top",         SqlDbType.VarChar, 10)
            };
            parameters[0].Value = model.t_u_id;
            parameters[1].Value = model.t_s_id;
            parameters[2].Value = model.content;
            parameters[3].Value = model.modifytime;
            parameters[4].Value = model.publishtime;
            parameters[5].Value = model.title;
            parameters[6].Value = model.good;
            parameters[7].Value = model.top;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public bbs.Model.Topic GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,t_u_id,t_s_id,content,modifytime,publishtime,title,good,[top] from t_topic ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            bbs.Model.Topic model = new bbs.Model.Topic();
            DataSet         ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }