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

📄 checkticketadd.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;

namespace Botheighten.Yanghui.Web
{
	/// <summary>
	/// CheckTicketAdd 的摘要说明。
	/// </summary>
	public class CheckTicketAdd : BasePage
	{
		protected System.Web.UI.WebControls.Label lblTitle;
		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.ValidationSummary ErrorSummary;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.TextBox txtRemark;
		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 btnGoBack;
		protected System.Web.UI.WebControls.Label lblMessage;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.DropDownList ddlLineId;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.DropDownList ddlInstructionId;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.DropDownList ddlPCode;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.TextBox txtQuantity;
		protected System.Web.UI.WebControls.Label Label10;
		protected System.Web.UI.WebControls.Label Label11;
		protected System.Web.UI.WebControls.TextBox txtBoxUnit;
		protected System.Web.UI.WebControls.TextBox txtBoxs;
		protected System.Web.UI.WebControls.TextBox txtOther;
		protected System.Web.UI.WebControls.CheckBox chkTodayOut;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator3;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator4;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.TextBox txtPeriod;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator6;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
		protected System.Web.UI.WebControls.RangeValidator RangeQ;
		protected System.Web.UI.HtmlControls.HtmlTable tableMod;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			Principal p=this.CurrentUser();
			this.CheckPermissionPage(p.Id,"","601");
			this.ReponseWriteDeleteScript ();
			this.lblMessage.Visible=false;
			//			btnDelete.Attributes.Add("onClick","javascript:return confirm('确定要删除此记录吗?');");
			//btnDelAll.Attributes.Add("onClick",@"javascript:return confirm('警告:确定要删除本页所有记录吗? \n 删除本页记录可能会误删除一些记录,请谨慎操作!');");
			if(!Page.IsPostBack)
			{
				//				if(p.IsSuper=="Y" && p.Id.Trim().ToLower()=="admin")
				//					this.btnDelAll.Visible=true;
				//				else
				//					this.btnDelAll.Visible=false;

				this.txtCode.Text = "c"+UniqueSerialGenerator.GetSerialNo();

				DataTable dtLine=LineSystem.AllLine("Y");
				Common.BindDrop(this.ddlLineId,dtLine,Line.CODE,Line.ID);

				this.BindInstruction();
				this.BindBomCode();
				this.BindPQ();

				this.lblInsertDate.Text = System.DateTime.Now.ToString();
				this.lblInsertOperater.Text = this.CurrentUser().Id;

			}

		}

		private void BindInstruction()
		{
			string lineid="";
			if(this.ddlLineId.Items.Count>0)
                lineid=this.ddlLineId.SelectedItem.Value;
		
			string[] flags=new String[]{"T","B"};
			DataTable dtInstruction=InstructionSystem.GetInstruction("","",lineid,"","",flags);
			Common.BindDrop(this.ddlInstructionId,dtInstruction,Instruction.SERIALNO,Instruction.ID);

		}

		private void BindBomCode()
		{
			string iid="";
			if(this.ddlInstructionId.Items.Count>0)
				iid=this.ddlInstructionId.SelectedItem.Value;
			DataTable dtBomCode=InstructionSystem.AllInstructionLine(iid);
			//Common.BindDrop(this.ddlPCode,dtBomCode,InstructionLine.BOMCODE,InstructionLine.ID);
			DropDownList lc=this.ddlPCode;
			lc.Items.Clear();
			foreach(DataRow myRow in dtBomCode.Rows)
			{
				lc.Items.Add(new ListItem(myRow[InstructionLine.BOMCODE].ToString(),myRow[InstructionLine.ID].ToString()));
				//lc.Items.Add(new ListItem(myRow[InstructionLine.BOMCODE].ToString(),myRow[InstructionLine.ID].ToString()));
			}
			lc.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.ddlLineId.SelectedIndexChanged += new System.EventHandler(this.ddlLineId_SelectedIndexChanged);
			this.ddlInstructionId.SelectedIndexChanged += new System.EventHandler(this.ddlInstructionId_SelectedIndexChanged);
			this.ddlPCode.SelectedIndexChanged += new System.EventHandler(this.ddlPCode_SelectedIndexChanged);
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_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,"失败:备注只允许250个字符之内",250)) return;
			CheckTicket ct=new CheckTicket();
			BindAttribute(ct);
			if(ct.Id=="")
				ct.Id=LoginSystem.GetTableId("CheckTicket").ToString();
			
			if(!ProductSystem.CheckCheckTicketIsUnique(ct))
			{
				this.lblMessage.Text ="失败:送检单编号已经存在,请确保唯一";
				this.lblMessage.Visible=true;
			}
			else
			{
				try
				{
					ct.Save();
					this.ChangeInstructionFlag();
				}
				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.btnAdd.Visible=false;

				//				this.InitAdd();
			}

			//Response.Redirect("CheckTicketAdd2.aspx",true);
		}

		private void ChangeInstructionFlag()
		{
			InstructionLine il=new InstructionLine();
			il.Id=this.ddlPCode.SelectedItem.Value;
			il.Retrieve();
			Instruction i=new Instruction();
			i.Id=il.InstructionId;
			i.Retrieve();
			if(i.IsPersistent)
			{
				if(InstructionSystem.IsCheckSendAll(i.Id))
                    i.Flag="C";
				else
					i.Flag="B";
				i.Save();

//				Order o=new Order();
//				o.Id=il.OrderId;
//				o.Retrieve();
//				if(o.IsPersistent)
//				{
//					o.CompleteQuantity+=il.Quantity;
//					o.Save();
//				}
			}
		}

		private void BindAttribute(CheckTicket ct)
		{
			ct.Id="";
			ct.Code=this.txtCode.Text.Trim();
			ct.LineId=this.ddlLineId.SelectedItem.Value;
			ct.BOMCode=this.ddlPCode.SelectedItem.Text;
			InstructionLine il=new InstructionLine();
			il.Id=this.ddlPCode.SelectedItem.Value;
			il.Retrieve();
			if(il.IsPersistent)
				ct.OrderHeadId=il.OrderHeadId;
			else
				ct.OrderHeadId="";
			
			ct.Quantity=int.Parse(this.txtQuantity.Text.Trim());
			ct.InstructionId=this.ddlInstructionId.SelectedItem.Value;
			ct.Period=this.txtPeriod.Text.Trim();
			ct.Boxs=int.Parse(this.txtBoxs.Text.Trim());
			ct.BoxUnit=int.Parse(this.txtBoxUnit.Text.Trim());
			string other=this.txtOther.Text.Trim();
			if(other!="")
				ct.Other=int.Parse(other);
			else
				ct.Other=0;
			ct.TodayOut=this.chkTodayOut.Checked?"Y":"N";
			ct.InsertDate=System.DateTime.Now;
			ct.InsertOperater=this.CurrentUser().Id;
			ct.Flag="N";
			ct.Remark=this.txtRemark.Text;
			ct.CheckDate=new DateTime(1900,1,1);
			ct.InDate=new DateTime(1900,1,1);
			
		}

		private void btnGoBack_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("CheckTicketWeb.aspx",true);
		}

		private void ddlLineId_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.BindInstruction();
			this.BindBomCode();
		}

		private void ddlInstructionId_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.BindBomCode();
		}

		private void ddlPCode_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.BindPQ();

		}

		private void BindPQ()
		{
			InstructionLine il=new InstructionLine();
			if(this.ddlPCode.Items.Count>0)
			{
				il.Id=this.ddlPCode.SelectedItem.Value;
			
			il.Retrieve();
			if(il.IsPersistent)
			{
				this.txtQuantity.Text = il.Quantity.ToString();
				this.RangeQ.MaximumValue=il.Quantity.ToString();

			}

			else
			{
				this.txtQuantity.Text ="";
				this.RangeQ.MaximumValue="0";
			}
			}
		}
	}
}

⌨️ 快捷键说明

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