41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System.Data.Common;
|
||
using WebLib;
|
||
|
||
namespace 報到系統
|
||
{
|
||
/// <summary>
|
||
/// BWEX 系統設定資料存取類別
|
||
/// </summary>
|
||
public class DAC_BWEX : DAC
|
||
{
|
||
public DAC_BWEX() : base() { }
|
||
|
||
public DAC_BWEX(DbConnection conn) : base(conn) { }
|
||
|
||
/// <summary>依 KeyName 取得 KeyValue</summary>
|
||
public string GetKeyValue(string keyName)
|
||
{
|
||
DbCommand cmd = NewCommand();
|
||
cmd.CommandText = "select [BSNAM] from [BWEX] where [BSNUM] = @KeyName and [BSITM] = ' 1'";
|
||
AddParam(cmd, "KeyName", keyName);
|
||
string result;
|
||
ExecuteScalar(cmd, out result);
|
||
return result;
|
||
}
|
||
|
||
/// <summary>更新 KeyValue(若不存在則 INSERT)</summary>
|
||
public void SetKeyValue(string keyName, string keyValue)
|
||
{
|
||
DbCommand cmd = NewCommand();
|
||
cmd.CommandText =
|
||
"if exists (select 1 from [BWEX] where [BSNUM] = @KeyName and [BSITM] = ' 1') " +
|
||
" update [BWEX] set [BSNAM] = @KeyValue where [BSNUM] = @KeyName and [BSITM] = ' 1'" +
|
||
"else " +
|
||
" insert into [BWEX] ([BSNUM], [BSITM], [BSNAM]) values (@KeyName, ' 1', @KeyValue)";
|
||
AddParam(cmd, "KeyName", keyName);
|
||
AddParam(cmd, "KeyValue", keyValue);
|
||
ExecuteNonQuery(cmd);
|
||
}
|
||
}
|
||
}
|