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

📄 pzmx_add.aspx.cs

📁 ASP.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 System.Data.SqlClient;
using com.unicafe.ui;
using com.unicafe.common;
using com.unicafe.security;
using com.ascs.plp.common;
using com.ascs.plp.publics;

namespace PLP.CWZZ.PZGL
{
	/// <summary>
	/// PZMX_ADD 的摘要说明。
	/// </summary>
	public class PZMX_ADD : com.unicafe.ui.UnicafePage
	{
		protected System.Web.UI.WebControls.DropDownList DDL_WLHLX;
		SqlConnection cn = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
		Com.Ascs.Plp.CW.CW_PZXM CW_PZXM = new Com.Ascs.Plp.CW.CW_PZXM();
		protected System.Web.UI.WebControls.TextBox KJKM;
		protected System.Web.UI.WebControls.TextBox TextChange;
		protected System.Web.UI.WebControls.DropDownList gsyg;
		protected System.Web.UI.WebControls.DropDownList wlh;
		protected System.Web.UI.WebControls.DropDownList gsbm;
		Com.Ascs.Plp.CW.CW_PZXMMgr CW_PZXMMgr = new Com.Ascs.Plp.CW.CW_PZXMMgr();
		protected System.Web.UI.WebControls.LinkButton datacheck;
		protected System.Web.UI.WebControls.TextBox KMMC;
		protected System.Web.UI.WebControls.TextBox jfje;
		protected System.Web.UI.WebControls.TextBox dfje;
		protected System.Web.UI.WebControls.TextBox zy;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator1;
		protected System.Web.UI.WebControls.RangeValidator RangeValidator2;
		Com.Ascs.Plp.CW.CW_PZMgr CW_PZMgr = new Com.Ascs.Plp.CW.CW_PZMgr();
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				// 在此处放置用户代码以初始化页面
				this.VerifyPage();                            //登录检查
				this.VerifyPage("zz_pzgl_mgr");
				ViewState["JGDM"]=this.CurrentJGXX.JGDM;
				ViewState["KJND"]=this.Request.QueryString["KJND"];
				ViewState["CD"]=this.CW_PZXMMgr.GetYJKMCD();

				if (!this.IsPostBack)  //判断第一次显示
				{
					this.DDLBind();
				}
			}
			catch(Exception e1)
			{
				LogService.Write ("显示会计凭证细目时产生异常。");
				LogService.Write (e1.Message);
				Prompt.PromptError(this,"显示会计凭证细目时产生异常。");
			}
		}

		#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.DDL_WLHLX.SelectedIndexChanged += new System.EventHandler(this.DDL_WLHLX_SelectedIndexChanged);
			this.datacheck.Click += new System.EventHandler(this.datacheck_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void DDL_WLHLX_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			try
			{
				string sql=string.Empty;
				DataTable dt;
				switch(this.DDL_WLHLX.SelectedItem.Value)
				{
					case "0":
						this.wlh.Items.Clear();
						this.wlh.Items.Insert(0,new ListItem("请选择",""));
						break;
					case "1":
						sql=string.Format("select KHDM,KHMC from KHXX where JGDM='{0}'",ViewState["JGDM"].ToString());
						dt=this.CW_PZMgr.CreateDataTableFromSql(sql);
						if(dt.Rows.Count>0)
						{
							this.wlh.DataSource=dt;
							this.wlh.DataTextField="KHMC";
							this.wlh.DataValueField="KHDM";
							this.wlh.DataBind();
							this.wlh.Items.Insert(0,new ListItem("请选择",""));
						}
						break;
					case "2":
						sql=string.Format("select GYSDM,GYSMC from GYSXX where JGDM='{0}'",ViewState["JGDM"].ToString());
						dt=this.CW_PZMgr.CreateDataTableFromSql(sql);
						if(dt.Rows.Count>0)
						{
							this.wlh.DataSource=dt;
							this.wlh.DataTextField="GYSMC";
							this.wlh.DataValueField="GYSDM";
							this.wlh.DataBind();
							this.wlh.Items.Insert(0,new ListItem("请选择",""));
						}
						break;
					case "3":
						sql=string.Format("select JGDM,JGMC from JGXX");
						dt=this.CW_PZMgr.CreateDataTableFromSql(sql);
						if(dt.Rows.Count>0)
						{
							this.wlh.DataSource=dt;
							this.wlh.DataTextField="JGMC";
							this.wlh.DataValueField="JGDM";
							this.wlh.DataBind();
							this.wlh.Items.Insert(0,new ListItem("请选择",""));
						}
						break;
				}
			}
			catch(Exception e1)
			{
				LogService.Write ("选择往来户类型时产生异常。");
				LogService.Write (e1.Message);
				Prompt.PromptError(this,"选择往来户类型时产生异常。");
			}
		}

		private void DDLBind()
		{
			string sql=string.Empty;
			sql=string.Format("select DeptID,DeptName from Departments where JGDM='{0}' or DeptID='0'",ViewState["JGDM"].ToString());
			DataTable dt=this.CW_PZMgr.CreateDataTableFromSql(sql);
			if(dt.Rows.Count>0)
			{
				this.gsbm.DataSource=dt;
				this.gsbm.DataTextField="DeptName";
				this.gsbm.DataValueField="DeptID";
				this.gsbm.DataBind();
				this.gsbm.Items.Insert(0,new ListItem("请选择",""));
			}

			sql=string.Format("SELECT Employees.EmplID,Employees.EmplNameL + Employees.EmplNameF AS EmplNameL,Departments.JGDM, Employees.EmplEnabled FROM Employees INNER JOIN EmplDept ON Employees.EmplID = EmplDept.EmplID INNER JOIN Departments ON EmplDept.DeptID = Departments.DeptID where EmplEnabled='1'and JGDM='{0}'",ViewState["JGDM"].ToString());
			DataTable dt1=this.CW_PZMgr.CreateDataTableFromSql(sql);
			if(dt1.Rows.Count>0)
			{
				this.gsyg.DataSource=dt1;
				this.gsyg.DataTextField="EmplNameL";
				this.gsyg.DataValueField="EmplID";
				this.gsyg.DataBind();
				this.gsyg.Items.Insert(0,new ListItem("请选择",""));
			}
		}

		private void datacheck_Click(object sender, System.EventArgs e)
		{
			try
			{
				//需要增加数据检测
				try
				{
					ViewState["PZBH"]=this.Request.QueryString["PZBH"];
					ViewState["KJND"]=this.Request.QueryString["KJND"];
					this.CW_PZXM.PZBH=this.Request.QueryString["PZBH"];
					this.CW_PZXM.KJND=this.Request.QueryString["KJND"];
					this.CW_PZXM.KJQJ=this.Request.QueryString["KJQJBH"];
					this.CW_PZXM.JGDM=this.Request.QueryString["JGDM"];
					CW_PZXM.ZY = Request.Form["zy"];
					this.CW_PZXM.KJKM=Request.Form["KMMC"];
					string sReturn=this.CHECKKJKM(this.CW_PZXM.KJND,this.CW_PZXM.KJKM,this.gsbm.SelectedIndex,this.gsyg.SelectedIndex,this.wlh.SelectedIndex,this.DDL_WLHLX.SelectedIndex);
					if(sReturn!=string.Empty)
					{
						this.Response.Write("<script>alert('"+sReturn+"')</script>");
						return;
					}
					if(this.gsbm.SelectedIndex>-1)
					{
						CW_PZXM.BMBH=this.gsbm.SelectedItem.Value;
					}
					else
					{
						CW_PZXM.BMBH=string.Empty;
					}
					if(this.gsyg.SelectedIndex>-1)
					{
						CW_PZXM.YGBH=this.gsyg.SelectedItem.Value;
					}
					else
					{
						CW_PZXM.BMBH=string.Empty;
					}
					if(this.wlh.SelectedIndex>-1)
					{
						CW_PZXM.WLHBM = this.wlh.SelectedItem.Value;
					}
					else
					{
						CW_PZXM.WLHBM=string.Empty;
					}
					if(this.DDL_WLHLX.SelectedIndex>-1)
					{
						CW_PZXM.WLHLX = this.DDL_WLHLX.SelectedItem.Value;
					}
					else
					{
						CW_PZXM.WLHLX=string.Empty;
					}
				
					if(Request.Form["jfje"]!=string.Empty)
					{
						CW_PZXM.JFJE= Convert.ToDecimal(Request.Form["jfje"]);
					}
					else
					{
						CW_PZXM.JFJE=0;
					}
					if(Request.Form["dfje"]!=string.Empty)
					{
						CW_PZXM.DFJE= Convert.ToDecimal(Request.Form["dfje"]);
					}
					else
					{
						CW_PZXM.DFJE=0;
					}
				}
				catch(Exception Err)
				{
					LogService.Write(Err.Message);
					this.Response.Redirect("../../Publics/Error.aspx?errmsg=未能获取凭证细目的完整信息。");  
					return;
				}
				
				cn.Open();
											
				//新增会计科目
				SqlCommand mySqlCommandXM = new SqlCommand();
				mySqlCommandXM.Connection=cn;
				SqlTransaction myTransXM = this.cn.BeginTransaction();//建立事务
				mySqlCommandXM.Transaction = myTransXM;//绑定事务
				if (CW_PZXMMgr.AddCW_PZXM(mySqlCommandXM,CW_PZXM))
				{
					myTransXM.Commit();
					this.MODKJKM_SYBJ(this.CW_PZXM.KJND,this.CW_PZXM.KJKM);
					string ReturnURL =PLP.CWZZ.PZGL.PZMX_ADD.PZXMADD_CreatReturnURL(this,CW_PZXM);
					Response.Write("<script language=javascript>window.opener.location='" + ReturnURL + 	"';window.close();</script>");
				
				}
				else	
				{
					myTransXM.Rollback();
					//使用时将下面代码中的"MainModel_1.aspx"改到特定页面的打开页面的URL
					Response.Write("<script language=javascript>window.opener.location='../../Publics/Error.aspx?errmsg=凭证细目没有增加成功。';window.close();</script>");  
							
				}

				cn.Close();
			}
			catch(Exception e1)
			{
				LogService.Write ("添加会计凭证细目时产生异常。");
				LogService.Write (e1.Message);
				Prompt.PromptError(this,"添加会计凭证细目时产生异常。");
			}
		}

		private void MODKJKM_SYBJ(string KJND,string KJKM)
		{ 
			//cn.Open();
			Com.Ascs.Plp.CW.CW_KJKM CW_KJKM=new Com.Ascs.Plp.CW.CW_KJKM();
			Com.Ascs.Plp.CW.CW_KJKMMgr CW_KJKMMgr=new Com.Ascs.Plp.CW.CW_KJKMMgr();
			CW_KJKM=CW_KJKMMgr.GetCW_KJKM(KJND,KJKM);
			CW_KJKM.SFYJSY="1";
			CW_KJKMMgr.UpdateCW_KJKM(cn,CW_KJKM);
			//cn.Close();
		}

		private string CHECKKJKM(string KJND,string KJKM,int BMBM,int YGBM,int WLHBM,int WLHLX)
		{
			string sReturn=string.Empty;
			string sql=string.Format("select * from CW_KJKM where KJND='{0}' and KMBM='{1}' and TYBJ='0' and SFMX='1'",KJND,KJKM);
			DataTable dt=this.CW_PZMgr.CreateDataTableFromSql(sql);
			if(dt.Rows.Count==1)
			{
				if(dt.Rows[0]["SFBMHS"].ToString()=="1"&&BMBM<1)
				{
					sReturn="该科目部门核算,请选择部门!";
				}
				else if(dt.Rows[0]["SFBMHS"].ToString()=="0"&&BMBM>0)
				{
					sReturn="该科目没有部门核算,请不要选择部门!";
					this.gsbm.SelectedIndex=0;
				}
				if(dt.Rows[0]["SFYGHS"].ToString()=="1"&&YGBM<1)
				{
					sReturn+="该科目员工核算,请选择员工!";
				}
				else if(dt.Rows[0]["SFYGHS"].ToString()=="0"&&YGBM>0)
				{
					sReturn+="该科目没有员工核算,请不要选择员工!";
					this.gsyg.SelectedIndex=0;
				}
				if(dt.Rows[0]["SFWLHHS"].ToString()=="1"&&WLHBM<1)
				{
					sReturn+="该科目往来户核算,请选择往来户!";
				}
				else if(dt.Rows[0]["SFWLHHS"].ToString()=="0")
				{
					if(WLHBM>0||WLHLX>0)
					{
						sReturn+="该科目没有往来户核算,请不要选择往来户!";
						this.DDL_WLHLX.SelectedIndex=0;
						this.wlh.SelectedIndex=0;
					}
				}
			}
			else
			{
				sReturn="科目编码书写有误请重新填写!原因有可能是:1.该科目不存在。2.该科目不是末级科目。3.该科目已经停用。";
			}
			return sReturn;
		}

		public static string PZXMADD_CreatReturnURL(System.Web.UI.Page thePage,Com.Ascs.Plp.CW.CW_PZXM CW_PZXM)
		{
			//获取父页面的当前页索引
			string PageIndex = thePage.Request.QueryString["PageIndex"];
			//获取父页面的URL
			string ParentURL = thePage.Request.QueryString["ParentURL"];

			ParentURL = string.Format("{0}?PageIndex={1}&JGDM={2}&KJQJ={3}&KJND={4}&PZBH={5}",ParentURL,PageIndex,CW_PZXM.JGDM,CW_PZXM.KJQJ,CW_PZXM.KJND,CW_PZXM.PZBH);
			return ParentURL;
		}
	}
}

⌨️ 快捷键说明

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