This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,759 @@
using System;
using System.Data;
using System.Data.SqlClient;
namespace DatabaseImport
{
public class DbOperations
{
public abstract class Tags
{
public enum TagFields
{
TagId,
TagText,
Obsolete
}
}
public abstract class DbVersions
{
public enum DbVersionFields
{
Version,
Step,
Date,
Remarks,
UserField
}
}
public abstract class Settings
{
public enum UserFields
{
PropertyId,
PropertyType,
PropertyValue,
UserId
}
}
public abstract class Users
{
public enum UserFields
{
ID,
UserName,
DisplayName,
Password,
Role,
LastModified,
LastModifiedBy,
LocalOnly
}
public enum UIItemFields
{
ID,
Name
}
}
public abstract class SensorDB
{
public enum SensorDataFields
{
SerialNumber = 1,
UserSerialNumber,
Model,
Manufacturer,
Status,
MeasurementUnit,
OffsetToleranceLow,
OffsetToleranceHigh,
Id,
Capacity,
Comment,
BridgeType,
BridgeLegMode,
Shunt,
Invert,
UserValue1,
UserValue2,
UserValue3,
FilterClass,
BridgeResistance,
IsoCode,
CheckOffset,
SupportedExcitation,
InitialEU,
CalInterval,
CalibrationSignal,
InternalShuntResistance,
ExternalShuntResistance,
UniPolar,
RangeLow,
RangeAve,
RangeHigh,
Created,
TimesUsed,
SensorCategory,
BypassFilter,
CouplingMode,
Version,
LastModified,
ModifiedBy,
LocalOnly,
AxisNumber,
NumberOfAxes,
UserTags,
DoNotUse,
Broken,
eId,
DiagnosticsMode
}
public enum SensorModelFields
{
Model,
Manufacturer,
UserPartNumber,
Capacity,
OffsetToleranceLow,
OffsetToleranceHigh,
MeasurementUnit,
Bridge,
Shunt,
BridgeResistance,
FilterClass,
UniPolar,
IgnoreRange,
CouplingMode,
Version,
RangeLow,
RangeAve,
RangeHigh,
LastModified,
ModifiedBy,
LocalOnly,
NumberOfAxes,
CalInterval,
AxisNumber,
Polarity,
Invert,
CheckOffset,
CalibrationRecord,
ISOCode,
SupportedExcitation
}
public enum SensorCalibrationFields
{
SerialNumber,
CalibrationDate,
Username,
LocalOnly,
NonLinear,
CalibrationRecords,
ModifyDate,
IsProportional,
RemoveOffset,
ZeroMethod,
CertificationDocuments,
InitialOffset
}
}
/// <summary>
/// current db version in this code base
/// </summary>
public const int CURRENT_DB_VERSION = 61;
public class DbTypeAttr : Attribute
{
public string DbType { get; private set; }
internal DbTypeAttr(string attr)
{
DbType = attr;
}
public static string GetDbType(object o)
{
if (o != null)
{
var mi = o.GetType().GetMember(o.ToString());
if (mi != null && mi.Length > 0)
{
var attr = GetCustomAttribute(mi[0], typeof(DbTypeAttr)) as DbTypeAttr;
if (null != attr)
{
return attr.DbType;
}
}
}
return null;
}
}
public abstract class CalculatedChannels
{
public const string Table = "tblCalculatedChannels";
public enum Fields
{
[DbTypeAttr("INTEGER PRIMARY KEY NOT NULL")]
Id,
[DbTypeAttr("INTEGER")]
Operation,
[DbTypeAttr("NVARCHAR(255)")]
CalculatedChannelValueCode,
[DbTypeAttr("BLOB")]
InputChannelIds,
[DbTypeAttr("NVARCHAR(255)")]
CFCForInputChannels,
[DbTypeAttr("NVARCHAR(255)")]
CFCForOutput,
[DbTypeAttr("NVARCHAR(255)")]
TestSetupName,
[DbTypeAttr("NVARCHAR(255)")]
CCName
}
}
public abstract class LevelTriggers
{
//public const string Table = "tblLevelTriggers";
public enum Fields
{
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
TestSetupName,
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
GroupSerialNumber,
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
TestObjectChannelId,
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
HardwareChannelId,
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
SensorSerialNumber,
[DbTypeAttr("BIT NOT NULL")]
GreaterThanEnabled,
[DbTypeAttr("FLOAT NOT NULL")]
GreaterThanEU,
[DbTypeAttr("BIT NOT NULL")]
LessThanEnabled,
[DbTypeAttr("FLOAT NOT NULL")]
LessThanEU,
[DbTypeAttr("FLOAT NULL")]
InsideUpperEU,
[DbTypeAttr("FLOAT NULL")]
InsideLowerEU,
[DbTypeAttr("FLOAT NULL")]
OutsideUpperEU,
[DbTypeAttr("FLOAT NULL")]
OutsideLowerEU,
[DbTypeAttr("BIT NULL")]
TriggerInside,
[DbTypeAttr("BIT NULL")]
TriggerOutside,
[DbTypeAttr("NVARCHAR(255) NOT NULL")]
TestObjectName
};
}
public abstract class TestSetups
{
public enum HardwareFields
{
TestSetupName,
HardwareId,
AddOrRemove //0=remove,1=add
}
public enum ChannelSettingFields
{
TestName,
TestObjectName,
ChannelId,
Setting,
SensorSerial,
Disabled
}
// public const string TestSetupsTable = "tblTestSetups";
public enum Fields
{
SetupName,
SetupDescription,
AutomaticTestProgression,
AutomaticProgressionDelayMS,
InvertTrigger,
InvertStart,
ViewDiagnostics,
VerifyChannels,
AutoVerifyChannels,
VerifyChannelsDelayMS,
RecordingMode,
SamplesPerSecond,
PreTriggerSeconds,
PostTriggerSeconds,
StrictDiagnostics,
RequireConfirmationOnErrors,
ROIDownload,
ViewROIDownload,
DownloadAll,
ViewRealtime,
RealtimePlotCount,
RegionsOfInterest,
ROIStart,
ROIEnd,
ViewDownloadAll,
Export,
ExportFormat,
LabDetails,
UseLabDetails,
CustomerDetails,
UseCustomerDetails,
AllowMissingSensors,
AllowSensorIdToBlankChannel,
LocalOnly,
LastModified,
LastModifiedBy,
TurnOffExcitation,
TriggerCheckRealtime,
TriggerCheckStep,
PostTestDiagnostics,
ExportFolder,
DownloadFolder,
CommonStatusLine,
SameAsDownloadFolder,
UploadData,
UploadDataFolder,
UploadExportsOnly,
Settings,
WarnOnBatteryFail,
Dirty,
Complete,
ErrorMessage,
TestEngineerDetails,
UseTestEngineerDetails,
UserTags,
DoAutoArm,
CheckoutMode,
QuitTestWithoutWarning,
SuppressMissingSensorsWarning,
ISFFile,
NotAllChannelsRealTime,
NotAllChannelsViewer
}
public enum TestSetupObjectFields
{
TestObjectSerialNumber,
TestObjectName, //TestObjectSerialNumber was changed to TestObjectName in a later version
TestSetupName,
TargetSampleRate,
ExcitationWarmupTimeMS,
LocalOnly,
TestObjectType,
TestObjectPosition
}
public enum TestObjectMetaDataFields
{
TestObject,
ISOTestObject,
SetupName,
TestSetupName,
PropName,
PropValue,
Optional,
Version,
}
public enum GraphFields
{
GraphName,
GraphDescription,
TemplateName,
Channels,
UseDomainMin,
DomainMin,
UseDomainMax,
DomainMax,
UseRangeMin,
RangeMin,
UseRangeMax,
RangeMax,
Thresholds,
LocalOnly,
TestSetupName
}
}
public abstract class TestObjectChannelSettings
{
public enum Fields
{
TestObjectSerial,
ChannelId,
Setting,
SensorSerial,
SerialNumber
}
}
public abstract class DigitalOutputSettings
{
public enum Fields
{
ChannelDescription,
DelayMS,
DurationMS,
OutputMode,
LimitDuration,
LastModified,
LastModifiedBy,
Version,
LocalOnly,
DurationMSFloat,
UserTags,
Broken, //new in 2.0
DoNotUse //new in 2.0
}
}
public abstract class Squib
{
public enum Fields
{
SerialNumber,
SquibDescription,
BypassCurrentFilter,
BypassVoltageFilter,
DelayMS,
DurationMS,
FireMode,
ISOCode,
MeasurementType,
SquibOutputCurrent,
SquibToleranceLow,
SquibToleranceHigh,
LimitDuration,
ArticleId,
LocalOnly,
Version,
LastModified,
LastModifiedBy,
UserValue1,
UserValue2,
UserValue3,
UserTags,
Broken, //new in 2.0
DoNotUse //new in 2.0
}
}
public class MMETables
{
public enum MMEDirectionsFields
{
s_GUID,
DIRECTION,
TEXT_L1,
TEXT_L2,
DATE,
VERSION,
EXPIRED,
REMARKS,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY,
SORTKEY
}
public enum MMEFilterClassesFields
{
s_GUID,
FILTER_CLASS,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEFineLocations1Fields
{
s_GUID,
FINE_LOC_1,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEFineLocations2Fields
{
s_GUID,
FINE_LOC_2,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEFineLocations3Fields
{
s_GUID,
FINE_LOC_3,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
PICTURE_SHORTNAME,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEPhysicalDimensionFields
{
s_GUID,
PHYSICAL_DIMENSION,
TEXT_L1,
TEXT_L2,
DEFAULT_UNIT,
LENGTH_EXP,
TIME_EXP,
MASS_EXP,
ELECTRIC_CURRENT_EXP,
TEMPERATURE_EXP,
LUMINOUS_INTENSITY_EXP,
AMOUNT_OFSUBSTANCE_EXP,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEPositionsFields
{
s_GUID,
POSITION,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMETestObjectsFields
{
s_GUID,
TEST_OBJECT,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
public enum MMEMainLocationsFields
{
s_GUID,
TYPE,
TRANS_MAIN_LOC,
TEXT_L1,
TEXT_L2,
VERSION,
DATE,
REMARKS,
EXPIRED,
SORTKEY,
PICTURE_SHORTNAME,
LAST_CHANGE,
LAST_CHANGE_TEXT,
HISTORY
}
}
public static bool _usingCentralizedDB = true; //True means using a remote, centralized server; False means using a local SqlLocalDb
public static bool _usingMSSQL = true;
public static bool _usingNTLMAuthentication = false;
public static string _previousDir = string.Empty;
public class DAS
{
public enum Fields
{
SerialNumber,
Type,
MaxModules,
MaxMemory,
MaxSampleRate,
MinSampleRate,
FirmwareVersion,
CalDate,
ProtocolVersion,
LastModified,
LastModifiedBy,
Version,
LocalOnly,
LastUsed,
LastUsedBy,
Connection,
Channels,
Position,
ChannelTypes,
Reprogramable,
Reconfigurable,
IsModule,
PositionOnDistributor,
PositionOnChain,
Port,
ParentDAS,
MaxAAFRate
}
public enum DASChannelFields
{
HardwareId,
ChannelIdx,
SupportedBridges,
SupportedExcitations,
DASDisplayOrder,
LocalOnly,
SupportedDigitalInputModes,
SupportedSquibFireModes,
SupportedDigitalOutputModes,
ModuleSerialNumber,
ModuleArrayIndex
}
}
private static System.Data.SqlClient.SqlCommand _cmd = null;
public static System.Data.SqlClient.SqlCommand cmd
{
get => _cmd;
set => _cmd = value;
}
public static System.Data.SqlClient.SqlCommand GetSQLCommand()
{
return GetSQLCommand(false);
}
public static bool IsServerConnected()
{
using (var connection = new SqlConnection(Connection.GetLocalConnectionString()))
{
try
{
connection.Open();
return true;
}
catch (SqlException)
{
return false;
}
}
}
public static System.Data.SqlClient.SqlCommand GetSQLCommand(bool newCommand)
{
if (_cmd == null) { _cmd = new System.Data.SqlClient.SqlCommand(); }
var currentCmd = _cmd;
if (newCommand) { currentCmd = new System.Data.SqlClient.SqlCommand(); }
if (currentCmd.Connection == null || currentCmd.Connection.State != ConnectionState.Open)
{
currentCmd.Connection = new System.Data.SqlClient.SqlConnection(Connection.GetLocalConnectionString());
currentCmd.Connection.Open();
}
currentCmd.Parameters.Clear();
return currentCmd;
}
private string _localConnection = null;
public string GetLocalConnectionString()
{
lock (dbLock)
{
if (null != _localConnection) return _localConnection;
if (null == Server /*&& !_bCS3*/) { throw new Exception("db connection not initialized"); }
//if (_bCS3)
//{
// _localConnection = _bCS3UsingNTLMAuthentication ? string.Format("Server={0};Database={1};Trusted_Connection=TRUE;", _csHost, _cs3Name) : string.Format("Server={0};Database={1};User Id={2};Password={3}", _csHost, _cs3Name, _csUser, _cs3Password);
//}
//else
//{
_localConnection = _usingNTLMAuthentication ?
string.Format("Server={0};Database={1};Trusted_Connection=TRUE;", Server, DBName) :
string.Format("Server={0};Database={1};User Id={2};Password={3};", Server, DBName, Username, Password);
//}
}
return _localConnection;
}
public string Server { get; set; } = null;
public string Username { get; set; } = null;
public string Password { get; set; } = null;
public string DBName { get; set; } = null;
private static DbOperations _dbOperations = null;
private static readonly object dbLock = new object();
public static DbOperations Connection
{
get
{
lock (dbLock)
{
if (null == _dbOperations) { _dbOperations = new DbOperations(); }
}
return _dbOperations;
}
}
public DataSet QueryDataSet(System.Data.SqlClient.SqlCommand icmd)
{
//try { Log(icmd); }
//catch (Exception ex) { APILogger.Log(ex); }
if (cmd == null) return null;
using (var adapter = new System.Data.SqlClient.SqlDataAdapter(icmd))
{
var ds = new DataSet();
try
{
adapter.Fill(ds);
return ds;
}
catch (Exception ex)
{
//Log(icmd, true);
throw ex;
}
}
// }
}
public class DigitalInputSettings
{
public enum Fields
{
SettingName,
SettingMode,
ScaleMultiplier,
LastModified,
LastModifiedBy,
SensorId,
UserValue1,
UserValue2,
UserValue3,
UserTags,
eId,
Broken, //new in 2.0
DoNotUse //new in 2.0
}
}
}
}

View File

@@ -0,0 +1,125 @@
namespace DatabaseImport
{
public class DbOperationsEnum
{
public enum StoredProcedure
{
sp_UserDelete,
sp_UserGet,
sp_UserGetIdsAll,
sp_CalculatedChannelsGet,
sp_CustomerDetailsDelete,
sp_CustomerDetailsGet,
sp_DASChannelsGet,
sp_DASDelete,
sp_DASGet,
sp_DBImportCustomerDetails,
sp_DBImportDASList,
sp_DBImportDbVersions,
sp_DBImportGroup,
sp_DBImportGroupTemplate,
sp_DBImportLabDetails,
sp_DBImportLastUsedHardware,
sp_DBImportMMEDirections,
sp_DBImportMMEFineLocations1,
sp_DBImportMMEFineLocations2,
sp_DBImportMMEFineLocations3,
sp_DBImportMMEMainLocations,
sp_DBImportMMEPhysicalDimensions,
sp_DBImportMMEPositions,
sp_DBImportMMEPossibleChannels,
sp_DBImportMMETestObjects,
sp_DBImportSensorModel,
sp_DBImportSensors,
sp_DBImportSensorsCalibration,
sp_DBImportSettings,
sp_DBImportTagAssignments,
sp_DBImportTags,
sp_DBImportTemplateRegions,
sp_DBImportTemplateZones,
sp_DBImportTestEngineerDetails,
sp_DBImportTestSetups,
sp_DBImportUIItems,
sp_DBImportUIItemSettings,
sp_DBImportUsers,
sp_DefaultPropertiesGet,
sp_LabratoryDetailsDelete,
sp_LabratoryDetailsGet,
sp_LevelTriggersGet,
sp_MMEDirectionsDelete,
sp_MMEDirectionsGet,
sp_MMEDirectionsGetCustom,
sp_MMEFiguresGet,
sp_MMEFiguresGetCustom,
sp_MMEFilterClassesDelete,
sp_MMEFilterClassesGet,
sp_MMEFilterClassesGetCustom,
sp_MMEFineLocations1Delete,
sp_MMEFineLocations1Get,
sp_MMEFineLocations1GetCustom,
sp_MMEFineLocations2Delete,
sp_MMEFineLocations2Get,
sp_MMEFineLocations2GetCustom,
sp_MMEFineLocations3Delete,
sp_MMEFineLocations3Get,
sp_MMEFineLocations3GetCustom,
sp_MMEMainLocationsDelete,
sp_MMEMainLocationsGet,
sp_MMEMainLocationsGetCustom,
sp_MMEPhysicalDimensionsDelete,
sp_MMEPhysicalDimensionsGet,
sp_MMEPhysicalDimensionsGetCustom,
sp_MMEPositionsDelete,
sp_MMEPositionsGet,
sp_MMEPositionsGetCustom,
sp_MMEPossibleChannelsDelete,
sp_MMEPossibleChannelsGet,
sp_MMEPossibleChannelsGetCustom,
sp_MMETestObjectsDelete,
sp_MMETestObjectsGet,
sp_MMETestObjectsGetCustom,
sp_MMETestObjectsUpdateInsert,
sp_TemplateChannelsGet,
sp_TemplateRegionsGet,
sp_TemplateZonesGet,
sp_TestChannelSettingsGet,
sp_TestEngineerDetailsDelete,
sp_TestEngineerDetailsGet,
sp_TestGraphsGet,
sp_TestObjectChannelSettingsGet,
sp_TestObjectHardwareIdsGet,
sp_TestObjectSensorsGet,
sp_TestObjectsDelete,
sp_TestObjectsGet,
sp_TestObjectTemplatesDelete,
sp_TestObjectTemplatesGet,
sp_TestSetupDASSettingsGet,
sp_TestSetupHardwareGet,
sp_TestSetupObjectMetaDataGet,
sp_TestSetupObjectsGet,
sp_TestSetupsDeleteAll,
sp_TestSetupsGet,
sp_TestSetupsUpdateInsert,
sp_TestSetupsIsCompleteUpdate,
sp_SensorCalibrationsDelete,
sp_SensorCalibrationsGet,
sp_SensorDeleteAll,
sp_SensorsDeleteAll,
sp_SensorsAnalogGet,
sp_SensorsDigitalInGet,
sp_SensorsDigitalOutGet,
sp_SensorsSquibGet,
sp_SensorModelsDelete,
sp_SensorModelsGet,
sp_SettingsGet,
sp_SettingsUpdateInsert,
sp_TagsDelete,
sp_TagsGet,
sp_UIItemsDelete,
sp_UIItemsGet,
sp_UserPropertiesInsert,
sp_DbVersionDelete,
sp_DbVersionGet,
}
}
}

View File

@@ -0,0 +1,94 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
namespace DatabaseImport
{
public abstract class DbTimeStampBase : IDbTimeStampAware, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
{
if (Equals(storage, value)) return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
protected long DbTimeStamp;
public long GetTimeStampMemory()
{
return DbTimeStamp;
}
public void SetTimeStampMemory(long value) { DbTimeStamp = value; }
public void SetTimeStampMemory(DataRow row)
{
DbTimeStamp = 0;
}
public void SetTimeStampMemory(IDataReader reader)
{
DbTimeStamp = 0;
}
public long GetTimeStampDb(Dictionary<string, long> lookup)
{
//var constraints = GetConstraints();
return 0; //lookup.ContainsKey(constraints[0].DbValue.ToString()) ? lookup[constraints[0].DbValue.ToString()] : GetTimeStampDb();
}
public long GetTimeStampDb()
{
return 0;
//using (var sql = DbOperations.GetSQLCommand())
//{
// var sb = new StringBuilder(50);
// sb.AppendFormat("SELECT DbTimeStamp as A FROM {0} ", LookupTable);
// var constraints = GetConstraints();
// for (var i = 0; i < constraints.Length; i++)
// {
// sb.Append(0 == i ? "WHERE " : " AND ");
// sb.AppendFormat("{0}=@{1}", constraints[i].ColumnName, i);
// DbOperations.CreateParam(sql, string.Format("@{0}", i), constraints[i].DbType, constraints[i].DbValue);
// }
// sql.CommandText = sb.ToString();
// using (var ds = DbOperations.Connection.QueryDataSet(sql))
// {
// if (ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count <= 0) return 0;
// if (DBNull.Value.Equals(ds.Tables[0].Rows[0]["A"])) return 0;
// try
// {
// var res = BitConverter.ToInt64(ds.Tables[0].Rows[0]["A"] as byte[], 0);
// System.Diagnostics.Trace.WriteLine(string.Format("Db: {0}", res));
// return res;
// }
// catch (Exception ex) { APILogger.Log(ex); return 0; }
// }
//}
}
public bool IsOutOfDate()
{
var db = GetTimeStampDb();
var mem = GetTimeStampMemory();
//if there's no record in the db, don't mark as out of date
if (db == 0) { return false; }
//if is in db, but in memory is new, allow overwrite...
if (mem == 0 && db != 0) { mem = db; SetTimeStampMemory(db); }
return db != mem;
}
}
public interface IDbTimeStampAware
{
long GetTimeStampMemory();
void SetTimeStampMemory(long value);
long GetTimeStampDb();
bool IsOutOfDate();
}
}