📄 productmodify.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 Common;
using DataAccessLibrary;
namespace FerrariSales.Page
{
/// <summary>
/// ProductModify 的摘要说明。
/// </summary>
public class ProductModify : BasePage
{
protected System.Web.UI.WebControls.TextBox txt_ModisCode;
protected System.Web.UI.WebControls.TextBox txt_ProductName;
protected System.Web.UI.WebControls.TextBox txt_PreFixChassis;
protected System.Web.UI.WebControls.TextBox txt_PreFixEngine;
protected System.Web.UI.WebControls.TextBox txt_NetWeight;
protected System.Web.UI.WebControls.TextBox txt_GrossWeight;
protected System.Web.UI.WebControls.TextBox txt_Measurement;
protected System.Web.UI.WebControls.DropDownList cbo_IsProduct;
protected System.Web.UI.WebControls.Label lbl_ProductID;
protected System.Web.UI.WebControls.TextBox txt_Capacity;
protected System.Web.UI.WebControls.Button btn_New;
protected System.Web.UI.WebControls.Button btn_Update;
protected System.Web.UI.WebControls.Button btn_Cancel;
protected System.Web.UI.WebControls.RegularExpressionValidator val_PreFixEngine;
protected System.Web.UI.WebControls.RegularExpressionValidator val_ModisCode;
protected System.Web.UI.WebControls.RegularExpressionValidator val_PreFixChassis;
protected System.Web.UI.WebControls.RegularExpressionValidator val_NewWeight;
protected System.Web.UI.WebControls.RegularExpressionValidator val_GrossWeight;
protected System.Web.UI.WebControls.RegularExpressionValidator val_Measurement;
protected System.Web.UI.WebControls.RegularExpressionValidator val_Capacity;
protected System.Web.UI.WebControls.RequiredFieldValidator val_ModisCodeReq;
private void Page_Load(object sender, System.EventArgs e)
{
//用户登录安全性检查(每个页面都要有,从BasePage继承)
this.SecurityCheck();
if (!Page.IsPostBack)
{
//判断操作类型(有URL参数的为新增)
string productID = Request["id"];
if (productID == null || productID == "")
{
//------新增模式------
//点击取消Button后的页面跳转
string strCancelUrl = "javascript:window.location.href('Product.aspx');return false;";
this.btn_Cancel.Attributes.Add("OnClick",strCancelUrl);
return;
}
else
{
//------修改模式------
//检索车型信息
this.GetProductInfo(productID);
//将ProductID保存到缓存
this.ViewState["ProductID"] = productID;
//点击取消Button后的页面跳转
string strCancelUrl = "javascript:window.location.href('Product.aspx?id=" + productID + "');return false;";
this.btn_Cancel.Attributes.Add("OnClick",strCancelUrl);
}
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_New.Click += new System.EventHandler(this.btn_New_Click);
this.btn_Update.Click += new System.EventHandler(this.btn_Update_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// <summary>
/// 检索车型信息
/// </summary>
public void GetProductInfo(string productID)
{
//检索产品信息
BisProduct bisProduct = new BisProduct();
DataTable table = bisProduct.GetProductInfoAndValue(productID);
if (table == null)
{
//产品不存在(此为安全代码)
this.Response.Redirect("Product.aspx");
this.Response.End();
}
this.lbl_ProductID.Text = ConvertType.GetString(table.Rows[0]["ProductID"]);
this.txt_ModisCode.Text = ConvertType.GetString(table.Rows[0]["ModisCode"]);
this.txt_ProductName.Text = ConvertType.GetString(table.Rows[0]["ProductName"]);
this.txt_PreFixChassis.Text = ConvertType.GetString(table.Rows[0]["PreFixChassis"]);
this.txt_PreFixEngine.Text = ConvertType.GetString(table.Rows[0]["PreFixEngine"]);
this.txt_NetWeight.Text = CommonFunc.ConvertNumericToPageStyle(ConvertType.GetInt(table.Rows[0]["NetWeight"]));
this.txt_GrossWeight.Text = CommonFunc.ConvertNumericToPageStyle(ConvertType.GetInt(table.Rows[0]["GrossWeight"]));
this.txt_Measurement.Text = CommonFunc.ConvertNumericToPageStyle(ConvertType.GetDecimal(table.Rows[0]["Measurement"]));
this.txt_Capacity.Text = Common.CommonFunc.ConvertNumericToPageStyle(ConvertType.GetDecimal(table.Rows[0]["Capacity"]));
this.cbo_IsProduct.SelectedValue = ConvertType.GetString(table.Rows[0]["IsProduct"]);
}
private void btn_New_Click(object sender, System.EventArgs e)
{
//暂时不需要实现新增功能
}
/// <summary>
/// 信息修改
/// </summary>
private void btn_Update_Click(object sender, System.EventArgs e)
{
//取得表单提交的数据
DataTblProduct tblProduct = new DataTblProduct();
tblProduct.ProductID = this.ViewState["ProductID"].ToString();
tblProduct.ModisCode = this.txt_ModisCode.Text.Trim();
tblProduct.ProductName = this.txt_ProductName.Text.Trim();
tblProduct.PreFixChassis = this.txt_PreFixChassis.Text.Trim();
tblProduct.PreFixEngine = this.txt_PreFixEngine.Text.Trim();
tblProduct.NetWeight = int.Parse(this.txt_NetWeight.Text);
tblProduct.GrossWeight = int.Parse(this.txt_GrossWeight.Text);
tblProduct.Measurement = decimal.Parse(this.txt_Measurement.Text);
tblProduct.Capacity = decimal.Parse(this.txt_Capacity.Text);
tblProduct.IsProduct = this.cbo_IsProduct.SelectedValue;
//更新
BisProduct bisProduct = new BisProduct();
if (bisProduct.UpdateProductInfo(tblProduct))
{
//更新成功,页面返回
this.Response.Redirect("Product.aspx?id=" + tblProduct.ProductID);
this.Response.End();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -