📄 kjkm_add.aspx.cs
字号:
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_ADD 的摘要说明。
/// </summary>
public class KJKM_ADD : com.unicafe.ui.UnicafePage
{
protected System.Web.UI.WebControls.TextBox kmmc;
protected System.Web.UI.WebControls.DropDownList DDL_KMLB;
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.CheckBox CheckBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox SJKM;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.TextBox KMBM;
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)
{
ViewState["SJKM"] = SJKM.Text;
Label1.Text = this.Request.QueryString["KJND"];
}
else
{
if(ViewState["SJKM"].ToString() != SJKM.Text && this.Request.Form["__EVENTTARGET"] == "")
{
//说明会计科目已经修改,是会计科目回发带来的操作
ViewState["SJKM"] = SJKM.Text;
CommonService.LocateDropDownList(DDL_KMLB, GetType(Label1.Text, SJKM.Text));
//确定要新增的会计科目的长度
KMBM.MaxLength = GetLength(Label1.Text, SJKM.Text);
if(KMBM.Text.Length > KMBM.MaxLength)
{
KMBM.Text = KMBM.Text.Substring(0,KMBM.MaxLength);
}
}
}
}
#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.CheckBox1.CheckedChanged += new System.EventHandler(this.CheckBox1_CheckedChanged);
this.LinkButton1.Click += new System.EventHandler(this.LinkButton1_Click);
this.ID = "KJKM_ADD";
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据是否有上级科目决定该科目的长度
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// **************************************************************************
private void CheckBox1_CheckedChanged(object sender, System.EventArgs e)
{
ViewState["SJKM"] = SJKM.Text;
if(CheckBox1.Checked == true)
{
SJKM.Text = "";
}
else
{
SJKM.Text = "0";
//确定要新增的会计科目的长度
KMBM.MaxLength = GetLength(Label1.Text, SJKM.Text);
if(KMBM.Text.Length > KMBM.MaxLength)
{
KMBM.Text = KMBM.Text.Substring(0,KMBM.MaxLength);
}
}
}
/// **************************************************************************
/// END
/// **************************************************************************
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据上级科目获取科目级别长度
/// </summary>
/// <returns></returns>
/// **************************************************************************
private int GetLength(string KJND, string SJKM)
{
string sql;
if(SJKM == "0")
{
sql = "Select CD From CW_KJKMJB Where KMJB = 1";
}
else
{
sql = "Select Sum(CD) From CW_KJKMJB Where KMJB<=((Select KMJB From CW_KJKM Where KJND='" + KJND + "' And KMBM='" + SJKM + "')+1)";
}
return int.Parse(CommonService.ExecQuery(sql,3).ToString());
}
/// **************************************************************************
/// END
/// **************************************************************************
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据会计年度和上级科目编码获取科目级别
/// </summary>
/// <param name="KJND">会计年度</param>
/// <param name="SJKMBM">上级科目编码</param>
/// <returns>科目级别</returns>
/// **************************************************************************
private int GetLevel(string KJND, string SJKMBM)
{
string sql;
if(SJKMBM == "0")
{
return 1;
}
else
{
sql = "Select KMJB+1 From CW_KJKM Where KJND = '" + KJND + "' And KMBM = '" + SJKMBM + "'";
return int.Parse(CommonService.ExecQuery(sql,3).ToString());
}
}
/// **************************************************************************
/// END
/// **************************************************************************
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据会计年度和上级科目编码获取科目类别
/// </summary>
/// <param name="KJND"></param>
/// <param name="SJKMBM"></param>
/// <returns></returns>
/// **************************************************************************
private string GetType(string KJND, string SJKMBM)
{
string sql;
sql = "Select LB From CW_KJKM Where KJND = '" + KJND + "' And KMBM = '" + SJKMBM + "'";
return CommonService.ExecQuery(sql, 3).ToString();
}
/// **************************************************************************
/// END
/// **************************************************************************
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 执行添加方法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// **************************************************************************
private void LinkButton1_Click(object sender, System.EventArgs e)
{
try
{
thisKJKM.KJND = Label1.Text;
thisKJKM.KMBM = KMBM.Text;
thisKJKM.KMMC = kmmc.Text;
thisKJKM.SJKMBM = SJKM.Text;
thisKJKM.LB = DDL_KMLB.SelectedItem.Value;
thisKJKM.KMFX = DDL_KMFX.SelectedItem.Value;
thisKJKM.KMJB = GetLevel(thisKJKM.KJND, thisKJKM.SJKMBM);
thisKJKM.SFMX = DDL_SFMX.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.TYBJ = "0";
thisKJKM.SFYJSY = "0";
//检查会计科目对象的合法性
Prompt prt = new Prompt();
prt = ValidCheck(thisKJKM);
//根据检查结果进行不同处理
if(prt.Flag !=1 && prt.Flag != 2)
{
prt.ShowPrompt(this);
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.AddCW_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></returns>
/// **************************************************************************
private Prompt ValidCheck(Com.Ascs.Plp.CW.CW_KJKM KJKM)
{
Prompt result = new Prompt();
result.Flag = 1;
result.Info = "Success";
//检查项一:必须保证会计科目长度与其级别对应
if (GetLength(KJKM.KJND, KJKM.SJKMBM) != KJKM.KMBM.Trim().Length)
{
result.Flag = 3;
result.Info = "该会计科目的长度与它的级别不对应。<br>未通过合法性检查。";
return result;
}
//检查项二:除一级科目外,其它科目必须与其上级科目之间有编号上的包含关系
if (KJKM.KMJB != 1 && KJKM.KMBM.IndexOf(KJKM.SJKMBM) != 0)
{
result.Flag = 3;
result.Info = "该会计科目的科目编码与它的上级科目不对应。<br>未通过合法性检查。";
return result;
}
//检查项三:上级科目必须不能是末级科目
if (KJKM.SJKMBM != "0" && thisKJKMMgr.GetCW_KJKM(KJKM.KJND, KJKM.SJKMBM).SFMX != "0")
{
result.Flag = 3;
result.Info = "该会计科目的上级科目是末级科目。<br>未通过合法性检查。";
return result;
}
//检查项四:科目类别必须是会计科目的第一个字符
if (KJKM.KMBM.IndexOf(KJKM.LB) != 0)
{
result.Flag = 3;
result.Info = "该会计科目不属于选取的科目类型。<br>未通过合法性检查。";
return result;
}
//检查项五:没有重复记录
if (thisKJKMMgr.GetCW_KJKM(KJKM.KJND, KJKM.KMBM) != null)
{
result.Flag = 3;
result.Info = "已经存在相同科目编码的会计科目。<br>未通过合法性检查。";
return result;
}
//检查项目六:会计科目名称有没有重复
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 KMMC=@KMMC";
SqlCmd.CommandText = sql;
SqlCmd.Parameters.Clear();
SqlCmd.Parameters.Add("@KJND",KJKM.KJND);
SqlCmd.Parameters.Add("@KMMC",KJKM.KMMC.Trim());
if(int.Parse(CommonService.ExecQuery(SqlCmd,3).ToString()) != 0)
{
result.Flag = 3;
result.Info = "已经存在相同科目名称的会计科目。<br>未通过合法性检查。";
return result;
}
return result;
}
/// **************************************************************************
/// END
/// **************************************************************************
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -