public void btnSave_Click(object sender, EventArgs e) { string strErr = ""; if (this.txtFareName.Text.Trim().Length == 0) { strErr += "FareName不能为空!\\n"; } if (!PageValidate.IsDecimal(txtPrice.Text)) { strErr += "Price格式错误!\\n"; } if (strErr != "") { MessageBox.Show(this, strErr); return; } int GroupPriceNo = int.Parse(this.lblGroupPriceNo.Text); int FareRateNo = int.Parse(this.lblFareRateNo.Text); string FareName = this.txtFareName.Text; decimal Price = decimal.Parse(this.txtPrice.Text); WebDemo.Model.WebDemo.RatePrice model = new WebDemo.Model.WebDemo.RatePrice(); model.GroupPriceNo = GroupPriceNo; model.FareRateNo = FareRateNo; model.FareName = FareName; model.Price = Price; WebDemo.BLL.WebDemo.RatePrice bll = new WebDemo.BLL.WebDemo.RatePrice(); bll.Update(model); Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx"); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(WebDemo.Model.WebDemo.RatePrice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update RatePrice set "); strSql.Append("FareName=@FareName,"); strSql.Append("Price=@Price"); strSql.Append(" where GroupPriceNo=@GroupPriceNo and FareRateNo=@FareRateNo "); SqlParameter[] parameters = { new SqlParameter("@FareName", SqlDbType.NVarChar, 10), new SqlParameter("@Price", SqlDbType.Decimal, 9), new SqlParameter("@GroupPriceNo", SqlDbType.Int, 4), new SqlParameter("@FareRateNo", SqlDbType.Int, 4) }; parameters[0].Value = model.FareName; parameters[1].Value = model.Price; parameters[2].Value = model.GroupPriceNo; parameters[3].Value = model.FareRateNo; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(WebDemo.Model.WebDemo.RatePrice model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into RatePrice("); strSql.Append("GroupPriceNo,FareRateNo,FareName,Price)"); strSql.Append(" values ("); strSql.Append("@GroupPriceNo,@FareRateNo,@FareName,@Price)"); SqlParameter[] parameters = { new SqlParameter("@GroupPriceNo", SqlDbType.Int, 4), new SqlParameter("@FareRateNo", SqlDbType.Int, 4), new SqlParameter("@FareName", SqlDbType.NVarChar, 10), new SqlParameter("@Price", SqlDbType.Decimal, 9) }; parameters[0].Value = model.GroupPriceNo; parameters[1].Value = model.FareRateNo; parameters[2].Value = model.FareName; parameters[3].Value = model.Price; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.RatePrice GetModel(int GroupPriceNo, int FareRateNo) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 GroupPriceNo,FareRateNo,FareName,Price from RatePrice "); strSql.Append(" where GroupPriceNo=@GroupPriceNo and FareRateNo=@FareRateNo "); SqlParameter[] parameters = { new SqlParameter("@GroupPriceNo", SqlDbType.Int, 4), new SqlParameter("@FareRateNo", SqlDbType.Int, 4) }; parameters[0].Value = GroupPriceNo; parameters[1].Value = FareRateNo; WebDemo.Model.WebDemo.RatePrice model = new WebDemo.Model.WebDemo.RatePrice(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void ShowInfo(int GroupPriceNo, int FareRateNo) { WebDemo.BLL.WebDemo.RatePrice bll = new WebDemo.BLL.WebDemo.RatePrice(); WebDemo.Model.WebDemo.RatePrice model = bll.GetModel(GroupPriceNo, FareRateNo); this.lblGroupPriceNo.Text = model.GroupPriceNo.ToString(); this.lblFareRateNo.Text = model.FareRateNo.ToString(); this.txtFareName.Text = model.FareName; this.txtPrice.Text = model.Price.ToString(); }
/// <summary> /// 得到一个对象实体 /// </summary> public WebDemo.Model.WebDemo.RatePrice DataRowToModel(DataRow row) { WebDemo.Model.WebDemo.RatePrice model = new WebDemo.Model.WebDemo.RatePrice(); if (row != null) { if (row["GroupPriceNo"] != null && row["GroupPriceNo"].ToString() != "") { model.GroupPriceNo = int.Parse(row["GroupPriceNo"].ToString()); } if (row["FareRateNo"] != null && row["FareRateNo"].ToString() != "") { model.FareRateNo = int.Parse(row["FareRateNo"].ToString()); } if (row["FareName"] != null) { model.FareName = row["FareName"].ToString(); } if (row["Price"] != null && row["Price"].ToString() != "") { model.Price = decimal.Parse(row["Price"].ToString()); } } return(model); }