?? kjkm_mod.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_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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -