📄 warehousepweb.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 Botheighten.Yanghui.BusinessFacade;
using Botheighten.Yanghui.Framework;
using Botheighten.Yanghui.BusinessRules;
namespace Botheighten.Yanghui.Web
{
/// <summary>
/// WarehousePWeb 的摘要说明。
/// </summary>
public class WarehousePWeb : BasePage
{
protected System.Web.UI.WebControls.DataGrid grid;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.Button btnContinue;
protected System.Web.UI.WebControls.Button btnDelete;
protected System.Web.UI.WebControls.Button btnUpdate;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.Label lblInsertDate;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label lblInsertOperater;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.CheckBox chkFlag;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox txtRemark;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtMaster;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.ValidationSummary ErrorSummary;
protected System.Web.UI.WebControls.RequiredFieldValidator reqId;
protected System.Web.UI.WebControls.TextBox txtCode;
protected System.Web.UI.WebControls.Label lblCode;
protected System.Web.UI.WebControls.TextBox txtCodeHide;
protected System.Web.UI.WebControls.TextBox txtId;
protected System.Web.UI.WebControls.Label lblTitle;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Principal p=this.CurrentUser();
this.CheckPermissionPage(p.Id,"","105");
this.ReponseWriteDeleteScript ();
this.lblMessage.Visible=false;
btnDelete.Attributes.Add("onClick","javascript:return confirm('确定要删除此记录吗?');");
//this.lblCompanyName.Text = Application["CompanyInfo"].ToString();
if(!Page.IsPostBack)
{
this.grid.PageSize=int.Parse(Application["PageSize"].ToString());
this.InitAdd();
this.BindGrid();
}
}
private void InitButton(bool isAdd)
{
this.btnAdd.Visible=isAdd;
this.btnUpdate.Visible=!isAdd;
this.btnDelete.Visible=!isAdd;
this.btnContinue.Visible=!isAdd;
}
private void InitAdd()
{
this.txtId.Text="";
this.txtCode.Text="";
this.txtCodeHide.Text ="";
this.txtName.Text="";
this.txtMaster.Text="";
this.txtRemark.Text="";
this.chkFlag.Checked=true;
this.lblInsertOperater.Text = this.CurrentUser().Id;
this.lblInsertDate.Text = System.DateTime.Now.ToString();
this.InitButton(true);
}
private void BindGrid()
{
DataView dt=WarehouseSystem.AllWarehouse(true,"").DefaultView;
Common.ReSet(this.grid,dt);
grid.DataSource=dt;
grid.DataBind();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.grid.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.grid_PageIndexChanged);
this.grid.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_EditCommand);
this.grid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.grid_SortCommand);
this.grid.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.grid_DeleteCommand);
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
this.btnContinue.Click += new System.EventHandler(this.btnContinue_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnContinue_Click(object sender, System.EventArgs e)
{
this.InitAdd();
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
if(!Common.CheckMultTextBox(this.txtRemark,this.lblMessage,"失败:备注只允许100个字符之内",100)) return;
Warehouse w=new Warehouse();
BindAttribute(w);
if(w.Id=="")
w.Id=LoginSystem.GetTableId("Warehouse").ToString();
if(!WarehouseSystem.CheckWarehouseIsUnique(w))
{
this.lblMessage.Text ="失败:仓库编号已经存在,请确保唯一";
this.lblMessage.Visible=true;
}
else
{
try
{
w.Save();
}
catch (LeaseException le)
{
if (le.ErrorType == LeaseExceptionType.PrimaryConflictException)
{
this.lblMessage.Text = "失败:新增记录时,主关键字冲突";
this.lblMessage.Visible = true;
}
else
{
throw le;
}
}
this.BindGrid();
this.lblMessage.Text ="成功:新增记录成功";
this.lblMessage.Visible=true;
this.InitAdd();
}
}
private void BindAttribute(Warehouse w)
{
w.Id=this.txtId.Text.Trim();
w.Remark=this.txtRemark.Text.Trim();
w.Code=this.txtCode.Text.Trim();
w.Flag=this.chkFlag.Checked?"Y":"N";
w.InsertDate=System.DateTime.Now;
w.InsertOperater=this.CurrentUser().Id;
w.Master=this.txtMaster.Text.Trim();
w.Name=this.txtName.Text.Trim();
w.IsFinishProduct="Y";
}
private void grid_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
this.grid.SelectedIndex=-1;
Common.SortGrid(grid,e.SortExpression.ToString());
this.BindGrid();
}
private void grid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
grid.CurrentPageIndex=e.NewPageIndex;
BindGrid();
}
private void grid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
grid.SelectedIndex = e.Item.ItemIndex;
string id = grid.DataKeys[e.Item.ItemIndex].ToString();
if(id!="")
{
Warehouse w=new Warehouse();
w.Id=id;
w.Retrieve();
this.SetFormBy (w);
this.InitButton(false);
}
}
private void SetFormBy(Warehouse w)
{
this.txtId.Text = w.Id;
this.txtCode.Text = w.Code;
this.txtCodeHide.Text =w.Code;
this.txtName.Text = w.Name;
this.txtRemark.Text = w.Remark;
this.txtMaster.Text = w.Master;
this.chkFlag.Checked=w.Flag=="Y"?true:false;
this.lblInsertDate.Text = w.InsertDate.ToString();
this.lblInsertOperater.Text = w.InsertOperater.ToString();
//Common.SelectFlg (this.cboQuality ,aProvider.Quality.ToString ());
}
private void grid_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
grid.SelectedIndex = e.Item.ItemIndex;
string id = grid.DataKeys[e.Item.ItemIndex].ToString();
if(id!="")
{
Warehouse w=new Warehouse();
w.Id=id;
this.DeleteRecord(w);
this.BindGrid ();
}
}
public void DeleteRecord(Warehouse w)
{
if(WarehouseSystem.WarehouseHasLocation(w.Id))
{
this.lblMessage.Text="失败:此仓库中具有库位,请先确认删除相应的库位信息";
this.lblMessage.Visible=true;
return;
}
try
{
w.Delete();
}
catch(LeaseException exp)
{
if(exp.ErrorType==LeaseExceptionType.RestrictException)
{
this.lblMessage.Text="失败:删除记录遇到错误,记录已经不存在";
this.lblMessage.Visible=true;
}
else
{
throw exp;
}
}
this.lblMessage.Text ="成功:删除记录成功";
this.lblMessage.Visible=true;
}
private void btnDelete_Click(object sender, System.EventArgs e)
{
string id=this.txtId.Text.Trim();
if(id!="")
{
Warehouse w=new Warehouse();
w.Id=id;
this.DeleteRecord(w);
this.InitAdd();
this.BindGrid ();
}
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if(!Common.CheckMultTextBox(this.txtRemark,this.lblMessage,"失败:备注只允许100个字符之内",100)) return;
Warehouse w=new Warehouse();
w.IsPersistent=true;
BindAttribute(w);
if(!WarehouseSystem.CheckWarehouseIsUnique(w) && this.txtCodeHide.Text.Trim()!=this.txtCode.Text.Trim())
{
this.lblMessage.Text ="失败:仓库编号已经存在,请确保唯一";
this.lblMessage.Visible=true;
}
else
{
w.Save();
this.lblMessage.Text="成功:更新记录成功";
this.lblMessage.Visible=true;
}
this.InitAdd();
this.BindGrid ();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -