private void ShowInfo() { OLBookstore.BLL.RecomBooksManager bll = new OLBookstore.BLL.RecomBooksManager(); OLBookstore.Model.RecomBooks model = bll.GetModel(); this.lblBookId.Text = model.BookId.ToString(); this.lblUserId.Text = model.UserId.ToString(); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(OLBookstore.Model.RecomBooks model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update RecomBooks set "); strSql.Append("BookId=@BookId,"); strSql.Append("UserId=@UserId"); strSql.Append(" where "); SqlParameter[] parameters = { new SqlParameter("@BookId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4) }; parameters[0].Value = model.BookId; parameters[1].Value = model.UserId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(OLBookstore.Model.RecomBooks model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into RecomBooks("); strSql.Append("BookId,UserId)"); strSql.Append(" values ("); strSql.Append("@BookId,@UserId)"); SqlParameter[] parameters = { new SqlParameter("@BookId", SqlDbType.Int, 4), new SqlParameter("@UserId", SqlDbType.Int, 4) }; parameters[0].Value = model.BookId; parameters[1].Value = model.UserId; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
protected 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 (strErr != "") { MessageBox.Show(this, strErr); return; } int BookId = int.Parse(this.txtBookId.Text); int UserId = int.Parse(this.txtUserId.Text); OLBookstore.Model.RecomBooks model = new OLBookstore.Model.RecomBooks(); model.BookId = BookId; model.UserId = UserId; OLBookstore.BLL.RecomBooksManager bll = new OLBookstore.BLL.RecomBooksManager(); bll.Add(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "add.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public OLBookstore.Model.RecomBooks DataRowToModel(DataRow row) { OLBookstore.Model.RecomBooks model = new OLBookstore.Model.RecomBooks(); if (row != null) { 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()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public OLBookstore.Model.RecomBooks GetModel() { //该表无主键信息,请自定义主键/条件字段 StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 BookId,UserId from RecomBooks "); strSql.Append(" where "); SqlParameter[] parameters = { }; OLBookstore.Model.RecomBooks model = new OLBookstore.Model.RecomBooks(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }