using System.Data.Common;
using WebLib;
namespace 報到系統
{
///
/// BWEX 系統設定資料存取類別
///
public class DAC_BWEX : DAC
{
public DAC_BWEX() : base() { }
public DAC_BWEX(DbConnection conn) : base(conn) { }
/// 依 KeyName 取得 KeyValue
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;
}
/// 更新 KeyValue(若不存在則 INSERT)
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);
}
}
}