forked from trimble-oss/dba-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRepositorySettings.cs
51 lines (46 loc) · 1.78 KB
/
RepositorySettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Data;
using Microsoft.Data.SqlClient;
namespace DBADash
{
public class RepositorySettings
{
public static object GetSetting(string SettingName, string connectionString)
{
using var cn = new SqlConnection(connectionString);
using var cmd = new SqlCommand("Settings_Get", cn) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.AddWithValue("SettingName", SettingName);
cn.Open();
using var rdr = cmd.ExecuteReader();
if (rdr.Read())
{
return rdr["SettingValue"] == DBNull.Value ? null : rdr["SettingValue"];
}
else
{
return null;
}
}
public static void UpdateSetting(string SettingName, object SettingValue, string connectionString)
{
using var cn = new SqlConnection(connectionString);
using var cmd = new SqlCommand("Settings_Upd", cn) { CommandType = CommandType.StoredProcedure };
cmd.Parameters.AddWithValue("SettingName", SettingName);
cmd.Parameters.AddWithValue("SettingValue", SettingValue ?? DBNull.Value);
cn.Open();
cmd.ExecuteNonQuery();
}
public static int? GetIntSetting(string SettingName, string connectionString)
{
return (int?)GetSetting(SettingName, connectionString);
}
public static int? GetStringSetting(string SettingName, string connectionString)
{
return (int?)GetSetting(SettingName, connectionString);
}
public static int? GetSummaryRefreshInterval(string connectionString)
{
return GetIntSetting("SummaryRefreshInterval", connectionString);
}
}
}