init
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using DTS.Common.Storage;
|
||||
|
||||
|
||||
namespace DTS.Common.Settings
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// user specific setting, this allows users to have specific settings for columns, tables, etc in the future
|
||||
/// </summary>
|
||||
public class UserSetting : Setting
|
||||
{
|
||||
public UserSetting(string id, string defaultValue, string user)
|
||||
: base(id, PropertyTypes.User, defaultValue, user)
|
||||
{
|
||||
|
||||
}
|
||||
protected override void GetPropertyValue(string defaultValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var cmd = DbOperations.GetSQLCommand(true))
|
||||
{
|
||||
try
|
||||
{
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_SettingsGet.ToString();
|
||||
cmd.Parameters.Add(new SqlParameter("@UserId", SqlDbType.NVarChar) { Value = UserId });
|
||||
cmd.Parameters.Add(new SqlParameter("@PropertyId", SqlDbType.NVarChar) { Value = PropertyId });
|
||||
|
||||
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
||||
{
|
||||
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
||||
{
|
||||
_propertyValue =
|
||||
Convert.ToString(
|
||||
ds.Tables[0].Rows[0][
|
||||
DbOperations.Settings.UserFields.PropertyValue.ToString()]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_propertyValue = defaultValue;
|
||||
StoreInDB();
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
cmd.Connection.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception) //TODO: handle exception properly
|
||||
{
|
||||
_propertyValue = defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user