📄 updatebook.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BookShop;
using System.Data.SqlClient;
public partial class UpdateBook : System.Web.UI.Page
{
private int nBookID = -1;
private int nCategoryID = -1;
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["CategoryID"] != null)
{
nCategoryID = Int32.Parse(Request.Params["CategoryID"].ToString());
}
if (Request.Params["BookID"] != null)
{
nBookID = Int32.Parse(Request.Params["BookID"].ToString());
}
if (!Page.IsPostBack)
{
if (nBookID > -1)
{
///显示被修改书籍的数据
BindBookData(nBookID);
}
}
///设置更新按钮的可用性
UpdateBtn.Enabled = (nBookID <= -1) ? false : true;
}
private void BindBookData(int nBookID)
{
///从数据库获取数据
Book book = new Book();
SqlDataReader recb = book.GetSingleBook(nBookID);
///显示数据
if (recb.Read())
{
Name.Text = recb["Name"].ToString();
Desn.Text = recb["Desn"].ToString();
Author.Text = recb["Author"].ToString();
Publish.Text = recb["Publish"].ToString();
PublishDate.Text = recb["PublishDate"].ToString();
Foreword.Text = recb["Foreword"].ToString();
List.Text = recb["List"].ToString();
OutLine.Text = recb["OutLine"].ToString();
BuyInDate.Text = recb["BuyInDate"].ToString();
Price.Text = recb["Price"].ToString();
TotalNum.Text = recb["TotalNum"].ToString();
StoreNum.Text = recb["StoreNum"].ToString();
SellOrder.Text = recb["SellOrder"].ToString();
Attribute1.Text = recb["Attribute1"].ToString();
Attribute2.Text = recb["Attribute2"].ToString();
Attribute3.Text = recb["Attribute3"].ToString();
Attribute4.Text = recb["Attribute4"].ToString();
Attribute5.Text = recb["Attribute5"].ToString();
Remark.Text = recb["Remark"].ToString();
}
///关闭数据源
recb.Close();
}
protected void UpdateBtn_Click(object sender,EventArgs e)
{
///如果页面输入内容合法
if (Page.IsValid == true)
{
///定义类
Book book = new Book();
try
{
///修改书籍信息
book.UpdateBook(nBookID,Name.Text.Trim(),Desn.Text.Trim(),
Author.Text.Trim(),Publish.Text.Trim(),DateTime.Parse(PublishDate.Text.Trim()),
ISBN.Text.Trim(),Foreword.Text.Trim(),List.Text.Trim(),
OutLine.Text.Trim(),DateTime.Parse(BuyInDate.Text.Trim()),
Decimal.Parse(Price.Text.Trim()),
Int32.Parse(TotalNum.Text.Trim()),Attribute1.Text,
Attribute2.Text,Attribute3.Text,Attribute4.Text,Attribute5.Text,
Remark.Text);
///显示操作结果信息
Response.Write("<script>window.alert('" + ASPNET2System.OPERATIONADDSUCCESSMESSAGE + "')</script>");
}
catch (Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ ASPNET2System.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
}
protected void ReturnBtn_Click(object sender,EventArgs e)
{
///返回管理页面
Response.Redirect("~/DesktopModules/Book/MainManage.aspx?CategoryID="
+ nCategoryID.ToString());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -