📄 reasonweb.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>
/// ReasonWeb 的摘要说明。
/// </summary>
public class ReasonWeb : BasePage
{
protected System.Web.UI.WebControls.Label lblTitle;
protected System.Web.UI.WebControls.TextBox txtId;
protected System.Web.UI.WebControls.ValidationSummary ErrorSummary;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.TextBox txtRemark;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.CheckBox chkFlag;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label lblInsertOperater;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.Label lblInsertDate;
protected System.Web.UI.WebControls.Button btnAdd;
protected System.Web.UI.WebControls.Button btnUpdate;
protected System.Web.UI.WebControls.Button btnDelete;
protected System.Web.UI.WebControls.Button btnContinue;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.DataGrid grid;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Principal p=this.CurrentUser();
this.CheckPermissionPage(p.Id,"","130");
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.txtName.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=RejectSystem.AllReason("").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.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.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.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;
Reason r=new Reason();
BindAttribute(r);
if(r.Id=="")
r.Id=LoginSystem.GetTableId("Reason").ToString();
try
{
r.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(Reason r)
{
r.Id=this.txtId.Text.Trim();
r.Description =this.txtRemark.Text.Trim();
r.Flag=this.chkFlag.Checked?"Y":"N";
r.InsertDate=System.DateTime.Now;
r.InsertOperater=this.CurrentUser().Id;
r.Name=this.txtName.Text.Trim();
}
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!="")
{
Reason r=new Reason();
r.Id=id;
r.Retrieve();
this.SetFormBy (r);
this.InitButton(false);
}
}
private void SetFormBy(Reason r)
{
this.txtId.Text = r.Id;
this.txtName.Text = r.Name;
this.txtRemark.Text = r.Description;
this.chkFlag.Checked=r.Flag=="Y"?true:false;
this.lblInsertDate.Text = r.InsertDate.ToString();
this.lblInsertOperater.Text = r.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!="")
{
Reason r=new Reason();
r.Id=id;
this.DeleteRecord(r);
this.BindGrid ();
}
}
public void DeleteRecord(Reason r)
{
if(RejectSystem.ReasonHasReject(r.Id))
{
this.lblMessage.Text="失败:此报损原因正被使用,请先确认删除相应的报损信息";
this.lblMessage.Visible=true;
return;
}
try
{
r.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!="")
{
Reason r=new Reason();
r.Id=id;
this.DeleteRecord(r);
this.InitAdd();
this.BindGrid ();
}
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if(!Common.CheckMultTextBox(this.txtRemark,this.lblMessage,"失败:备注只允许100个字符之内",100)) return;
Reason r=new Reason();
r.IsPersistent=true;
BindAttribute(r);
r.Save();
this.lblMessage.Text="成功:更新记录成功";
this.lblMessage.Visible=true;
this.InitAdd();
this.BindGrid ();
}
private void btnList_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -