kjkm_mod.aspx.cs

来自「企业管理信息化之财务管理系统」· CS 代码 · 共 276 行

CS
276
字号
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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 com.unicafe.ui;
using com.unicafe.common;
using com.unicafe.security;
using com.ascs.plp.common;
using com.ascs.plp.cg;
using com.ascs.plp.publics;
using Com.Ascs.Plp.CW;
using Com.Ascs.Plp.Cw.Publics;


namespace PLP.CWZZ.KJKM
{
	/// <summary>
	/// KJKM_MOD 的摘要说明。
	/// </summary>
	public class KJKM_MOD : com.unicafe.ui.UnicafePage
	{
		protected System.Web.UI.WebControls.TextBox KMMC;
		protected System.Web.UI.WebControls.DropDownList DDL_KMFX;
		protected System.Web.UI.WebControls.DropDownList DDL_SFXJ;
		protected System.Web.UI.WebControls.DropDownList DDL_SFBM;
		protected System.Web.UI.WebControls.DropDownList DDL_SFYG;
		protected System.Web.UI.WebControls.DropDownList DDL_SFWL;
		protected System.Web.UI.WebControls.DropDownList DDL_SFMX;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.LinkButton LinkButton1;
		Com.Ascs.Plp.CW.CW_KJKM thisKJKM = new CW_KJKM();
		Com.Ascs.Plp.CW.CW_KJKMMgr thisKJKMMgr = new CW_KJKMMgr();

		private void Page_Load(object sender, System.EventArgs e)
		{
			this.VerifyPage();
			this.VerifyPage("zt_kjkm_mgr");
			if(!this.IsPostBack)
			{
				//根据父页面获取要修改的会计科目的主关键字
				string[] pks = CommonService.GetCurrentPks(this);
				thisKJKM.KJND = pks[0];
				thisKJKM.KMBM = pks[1];

				//给页面上各控件赋初值
				thisKJKM = thisKJKMMgr.GetCW_KJKM(thisKJKM.KJND, thisKJKM.KMBM);
				Label1.Text = thisKJKM.KJND;
				Label2.Text = (thisKJKM.SJKMBM=="0"? "无":thisKJKM.SJKMBM);
				Label3.Text = thisKJKM.KMBM;
				Label4.Text = ConvertType(thisKJKM.LB);
				KMMC.Text = thisKJKM.KMMC;
				CommonService.LocateDropDownList(DDL_KMFX, thisKJKM.KMFX);
				CommonService.LocateDropDownList(DDL_SFXJ, thisKJKM.SFXJHS);
				CommonService.LocateDropDownList(DDL_SFBM, thisKJKM.SFBMHS);
				CommonService.LocateDropDownList(DDL_SFYG, thisKJKM.SFYGHS);
				CommonService.LocateDropDownList(DDL_SFWL, thisKJKM.SFWLHHS);
				CommonService.LocateDropDownList(DDL_SFMX, thisKJKM.SFMX);
			}
		}


		#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.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
			this.ID = "KJKM_MOD";
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

	
	

		/// **************************************************************************
		/// BEIGIN
		/// <summary>
		/// 执行修改方法
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// **************************************************************************
		private void LinkButton1_Click(object sender, System.EventArgs e)
		{
			try
			{
				string[] pks = CommonService.GetCurrentPks(this);
				thisKJKM.KJND = pks[0];
				thisKJKM.KMBM = pks[1];

				thisKJKM = thisKJKMMgr.GetCW_KJKM(thisKJKM.KJND, thisKJKM.KMBM);

				thisKJKM.KMMC = KMMC.Text;
				thisKJKM.KMFX = DDL_KMFX.SelectedItem.Value;
				thisKJKM.SFXJHS = DDL_SFXJ.SelectedItem.Value;
				thisKJKM.SFBMHS = DDL_SFBM.SelectedItem.Value;
				thisKJKM.SFYGHS = DDL_SFYG.SelectedItem.Value;
				thisKJKM.SFWLHHS = DDL_SFWL.SelectedItem.Value;
				thisKJKM.SFMX = DDL_SFMX.SelectedItem.Value;
				
				//检查会计科目对象的合法性
				Prompt prt = new Prompt();
				prt = ValidCheck(thisKJKM);
					prt.ShowPrompt(this);
				
				//根据检查结果进行不同处理
				if(prt.Flag !=1 && prt.Flag != 2)
				{
					return;
				}
				else
				{
					//定义SqlConnection, SqlCommand, Transaction等对象
					SqlConnection SqlCn = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
					SqlCn.Open();
					//开始事务
					SqlTransaction SqlTrans = SqlCn.BeginTransaction();
					SqlCommand cmd = SqlCn.CreateCommand();
					cmd.Transaction = SqlTrans;
				
					//执行向会计科目表的修改操作
					if(thisKJKMMgr.UpdateCW_KJKM(cmd, thisKJKM) == false)
					{
						SqlTrans.Rollback();
						SqlCn.Close();
						Prompt.PromptError(this, "修改会计科目时产生异常。");
						return;
					}
					else
					{
						//如果全部成功,先提交,然后给出成功提示
						SqlTrans.Commit();
						Prompt.PromptMessage(this, "会计科目修改成功!");

						//成功后将会计年度和科目类别写入Session并刷新父页面
						this.Session["KJND"] = thisKJKM.KJND;
						this.Session["KMLX"] = thisKJKM.LB;

						CommonService.Return(this);
					}
				}
			}
			catch(Exception e1)
			{
				LogService.Write ("修改会计科目时产生异常。");
				LogService.Write (e1.Message);
				Prompt.PromptError(this,"修改会计科目时产生异常。");
			}
		}
		/// **************************************************************************
		/// END
		/// **************************************************************************






		/// **************************************************************************
		/// BEIGIN
		/// <summary>
		/// 数据有效性检查
		/// </summary>
		/// <param name="KJKM">待检查的会计科目</param>
		/// <returns>Prompt信息提示对象</returns>
		/// **************************************************************************
		private Prompt ValidCheck(Com.Ascs.Plp.CW.CW_KJKM KJKM)
		{
			Prompt result = new Prompt();
			result.Flag = 1;
			result.Info = "Success";

			SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());	
			System.Data.SqlClient.SqlCommand SqlCmd = Connection.CreateCommand();

			//检查项目一:会计科目名称有没有重复
			//给SqlCommand对象指定到某个SQL语句
			string sql = "Select Count(*) From CW_KJKM Where KJND=@KJND And Not KMBM=@KMBM And KMMC=@KMMC";
			SqlCmd.CommandText = sql;
			SqlCmd.Parameters.Clear();
			SqlCmd.Parameters.Add("@KJND",KJKM.KJND);
			SqlCmd.Parameters.Add("@KMBM",KJKM.KMBM);
			SqlCmd.Parameters.Add("@KMMC",KJKM.KMMC.Trim());
			if(int.Parse(CommonService.ExecQuery(SqlCmd,3).ToString()) != 0)
			{
				result.Flag = 3;
				result.Info = "已经存在相同科目名称的会计科目。<br>未通过合法性检查。";
				return result;
			}

			//检查项目二:修改后的会计科目如果是末级科目,则不能有下级科目
			if(KJKM.SFMX == "1")
			{
				sql = "Select Count(*) From CW_KJKM Where KJND=@KJND And SJKMBM=@SJKMBM";
				SqlCmd.CommandText = sql;
				SqlCmd.Parameters.Clear();
				SqlCmd.Parameters.Add("@KJND",KJKM.KJND);
				SqlCmd.Parameters.Add("@SJKMBM",KJKM.KMBM);
				if(int.Parse(CommonService.ExecQuery(SqlCmd,3).ToString()) != 0)
				{
					result.Flag = 3;
					result.Info = "该会计科目已经存在下级科目,而已经有下级科目的会计科目不能设置为末级科目。<br>未通过合法性检查。";
					return result;
				}
			}
			return result;
		}
		/// **************************************************************************
		/// END
		/// **************************************************************************



		
		/// **************************************************************************
		/// BEIGIN
		/// <summary>
		/// 将科目类别代码转换成文字描述
		/// </summary>
		/// <param name="obj"></param>
		/// <returns></returns>
		/// **************************************************************************
		public string ConvertType(string LB)
		{
			string sReturn=string.Empty;
			switch(LB)
			{
				case "1":
					sReturn="资产";
					break;
				case "2":
					sReturn="负债";
					break;
				case "3":
					sReturn="权益";
					break;
				case "4":
					sReturn="成本";
					break;
				case "5":
					sReturn="损益";
					break;
			}
			return sReturn;
		}
		/// **************************************************************************
		/// END
		/// **************************************************************************


	}
}

⌨️ 快捷键说明

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