📄 updateproduct.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MisStock.Components;
namespace MisStock.DesktopModules.Product
{
/// <summary>
/// Update 的摘要说明。
/// </summary>
public class UpdateProduct : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox ProNo;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.TextBox ProName;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.DropDownList ProductTypeList;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.TextBox ProStyle;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.TextBox ProUnit;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;
protected System.Web.UI.WebControls.Label lblAdditionalNo;
protected System.Web.UI.WebControls.TextBox Price;
protected System.Web.UI.WebControls.RequiredFieldValidator rfNew;
protected System.Web.UI.WebControls.RegularExpressionValidator reNew;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.TextBox Quantity;
protected System.Web.UI.WebControls.RequiredFieldValidator rfBD;
protected System.Web.UI.WebControls.RegularExpressionValidator reBD;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox Lower;
protected System.Web.UI.WebControls.RequiredFieldValidator rfL;
protected System.Web.UI.WebControls.RegularExpressionValidator reL;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox Upper;
protected System.Web.UI.WebControls.RequiredFieldValidator rfU;
protected System.Web.UI.WebControls.RegularExpressionValidator reU;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.TextBox Remark;
protected System.Web.UI.WebControls.Button UpdateBtn;
protected System.Web.UI.WebControls.Button ReturnBtn;
private int nProductID = -1;
private void Page_Load(object sender, System.EventArgs e)
{
///判断用户是否登陆
if(Session["UserID"] == null)
{
Response.Redirect("~/Default.aspx");
}
///判断用户是否是超级管理员
if(Components.User.IsAuthorityAdmin(Session["UserID"].ToString()) >= Components.User.USERTYPENORMAL)
{
Response.Write("<script>alert(\"你没有权限,请与管理员联系!\")</script>");
Response.Write("<script>history.back();</script>");
}
if(Request.Params["ProductID"] != null)
{
nProductID = Int32.Parse(Request.Params["ProductID"].ToString());
}
if(!Page.IsPostBack)
{
///绑定控件的数据
BindProductTypeData();
if(nProductID > -1)
{
///显示信息
BindProductData(nProductID);
}
}
///设置按钮的可用性
UpdateBtn.Enabled = (ProductTypeList.Items.Count <= 0 || nProductID <= -1) ? false : true;
}
private void BindProductTypeData()
{
///定义获取数据的类
MisStock.Components.ProductType type = new MisStock.Components.ProductType();
SqlDataReader rect = type.GetProductTypes();
///设定控件的数据源
ProductTypeList.DataSource = rect;
///设定控件的Text属性和Value属性
ProductTypeList.DataTextField = "Name";
ProductTypeList.DataValueField = "ProductTypeID";
///绑定控件的数据
ProductTypeList.DataBind();
///关闭数据读取器和数据库的连接
rect.Close();
}
private void BindProductData(int nProductID)
{
///定义获取数据的类
MisStock.Components.Product product = new MisStock.Components.Product();
SqlDataReader recp = product.GetSingleProduct(nProductID);
///从获取的数据中读取数据
if(recp.Read())
{
ProNo.Text = recp["ProNo"].ToString();
ProName.Text = recp["ProName"].ToString();
ProStyle.Text = recp["ProStyle"].ToString();
ProUnit.Text = recp["ProUnit"].ToString();
Price.Text = recp["Price"].ToString();
Quantity.Text = recp["Quantity"].ToString();
Lower.Text = recp["LowerSum"].ToString();
Upper.Text = recp["UpperSum"].ToString();
Remark.Text = recp["Remark"].ToString();
///设置列表控件的数据
MisSystem.SetListBoxItem(ProductTypeList,recp["ProductTypeID"].ToString());
}
///关闭数据读取器和数据库的连接
recp.Close();
}
private void ReturnBtn_Click(object sender, System.EventArgs e)
{
///跳转到管理页面
Response.Redirect("~/DesktopModules/Product/ProductManage.aspx");
}
private void UpdateBtn_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
///定义类
MisStock.Components.Product product = new MisStock.Components.Product();
try
{
///修改操作
product.UpdateProduct(nProductID,
ProNo.Text.Trim(),ProName.Text.Trim(),
Int32.Parse(ProductTypeList.SelectedValue),
ProStyle.Text.Trim(),
ProUnit.Text.Trim(),
Convert.ToDecimal(Price.Text.Trim()),
Int32.Parse(Quantity.Text.Trim()),
Int32.Parse(Lower.Text.Trim()),
Int32.Parse(Upper.Text.Trim()),
Remark.Text);
///显示操作结果信息
Response.Write ("<script>window.alert('" + MisSystem.OPERATIONUPDATESUCCESSMESSAGE + "')</script>");
}
catch(Exception ex)
{
///显示修改操作中的失败、错误信息
Response.Redirect("~/DesktopModules/ErrorPage.aspx?ErrorUrl="
+ MisSystem.RedirectErrorUrl(Request.RawUrl)
+ "&ErrorMessage=" + ex.Message.Replace("\n"," "));
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.UpdateBtn.Click += new System.EventHandler(this.UpdateBtn_Click);
this.ReturnBtn.Click += new System.EventHandler(this.ReturnBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -