예제 #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Shop.Model.Comment DataRowToModel(DataRow row)
 {
     Shop.Model.Comment model = new Shop.Model.Comment();
     if (row != null)
     {
         if (row["comid"] != null && row["comid"].ToString() != "")
         {
             model.comid = int.Parse(row["comid"].ToString());
         }
         if (row["uname"] != null)
         {
             model.uname = row["uname"].ToString();
         }
         if (row["comcontent"] != null)
         {
             model.comcontent = row["comcontent"].ToString();
         }
         if (row["comtime"] != null && row["comtime"].ToString() != "")
         {
             model.comtime = DateTime.Parse(row["comtime"].ToString());
         }
         if (row["replycontent"] != null)
         {
             model.replycontent = row["replycontent"].ToString();
         }
         if (row["comreplytime"] != null && row["comreplytime"].ToString() != "")
         {
             model.comreplytime = DateTime.Parse(row["comreplytime"].ToString());
         }
     }
     return(model);
 }
예제 #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Shop.Model.Comment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_comment(");
            strSql.Append("uname,comcontent,comtime,replycontent,comreplytime)");
            strSql.Append(" values (");
            strSql.Append("@uname,@comcontent,@comtime,@replycontent,@comreplytime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@uname",        SqlDbType.VarChar,    30),
                new SqlParameter("@comcontent",   SqlDbType.VarChar,   500),
                new SqlParameter("@comtime",      SqlDbType.DateTime),
                new SqlParameter("@replycontent", SqlDbType.VarChar,   500),
                new SqlParameter("@comreplytime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.uname;
            parameters[1].Value = model.comcontent;
            parameters[2].Value = model.comtime;
            parameters[3].Value = model.replycontent;
            parameters[4].Value = model.comreplytime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Shop.Model.Comment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_comment set ");
            strSql.Append("uname=@uname,");
            strSql.Append("comcontent=@comcontent,");
            strSql.Append("comtime=@comtime,");
            strSql.Append("replycontent=@replycontent,");
            strSql.Append("comreplytime=@comreplytime");
            strSql.Append(" where comid=@comid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@uname",        SqlDbType.VarChar,    30),
                new SqlParameter("@comcontent",   SqlDbType.VarChar,   500),
                new SqlParameter("@comtime",      SqlDbType.DateTime),
                new SqlParameter("@replycontent", SqlDbType.VarChar,   500),
                new SqlParameter("@comreplytime", SqlDbType.DateTime),
                new SqlParameter("@comid",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.uname;
            parameters[1].Value = model.comcontent;
            parameters[2].Value = model.comtime;
            parameters[3].Value = model.replycontent;
            parameters[4].Value = model.comreplytime;
            parameters[5].Value = model.comid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Shop.Model.Comment GetModel(int comid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 comid,uname,comcontent,comtime,replycontent,comreplytime from t_comment ");
            strSql.Append(" where comid=@comid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@comid", SqlDbType.Int, 4)
            };
            parameters[0].Value = comid;

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

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