/// <summary> /// 更新一条数据 /// </summary> public bool Update(OLBookstore.Model.OrderBook model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update OrderBook set "); strSql.Append("OrderID=@OrderID,"); strSql.Append("BookID=@BookID,"); strSql.Append("Quantity=@Quantity,"); strSql.Append("UnitPrice=@UnitPrice"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@OrderID", SqlDbType.Int, 4), new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Quantity", SqlDbType.Int, 4), new SqlParameter("@UnitPrice", SqlDbType.Money, 8), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.OrderID; parameters[1].Value = model.BookID; parameters[2].Value = model.Quantity; parameters[3].Value = model.UnitPrice; parameters[4].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(OLBookstore.Model.OrderBook model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into OrderBook("); strSql.Append("OrderID,BookID,Quantity,UnitPrice)"); strSql.Append(" values ("); strSql.Append("@OrderID,@BookID,@Quantity,@UnitPrice)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@OrderID", SqlDbType.Int, 4), new SqlParameter("@BookID", SqlDbType.Int, 4), new SqlParameter("@Quantity", SqlDbType.Int, 4), new SqlParameter("@UnitPrice", SqlDbType.Money, 8) }; parameters[0].Value = model.OrderID; parameters[1].Value = model.BookID; parameters[2].Value = model.Quantity; parameters[3].Value = model.UnitPrice; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public OLBookstore.Model.OrderBook DataRowToModel(DataRow row) { OLBookstore.Model.OrderBook model = new OLBookstore.Model.OrderBook(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["OrderID"] != null && row["OrderID"].ToString() != "") { model.OrderID = int.Parse(row["OrderID"].ToString()); } if (row["BookID"] != null && row["BookID"].ToString() != "") { model.BookID = int.Parse(row["BookID"].ToString()); } if (row["Quantity"] != null && row["Quantity"].ToString() != "") { model.Quantity = int.Parse(row["Quantity"].ToString()); } if (row["UnitPrice"] != null && row["UnitPrice"].ToString() != "") { model.UnitPrice = decimal.Parse(row["UnitPrice"].ToString()); } } return(model); }
private void ShowInfo(int Id) { OLBookstore.BLL.OrderBookManager bll = new OLBookstore.BLL.OrderBookManager(); OLBookstore.Model.OrderBook model = bll.GetModel(Id); this.lblId.Text = model.Id.ToString(); this.lblOrderID.Text = model.OrderID.ToString(); this.lblBookID.Text = model.BookID.ToString(); this.lblQuantity.Text = model.Quantity.ToString(); this.lblUnitPrice.Text = model.UnitPrice.ToString(); }
public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (!PageValidate.IsNumber(txtOrderID.Text)) { strErr += "OrderID格式错误!\\n"; } if (!PageValidate.IsNumber(txtBookID.Text)) { strErr += "BookID格式错误!\\n"; } if (!PageValidate.IsNumber(txtQuantity.Text)) { strErr += "Quantity格式错误!\\n"; } if (!PageValidate.IsDecimal(txtUnitPrice.Text)) { strErr += "UnitPrice格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int Id = int.Parse(this.lblId.Text); int OrderID = int.Parse(this.txtOrderID.Text); int BookID = int.Parse(this.txtBookID.Text); int Quantity = int.Parse(this.txtQuantity.Text); decimal UnitPrice = decimal.Parse(this.txtUnitPrice.Text); OLBookstore.Model.OrderBook model = new OLBookstore.Model.OrderBook(); model.Id = Id; model.OrderID = OrderID; model.BookID = BookID; model.Quantity = Quantity; model.UnitPrice = UnitPrice; OLBookstore.BLL.OrderBookManager bll = new OLBookstore.BLL.OrderBookManager(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 得到一个对象实体 /// </summary> public OLBookstore.Model.OrderBook GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,OrderID,BookID,Quantity,UnitPrice from OrderBook "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; OLBookstore.Model.OrderBook model = new OLBookstore.Model.OrderBook(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }