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

            strSql.Append("insert into BookRatings(");
            strSql.Append("BookId,UserId,Rating,Comment,CreatedTime)");
            strSql.Append(" values (");
            strSql.Append("@BookId,@UserId,@Rating,@Comment,@CreatedTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@BookId",      SqlDbType.Int,       4),
                new SqlParameter("@UserId",      SqlDbType.Int,       4),
                new SqlParameter("@Rating",      SqlDbType.Int,       4),
                new SqlParameter("@Comment",     SqlDbType.NVarChar, -1),
                new SqlParameter("@CreatedTime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.BookId;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.Rating;
            parameters[3].Value = model.Comment;
            parameters[4].Value = model.CreatedTime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public OLBookstore.Model.BookRatings DataRowToModel(DataRow row)
 {
     OLBookstore.Model.BookRatings model = new OLBookstore.Model.BookRatings();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
         if (row["UserId"] != null && row["UserId"].ToString() != "")
         {
             model.UserId = int.Parse(row["UserId"].ToString());
         }
         if (row["Rating"] != null && row["Rating"].ToString() != "")
         {
             model.Rating = int.Parse(row["Rating"].ToString());
         }
         if (row["Comment"] != null)
         {
             model.Comment = row["Comment"].ToString();
         }
         if (row["CreatedTime"] != null && row["CreatedTime"].ToString() != "")
         {
             model.CreatedTime = DateTime.Parse(row["CreatedTime"].ToString());
         }
     }
     return(model);
 }
Ejemplo n.º 3
0
 private void ShowInfo(int Id)
 {
     OLBookstore.BLL.BookRatingsManager bll   = new OLBookstore.BLL.BookRatingsManager();
     OLBookstore.Model.BookRatings      model = bll.GetModel(Id);
     this.lblId.Text          = model.Id.ToString();
     this.lblBookId.Text      = model.BookId.ToString();
     this.lblUserId.Text      = model.UserId.ToString();
     this.lblRating.Text      = model.Rating.ToString();
     this.lblComment.Text     = model.Comment;
     this.lblCreatedTime.Text = model.CreatedTime.ToString();
 }
Ejemplo n.º 4
0
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (!PageValidate.IsNumber(txtBookId.Text))
            {
                strErr += "BookId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtUserId.Text))
            {
                strErr += "UserId格式错误!\\n";
            }
            if (!PageValidate.IsNumber(txtRating.Text))
            {
                strErr += "Rating格式错误!\\n";
            }
            if (this.txtComment.Text.Trim().Length == 0)
            {
                strErr += "Comment不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txtCreatedTime.Text))
            {
                strErr += "CreatedTime格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      Id          = int.Parse(this.lblId.Text);
            int      BookId      = int.Parse(this.txtBookId.Text);
            int      UserId      = int.Parse(this.txtUserId.Text);
            int      Rating      = int.Parse(this.txtRating.Text);
            string   Comment     = this.txtComment.Text;
            DateTime CreatedTime = DateTime.Parse(this.txtCreatedTime.Text);


            OLBookstore.Model.BookRatings model = new OLBookstore.Model.BookRatings();
            model.Id          = Id;
            model.BookId      = BookId;
            model.UserId      = UserId;
            model.Rating      = Rating;
            model.Comment     = Comment;
            model.CreatedTime = CreatedTime;

            OLBookstore.BLL.BookRatingsManager bll = new OLBookstore.BLL.BookRatingsManager();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(OLBookstore.Model.BookRatings model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BookRatings set ");
            strSql.Append("BookId=@BookId,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("Rating=@Rating,");
            strSql.Append("Comment=@Comment,");
            strSql.Append("CreatedTime=@CreatedTime");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@BookId",      SqlDbType.Int,        4),
                new SqlParameter("@UserId",      SqlDbType.Int,        4),
                new SqlParameter("@Rating",      SqlDbType.Int,        4),
                new SqlParameter("@Comment",     SqlDbType.NVarChar,  -1),
                new SqlParameter("@CreatedTime", SqlDbType.DateTime),
                new SqlParameter("@Id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.BookId;
            parameters[1].Value = model.UserId;
            parameters[2].Value = model.Rating;
            parameters[3].Value = model.Comment;
            parameters[4].Value = model.CreatedTime;
            parameters[5].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public OLBookstore.Model.BookRatings GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,BookId,UserId,Rating,Comment,CreatedTime from BookRatings ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

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

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