Ejemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BookShop.Model.BookComment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BookComment(");
            strSql.Append("Msg,CreateDateTime,BookId)");
            strSql.Append(" values (");
            strSql.Append("@Msg,@CreateDateTime,@BookId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Msg",            SqlDbType.NVarChar,  -1),
                new SqlParameter("@CreateDateTime", SqlDbType.DateTime),
                new SqlParameter("@BookId",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Msg;
            parameters[1].Value = model.CreateDateTime;
            parameters[2].Value = model.BookId;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BookShop.Model.BookComment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BookComment set ");
            strSql.Append("Msg=@Msg,");
            strSql.Append("CreateDateTime=@CreateDateTime,");
            strSql.Append("BookId=@BookId");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Msg",            SqlDbType.NVarChar,  -1),
                new SqlParameter("@CreateDateTime", SqlDbType.DateTime),
                new SqlParameter("@BookId",         SqlDbType.Int,        4),
                new SqlParameter("@Id",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Msg;
            parameters[1].Value = model.CreateDateTime;
            parameters[2].Value = model.BookId;
            parameters[3].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <BookShop.Model.BookComment> DataTableToList(DataTable dt)
        {
            List <BookShop.Model.BookComment> modelList = new List <BookShop.Model.BookComment>();
            int rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                BookShop.Model.BookComment model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new BookShop.Model.BookComment();
                    if (dt.Rows[n]["Id"].ToString() != "")
                    {
                        model.Id = int.Parse(dt.Rows[n]["Id"].ToString());
                    }
                    model.Msg = dt.Rows[n]["Msg"].ToString();
                    if (dt.Rows[n]["CreateDateTime"].ToString() != "")
                    {
                        model.CreateDateTime = DateTime.Parse(dt.Rows[n]["CreateDateTime"].ToString());
                    }
                    if (dt.Rows[n]["BookId"].ToString() != "")
                    {
                        model.BookId = int.Parse(dt.Rows[n]["BookId"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.BookComment GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Msg,CreateDateTime,BookId from BookComment ");
            strSql.Append(" where Id=@Id ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Msg = ds.Tables[0].Rows[0]["Msg"].ToString();
                if (ds.Tables[0].Rows[0]["CreateDateTime"].ToString() != "")
                {
                    model.CreateDateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["BookId"].ToString() != "")
                {
                    model.BookId = int.Parse(ds.Tables[0].Rows[0]["BookId"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.BookComment DataRowToModel(DataRow row)
 {
     BookShop.Model.BookComment model = new BookShop.Model.BookComment();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Msg"] != null)
         {
             model.Msg = row["Msg"].ToString();
         }
         if (row["CreateDateTime"] != null && row["CreateDateTime"].ToString() != "")
         {
             model.CreateDateTime = DateTime.Parse(row["CreateDateTime"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
     }
     return(model);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BookShop.Model.BookComment DataRowToModel(DataRow row)
 {
     BookShop.Model.BookComment model=new BookShop.Model.BookComment();
     if (row != null)
     {
         if(row["Id"]!=null && row["Id"].ToString()!="")
         {
             model.Id=int.Parse(row["Id"].ToString());
         }
         if(row["Msg"]!=null)
         {
             model.Msg=row["Msg"].ToString();
         }
         if(row["CreateDateTime"]!=null && row["CreateDateTime"].ToString()!="")
         {
             model.CreateDateTime=DateTime.Parse(row["CreateDateTime"].ToString());
         }
         if(row["BookId"]!=null && row["BookId"].ToString()!="")
         {
             model.BookId=int.Parse(row["BookId"].ToString());
         }
     }
     return model;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BookShop.Model.BookComment GetModel(int Id)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 Id,Msg,CreateDateTime,BookId from BookComment ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@Id", SqlDbType.Int,4)
            };
            parameters[0].Value = Id;

            BookShop.Model.BookComment model=new BookShop.Model.BookComment();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public void Update(BookShop.Model.BookComment model)
 {
     dal.Update(model);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(BookShop.Model.BookComment model)
 {
     return(dal.Add(model));
 }