589 lines
26 KiB
C#
589 lines
26 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Xml;
|
|||
|
|
|
|||
|
|
namespace DatabaseImport
|
|||
|
|
{
|
|||
|
|
public class DbImporter
|
|||
|
|
{
|
|||
|
|
public DbImporter()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
public DbImporter(int dbType, string dbName, string server, bool useNTLMAuthentication, string localDbUser, string localDbPassword)
|
|||
|
|
{
|
|||
|
|
DbOperations.Connection.DBName = dbName;
|
|||
|
|
if (1 == dbType)
|
|||
|
|
{
|
|||
|
|
//Local
|
|||
|
|
DbOperations._usingCentralizedDB = false;
|
|||
|
|
DbOperations._usingNTLMAuthentication = true;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//Centralized
|
|||
|
|
DbOperations._usingCentralizedDB = true;
|
|||
|
|
DbOperations._usingNTLMAuthentication = useNTLMAuthentication;
|
|||
|
|
DbOperations.Connection.Username = localDbUser;
|
|||
|
|
DbOperations.Connection.Password = localDbPassword;
|
|||
|
|
}
|
|||
|
|
DbOperations.Connection.Server = server;
|
|||
|
|
}
|
|||
|
|
public enum TopLevelFields
|
|||
|
|
{
|
|||
|
|
CustomerDetails,
|
|||
|
|
TestEngineerDetails,
|
|||
|
|
LabDetails,
|
|||
|
|
DASList,
|
|||
|
|
SensorModels,
|
|||
|
|
Sensors,
|
|||
|
|
Calibrations,
|
|||
|
|
CustomDirections,
|
|||
|
|
CustomFilterClasses,
|
|||
|
|
CustomTestObjects,
|
|||
|
|
CustomFinLoc1s,
|
|||
|
|
CustomFinLoc2s,
|
|||
|
|
CustomFinLoc3s,
|
|||
|
|
CustomMainLocs,
|
|||
|
|
CustomPhysicalDimensions,
|
|||
|
|
CustomPositions,
|
|||
|
|
CustomChannels,
|
|||
|
|
GroupTemplates,
|
|||
|
|
Groups,
|
|||
|
|
TestSetups,
|
|||
|
|
Users,
|
|||
|
|
GlobalSettings
|
|||
|
|
}
|
|||
|
|
public delegate void SetStatusDelegate(string status, bool output = false);
|
|||
|
|
public void ImportXML(string ImportFile, SetStatusDelegate SetStatus)
|
|||
|
|
{
|
|||
|
|
// DataPRO database import XML file
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//(System.Windows.Application.Current as App).SetAppBusy();
|
|||
|
|
|
|||
|
|
////If local, make a backup, just in case.
|
|||
|
|
//var sourceDb = Path.Combine("db", "DataPRO.mdf"); ///////////////Fix this to get the actual db file, not necessarily the one in the current directory
|
|||
|
|
//if (File.Exists(sourceDb))
|
|||
|
|
//{
|
|||
|
|
// var destDb = Path.Combine("db", "DataPRO_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".mdf");
|
|||
|
|
// try
|
|||
|
|
// {
|
|||
|
|
// File.Copy(sourceDb, destDb, true);
|
|||
|
|
// }
|
|||
|
|
// catch(Exception ex)
|
|||
|
|
// {
|
|||
|
|
// MessageBox.Show(ex.Message);
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
ImportSensorsImportControl.ClearAllTables(true);
|
|||
|
|
|
|||
|
|
using (var reader = XmlReader.Create(ImportFile))
|
|||
|
|
{
|
|||
|
|
while (reader.Read())
|
|||
|
|
{
|
|||
|
|
var customTestObject = false;
|
|||
|
|
if (reader.NodeType != XmlNodeType.Element) continue;
|
|||
|
|
var elementName = string.Empty;
|
|||
|
|
switch (reader.Name)
|
|||
|
|
{
|
|||
|
|
case "CustomerDetails":
|
|||
|
|
elementName = "CustomerDetail";
|
|||
|
|
break;
|
|||
|
|
case "TestEngineerDetails":
|
|||
|
|
elementName = "TestEngineerDetail";
|
|||
|
|
break;
|
|||
|
|
case "LabDetails":
|
|||
|
|
elementName = "LabDetail";
|
|||
|
|
break;
|
|||
|
|
case "DASList":
|
|||
|
|
elementName = "DASHardware";
|
|||
|
|
break;
|
|||
|
|
case "SensorModels":
|
|||
|
|
elementName = "SensorModel";
|
|||
|
|
break;
|
|||
|
|
case "Sensors":
|
|||
|
|
elementName = "SensorData";
|
|||
|
|
break;
|
|||
|
|
case "Calibrations":
|
|||
|
|
elementName = "SensorCalibration";
|
|||
|
|
break;
|
|||
|
|
case "CustomDirections":
|
|||
|
|
elementName = "CustomDirection";
|
|||
|
|
break;
|
|||
|
|
case "CustomTestObjects":
|
|||
|
|
elementName = "TestObject";
|
|||
|
|
customTestObject = true;
|
|||
|
|
break;
|
|||
|
|
case "CustomFinLoc1s":
|
|||
|
|
elementName = "FineLocation1";
|
|||
|
|
break;
|
|||
|
|
case "CustomFinLoc2s":
|
|||
|
|
elementName = "FineLocation2";
|
|||
|
|
break;
|
|||
|
|
case "CustomFinLoc3s":
|
|||
|
|
elementName = "FineLocation3";
|
|||
|
|
break;
|
|||
|
|
case "CustomMainLocs":
|
|||
|
|
elementName = "TransducerMainLocation";
|
|||
|
|
break;
|
|||
|
|
case "CustomPhysicalDimensions":
|
|||
|
|
elementName = "PhysicalDimension";
|
|||
|
|
break;
|
|||
|
|
case "CustomPositions":
|
|||
|
|
elementName = "Position";
|
|||
|
|
break;
|
|||
|
|
case "CustomChannels":
|
|||
|
|
elementName = "CustomChannel";
|
|||
|
|
//ImportTestSetup.possibleChannelIdMap.Clear();
|
|||
|
|
break;
|
|||
|
|
case "GroupTemplates":
|
|||
|
|
elementName = "GroupTemplate";
|
|||
|
|
break;
|
|||
|
|
case "Groups":
|
|||
|
|
elementName = "TestObject";
|
|||
|
|
break;
|
|||
|
|
case "TestSetups":
|
|||
|
|
elementName = "TestSetup";
|
|||
|
|
break;
|
|||
|
|
case "UIItems":
|
|||
|
|
elementName = "UIItem";
|
|||
|
|
break;
|
|||
|
|
case "Users":
|
|||
|
|
elementName = "User";
|
|||
|
|
break;
|
|||
|
|
case "UIItemSettings":
|
|||
|
|
elementName = "UIItemSetting";
|
|||
|
|
break;
|
|||
|
|
case "GlobalSettings":
|
|||
|
|
elementName = "Setting";
|
|||
|
|
break;
|
|||
|
|
case "LastUsedHardware":
|
|||
|
|
elementName = "UserHardware";
|
|||
|
|
break;
|
|||
|
|
case "Tags":
|
|||
|
|
elementName = "Tag";
|
|||
|
|
break;
|
|||
|
|
case "TagAssignments":
|
|||
|
|
elementName = "TagAssignment";
|
|||
|
|
break;
|
|||
|
|
case "TemplateZones":
|
|||
|
|
elementName = "TemplateZone";
|
|||
|
|
break;
|
|||
|
|
case "TemplateRegions":
|
|||
|
|
elementName = "TemplateRegion";
|
|||
|
|
break;
|
|||
|
|
case "DbVersions":
|
|||
|
|
elementName = "DbVersion";
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
break;
|
|||
|
|
} // switch
|
|||
|
|
if (string.IsNullOrEmpty(elementName)) continue;
|
|||
|
|
var totalItems = reader.GetAttribute("TotalItems");
|
|||
|
|
if (string.IsNullOrWhiteSpace(totalItems) || Convert.ToInt32(totalItems) == 0) continue;
|
|||
|
|
if (!reader.ReadToFollowing(elementName)) continue;
|
|||
|
|
var counter = 0;
|
|||
|
|
do
|
|||
|
|
{
|
|||
|
|
var outerXML = reader.ReadOuterXml();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
ImportTestSetup.ProcessRootNode(customTestObject ? "CustomTestObject" : elementName,
|
|||
|
|
outerXML, /*_page,*/ SetStatus);
|
|||
|
|
counter++;
|
|||
|
|
SetStatus("Importing " + elementName + "..." + counter + "/" + totalItems +
|
|||
|
|
" processed");
|
|||
|
|
while (string.IsNullOrEmpty(reader.Name))
|
|||
|
|
{
|
|||
|
|
reader.Read();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
SetStatus("Failure " + elementName + " " + counter + ":" + outerXML);
|
|||
|
|
throw ex;
|
|||
|
|
}
|
|||
|
|
} while (reader.Name == elementName);
|
|||
|
|
customTestObject = false;
|
|||
|
|
} //while
|
|||
|
|
} //using
|
|||
|
|
|
|||
|
|
//Add an entry in the UserProperties table for each user if a
|
|||
|
|
//Setting that was imported exists in the DefaultProperties table
|
|||
|
|
AssignSettingsToAllUsers();
|
|||
|
|
//12431Cannot run test after 1.4 to 1.10 migration with TDAS G5 VDS.
|
|||
|
|
//migrate from 1.4 skips the migration steps, migration step 66 fixes the issue with G5 VDS channels
|
|||
|
|
//so we need to make use of the data transformation in that step (without changing the db version though)
|
|||
|
|
MigrateG5ChannelSupportedBridges();
|
|||
|
|
MigrateSPSChannelSupportedBridges();
|
|||
|
|
SetStatus("Done with database import");
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw ex;
|
|||
|
|
}
|
|||
|
|
//finally
|
|||
|
|
//{
|
|||
|
|
// SetStatus("Done with database import");
|
|||
|
|
// //(System.Windows.Application.Current as App).SetAppAvailable();
|
|||
|
|
//}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 12431 Cannot run test after 1.4 to 1.10 migration with TDAS G5 VDS.
|
|||
|
|
/// this does the migration without updating the version step
|
|||
|
|
/// when migrating from 1.4 we start with a clean 1.10 database, which has db version 67
|
|||
|
|
/// because of this migrateversion66 is never called.
|
|||
|
|
/// to fix the 1.4 vds data that is fixed in migrateversion66, we have to call this directly
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public bool MigrateG5ChannelSupportedBridges()
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.Text;
|
|||
|
|
cmd.CommandText =
|
|||
|
|
"SELECT DISTINCT(A.[DASId]) FROM [DAS] as A inner join [DASChannels] as B on A.DASId=B.DASId where A.Type=12";
|
|||
|
|
|
|||
|
|
var dasIds = new List<int>();
|
|||
|
|
var reader = cmd.ExecuteReader();
|
|||
|
|
while (reader.Read())
|
|||
|
|
{
|
|||
|
|
dasIds.Add(Convert.ToInt32(reader["DASId"]));
|
|||
|
|
}
|
|||
|
|
reader.Close();
|
|||
|
|
if (dasIds.Any())
|
|||
|
|
{
|
|||
|
|
var sb = new StringBuilder();
|
|||
|
|
//12431 Cannot run test after 1.4 to 1.10 migration with TDAS G5 VDS.
|
|||
|
|
sb.Append(
|
|||
|
|
"UPDATE [DASChannels] SET SupportedBridges=140 WHERE SupportedBridges=12 AND DASID in (");
|
|||
|
|
var bNeedComma = false;
|
|||
|
|
foreach (var id in dasIds)
|
|||
|
|
{
|
|||
|
|
if (bNeedComma)
|
|||
|
|
{
|
|||
|
|
sb.Append(", ");
|
|||
|
|
}
|
|||
|
|
sb.Append(id);
|
|||
|
|
bNeedComma = true;
|
|||
|
|
}
|
|||
|
|
sb.Append(")");
|
|||
|
|
cmd.CommandText = sb.ToString();
|
|||
|
|
|
|||
|
|
cmd.ExecuteNonQuery();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(ex.Message, ex);
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
public bool IsServerConnected()
|
|||
|
|
{
|
|||
|
|
return DbOperations.IsServerConnected();
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 12850 Channel count mismatch with SPS when migrating from 1.4 to 1.10
|
|||
|
|
/// This should set the SupportedBridges value in the DASChannels table to 143 when migrating
|
|||
|
|
/// from 1.4 if the <ProtocolVersion> is 154 or greater
|
|||
|
|
/// (SLICE2_MinimumProtocols[DFConstantsAndEnums.ProtocolLimitedCommands.HalfBridgeSigPlusSupport] = 154;).
|
|||
|
|
/// </summary>
|
|||
|
|
public void MigrateSPSChannelSupportedBridges()
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.Text;
|
|||
|
|
cmd.CommandText =
|
|||
|
|
"SELECT DISTINCT(A.[DASId]) FROM [DAS] as A inner join [DASChannels] as B on A.DASId=B.DASId where A.Type=19 AND A.ProtocolVersion >= 154";
|
|||
|
|
|
|||
|
|
var dasIds = new List<int>();
|
|||
|
|
var reader = cmd.ExecuteReader();
|
|||
|
|
while (reader.Read())
|
|||
|
|
{
|
|||
|
|
dasIds.Add(Convert.ToInt32(reader["DASId"]));
|
|||
|
|
}
|
|||
|
|
reader.Close();
|
|||
|
|
if (dasIds.Any())
|
|||
|
|
{
|
|||
|
|
var sb = new StringBuilder();
|
|||
|
|
//12431 Cannot run test after 1.4 to 1.10 migration with SPS.
|
|||
|
|
sb.Append("UPDATE [DASChannels] SET SupportedBridges=143 WHERE SupportedBridges=15 AND DASID in (");
|
|||
|
|
var bNeedComma = false;
|
|||
|
|
foreach (var id in dasIds)
|
|||
|
|
{
|
|||
|
|
if (bNeedComma)
|
|||
|
|
{
|
|||
|
|
sb.Append(", ");
|
|||
|
|
}
|
|||
|
|
sb.Append(id);
|
|||
|
|
bNeedComma = true;
|
|||
|
|
}
|
|||
|
|
sb.Append(")");
|
|||
|
|
cmd.CommandText = sb.ToString();
|
|||
|
|
|
|||
|
|
cmd.ExecuteNonQuery();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception ex)
|
|||
|
|
{
|
|||
|
|
throw new Exception(ex.Message, ex);
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//return true;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Users can override the system defaults for some settings
|
|||
|
|
/// </summary>
|
|||
|
|
private void AssignSettingsToAllUsers()
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
var userIdList = GetAllUserIds();
|
|||
|
|
foreach (var userId in userIdList)
|
|||
|
|
{
|
|||
|
|
var defaultPropertyList = GetAllDefaultProperties();
|
|||
|
|
foreach (var defaultProperty in defaultPropertyList)
|
|||
|
|
{
|
|||
|
|
string settingValue = null;
|
|||
|
|
switch (defaultProperty.Item2)
|
|||
|
|
{
|
|||
|
|
case "AllowAdvancedRecordingModes":
|
|||
|
|
settingValue = GetSettingValue("AllowAdvancedRecordingModes");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "AllowTSRAIRRecordingModes":
|
|||
|
|
settingValue = GetSettingValue("AllowTSRAIRRecordingModes");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultArmCheckListStep":
|
|||
|
|
settingValue = GetSettingValue("AutoAdd_ArmChecklist");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultAutomaticMode":
|
|||
|
|
settingValue = GetSettingValue("TestSetupDefaultAutomaticMode");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultCommonStatusLine":
|
|||
|
|
settingValue = GetSettingValue("CommonStatusLine");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultRealtimeGraphCount":
|
|||
|
|
settingValue = GetSettingValue("NumberRealtimeCharts");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultRecordingMode":
|
|||
|
|
settingValue = GetSettingValue("DefaultRecordingMode");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
case "DefaultTestSetupAutomaticProgressDelaySeconds":
|
|||
|
|
settingValue = GetSettingValue("AutomaticModeDelayMS");
|
|||
|
|
if (settingValue != null)
|
|||
|
|
{
|
|||
|
|
SetUserProperty(userId, defaultProperty.Item1, settingValue);
|
|||
|
|
}
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get all of the ID values from the Users table
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
private List<int> GetAllUserIds()
|
|||
|
|
{
|
|||
|
|
var userIdList = new List<int>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_UserGetIdsAll.ToString(); //Only used in DataPROPre20.mdf, not DataPRO.mdf
|
|||
|
|
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
userIdList.Add(Convert.ToInt32(dr[DbOperations.Users.UserFields.ID.ToString()]));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//APILogger.Log("problem getting user", ex);
|
|||
|
|
}
|
|||
|
|
return userIdList;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get all of the system default properties
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
List<Tuple<int, string>> GetAllDefaultProperties()
|
|||
|
|
{
|
|||
|
|
var properties = new List<Tuple<int, string>>();
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_DefaultPropertiesGet.ToString();
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@PropertyId", SqlDbType.Int) { Value = null });
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
properties.AddRange(from DataRow row in ds.Tables[0].Rows
|
|||
|
|
let id = Convert.ToInt32(row["PropertyId"])
|
|||
|
|
let value = Convert.ToString(row["PropertyName"])
|
|||
|
|
select new Tuple<int, string>(id, value));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally { cmd.Connection.Dispose(); }
|
|||
|
|
}
|
|||
|
|
return properties;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Get a value to override the system default for a setting
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="settingId"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
string GetSettingValue(string settingId)
|
|||
|
|
{
|
|||
|
|
string settingValue = null;
|
|||
|
|
const string SYSTEM = "SYSTEM";
|
|||
|
|
|
|||
|
|
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 = SYSTEM });
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@PropertyId", SqlDbType.NVarChar) { Value = settingId });
|
|||
|
|
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
settingValue = Convert.ToString(ds.Tables[0].Rows[0][DbOperations.Settings.UserFields.PropertyValue.ToString()]);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception) //TODO: handle exception properly
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
return settingValue;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Add an entry to the UserProperties table
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="userId"></param>
|
|||
|
|
/// <param name="propertyId"></param>
|
|||
|
|
/// <param name="propertyValue"></param>
|
|||
|
|
void SetUserProperty(int userId, int propertyId, string propertyValue)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_UserPropertiesInsert.ToString();
|
|||
|
|
|
|||
|
|
#region params
|
|||
|
|
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@UserId", SqlDbType.Int) { Value = userId });
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@PropertyId", SqlDbType.Int) { Value = propertyId });
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@PropertyValue", SqlDbType.NVarChar) { Value = propertyValue });
|
|||
|
|
var errorNumberParam =
|
|||
|
|
new SqlParameter("@errorNumber", SqlDbType.Int) { Direction = ParameterDirection.Output };
|
|||
|
|
cmd.Parameters.Add(errorNumberParam);
|
|||
|
|
var errorMessageParam =
|
|||
|
|
new SqlParameter("@errorMessage", SqlDbType.NVarChar, 250)
|
|||
|
|
{
|
|||
|
|
Direction = ParameterDirection.Output
|
|||
|
|
};
|
|||
|
|
cmd.Parameters.Add(errorMessageParam);
|
|||
|
|
|
|||
|
|
#endregion params
|
|||
|
|
|
|||
|
|
cmd.ExecuteNonQuery();
|
|||
|
|
if (int.Parse(errorNumberParam.Value.ToString()) != 0)
|
|||
|
|
{
|
|||
|
|
//errorMessageParam.Value
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception) {/* APILogger.LogException(ex);*/ }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|