📄 bommodweb.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>
/// BOMModWeb 的摘要说明。
/// </summary>
public class BOMModWeb : 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.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.Label Label1;
protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
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 btnGoBack;
protected System.Web.UI.WebControls.Label lblMessage;
protected System.Web.UI.WebControls.TextBox txtName;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator2;
protected System.Web.UI.WebControls.TextBox txtJGCost;
protected System.Web.UI.WebControls.TextBox txtJGPrice;
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.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label7;
protected System.Web.UI.WebControls.DropDownList ddlMaterielCat;
protected System.Web.UI.WebControls.Label Label8;
protected System.Web.UI.WebControls.Label Label10;
protected System.Web.UI.WebControls.Label Label11;
protected System.Web.UI.WebControls.Label Label12;
protected System.Web.UI.WebControls.DropDownList ddlUnit;
protected System.Web.UI.WebControls.ListBox lstMateriel;
protected System.Web.UI.WebControls.Label txtMCode;
protected System.Web.UI.WebControls.TextBox txtMQ;
protected System.Web.UI.WebControls.DropDownList ddlPercent;
protected System.Web.UI.WebControls.TextBox txtMId;
protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
protected System.Web.UI.WebControls.DataGrid grid;
protected System.Web.UI.WebControls.RangeValidator Rangevalidator3;
protected System.Web.UI.WebControls.Label Label9;
protected System.Web.UI.WebControls.CheckBox chkUse;
protected System.Web.UI.WebControls.TextBox txtBOMCode;
protected System.Web.UI.HtmlControls.HtmlTable tableMod;
//protected DataTable dtBOMLine;
//protected DataTable dtBOMLine;
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('确定要删除整个BOM吗?请谨慎操作');");
Button3.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()
{
string id=this.ViewState["Id"].ToString();
this.InitButton(false);
this.InitBoth();
BOM m=new BOM();
m.Id=id;
m.Retrieve();
if(m.IsPersistent)
{
this.txtId.Text=m.Id;
this.txtCode.Text =m.Code;
this.txtCodeHide.Text=m.Code;
this.txtName.Text =m.Name;
this.txtJGCost.Text = m.JGCost.ToString();
this.txtJGPrice.Text =m.JGPrice.ToString();
this.txtRemark.Text =m.Remark;
this.lblInsertDate.Text = m.InsertDate.ToString();
this.lblInsertOperater.Text = m.InsertOperater;
}
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.txtName.Text ="";
this.txtJGCost.Text ="";
this.txtJGPrice.Text ="";
this.txtRemark.Text="";
this.lblInsertOperater.Text = this.CurrentUser().Id;
this.lblInsertDate.Text = System.DateTime.Now.ToString();
this.InitButton(true);
}
private void InitBoth()
{
DataTable dtMC=MaterielSystem.AllMaterielCatalog("Y");
Common.BindDrop(this.ddlMaterielCat,dtMC,MaterielCatalog.NAME,MaterielCatalog.ID,"所有","");
DataTable dtUnit=UnitSystem.AllUnit("Y");
Common.BindDrop(this.ddlUnit,dtUnit,BusinessRules.Unit.CODE,BusinessRules.Unit.ID);
DataTable dtMater=MaterielSystem.AllMateriel(this.ddlMaterielCat.SelectedItem.Value,"Y");
ListBox lc=this.lstMateriel;
lc.Items.Clear();
foreach(DataRow myRow in dtMater.Rows)
{
lc.Items.Add(new ListItem("["+myRow[Materiel.CODE].ToString()+"]"+Common.GetLeftString(myRow[Materiel.DESCRIPTION].ToString(),20),myRow[Materiel.ID].ToString()));
}
lc.DataBind();
//Common.BindDrop(this.lstMateriel,dtMater,Materiel.CODE,Materiel.ID);
DataTable dtBOMLine;
if(this.ViewState["Id"].ToString()!="")
{
dtBOMLine=BOMSystem.AllBOMLine(this.ViewState["Id"].ToString(),"");
}
else
{
dtBOMLine=BOMSystem.AllBOMLine("0","");
}
this.ViewState["BOMLine"]=dtBOMLine;
Common.ReSet(this.grid,dtBOMLine.DefaultView);
grid.DataSource=dtBOMLine.DefaultView;
grid.DataBind();
}
// 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.ddlMaterielCat.SelectedIndexChanged += new System.EventHandler(this.ddlMaterielCat_SelectedIndexChanged);
this.txtBOMCode.TextChanged += new System.EventHandler(this.txtBOMCode_TextChanged);
this.lstMateriel.SelectedIndexChanged += new System.EventHandler(this.ListBox1_SelectedIndexChanged);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.grid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grid_ItemDataBound);
this.grid.SelectedIndexChanged += new System.EventHandler(this.grid_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.txtRemark,this.lblMessage,"失败:BOM备注只允许100个字符之内",100)) return;
BOM b=new BOM();
BindAttribute(b);
if(b.Id=="")
b.Id=LoginSystem.GetTableId("BOM").ToString();
if(!BOMSystem.CheckBOMIsUnique(b) && this.txtCodeHide.Text.Trim()!=this.txtCode.Text.Trim())
{
this.lblMessage.Text ="失败:成品编号已经存在,请确保唯一";
this.lblMessage.Visible=true;
}
else
{
try
{
DataTable dt=(DataTable)this.ViewState["BOMLine"];
dt.AcceptChanges();
BOMSystem.SaveBOM(b,dt);
}
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(BOM b)
{
b.Id=this.txtId.Text.Trim();
b.Code=this.txtCode.Text.Trim();
b.Name=this.txtName.Text.Trim();
string cost=this.txtJGCost.Text.Trim();
if(cost=="")
b.JGCost=0;
else
b.JGCost=double.Parse(cost);
string price=this.txtJGPrice.Text.Trim();
if(price=="")
b.JGPrice=0;
else
b.JGPrice=double.Parse(price);
b.InsertDate=System.DateTime.Now;
b.InsertOperater=this.CurrentUser().Id;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -