110 lines
2.8 KiB
C#
110 lines
2.8 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Dapper;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace kmCustomReportsNET.ClassObj;
|
|
|
|
public class ClsConstants
|
|
{
|
|
|
|
public static string KDrive = @"\\salem\k";
|
|
|
|
/// <summary>
|
|
/// T = Dot-Net (C#) version of the reports
|
|
/// </summary>
|
|
public enum enuReportIDs : byte
|
|
{
|
|
/// <summary>
|
|
/// Dobbs Monthly Email Contests
|
|
/// </summary>
|
|
T1439 = 101
|
|
}
|
|
|
|
static ConcurrentDictionary<string, DateTimeOffset> dctScheduler = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
internal static string GetCustomerRegistryItem(string KeyName)
|
|
{
|
|
string rv = string.Empty;
|
|
|
|
try
|
|
{
|
|
using (var cn = new SqlConnection(kmCommonLibsCore.Constants.GetCnString(kmCommonLibsCore.Constants.enuServer.RDB)))
|
|
{
|
|
var Sql = "Select [Value] From crpt.[Registry] Where [Key]=@Key And [Enabled]=1";
|
|
var parms = new { Key = KeyName };
|
|
var theValue = cn.ExecuteScalar(Sql, parms);
|
|
|
|
if (theValue != null && !string.IsNullOrWhiteSpace(theValue.ToString()))
|
|
rv = theValue?.ToString() ?? string.Empty;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
kmCommonLibsCore.ClsErrorReporting.ErrorEncountered(ex);
|
|
rv = string.Empty;
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
internal static void SetCustomerRegistryItem(string KeyName, string Value)
|
|
{
|
|
using (var cn = new SqlConnection(kmCommonLibsCore.Constants.GetCnString(kmCommonLibsCore.Constants.enuServer.RDB)))
|
|
{
|
|
var Sql = "Select Count(*) As Cnt From crpt.[Registry] Where [Key]=@Key And [Enabled]=1";
|
|
var parms = new { Key = KeyName };
|
|
int cnt = cn.ExecuteScalar<int>(Sql, parms);
|
|
|
|
if (cnt < 1)
|
|
Sql = "Insert Into crpt.[Registry] ([Key], [Value], [Enabled]) Values (@Key, @Value, 1)";
|
|
else
|
|
Sql = "Update crpt.[Registry] Set [Value]=@Value, [DateChanged]=SysDateTimeOffset() Where [Key]=@Key And [Enabled]=1";
|
|
|
|
cn.Execute(Sql, parms);
|
|
}
|
|
}
|
|
|
|
internal static bool NeedToRun(string TaskName)
|
|
{
|
|
bool rv = false;
|
|
|
|
if (!dctScheduler.ContainsKey(TaskName) || dctScheduler[TaskName] < DateTimeOffset.Now)
|
|
rv = true;
|
|
else
|
|
rv = false;
|
|
return rv;
|
|
}
|
|
|
|
internal static void SetNextRun(string TaskName, DateTimeOffset theTime)
|
|
{
|
|
dctScheduler[TaskName] = theTime;
|
|
}
|
|
|
|
internal static bool CanWeGo(byte whichLevel)
|
|
{
|
|
var rv = true;
|
|
lock (Program.objSync2)
|
|
{
|
|
try
|
|
{
|
|
using (var cn = new SqlConnection(kmCommonLibsCore.Constants.cnCommon))
|
|
{
|
|
rv = (Convert.ToInt32(cn.ExecuteScalar($"Select dbo.rdbCanWeGo({whichLevel})")) == 1) ? true : false;
|
|
}
|
|
}
|
|
catch // Something is wrong with SQL, so don't let anything run
|
|
{
|
|
rv = false;
|
|
throw;
|
|
}
|
|
}
|
|
return rv;
|
|
} //CanWeGo
|
|
|
|
}
|