⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 productlocationmod.aspx.cs

📁 可供共享学习.net环境下生产管理的实现
💻 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;
using Botheighten.Yanghui.Web.Controls;

namespace Botheighten.Yanghui.Web
{
	/// <summary>
	/// ProductLocationMod 的摘要说明。
	/// </summary>
	public class ProductLocationMod : BasePage
	{
		protected System.Web.UI.WebControls.Label lblTitle;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.TextBox txtId;
		protected System.Web.UI.WebControls.Button btnAdd;
		protected System.Web.UI.WebControls.Button Button3;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.DropDownList ddlWare;
		protected System.Web.UI.WebControls.ValidationSummary ErrorSummary;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.DropDownList ddlLoc;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.TextBox txtOrder;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Web.UI.WebControls.Button Button2;
		protected System.Web.UI.WebControls.DataGrid grid;
		protected System.Web.UI.HtmlControls.HtmlTable tableLocation;

		protected BOM_C BOM_C1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			Principal p=this.CurrentUser();
			this.CheckPermissionPage(p.Id,"","104");
			this.ReponseWriteDeleteScript ();
			this.lblMessage.Visible=false;
		
			if(!Page.IsPostBack)
			{
				this.tableLocation.Visible=false;
				string mid="";
				if(Request.QueryString["id"]!=null)
					mid=Request.QueryString["id"].ToString();
				this.ViewState["ID"]=mid;

				BOM_C1.PId=mid;
				BOM_C1.Bind();

				DataTable dtWare=WarehouseSystem.AllWarehouse(true,"Y");
				Common.BindDrop(this.ddlWare,dtWare,Warehouse.CODE,Warehouse.ID);

				this.BindLocation();

				this.BindGrid();
			}
		}

		private void BindLocation()
		{
			if(this.ddlWare.Items.Count>0)
			{
				DataTable dtLoc=WarehouseSystem.AllLocation(this.ddlWare.SelectedItem.Value,"Y");
				Common.BindDrop(this.ddlLoc,dtLoc,Location.CODE,Location.ID);
			}
		}

		private void BindGrid()
		{
			if(this.ViewState["ID"].ToString()!="")
			{
				DataTable dt=ProductSystem.AllProductLocations(this.ViewState["ID"].ToString());
				Common.ReSet(this.grid,dt.DefaultView);
				this.grid.DataSource=dt;
				this.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.Button3.Click += new System.EventHandler(this.Button3_Click);
			this.ddlWare.SelectedIndexChanged += new System.EventHandler(this.ddlWare_SelectedIndexChanged);
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			this.Button2.Click += new System.EventHandler(this.Button2_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.grid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.grid_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void grid_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			grid.CurrentPageIndex=e.NewPageIndex;
			BindGrid();
		}

		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_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			//grid.SelectedIndex = e.Item.ItemIndex;
			string id = grid.DataKeys[e.Item.ItemIndex].ToString();
			if(id!="")
			{

				ProductLocation ml=new ProductLocation();
				ml.Id=id;
				ml.Retrieve();
				this.DeleteRecord(ml);			
				this.BindGrid ();
			}
		}

		public void DeleteRecord(ProductLocation ml)
		{
			try
			{
				ml.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 grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if(e.Item.ItemType==ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
			{
				e.Item.Cells[3].Text = WarehouseSystem.GetLocationCode(e.Item.Cells[3].Text.Trim());
//				if(e.Item.Cells[2].Text.Trim()=="1")
//					e.Item.ForeColor=Color.Red;
				//				e.Item.Cells[4].Text = Common.GetLeftString(e.Item.Cells[4].Text.Trim(),20);
				//				e.Item.Cells[6].Text = UnitSystem.GetUnitCode(e.Item.Cells[6].Text.Trim());
			}
		}

		private void ddlWare_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.BindLocation();
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			this.tableLocation.Visible=true;
			this.txtId.Text="";
			this.txtOrder.Text=(this.grid.Items.Count+1).ToString();
			this.txtOrder.Enabled=true;
			
		}

		private void Button2_Click(object sender, System.EventArgs e)
		{
			this.tableLocation.Visible=false;
		}

		private void grid_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string id=this.grid.DataKeys[e.Item.ItemIndex].ToString();
			if(id!="")
			{
				ProductLocation ml=new ProductLocation();
				ml.Id=id;
				ml.Retrieve();
				if(ml.IsPersistent)
				{
					Location l=new Location();
					l.Id=ml.LocationId;
					l.Retrieve();
					if(l.IsPersistent)
					{
						Common.SelectFlg(this.ddlWare,l.WarehouseId);
						this.BindLocation();
						Common.SelectFlg(this.ddlLoc,l.Id);
						this.txtOrder.Text = ml.Order.ToString();
//						if(ml.Order==1)
//							this.txtOrder.Enabled=false;
//						else
//							this.txtOrder.Enabled=true;
						this.txtId.Text = ml.Id;
					}
					this.tableLocation.Visible=true;
				}
			}
		}

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string id=this.txtId.Text.Trim();
			string o=this.txtOrder.Text.Trim();
			if(o=="")
				o=(this.grid.Items.Count +1).ToString();
			ProductLocation pl=new ProductLocation();
			if(id=="")
			{
				
				pl.Id=LoginSystem.GetTableId("ProductLocation").ToString();
				pl.LocationId=this.ddlLoc.SelectedItem.Value;
				pl.ProductId=this.ViewState["ID"].ToString();
				pl.Order=int.Parse(o);

			}
			else
			{

				pl.Id=id;
				pl.Retrieve();
				pl.LocationId=this.ddlLoc.SelectedItem.Value;
				pl.ProductId=this.ViewState["ID"].ToString();
				pl.Order=int.Parse(o);
			}

			try
			{
				pl.Save();
			}
			catch
			{
				this.lblMessage.Text="失败:在保存时遇到错误";
				this.lblMessage.Visible=true;
				return;
			}

			this.lblMessage.Text="成功:添加/修改 存放库位成功";
			this.lblMessage.Visible=true;
			this.BindGrid();

		}

		private void Button3_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("ProductLocationWeb.aspx");
			Response.End();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -