From e3cb2b26fe366d48b6937612f7e37936c83bc4b5 Mon Sep 17 00:00:00 2001 From: Andy Howard Date: Thu, 30 Oct 2025 12:58:43 +0000 Subject: [PATCH] BusinessMgr 3.0.1.9 Interfaces data model --- SacsCoreWeb/Web/Components/SaController.cs | 6 +- SacsStandardBase/Base/Bus/ItemId.cs | 13 +- .../Base/Bus/SacsHierarchyItem.cs | 17 +- SacsStandardBase/Base/Bus/SysId.cs | 20 +- .../Base/CodeTypes/SaCodeTypeDbDfn.cs | 161 +++--- SacsStandardBase/Base/Core/DataValue.cs | 14 +- SacsStandardBase/Base/Dbas/DbDfnTable.cs | 18 +- .../Base/Interfaces/SaInterface.cs | 42 +- .../Base/Interfaces/SaInterfaceConsole.cs | 123 ++-- .../Base/Interfaces/SaInterfaceDataItem.cs | 38 +- .../Base/Interfaces/SaInterfaceDbDfn.cs | 234 ++++---- .../Base/Interfaces/SaInterfaceProcess.cs | 22 +- .../Base/ItemOptions/SaItemOptionDbDfn.cs | 161 +++--- .../Base/Security/SaSecurityDbDfn.cs | 161 +++--- .../Dbas/Base/DatabaseDefinitionGenerator.cs | 533 +++++++++--------- SacsStandardDbas/Dbas/Base/SacsDatabase.cs | 33 +- .../Dbas/CodeTypes/Internal/SaCodeType_Db.cs | 2 +- .../Dbas/CodeTypes/Internal/SaCode_Db.cs | 2 +- .../CodeTypes/SaCodeTypeDbDfnGenerator.cs | 4 +- .../Internal/SaInterfaceDataItem_Db.cs | 99 ++-- .../Internal/SaInterfaceProcessDataItem_Db.cs | 69 ++- .../Internal/SaInterfaceProcessMessage_Db.cs | 92 +-- .../Internal/SaInterfaceProcess_Db.cs | 96 ++-- .../Interfaces/Internal/SaInterface_Db.cs | 84 ++- .../Interfaces/SaInterfaceConsole_Dbas.cs | 101 ++-- .../Interfaces/SaInterfaceDbDfnGenerator.cs | 44 +- ...erfaceMgr_Dbas-InterfaceProcessMessages.cs | 20 +- .../SaInterfaceMgr_Dbas-InterfaceProcesses.cs | 22 +- .../SaInterfaceMgr_Dbas-Interfaces.cs | 99 ++-- .../Interfaces/SaInterfaceProcess_Db_Local.cs | 35 +- .../ItemOptions/Internal/SaItemOption_Db.cs | 2 +- .../Dbas/Security/Internal/SaSecItem_Db.cs | 2 +- .../Dbas/Security/Internal/SaSecLink_Db.cs | 2 +- .../SaSecurityMgr_Dbas-SecurityLink.cs | 9 +- .../Resources/Database/SaInterfaceDbDfn.xml | 103 ++-- 35 files changed, 1355 insertions(+), 1128 deletions(-) diff --git a/SacsCoreWeb/Web/Components/SaController.cs b/SacsCoreWeb/Web/Components/SaController.cs index b79a382..8b703ae 100644 --- a/SacsCoreWeb/Web/Components/SaController.cs +++ b/SacsCoreWeb/Web/Components/SaController.cs @@ -3,8 +3,6 @@ using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Routing; -using Microsoft.Net.Http.Headers; -using Newtonsoft.Json; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; @@ -16,8 +14,6 @@ using System.Collections.Specialized; using System.Globalization; using System.Linq; using System.Text; -using System.Text.RegularExpressions; -using System.Threading.Tasks; using System.Web; namespace Sacs.Web.Components @@ -43,7 +39,7 @@ namespace Sacs.Web.Components //------------------------------------------------------------------- // Properties. public DateTime CreatedAt { get; } = DateTime.Now; - public bool DebugMode { get; } = SacsSystem.DebugMode; + public static bool DebugMode { get; } = SacsSystem.DebugMode; /// /// Indicate whether session data should be stored by action. /// Any action that might modify the session data must store it. diff --git a/SacsStandardBase/Base/Bus/ItemId.cs b/SacsStandardBase/Base/Bus/ItemId.cs index 8788380..b393877 100644 --- a/SacsStandardBase/Base/Bus/ItemId.cs +++ b/SacsStandardBase/Base/Bus/ItemId.cs @@ -1,5 +1,4 @@ -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Base.Utils; using System; using System.Collections.Generic; using System.Xml.Serialization; @@ -18,16 +17,16 @@ namespace Sarand.Net.Standard.Base.Bus //------------------------------------------------------------------- // Construction. public ItemId() { } - public ItemId(short itemType, SysId id, String caption = "") + public ItemId(short? itemType, SysId id, String caption = "") { - Type = itemType; + Type = itemType ?? 0; Id = SysId.InvalidOnNull(id); idType = ItemIdType.SysId; Caption = StringUtil.EmptyOnNull(caption); } - public ItemId(short itemType, String stringId, String caption = "") + public ItemId(short? itemType, String stringId, String caption = "") { - Type = itemType; + Type = itemType ?? 0; StringId = StringUtil.EmptyOnNull(stringId); idType = ItemIdType.String; Caption = StringUtil.EmptyOnNull(caption); @@ -58,7 +57,7 @@ namespace Sarand.Net.Standard.Base.Bus return true; } /// Return the Item Id if non-=null, otherwise empty Item Id. - public static ItemId InvalidOnNull (ItemId itemId) + public static ItemId InvalidOnNull(ItemId itemId) { return itemId ?? new ItemId(); } diff --git a/SacsStandardBase/Base/Bus/SacsHierarchyItem.cs b/SacsStandardBase/Base/Bus/SacsHierarchyItem.cs index a06d83f..b351a57 100644 --- a/SacsStandardBase/Base/Bus/SacsHierarchyItem.cs +++ b/SacsStandardBase/Base/Bus/SacsHierarchyItem.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; +using System.Linq; namespace Sarand.Net.Standard.Base.Bus { @@ -424,16 +423,16 @@ namespace Sarand.Net.Standard.Base.Bus //------------------------------------------------------------------- // Update stamps. public UpdateStamp CreateStamp { get { return data.CreateStamp; } } - public void SetCreateStamp(DateTime on, SysId by, String host) + public void SetCreateStamp(DateTime? on, SysId by, String host) { - CreateStamp.On = on; + CreateStamp.On = on ?? default(DateTime); CreateStamp.By = by; CreateStamp.Host = host; } public UpdateStamp UpdateStamp { get { return data.UpdateStamp; } } - public void SetUpdateStamp(DateTime on, SysId by, String host) + public void SetUpdateStamp(DateTime? on, SysId by, String host) { - UpdateStamp.On = on; + UpdateStamp.On = on ?? default(DateTime); UpdateStamp.By = by; UpdateStamp.Host = host; } diff --git a/SacsStandardBase/Base/Bus/SysId.cs b/SacsStandardBase/Base/Bus/SysId.cs index 06d4ec6..dcf2bb0 100644 --- a/SacsStandardBase/Base/Bus/SysId.cs +++ b/SacsStandardBase/Base/Bus/SysId.cs @@ -1,14 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Diagnostics.CodeAnalysis; -using System.Diagnostics.Contracts; -using System.Linq; -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; namespace Sarand.Net.Standard.Base.Bus { @@ -24,9 +22,13 @@ namespace Sarand.Net.Standard.Base.Bus //------------------------------------------------------------------- // Construction. public SysId() { } - public SysId(Int64 id) + public SysId(Int64? id) { - this.id = id; + this.id = id ?? 0; + } + public SysId(Int32? id) + { + this.id = id ?? 0; } //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/CodeTypes/SaCodeTypeDbDfn.cs b/SacsStandardBase/Base/CodeTypes/SaCodeTypeDbDfn.cs index e688a7c..adfeb30 100644 --- a/SacsStandardBase/Base/CodeTypes/SaCodeTypeDbDfn.cs +++ b/SacsStandardBase/Base/CodeTypes/SaCodeTypeDbDfn.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:21 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Base.CodeTypes { @@ -25,7 +25,7 @@ namespace Sarand.Net.Standard.Base.CodeTypes // Column identifiers. public enum ColumnIdx { - Unknown = 0, + Unknown = 0, SaCode_Id, SaCode_CodeTypeId, SaCode_Code, @@ -65,7 +65,7 @@ namespace Sarand.Net.Standard.Base.CodeTypes public static ulong MaxTextLen { get; private set; } //------------------------------------------------------------------- - // Retrieve Table details (eg. name: 'Company'). + // Retrieve Table details. public static int GetTableCount () { return tableCount; @@ -123,8 +123,7 @@ namespace Sarand.Net.Standard.Base.CodeTypes String tableName = StringUtil.EmptyOnNull(tableAlias); if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column)); columnName = tableName + (tableName.Length > 0 ? "." : "") + columnName; - if (braces) - columnName = "(" + columnName + ")"; + if (braces) columnName = $"({columnName})"; } return columnName; } @@ -157,11 +156,11 @@ namespace Sarand.Net.Standard.Base.CodeTypes case DbReservedWordDelim.None: break; case DbReservedWordDelim.DoubleQuotes: - word = "\"" + word + "\""; + word = $"\"{word}\""; break; case DbReservedWordDelim.SquareBrackets: default: - word = "[" + word + "]"; + word = $"[{word}]"; break; } return word; @@ -303,80 +302,80 @@ namespace Sarand.Net.Standard.Base.CodeTypes // Reserved words. private static readonly HashSet reservedWords = new HashSet() { - "ADD", - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "ASC", - "AVG", - "BEGIN", - "BETWEEN", - "BY", - "CASE", - "CAST", - "COLUMN", - "COMMIT", - "CONSTRAINT", - "CONVERT", - "COUNT", - "CREATE", - "CURRENCY", - "DEFAULT", - "DELETE", - "DESC", - "DISTINCT", - "DROP", - "ELSE", - "END", - "EXECUTE", - "EXISTS", - "FALSE", - "FROM", - "GRANT", - "GROUP", - "HAVING", - "IN", - "INDEX", - "INNER", - "INSERT", - "INTO", - "IS", - "JOIN", - "KEY", - "LEFT", - "LIKE", - "MAX", - "MIN", - "NOT", - "NULL", - "ON", - "OR", - "ORDER", - "OUTER", - "OUTPUT", - "PRIMARY", - "PROCEDURE", - "REVOKE", - "ROLLBACK", - "ROWCOUNT", - "SELECT", - "SET", - "SQL", - "SUM", - "TABLE", - "THEN", - "TRANSACTION", - "TRUE", - "UNION", - "UNIQUE", - "UPDATE", - "USER", - "VALUES", - "VIEW", - "WHEN", - "WHERE", + "ADD", + "ALL", + "ALTER", + "AND", + "ANY", + "AS", + "ASC", + "AVG", + "BEGIN", + "BETWEEN", + "BY", + "CASE", + "CAST", + "COLUMN", + "COMMIT", + "CONSTRAINT", + "CONVERT", + "COUNT", + "CREATE", + "CURRENCY", + "DEFAULT", + "DELETE", + "DESC", + "DISTINCT", + "DROP", + "ELSE", + "END", + "EXECUTE", + "EXISTS", + "FALSE", + "FROM", + "GRANT", + "GROUP", + "HAVING", + "IN", + "INDEX", + "INNER", + "INSERT", + "INTO", + "IS", + "JOIN", + "KEY", + "LEFT", + "LIKE", + "MAX", + "MIN", + "NOT", + "NULL", + "ON", + "OR", + "ORDER", + "OUTER", + "OUTPUT", + "PRIMARY", + "PROCEDURE", + "REVOKE", + "ROLLBACK", + "ROWCOUNT", + "SELECT", + "SET", + "SQL", + "SUM", + "TABLE", + "THEN", + "TRANSACTION", + "TRUE", + "UNION", + "UNIQUE", + "UPDATE", + "USER", + "VALUES", + "VIEW", + "WHEN", + "WHERE" }; //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/Core/DataValue.cs b/SacsStandardBase/Base/Core/DataValue.cs index f6586f8..92e21a2 100644 --- a/SacsStandardBase/Base/Core/DataValue.cs +++ b/SacsStandardBase/Base/Core/DataValue.cs @@ -1,7 +1,7 @@ -using System; -using System.Collections.Generic; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; namespace Sarand.Net.Standard.Base.Core { @@ -250,7 +250,7 @@ namespace Sarand.Net.Standard.Base.Core if (dataType == DataType.Decimal) { SaLogger.Warn($"{SysUtil.Fn} Data type: {dataType.ToString()}."); - return (double)(decimal)value; + return Convert.ToDouble((decimal)value); } if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}."); return 0.0; @@ -259,6 +259,12 @@ namespace Sarand.Net.Standard.Base.Core { if (dataType == DataType.Decimal) return (decimal)value; if (dataType == DataType.Unknown) return 0.00m; + // Aug-2018 Temporarily allow decimal values to be returned as double. + if (dataType == DataType.Double) + { + SaLogger.Warn($"{SysUtil.Fn} Data type: {dataType.ToString()}."); + return Convert.ToDecimal((double)value); + } if (SacsSystem.DebugMode) SaLogger.Debug($"{SysUtil.Fn} Incorrect data type: {dataType.ToString()}."); return 0.00m; } diff --git a/SacsStandardBase/Base/Dbas/DbDfnTable.cs b/SacsStandardBase/Base/Dbas/DbDfnTable.cs index 1466f0f..ba46a6e 100644 --- a/SacsStandardBase/Base/Dbas/DbDfnTable.cs +++ b/SacsStandardBase/Base/Dbas/DbDfnTable.cs @@ -1,8 +1,7 @@ -using System; +using Sarand.Net.Standard.Base.Utils; +using System; using System.Collections.Generic; using System.Linq; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Base.Dbas { @@ -48,6 +47,18 @@ namespace Sarand.Net.Standard.Base.Dbas return (this.Name.EqualsCI(name)); } + //------------------------------------------------------------------- + // Utilities. + + public void ChangeTableName(String newName) + { + this.Name = newName; + foreach (DbDfnColumn columnDfn in Columns) + columnDfn.Table = newName; + foreach (DbDfnIndex indexDfn in Indices) + indexDfn.Table = newName; + } + //------------------------------------------------------------------- // Columns. public bool HasColumnByName(String columnName) @@ -157,6 +168,7 @@ namespace Sarand.Net.Standard.Base.Dbas //------------------------------------------------------------------- } + //======================================================================= // Table list extensions. public static class DbDfnTableList diff --git a/SacsStandardBase/Base/Interfaces/SaInterface.cs b/SacsStandardBase/Base/Interfaces/SaInterface.cs index 9b31169..6162309 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterface.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterface.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; namespace Sarand.Net.Standard.Base.Interfaces { @@ -56,7 +56,7 @@ namespace Sarand.Net.Standard.Base.Interfaces // Data members. private readonly DataProperties data = new DataProperties(); // Construction. - public Data () + public Data() { Status = DefaultStatus; } @@ -93,7 +93,7 @@ namespace Sarand.Net.Standard.Base.Interfaces set { SetFlag(Flag_Active, value); } } // Population. - internal void PopulateFrom (Data data) + internal void PopulateFrom(Data data) { Context = data.Context; Category = data.Category; @@ -102,7 +102,7 @@ namespace Sarand.Net.Standard.Base.Interfaces Caption = data.Caption; base.PopulateFrom(data); } - public Data Clone () + public Data Clone() { Data data = new Data(); data.PopulateFrom(this); @@ -130,7 +130,7 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // Construction. - public SaInterface (SysId id, String context, SaInterfaceCategory category, short type) : + public SaInterface(SysId id, String context, SaInterfaceCategory category, short type) : base(id) { base.SetData(data); @@ -149,7 +149,7 @@ namespace Sarand.Net.Standard.Base.Interfaces public static SaStatus DefaultStatus { get { return ActiveStatus; } } public static SaStatus ActiveStatus { get { return SaStatus.Active; } } public static List ValidStatuses { get { return new List(validStatuses); } } - public static DataValue.TriStateType GetStatusTriState (SaStatus status) + public static DataValue.TriStateType GetStatusTriState(SaStatus status) { switch (status) { @@ -161,10 +161,17 @@ namespace Sarand.Net.Standard.Base.Interfaces return Core.DataValue.TriStateType.Unknown; } + //------------------------------------------------------------------- + // Utilities. + public ItemId GetItemId() + { + return new ItemId((short)SaDataItemType.Interface, Id); + } + //------------------------------------------------------------------- // Properties. - public Data GetData () { return data.Clone(); } - public void SetData (Data data) + public Data GetData() { return data.Clone(); } + public void SetData(Data data) { // Properties that cannot be changed if previously specified. if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id)) @@ -173,7 +180,7 @@ namespace Sarand.Net.Standard.Base.Interfaces throw new NotSupportedException($"{SysUtil.Fn} Context cannot be changed"); if ((int)Category >= 0 && (int)Category != (int)data.Category) throw new NotSupportedException($"{SysUtil.Fn} Category cannot be changed"); - if (Type >= 0 && Type != data.Type) + if (Type >= 0 && Type != data.Type) throw new NotSupportedException($"{SysUtil.Fn} Type cannot be changed"); // Populate individual properties to ensure that 'Changed' indicator is kept up to date. this.data.PopulateFrom(data); @@ -230,6 +237,7 @@ namespace Sarand.Net.Standard.Base.Interfaces public String Context { get; set; } public SaInterfaceCategory InterfaceCategory { get; set; } = SaInterfaceCategory.Unknown; public HashSet InterfaceTypesIncluded { get; } = new HashSet(); + public String Search { get; set; } /// Exact code match public String Code { get; set; } public String CaptionPartial { get; set; } @@ -250,11 +258,11 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // E x i s t s //------------------------------------------------------------------- - public static bool ExistsByContextCategoryType (this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) + public static bool ExistsByContextCategoryType(this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) { return interfaces.Exists(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType); } - public static bool ExistsByContextCategoryType (this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) + public static bool ExistsByContextCategoryType(this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) { return interfaces.Exists(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType); } @@ -262,19 +270,19 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // F i n d A l l //------------------------------------------------------------------- - public static List FindAllByContextCategory (this List interfaces, String context, SaInterfaceCategory interfaceCategory) + public static List FindAllByContextCategory(this List interfaces, String context, SaInterfaceCategory interfaceCategory) { return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory); } - public static List FindAllByContextCategory (this List interfaces, String context, SaInterfaceCategory interfaceCategory) + public static List FindAllByContextCategory(this List interfaces, String context, SaInterfaceCategory interfaceCategory) { return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory); } - public static List FindAllByContextCategoryType (this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) + public static List FindAllByContextCategoryType(this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) { return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType); } - public static List FindAllByContextCategoryType (this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) + public static List FindAllByContextCategoryType(this List interfaces, String context, SaInterfaceCategory interfaceCategory, short interfaceType) { return interfaces.FindAll(item => item.Context.EqualsCI(context) && item.Category == interfaceCategory && item.Type == interfaceType); } diff --git a/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs b/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs index 9a70cbd..31611db 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs @@ -16,7 +16,7 @@ namespace Sarand.Net.Standard.Base.Interfaces // Interface definition. public class SaInterfaceDfn { - public SaInterfaceDfn (String context, SaInterfaceCategory category, TypeCodeDesc typeDfn, bool duplicatesAllowed) + public SaInterfaceDfn(String context, SaInterfaceCategory category, TypeCodeDesc typeDfn, bool duplicatesAllowed) { Context = context; Category = category; @@ -36,13 +36,13 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // Static initialisation. - static SaInterfaceConsole () + static SaInterfaceConsole() { } //------------------------------------------------------------------- // Construction. - protected SaInterfaceConsole () + protected SaInterfaceConsole() { } protected override void Dispose(bool disposing) @@ -64,26 +64,26 @@ namespace Sarand.Net.Standard.Base.Interfaces //--------------------------------------------------------------- // Manage interfaces - displays dialog. - public abstract bool ManageInterfaces (String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo); + public abstract bool ManageInterfaces(String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo); //--------------------------------------------------------------- // Utilities. - public abstract String GetItemTypeDesc (short itemType); - public abstract String GetItemCaption (ItemId itemId); + public abstract String GetItemTypeDesc(short itemType); + public abstract String GetItemCaption(ItemId itemId); //--------------------------------------------------------------- // Interface item option definitions. - public abstract List GetInterfaceItemOptionDfns (SaInterfaceCategory interfaceCategory, short interfaceType); - public abstract List GetInterfaceItemOptionDfns (SysId interfaceId); + public abstract List GetInterfaceItemOptionDfns(SaInterfaceCategory interfaceCategory, short interfaceType); + public abstract List GetInterfaceItemOptionDfns(SysId interfaceId); //------------------------------------------------------------------- // I n t e r f a c e R e g i s t r a t i o n //------------------------------------------------------------------- - public bool HasRegisteredInterfaces () + public bool HasRegisteredInterfaces() { return (interfaceDfns.Count > 0); } - protected void RegisterInterfaces (String context, SaInterfaceCategory category, List types, bool allowDuplicates) + protected void RegisterInterfaces(String context, SaInterfaceCategory category, List types, bool allowDuplicates) { foreach (TypeCodeDesc typeDfn in types) { @@ -94,11 +94,11 @@ namespace Sarand.Net.Standard.Base.Interfaces interfaceDfns.Add(interfaceDfn); } } - public void ClearRegisteredInterfaces () + public void ClearRegisteredInterfaces() { interfaceDfns.Clear(); } - public List GetInterfaceDfns (String context, bool createOnly) + public List GetInterfaceDfns(String context, bool createOnly) { List interfaceDfns = new List(); foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context))) @@ -108,7 +108,7 @@ namespace Sarand.Net.Standard.Base.Interfaces } return interfaceDfns; } - public bool HasInterfaceDfns (String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly) + public bool HasInterfaceDfns(String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly) { List interfaceDfns = new List(); foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context) && ((int)interfaceCategory < 1 || item.Category == interfaceCategory) && ((int)interfaceType < 1 || item.InterfaceType == interfaceType))) @@ -118,7 +118,7 @@ namespace Sarand.Net.Standard.Base.Interfaces } return false; } - public List GetInterfaceDfns (String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly) + public List GetInterfaceDfns(String context, SaInterfaceCategory interfaceCategory, short interfaceType, bool createOnly) { List interfaceDfns = new List(); foreach (SaInterfaceDfn dfn in this.interfaceDfns.FindAll(item => item.Context.EqualsCI(context) && ((int)interfaceCategory < 1 || item.Category == interfaceCategory) && ((int)interfaceType < 1 || item.InterfaceType == interfaceType))) @@ -128,7 +128,7 @@ namespace Sarand.Net.Standard.Base.Interfaces } return interfaceDfns; } - public virtual String GetInterfaceTypeDesc (String context, SaInterfaceCategory category, short type) + public virtual String GetInterfaceTypeDesc(String context, SaInterfaceCategory category, short type) { SaInterfaceDfn dfn = interfaceDfns.Find(item => item.Context.EqualsCI(context) && item.Category == category && item.InterfaceType == type); if (dfn != null) @@ -139,78 +139,83 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // I n t e r f a c e A c c e s s C o n t r o l //------------------------------------------------------------------- - public abstract bool CanCreateInterfaces (); - public abstract bool CanCreateInterfaces (String context, SaInterfaceCategory interfaceCategory); - public abstract bool CanCreateInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType); - public abstract bool AreMultipleInterfaceInstancesAllowed (String context, SaInterfaceCategory interfaceCategory, short interfaceType); - public abstract bool AreMultipleActiveInterfacesAllowed (String context, SaInterfaceCategory interfaceCategory); - public abstract bool CanUpdateInterface (SaInterface interfaceObj); - public abstract bool CanCopyInterfaces (); - public abstract bool CanCopyInterfaces (String context, SaInterfaceCategory interfaceCategory); - public abstract bool CanCopyInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType); - public abstract bool CanCopyInterface (SaInterface interfaceObj); - public abstract bool IsCompatibleForInterfaceCopy (String context, SaInterfaceCategory interfaceCategory, int typeFrom, int typeTo); - public abstract bool CanRemoveInterface (SaInterface interfaceObj); + public abstract bool CanCreateInterfaces(); + public abstract bool CanCreateInterfaces(String context, SaInterfaceCategory interfaceCategory); + public abstract bool CanCreateInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType); + public abstract bool AreMultipleInterfaceInstancesAllowed(String context, SaInterfaceCategory interfaceCategory, short interfaceType); + public abstract bool AreMultipleActiveInterfacesAllowed(String context, SaInterfaceCategory interfaceCategory); + public abstract bool CanUpdateInterface(SaInterface interfaceObj); + public abstract bool CanCopyInterfaces(); + public abstract bool CanCopyInterfaces(String context, SaInterfaceCategory interfaceCategory); + public abstract bool CanCopyInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType); + public abstract bool CanCopyInterface(SaInterface interfaceObj); + public abstract bool IsCompatibleForInterfaceCopy(String context, SaInterfaceCategory interfaceCategory, int typeFrom, int typeTo); + public abstract bool CanRemoveInterface(SaInterface interfaceObj); // Interface management. - public abstract SysId CreateInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType, String code, String caption, DbUpdateInfo dbUpdateInfo); + public abstract SysId CreateInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType, String code, String caption, DbUpdateInfo dbUpdateInfo); + public abstract bool UpdateInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo); // Associated events. - public abstract void OnInterfaceCreated (SysId interfaceId); - public abstract void OnInterfaceUpdated (SysId interfaceId); - public abstract void OnInterfaceRemoved (SysId interfaceId); + public abstract void OnInterfaceCreated(SysId interfaceId); + public abstract void OnInterfaceUpdated(SysId interfaceId); + public abstract void OnInterfaceRemoved(SysId interfaceId); // Clear configuration options, data items, processes etc. - public abstract bool ClearDependentData (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo); + public abstract bool ClearDependentData(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo); //--------------------------------------------------------------- // Process interface. - public abstract bool CanProcessInterface (SaInterface interfaceObj); - public abstract bool ProcessInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo); + public abstract bool CanProcessInterface(SaInterface interfaceObj); + public abstract bool ProcessInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo); //--------------------------------------------------------------- // Retrieve interfaces. - public abstract SaInterface GetInterfaceById (SysId interfaceId); - public abstract SaInterface GetInterface (SaInterface.Params prmInterface); - public abstract List GetInterfaceList (SaInterface.Params prmInterface); + public abstract SaInterface GetInterfaceById(SysId interfaceId); + public abstract SaInterface GetInterface(SaInterface.Params prmInterface); + public abstract ColumnDfn GetInterfaceColumnDfn(SaInterface.Column columnId, string caption = "", int width = 0); + public abstract long GetInterfaceCount(SaInterface.Params prmInterface); + public abstract List GetInterfaceList(SaInterface.Params prmInterface); + public abstract DbResultSet ExecuteInterfaceQuery(List columns, SaInterface.Params prm); + public abstract DataValue GetInterfaceDataValue(ColumnDfn column, NamedValue.Map values); //--------------------------------------------------------------- // Conversion between Interface Category & Code and the equivalent database Id. - public abstract SysId GetInterfaceIdForContextCategoryType (String context, SaInterfaceCategory interfaceCategory, short interfaceType); - public abstract SysId GetInterfaceIdForContextCategoryCode (String context, SaInterfaceCategory interfaceCategory, String code); - public abstract SaInterfaceCategory GetCategoryForInterfaceId (SysId interfaceId); - public abstract String GetCodeForInterfaceId (SysId interfaceId); + public abstract SysId GetInterfaceIdForContextCategoryType(String context, SaInterfaceCategory interfaceCategory, short interfaceType); + public abstract SysId GetInterfaceIdForContextCategoryCode(String context, SaInterfaceCategory interfaceCategory, String code); + public abstract SaInterfaceCategory GetCategoryForInterfaceId(SysId interfaceId); + public abstract String GetCodeForInterfaceId(SysId interfaceId); //--------------------------------------------------------------- // I n t e r f a c e P r o c e s s e s //--------------------------------------------------------------- // Identify the highest sequence currently in use for an interface. - public abstract int GetMaxProcessSequence (SysId interfaceId, SaInterfaceProcessDirection processDirection, bool completedOnly = true); + public abstract int GetMaxProcessSequence(SysId interfaceId, SaInterfaceProcessDirection processDirection, bool completedOnly = true); // Create new process and imediately store details on database (status set to 'In Progress'). - public abstract SaInterfaceProcess StartInterfaceProcess (SysId interfaceId, SaInterfaceProcessDirection eDirection, String batchRef, DateTime batchAt, int sequence, DbUpdateInfo dbUpdateInfo); + public abstract SaInterfaceProcess StartInterfaceProcess(SysId interfaceId, SaInterfaceProcessDirection eDirection, String batchRef, DateTime batchAt, int sequence, DbUpdateInfo dbUpdateInfo); // Retrieve a process using its identity (restricted by interface). - public abstract SaInterfaceProcess GetInterfaceProcess (SysId interfaceId, SysId interfaceProcessId); + public abstract SaInterfaceProcess GetInterfaceProcess(SysId interfaceId, SysId interfaceProcessId); // Update the details for a process. - public abstract bool StoreInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo); + public abstract bool StoreInterfaceProcess(SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo); //--------------------------------------------------------------- // I n t e r f a c e P r o c e s s M e s s a g e s //--------------------------------------------------------------- - public abstract bool LogInterfaceProcessMessage (SysId interfaceProcessId, DbUpdateInfo dbUpdateInfo, String message, SaMessageLevel messageLevel = SaMessageLevel.Info, String Filename = "", int LineNumber = 0, ItemId ItemId = null); + public abstract bool LogInterfaceProcessMessage(SysId interfaceProcessId, DbUpdateInfo dbUpdateInfo, String message, SaMessageLevel messageLevel = SaMessageLevel.Info, String Filename = "", int LineNumber = 0, ItemId ItemId = null); //--------------------------------------------------------------- // I n t e r f a c e D a t a I t e m s //--------------------------------------------------------------- - public abstract bool ItemHasDataItems (ItemId itemId); - public abstract bool InterfaceDataItemExistsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); - public abstract SaInterfaceDataItem CreateInterfaceDataItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference); - public abstract SaInterfaceDataItem GetInterfaceDataItem (SysId interfaceDataItemId); + public abstract bool ItemHasDataItems(ItemId itemId); + public abstract bool InterfaceDataItemExistsByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); + public abstract SaInterfaceDataItem CreateInterfaceDataItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference); + public abstract SaInterfaceDataItem GetInterfaceDataItem(SysId interfaceDataItemId); /// Fails if more than 1 matching data item. - public abstract SaInterfaceDataItem GetInterfaceDataItemByItemRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference); + public abstract SaInterfaceDataItem GetInterfaceDataItemByItemRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference); /// Fails if more than 1 matching data item. - public abstract SaInterfaceDataItem GetInterfaceDataItemByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); + public abstract SaInterfaceDataItem GetInterfaceDataItemByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); /// Fails if more than 1 matching data item. - public abstract SaInterfaceDataItem GetInterfaceDataItemByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId); - public abstract List GetInterfaceDataItemsByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId); - public abstract List GetInterfaceDataItemsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); - public abstract bool StoreInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo); - public abstract bool StoreInterfaceDataItems (List interfaceDataItems, DbUpdateInfo dbUpdateInfo); - public abstract bool ClearInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo); - public abstract bool ClearInterfaceDataItems (ItemId itemId, DbUpdateInfo dbUpdateInfo); + public abstract SaInterfaceDataItem GetInterfaceDataItemByItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId); + public abstract List GetInterfaceDataItemsByItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId); + public abstract List GetInterfaceDataItemsByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference); + public abstract bool StoreInterfaceDataItem(SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo); + public abstract bool StoreInterfaceDataItems(List interfaceDataItems, DbUpdateInfo dbUpdateInfo); + public abstract bool ClearInterfaceDataItem(SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo); + public abstract bool ClearInterfaceDataItems(ItemId itemId, DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- } diff --git a/SacsStandardBase/Base/Interfaces/SaInterfaceDataItem.cs b/SacsStandardBase/Base/Interfaces/SaInterfaceDataItem.cs index 6a648d1..afaaec3 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterfaceDataItem.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterfaceDataItem.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; namespace Sarand.Net.Standard.Base.Interfaces { @@ -57,10 +57,10 @@ namespace Sarand.Net.Standard.Base.Interfaces public String ExternalReference { get; set; } = String.Empty; public SaStatus ProcessStatus { get; set; } = SaStatus.Unknown; public SysId ProcessStatusBy { get; set; } = null; - public DateTime ProcessStatusAt { get; set; } = DateTime.MinValue; + public DateTime? ProcessStatusAt { get; set; } = DateTime.MinValue; public SaStatus ItemStatus { get; set; } = SaStatus.Unknown; public SysId ItemStatusBy { get; set; } = null; - public DateTime ItemStatusAt { get; set; } = DateTime.MinValue; + public DateTime? ItemStatusAt { get; set; } = DateTime.MinValue; } //------------------------------------------------------------------- @@ -70,7 +70,7 @@ namespace Sarand.Net.Standard.Base.Interfaces // Data members. private readonly DataProperties data = new DataProperties(); // Construction. - public Data () + public Data() { ProcessStatus = DefaultProcessStatus; ItemStatus = DefaultItemStatus; @@ -106,10 +106,10 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.ProcessStatusBy; } set { CheckChanged(data.ProcessStatusBy, value); data.ProcessStatusBy = value; } } - public DateTime ProcessStatusAt + public DateTime? ProcessStatusAt { get { return data.ProcessStatusAt; } - set { CheckChanged(data.ProcessStatusAt, value); data.ProcessStatusAt = value; } + set { CheckChangedNullable(data.ProcessStatusAt, value); data.ProcessStatusAt = value; } } public SaStatus ItemStatus { @@ -121,13 +121,13 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.ItemStatusBy; } set { CheckChanged(data.ItemStatusBy, value); data.ItemStatusBy = value; } } - public DateTime ItemStatusAt + public DateTime? ItemStatusAt { get { return data.ItemStatusAt; } - set { CheckChanged(data.ItemStatusAt, value); data.ItemStatusAt = value; } + set { CheckChangedNullable(data.ItemStatusAt, value); data.ItemStatusAt = value; } } // Population. - internal void PopulateFrom (Data data) + internal void PopulateFrom(Data data) { InterfaceId = data.InterfaceId; Direction = data.Direction; @@ -141,7 +141,7 @@ namespace Sarand.Net.Standard.Base.Interfaces ItemStatusAt = data.ItemStatusAt; base.PopulateFrom(data); } - public Data Clone () + public Data Clone() { Data data = new Data(); data.PopulateFrom(this); @@ -175,7 +175,7 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // Construction. - public SaInterfaceDataItem (SysId id, SysId interfaceId, SaInterfaceProcessDirection direction, ItemId itemId, String externalReference) : + public SaInterfaceDataItem(SysId id, SysId interfaceId, SaInterfaceProcessDirection direction, ItemId itemId, String externalReference) : base(id) { base.SetData(data); @@ -202,7 +202,7 @@ namespace Sarand.Net.Standard.Base.Interfaces public static SaStatus CancelledProcessStatus { get { return SaStatus.Cancelled; } } public static SaStatus FailedProcessStatus { get { return SaStatus.Failed; } } public static List ValidProcessStatuses { get { return new List(validProcessStatuses); } } - public static DataValue.TriStateType GetProcessStatusTriState (SaStatus status) + public static DataValue.TriStateType GetProcessStatusTriState(SaStatus status) { switch (status) { @@ -231,7 +231,7 @@ namespace Sarand.Net.Standard.Base.Interfaces }; public static SaStatus DefaultItemStatus { get { return SaStatus.Unknown; } } public static List ValidItemStatuses { get { return new List(validItemStatuses); } } - public static DataValue.TriStateType GetItemStatusTriState (SaStatus status) + public static DataValue.TriStateType GetItemStatusTriState(SaStatus status) { switch (status) { @@ -250,8 +250,8 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // Properties. - public Data GetData () { return data.Clone(); } - public void SetData (Data data) + public Data GetData() { return data.Clone(); } + public void SetData(Data data) { // Properties that cannot be changed if previously specified. if (SysId.IsValid(Id) && SysId.ToInt(Id) != SysId.ToInt(data.Id)) @@ -299,7 +299,7 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.ProcessStatusBy; } set { data.ProcessStatusBy = value; } } - public DateTime ProcessStatusAt + public DateTime? ProcessStatusAt { get { return data.ProcessStatusAt; } set { data.ProcessStatusAt = value; } @@ -314,7 +314,7 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.ItemStatusBy; } set { data.ItemStatusBy = value; } } - public DateTime ItemStatusAt + public DateTime? ItemStatusAt { get { return data.ItemStatusAt; } set { data.ItemStatusAt = value; } diff --git a/SacsStandardBase/Base/Interfaces/SaInterfaceDbDfn.cs b/SacsStandardBase/Base/Interfaces/SaInterfaceDbDfn.cs index 5894e9d..0930963 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterfaceDbDfn.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterfaceDbDfn.cs @@ -1,3 +1,4 @@ +using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Utils; using System; @@ -5,7 +6,7 @@ using System.Collections.Generic; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Base.Interfaces { @@ -27,7 +28,7 @@ namespace Sarand.Net.Standard.Base.Interfaces // Column identifiers. public enum ColumnIdx { - Unknown = 0, + Unknown = 0, SaInterface_Id, SaInterface_Context, SaInterface_Code, @@ -113,22 +114,39 @@ namespace Sarand.Net.Standard.Base.Interfaces // Data members. private static readonly int tableCount = 5; private static readonly int columnCount = 79; - private static ulong maxTextLen = 0; + public static ulong MaxTextLen { get; private set; } //------------------------------------------------------------------- - // Retrieve Table details (eg. name: 'Company'). + // Retrieve Table details. public static int GetTableCount () { return tableCount; } + public static String GetSchemaName (TableIdx table, bool delimitReservedWords = true) + { + int tableIdx = (int)table - 1; + if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; + String schemaName = tables[(int)tableIdx].Schema; + if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); } + return schemaName; + } public static String GetTableName (TableIdx table, bool delimitReservedWords = true) { int tableIdx = (int)table - 1; if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; - String tableName = tables[(int)tableIdx]; + String tableName = tables[(int)tableIdx].Name; if (delimitReservedWords) tableName = DelimitReservedWord(tableName); return tableName; } + public static String GetTableNameQual (TableIdx table, bool delimitReservedWords = true) + { + int tableIdx = (int)table - 1; + if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; + String schemaName = tables[(int)tableIdx].Schema; + String tableName = tables[(int)tableIdx].Name; + if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); tableName = DelimitReservedWord(tableName); } + return (StringUtil.IsBlank(schemaName) ? "" : schemaName + ".") + tableName; + } //------------------------------------------------------------------- // Identify the table that corresponds with the specified column. @@ -157,8 +175,7 @@ namespace Sarand.Net.Standard.Base.Interfaces String tableName = StringUtil.EmptyOnNull(tableAlias); if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column)); columnName = tableName + (tableName.Length > 0 ? "." : "") + columnName; - if (braces) - columnName = "(" + columnName + ")"; + if (braces) columnName = $"({columnName})"; } return columnName; } @@ -178,17 +195,24 @@ namespace Sarand.Net.Standard.Base.Interfaces } public static String DelimitReservedWord (String word) { - if (!IsReservedWord(word)) return word; - switch (reservedWordDelim) + return IsReservedWord(word) ? DelimitWord(word) : word; + } + public static String DelimitWord (String word) + { + return DelimitWord(word, reservedWordDelim); + } + public static String DelimitWord (String word, DbReservedWordDelim wordDelim) + { + switch (wordDelim) { case DbReservedWordDelim.None: break; case DbReservedWordDelim.DoubleQuotes: - word = "\"" + word + "\""; + word = $"\"{word}\""; break; case DbReservedWordDelim.SquareBrackets: default: - word = "[" + word + "]"; + word = $"[{word}]"; break; } return word; @@ -210,7 +234,7 @@ namespace Sarand.Net.Standard.Base.Interfaces } public static void SetMaxTextLen (ulong maxTextLen) { - SaInterfaceDbDfn.maxTextLen = maxTextLen; + SaInterfaceDbDfn.MaxTextLen = maxTextLen; } public static bool IsColFmtText (ColumnIdx column) { @@ -225,7 +249,7 @@ namespace Sarand.Net.Standard.Base.Interfaces if (columns[columnIdx].DataType == DbColumnDataType.VarChar) { ulong textLen = columns[columnIdx].DataLen; - if (maxTextLen > 0 && textLen > maxTextLen) textLen = maxTextLen; + if (MaxTextLen > 0 && textLen > MaxTextLen) textLen = MaxTextLen; return textLen; } return 0; @@ -256,18 +280,28 @@ namespace Sarand.Net.Standard.Base.Interfaces //------------------------------------------------------------------- // Table definitions. - private static readonly String[] tables = + private class TableDfn { - "SaInterface", - "SaInterfaceDataItem", - "SaInterfaceProcess", - "SaInterfaceProcessDataItem", - "SaInterfaceProcessMessage", + internal String Schema { get; set; } + internal String Name { get; set; } + internal TableDfn (String schema, String name) + { + this.Schema= schema; + this.Name = name; + } + } + private static readonly TableDfn[] tables = + { + new TableDfn("dbo","SaInterface"), + new TableDfn("dbo","SaInterfaceDataItem"), + new TableDfn("dbo","SaInterfaceProcess"), + new TableDfn("dbo","SaInterfaceProcessDataItem"), + new TableDfn("dbo","SaInterfaceProcessMessage"), }; //------------------------------------------------------------------- // Table column definitions. - internal class ColumnDfn + private class ColumnDfn { internal TableIdx TableIdx { get; set; } internal String Name { get; set; } @@ -285,8 +319,6 @@ namespace Sarand.Net.Standard.Base.Interfaces this.DataLen = dataLen; } } - - //------------------------------------------------------------------- private static readonly ColumnDfn[] columns = { new ColumnDfn(1,"Id",4,4,false,10), @@ -294,7 +326,7 @@ namespace Sarand.Net.Standard.Base.Interfaces new ColumnDfn(1,"Code",0,-9,false,32), new ColumnDfn(1,"Category",3,5,false,5), new ColumnDfn(1,"Type",3,5,false,5), - new ColumnDfn(1,"Caption",0,-9,false,50), + new ColumnDfn(1,"Caption",0,-9,false,100), new ColumnDfn(1,"Notes",0,-9,false,255), new ColumnDfn(1,"Flags",3,5,false,5), new ColumnDfn(1,"Status",0,-9,false,3), @@ -354,8 +386,8 @@ namespace Sarand.Net.Standard.Base.Interfaces new ColumnDfn(4,"UpdateHost",0,-9,false,64), new ColumnDfn(5,"Id",4,4,false,10), new ColumnDfn(5,"ProcessId",4,4,false,10), - new ColumnDfn(5,"MsgType",0,12,false,3), - new ColumnDfn(5,"Msg",0,-9,false,1024), + new ColumnDfn(5,"MsgType",0,-9,false,3), + new ColumnDfn(5,"Msg",0,-9,false,4000), new ColumnDfn(5,"FileName",0,-9,false,64), new ColumnDfn(5,"LineNumber",4,4,false,10), new ColumnDfn(5,"ItemType",3,5,false,5), @@ -364,90 +396,90 @@ namespace Sarand.Net.Standard.Base.Interfaces new ColumnDfn(5,"Status",0,12,false,3), new ColumnDfn(5,"CreateOn",9,93,false,23), new ColumnDfn(5,"CreateBy",4,4,false,10), - new ColumnDfn(5,"CreateHost",0,-9,false,64), + new ColumnDfn(5,"CreateHost",0,12,false,64), new ColumnDfn(5,"UpdateOn",9,93,false,23), new ColumnDfn(5,"UpdateBy",4,4,false,10), - new ColumnDfn(5,"UpdateHost",0,-9,false,64), + new ColumnDfn(5,"UpdateHost",0,12,false,64), }; //------------------------------------------------------------------- // Reserved words. private static readonly HashSet reservedWords = new HashSet() { - "ADD", - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "ASC", - "AVG", - "BEGIN", - "BETWEEN", - "BY", - "CASE", - "CAST", - "COLUMN", - "COMMIT", - "CONSTRAINT", - "CONVERT", - "COUNT", - "CREATE", - "CURRENCY", - "DEFAULT", - "DELETE", - "DESC", - "DISTINCT", - "DROP", - "ELSE", - "END", - "EXECUTE", - "EXISTS", - "FALSE", - "FROM", - "GRANT", - "GROUP", - "HAVING", - "IN", - "INDEX", - "INNER", - "INSERT", - "INTO", - "IS", - "JOIN", - "KEY", - "LEFT", - "LIKE", - "MAX", - "MIN", - "NOT", - "NULL", - "ON", - "OR", - "ORDER", - "OUTER", - "OUTPUT", - "PRIMARY", - "PROCEDURE", - "REVOKE", - "ROLLBACK", - "ROWCOUNT", - "SELECT", - "SET", - "SQL", - "SUM", - "TABLE", - "THEN", - "TRANSACTION", - "TRUE", - "UNION", - "UNIQUE", - "UPDATE", - "USER", - "VALUES", - "VIEW", - "WHEN", - "WHERE", + "ADD", + "ALL", + "ALTER", + "AND", + "ANY", + "AS", + "ASC", + "AVG", + "BEGIN", + "BETWEEN", + "BY", + "CASE", + "CAST", + "COLUMN", + "COMMIT", + "CONSTRAINT", + "CONVERT", + "COUNT", + "CREATE", + "CURRENCY", + "DEFAULT", + "DELETE", + "DESC", + "DISTINCT", + "DROP", + "ELSE", + "END", + "EXECUTE", + "EXISTS", + "FALSE", + "FROM", + "GRANT", + "GROUP", + "HAVING", + "IN", + "INDEX", + "INNER", + "INSERT", + "INTO", + "IS", + "JOIN", + "KEY", + "LEFT", + "LIKE", + "MAX", + "MIN", + "NOT", + "NULL", + "ON", + "OR", + "ORDER", + "OUTER", + "OUTPUT", + "PRIMARY", + "PROCEDURE", + "REVOKE", + "ROLLBACK", + "ROWCOUNT", + "SELECT", + "SET", + "SQL", + "SUM", + "TABLE", + "THEN", + "TRANSACTION", + "TRUE", + "UNION", + "UNIQUE", + "UPDATE", + "USER", + "VALUES", + "VIEW", + "WHEN", + "WHERE" }; //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/Interfaces/SaInterfaceProcess.cs b/SacsStandardBase/Base/Interfaces/SaInterfaceProcess.cs index f61d16c..a9586a3 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterfaceProcess.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterfaceProcess.cs @@ -1,8 +1,8 @@ -using System; -using System.Collections.Generic; -using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; namespace Sarand.Net.Standard.Base.Interfaces { @@ -60,8 +60,8 @@ namespace Sarand.Net.Standard.Base.Interfaces public SaInterfaceProcessDirection Direction { get; set; } = SaInterfaceProcessDirection.Unknown; public String Reference { get; set; } = String.Empty; public int Sequence { get; set; } = 0; - public DateTime ProcessAt { get; set; } = DateTime.MinValue; - public DateTime BatchAt { get; set; } = DateTime.MinValue; + public DateTime? ProcessAt { get; set; } = DateTime.MinValue; + public DateTime? BatchAt { get; set; } = DateTime.MinValue; public int ElapseSecs { get; set; } = 0; } @@ -97,15 +97,15 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.Sequence; } set { CheckChanged(data.Sequence, value); data.Sequence = value; } } - public DateTime ProcessAt + public DateTime? ProcessAt { get { return data.ProcessAt; } - set { CheckChanged(data.ProcessAt, value); data.ProcessAt = value; } + set { CheckChangedNullable(data.ProcessAt, value); data.ProcessAt = value; } } - public DateTime BatchAt + public DateTime? BatchAt { get { return data.BatchAt; } - set { CheckChanged(data.BatchAt, value); data.BatchAt = value; } + set { CheckChangedNullable(data.BatchAt, value); data.BatchAt = value; } } public int ElapseSecs { @@ -237,12 +237,12 @@ namespace Sarand.Net.Standard.Base.Interfaces get { return data.Sequence; } protected set { data.Sequence = value; } } - public DateTime ProcessAt + public DateTime? ProcessAt { get { return data.ProcessAt; } set { data.ProcessAt = value; } } - public DateTime BatchAt + public DateTime? BatchAt { get { return data.BatchAt; } set { data.BatchAt = value; } diff --git a/SacsStandardBase/Base/ItemOptions/SaItemOptionDbDfn.cs b/SacsStandardBase/Base/ItemOptions/SaItemOptionDbDfn.cs index 991c57b..88428a6 100644 --- a/SacsStandardBase/Base/ItemOptions/SaItemOptionDbDfn.cs +++ b/SacsStandardBase/Base/ItemOptions/SaItemOptionDbDfn.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:21 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Base.ItemOptions { @@ -24,7 +24,7 @@ namespace Sarand.Net.Standard.Base.ItemOptions // Column identifiers. public enum ColumnIdx { - Unknown = 0, + Unknown = 0, SaItemOption_ItemType, SaItemOption_ItemId, SaItemOption_Name, @@ -48,7 +48,7 @@ namespace Sarand.Net.Standard.Base.ItemOptions public static ulong MaxTextLen { get; private set; } //------------------------------------------------------------------- - // Retrieve Table details (eg. name: 'Company'). + // Retrieve Table details. public static int GetTableCount () { return tableCount; @@ -106,8 +106,7 @@ namespace Sarand.Net.Standard.Base.ItemOptions String tableName = StringUtil.EmptyOnNull(tableAlias); if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column)); columnName = tableName + (tableName.Length > 0 ? "." : "") + columnName; - if (braces) - columnName = "(" + columnName + ")"; + if (braces) columnName = $"({columnName})"; } return columnName; } @@ -140,11 +139,11 @@ namespace Sarand.Net.Standard.Base.ItemOptions case DbReservedWordDelim.None: break; case DbReservedWordDelim.DoubleQuotes: - word = "\"" + word + "\""; + word = $"\"{word}\""; break; case DbReservedWordDelim.SquareBrackets: default: - word = "[" + word + "]"; + word = $"[{word}]"; break; } return word; @@ -269,80 +268,80 @@ namespace Sarand.Net.Standard.Base.ItemOptions // Reserved words. private static readonly HashSet reservedWords = new HashSet() { - "ADD", - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "ASC", - "AVG", - "BEGIN", - "BETWEEN", - "BY", - "CASE", - "CAST", - "COLUMN", - "COMMIT", - "CONSTRAINT", - "CONVERT", - "COUNT", - "CREATE", - "CURRENCY", - "DEFAULT", - "DELETE", - "DESC", - "DISTINCT", - "DROP", - "ELSE", - "END", - "EXECUTE", - "EXISTS", - "FALSE", - "FROM", - "GRANT", - "GROUP", - "HAVING", - "IN", - "INDEX", - "INNER", - "INSERT", - "INTO", - "IS", - "JOIN", - "KEY", - "LEFT", - "LIKE", - "MAX", - "MIN", - "NOT", - "NULL", - "ON", - "OR", - "ORDER", - "OUTER", - "OUTPUT", - "PRIMARY", - "PROCEDURE", - "REVOKE", - "ROLLBACK", - "ROWCOUNT", - "SELECT", - "SET", - "SQL", - "SUM", - "TABLE", - "THEN", - "TRANSACTION", - "TRUE", - "UNION", - "UNIQUE", - "UPDATE", - "USER", - "VALUES", - "VIEW", - "WHEN", - "WHERE", + "ADD", + "ALL", + "ALTER", + "AND", + "ANY", + "AS", + "ASC", + "AVG", + "BEGIN", + "BETWEEN", + "BY", + "CASE", + "CAST", + "COLUMN", + "COMMIT", + "CONSTRAINT", + "CONVERT", + "COUNT", + "CREATE", + "CURRENCY", + "DEFAULT", + "DELETE", + "DESC", + "DISTINCT", + "DROP", + "ELSE", + "END", + "EXECUTE", + "EXISTS", + "FALSE", + "FROM", + "GRANT", + "GROUP", + "HAVING", + "IN", + "INDEX", + "INNER", + "INSERT", + "INTO", + "IS", + "JOIN", + "KEY", + "LEFT", + "LIKE", + "MAX", + "MIN", + "NOT", + "NULL", + "ON", + "OR", + "ORDER", + "OUTER", + "OUTPUT", + "PRIMARY", + "PROCEDURE", + "REVOKE", + "ROLLBACK", + "ROWCOUNT", + "SELECT", + "SET", + "SQL", + "SUM", + "TABLE", + "THEN", + "TRANSACTION", + "TRUE", + "UNION", + "UNIQUE", + "UPDATE", + "USER", + "VALUES", + "VIEW", + "WHEN", + "WHERE" }; //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/Security/SaSecurityDbDfn.cs b/SacsStandardBase/Base/Security/SaSecurityDbDfn.cs index 5afad9a..4e69482 100644 --- a/SacsStandardBase/Base/Security/SaSecurityDbDfn.cs +++ b/SacsStandardBase/Base/Security/SaSecurityDbDfn.cs @@ -6,7 +6,7 @@ using System.Collections.Generic; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:20 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Base.Security { @@ -25,7 +25,7 @@ namespace Sarand.Net.Standard.Base.Security // Column identifiers. public enum ColumnIdx { - Unknown = 0, + Unknown = 0, SaSecItem_Id, SaSecItem_Code, SaSecItem_Description, @@ -74,7 +74,7 @@ namespace Sarand.Net.Standard.Base.Security public static ulong MaxTextLen { get; private set; } //------------------------------------------------------------------- - // Retrieve Table details (eg. name: 'Company'). + // Retrieve Table details. public static int GetTableCount () { return tableCount; @@ -132,8 +132,7 @@ namespace Sarand.Net.Standard.Base.Security String tableName = StringUtil.EmptyOnNull(tableAlias); if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column)); columnName = tableName + (tableName.Length > 0 ? "." : "") + columnName; - if (braces) - columnName = "(" + columnName + ")"; + if (braces) columnName = $"({columnName})"; } return columnName; } @@ -166,11 +165,11 @@ namespace Sarand.Net.Standard.Base.Security case DbReservedWordDelim.None: break; case DbReservedWordDelim.DoubleQuotes: - word = "\"" + word + "\""; + word = $"\"{word}\""; break; case DbReservedWordDelim.SquareBrackets: default: - word = "[" + word + "]"; + word = $"[{word}]"; break; } return word; @@ -321,80 +320,80 @@ namespace Sarand.Net.Standard.Base.Security // Reserved words. private static readonly HashSet reservedWords = new HashSet() { - "ADD", - "ALL", - "ALTER", - "AND", - "ANY", - "AS", - "ASC", - "AVG", - "BEGIN", - "BETWEEN", - "BY", - "CASE", - "CAST", - "COLUMN", - "COMMIT", - "CONSTRAINT", - "CONVERT", - "COUNT", - "CREATE", - "CURRENCY", - "DEFAULT", - "DELETE", - "DESC", - "DISTINCT", - "DROP", - "ELSE", - "END", - "EXECUTE", - "EXISTS", - "FALSE", - "FROM", - "GRANT", - "GROUP", - "HAVING", - "IN", - "INDEX", - "INNER", - "INSERT", - "INTO", - "IS", - "JOIN", - "KEY", - "LEFT", - "LIKE", - "MAX", - "MIN", - "NOT", - "NULL", - "ON", - "OR", - "ORDER", - "OUTER", - "OUTPUT", - "PRIMARY", - "PROCEDURE", - "REVOKE", - "ROLLBACK", - "ROWCOUNT", - "SELECT", - "SET", - "SQL", - "SUM", - "TABLE", - "THEN", - "TRANSACTION", - "TRUE", - "UNION", - "UNIQUE", - "UPDATE", - "USER", - "VALUES", - "VIEW", - "WHEN", - "WHERE", + "ADD", + "ALL", + "ALTER", + "AND", + "ANY", + "AS", + "ASC", + "AVG", + "BEGIN", + "BETWEEN", + "BY", + "CASE", + "CAST", + "COLUMN", + "COMMIT", + "CONSTRAINT", + "CONVERT", + "COUNT", + "CREATE", + "CURRENCY", + "DEFAULT", + "DELETE", + "DESC", + "DISTINCT", + "DROP", + "ELSE", + "END", + "EXECUTE", + "EXISTS", + "FALSE", + "FROM", + "GRANT", + "GROUP", + "HAVING", + "IN", + "INDEX", + "INNER", + "INSERT", + "INTO", + "IS", + "JOIN", + "KEY", + "LEFT", + "LIKE", + "MAX", + "MIN", + "NOT", + "NULL", + "ON", + "OR", + "ORDER", + "OUTER", + "OUTPUT", + "PRIMARY", + "PROCEDURE", + "REVOKE", + "ROLLBACK", + "ROWCOUNT", + "SELECT", + "SET", + "SQL", + "SUM", + "TABLE", + "THEN", + "TRANSACTION", + "TRUE", + "UNION", + "UNIQUE", + "UPDATE", + "USER", + "VALUES", + "VIEW", + "WHEN", + "WHERE" }; //------------------------------------------------------------------- diff --git a/SacsStandardDbas/Dbas/Base/DatabaseDefinitionGenerator.cs b/SacsStandardDbas/Dbas/Base/DatabaseDefinitionGenerator.cs index c900a3c..6a6a3fa 100644 --- a/SacsStandardDbas/Dbas/Base/DatabaseDefinitionGenerator.cs +++ b/SacsStandardDbas/Dbas/Base/DatabaseDefinitionGenerator.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text.RegularExpressions; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.IO; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text.RegularExpressions; namespace Sarand.Net.Standard.Dbas.Base { @@ -101,7 +101,8 @@ namespace Sarand.Net.Standard.Dbas.Base // Data members. private Config config = null; private const String DefaultSchema_MSSQL = "dbo"; - private static String /*lf = "\n",*/ crlf = "\r\n", tab1 = "\t", tab2 = "\t\t", tab3 = "\t\t\t", tab4 = "\t\t\t\t", tab5 = "\t\t\t\t\t"; + private static String /*lf = "\n",*/ crlf = "\r\n", tab1 = "\t", tab2 = "\t\t", tab3 = "\t\t\t", tab4 = "\t\t\t\t"; /*, tab5 = "\t\t\t\t\t";*/ + // Reserved words. private static readonly String[] reservedWords = { @@ -118,7 +119,7 @@ namespace Sarand.Net.Standard.Dbas.Base // Validate configuration. this.config = config; if (!FileUtil.IsDirectory(config.OutputDirectory)) - throw new Exception("Invalid directory specified [" + config.OutputDirectory + "]"); + throw new Exception($"Invalid directory specified [{config.OutputDirectory}]"); // Validate and cleanse configuration parameters. if (StringUtil.IsEmpty(StringUtil.TrimAll(config.TableClass.BaseClass))) @@ -136,6 +137,24 @@ namespace Sarand.Net.Standard.Dbas.Base // Table definitions. List tableDfns = new List(config.Database.GetTableDfns()); + // Convert 'Alternative' table names found in database to standard table names. + Dictionary tablesByName = tableDfns.ToDictionary(tbl => tbl.Name, tbl => tbl); + foreach (DbDfnTable tableDfn in tableDfns) + { + // Check whether tabl name is in 'Alternative' list. + String standardTableName = config.Schema.AlternativeTableNames.Where(kv => kv.Value.ContainsCI(tableDfn.Name)).Select(kv => kv.Key).FirstOrDefault(); + if (StringUtil.IsBlank(standardTableName)) continue; + + // Check that 'Standard' table name isn't already used. + if (tablesByName.ContainsKey(standardTableName)) + throw new Exception($"Cannot map alternative table name '{tableDfn.Name}' to standard table name '{standardTableName}' as standard table name already exists in database."); + + // Rename table. + tablesByName.Remove(tableDfn.Name); + tableDfn.ChangeTableName(standardTableName); + tablesByName[tableDfn.Name] = tableDfn; + } + // Database schema XML. GenerateDatabaseSchemaXml(tableDfns.Where(item => IsValidTable(item.Name, DefinitionOutput.DatabaseSchema))); @@ -152,8 +171,9 @@ namespace Sarand.Net.Standard.Dbas.Base private bool IsValidTable(String table, DefinitionOutput output) { if (String.IsNullOrEmpty(table)) return false; - if (config.Schema.Tables_Included.Count > 0 && !config.Schema.Tables_Included.ContainsCI(table)) return false; - if (config.Schema.Tables_Excluded.Count > 0 && config.Schema.Tables_Excluded.ContainsCI(table)) return false; + if (config.Schema.Tables_Included.Any() && !config.Schema.Tables_Included.ContainsCI(table) && !config.Schema.Tables_Included.Any(tbl => config.Schema.AlternativeTableNames.GetValueOrDefault(tbl)?.ContainsCI(table) ?? false)) + return false; + if (config.Schema.Tables_Excluded.ContainsCI(table)) return false; // Tables excluded from specific output. if (output == DefinitionOutput.DatabaseSchema && config.Schema.Tables_ExcludedFromDatabaseSchema.Contains(table)) return false; if (output == DefinitionOutput.DatabaseDefinitionClass && config.Schema.Tables_ExcludedFromDatabaseDefinitionClass.Contains(table)) return false; @@ -267,23 +287,23 @@ namespace Sarand.Net.Standard.Dbas.Base { // Database definition file: foreach (String namespace_Base in config.DefinitionClass.Usings.OrderBy(s => s)) - file.WriteLine("using " + namespace_Base + ";"); + file.WriteLine($"using {namespace_Base};"); file.WriteLine("using System;"); file.WriteLine("using System.Collections.Generic;"); file.WriteLine("using System.Linq;"); file.WriteLine(""); file.WriteLine("//---------------------------------------------------------------------------"); - file.WriteLine("// Code generated by Sarand Database Utilities " + DateTime.Now.Format("ddd d-MMM-yyyy HH:mm:ss")); + file.WriteLine($"// Code generated by Sarand Database Utilities {DateTime.Now.Format("ddd d-MMM-yyyy HH:mm:ss")}"); file.WriteLine("//---------------------------------------------------------------------------"); - file.WriteLine("namespace " + config.DefinitionClass.Namespace); + file.WriteLine($"namespace {config.DefinitionClass.Namespace}"); file.WriteLine("{"); - file.WriteLine(tab1 + "public class " + config.DefinitionClass.Classname); - file.WriteLine(tab1 + "{"); - file.WriteLine(tab2 + "//-------------------------------------------------------------------"); + file.WriteLine($"{tab1}public class {config.DefinitionClass.Classname}"); + file.WriteLine($"{tab1}{{"); GenerateDatabaseDefinitionTablesEnum(tableDfns, file); GenerateDatabaseDefinitionColumnsEnum(tableDfns, file); GenerateDatabaseDefinitionClass(tableDfns, config.DefinitionClass.Classname, file); - file.WriteLine(tab1 + "}"); + file.WriteLine($"{crlf}{tab2}//-------------------------------------------------------------------"); + file.WriteLine($"{tab1}}}"); file.WriteLine("}"); //file.Close(); - Unecessary as the object will be disposed at the end of the 'using' block which is the same as Close. } @@ -294,270 +314,279 @@ namespace Sarand.Net.Standard.Dbas.Base //------------------------------------------------------------------- public static void GenerateDatabaseDefinitionTablesEnum(IEnumerable tableDfns, StreamWriter file) { - file.WriteLine(tab2 + "// Table identifiers."); - file.WriteLine(tab2 + "public enum TableIdx"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "Unknown = 0,"); + // No need or CR before opening comment line as at top of class. + file.WriteLine(@" //------------------------------------------------------------------- + // Table identifiers. + public enum TableIdx + { + Unknown = 0,"); foreach (DbDfnTable tableDfn in tableDfns) - { - file.WriteLine(tab3 + tableDfn.Name + ","); - } - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine($"{tab3}{tableDfn.Name},"); + file.WriteLine($"{tab2}}}"); } //------------------------------------------------------------------- public static void GenerateDatabaseDefinitionColumnsEnum(IEnumerable tableDfns, StreamWriter file) { - file.WriteLine(tab2 + "// Column identifiers."); - file.WriteLine(tab2 + "public enum ColumnIdx"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "Unknown = 0,"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Column identifiers. + public enum ColumnIdx + { + Unknown = 0,"); foreach (DbDfnTable tableDfn in tableDfns) { foreach (var columnDfn in tableDfn.Columns) - file.WriteLine(tab3 + tableDfn.Name + "_" + columnDfn.Name + ","); + file.WriteLine($"{tab3}{tableDfn.Name}_{columnDfn.Name},"); } - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine($"{tab2}}}"); } //------------------------------------------------------------------- public static void GenerateDatabaseDefinitionClass(IEnumerable tableDfns, String classnameDefinition, StreamWriter file) { - file.WriteLine(tab2 + "// Data members."); - file.WriteLine(tab2 + "private static readonly int tableCount = " + tableDfns.Count() + ";"); - file.WriteLine(tab2 + "private static readonly int columnCount = " + tableDfns.GetColumnCount() + ";"); - file.WriteLine(tab2 + "public static ulong MaxTextLen { get; private set; }"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + // Data members. + file.WriteLine(@$" + //------------------------------------------------------------------- + // Data members. + private static readonly int tableCount = {tableDfns.Count()}; + private static readonly int columnCount = {tableDfns.GetColumnCount()}; + public static ulong MaxTextLen {{ get; private set; }}"); // Table methods. - file.WriteLine(tab2 + "// Retrieve Table details (eg. name: 'Company')."); - file.WriteLine(tab2 + "public static int GetTableCount ()"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "return tableCount;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String GetSchemaName (TableIdx table, bool delimitReservedWords = true)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int tableIdx = (int)table - 1;"); - file.WriteLine(tab3 + "if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;"); - file.WriteLine(tab3 + "String schemaName = tables[(int)tableIdx].Schema;"); - file.WriteLine(tab3 + "if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); }"); - file.WriteLine(tab3 + "return schemaName;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String GetTableName (TableIdx table, bool delimitReservedWords = true)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int tableIdx = (int)table - 1;"); - file.WriteLine(tab3 + "if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;"); - file.WriteLine(tab3 + "String tableName = tables[(int)tableIdx].Name;"); - file.WriteLine(tab3 + "if (delimitReservedWords) tableName = DelimitReservedWord(tableName);"); - file.WriteLine(tab3 + "return tableName;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String GetTableNameQual (TableIdx table, bool delimitReservedWords = true)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int tableIdx = (int)table - 1;"); - file.WriteLine(tab3 + "if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty;"); - file.WriteLine(tab3 + "String schemaName = tables[(int)tableIdx].Schema;"); - file.WriteLine(tab3 + "String tableName = tables[(int)tableIdx].Name;"); - file.WriteLine(tab3 + "if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); tableName = DelimitReservedWord(tableName); }"); - file.WriteLine(tab3 + "return (StringUtil.IsBlank(schemaName) ? \"\" : schemaName + \".\") + tableName;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Retrieve Table details. + public static int GetTableCount () + { + return tableCount; + } + public static String GetSchemaName (TableIdx table, bool delimitReservedWords = true) + { + int tableIdx = (int)table - 1; + if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; + String schemaName = tables[(int)tableIdx].Schema; + if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); } + return schemaName; + } + public static String GetTableName (TableIdx table, bool delimitReservedWords = true) + { + int tableIdx = (int)table - 1; + if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; + String tableName = tables[(int)tableIdx].Name; + if (delimitReservedWords) tableName = DelimitReservedWord(tableName); + return tableName; + } + public static String GetTableNameQual (TableIdx table, bool delimitReservedWords = true) + { + int tableIdx = (int)table - 1; + if (tableIdx < 0 || tableIdx >= tableCount) return String.Empty; + String schemaName = tables[(int)tableIdx].Schema; + String tableName = tables[(int)tableIdx].Name; + if (delimitReservedWords) { schemaName = DelimitReservedWord(schemaName); tableName = DelimitReservedWord(tableName); } + return (StringUtil.IsBlank(schemaName) ? """" : schemaName + ""."") + tableName; + }"); // Table for Column method. - file.WriteLine(tab2 + "// Identify the table that corresponds with the specified column."); - file.WriteLine(tab2 + "public static TableIdx GetTableForColumn (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return TableIdx.Unknown;"); - file.WriteLine(tab3 + "return columns[columnIdx].TableIdx;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Identify the table that corresponds with the specified column. + public static TableIdx GetTableForColumn (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return TableIdx.Unknown; + return columns[columnIdx].TableIdx; + }"); // Column methods. - file.WriteLine(tab2 + "// Retrieve the specified Column's name (Qualified include table name: '(.Column>)')."); - file.WriteLine(tab2 + "public static String GetColumnName (ColumnIdx column, bool delimitReservedWords = true)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return String.Empty;"); - file.WriteLine(tab3 + "String columnName = columns[columnIdx].Name;"); - file.WriteLine(tab3 + "if (delimitReservedWords) columnName = DelimitReservedWord(columnName);"); - file.WriteLine(tab3 + "return columnName;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String GetColumnNameQual (ColumnIdx column, String tableAlias = \"\", bool braces = false)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "String columnName = GetColumnName(column);"); - file.WriteLine(tab3 + "if (!String.IsNullOrEmpty(columnName))"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "String tableName = StringUtil.EmptyOnNull(tableAlias);"); - file.WriteLine(tab4 + "if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column));"); - file.WriteLine(tab4 + "columnName = tableName + (tableName.Length > 0 ? \".\" : \"\") + columnName;"); - file.WriteLine(tab4 + "if (braces)"); - file.WriteLine(tab5 + "columnName = \"(\" + columnName + \")\";"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab3 + "return columnName;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Retrieve the specified Column's name (Qualified include table name: '(
.Column>)'). + public static String GetColumnName (ColumnIdx column, bool delimitReservedWords = true) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return String.Empty; + String columnName = columns[columnIdx].Name; + if (delimitReservedWords) columnName = DelimitReservedWord(columnName); + return columnName; + } + public static String GetColumnNameQual (ColumnIdx column, String tableAlias = """", bool braces = false) + { + String columnName = GetColumnName(column); + if (!String.IsNullOrEmpty(columnName)) + { + String tableName = StringUtil.EmptyOnNull(tableAlias); + if (tableName.IsEmpty()) tableName = GetTableName(GetTableForColumn(column)); + columnName = tableName + (tableName.Length > 0 ? ""."" : """") + columnName; + if (braces) columnName = $""({columnName})""; + } + return columnName; + }"); // Reserved word methods. - file.WriteLine(tab2 + "// Reserved words."); - file.WriteLine(tab2 + "private static DbReservedWordDelim reservedWordDelim = DbReservedWordDelim.SquareBrackets;"); - file.WriteLine(tab2 + "public static void SetReservedWordDelim (DbReservedWordDelim reservedWordDelim)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + classnameDefinition + ".reservedWordDelim = reservedWordDelim;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static bool IsReservedWord (String word)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "if (String.IsNullOrEmpty(word)) return false;"); - file.WriteLine(tab3 + "if (reservedWords.Contains(word, StringComparer.OrdinalIgnoreCase)) return true;"); - file.WriteLine(tab3 + "return false;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String DelimitReservedWord (String word)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "return IsReservedWord(word) ? DelimitWord(word) : word;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String DelimitWord (String word)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "return DelimitWord(word, reservedWordDelim);"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static String DelimitWord (String word, DbReservedWordDelim wordDelim)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "switch (wordDelim)"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "case DbReservedWordDelim.None:"); - file.WriteLine(tab5 + "break;"); - file.WriteLine(tab4 + "case DbReservedWordDelim.DoubleQuotes:"); - file.WriteLine(tab5 + "word = \"\\\"\" + word + \"\\\"\"; "); - file.WriteLine(tab5 + "break;"); - file.WriteLine(tab4 + "case DbReservedWordDelim.SquareBrackets:"); - file.WriteLine(tab4 + "default:"); - file.WriteLine(tab5 + "word = \"[\" + word + \"]\"; "); - file.WriteLine(tab5 + "break;"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab3 + "return word;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Reserved words. + private static DbReservedWordDelim reservedWordDelim = DbReservedWordDelim.SquareBrackets; + public static void SetReservedWordDelim (DbReservedWordDelim reservedWordDelim) + { + " + classnameDefinition + @".reservedWordDelim = reservedWordDelim; + } + public static bool IsReservedWord (String word) + { + if (String.IsNullOrEmpty(word)) return false; + if (reservedWords.Contains(word, StringComparer.OrdinalIgnoreCase)) return true; + return false; + } + public static String DelimitReservedWord (String word) + { + return IsReservedWord(word) ? DelimitWord(word) : word; + } + public static String DelimitWord (String word) + { + return DelimitWord(word, reservedWordDelim); + } + public static String DelimitWord (String word, DbReservedWordDelim wordDelim) + { + switch (wordDelim) + { + case DbReservedWordDelim.None: + break; + case DbReservedWordDelim.DoubleQuotes: + word = $""\""{word}\""""; + break; + case DbReservedWordDelim.SquareBrackets: + default: + word = $""[{word}]""; + break; + } + return word; + }"); // Column information methods. - file.WriteLine(tab2 + "// Retrieve information about the specified Column."); - file.WriteLine(tab2 + "public static DbColumnDataType GetColDataType (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return DbColumnDataType.Unknown;"); - file.WriteLine(tab3 + "return columns[columnIdx].DataType;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static short GetColNativeDataType (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return 0;"); - file.WriteLine(tab3 + "return columns[columnIdx].NativeDataType;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static void SetMaxTextLen (ulong maxTextLen)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + classnameDefinition + ".MaxTextLen = maxTextLen;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static bool IsColFmtText (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return false;"); - file.WriteLine(tab3 + "return (columns[columnIdx].DataType == DbColumnDataType.VarChar);"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static ulong GetColTextLen (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return 0;"); - file.WriteLine(tab3 + "if (columns[columnIdx].DataType == DbColumnDataType.VarChar)"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "ulong textLen = columns[columnIdx].DataLen;"); - file.WriteLine(tab4 + "if (MaxTextLen > 0 && textLen > MaxTextLen) textLen = MaxTextLen;"); - file.WriteLine(tab4 + "return textLen;"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab3 + "return 0;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static bool IsColFmtBool (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return false;"); - file.WriteLine(tab3 + "return (columns[columnIdx].DataType == DbColumnDataType.Bit);"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "public static bool IsColFmtNumeric (ColumnIdx column)"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "int columnIdx = (int)column - 1;"); - file.WriteLine(tab3 + "if (columnIdx < 0 || columnIdx >= columnCount) return false;"); - file.WriteLine(tab3 + "switch (columns[columnIdx].DataType)"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "case DbColumnDataType.TinyInt:"); - file.WriteLine(tab4 + "case DbColumnDataType.SmallInt:"); - file.WriteLine(tab4 + "case DbColumnDataType.Int:"); - file.WriteLine(tab4 + "case DbColumnDataType.BigInt:"); - file.WriteLine(tab4 + "case DbColumnDataType.Single:"); - file.WriteLine(tab4 + "case DbColumnDataType.Double:"); - file.WriteLine(tab4 + "case DbColumnDataType.Decimal:"); - file.WriteLine(tab5 + "return true;"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab3 + "return false;"); - file.WriteLine(tab2 + "}"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Retrieve information about the specified Column. + public static DbColumnDataType GetColDataType (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return DbColumnDataType.Unknown; + return columns[columnIdx].DataType; + } + public static short GetColNativeDataType (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return 0; + return columns[columnIdx].NativeDataType; + } + public static void SetMaxTextLen (ulong maxTextLen) + { + " + classnameDefinition + @".MaxTextLen = maxTextLen; + } + public static bool IsColFmtText (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return false; + return (columns[columnIdx].DataType == DbColumnDataType.VarChar); + } + public static ulong GetColTextLen (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return 0; + if (columns[columnIdx].DataType == DbColumnDataType.VarChar) + { + ulong textLen = columns[columnIdx].DataLen; + if (MaxTextLen > 0 && textLen > MaxTextLen) textLen = MaxTextLen; + return textLen; + } + return 0; + } + public static bool IsColFmtBool (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return false; + return (columns[columnIdx].DataType == DbColumnDataType.Bit); + } + public static bool IsColFmtNumeric (ColumnIdx column) + { + int columnIdx = (int)column - 1; + if (columnIdx < 0 || columnIdx >= columnCount) return false; + switch (columns[columnIdx].DataType) + { + case DbColumnDataType.TinyInt: + case DbColumnDataType.SmallInt: + case DbColumnDataType.Int: + case DbColumnDataType.BigInt: + case DbColumnDataType.Single: + case DbColumnDataType.Double: + case DbColumnDataType.Decimal: + return true; + } + return false; + }"); // Table names. - file.WriteLine(tab2 + "// Table definitions."); - file.WriteLine(tab2 + "private class TableDfn"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "internal String Schema { get; set; }"); - file.WriteLine(tab3 + "internal String Name { get; set; }"); - file.WriteLine(tab3 + "internal TableDfn (String schema, String name)"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "this.Schema= schema;"); - file.WriteLine(tab4 + "this.Name = name;"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "private static readonly TableDfn[] tables ="); - file.WriteLine(tab2 + "{"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Table definitions. + private class TableDfn + { + internal String Schema { get; set; } + internal String Name { get; set; } + internal TableDfn (String schema, String name) + { + this.Schema= schema; + this.Name = name; + } + } + private static readonly TableDfn[] tables = + {"); foreach (DbDfnTable tableDfn in tableDfns) file.WriteLine(tab3 + "new TableDfn(\"" + tableDfn.Schema + "\",\"" + tableDfn.Name + "\"),"); - file.WriteLine(tab2 + "};"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine($"{tab2}}};"); // Table Column definitions. - file.WriteLine(tab2 + "// Table column definitions."); - file.WriteLine(tab2 + "private class ColumnDfn"); - file.WriteLine(tab2 + "{"); - file.WriteLine(tab3 + "internal TableIdx TableIdx { get; set; }"); - file.WriteLine(tab3 + "internal String Name { get; set; }"); - file.WriteLine(tab3 + "internal DbColumnDataType DataType { get; set; }"); - file.WriteLine(tab3 + "internal short NativeDataType { get; set; }"); - file.WriteLine(tab3 + "internal bool IsIdentity { get; set; }"); - file.WriteLine(tab3 + "internal ulong DataLen { get; set; }"); - file.WriteLine(tab3 + "internal ColumnDfn (int tableIdx, String name, int dataType, short nativeDataType, bool isIdentity, ulong dataLen)"); - file.WriteLine(tab3 + "{"); - file.WriteLine(tab4 + "this.TableIdx = (TableIdx)tableIdx;"); - file.WriteLine(tab4 + "this.Name = name;"); - file.WriteLine(tab4 + "this.DataType = (DbColumnDataType)dataType;"); - file.WriteLine(tab4 + "this.NativeDataType = nativeDataType;"); - file.WriteLine(tab4 + "this.IsIdentity = isIdentity;"); - file.WriteLine(tab4 + "this.DataLen = dataLen;"); - file.WriteLine(tab3 + "}"); - file.WriteLine(tab2 + "}"); - file.WriteLine(tab2 + "private static readonly ColumnDfn[] columns ="); - file.WriteLine(tab2 + "{"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Table column definitions. + private class ColumnDfn + { + internal TableIdx TableIdx { get; set; } + internal String Name { get; set; } + internal DbColumnDataType DataType { get; set; } + internal short NativeDataType { get; set; } + internal bool IsIdentity { get; set; } + internal ulong DataLen { get; set; } + internal ColumnDfn (int tableIdx, String name, int dataType, short nativeDataType, bool isIdentity, ulong dataLen) + { + this.TableIdx = (TableIdx)tableIdx; + this.Name = name; + this.DataType = (DbColumnDataType)dataType; + this.NativeDataType = nativeDataType; + this.IsIdentity = isIdentity; + this.DataLen = dataLen; + } + } + private static readonly ColumnDfn[] columns = + {"); uint tableIdx = 0; foreach (DbDfnTable tableDfn in tableDfns) { tableIdx++; foreach (var columnDfn in tableDfn.Columns) - file.WriteLine(tab3 + "new ColumnDfn(" + tableIdx.ToString() + ",\"" + columnDfn.Name + "\"," + ((int)columnDfn.DataType).ToString() + "," + columnDfn.DataTypeNative.ToString() + "," + (columnDfn.IsIdentity ? "true" : "false") + "," + columnDfn.Size.ToString() + "),"); + file.WriteLine($"{tab3}new ColumnDfn({tableIdx},\"{columnDfn.Name}\",{(int)columnDfn.DataType},{columnDfn.DataTypeNative},{(columnDfn.IsIdentity ? "true" : "false")},{columnDfn.Size}),"); } - file.WriteLine(tab2 + "};"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine($"{tab2}}};"); // Reserved words. - file.WriteLine(tab2 + "// Reserved words."); - file.WriteLine(tab2 + "private static readonly HashSet reservedWords = new HashSet()"); - file.WriteLine(tab2 + "{"); - foreach (String reservedword in reservedWords) - file.WriteLine(tab3 + "\"" + reservedword + "\", "); - file.WriteLine(tab2 + "};"); - file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); + file.WriteLine(@" + //------------------------------------------------------------------- + // Reserved words. + private static readonly HashSet reservedWords = new HashSet() + { + " + reservedWords.Concat($",{crlf}{tab3}", "\"", "\"") + @" + };"); + } //------------------------------------------------------------------- @@ -631,23 +660,23 @@ namespace Sarand.Net.Standard.Dbas.Base file.WriteLine(tab2 + "// Data members."); file.WriteLine(tab2 + "protected static List fields { get; } = new List()"); file.WriteLine(tab2 + "{"); - foreach (var columnDfn in tableDfn.Columns) file.WriteLine(tab3 + "\"" + columnDfn.Name + "\","); + foreach (var columnDfn in tableDfn.Columns) file.WriteLine($"{tab3}\"{columnDfn.Name}\","); file.WriteLine(tab2 + "};"); file.WriteLine(tab2 + "protected static List fieldsId { get; } = new List()"); file.WriteLine(tab2 + "{"); - foreach (var columnDfn in tableDfn.Columns.FindAll(item => item.IsIdentity)) file.WriteLine(tab3 + "\"" + columnDfn.Name + "\","); + foreach (var columnDfn in tableDfn.Columns.FindAll(item => item.IsIdentity)) file.WriteLine($"{tab3}\"{columnDfn.Name}\","); file.WriteLine(tab2 + "};"); file.WriteLine(tab2 + "protected static List fieldsPrimary { get; } = new List()"); file.WriteLine(tab2 + "{"); - foreach (String columnName in primaryColumnNames) file.WriteLine(tab3 + "\"" + columnName + "\","); + foreach (String columnName in primaryColumnNames) file.WriteLine($"{tab3}\"{columnName}\","); file.WriteLine(tab2 + "};"); file.WriteLine(tab2 + "protected static List fieldsNullable { get; } = new List()"); file.WriteLine(tab2 + "{"); - foreach (var columnDfn in tableDfn.Columns.FindAll(item => item.IsNullable)) file.WriteLine(tab3 + "\"" + columnDfn.Name + "\","); + foreach (var columnDfn in tableDfn.Columns.FindAll(item => item.IsNullable)) file.WriteLine($"{tab3}\"{columnDfn.Name}\","); file.WriteLine(tab2 + "};"); file.WriteLine(tab2 + "protected static List fieldsIgnoreOnUpdate { get; } = new List()"); file.WriteLine(tab2 + "{"); - foreach (String columnName in columnsIgnoredOnUpdate) file.WriteLine(tab3 + "\"" + columnName + "\","); + foreach (String columnName in columnsIgnoredOnUpdate) file.WriteLine($"{tab3}\"{columnName}\","); file.WriteLine(tab2 + "};"); /* file.WriteLine(tab2 + "protected static List fieldsNonId { get; } = new List()"); @@ -668,14 +697,14 @@ namespace Sarand.Net.Standard.Dbas.Base // Properties. file.WriteLine(crlf + tab2 + "//-------------------------------------------------------------------"); file.WriteLine(tab2 + "// Properties."); - file.WriteLine(tab2 + "public override String SchemaName { get; } = \"" + tableDfn.Schema + "\";"); + file.WriteLine(tab2 + $"public override String SchemaName {{ get; }} = \"{tableDfn.Schema}\";"); if (alternativeTableNames.Count == 0) - file.WriteLine(tab2 + "public override String TableName { get; } = \"" + tableDfn.Name + "\";"); + file.WriteLine(tab2 + $"public override String TableName {{ get; }} = \"{tableDfn.Name}\";"); else { // Logic to handle alternative table names. - file.WriteLine(tab2 + "public override String TableName { get { return GetActualTableName(\"" + tableDfn.Name + "\"); } }"); - file.WriteLine(tab2 + "public override List AlternativeTableNames { get; } = new List() { " + alternativeTableNames.Concat(", ", "\"", "\"") + " };"); + file.WriteLine(tab2 + $"public override String TableName {{ get {{ return GetActualTableName(\"{tableDfn.Name}\"); }} }}"); + file.WriteLine(tab2 + $"public override List AlternativeTableNames {{ get; }} = new List() {{ {alternativeTableNames.Concat(", ", "\"", "\"")} }};"); } file.WriteLine(tab2 + "public String TableNameFmt { get { return (!String.IsNullOrEmpty(SchemaName) ? \"[\" + SchemaName + \"].\" : \"\") + \"[\" + TableName + \"]\"; } }"); file.WriteLine(tab2 + "public static List Fields { get { return new List(fields); } }"); @@ -684,7 +713,7 @@ namespace Sarand.Net.Standard.Dbas.Base file.WriteLine(tab2 + "// Columns."); file.WriteLine(tab2 + "public ColumnsData Cols { get; } = new ColumnsData();"); foreach (var columnDfn in tableDfn.Columns) - file.WriteLine(tab2 + "public " + GetColumnVariableType(columnDfn) + (TreatColumnAsNullable(columnDfn) ? "?" : "") + " _" + columnDfn.Name + " { get { return Cols._" + columnDfn.Name + ".Value; } set { Cols._" + columnDfn.Name + ".Value = value; } }"); + file.WriteLine(tab2 + $"public {GetColumnVariableType(columnDfn)}{(TreatColumnAsNullable(columnDfn) ? "?" : "")} _{columnDfn.Name} {{ get {{ return Cols._{columnDfn.Name}.Value; }} set {{ Cols._{columnDfn.Name}.Value = value; }} }}"); file.WriteLine(tab2 + "// Existing columns - confirmed on database if table exists."); file.WriteLine(tab2 + "public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } }"); file.WriteLine(tab2 + "public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } }"); diff --git a/SacsStandardDbas/Dbas/Base/SacsDatabase.cs b/SacsStandardDbas/Dbas/Base/SacsDatabase.cs index db23d83..3c34eed 100644 --- a/SacsStandardDbas/Dbas/Base/SacsDatabase.cs +++ b/SacsStandardDbas/Dbas/Base/SacsDatabase.cs @@ -1,16 +1,16 @@ -using System; +using Microsoft.Win32; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Dbas.Data; +using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; using System.Runtime.InteropServices; using System.Text; -using Microsoft.Win32; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Dbas.Data; namespace Sarand.Net.Standard.Dbas.Base { @@ -209,19 +209,24 @@ namespace Sarand.Net.Standard.Dbas.Base columnNameValues.Add(columnName, SysId.ToInt(value).ToString()); } /// Add numeric value pair - used to build value lists for insert and update. - public static void AddValuePair(List columnNameValues, String columnName, long value) + public static void AddValuePair(List columnNameValues, String columnName, Int32? value) { - columnNameValues.Add(columnName, value.ToString()); + columnNameValues.Add(columnName, value is null ? "NULL" : $"{value}"); + } + /// Add numeric value pair - used to build value lists for insert and update. + public static void AddValuePair(List columnNameValues, String columnName, Int64? value) + { + columnNameValues.Add(columnName, value is null ? "NULL" : $"{value}"); } /// Add decimal value pair - used to build value lists for insert and update. - public static void AddValuePair(List columnNameValues, String columnName, decimal value) + public static void AddValuePair(List columnNameValues, String columnName, decimal? value) { - columnNameValues.Add(columnName, value.ToString()); + columnNameValues.Add(columnName, value is null ? "NULL" : $"{value}"); } /// Add date/time value pair - used to build value lists for insert and update. - public static void AddValuePair(List columnNameValues, String columnName, DateTime value) + public static void AddValuePair(List columnNameValues, String columnName, DateTime? value) { - AddValuePair(columnNameValues, columnName, DateUtil.Format(value, "yyyy/MM/dd HH:mm:ss"), true); + AddValuePair(columnNameValues, columnName, value is null ? "NULL" : DateUtil.Format(value, "yyyy/MM/dd HH:mm:ss"), true); } // Specific queries. public abstract long GetRowCount(String tableName, String filter); diff --git a/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCodeType_Db.cs b/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCodeType_Db.cs index c2dc94a..40769ee 100644 --- a/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCodeType_Db.cs +++ b/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCodeType_Db.cs @@ -10,7 +10,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:21 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.CodeTypes.Internal { diff --git a/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCode_Db.cs b/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCode_Db.cs index 8f61393..299405d 100644 --- a/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCode_Db.cs +++ b/SacsStandardDbas/Dbas/CodeTypes/Internal/SaCode_Db.cs @@ -10,7 +10,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:21 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.CodeTypes.Internal { diff --git a/SacsStandardDbas/Dbas/CodeTypes/SaCodeTypeDbDfnGenerator.cs b/SacsStandardDbas/Dbas/CodeTypes/SaCodeTypeDbDfnGenerator.cs index d50eb9b..431862c 100644 --- a/SacsStandardDbas/Dbas/CodeTypes/SaCodeTypeDbDfnGenerator.cs +++ b/SacsStandardDbas/Dbas/CodeTypes/SaCodeTypeDbDfnGenerator.cs @@ -22,7 +22,7 @@ namespace Sarand.Net.Standard.Dbas.CodeType /// public static bool Generate(String connectionString) { - String fn = className + ".Generate"; + String fn = $"{className}.Generate"; // Locate output folder: String directory = GetOutputFolder(); @@ -87,7 +87,7 @@ namespace Sarand.Net.Standard.Dbas.CodeType //------------------------------------------------------------------- private static String GetOutputFolder() { - String fn = className + ".GetOutputFolder"; + String fn = $"{className}.GetOutputFolder"; String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location)); String directory = assemblyDirectory; SaLogger.Debug($"{fn} Assembly folder: {directory}"); diff --git a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceDataItem_Db.cs b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceDataItem_Db.cs index 407012c..2ae9506 100644 --- a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceDataItem_Db.cs +++ b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceDataItem_Db.cs @@ -1,15 +1,16 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { @@ -26,24 +27,24 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public ColumnDataInt16 _ItemType { get; } = new ColumnDataInt16("ItemType"); public ColumnDataInt32 _ItemId { get; } = new ColumnDataInt32("ItemId"); public ColumnDataString _ProcessStatus { get; } = new ColumnDataString("ProcessStatus"); - public ColumnDataInt32 _ProcessStatusBy { get; } = new ColumnDataInt32("ProcessStatusBy"); - public ColumnDataDateTime _ProcessStatusAt { get; } = new ColumnDataDateTime("ProcessStatusAt"); + public ColumnDataInt32Nullable _ProcessStatusBy { get; } = new ColumnDataInt32Nullable("ProcessStatusBy"); + public ColumnDataDateTimeNullable _ProcessStatusAt { get; } = new ColumnDataDateTimeNullable("ProcessStatusAt"); public ColumnDataString _ItemStatus { get; } = new ColumnDataString("ItemStatus"); - public ColumnDataInt32 _ItemStatusBy { get; } = new ColumnDataInt32("ItemStatusBy"); - public ColumnDataDateTime _ItemStatusAt { get; } = new ColumnDataDateTime("ItemStatusAt"); + public ColumnDataInt32Nullable _ItemStatusBy { get; } = new ColumnDataInt32Nullable("ItemStatusBy"); + public ColumnDataDateTimeNullable _ItemStatusAt { get; } = new ColumnDataDateTimeNullable("ItemStatusAt"); public ColumnDataString _Notes { get; } = new ColumnDataString("Notes"); - public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); - public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); - public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataInt16Nullable _Flags { get; } = new ColumnDataInt16Nullable("Flags"); + public ColumnDataDateTimeNullable _CreateOn { get; } = new ColumnDataDateTimeNullable("CreateOn"); + public ColumnDataInt32Nullable _CreateBy { get; } = new ColumnDataInt32Nullable("CreateBy"); public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); - public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); - public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataDateTimeNullable _UpdateOn { get; } = new ColumnDataDateTimeNullable("UpdateOn"); + public ColumnDataInt32Nullable _UpdateBy { get; } = new ColumnDataInt32Nullable("UpdateBy"); public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); } //------------------------------------------------------------------- // Data members. - private static List fields { get; } = new List() + protected static List fields { get; } = new List() { "Id", "InterfaceId", @@ -66,14 +67,32 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal "UpdateBy", "UpdateHost", }; - private static List fieldsId { get; } = new List() + protected static List fieldsId { get; } = new List() { }; - private static List fieldsPrimary { get; } = new List() + protected static List fieldsPrimary { get; } = new List() { "Id", }; - private static List fieldsIgnoreOnUpdate { get; } = new List() + protected static List fieldsNullable { get; } = new List() + { + "ExternalRef", + "ProcessStatus", + "ProcessStatusBy", + "ProcessStatusAt", + "ItemStatus", + "ItemStatusBy", + "ItemStatusAt", + "Notes", + "Flags", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; + protected static List fieldsIgnoreOnUpdate { get; } = new List() { "CreateOn", "CreateBy", @@ -108,22 +127,23 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public Int16 _ItemType { get { return Cols._ItemType.Value; } set { Cols._ItemType.Value = value; } } public Int32 _ItemId { get { return Cols._ItemId.Value; } set { Cols._ItemId.Value = value; } } public String _ProcessStatus { get { return Cols._ProcessStatus.Value; } set { Cols._ProcessStatus.Value = value; } } - public Int32 _ProcessStatusBy { get { return Cols._ProcessStatusBy.Value; } set { Cols._ProcessStatusBy.Value = value; } } - public DateTime _ProcessStatusAt { get { return Cols._ProcessStatusAt.Value; } set { Cols._ProcessStatusAt.Value = value; } } + public Int32? _ProcessStatusBy { get { return Cols._ProcessStatusBy.Value; } set { Cols._ProcessStatusBy.Value = value; } } + public DateTime? _ProcessStatusAt { get { return Cols._ProcessStatusAt.Value; } set { Cols._ProcessStatusAt.Value = value; } } public String _ItemStatus { get { return Cols._ItemStatus.Value; } set { Cols._ItemStatus.Value = value; } } - public Int32 _ItemStatusBy { get { return Cols._ItemStatusBy.Value; } set { Cols._ItemStatusBy.Value = value; } } - public DateTime _ItemStatusAt { get { return Cols._ItemStatusAt.Value; } set { Cols._ItemStatusAt.Value = value; } } + public Int32? _ItemStatusBy { get { return Cols._ItemStatusBy.Value; } set { Cols._ItemStatusBy.Value = value; } } + public DateTime? _ItemStatusAt { get { return Cols._ItemStatusAt.Value; } set { Cols._ItemStatusAt.Value = value; } } public String _Notes { get { return Cols._Notes.Value; } set { Cols._Notes.Value = value; } } - public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } - public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } - public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public Int16? _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public DateTime? _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32? _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } - public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } - public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public DateTime? _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32? _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } // Existing columns - confirmed on database if table exists. public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + public List UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } } //------------------------------------------------------------------- // Population. @@ -149,18 +169,18 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal _ItemType = GetFieldInt16(dbDataReader, "ItemType", _ItemType); _ItemId = GetFieldInt32(dbDataReader, "ItemId", _ItemId); _ProcessStatus = GetFieldString(dbDataReader, "ProcessStatus", _ProcessStatus); - _ProcessStatusBy = GetFieldInt32(dbDataReader, "ProcessStatusBy", _ProcessStatusBy); - _ProcessStatusAt = GetFieldDateTime(dbDataReader, "ProcessStatusAt", _ProcessStatusAt); + _ProcessStatusBy = GetFieldInt32Nullable(dbDataReader, "ProcessStatusBy", _ProcessStatusBy); + _ProcessStatusAt = GetFieldDateTimeNullable(dbDataReader, "ProcessStatusAt", _ProcessStatusAt); _ItemStatus = GetFieldString(dbDataReader, "ItemStatus", _ItemStatus); - _ItemStatusBy = GetFieldInt32(dbDataReader, "ItemStatusBy", _ItemStatusBy); - _ItemStatusAt = GetFieldDateTime(dbDataReader, "ItemStatusAt", _ItemStatusAt); + _ItemStatusBy = GetFieldInt32Nullable(dbDataReader, "ItemStatusBy", _ItemStatusBy); + _ItemStatusAt = GetFieldDateTimeNullable(dbDataReader, "ItemStatusAt", _ItemStatusAt); _Notes = GetFieldString(dbDataReader, "Notes", _Notes); - _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); - _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); - _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _Flags = GetFieldInt16Nullable(dbDataReader, "Flags", _Flags); + _CreateOn = GetFieldDateTimeNullable(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32Nullable(dbDataReader, "CreateBy", _CreateBy); _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); - _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); - _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateOn = GetFieldDateTimeNullable(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32Nullable(dbDataReader, "UpdateBy", _UpdateBy); _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); } @@ -212,10 +232,15 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand (DbCommand dbCommand, List columnsToUpdate = null) { // Columns to update. - List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + List columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList(); + if (!columnNames.Any()) + { + SaLogger.Warn($"{SysUtil.Fn} No columns to update. [{GetType().Name}]"); + return false; + } // Construct query. String query = "UPDATE " + TableNameFmt + " SET "; if (dbCommand is SqlCommand) diff --git a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessDataItem_Db.cs b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessDataItem_Db.cs index b8f4887..15f4879 100644 --- a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessDataItem_Db.cs +++ b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessDataItem_Db.cs @@ -1,15 +1,16 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { @@ -22,19 +23,19 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public ColumnDataInt32 _ProcessId { get; } = new ColumnDataInt32("ProcessId"); public ColumnDataInt32 _InterfaceDataItemId { get; } = new ColumnDataInt32("InterfaceDataItemId"); public ColumnDataString _ItemData { get; } = new ColumnDataString("ItemData"); - public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); + public ColumnDataInt16Nullable _Flags { get; } = new ColumnDataInt16Nullable("Flags"); public ColumnDataString _Status { get; } = new ColumnDataString("Status"); - public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); - public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataDateTimeNullable _CreateOn { get; } = new ColumnDataDateTimeNullable("CreateOn"); + public ColumnDataInt32Nullable _CreateBy { get; } = new ColumnDataInt32Nullable("CreateBy"); public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); - public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); - public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataDateTimeNullable _UpdateOn { get; } = new ColumnDataDateTimeNullable("UpdateOn"); + public ColumnDataInt32Nullable _UpdateBy { get; } = new ColumnDataInt32Nullable("UpdateBy"); public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); } //------------------------------------------------------------------- // Data members. - private static List fields { get; } = new List() + protected static List fields { get; } = new List() { "ProcessId", "InterfaceDataItemId", @@ -48,15 +49,27 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal "UpdateBy", "UpdateHost", }; - private static List fieldsId { get; } = new List() + protected static List fieldsId { get; } = new List() { }; - private static List fieldsPrimary { get; } = new List() + protected static List fieldsPrimary { get; } = new List() { "ProcessId", "InterfaceDataItemId", }; - private static List fieldsIgnoreOnUpdate { get; } = new List() + protected static List fieldsNullable { get; } = new List() + { + "ItemData", + "Flags", + "Status", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; + protected static List fieldsIgnoreOnUpdate { get; } = new List() { "CreateOn", "CreateBy", @@ -92,17 +105,18 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public Int32 _ProcessId { get { return Cols._ProcessId.Value; } set { Cols._ProcessId.Value = value; } } public Int32 _InterfaceDataItemId { get { return Cols._InterfaceDataItemId.Value; } set { Cols._InterfaceDataItemId.Value = value; } } public String _ItemData { get { return Cols._ItemData.Value; } set { Cols._ItemData.Value = value; } } - public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public Int16? _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } public String _Status { get { return Cols._Status.Value; } set { Cols._Status.Value = value; } } - public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } - public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public DateTime? _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32? _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } - public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } - public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public DateTime? _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32? _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } // Existing columns - confirmed on database if table exists. public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + public List UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } } //------------------------------------------------------------------- // Population. @@ -124,13 +138,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal _ProcessId = GetFieldInt32(dbDataReader, "ProcessId", _ProcessId); _InterfaceDataItemId = GetFieldInt32(dbDataReader, "InterfaceDataItemId", _InterfaceDataItemId); _ItemData = GetFieldString(dbDataReader, "ItemData", _ItemData); - _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); + _Flags = GetFieldInt16Nullable(dbDataReader, "Flags", _Flags); _Status = GetFieldString(dbDataReader, "Status", _Status); - _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); - _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _CreateOn = GetFieldDateTimeNullable(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32Nullable(dbDataReader, "CreateBy", _CreateBy); _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); - _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); - _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateOn = GetFieldDateTimeNullable(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32Nullable(dbDataReader, "UpdateBy", _UpdateBy); _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); } @@ -173,10 +187,15 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand (DbCommand dbCommand, List columnsToUpdate = null) { // Columns to update. - List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + List columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList(); + if (!columnNames.Any()) + { + SaLogger.Warn($"{SysUtil.Fn} No columns to update. [{GetType().Name}]"); + return false; + } // Construct query. String query = "UPDATE " + TableNameFmt + " SET "; if (dbCommand is SqlCommand) diff --git a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessMessage_Db.cs b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessMessage_Db.cs index d04c182..7470b69 100644 --- a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessMessage_Db.cs +++ b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcessMessage_Db.cs @@ -1,15 +1,16 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { @@ -24,22 +25,22 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public ColumnDataString _MsgType { get; } = new ColumnDataString("MsgType"); public ColumnDataString _Msg { get; } = new ColumnDataString("Msg"); public ColumnDataString _FileName { get; } = new ColumnDataString("FileName"); - public ColumnDataInt32 _LineNumber { get; } = new ColumnDataInt32("LineNumber"); - public ColumnDataInt16 _ItemType { get; } = new ColumnDataInt16("ItemType"); - public ColumnDataInt32 _ItemId { get; } = new ColumnDataInt32("ItemId"); - public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); + public ColumnDataInt32Nullable _LineNumber { get; } = new ColumnDataInt32Nullable("LineNumber"); + public ColumnDataInt16Nullable _ItemType { get; } = new ColumnDataInt16Nullable("ItemType"); + public ColumnDataInt32Nullable _ItemId { get; } = new ColumnDataInt32Nullable("ItemId"); + public ColumnDataInt16Nullable _Flags { get; } = new ColumnDataInt16Nullable("Flags"); public ColumnDataString _Status { get; } = new ColumnDataString("Status"); - public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); - public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataDateTimeNullable _CreateOn { get; } = new ColumnDataDateTimeNullable("CreateOn"); + public ColumnDataInt32Nullable _CreateBy { get; } = new ColumnDataInt32Nullable("CreateBy"); public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); - public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); - public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataDateTimeNullable _UpdateOn { get; } = new ColumnDataDateTimeNullable("UpdateOn"); + public ColumnDataInt32Nullable _UpdateBy { get; } = new ColumnDataInt32Nullable("UpdateBy"); public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); } //------------------------------------------------------------------- // Data members. - private static List fields { get; } = new List() + protected static List fields { get; } = new List() { "Id", "ProcessId", @@ -58,14 +59,31 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal "UpdateBy", "UpdateHost", }; - private static List fieldsId { get; } = new List() + protected static List fieldsId { get; } = new List() { }; - private static List fieldsPrimary { get; } = new List() + protected static List fieldsPrimary { get; } = new List() { "Id", }; - private static List fieldsIgnoreOnUpdate { get; } = new List() + protected static List fieldsNullable { get; } = new List() + { + "MsgType", + "Msg", + "FileName", + "LineNumber", + "ItemType", + "ItemId", + "Flags", + "Status", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; + protected static List fieldsIgnoreOnUpdate { get; } = new List() { "CreateOn", "CreateBy", @@ -102,20 +120,21 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public String _MsgType { get { return Cols._MsgType.Value; } set { Cols._MsgType.Value = value; } } public String _Msg { get { return Cols._Msg.Value; } set { Cols._Msg.Value = value; } } public String _FileName { get { return Cols._FileName.Value; } set { Cols._FileName.Value = value; } } - public Int32 _LineNumber { get { return Cols._LineNumber.Value; } set { Cols._LineNumber.Value = value; } } - public Int16 _ItemType { get { return Cols._ItemType.Value; } set { Cols._ItemType.Value = value; } } - public Int32 _ItemId { get { return Cols._ItemId.Value; } set { Cols._ItemId.Value = value; } } - public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public Int32? _LineNumber { get { return Cols._LineNumber.Value; } set { Cols._LineNumber.Value = value; } } + public Int16? _ItemType { get { return Cols._ItemType.Value; } set { Cols._ItemType.Value = value; } } + public Int32? _ItemId { get { return Cols._ItemId.Value; } set { Cols._ItemId.Value = value; } } + public Int16? _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } public String _Status { get { return Cols._Status.Value; } set { Cols._Status.Value = value; } } - public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } - public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public DateTime? _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32? _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } - public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } - public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public DateTime? _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32? _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } // Existing columns - confirmed on database if table exists. public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + public List UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } } //------------------------------------------------------------------- // Population. @@ -139,16 +158,16 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal _MsgType = GetFieldString(dbDataReader, "MsgType", _MsgType); _Msg = GetFieldString(dbDataReader, "Msg", _Msg); _FileName = GetFieldString(dbDataReader, "FileName", _FileName); - _LineNumber = GetFieldInt32(dbDataReader, "LineNumber", _LineNumber); - _ItemType = GetFieldInt16(dbDataReader, "ItemType", _ItemType); - _ItemId = GetFieldInt32(dbDataReader, "ItemId", _ItemId); - _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); + _LineNumber = GetFieldInt32Nullable(dbDataReader, "LineNumber", _LineNumber); + _ItemType = GetFieldInt16Nullable(dbDataReader, "ItemType", _ItemType); + _ItemId = GetFieldInt32Nullable(dbDataReader, "ItemId", _ItemId); + _Flags = GetFieldInt16Nullable(dbDataReader, "Flags", _Flags); _Status = GetFieldString(dbDataReader, "Status", _Status); - _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); - _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _CreateOn = GetFieldDateTimeNullable(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32Nullable(dbDataReader, "CreateBy", _CreateBy); _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); - _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); - _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateOn = GetFieldDateTimeNullable(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32Nullable(dbDataReader, "UpdateBy", _UpdateBy); _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); } @@ -196,10 +215,15 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand (DbCommand dbCommand, List columnsToUpdate = null) { // Columns to update. - List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + List columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList(); + if (!columnNames.Any()) + { + SaLogger.Warn($"{SysUtil.Fn} No columns to update. [{GetType().Name}]"); + return false; + } // Construct query. String query = "UPDATE " + TableNameFmt + " SET "; if (dbCommand is SqlCommand) diff --git a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcess_Db.cs b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcess_Db.cs index 5a2fb11..d3e01be 100644 --- a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcess_Db.cs +++ b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterfaceProcess_Db.cs @@ -1,15 +1,16 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { @@ -23,18 +24,18 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public ColumnDataInt32 _InterfaceId { get; } = new ColumnDataInt32("InterfaceId"); public ColumnDataInt16 _Direction { get; } = new ColumnDataInt16("Direction"); public ColumnDataString _ProcRef { get; } = new ColumnDataString("ProcRef"); - public ColumnDataInt32 _ProcSeq { get; } = new ColumnDataInt32("ProcSeq"); - public ColumnDataDateTime _ProcessAt { get; } = new ColumnDataDateTime("ProcessAt"); - public ColumnDataDateTime _BatchAt { get; } = new ColumnDataDateTime("BatchAt"); - public ColumnDataInt32 _ElapseSecs { get; } = new ColumnDataInt32("ElapseSecs"); - public ColumnDataInt32 _ItemCount { get; } = new ColumnDataInt32("ItemCount"); - public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); + public ColumnDataInt32Nullable _ProcSeq { get; } = new ColumnDataInt32Nullable("ProcSeq"); + public ColumnDataDateTimeNullable _ProcessAt { get; } = new ColumnDataDateTimeNullable("ProcessAt"); + public ColumnDataDateTimeNullable _BatchAt { get; } = new ColumnDataDateTimeNullable("BatchAt"); + public ColumnDataInt32Nullable _ElapseSecs { get; } = new ColumnDataInt32Nullable("ElapseSecs"); + public ColumnDataInt32Nullable _ItemCount { get; } = new ColumnDataInt32Nullable("ItemCount"); + public ColumnDataInt16Nullable _Flags { get; } = new ColumnDataInt16Nullable("Flags"); public ColumnDataString _Status { get; } = new ColumnDataString("Status"); - public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); - public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataDateTimeNullable _CreateOn { get; } = new ColumnDataDateTimeNullable("CreateOn"); + public ColumnDataInt32Nullable _CreateBy { get; } = new ColumnDataInt32Nullable("CreateBy"); public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); - public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); - public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataDateTimeNullable _UpdateOn { get; } = new ColumnDataDateTimeNullable("UpdateOn"); + public ColumnDataInt32Nullable _UpdateBy { get; } = new ColumnDataInt32Nullable("UpdateBy"); public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); } @@ -67,6 +68,23 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { "Id", }; + protected static List fieldsNullable { get; } = new List() + { + "ProcRef", + "ProcSeq", + "ProcessAt", + "BatchAt", + "ElapseSecs", + "ItemCount", + "Flags", + "Status", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; protected static List fieldsIgnoreOnUpdate { get; } = new List() { "CreateOn", @@ -102,22 +120,23 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public Int32 _InterfaceId { get { return Cols._InterfaceId.Value; } set { Cols._InterfaceId.Value = value; } } public Int16 _Direction { get { return Cols._Direction.Value; } set { Cols._Direction.Value = value; } } public String _ProcRef { get { return Cols._ProcRef.Value; } set { Cols._ProcRef.Value = value; } } - public Int32 _ProcSeq { get { return Cols._ProcSeq.Value; } set { Cols._ProcSeq.Value = value; } } - public DateTime _ProcessAt { get { return Cols._ProcessAt.Value; } set { Cols._ProcessAt.Value = value; } } - public DateTime _BatchAt { get { return Cols._BatchAt.Value; } set { Cols._BatchAt.Value = value; } } - public Int32 _ElapseSecs { get { return Cols._ElapseSecs.Value; } set { Cols._ElapseSecs.Value = value; } } - public Int32 _ItemCount { get { return Cols._ItemCount.Value; } set { Cols._ItemCount.Value = value; } } - public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public Int32? _ProcSeq { get { return Cols._ProcSeq.Value; } set { Cols._ProcSeq.Value = value; } } + public DateTime? _ProcessAt { get { return Cols._ProcessAt.Value; } set { Cols._ProcessAt.Value = value; } } + public DateTime? _BatchAt { get { return Cols._BatchAt.Value; } set { Cols._BatchAt.Value = value; } } + public Int32? _ElapseSecs { get { return Cols._ElapseSecs.Value; } set { Cols._ElapseSecs.Value = value; } } + public Int32? _ItemCount { get { return Cols._ItemCount.Value; } set { Cols._ItemCount.Value = value; } } + public Int16? _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } public String _Status { get { return Cols._Status.Value; } set { Cols._Status.Value = value; } } - public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } - public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public DateTime? _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32? _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } - public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } - public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public DateTime? _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32? _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } // Existing columns - confirmed on database if table exists. public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + public List UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } } //------------------------------------------------------------------- // Population. @@ -140,18 +159,18 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal _InterfaceId = GetFieldInt32(dbDataReader, "InterfaceId", _InterfaceId); _Direction = GetFieldInt16(dbDataReader, "Direction", _Direction); _ProcRef = GetFieldString(dbDataReader, "ProcRef", _ProcRef); - _ProcSeq = GetFieldInt32(dbDataReader, "ProcSeq", _ProcSeq); - _ProcessAt = GetFieldDateTime(dbDataReader, "ProcessAt", _ProcessAt); - _BatchAt = GetFieldDateTime(dbDataReader, "BatchAt", _BatchAt); - _ElapseSecs = GetFieldInt32(dbDataReader, "ElapseSecs", _ElapseSecs); - _ItemCount = GetFieldInt32(dbDataReader, "ItemCount", _ItemCount); - _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); + _ProcSeq = GetFieldInt32Nullable(dbDataReader, "ProcSeq", _ProcSeq); + _ProcessAt = GetFieldDateTimeNullable(dbDataReader, "ProcessAt", _ProcessAt); + _BatchAt = GetFieldDateTimeNullable(dbDataReader, "BatchAt", _BatchAt); + _ElapseSecs = GetFieldInt32Nullable(dbDataReader, "ElapseSecs", _ElapseSecs); + _ItemCount = GetFieldInt32Nullable(dbDataReader, "ItemCount", _ItemCount); + _Flags = GetFieldInt16Nullable(dbDataReader, "Flags", _Flags); _Status = GetFieldString(dbDataReader, "Status", _Status); - _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); - _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _CreateOn = GetFieldDateTimeNullable(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32Nullable(dbDataReader, "CreateBy", _CreateBy); _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); - _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); - _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateOn = GetFieldDateTimeNullable(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32Nullable(dbDataReader, "UpdateBy", _UpdateBy); _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); } @@ -200,10 +219,15 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand (DbCommand dbCommand, List columnsToUpdate = null) { // Columns to update. - List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + List columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList(); + if (!columnNames.Any()) + { + SaLogger.Warn($"{SysUtil.Fn} No columns to update. [{GetType().Name}]"); + return false; + } // Construct query. String query = "UPDATE " + TableNameFmt + " SET "; if (dbCommand is SqlCommand) diff --git a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterface_Db.cs b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterface_Db.cs index b638a06..8ca7957 100644 --- a/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterface_Db.cs +++ b/SacsStandardDbas/Dbas/Interfaces/Internal/SaInterface_Db.cs @@ -1,15 +1,16 @@ +using Microsoft.Data.SqlClient; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Utils; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:13 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Interfaces.Internal { @@ -22,23 +23,23 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public ColumnDataInt32 _Id { get; } = new ColumnDataInt32("Id"); public ColumnDataString _Context { get; } = new ColumnDataString("Context"); public ColumnDataString _Code { get; } = new ColumnDataString("Code"); - public ColumnDataInt16 _Category { get; } = new ColumnDataInt16("Category"); - public ColumnDataInt16 _Type { get; } = new ColumnDataInt16("Type"); + public ColumnDataInt16Nullable _Category { get; } = new ColumnDataInt16Nullable("Category"); + public ColumnDataInt16Nullable _Type { get; } = new ColumnDataInt16Nullable("Type"); public ColumnDataString _Caption { get; } = new ColumnDataString("Caption"); public ColumnDataString _Notes { get; } = new ColumnDataString("Notes"); - public ColumnDataInt16 _Flags { get; } = new ColumnDataInt16("Flags"); + public ColumnDataInt16Nullable _Flags { get; } = new ColumnDataInt16Nullable("Flags"); public ColumnDataString _Status { get; } = new ColumnDataString("Status"); - public ColumnDataDateTime _CreateOn { get; } = new ColumnDataDateTime("CreateOn"); - public ColumnDataInt32 _CreateBy { get; } = new ColumnDataInt32("CreateBy"); + public ColumnDataDateTimeNullable _CreateOn { get; } = new ColumnDataDateTimeNullable("CreateOn"); + public ColumnDataInt32Nullable _CreateBy { get; } = new ColumnDataInt32Nullable("CreateBy"); public ColumnDataString _CreateHost { get; } = new ColumnDataString("CreateHost"); - public ColumnDataDateTime _UpdateOn { get; } = new ColumnDataDateTime("UpdateOn"); - public ColumnDataInt32 _UpdateBy { get; } = new ColumnDataInt32("UpdateBy"); + public ColumnDataDateTimeNullable _UpdateOn { get; } = new ColumnDataDateTimeNullable("UpdateOn"); + public ColumnDataInt32Nullable _UpdateBy { get; } = new ColumnDataInt32Nullable("UpdateBy"); public ColumnDataString _UpdateHost { get; } = new ColumnDataString("UpdateHost"); } //------------------------------------------------------------------- // Data members. - private static List fields { get; } = new List() + protected static List fields { get; } = new List() { "Id", "Context", @@ -56,14 +57,29 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal "UpdateBy", "UpdateHost", }; - private static List fieldsId { get; } = new List() + protected static List fieldsId { get; } = new List() { }; - private static List fieldsPrimary { get; } = new List() + protected static List fieldsPrimary { get; } = new List() { "Id", }; - private static List fieldsIgnoreOnUpdate { get; } = new List() + protected static List fieldsNullable { get; } = new List() + { + "Context", + "Category", + "Type", + "Notes", + "Flags", + "Status", + "CreateOn", + "CreateBy", + "CreateHost", + "UpdateOn", + "UpdateBy", + "UpdateHost", + }; + protected static List fieldsIgnoreOnUpdate { get; } = new List() { "CreateOn", "CreateBy", @@ -93,21 +109,22 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal public Int32 _Id { get { return Cols._Id.Value; } set { Cols._Id.Value = value; } } public String _Context { get { return Cols._Context.Value; } set { Cols._Context.Value = value; } } public String _Code { get { return Cols._Code.Value; } set { Cols._Code.Value = value; } } - public Int16 _Category { get { return Cols._Category.Value; } set { Cols._Category.Value = value; } } - public Int16 _Type { get { return Cols._Type.Value; } set { Cols._Type.Value = value; } } + public Int16? _Category { get { return Cols._Category.Value; } set { Cols._Category.Value = value; } } + public Int16? _Type { get { return Cols._Type.Value; } set { Cols._Type.Value = value; } } public String _Caption { get { return Cols._Caption.Value; } set { Cols._Caption.Value = value; } } public String _Notes { get { return Cols._Notes.Value; } set { Cols._Notes.Value = value; } } - public Int16 _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } + public Int16? _Flags { get { return Cols._Flags.Value; } set { Cols._Flags.Value = value; } } public String _Status { get { return Cols._Status.Value; } set { Cols._Status.Value = value; } } - public DateTime _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } - public Int32 _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } + public DateTime? _CreateOn { get { return Cols._CreateOn.Value; } set { Cols._CreateOn.Value = value; } } + public Int32? _CreateBy { get { return Cols._CreateBy.Value; } set { Cols._CreateBy.Value = value; } } public String _CreateHost { get { return Cols._CreateHost.Value; } set { Cols._CreateHost.Value = value; } } - public DateTime _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } - public Int32 _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } + public DateTime? _UpdateOn { get { return Cols._UpdateOn.Value; } set { Cols._UpdateOn.Value = value; } } + public Int32? _UpdateBy { get { return Cols._UpdateBy.Value; } set { Cols._UpdateBy.Value = value; } } public String _UpdateHost { get { return Cols._UpdateHost.Value; } set { Cols._UpdateHost.Value = value; } } // Existing columns - confirmed on database if table exists. public List ExistingColumnNames { get { return GetExistingColumnNames(Fields); } } public List ExistingColumnNamesNonId { get { return GetExistingColumnNames(FieldsNonId); } } + public List UpdatableColumns { get { return ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); } } //------------------------------------------------------------------- // Population. @@ -129,17 +146,17 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal _Id = GetFieldInt32(dbDataReader, "Id", _Id); _Context = GetFieldString(dbDataReader, "Context", _Context); _Code = GetFieldString(dbDataReader, "Code", _Code); - _Category = GetFieldInt16(dbDataReader, "Category", _Category); - _Type = GetFieldInt16(dbDataReader, "Type", _Type); + _Category = GetFieldInt16Nullable(dbDataReader, "Category", _Category); + _Type = GetFieldInt16Nullable(dbDataReader, "Type", _Type); _Caption = GetFieldString(dbDataReader, "Caption", _Caption); _Notes = GetFieldString(dbDataReader, "Notes", _Notes); - _Flags = GetFieldInt16(dbDataReader, "Flags", _Flags); + _Flags = GetFieldInt16Nullable(dbDataReader, "Flags", _Flags); _Status = GetFieldString(dbDataReader, "Status", _Status); - _CreateOn = GetFieldDateTime(dbDataReader, "CreateOn", _CreateOn); - _CreateBy = GetFieldInt32(dbDataReader, "CreateBy", _CreateBy); + _CreateOn = GetFieldDateTimeNullable(dbDataReader, "CreateOn", _CreateOn); + _CreateBy = GetFieldInt32Nullable(dbDataReader, "CreateBy", _CreateBy); _CreateHost = GetFieldString(dbDataReader, "CreateHost", _CreateHost); - _UpdateOn = GetFieldDateTime(dbDataReader, "UpdateOn", _UpdateOn); - _UpdateBy = GetFieldInt32(dbDataReader, "UpdateBy", _UpdateBy); + _UpdateOn = GetFieldDateTimeNullable(dbDataReader, "UpdateOn", _UpdateOn); + _UpdateBy = GetFieldInt32Nullable(dbDataReader, "UpdateBy", _UpdateBy); _UpdateHost = GetFieldString(dbDataReader, "UpdateHost", _UpdateHost); } @@ -186,10 +203,15 @@ namespace Sarand.Net.Standard.Dbas.Interfaces.Internal //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand (DbCommand dbCommand, List columnsToUpdate = null) { // Columns to update. - List columnNames = ExistingColumnNamesNonId.Where(item => !fieldsPrimary.ContainsCI(item) && !fieldsIgnoreOnUpdate.ContainsCI(item)).ToList(); + List columnNames = (columnsToUpdate?.Any() ?? false ? columnsToUpdate : UpdatableColumns).Where(col => UpdatableColumns.ContainsCI(col)).ToList(); + if (!columnNames.Any()) + { + SaLogger.Warn($"{SysUtil.Fn} No columns to update. [{GetType().Name}]"); + return false; + } // Construct query. String query = "UPDATE " + TableNameFmt + " SET "; if (dbCommand is SqlCommand) diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs index 8d01d07..9fa2c05 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs @@ -1,11 +1,10 @@ -using System; -using System.Collections.Generic; +using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Interfaces; -using Sarand.Net.Standard.Dbas.Base; using Sarand.Net.Standard.Base.Utils; +using System; +using System.Collections.Generic; namespace Sarand.Net.Standard.Dbas.Interfaces { @@ -18,13 +17,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Static initialisation. - static SaInterfaceConsole_Dbas () + static SaInterfaceConsole_Dbas() { } //------------------------------------------------------------------- // Construction. - protected SaInterfaceConsole_Dbas (ISacsDatabase database) + protected SaInterfaceConsole_Dbas(ISacsDatabase database) { Database = database; interfaceMgr = new SaInterfaceMgr_Dbas(this); @@ -48,35 +47,43 @@ namespace Sarand.Net.Standard.Dbas.Interfaces // M a n a g e I n t e r f a c e s //------------------------------------------------------------------- // Manage interfaces - returns true if changes made. - public override bool ManageInterfaces (String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo) + public override bool ManageInterfaces(String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); MaintainInterfacesFn?.Invoke(this, interfaceContext, userCanManageInterfaces, userCanProcessInterfaces, dbUpdateInfo); return false; } // Method to display Interface management dialog. - protected delegate bool MaintainInterfacesFunction (SaInterfaceConsole codeTypeConsole, String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo); + protected delegate bool MaintainInterfacesFunction(SaInterfaceConsole codeTypeConsole, String interfaceContext, bool userCanManageInterfaces, bool userCanProcessInterfaces, DbUpdateInfo dbUpdateInfo); protected abstract MaintainInterfacesFunction MaintainInterfacesFn { get; } //------------------------------------------------------------------- // I n t e r f a c e M a n a g e m e n t //------------------------------------------------------------------- // Interface management. - public override SysId CreateInterface (String context, SaInterfaceCategory interfaceCategory, short interfaceType, String code, String caption, DbUpdateInfo dbUpdateInfo) + public override SysId CreateInterface(String context, SaInterfaceCategory interfaceCategory, short interfaceType, String code, String caption, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); - SaInterface interfaceObj = interfaceMgr.CreateInterface(context,interfaceCategory,interfaceType); + SaInterface interfaceObj = interfaceMgr.CreateInterface(context, interfaceCategory, interfaceType); interfaceObj.Code = code; interfaceObj.Caption = caption; - if (!interfaceMgr.InsertInterface(interfaceObj,dbUpdateInfo)) + if (!interfaceMgr.InsertInterface(interfaceObj, dbUpdateInfo)) { SetErrorState(interfaceMgr.ErrorStateMessage); return null; } return interfaceObj.Id; } + public override bool UpdateInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + { + ClearErrorState(); + if (!interfaceMgr.UpdateInterface(interfaceObj, dbUpdateInfo)) + return SetErrorState(interfaceMgr.ErrorStateMessage); + return true; + } + // Clear configuration options, data items, processes etc. - public override bool ClearDependentData (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + public override bool ClearDependentData(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); throw new NotImplementedException(); @@ -85,22 +92,38 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // Retrieve interfaces. - public override SaInterface GetInterface (SaInterface.Params prmInterface) + public override SaInterface GetInterface(SaInterface.Params prmInterface) { return interfaceMgr.GetInterface(prmInterface); } - public override SaInterface GetInterfaceById (SysId interfaceId) + public override SaInterface GetInterfaceById(SysId interfaceId) { return interfaceMgr.GetInterfaceById(interfaceId); } - public override List GetInterfaceList (SaInterface.Params prmInterface) + public override ColumnDfn GetInterfaceColumnDfn(SaInterface.Column columnId, string caption = "", int width = 0) + { + return interfaceMgr.GetInterfaceColumnDfn(columnId, caption, width); + } + public override long GetInterfaceCount(SaInterface.Params prmInterface) + { + return interfaceMgr.GetInterfaceCount(prmInterface); + } + public override List GetInterfaceList(SaInterface.Params prmInterface) { return interfaceMgr.GetInterfaceList(prmInterface); } + public override DbResultSet ExecuteInterfaceQuery(List columns, SaInterface.Params prm) + { + return interfaceMgr.ExecuteInterfaceQuery(columns, prm); + } + public override DataValue GetInterfaceDataValue(ColumnDfn column, NamedValue.Map values) + { + return interfaceMgr.GetInterfaceDataValue(column, values); + } //--------------------------------------------------------------- // Conversion between Interface Category & Type and the equivalent database Id (if only one exists). - public override SysId GetInterfaceIdForContextCategoryType (String context, SaInterfaceCategory interfaceCategory, short interfaceType) + public override SysId GetInterfaceIdForContextCategoryType(String context, SaInterfaceCategory interfaceCategory, short interfaceType) { ClearErrorState(); SaInterface.Params prmInterface = new SaInterface.Params(); @@ -115,7 +138,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces return null; } // Conversion between Interface Category & Code and the equivalent database Id (if only one exists). - public override SysId GetInterfaceIdForContextCategoryCode (String context, SaInterfaceCategory interfaceCategory, String code) + public override SysId GetInterfaceIdForContextCategoryCode(String context, SaInterfaceCategory interfaceCategory, String code) { ClearErrorState(); SaInterface.Params prmInterface = new SaInterface.Params(); @@ -129,14 +152,14 @@ namespace Sarand.Net.Standard.Dbas.Interfaces return interfaceObj.Id; return null; } - public override SaInterfaceCategory GetCategoryForInterfaceId (SysId interfaceId) + public override SaInterfaceCategory GetCategoryForInterfaceId(SysId interfaceId) { SaInterface interfaceObj = interfaceMgr.GetInterfaceById(interfaceId); if (interfaceObj != null) return interfaceObj.Category; return SaInterfaceCategory.Unknown; } - public override String GetCodeForInterfaceId (SysId interfaceId) + public override String GetCodeForInterfaceId(SysId interfaceId) { SaInterface interfaceObj = interfaceMgr.GetInterfaceById(interfaceId); if (interfaceObj != null) @@ -148,7 +171,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces // I n t e r f a c e P r o c e s s e s //--------------------------------------------------------------- // Identify the highest sequence currently in use for an interface. - public override int GetMaxProcessSequence (SysId interfaceId, SaInterfaceProcessDirection processDirection, bool completedOnly = true) + public override int GetMaxProcessSequence(SysId interfaceId, SaInterfaceProcessDirection processDirection, bool completedOnly = true) { ClearErrorState(); int sequence = interfaceMgr.GetMaxProcessSequenceForInterface(interfaceId, processDirection); @@ -159,7 +182,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // Create new process and imediately store details on database (status set to 'In Progress'). - public override SaInterfaceProcess StartInterfaceProcess (SysId interfaceId, SaInterfaceProcessDirection eDirection, String batchRef, DateTime batchAt, int sequence, DbUpdateInfo dbUpdateInfo) + public override SaInterfaceProcess StartInterfaceProcess(SysId interfaceId, SaInterfaceProcessDirection eDirection, String batchRef, DateTime batchAt, int sequence, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!interfaceMgr.InterfaceExistsById(interfaceId)) @@ -171,7 +194,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces interfaceProcess.ProcessAt = DateTime.Now; interfaceProcess.BatchAt = batchAt; interfaceProcess.Status = SaStatus.InProgress; - if (!interfaceMgr.InsertInterfaceProcess(interfaceProcess,dbUpdateInfo)) + if (!interfaceMgr.InsertInterfaceProcess(interfaceProcess, dbUpdateInfo)) { interfaceProcess = null; SetErrorState(interfaceMgr.ErrorStateMessage); @@ -181,7 +204,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // Retrieve a process using its identity (restricted by interface). - public override SaInterfaceProcess GetInterfaceProcess (SysId interfaceId, SysId interfaceProcessId) + public override SaInterfaceProcess GetInterfaceProcess(SysId interfaceId, SysId interfaceProcessId) { ClearErrorState(); SaInterfaceProcess interfaceProcess = interfaceMgr.GetInterfaceProcessById(interfaceProcessId); @@ -200,14 +223,14 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // Update the details for a process. - public override bool StoreInterfaceProcess (SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo) + public override bool StoreInterfaceProcess(SaInterfaceProcess interfaceProcess, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!SysId.IsValid(interfaceProcess.Id)) { // Insert interface process. if (!interfaceMgr.InsertInterfaceProcess(interfaceProcess, dbUpdateInfo)) - return SetErrorState("Failed to insert process - "+interfaceMgr.ErrorStateMessage); + return SetErrorState("Failed to insert process - " + interfaceMgr.ErrorStateMessage); } else { @@ -221,7 +244,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // I n t e r f a c e P r o c e s s M e s s a g e s //--------------------------------------------------------------- - public override bool LogInterfaceProcessMessage (SysId interfaceProcessId, DbUpdateInfo dbUpdateInfo, String message, SaMessageLevel messageLevel = SaMessageLevel.Info, String filename = "", int lineNumber = 0, ItemId itemId = null) + public override bool LogInterfaceProcessMessage(SysId interfaceProcessId, DbUpdateInfo dbUpdateInfo, String message, SaMessageLevel messageLevel = SaMessageLevel.Info, String filename = "", int lineNumber = 0, ItemId itemId = null) { ClearErrorState(); if (!interfaceMgr.InterfaceProcessExistsById(interfaceProcessId)) return SetErrorState("Invalid interface process id supplied"); @@ -243,14 +266,14 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //--------------------------------------------------------------- // I n t e r f a c e D a t a I t e m s //--------------------------------------------------------------- - public override bool ItemHasDataItems (ItemId itemId) + public override bool ItemHasDataItems(ItemId itemId) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); prmInterfaceDataItem.ItemIdsIncluded.Add(itemId); return (interfaceMgr.GetInterfaceDataItemCount(prmInterfaceDataItem) > 0); } - public override bool InterfaceDataItemExistsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) + public override bool InterfaceDataItemExistsByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); @@ -260,17 +283,17 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ExternalReference = externalReference; return (interfaceMgr.GetInterfaceDataItemCount(prmInterfaceDataItem) > 0); } - public override SaInterfaceDataItem CreateInterfaceDataItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference) + public override SaInterfaceDataItem CreateInterfaceDataItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference) { ClearErrorState(); return interfaceMgr.CreateInterfaceDataItem(interfaceId, processDirection, itemId, externalReference); } - public override SaInterfaceDataItem GetInterfaceDataItem (SysId interfaceDataItemId) + public override SaInterfaceDataItem GetInterfaceDataItem(SysId interfaceDataItemId) { ClearErrorState(); return interfaceMgr.GetInterfaceDataItemById(interfaceDataItemId); } - public override SaInterfaceDataItem GetInterfaceDataItemByItemRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference) + public override SaInterfaceDataItem GetInterfaceDataItemByItemRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId, String externalReference) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); @@ -280,7 +303,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ExternalReference = externalReference; return interfaceMgr.GetInterfaceDataItem(prmInterfaceDataItem); } - public override SaInterfaceDataItem GetInterfaceDataItemByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) + public override SaInterfaceDataItem GetInterfaceDataItemByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) { // Fails if more than 1 matching data item. ClearErrorState(); @@ -291,7 +314,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ExternalReference = externalReference; return interfaceMgr.GetInterfaceDataItem(prmInterfaceDataItem); } - public override SaInterfaceDataItem GetInterfaceDataItemByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId) + public override SaInterfaceDataItem GetInterfaceDataItemByItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId) { // Fails if more than 1 matching data item. ClearErrorState(); @@ -301,7 +324,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ItemIdsIncluded.Add(itemId); return interfaceMgr.GetInterfaceDataItem(prmInterfaceDataItem); } - public override List GetInterfaceDataItemsByItem (SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId) + public override List GetInterfaceDataItemsByItem(SysId interfaceId, SaInterfaceProcessDirection processDirection, ItemId itemId) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); @@ -310,7 +333,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ItemIdsIncluded.Add(itemId); return interfaceMgr.GetInterfaceDataItemList(prmInterfaceDataItem); } - public override List GetInterfaceDataItemsByRef (SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) + public override List GetInterfaceDataItemsByRef(SysId interfaceId, SaInterfaceProcessDirection processDirection, short itemType, String externalReference) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); @@ -320,7 +343,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces prmInterfaceDataItem.ExternalReference = externalReference; return interfaceMgr.GetInterfaceDataItemList(prmInterfaceDataItem); } - public override bool StoreInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo) + public override bool StoreInterfaceDataItem(SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (interfaceDataItem == null) return SetErrorState("data item must be supplied"); @@ -336,7 +359,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces } return true; } - public override bool StoreInterfaceDataItems (List interfaceDataItems, DbUpdateInfo dbUpdateInfo) + public override bool StoreInterfaceDataItems(List interfaceDataItems, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); foreach (SaInterfaceDataItem interfaceDataItem in interfaceDataItems) @@ -346,14 +369,14 @@ namespace Sarand.Net.Standard.Dbas.Interfaces } return true; } - public override bool ClearInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo) + public override bool ClearInterfaceDataItem(SaInterfaceDataItem interfaceDataItem, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!interfaceMgr.DeleteInterfaceDataItem(interfaceDataItem, dbUpdateInfo)) return SetErrorState(interfaceMgr.ErrorStateMessage); return true; } - public override bool ClearInterfaceDataItems (ItemId itemId, DbUpdateInfo dbUpdateInfo) + public override bool ClearInterfaceDataItems(ItemId itemId, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); SaInterfaceDataItem.Params prmInterfaceDataItem = new SaInterfaceDataItem.Params(); diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceDbDfnGenerator.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceDbDfnGenerator.cs index 5c022da..81c7471 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceDbDfnGenerator.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceDbDfnGenerator.cs @@ -1,11 +1,11 @@ -using System; -using System.IO; -using System.Reflection; -using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.IO; using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Base; +using System; +using System.IO; +using System.Reflection; namespace Sarand.Net.Standard.Dbas.Interface { @@ -14,16 +14,15 @@ namespace Sarand.Net.Standard.Dbas.Interface { //------------------------------------------------------------------- // Data members. - //private static string messageBoxTitle = "Sarand Interface Module database definition generator"; - //private static String dbConnectionString = "Driver={SQL Server Native Client 11.0};Server=Sarand106\\SQL2014;Database=SaStockTracker_Solent_STN;Trusted_Connection=Yes;MARS_Connection=yes;"; + private static String className = nameof(SaInterfaceDbDfnGenerator); //------------------------------------------------------------------- /// /// Generate database definitions. /// - public static bool Generate (String connectionString) + public static bool Generate(String connectionString) { - String fn = nameof(SaInterfaceDbDfnGenerator) + ".Generate"; + String fn = $"{className}.Generate"; // Locate output folder: String directory = GetOutputFolder(); @@ -42,13 +41,13 @@ namespace Sarand.Net.Standard.Dbas.Interface } catch (Exception exc) { - SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc)); + SaLogger.Error($"{fn} {ExceptionUtil.GetLogMessage(exc, "generating Interface database definition")}"); } return false; } //------------------------------------------------------------------- - private static bool GenerateDatabaseDefinition (SacsDatabase database, String directory) + private static bool GenerateDatabaseDefinition(SacsDatabase database, String directory) { DatabaseDefinitionGenerator.Config config = new DatabaseDefinitionGenerator.Config() { @@ -73,10 +72,19 @@ namespace Sarand.Net.Standard.Dbas.Interface config.Schema.InsertOnlyColumns.Add("SaInterfaceDataItem", "InterfaceId"); config.Schema.InsertOnlyColumns.Add("SaInterfaceProcessDataItem", "ProcessId,InterfaceDataItemId"); // Database Definition class. - config.DefinitionClass.Namespace = "Sarand.Net.Standard.Base.Interfaces"; - config.DefinitionClass.Classname = "SaInterfaceDbDfn"; + config.DefinitionClass.Usings.Clear(); + config.DefinitionClass.Usings.Add("Sarand.Net.Standard.Base.Core"); + config.DefinitionClass.Usings.Add("Sarand.Net.Standard.Base.Utils"); + config.DefinitionClass.Usings.Add("Sarand.Net.Standard.Base.Dbas"); + config.DefinitionClass.Namespace = "Sarand.Net.Standard.Base.Interfaces"; + config.DefinitionClass.Classname = "SaInterfaceDbDfn"; // Table class. + config.TableClass.Usings.Add("Sarand.Net.Standard.Base.App"); + config.TableClass.Usings.Add("Sarand.Net.Standard.Base.Core"); + config.TableClass.Usings.Add("Sarand.Net.Standard.Base.Utils"); + config.TableClass.Usings.Add("Sarand.Net.Standard.Base.Dbas"); config.TableClass.Namespace = "Sarand.Net.Standard.Dbas.Interfaces.Internal"; + config.TableClass.ClassName_DatabaseInfo = "IDatabaseInfo"; config.TableClass.MandatoryConstructorDbInfo = true; // Generate database definition. @@ -84,10 +92,10 @@ namespace Sarand.Net.Standard.Dbas.Interface return generator.Generate(config); } //------------------------------------------------------------------- - private static String GetOutputFolder () + private static String GetOutputFolder() { - String fn = nameof(SaInterfaceDbDfnGenerator) + ".GetOutputFolder"; - String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof (DatabaseDefinitionGenerator)).Location)); + String fn = $"{className}.GetOutputFolder"; + String assemblyDirectory = FileUtil.GetParentDirectory((Assembly.GetAssembly(typeof(DatabaseDefinitionGenerator)).Location)); String directory = assemblyDirectory; SaLogger.Debug(fn + " Assembly folder: " + directory); // Locate the parent of the 'Workspace' solution root folder. @@ -106,11 +114,11 @@ namespace Sarand.Net.Standard.Dbas.Interface return String.Empty; } // Code files are generated to '..\Dbas\Generated\Interfaces\' folder. - directory += Path.DirectorySeparatorChar + "Database" + Path.DirectorySeparatorChar + "Generated" + Path.DirectorySeparatorChar + "Interfaces"; - SaLogger.Debug(fn + " Output folder: " + directory); + directory = Path.Combine(directory, "Database", "Generated", "Interfaces"); + SaLogger.Debug($"{fn} Output folder: {directory}"); if (!FileUtil.ValidateDirectory(directory, true)) { - SaLogger.Error(fn + " Output folder not found:\n\n" + directory); + SaLogger.Error($"{fn} Output folder not found: {directory}"); return String.Empty; } return directory; diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcessMessages.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcessMessages.cs index 1a2325d..02f1880 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcessMessages.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcessMessages.cs @@ -1,15 +1,15 @@ -using System; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Interfaces; +using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Dbas.Data; +using Sarand.Net.Standard.Dbas.Interfaces.Internal; +using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Interfaces; -using Sarand.Net.Standard.Dbas.Data; -using Sarand.Net.Standard.Dbas.Interfaces.Internal; -using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Dbas.Interfaces { @@ -212,7 +212,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces interfaceProcessMessage.Level = SaMessageLevel.Warning; interfaceProcessMessage.Message = dbInterfaceProcessMessage._Msg; interfaceProcessMessage.Filename = dbInterfaceProcessMessage._FileName; - interfaceProcessMessage.LineNumber = dbInterfaceProcessMessage._LineNumber; + interfaceProcessMessage.LineNumber = dbInterfaceProcessMessage._LineNumber ?? 0; interfaceProcessMessage.ItemId = new ItemId(dbInterfaceProcessMessage._ItemType, new SysId(dbInterfaceProcessMessage._ItemId)); interfaceProcessMessage.Status = SacsSystem.GetStatusForCode(dbInterfaceProcessMessage._Status); interfaceProcessMessage.SetCreateStamp(dbInterfaceProcessMessage._CreateOn, new SysId(dbInterfaceProcessMessage._CreateBy), dbInterfaceProcessMessage._CreateHost); diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcesses.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcesses.cs index bf3aa2a..b5cee62 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcesses.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-InterfaceProcesses.cs @@ -1,15 +1,15 @@ -using System; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Interfaces; +using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Dbas.Data; +using Sarand.Net.Standard.Dbas.Interfaces.Internal; +using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Interfaces; -using Sarand.Net.Standard.Dbas.Data; -using Sarand.Net.Standard.Dbas.Interfaces.Internal; -using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Dbas.Interfaces { @@ -49,7 +49,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces private SaInterfaceProcess CreateInterfaceProcess(SaInterfaceProcess_Db dbInterfaceProcess) { ClearErrorState(); - SaInterfaceProcess interfaceProcess = new SaInterfaceProcess_Dbas(new SysId(dbInterfaceProcess._Id), new SysId(dbInterfaceProcess._InterfaceId), (SaInterfaceProcessDirection)dbInterfaceProcess._Direction, dbInterfaceProcess._ProcRef, dbInterfaceProcess._ProcSeq, (ushort)dbInterfaceProcess._Flags); + SaInterfaceProcess interfaceProcess = new SaInterfaceProcess_Dbas(new SysId(dbInterfaceProcess._Id), new SysId(dbInterfaceProcess._InterfaceId), (SaInterfaceProcessDirection)dbInterfaceProcess._Direction, dbInterfaceProcess._ProcRef, dbInterfaceProcess._ProcSeq ?? 0, (ushort)dbInterfaceProcess._Flags); PopulateFrom(dbInterfaceProcess, interfaceProcess); return interfaceProcess; } @@ -284,7 +284,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //interfaceProcess.Sequence = dbInterfaceProcess._ProcSeq; interfaceProcess.ProcessAt = dbInterfaceProcess._ProcessAt; interfaceProcess.BatchAt = dbInterfaceProcess._BatchAt; - interfaceProcess.ElapseSecs = dbInterfaceProcess._ElapseSecs; + interfaceProcess.ElapseSecs = dbInterfaceProcess._ElapseSecs ?? 0; interfaceProcess.Status = SacsSystem.GetStatusForCode(dbInterfaceProcess._Status); interfaceProcess.SetCreateStamp(dbInterfaceProcess._CreateOn, new SysId(dbInterfaceProcess._CreateBy), dbInterfaceProcess._CreateHost); interfaceProcess.SetUpdateStamp(dbInterfaceProcess._UpdateOn, new SysId(dbInterfaceProcess._UpdateBy), dbInterfaceProcess._UpdateHost); diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-Interfaces.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-Interfaces.cs index bac060d..8b85df9 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-Interfaces.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceMgr_Dbas-Interfaces.cs @@ -1,15 +1,16 @@ -using System; +using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; +using Sarand.Net.Standard.Base.Interfaces; +using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Dbas.Data; +using Sarand.Net.Standard.Dbas.Interfaces.Internal; +using System; using System.Collections.Generic; using System.Data.Common; using System.Linq; -using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; -using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.Interfaces; -using Sarand.Net.Standard.Dbas.Data; -using Sarand.Net.Standard.Dbas.Interfaces.Internal; -using Sarand.Net.Standard.Base.Utils; +using System.Text.RegularExpressions; namespace Sarand.Net.Standard.Dbas.Interfaces { @@ -20,20 +21,20 @@ namespace Sarand.Net.Standard.Dbas.Interfaces // I n t e r f a c e s //******************************************************************* // Associated data. - public override bool InterfaceHasProcesses (SysId id) + public override bool InterfaceHasProcesses(SysId id) { ClearErrorState(); String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcess_InterfaceId) + "=" + SysId.ToString(id); return (Database.GetRowCount(TableName_InterfaceProcess, filter) > 0); } - public override bool InterfaceHasDataItems (SysId id) + public override bool InterfaceHasDataItems(SysId id) { ClearErrorState(); String filter = SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceDataItem_InterfaceId) + "=" + SysId.ToString(id); return (Database.GetRowCount(TableName_InterfaceDataItem, filter) > 0); } // Process sequence. - public override int GetMaxProcessSequenceForInterface (SysId interfaceId, SaInterfaceProcessDirection processDirection) + public override int GetMaxProcessSequenceForInterface(SysId interfaceId, SaInterfaceProcessDirection processDirection) { ClearErrorState(); if (!SysId.IsValid(interfaceId)) return 0; @@ -46,19 +47,19 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Create Item. - public override SaInterface CreateInterface (String context, SaInterfaceCategory category, short type) + public override SaInterface CreateInterface(String context, SaInterfaceCategory category, short type) { ClearErrorState(); return new SaInterface_Dbas(null, context, category, type, 0); } - private SaInterface CreateInterface (SaInterface_Db dbInterface) + private SaInterface CreateInterface(SaInterface_Db dbInterface) { ClearErrorState(); - SaInterface saInterface = new SaInterface_Dbas(new SysId(dbInterface._Id), dbInterface._Context, (SaInterfaceCategory)dbInterface._Category, dbInterface._Type, (ushort)dbInterface._Flags); + SaInterface saInterface = new SaInterface_Dbas(new SysId(dbInterface._Id), dbInterface._Context, (SaInterfaceCategory)dbInterface._Category, dbInterface._Type ?? 0, (ushort)dbInterface._Flags); PopulateFrom(dbInterface, saInterface); return saInterface; } - private SaInterface CreateInterface (DbDataReader dataReader) + private SaInterface CreateInterface(DbDataReader dataReader) { SaInterface_Db dbInterface = new SaInterface_Db(DbInfo); dbInterface.PopulateFrom(dataReader); @@ -67,13 +68,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Item exists. - public override bool InterfaceExistsById (SysId id) + public override bool InterfaceExistsById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return false; return GetInterfaceCount(SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Id, aliasInterface) + "=" + SysId.ToString(id)) == 1; } - public override bool InterfaceExistsByCode (String code) + public override bool InterfaceExistsByCode(String code) { ClearErrorState(); if (StringUtil.IsEmpty(code)) return false; @@ -82,11 +83,11 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Get Item. - public override SaInterface GetInterface (SaInterface.Params prm) + public override SaInterface GetInterface(SaInterface.Params prm) { return GetInterface(GetInterfaceQueryFilter(prm).Concat(" AND ", "(", ")")); } - private SaInterface GetInterface (String filter) + private SaInterface GetInterface(String filter) { ClearErrorState(); if (GetInterfaceCount(filter) != 1) return null; @@ -110,13 +111,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces } return interfaceObj; } - public override SaInterface GetInterfaceById (SysId id) + public override SaInterface GetInterfaceById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return null; return GetInterface("Id=" + SysId.ToString(id)); } - public override SaInterface GetInterfaceByContextCode (String context, String code) + public override SaInterface GetInterfaceByContextCode(String context, String code) { ClearErrorState(); if (StringUtil.IsEmpty(code)) return null; @@ -125,7 +126,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Validate Item properties. - public override bool IsValidInterfaceData (SaInterface.Data interfaceData, SaInterface.ErrField errField) + public override bool IsValidInterfaceData(SaInterface.Data interfaceData, SaInterface.ErrField errField) { ClearErrorState(); if (!base.IsValidInterfaceData(interfaceData, errField)) return false; @@ -134,7 +135,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Insert Item. - public override bool InsertInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + public override bool InsertInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!IsValidInterface(interfaceObj)) return false; @@ -162,7 +163,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Update Item. - public override bool UpdateInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + public override bool UpdateInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!IsValidInterface(interfaceObj)) return false; @@ -187,13 +188,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Delete Item. - public override bool InterfaceCanBeDeleted (SaInterface interfaceObj) + public override bool InterfaceCanBeDeleted(SaInterface interfaceObj) { ClearErrorState(); if (!base.InterfaceCanBeDeleted(interfaceObj)) return false; return true; } - public override bool DeleteInterface (SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + public override bool DeleteInterface(SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!InterfaceCanBeDeleted(interfaceObj)) return false; @@ -218,7 +219,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Copy data properties to and from database. - private void PopulateTo (SaInterface_Db dbInterface, SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) + private void PopulateTo(SaInterface_Db dbInterface, SaInterface interfaceObj, DbUpdateInfo dbUpdateInfo) { dbInterface._Id = interfaceObj.Id.ToInt(); dbInterface._Context = interfaceObj.Context; @@ -240,7 +241,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces dbInterface._UpdateBy = dbUpdateInfo.UserId.ToInt(); dbInterface._UpdateHost = dbUpdateInfo.Host; } - private void PopulateFrom (SaInterface_Db dbInterface, SaInterface interfaceObj) + private void PopulateFrom(SaInterface_Db dbInterface, SaInterface interfaceObj) { //interface.Id = new SysId(dbInterface._Id); //interfaceObj.Context = dbInterface._Context; @@ -270,7 +271,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces alias = aliasInterface; col.Set(caption, width, (int)dbCol, prefix + SaInterfaceDbDfn.GetColumnName(dbCol, false), SaInterfaceDbDfn.GetColumnNameQual(dbCol, alias), dataType, align); } - public override ColumnDfn GetInterfaceColumnDfn (SaInterface.Column columnId, string caption = "", int width = 0) + public override ColumnDfn GetInterfaceColumnDfn(SaInterface.Column columnId, string caption = "", int width = 0) { ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width); switch (columnId) @@ -359,7 +360,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Query filter. - public override List GetInterfaceQueryFilter (SaInterface.Params prm) + public override List GetInterfaceQueryFilter(SaInterface.Params prm) { List filter = new List(); @@ -372,8 +373,28 @@ namespace Sarand.Net.Standard.Dbas.Interfaces if (!excludedIds.IsEmpty()) filter.Add(colId + " NOT IN (" + excludedIds + ")"); - // Context. String colContext = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Context, aliasInterface); + String colCode = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Code, aliasInterface); + String colCaption = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Caption, aliasInterface); + String colNotes = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Notes, aliasInterface); + + // Generic search. + if (!StringUtil.IsBlank(prm.Search)) + { + foreach (String search in Regex.Split(prm.Search, "[\\s,;\\-+]+")) + { + if (StringUtil.IsBlank(search)) continue; + String searchForLike = DbQuery.FormatForLike(search, true); + List searchFilter = new List(); + searchFilter.Add($"{colContext} LIKE '%{searchForLike}%'"); + searchFilter.Add($"{colCode} LIKE '%{searchForLike}%'"); + searchFilter.Add($"{colCaption} LIKE '%{searchForLike}%'"); + searchFilter.Add($"{colNotes} LIKE '%{searchForLike}%'"); + filter.Add(searchFilter.Concat(" OR ", "(", ")")); + } + } + + // Context. if (!StringUtil.IsEmpty(prm.Context)) filter.Add(colContext + "='" + DbQuery.FormatForCondition(prm.Context) + "'"); @@ -388,18 +409,16 @@ namespace Sarand.Net.Standard.Dbas.Interfaces filter.Add(colType + " In (" + String.Join(",", prm.InterfaceTypesIncluded) + ")"); // Code. - String colCode = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Code, aliasInterface); if (!StringUtil.IsEmpty(prm.Code)) filter.Add(colCode + "='" + DbQuery.FormatForCondition(prm.Code) + "'"); // Caption. - String colCaption = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Caption, aliasInterface); if (!StringUtil.IsEmpty(prm.CaptionPartial)) filter.Add(colCaption + " Like '%" + DbQuery.FormatForLike(prm.CaptionPartial) + "%'"); // Interface text - code or caption. if (!StringUtil.IsEmpty(prm.InterfaceText)) - filter.Add(colCode + " Like '%" + DbQuery.FormatForLike(prm.InterfaceText) + "%' Or "+ colCaption + " Like '%" + DbQuery.FormatForLike(prm.InterfaceText) + "%'"); + filter.Add(colCode + " Like '%" + DbQuery.FormatForLike(prm.InterfaceText) + "%' Or " + colCaption + " Like '%" + DbQuery.FormatForLike(prm.InterfaceText) + "%'"); // Active flag. String colFlags = SaInterfaceDbDfn.GetColumnNameQual(SaInterfaceDbDfn.ColumnIdx.SaInterface_Flags, aliasInterface); @@ -415,7 +434,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces return filter; } // Sort columns. - public List GetInterfaceSortColumns (SaInterface.Params prm) + public List GetInterfaceSortColumns(SaInterface.Params prm) { // Sort sequence: List sortColumnNames = new List(); @@ -453,12 +472,12 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Item count. - private long GetInterfaceCount (String filter) + private long GetInterfaceCount(String filter) { ClearErrorState(); return Database.GetRowCount($"{TableName_Interface} As {aliasInterface}", filter); } - public override long GetInterfaceCount (SaInterface.Params prm) + public override long GetInterfaceCount(SaInterface.Params prm) { ClearErrorState(); return GetInterfaceCount(GetInterfaceQueryFilter(prm).Concat(" AND ", "(", ")")); @@ -466,7 +485,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Item list. - public override List GetInterfaceList (SaInterface.Params prm) + public override List GetInterfaceList(SaInterface.Params prm) { ClearErrorState(); List interfaces = new List(); @@ -501,7 +520,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Item query. - public override DbResultSet ExecuteInterfaceQuery (List columns, SaInterface.Params prm) + public override DbResultSet ExecuteInterfaceQuery(List columns, SaInterface.Params prm) { ClearErrorState(); diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceProcess_Db_Local.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceProcess_Db_Local.cs index 43665d3..55da830 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceProcess_Db_Local.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceProcess_Db_Local.cs @@ -1,4 +1,6 @@ +using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Interfaces; using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Base; @@ -6,10 +8,7 @@ using Sarand.Net.Standard.Dbas.Interfaces.Internal; using System; using System.Collections.Generic; using System.Data.Common; -using Microsoft.Data.SqlClient; using System.Linq; -using Sarand.Net.Standard.Base.Dbas; -using Sarand.Net.Standard.Base.App; //--------------------------------------------------------------------------- // Code generated by Sarand Database Utilities Thu 3-Oct-2019 15:10:58 @@ -25,9 +24,9 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Data members. private String colNameProcDate = "ProcDate"; - private String colNameProcTime= "ProcTime"; + private String colNameProcTime = "ProcTime"; private String colNameBatchDate = "BatchDate"; - private String colNameBatchTime= "BatchTime"; + private String colNameBatchTime = "BatchTime"; private bool colExists_ProcessAt = false; private bool colExists_ProcDate = false; private bool colExists_ProcTime = false; @@ -37,7 +36,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Construction. - internal SaInterfaceProcess_Db_Local (IDatabaseInfo dbInfo) : base(dbInfo) + internal SaInterfaceProcess_Db_Local(IDatabaseInfo dbInfo) : base(dbInfo) { colExists_ProcessAt = ColumnExists(SaInterfaceDbDfn.GetColumnName(SaInterfaceDbDfn.ColumnIdx.SaInterfaceProcess_ProcessAt, false)); colExists_ProcDate = ColumnExists(colNameProcDate); @@ -52,7 +51,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Population. - public override void PopulateFrom (DbCommand dbCommand, String tableAlias, String filter) + public override void PopulateFrom(DbCommand dbCommand, String tableAlias, String filter) { if (colExists_ProcessAt) { @@ -68,7 +67,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces PopulateFrom(dbDataReader); } } - public override void PopulateFrom (DbDataReader dbDataReader) + public override void PopulateFrom(DbDataReader dbDataReader) { base.PopulateFrom(dbDataReader); // 'Process At' legacy fields: ProcDate (Int32) & ProcTime (Int32). @@ -95,7 +94,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Insert command. - public override bool ExecuteInsertCommand (DbCommand dbCommand) + public override bool ExecuteInsertCommand(DbCommand dbCommand) { if (colExists_ProcessAt) return ExecuteInsertCommand(dbCommand); @@ -109,13 +108,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces SacsDatabase.AddValuePair(columnValues, "ProcSeq", _ProcSeq); if (colExists_ProcDate && colExists_ProcTime) { - SacsDatabase.AddValuePair(columnValues, colNameProcDate, DateUtil.DateToInt32(_ProcessAt)); - SacsDatabase.AddValuePair(columnValues, colNameProcTime, DateUtil.TimeToInt32(_ProcessAt)); + SacsDatabase.AddValuePair(columnValues, colNameProcDate, DateUtil.DateToInt32(_ProcessAt ?? DateTime.MinValue)); + SacsDatabase.AddValuePair(columnValues, colNameProcTime, DateUtil.TimeToInt32(_ProcessAt ?? DateTime.MinValue)); } if (colExists_BatchDate && colExists_BatchTime) { - SacsDatabase.AddValuePair(columnValues, colNameBatchDate, DateUtil.DateToInt32(_BatchAt)); - SacsDatabase.AddValuePair(columnValues, colNameBatchTime, DateUtil.TimeToInt32(_BatchAt)); + SacsDatabase.AddValuePair(columnValues, colNameBatchDate, DateUtil.DateToInt32(_BatchAt ?? DateTime.MinValue)); + SacsDatabase.AddValuePair(columnValues, colNameBatchTime, DateUtil.TimeToInt32(_BatchAt ?? DateTime.MinValue)); } SacsDatabase.AddValuePair(columnValues, "ElapseSecs", _ElapseSecs); SacsDatabase.AddValuePair(columnValues, "ItemCount", _ItemCount); @@ -145,7 +144,7 @@ namespace Sarand.Net.Standard.Dbas.Interfaces //------------------------------------------------------------------- // Update command. - public override bool ExecuteUpdateCommand (DbCommand dbCommand) + public override bool ExecuteUpdateCommand(DbCommand dbCommand) { if (colExists_ProcessAt) return ExecuteUpdateCommand(dbCommand); @@ -156,13 +155,13 @@ namespace Sarand.Net.Standard.Dbas.Interfaces SacsDatabase.AddValuePair(columnValues, "ProcSeq", _ProcSeq); if (colExists_ProcDate && colExists_ProcTime) { - SacsDatabase.AddValuePair(columnValues, colNameProcDate, DateUtil.DateToInt32(_ProcessAt)); - SacsDatabase.AddValuePair(columnValues, colNameProcTime, DateUtil.TimeToInt32(_ProcessAt)); + SacsDatabase.AddValuePair(columnValues, colNameProcDate, DateUtil.DateToInt32(_ProcessAt ?? DateTime.MinValue)); + SacsDatabase.AddValuePair(columnValues, colNameProcTime, DateUtil.TimeToInt32(_ProcessAt ?? DateTime.MinValue)); } if (colExists_BatchDate && colExists_BatchTime) { - SacsDatabase.AddValuePair(columnValues, colNameBatchDate, DateUtil.DateToInt32(_BatchAt)); - SacsDatabase.AddValuePair(columnValues, colNameBatchTime, DateUtil.TimeToInt32(_BatchAt)); + SacsDatabase.AddValuePair(columnValues, colNameBatchDate, DateUtil.DateToInt32(_BatchAt ?? DateTime.MinValue)); + SacsDatabase.AddValuePair(columnValues, colNameBatchTime, DateUtil.TimeToInt32(_BatchAt ?? DateTime.MinValue)); } SacsDatabase.AddValuePair(columnValues, "ElapseSecs", _ElapseSecs); SacsDatabase.AddValuePair(columnValues, "ItemCount", _ItemCount); diff --git a/SacsStandardDbas/Dbas/ItemOptions/Internal/SaItemOption_Db.cs b/SacsStandardDbas/Dbas/ItemOptions/Internal/SaItemOption_Db.cs index 31144c7..1713cf4 100644 --- a/SacsStandardDbas/Dbas/ItemOptions/Internal/SaItemOption_Db.cs +++ b/SacsStandardDbas/Dbas/ItemOptions/Internal/SaItemOption_Db.cs @@ -10,7 +10,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:21 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.ItemOptions.Internal { diff --git a/SacsStandardDbas/Dbas/Security/Internal/SaSecItem_Db.cs b/SacsStandardDbas/Dbas/Security/Internal/SaSecItem_Db.cs index e4a87e3..c9e516b 100644 --- a/SacsStandardDbas/Dbas/Security/Internal/SaSecItem_Db.cs +++ b/SacsStandardDbas/Dbas/Security/Internal/SaSecItem_Db.cs @@ -10,7 +10,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:20 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Security.Internal { diff --git a/SacsStandardDbas/Dbas/Security/Internal/SaSecLink_Db.cs b/SacsStandardDbas/Dbas/Security/Internal/SaSecLink_Db.cs index fa324bd..b546b45 100644 --- a/SacsStandardDbas/Dbas/Security/Internal/SaSecLink_Db.cs +++ b/SacsStandardDbas/Dbas/Security/Internal/SaSecLink_Db.cs @@ -10,7 +10,7 @@ using System.Data.Common; using System.Linq; //--------------------------------------------------------------------------- -// Code generated by Sarand Database Utilities Thu 6-Feb-2025 13:02:20 +// Code generated by Sarand Database Utilities Thu 30-Oct-2025 11:28:12 //--------------------------------------------------------------------------- namespace Sarand.Net.Standard.Dbas.Security.Internal { diff --git a/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityLink.cs b/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityLink.cs index 0fff859..a5deb45 100644 --- a/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityLink.cs +++ b/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityLink.cs @@ -1,15 +1,14 @@ using Sarand.Net.Standard.Base.App; -using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; +using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Dbas; using Sarand.Net.Standard.Base.Security; +using Sarand.Net.Standard.Base.Utils; using Sarand.Net.Standard.Dbas.Data; using Sarand.Net.Standard.Dbas.Security.Internal; using System; using System.Collections.Generic; using System.Data.Common; -using System.Text; -using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Dbas.Security { @@ -203,8 +202,8 @@ namespace Sarand.Net.Standard.Dbas.Security securityLink.ApplicableFrom = DateUtil.Int32ToDate(dbSecurityLink._DateApplicFrom ?? 0); securityLink.ApplicableTo = DateUtil.Int32ToDate(dbSecurityLink._DateApplicTo ?? 0); securityLink.Status = SacsSystem.GetStatusForCode(dbSecurityLink._Status); - securityLink.SetCreateStamp(dbSecurityLink._CreateOn ?? DateTime.MinValue, new SysId(dbSecurityLink._CreateBy ?? 0), dbSecurityLink._CreateHost); - securityLink.SetUpdateStamp(dbSecurityLink._UpdateOn ?? DateTime.MinValue, new SysId(dbSecurityLink._UpdateBy ?? 0), dbSecurityLink._UpdateHost); + securityLink.SetCreateStamp(dbSecurityLink._CreateOn, new SysId(dbSecurityLink._CreateBy), dbSecurityLink._CreateHost); + securityLink.SetUpdateStamp(dbSecurityLink._UpdateOn, new SysId(dbSecurityLink._UpdateBy), dbSecurityLink._UpdateHost); securityLink.AcceptChanges(); } diff --git a/SacsStandardDbas/Resources/Database/SaInterfaceDbDfn.xml b/SacsStandardDbas/Resources/Database/SaInterfaceDbDfn.xml index 02d32d3..3084ab8 100644 --- a/SacsStandardDbas/Resources/Database/SaInterfaceDbDfn.xml +++ b/SacsStandardDbas/Resources/Database/SaInterfaceDbDfn.xml @@ -1,5 +1,5 @@ - - + + dbo @@ -101,8 +101,8 @@ -9 nvarchar false - 50 - 100 + 100 + 200 0 NoNulls false @@ -266,14 +266,14 @@ dbo
SaInterface
- PK_SaInterface + PK_Interface 1 true false false false - 1 - 1 + 0 + 0 false @@ -286,7 +286,7 @@ dbo SaInterface
- IDX_SaInterface_ContextCode + IDX_Interface_ContextCode 3 true false @@ -311,7 +311,7 @@ dbo SaInterface
- IDX_SaInterface_ContextCategoryType + IDX_Interface_ContextCategoryType 3 false false @@ -690,7 +690,7 @@ dbo SaInterfaceDataItem
- PK_SaInterfaceDataItem + PK_InterfaceDataItem 1 true false @@ -710,7 +710,7 @@ dbo SaInterfaceDataItem
- IDX_SaInterfaceDataItem_InterfaceItemRef + IDX_InterfaceDataItem_InterfaceItemRef 3 true false @@ -750,7 +750,7 @@ dbo SaInterfaceDataItem
- IDX_SaInterfaceDataItem_InterfaceStatusItemRef + IDX_InterfaceDataItem_InterfaceStatusItemRef 3 true false @@ -795,7 +795,7 @@ dbo SaInterfaceDataItem
- IDX_SaInterfaceDataItem_InterfaceDirectionItemRef + IDX_InterfaceDataItem_InterfaceDirectionItemRef 3 false false @@ -830,7 +830,7 @@ dbo SaInterfaceDataItem
- IDX_SaInterfaceDataItem_Item + IDX_InterfaceDataItem_Item 3 false false @@ -855,7 +855,7 @@ dbo SaInterfaceDataItem
- IDX_SaInterfaceDataItem_ItemExternal + IDX_InterfaceDataItem_ItemExternal 3 false false @@ -1178,14 +1178,14 @@ dbo SaInterfaceProcess
- PK_SaInterfaceProcess + PK_InterfaceProcess 1 true false false false - 1 - 22 + 0 + 0 false @@ -1198,7 +1198,7 @@ dbo SaInterfaceProcess
- IDX_SaInterfaceProcess_IntDirSeq + IDX_InterfaceProcess_IntDirSeq 3 true false @@ -1228,32 +1228,7 @@ dbo SaInterfaceProcess
- IDX_SaInterfaceProcess_IntProcAt - 3 - false - false - false - false - 0 - 0 - false - - - 1 - InterfaceId - true - - - 2 - ProcessAt - true - - -
- - dbo - SaInterfaceProcess
- IDX_SaInterfaceProcess_IntProcRef + IDX_InterfaceProcess_IntProc 3 false false @@ -1474,7 +1449,7 @@ dbo SaInterfaceProcessDataItem
- PK_SaInterfaceProcessDataItem + PK_InterfaceProcessDataItem 1 true false @@ -1499,7 +1474,7 @@ dbo SaInterfaceProcessDataItem
- IDX_SaInterfaceProcessDataItem_Item + IDX_InterfaceProcessDataItem_Item 3 false false @@ -1519,7 +1494,7 @@ dbo SaInterfaceProcessDataItem
- IDX_SaInterfaceProcessDataItem_ProcessItemData + IDX_InterfaceProcessDataItem_ProcItemData 3 false false @@ -1589,11 +1564,11 @@ MsgType VarChar - 12 - varchar + -9 + nvarchar false 3 - 3 + 6 0 Nullable true @@ -1609,8 +1584,8 @@ -9 nvarchar false - 1024 - 2048 + 4000 + 8000 0 Nullable true @@ -1759,11 +1734,11 @@ CreateHost VarChar - -9 - nvarchar + 12 + varchar false 64 - 128 + 64 0 Nullable true @@ -1810,11 +1785,11 @@ UpdateHost VarChar - -9 - nvarchar + 12 + varchar false 64 - 128 + 64 0 Nullable true @@ -1825,14 +1800,14 @@ dbo SaInterfaceProcessMessage
- PK_SaInterfaceProcessMessage + PK_InterfaceProcessMessage 1 true false false false - 12 - 342 + 0 + 0 false @@ -1845,7 +1820,7 @@ dbo SaInterfaceProcessMessage
- IDX_SaInterfaceProcessMessage_Process + IDX_InterfaceProcessMessage_Process 3 false false @@ -1865,7 +1840,7 @@ dbo SaInterfaceProcessMessage
- IDX_SaInterfaceProcessMessage_ProcessMsgType + IDX_InterfaceProcessMessage_ProcMsgType 3 false false