📄 materielmodweb.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>
/// MaterielModWeb 的摘要说明。
/// </summary>
public class MaterielModWeb : BasePage
{
protected System.Web.UI.WebControls.Label lblTitle;
protected System.Web.UI.WebControls.TextBox txtId;
protected System.Web.UI.WebControls.TextBox txtCodeHide;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.WebControls.DropDownList ddlMaterielCatalog;
protected System.Web.UI.WebControls.ValidationSummary ErrorSummary;
protected System.Web.UI.WebControls.Label lblCode;
protected System.Web.UI.WebControls.TextBox txtCode;
protected System.Web.UI.WebControls.RequiredFieldValidator reqId;
protected System.Web.UI.WebControls.Label lblName;
protected System.Web.UI.WebControls.TextBox txtDescription;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label lblPhone;
protected System.Web.UI.WebControls.DropDownList ddlUnit;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.TextBox txtCost;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.DropDownList ddlWarehouse;
protected System.Web.UI.WebControls.DropDownList ddlLocation;
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.Label lblMessage;
protected System.Web.UI.WebControls.Button btnGoBack;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator3;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator4;
protected System.Web.UI.WebControls.TextBox txtSpec;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
protected System.Web.UI.HtmlControls.HtmlTable tableMod;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
Principal p=this.CurrentUser();
this.CheckPermissionPage(p.Id,"","104");
this.ReponseWriteDeleteScript ();
this.lblMessage.Visible=false;
btnDelete.Attributes.Add("onClick","javascript:return confirm('确定要删除此记录吗?');");
//this.GoBackFunction(this.btnGoBack);
if(!Page.IsPostBack)
{
if(Request.QueryString["Id"]!=null)
this.ViewState["Id"]=Request.QueryString["Id"].ToString();
else
this.ViewState["Id"]="";
if(this.ViewState["Id"].ToString()!="")
this.InitUpdate();
else
this.InitAdd();
// this.BindGrid();
}
}
private void InitButton(bool isAdd)
{
this.btnAdd.Visible=isAdd;
this.btnUpdate.Visible=!isAdd;
this.btnDelete.Visible=!isAdd;
}
private void InitUpdate()
{
this.InitButton(false);
this.InitBoth();
string id=this.ViewState["Id"].ToString();
Materiel m=new Materiel();
m.Id=id;
m.Retrieve();
if(m.IsPersistent)
{
this.txtId.Text=m.Id;
this.txtCode.Text =m.Code;
this.txtCodeHide.Text=m.Code;
this.txtDescription.Text =m.Description;
this.txtSpec.Text = m.Spec;
this.txtCost.Text =m.Cost.ToString();
Common.SelectFlg(this.ddlMaterielCatalog,m.CatalogId);
Common.SelectFlg(this.ddlUnit,m.Unit);
Location l=new Location();
l.Id=m.LocationId;
l.Retrieve();
if(l.IsPersistent)
{
Common.SelectFlg(this.ddlWarehouse,l.WarehouseId);
this.BindLoc();
Common.SelectFlg(this.ddlLocation,l.Id);
}
this.lblInsertDate.Text = m.InsertDate.ToString();
this.lblInsertOperater.Text = m.InsertOperater;
this.chkFlag.Checked=m.Flag=="Y"?true:false;
//this.ddlMaterielCatalog.SelectedIndex=this.ddlMaterielCatalog.Items.IndexOf(this.ddlMaterielCatalog.Items.FindByValue(m.CatalogId));
}
else
{
this.lblMessage.Text="此记录可能已经删除,请返回刷新";
this.lblMessage.Visible=true;
this.btnAdd.Visible=false;
this.btnDelete.Visible=false;
this.btnUpdate.Visible=false;
this.btnGoBack.Visible=true;
}
}
private void InitAdd()
{
this.InitBoth();
this.txtId.Text="";
this.txtCode.Text="";
this.txtCodeHide.Text ="";
this.txtDescription.Text="";
this.txtSpec.Text="";
this.txtCost.Text="";
// if(this.ddlMaterielCatalog.Items.Count>0)
// this.ddlMaterielCatalog.SelectedIndex=0;
//
// if(this.ddlUnit.Items.Count>0)
// this.ddlUnit.SelectedIndex=0;
//
// if(this.ddlWarehouse.Items.Count>0)
// {
// this.ddlWarehouse.SelectedIndex=0;
// this.BindLoc();
// }
this.chkFlag.Checked=true;
this.lblInsertOperater.Text = this.CurrentUser().Id;
this.lblInsertDate.Text = System.DateTime.Now.ToString();
this.InitButton(true);
}
private void InitBoth()
{
DataTable dt=MaterielSystem.AllMaterielCatalog("Y");
Common.BindDrop(this.ddlMaterielCatalog,dt,MaterielCatalog.NAME,MaterielCatalog.ID);
DataTable dtUnit=UnitSystem.AllUnit("Y");
Common.BindDrop(this.ddlUnit,dtUnit,BusinessRules.Unit.CODE,BusinessRules.Unit.ID);
DataTable dtWare=WarehouseSystem.AllWarehouse(false,"Y");
Common.BindDrop(this.ddlWarehouse,dtWare,Warehouse.CODE,Warehouse.ID);
this.BindLoc();
}
private void BindLoc()
{
if(this.ddlWarehouse.Items.Count>0)
{
string w=this.ddlWarehouse.SelectedItem.Value;
if(w!="")
{
DataTable dtLoc=WarehouseSystem.AllLocation(w,"Y");
Common.BindDrop(this.ddlLocation,dtLoc,Location.CODE,Location.ID);
}
}
}
// private void BindGrid()
// {
// DataView dt=CustomSystem.AllCustom("").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.ddlWarehouse.SelectedIndexChanged += new System.EventHandler(this.ddlWarehouse_SelectedIndexChanged);
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.btnGoBack.Click += new System.EventHandler(this.btnGoBack_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnAdd_Click(object sender, System.EventArgs e)
{
if(!Common.CheckMultTextBox(this.txtDescription,this.lblMessage,"失败:物料描述只允许250个字符之内",250)) return;
Materiel m=new Materiel();
BindAttribute(m);
if(m.Id=="")
m.Id=LoginSystem.GetTableId("Materiel").ToString();
if(!MaterielSystem.CheckMaterielIsUnique(m))
{
this.lblMessage.Text ="失败:物料编号已经存在,请确保唯一";
this.lblMessage.Visible=true;
}
else
{
try
{
MaterielSystem.SaveMateriel(m);
}
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(Materiel m)
{
m.Id=this.txtId.Text.Trim();
m.Code=this.txtCode.Text.Trim();
m.Flag=this.chkFlag.Checked?"Y":"N";
m.InsertDate=System.DateTime.Now;
m.InsertOperater=this.CurrentUser().Id;
m.CatalogId=this.ddlMaterielCatalog.SelectedItem.Value;
m.Description=this.txtDescription.Text;
m.Spec=this.txtSpec.Text;
m.Unit=this.ddlUnit.SelectedItem.Value;
string cost=this.txtCost.Text.Trim();
m.Cost=cost==""?0:double.Parse(cost);
m.LocationId=this.ddlLocation.SelectedItem.Value;
}
// 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!="")
// {
// Custom custom=new Custom();
// custom.Id=id;
// custom.Retrieve();
// this.SetFormBy (custom);
// this.InitButton(false);
// }
// }
private void SetFormBy(Custom c)
{
this.txtId.Text = c.Id;
this.txtCode.Text = c.Code;
this.txtCodeHide.Text =c.Code;
this.txtSpec.Text = c.LinkMan;
this.chkFlag.Checked=c.Flag=="Y"?true:false;
this.lblInsertDate.Text = c.InsertDate.ToString();
this.lblInsertOperater.Text = c.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!="")
// {
// Custom c=new Custom();
// c.Id=id;
// this.DeleteRecord(c);
// this.BindGrid ();
// }
// }
public void DeleteRecord(Materiel m)
{
try
{
m.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!="")
{
Materiel m=new Materiel();
m.Id=id;
this.DeleteRecord(m);
// this.InitAdd();
// this.BindGrid ();
}
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
if(!Common.CheckMultTextBox(this.txtDescription,this.lblMessage,"失败:物料描述只允许250个字符之内",250)) return;
Materiel m=new Materiel();
m.IsPersistent=true;
BindAttribute(m);
if(!MaterielSystem.CheckMaterielIsUnique(m) && this.txtCodeHide.Text.Trim()!=this.txtCode.Text.Trim())
{
this.lblMessage.Text ="失败:物料编号已经存在,请确保唯一";
this.lblMessage.Visible=true;
}
else
{
MaterielSystem.SaveMateriel(m);
this.lblMessage.Text="成功:更新记录成功";
this.lblMessage.Visible=true;
}
// this.InitAdd();
// this.BindGrid ();
}
private void ddlWarehouse_SelectedIndexChanged(object sender, System.EventArgs e)
{
this.BindLoc();
}
private void btnGoBack_Click(object sender, System.EventArgs e)
{
Response.Redirect("MaterielWeb.aspx");
Response.End();
}
// private void Button1_Click(object sender, System.EventArgs e)
// {
// Response.Redirect("MaterielModWeb.aspx");
// Response.End();
// }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -