diff --git a/SacsStandardAccounts/Accounts/QuickBooks/Online/SaQuickBooksDataItem_Online.cs b/SacsStandardAccounts/Accounts/QuickBooks/Online/SaQuickBooksDataItem_Online.cs index b2ad2dd..5e1a83f 100644 --- a/SacsStandardAccounts/Accounts/QuickBooks/Online/SaQuickBooksDataItem_Online.cs +++ b/SacsStandardAccounts/Accounts/QuickBooks/Online/SaQuickBooksDataItem_Online.cs @@ -4,7 +4,6 @@ using Sarand.Net.Standard.Accounts.QuickBooks.Dbas; using Sarand.Net.Standard.Accounts.QuickBooks.Internal; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; -using Sarand.Net.Standard.Base.Xml; using System; using System.Collections.Generic; using System.Text; diff --git a/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs b/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs index 3f941e9..d16ab38 100644 --- a/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs +++ b/SacsStandardBase/Base/Interfaces/SaInterfaceConsole.cs @@ -45,6 +45,13 @@ namespace Sarand.Net.Standard.Base.Interfaces protected SaInterfaceConsole () { } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardBase/Base/ItemOptions/SaItemOptionConsole.cs b/SacsStandardBase/Base/ItemOptions/SaItemOptionConsole.cs index 4515904..354cea4 100644 --- a/SacsStandardBase/Base/ItemOptions/SaItemOptionConsole.cs +++ b/SacsStandardBase/Base/ItemOptions/SaItemOptionConsole.cs @@ -31,6 +31,13 @@ namespace Sarand.Net.Standard.Base.ItemOptions protected SaItemOptionConsole () { } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardBase/Base/Procs/SacsProcess.cs b/SacsStandardBase/Base/Procs/SaProcess_Base.cs similarity index 98% rename from SacsStandardBase/Base/Procs/SacsProcess.cs rename to SacsStandardBase/Base/Procs/SaProcess_Base.cs index f379016..d419018 100644 --- a/SacsStandardBase/Base/Procs/SacsProcess.cs +++ b/SacsStandardBase/Base/Procs/SaProcess_Base.cs @@ -16,7 +16,7 @@ namespace Sarand.Net.Standard.Base.Procs } //======================================================================= - public abstract class SacsProcess : SacsDisposable + public abstract class SaProcess_Base : SacsDisposable { //------------------------------------------------------------------- // Process options and groups - for configuration of process to run. @@ -81,7 +81,7 @@ namespace Sarand.Net.Standard.Base.Procs //------------------------------------------------------------------- // Construction. - protected SacsProcess (Config config) + protected SaProcess_Base (Config config) { this.config = config; } diff --git a/SacsStandardBase/Base/Procs/SacsReport.cs b/SacsStandardBase/Base/Procs/SaReport_Base.cs similarity index 95% rename from SacsStandardBase/Base/Procs/SacsReport.cs rename to SacsStandardBase/Base/Procs/SaReport_Base.cs index 192e551..2f821cf 100644 --- a/SacsStandardBase/Base/Procs/SacsReport.cs +++ b/SacsStandardBase/Base/Procs/SaReport_Base.cs @@ -5,7 +5,7 @@ using Sarand.Net.Standard.Base.Bus; namespace Sarand.Net.Standard.Base.Procs { //======================================================================= - public abstract class SacsReport : SaErrorStateItem + public abstract class SaReport_Base : SaErrorStateItem { //------------------------------------------------------------------- // Definitions. @@ -22,7 +22,7 @@ namespace Sarand.Net.Standard.Base.Procs //------------------------------------------------------------------- // Construction. - protected SacsReport (Config config) + protected SaReport_Base (Config config) { this.config = config; } diff --git a/SacsStandardBase/Base/ReferenceData/SaReferenceDataConsole.cs b/SacsStandardBase/Base/ReferenceData/SaReferenceDataConsole.cs index e33ce84..bc1ddc3 100644 --- a/SacsStandardBase/Base/ReferenceData/SaReferenceDataConsole.cs +++ b/SacsStandardBase/Base/ReferenceData/SaReferenceDataConsole.cs @@ -145,15 +145,22 @@ namespace Sarand.Net.Standard.Base.ReferenceData //------------------------------------------------------------------- // Static initialisation. - static SaReferenceDataConsole () + static SaReferenceDataConsole() { } //------------------------------------------------------------------- // Construction. - protected SaReferenceDataConsole () + protected SaReferenceDataConsole() { } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. @@ -163,11 +170,11 @@ namespace Sarand.Net.Standard.Base.ReferenceData //--------------------------------------------------------------- // Manage reference data - displays dialog. - public abstract bool ManageReferenceData (bool userCanManageReferenceData, DbUpdateInfo dbUpdateInfo); + public abstract bool ManageReferenceData(bool userCanManageReferenceData, DbUpdateInfo dbUpdateInfo); //--------------------------------------------------------------- // Reference data codes. - public static List GetReferenceDataCodes (ReferenceDataSystemCode systemCode) + public static List GetReferenceDataCodes(ReferenceDataSystemCode systemCode) { switch (systemCode) { diff --git a/SacsStandardBase/Base/Security/SaSecurityConsole.cs b/SacsStandardBase/Base/Security/SaSecurityConsole.cs index 94cf0e5..7410eac 100644 --- a/SacsStandardBase/Base/Security/SaSecurityConsole.cs +++ b/SacsStandardBase/Base/Security/SaSecurityConsole.cs @@ -45,7 +45,7 @@ namespace Sarand.Net.Standard.Base.Security // Definitions. protected class DataItemDfn { - public DataItemDfn (short dataItemType, String caption) + public DataItemDfn(short dataItemType, String caption) { DataItemType = dataItemType; Caption = caption; @@ -59,12 +59,12 @@ namespace Sarand.Net.Standard.Base.Security //------------------------------------------------------------------- // Data members. protected static String GroupSuperCode = "SUPER"; - protected static String AdminUserCode = "admin"; + protected static String AdminUserCode = "admin"; private static List securityItemTypes = new List(); //------------------------------------------------------------------- // Static initialisation - static SaSecurityConsole () + static SaSecurityConsole() { // Security item types. securityItemTypes.Add(SaSecurity.ItemType.User, "USER", "User"); @@ -75,9 +75,16 @@ namespace Sarand.Net.Standard.Base.Security //------------------------------------------------------------------- // Protected construction - use derived classes. - protected SaSecurityConsole () + protected SaSecurityConsole() { } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. @@ -97,14 +104,14 @@ namespace Sarand.Net.Standard.Base.Security // Database properties. public abstract bool DatabaseIsValid { get; } public abstract bool CanUpdateDatabase { get; } - public abstract bool ColumnExists (SaSecurityDbDfn.ColumnIdx columnIdx); + public abstract bool ColumnExists(SaSecurityDbDfn.ColumnIdx columnIdx); //------------------------------------------------------------------- // U t i l i t i e s //------------------------------------------------------------------- // Default user Id. private SysId userIdDefault = new SysId(); - public SysId GetUserIdDefault () + public SysId GetUserIdDefault() { return userIdDefault; } @@ -113,56 +120,56 @@ namespace Sarand.Net.Standard.Base.Security // L o g i n //------------------------------------------------------------------- /// User login. - public abstract bool LoginUser (SysId userId, bool recordLastLogin = true); + public abstract bool LoginUser(SysId userId, bool recordLastLogin = true); /// Using current windows user account. - public abstract bool LoginAuthenticatedUser (); - protected abstract bool OnLogin (SysId userId); + public abstract bool LoginAuthenticatedUser(); + protected abstract bool OnLogin(SysId userId); /// Logout - Clear user and security details. - public abstract bool LogoutUser (); - protected abstract void OnLogout (); + public abstract bool LogoutUser(); + protected abstract void OnLogout(); //------------------------------------------------------------------- // A p p l i c a t i o n I n t e r f a c e //------------------------------------------------------------------- /// Show Login form. - public abstract bool ManageSecurity (bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo); + public abstract bool ManageSecurity(bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo); /// Show Security maintenance form. - public abstract bool ShowUserLoginForm (DbUpdateInfo dbUpdateInfo); + public abstract bool ShowUserLoginForm(DbUpdateInfo dbUpdateInfo); /// User modified event. - public abstract bool OnUserModified (SysId userId); + public abstract bool OnUserModified(SysId userId); /// Security Group modified event. - public abstract bool OnSecurityGroupModified (SysId userId); + public abstract bool OnSecurityGroupModified(SysId userId); //------------------------------------------------------------------- // Password configuration. public PasswordConfig PasswordConfig { get; protected set; } = new PasswordConfig(); /// Show form to change password for currently logged in user. /// Flag to indicate password changed - public abstract bool ShowChangePasswordForm (DbUpdateInfo dbUpdateInfo); + public abstract bool ShowChangePasswordForm(DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- // A p p l i c a t i o n S e c u r i t y R i g h t s //------------------------------------------------------------------- // Register Security Rights. - public abstract void RegisterSecurityRights (); + public abstract void RegisterSecurityRights(); //------------------------------------------------------------------- // Security rights are optionally associated with a specified data item type (>0), // in which case they are always associated with a specific item Id of that type. - public bool RegisterSecurityRight (String code, String desc, short dataItemType = 0) + public bool RegisterSecurityRight(String code, String desc, short dataItemType = 0) { SecurityRights.Add(code, desc, dataItemType); return true; } // Replace previous rights. - public bool RegisterSecurityRights (List securityRights) + public bool RegisterSecurityRights(List securityRights) { SecurityRights.Clear(); SecurityRights.AddRange(securityRights); return true; } // Determine whether any security items are present and allow them to be populated. - public abstract bool RequiresPopulation (); - public abstract bool PopulateSecurityRights (DbUpdateInfo dbUpdateInfo); + public abstract bool RequiresPopulation(); + public abstract bool PopulateSecurityRights(DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- // A p p l i c a t i o n D a t a I t e m s @@ -171,18 +178,18 @@ namespace Sarand.Net.Standard.Base.Security // Items assign: Register the list of application data items of a particular type that can be associated with security rights. // Items full: If specified, only data items in the 'assign' list can be associated with security items and existing security // items that reference data items in the 'full' list but not in the 'assign' list cannot be modified. - public bool RegisterDataItemType (short dataItemType, String caption, List itemsAssign = null, List itemsFull = null) + public bool RegisterDataItemType(short dataItemType, String caption, List itemsAssign = null, List itemsFull = null) { - DataItemDfn dataItemDfn = new DataItemDfn(dataItemType,caption); + DataItemDfn dataItemDfn = new DataItemDfn(dataItemType, caption); if (itemsAssign != null) dataItemDfn.ItemsAssign.AddRange(itemsAssign); if (itemsFull != null) dataItemDfn.ItemsFull.AddRange(itemsFull); - DataItemDfns.Add(dataItemType,dataItemDfn); + DataItemDfns.Add(dataItemType, dataItemDfn); return true; } // Modify list of data item associated with specified type. - public bool RegisterDataItems (short dataItemType, List itemsAssign, List itemsFull = null) + public bool RegisterDataItems(short dataItemType, List itemsAssign, List itemsFull = null) { if (!DataItemDfns.ContainsKey(dataItemType)) return false; DataItemDfn dataItemDfn = DataItemDfns[dataItemType]; @@ -201,11 +208,11 @@ namespace Sarand.Net.Standard.Base.Security // U s e r S e c u r i t y P r o f i l e //------------------------------------------------------------------- /// Retrieve security profile for host computer - public abstract SaSecurityProfile GetHostSecurityProfile (); + public abstract SaSecurityProfile GetHostSecurityProfile(); /// Retrieve security profile for specified user - public abstract SaSecurityProfile GetUserSecurityProfile (SysId userId); + public abstract SaSecurityProfile GetUserSecurityProfile(SysId userId); /// Internal only - creat securitu profile. - protected SaSecurityProfile CreateSecurityProfile (SaSecurityItem secItem, List profileGroups, List profileRights, bool systemAdmin) + protected SaSecurityProfile CreateSecurityProfile(SaSecurityItem secItem, List profileGroups, List profileRights, bool systemAdmin) { return new SaSecurityProfile(secItem, profileGroups, profileRights, systemAdmin); } @@ -244,38 +251,41 @@ namespace Sarand.Net.Standard.Base.Security // S e c u r i t y I t e m s //------------------------------------------------------------------- // Security items (user, computer, group or right). - public bool SecurityItemCodeExists (SaSecurity.ItemType securityItemType, String userCode) + public bool SecurityItemCodeExists(SaSecurity.ItemType securityItemType, String userCode) { return SysId.IsValid(GetIdForItemCode(securityItemType, userCode)); } - public SaSecurityItem GetUserByCode (String code) + public SaSecurityItem GetUserByCode(String code) { return GetSecurityItemByCode(SaSecurity.ItemType.User, code); } - public abstract SaSecurityItem GetSecurityItemByCode (SaSecurity.ItemType securityItemType, String code); - public abstract SaSecurityItem GetSecurityItem (SaSecurityItem.Params prm); + public abstract SaSecurityItem GetUserByEmail(String emailAddress); + public abstract SaSecurityItem GetSecurityItemById(SaSecurity.ItemType securityItemType, SysId id); + public abstract SaSecurityItem GetSecurityItemByCode(SaSecurity.ItemType securityItemType, String code); + public abstract SaSecurityItem GetSecurityItem(SaSecurityItem.Params prm); // Security item properties. - public abstract SysId GetIdForItemCode (SaSecurity.ItemType securityItemType, string code); - public abstract String GetCodeForItemId (SysId securityItemId); - public abstract String GetNameForItemId (SysId securityItemId); - public abstract Dictionary GetSecurityItemDescriptions (List securityItemIds); + public abstract SysId GetIdForItemCode(SaSecurity.ItemType securityItemType, string code); + public abstract String GetCodeForItemId(SysId securityItemId); + public abstract String GetNameForItemId(SysId securityItemId); + public abstract Dictionary GetSecurityItemDescriptions(List securityItemIds); // Security Item list. - public abstract ColumnDfn GetSecurityItemColumnDfn (SaSecurityItem.Column columnId, String caption = "", int width = 0); - public abstract long GetSecurityItemCount (SaSecurityItem.Params prm); - public abstract List GetSecurityItemList (SaSecurityItem.Params prm); - public abstract DbResultSet ExecuteSecurityItemQuery (List columns, SaSecurityItem.Params prm); - public abstract DataValue GetSecurityItemDataValue (ColumnDfn column, NamedValue.Map values); + public abstract ColumnDfn GetSecurityItemColumnDfn(SaSecurityItem.Column columnId, String caption = "", int width = 0); + public abstract long GetSecurityItemCount(SaSecurityItem.Params prm); + public abstract List GetSecurityItemList(SaSecurityItem.Params prm); + public abstract DbResultSet ExecuteSecurityItemQuery(List columns, SaSecurityItem.Params prm); + public abstract DataValue GetSecurityItemDataValue(ColumnDfn column, NamedValue.Map values); //------------------------------------------------------------------- // Security item updates. - public abstract bool CreateUser (String code, String name, DbUpdateInfo dbUpdateInfo); - public abstract bool AssignUserToGroup (String userCode, String groupCode, DbUpdateInfo dbUpdateInfo); + public abstract bool CreateUser(String code, String name, DbUpdateInfo dbUpdateInfo); + public abstract bool AssignUserToGroup(String userCode, String groupCode, DbUpdateInfo dbUpdateInfo); + public abstract bool UpdateSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- // S e c u r i t y I t e m s L i n k s //------------------------------------------------------------------- // Security item links. - public abstract bool ItemsAreLinked (SysId securityItemId1, SysId securityItemId2); + public abstract bool ItemsAreLinked(SysId securityItemId1, SysId securityItemId2); //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/Security/SaSecurityItem.cs b/SacsStandardBase/Base/Security/SaSecurityItem.cs index 9e350c2..86cfb9b 100644 --- a/SacsStandardBase/Base/Security/SaSecurityItem.cs +++ b/SacsStandardBase/Base/Security/SaSecurityItem.cs @@ -5,6 +5,7 @@ using System.Text; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.App; +using Sarand.Net.Standard.Base.Utils; namespace Sarand.Net.Standard.Base.Security { @@ -45,11 +46,18 @@ namespace Sarand.Net.Standard.Base.Security public String EmailAddress { get; set; } = String.Empty; public String Description { get; set; } = String.Empty; public String Location { get; set; } = String.Empty; + public int DataItemType { get; set; } = -1; + // Security. public String PasswordEncrypted { get; set; } = String.Empty; public String PasswordSalt { get; set; } = String.Empty; public String PasswordHash { get; set; } = String.Empty; + public List PasswordHistory { get; } = new List(); + public String PasswordToken { get; set; } = String.Empty; + public DateTime PasswordChangedAt { get; set; } = DateTime.MinValue; + // Login. public DateTime LastLogin { get; set; } = DateTime.MinValue; - public int DataItemType { get; set; } = -1; + public DateTime LastInvalidLoginAt { get; set; } = DateTime.MinValue; + public short InvalidLoginCount { get; set; } } //------------------------------------------------------------------- @@ -89,6 +97,12 @@ namespace Sarand.Net.Standard.Base.Security get { return data.Location; } set { CheckChanged(data.Location, value); data.Location = value; } } + public int DataItemType + { + get { return data.DataItemType; } + set { CheckChanged(data.DataItemType, value); data.DataItemType = value; } + } + // Security. public String PasswordEncrypted { get { return data.PasswordEncrypted; } @@ -104,15 +118,41 @@ namespace Sarand.Net.Standard.Base.Security get { return data.PasswordHash; } set { CheckChanged(data.PasswordHash, value); data.PasswordHash = value; } } + public List PasswordHistory + { + get { return data.PasswordHistory; } + set + { + CheckChanged(data.PasswordHistory, value); + data.PasswordHistory.Clear(); + data.PasswordHistory.AddRange((value ?? new List()).FindAll(item => !StringUtil.IsEmpty(StringUtil.TrimAll(item)))); + } + } + public String PasswordToken + { + get { return data.PasswordToken; } + set { CheckChanged(data.PasswordToken, value); data.PasswordToken = value; } + } + public DateTime PasswordChangedAt + { + get { return data.PasswordChangedAt; } + set { CheckChanged(data.PasswordChangedAt, value); data.PasswordChangedAt = value; } + } + // Login. public DateTime LastLogin { get { return data.LastLogin; } set { CheckChanged(data.LastLogin, value); data.LastLogin = value; } } - public int DataItemType + public DateTime LastInvalidLoginAt { - get { return data.DataItemType; } - set { CheckChanged(data.DataItemType, value); data.DataItemType = value; } + get { return data.LastInvalidLoginAt; } + set { CheckChanged(data.LastInvalidLoginAt, value); data.LastInvalidLoginAt = value; } + } + public short InvalidLoginCount + { + get { return data.InvalidLoginCount; } + set { CheckChanged(data.InvalidLoginCount, value); data.InvalidLoginCount = value; } } // Flags. public bool AuthenticatedUser @@ -128,11 +168,18 @@ namespace Sarand.Net.Standard.Base.Security EmailAddress = data.EmailAddress; Description = data.Description; Location = data.Location; + DataItemType = data.DataItemType; + // Security. PasswordEncrypted = data.PasswordEncrypted; PasswordSalt = data.PasswordSalt; PasswordHash = data.PasswordHash; + PasswordHistory = data.PasswordHistory; + PasswordToken = data.PasswordToken; + PasswordChangedAt = data.PasswordChangedAt; + // Login. LastLogin = data.LastLogin; - DataItemType = data.DataItemType; + LastInvalidLoginAt = data.LastInvalidLoginAt; + InvalidLoginCount = data.InvalidLoginCount; base.PopulateFrom(data); } public Data Clone () @@ -153,7 +200,15 @@ namespace Sarand.Net.Standard.Base.Security public ValidValue EmailAddress { get; set; } = ValidValue.Valid; public ValidValue Description { get; set; } = ValidValue.Valid; public ValidValue Location { get; set; } = ValidValue.Valid; + // Security. public ValidValue Password { get; set; } = ValidValue.Valid; + public ValidValue PasswordHistory { get; set; } = ValidValue.Valid; + public ValidValue PasswordToken { get; set; } = ValidValue.Valid; + public ValidValue PasswordChanged { get; set; } = ValidValue.Valid; + // Login. + public ValidValue LastLogin { get; set; } = ValidValue.Valid; + public ValidValue LastInvalidLogin { get; set; } = ValidValue.Valid; + public ValidValue InvalidLoginCount { get; set; } = ValidValue.Valid; } //------------------------------------------------------------------- @@ -239,6 +294,14 @@ namespace Sarand.Net.Standard.Base.Security get { return data.Location; } set { data.Location = value; } } + public int DataItemType + { + get { return data.DataItemType; } + set { data.DataItemType = value; } + } + + // Security. + [Obsolete("Avoid using the original C++ password encryption - switch to hashed password instead.")] public String PasswordEncrypted { get { return data.PasswordEncrypted; } @@ -254,15 +317,37 @@ namespace Sarand.Net.Standard.Base.Security get { return data.PasswordHash; } set { data.PasswordHash = value; } } + public List PasswordHistory + { + get { return data.PasswordHistory; } + set { data.PasswordHistory = value; } + } + public String PasswordToken + { + get { return data.PasswordToken; } + set { data.PasswordToken = value; } + } + public DateTime PasswordChangedAt + { + get { return data.PasswordChangedAt; } + set { data.PasswordChangedAt = value; } + } + + // Login. public DateTime LastLogin { get { return data.LastLogin; } set { data.LastLogin = value; } } - public int DataItemType + public DateTime LastInvalidLoginAt { - get { return data.DataItemType; } - set { data.DataItemType = value; } + get { return data.LastInvalidLoginAt; } + set { data.LastInvalidLoginAt = value; } + } + public short InvalidLoginCount + { + get { return data.InvalidLoginCount; } + set { data.InvalidLoginCount = value; } } //------------------------------------------------------------------- diff --git a/SacsStandardBase/Base/Security/SaSecurityMgr-SecurityItem.cs b/SacsStandardBase/Base/Security/SaSecurityMgr-SecurityItem.cs index 4b147e2..4ef260f 100644 --- a/SacsStandardBase/Base/Security/SaSecurityMgr-SecurityItem.cs +++ b/SacsStandardBase/Base/Security/SaSecurityMgr-SecurityItem.cs @@ -28,7 +28,9 @@ namespace Sarand.Net.Standard.Base.Security public abstract bool SecurityItemExistsById (SysId id); public abstract bool SecurityItemExistsByTypeCode (SaSecurity.ItemType securityItemType, String code); public abstract SaSecurityItem GetSecurityItemById (SysId id); - public abstract SaSecurityItem GetSecurityItemByTypeCode (SaSecurity.ItemType securityItemType, String code); + public abstract SaSecurityItem GetSecurityItemByTypeId(SaSecurity.ItemType securityItemType, SysId id); + public abstract SaSecurityItem GetSecurityItemByTypeEmail(SaSecurity.ItemType securityItemType, String emailAddress); + public abstract SaSecurityItem GetSecurityItemByTypeCode(SaSecurity.ItemType securityItemType, String code); public abstract SaSecurityItem GetSecurityItem (SaSecurityItem.Params prmSecItem); // Create Security Item. diff --git a/SacsStandardBase/Base/UpdateLog/SaUpdateLogConsole.cs b/SacsStandardBase/Base/UpdateLog/SaUpdateLogConsole.cs index 479a6e1..dc309b4 100644 --- a/SacsStandardBase/Base/UpdateLog/SaUpdateLogConsole.cs +++ b/SacsStandardBase/Base/UpdateLog/SaUpdateLogConsole.cs @@ -28,6 +28,13 @@ namespace Sarand.Net.Standard.Base.UpdateLog protected SaUpdateLogConsole () { } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs index a6f89b9..c5299a4 100644 --- a/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/Interfaces/SaInterfaceConsole_Dbas.cs @@ -29,6 +29,14 @@ namespace Sarand.Net.Standard.Dbas.Interfaces Database = database; interfaceMgr = new SaInterfaceMgr_Dbas(this); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (interfaceMgr != null) interfaceMgr.Dispose(); interfaceMgr = null; + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardDbas/Dbas/ItemOptions/SaItemOptionConsole_Dbas.cs b/SacsStandardDbas/Dbas/ItemOptions/SaItemOptionConsole_Dbas.cs index 0202722..d9e2bd3 100644 --- a/SacsStandardDbas/Dbas/ItemOptions/SaItemOptionConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/ItemOptions/SaItemOptionConsole_Dbas.cs @@ -18,17 +18,25 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions //------------------------------------------------------------------- // Static initialisation. - static SaItemOptionConsole_Dbas () + static SaItemOptionConsole_Dbas() { } //------------------------------------------------------------------- // Construction. - protected SaItemOptionConsole_Dbas (SacsDatabase database) + protected SaItemOptionConsole_Dbas(SacsDatabase database) { Database = database; itemOptionMgr = new SaItemOptionMgr_Dbas(this); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (itemOptionMgr != null) itemOptionMgr.Dispose(); itemOptionMgr = null; + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. @@ -38,11 +46,11 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions //------------------------------------------------------------------- // Item Options form. - public override bool MangageItemOptions (List itemOptions) + public override bool MangageItemOptions(List itemOptions) { throw new NotImplementedException(); } - public override bool ShowItemOptionsDialog (ItemId itemId, DbUpdateInfo dbUpdateInfo) + public override bool ShowItemOptionsDialog(ItemId itemId, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (ShowItemOptionsDialogFn != null) @@ -50,24 +58,24 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions return false; } // Method to display Update Log dialog. - protected delegate bool ShowItemOptionsDialogFunction (SaItemOptionConsole codeTypeConsole, ItemId itemId, DbUpdateInfo dbUpdateInfo); + protected delegate bool ShowItemOptionsDialogFunction(SaItemOptionConsole codeTypeConsole, ItemId itemId, DbUpdateInfo dbUpdateInfo); protected abstract ShowItemOptionsDialogFunction ShowItemOptionsDialogFn { get; } //******************************************************************* // I t e m O p t i o n s //******************************************************************* // Retrieve specific option. - public override SaItemOption GetItemOption (ItemId itemId, String name, String context) + public override SaItemOption GetItemOption(ItemId itemId, String name, String context) { - return itemOptionMgr.GetItemOption(itemId,name,context); + return itemOptionMgr.GetItemOption(itemId, name, context); } // Retrieve options. - public override List GetItemOptions (SaItemOption.Params prmItemOption) + public override List GetItemOptions(SaItemOption.Params prmItemOption) { return itemOptionMgr.GetItemOptionList(prmItemOption); } - public override List GetItemOptionsForItem (ItemId itemId) + public override List GetItemOptionsForItem(ItemId itemId) { if (!ItemId.IsValid(itemId)) return new List(); @@ -77,31 +85,31 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions } // Retrieve specific option for range of items (all matching item if ID list is blank). - public override List GetItemOptions (List itemIds, String name, String context) + public override List GetItemOptions(List itemIds, String name, String context) { SaItemOption.Params prmItemOption = new SaItemOption.Params(); prmItemOption.IncludedItemIds.AddRange(itemIds); if (!StringUtil.IsEmpty(name)) - prmItemOption.IncludedNameContexts.Add(name,context); + prmItemOption.IncludedNameContexts.Add(name, context); return itemOptionMgr.GetItemOptionList(prmItemOption); } //------------------------------------------------------------------- // Create an item option. - public override SaItemOption CreateItemOption (ItemId itemId, String name, String context) + public override SaItemOption CreateItemOption(ItemId itemId, String name, String context) { return itemOptionMgr.CreateItemOption(itemId, name, context); } // Item independent options, eg. for processes. - public override SaItemOption CreateItemOptionByNameContext (String name, String context) + public override SaItemOption CreateItemOptionByNameContext(String name, String context) { return itemOptionMgr.CreateItemOption(null, name, context); } //------------------------------------------------------------------- // Store item option - create if not exsts, otherwise update. - public override bool StoreItemOption (SaItemOption itemOption, DbUpdateInfo dbUpdateInfo) + public override bool StoreItemOption(SaItemOption itemOption, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); // If option exists, update it. @@ -119,21 +127,21 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions return true; } // Store a specific option against the specified item. - public override bool StoreItemOption (ItemId itemId, String name, String context, String sValue, DbUpdateInfo dbUpdateInfo) + public override bool StoreItemOption(ItemId itemId, String name, String context, String sValue, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); - SaItemOption itemOption = CreateItemOption(itemId,name,context); + SaItemOption itemOption = CreateItemOption(itemId, name, context); return StoreItemOption(itemOption, dbUpdateInfo); } // Store the updated list of options against the specified item. - public override bool StoreItemOptions (ItemId itemId, List itemOptions, DbUpdateInfo dbUpdateInfo) + public override bool StoreItemOptions(ItemId itemId, List itemOptions, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); // Validate item options. foreach (SaItemOption itemOption in itemOptions) { if (itemOption.ItemId != null && !itemOption.ItemId.Equals(itemId)) return SetErrorState("Inconsistent item id in option list"); - if (!itemOptionMgr.IsValidItemOption(itemOption)) return SetErrorState("Validation error: "+itemOptionMgr.ErrorStateMessage); + if (!itemOptionMgr.IsValidItemOption(itemOption)) return SetErrorState("Validation error: " + itemOptionMgr.ErrorStateMessage); } // Retrieve existing options. List existingItemOptions = GetItemOptionsForItem(itemId).FindAll(item => item.ItemId.Equals(itemId)); @@ -147,25 +155,25 @@ namespace Sarand.Net.Standard.Dbas.ItemOptions // Clear options not in the list. foreach (SaItemOption itemOption in existingItemOptions) { - if (!ClearItemOption(itemOption,dbUpdateInfo)) return false; + if (!ClearItemOption(itemOption, dbUpdateInfo)) return false; } return true; } // Remove option(s) for the specified item. - public override bool ClearItemOption (SaItemOption itemOption, DbUpdateInfo dbUpdateInfo) + public override bool ClearItemOption(SaItemOption itemOption, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (itemOptionMgr.ItemOptionExists(itemOption) && !itemOptionMgr.DeleteItemOption(itemOption, dbUpdateInfo)) return SetErrorState(itemOptionMgr.ErrorStateMessage); return true; } - public override bool ClearItemOption (ItemId itemId, String name, String context, DbUpdateInfo dbUpdateInfo) + public override bool ClearItemOption(ItemId itemId, String name, String context, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); - return ClearItemOption(CreateItemOption(itemId, name, context),dbUpdateInfo); + return ClearItemOption(CreateItemOption(itemId, name, context), dbUpdateInfo); } - public override bool ClearItemOptions (ItemId itemId, DbUpdateInfo dbUpdateInfo) + public override bool ClearItemOptions(ItemId itemId, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (!itemOptionMgr.ClearItemOptionsForItem(itemId, dbUpdateInfo)) diff --git a/SacsStandardDbas/Dbas/Proc/SaDbProcess_CompareDatabaseSchemas.cs b/SacsStandardDbas/Dbas/Proc/SaDbProcess_CompareDatabaseSchemas.cs index 034c629..4e01e99 100644 --- a/SacsStandardDbas/Dbas/Proc/SaDbProcess_CompareDatabaseSchemas.cs +++ b/SacsStandardDbas/Dbas/Proc/SaDbProcess_CompareDatabaseSchemas.cs @@ -13,11 +13,11 @@ using System.Threading.Tasks; namespace Sarand.Net.Standard.Dbas.Proc { //======================================================================= - public class SaDbProcess_CompareDatabaseSchemas : SacsProcess + public class SaDbProcess_CompareDatabaseSchemas : SaProcess_Base { //------------------------------------------------------------------- // Configuration. - public new class Config : SacsProcess.Config + public new class Config : SaProcess_Base.Config { public Config(ISacsDatabase sourceDatabase, ISacsDatabase targetDatabase) { diff --git a/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbDefinition.cs b/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbDefinition.cs index 68279c5..4704f8c 100644 --- a/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbDefinition.cs +++ b/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbDefinition.cs @@ -16,7 +16,7 @@ using System.Threading.Tasks; namespace Sarand.Net.Standard.Dbas.Proc { //======================================================================= - public class SaDbProcess_ConvertDbDefinition : SacsProcess + public class SaDbProcess_ConvertDbDefinition : SaProcess_Base { //------------------------------------------------------------------- // Configuration. @@ -30,7 +30,7 @@ namespace Sarand.Net.Standard.Dbas.Proc Unknown = 0, CsCode } - public new class Config : SacsProcess.Config + public new class Config : SaProcess_Base.Config { public Config () { diff --git a/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbSchema.cs b/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbSchema.cs index a698cd7..c23509d 100644 --- a/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbSchema.cs +++ b/SacsStandardDbas/Dbas/Proc/SaDbProcess_ConvertDbSchema.cs @@ -17,11 +17,11 @@ using System.Xml.Linq; namespace Sarand.Net.Standard.Dbas.Proc { //======================================================================= - public class SaDbProcess_ConvertDbSchema : SacsProcess + public class SaDbProcess_ConvertDbSchema : SaProcess_Base { //------------------------------------------------------------------- // Configuration. - public new class Config : SacsProcess.Config + public new class Config : SaProcess_Base.Config { public Config() { diff --git a/SacsStandardDbas/Dbas/ReferenceData/SaReferenceDataConsole_Dbas.cs b/SacsStandardDbas/Dbas/ReferenceData/SaReferenceDataConsole_Dbas.cs index cf16329..c28c33c 100644 --- a/SacsStandardDbas/Dbas/ReferenceData/SaReferenceDataConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/ReferenceData/SaReferenceDataConsole_Dbas.cs @@ -28,6 +28,13 @@ namespace Sarand.Net.Standard.Dbas.ReferenceData Database = database; referenceDataMgr = new SaReferenceDataMgr_Dbas(this); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardDbas/Dbas/Security/SaSecurityConsole_Dbas.cs b/SacsStandardDbas/Dbas/Security/SaSecurityConsole_Dbas.cs index 2943098..422e8c7 100644 --- a/SacsStandardDbas/Dbas/Security/SaSecurityConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/Security/SaSecurityConsole_Dbas.cs @@ -20,31 +20,39 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Protected construction - use derived class. - protected SaSecurityConsole_Dbas (SacsDatabase database) + protected SaSecurityConsole_Dbas(SacsDatabase database) { Database = database; // Initialise security manager. securityMgr = new SaSecurityMgr_Dbas(this); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (securityMgr != null) securityMgr.Dispose(); securityMgr = null; + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Database properties. internal SacsDatabase Database { get; set; } public override bool DatabaseIsValid { get { return securityMgr.DatabaseIsValid; } } public override bool CanUpdateDatabase { get { return securityMgr.CanUpdateDatabase; } } - public override bool ColumnExists (SaSecurityDbDfn.ColumnIdx columnIdx) + public override bool ColumnExists(SaSecurityDbDfn.ColumnIdx columnIdx) { - return Database != null && Database.ColumnExists(SaSecurityDbDfn.GetTableName(SaSecurityDbDfn.GetTableForColumn(columnIdx), false), SaSecurityDbDfn.GetColumnName(columnIdx,false)); + return Database != null && Database.ColumnExists(SaSecurityDbDfn.GetTableName(SaSecurityDbDfn.GetTableForColumn(columnIdx), false), SaSecurityDbDfn.GetColumnName(columnIdx, false)); } //------------------------------------------------------------------- // A p p l i c a t i o n I n t e r f a c e //------------------------------------------------------------------- // Show User Login form. - protected delegate bool ShowUserLoginFormFunction (SaSecurityConsole securityConsole, DbUpdateInfo dbUpdateInfo); + protected delegate bool ShowUserLoginFormFunction(SaSecurityConsole securityConsole, DbUpdateInfo dbUpdateInfo); protected abstract ShowUserLoginFormFunction ShowUserLoginFormFn { get; } // Manage security. - public override bool ShowUserLoginForm (DbUpdateInfo dbUpdateInfo) + public override bool ShowUserLoginForm(DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (ShowUserLoginFormFn != null) @@ -54,10 +62,10 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Method to display Security management form. - protected delegate bool ShowManageSecurityDialogFunction (SaSecurityConsole securityConsole, SaSecurityMgr securityMgr, bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo); + protected delegate bool ShowManageSecurityDialogFunction(SaSecurityConsole securityConsole, SaSecurityMgr securityMgr, bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo); protected abstract ShowManageSecurityDialogFunction ShowManageSecurityDialogFn { get; } // Manage security. - public override bool ManageSecurity (bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo) + public override bool ManageSecurity(bool userCanManageSecurity, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (ShowManageSecurityDialogFn != null) @@ -66,7 +74,7 @@ namespace Sarand.Net.Standard.Dbas.Security } //------------------------------------------------------------------- - public override bool ShowChangePasswordForm (DbUpdateInfo dbUpdateInfo) + public override bool ShowChangePasswordForm(DbUpdateInfo dbUpdateInfo) { ClearErrorState(); throw new NotImplementedException(); @@ -75,7 +83,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // A p p l i c a t i o n S e c u r i t y R i g h t s //------------------------------------------------------------------- - public override bool RequiresPopulation () + public override bool RequiresPopulation() { ClearErrorState(); if (SecurityRights.Count == 0) return false; @@ -86,7 +94,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return false; } - public override bool PopulateSecurityRights (DbUpdateInfo dbUpdateInfo) + public override bool PopulateSecurityRights(DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (SecurityRights.Count == 0) return false; @@ -107,7 +115,7 @@ namespace Sarand.Net.Standard.Dbas.Security if (!HasErrorState()) PopulateAdminUser(dbUpdateInfo); return !HasErrorState(); } - private bool PopulateSuperGroup (DbUpdateInfo dbUpdateInfo) + private bool PopulateSuperGroup(DbUpdateInfo dbUpdateInfo) { ClearErrorState(); SaSecurityItem superGroup = securityMgr.GetSecurityItemByTypeCode(SaSecurity.ItemType.Group, GroupSuperCode); @@ -138,7 +146,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return !HasErrorState(); } - private bool PopulateAdminUser (DbUpdateInfo dbUpdateInfo) + private bool PopulateAdminUser(DbUpdateInfo dbUpdateInfo) { ClearErrorState(); SaSecurityItem user = null; @@ -179,7 +187,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // L o g i n //------------------------------------------------------------------- - public override bool LoginUser (SysId userId, bool recordLastLogin = true) + public override bool LoginUser(SysId userId, bool recordLastLogin = true) { String fn = GetType().Name + ".LoginUser"; ClearErrorState(); @@ -200,7 +208,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return true; } - public override bool LoginAuthenticatedUser () + public override bool LoginAuthenticatedUser() { String fn = GetType().Name + ".LoginAuthenticatedUser"; ClearErrorState(); @@ -234,7 +242,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- /// Logout - Clear user and security details. - public override bool LogoutUser () + public override bool LogoutUser() { OnLogout(); return true; @@ -245,7 +253,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- private SaSecurityProfile hostSecurityProfile; /// Retrieve security profile for host computer - public override SaSecurityProfile GetHostSecurityProfile () + public override SaSecurityProfile GetHostSecurityProfile() { ClearErrorState(); if (hostSecurityProfile == null) @@ -256,12 +264,12 @@ namespace Sarand.Net.Standard.Dbas.Security return hostSecurityProfile; } /// Retrieve security profile for specified user - public override SaSecurityProfile GetUserSecurityProfile (SysId userId) + public override SaSecurityProfile GetUserSecurityProfile(SysId userId) { ClearErrorState(); return GetSecurityProfile(securityMgr.GetSecurityItemById(userId)); } - private SaSecurityProfile GetSecurityProfile (SaSecurityItem secItem) + private SaSecurityProfile GetSecurityProfile(SaSecurityItem secItem) { String fn = GetType().Name + ".PopulateSecurityProfile"; if (secItem == null || !SysId.IsValid(secItem.Id)) return null; @@ -364,21 +372,29 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // S e c u r i t y I t e m s //------------------------------------------------------------------- - public override SaSecurityItem GetSecurityItemByCode (SaSecurity.ItemType securityItemType, string code) + public override SaSecurityItem GetUserByEmail(String emailAddress) + { + return securityMgr.GetSecurityItemByTypeEmail(SaSecurity.ItemType.User, emailAddress); + } + public override SaSecurityItem GetSecurityItemById(SaSecurity.ItemType securityItemType, SysId id) + { + return securityMgr.GetSecurityItemByTypeId(securityItemType, id); + } + public override SaSecurityItem GetSecurityItemByCode(SaSecurity.ItemType securityItemType, string code) { return securityMgr.GetSecurityItemByTypeCode(securityItemType, code); } - public override SaSecurityItem GetSecurityItem (SaSecurityItem.Params prm) + public override SaSecurityItem GetSecurityItem(SaSecurityItem.Params prm) { ClearErrorState(); - SaSecurityItem securityItem = securityMgr.GetSecurityItem (prm); + SaSecurityItem securityItem = securityMgr.GetSecurityItem(prm); SetErrorState(securityMgr.ErrorStateMessage); return securityItem; } //------------------------------------------------------------------- // Security Item properties. - public override SysId GetIdForItemCode (SaSecurity.ItemType securityItemType, string code) + public override SysId GetIdForItemCode(SaSecurity.ItemType securityItemType, string code) { ClearErrorState(); if (securityItemType != SaSecurity.ItemType.Unknown && !StringUtil.IsEmpty(code)) @@ -409,7 +425,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return null; } - public override string GetCodeForItemId (SysId itemId) + public override string GetCodeForItemId(SysId itemId) { ClearErrorState(); if (!SysId.IsValid(itemId)) @@ -441,7 +457,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return ""; } - public override string GetNameForItemId (SysId itemId) + public override string GetNameForItemId(SysId itemId) { ClearErrorState(); if (!SysId.IsValid(itemId)) @@ -473,7 +489,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return ""; } - public override Dictionary GetSecurityItemDescriptions (List securityItemIds) + public override Dictionary GetSecurityItemDescriptions(List securityItemIds) { ClearErrorState(); Dictionary securityItemDescs = new Dictionary(); @@ -505,7 +521,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Security item updates. - public override bool CreateUser (string code, string name, DbUpdateInfo dbUpdateInfo) + public override bool CreateUser(string code, string name, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); if (StringUtil.IsEmpty(code) || StringUtil.IsEmpty(name)) @@ -524,37 +540,44 @@ namespace Sarand.Net.Standard.Dbas.Security return !HasErrorState(); } - public override bool AssignUserToGroup (string userCode, string groupCode, DbUpdateInfo dbUpdateInfo) + public override bool AssignUserToGroup(string userCode, string groupCode, DbUpdateInfo dbUpdateInfo) { ClearErrorState(); throw new NotImplementedException(); } + public override bool UpdateSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) + { + ClearErrorState(); + if (!securityMgr.UpdateSecurityItem(securityItem, dbUpdateInfo)) + return SetErrorState(securityMgr.ErrorStateMessage); + return !HasErrorState(); + } //------------------------------------------------------------------- // Security Item list. - public override ColumnDfn GetSecurityItemColumnDfn (SaSecurityItem.Column columnId, String caption = "", int width = 0) + public override ColumnDfn GetSecurityItemColumnDfn(SaSecurityItem.Column columnId, String caption = "", int width = 0) { ClearErrorState(); return securityMgr.GetSecurityItemColumnDfn(columnId, caption, width); } - public override long GetSecurityItemCount (SaSecurityItem.Params prm) + public override long GetSecurityItemCount(SaSecurityItem.Params prm) { ClearErrorState(); return securityMgr.GetSecurityItemCount(prm); } - public override List GetSecurityItemList (SaSecurityItem.Params prm) + public override List GetSecurityItemList(SaSecurityItem.Params prm) { ClearErrorState(); return securityMgr.GetSecurityItemList(prm); } - public override DbResultSet ExecuteSecurityItemQuery (List columns, SaSecurityItem.Params prm) + public override DbResultSet ExecuteSecurityItemQuery(List columns, SaSecurityItem.Params prm) { ClearErrorState(); DbResultSet resultSet = securityMgr.ExecuteSecurityItemQuery(columns, prm); SetErrorState(securityMgr.ErrorStateMessage); return resultSet; } - public override DataValue GetSecurityItemDataValue (ColumnDfn column, NamedValue.Map values) + public override DataValue GetSecurityItemDataValue(ColumnDfn column, NamedValue.Map values) { ClearErrorState(); return securityMgr.GetSecurityItemDataValue(column, values); @@ -564,7 +587,7 @@ namespace Sarand.Net.Standard.Dbas.Security // S e c u r i t y I t e m s L i n k s //------------------------------------------------------------------- // Security item links. - public override bool ItemsAreLinked (SysId itemId1, SysId itemId2) + public override bool ItemsAreLinked(SysId itemId1, SysId itemId2) { ClearErrorState(); if (!SysId.IsValid(itemId1) || !SysId.IsValid(itemId2)) return false; diff --git a/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityItem.cs b/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityItem.cs index 7505be0..f3be614 100644 --- a/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityItem.cs +++ b/SacsStandardDbas/Dbas/Security/SaSecurityMgr_Dbas-SecurityItem.cs @@ -20,17 +20,17 @@ namespace Sarand.Net.Standard.Dbas.Security // S e c u r i t y I t e m //******************************************************************* // Associated data. - public override bool SecurityItemIsSourceOfLinks (SysId securityItemId) + public override bool SecurityItemIsSourceOfLinks(SysId securityItemId) { - String filter = SaSecurityDbDfn.GetColumnName(SaSecurityDbDfn.ColumnIdx.SaSecLink_ItemOwner)+"="+SysId.ToString(securityItemId); + String filter = SaSecurityDbDfn.GetColumnName(SaSecurityDbDfn.ColumnIdx.SaSecLink_ItemOwner) + "=" + SysId.ToString(securityItemId); return (Database.GetRowCount(TableName_SecLink, filter) > 0); } - public override bool SecurityItemIsTargetOfLinks (SysId securityItemId) + public override bool SecurityItemIsTargetOfLinks(SysId securityItemId) { - String filter = SaSecurityDbDfn.GetColumnName(SaSecurityDbDfn.ColumnIdx.SaSecLink_ItemTarget)+"="+SysId.ToString(securityItemId); + String filter = SaSecurityDbDfn.GetColumnName(SaSecurityDbDfn.ColumnIdx.SaSecLink_ItemTarget) + "=" + SysId.ToString(securityItemId); return (Database.GetRowCount(TableName_SecLink, filter) > 0); } - public override bool SecurityItemHasLinksWith (SysId securityItemIdOwner, SysId securityItemIdTarget) + public override bool SecurityItemHasLinksWith(SysId securityItemIdOwner, SysId securityItemIdTarget) { SaSecurityLink.Params prmSecLink = new SaSecurityLink.Params(); prmSecLink.includedItemIdsOwner.Add(securityItemIdOwner); @@ -41,7 +41,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Security Item exists. - public override bool SecurityItemExistsById (SysId id) + public override bool SecurityItemExistsById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return false; @@ -50,7 +50,7 @@ namespace Sarand.Net.Standard.Dbas.Security prmSecItem.StatusCat = SaSecurityItem.StatusCat.Any; return GetSecurityItemCount(prmSecItem) == 1; } - public override bool SecurityItemExistsByTypeCode (SaSecurity.ItemType securityItemType, string code) + public override bool SecurityItemExistsByTypeCode(SaSecurity.ItemType securityItemType, string code) { ClearErrorState(); if ((int)securityItemType < 1 || StringUtil.IsEmpty(code)) return false; @@ -63,11 +63,11 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Get SecurityItem. - public override SaSecurityItem GetSecurityItem (SaSecurityItem.Params prmSecItem) + public override SaSecurityItem GetSecurityItem(SaSecurityItem.Params prmSecItem) { return GetSecurityItem(GetSecurityItemQueryFilter(prmSecItem).Concat(" AND ", "(", ")")); } - private SaSecurityItem GetSecurityItem (String filter) + private SaSecurityItem GetSecurityItem(String filter) { ClearErrorState(); if (GetSecurityItemCount(filter) != 1) return null; @@ -90,7 +90,7 @@ namespace Sarand.Net.Standard.Dbas.Security } return securityItem; } - public override SaSecurityItem GetSecurityItemById (SysId id) + public override SaSecurityItem GetSecurityItemById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return null; @@ -99,7 +99,27 @@ namespace Sarand.Net.Standard.Dbas.Security prmSecItem.StatusCat = SaSecurityItem.StatusCat.Any; return GetSecurityItem(GetSecurityItemQueryFilter(prmSecItem).Concat(" AND ", "(", ")")); } - public override SaSecurityItem GetSecurityItemByTypeCode (SaSecurity.ItemType securityItemType, string code) + public override SaSecurityItem GetSecurityItemByTypeId(SaSecurity.ItemType securityItemType, SysId id) + { + ClearErrorState(); + if ((int)securityItemType < 1 || !SysId.IsValid(id)) return null; + SaSecurityItem.Params prmSecItem = new SaSecurityItem.Params(); + prmSecItem.IncludedIds.Add(id); + prmSecItem.SecurityItemType = securityItemType; + prmSecItem.StatusCat = SaSecurityItem.StatusCat.Any; + return GetSecurityItem(GetSecurityItemQueryFilter(prmSecItem).Concat(" AND ", "(", ")")); + } + public override SaSecurityItem GetSecurityItemByTypeEmail(SaSecurity.ItemType securityItemType, string emailAddress) + { + ClearErrorState(); + if ((int)securityItemType < 1 || StringUtil.IsEmpty(emailAddress)) return null; + SaSecurityItem.Params prmSecItem = new SaSecurityItem.Params(); + prmSecItem.SecurityItemType = securityItemType; + prmSecItem.EmailAddress = emailAddress; + prmSecItem.StatusCat = SaSecurityItem.StatusCat.Any; + return GetSecurityItem(GetSecurityItemQueryFilter(prmSecItem).Concat(" AND ", "(", ")")); + } + public override SaSecurityItem GetSecurityItemByTypeCode(SaSecurity.ItemType securityItemType, string code) { ClearErrorState(); if ((int)securityItemType < 1 || StringUtil.IsEmpty(code)) return null; @@ -112,12 +132,12 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Create item. - public override SaSecurityItem CreateSecurityItem (SaSecurity.ItemType securityItemType) + public override SaSecurityItem CreateSecurityItem(SaSecurity.ItemType securityItemType) { ClearErrorState(); return new SaSecurityItem_Dbas(null, securityItemType, 0); } - public SaSecurityItem CreateSecurityItem (SaSecItem_Db dbSecurityItem) + public SaSecurityItem CreateSecurityItem(SaSecItem_Db dbSecurityItem) { ClearErrorState(); SaSecurityItem securityItem = new SaSecurityItem_Dbas(new SysId(dbSecurityItem._Id), (SaSecurity.ItemType)dbSecurityItem._Type, (ushort)dbSecurityItem._Flags); @@ -127,7 +147,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Validate item properties. - public override bool IsValidSecurityItemData (SaSecurityItem.Data securityItemData, SaSecurityItem.ErrField errField) + public override bool IsValidSecurityItemData(SaSecurityItem.Data securityItemData, SaSecurityItem.ErrField errField) { ClearErrorState(); if (!base.IsValidSecurityItemData(securityItemData, errField)) return false; @@ -136,7 +156,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Insert item. - public override bool InsertSecurityItem (SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) + public override bool InsertSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) { String fn = GetType().Name + ".InsertSecurityItem"; ClearErrorState(); @@ -167,7 +187,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Update SecurityItem. - public override bool UpdateSecurityItem (SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) + public override bool UpdateSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) { String fn = GetType().Name + ".UpdateSecurityItem"; ClearErrorState(); @@ -204,13 +224,13 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Delete SecurityItem. - public override bool SecurityItemCanBeDeleted (SaSecurityItem securityItem) + public override bool SecurityItemCanBeDeleted(SaSecurityItem securityItem) { ClearErrorState(); if (!base.SecurityItemCanBeDeleted(securityItem)) return false; return true; } - public override bool DeleteSecurityItem (SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) + public override bool DeleteSecurityItem(SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) { String fn = GetType().Name + ".DeleteSecurityItem"; ClearErrorState(); @@ -237,7 +257,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Copy data properties to and from database. - private void PopulateTo (SaSecItem_Db dbSecurityItem, SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) + private void PopulateTo(SaSecItem_Db dbSecurityItem, SaSecurityItem securityItem, DbUpdateInfo dbUpdateInfo) { dbSecurityItem._Id = securityItem.Id.ToInt(); dbSecurityItem._Type = (byte)securityItem.ItemType; @@ -264,7 +284,7 @@ namespace Sarand.Net.Standard.Dbas.Security dbSecurityItem._UpdateBy = dbUpdateInfo.UserId.ToInt(); dbSecurityItem._UpdateHost = dbUpdateInfo.Host; } - private void PopulateFrom (SaSecItem_Db dbSecurityItem, SaSecurityItem securityItem) + private void PopulateFrom(SaSecItem_Db dbSecurityItem, SaSecurityItem securityItem) { //securityItem.Id = new SysId(dbSecurityItem._Id); securityItem.Code = dbSecurityItem._Code; @@ -286,11 +306,11 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // SecurityItem column definitions. - private static readonly String aliasSecurityItem = "aSecItm"; - private static readonly String colOwnerLinkCount = "OwnerLinkCount"; - private static readonly String colTargetLinkCount = "TargetLinkCount"; - private static readonly String colTargetLinkCount_Groups = "TargetLinkCount_Groups"; - private static readonly String colTargetLinkCount_Rights = "TargetLinkCount_Right"; + private static readonly String aliasSecurityItem = "aSecItm"; + private static readonly String colOwnerLinkCount = "OwnerLinkCount"; + private static readonly String colTargetLinkCount = "TargetLinkCount"; + private static readonly String colTargetLinkCount_Groups = "TargetLinkCount_Groups"; + private static readonly String colTargetLinkCount_Rights = "TargetLinkCount_Right"; private void SetSecurityItemColDfn (ColumnDfn col, String caption, int width, SaSecurityDbDfn.ColumnIdx dbCol, ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String, @@ -300,9 +320,9 @@ namespace Sarand.Net.Standard.Dbas.Security alias = aliasSecurityItem; col.Set(caption, width, (int)dbCol, prefix + SaSecurityDbDfn.GetColumnName(dbCol, false), SaSecurityDbDfn.GetColumnNameQual(dbCol, alias), dataType, align); } - public override ColumnDfn GetSecurityItemColumnDfn (SaSecurityItem.Column columnId, string caption = "", int width = 0) + public override ColumnDfn GetSecurityItemColumnDfn(SaSecurityItem.Column columnId, string caption = "", int width = 0) { - ColumnDfn columnDfn = new ColumnDfn((int)columnId,caption,width); + ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width); switch (columnId) { case SaSecurityItem.Column.Pos: @@ -382,7 +402,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // SecurityItem query filter. - public override List GetSecurityItemQueryFilter (SaSecurityItem.Params prm) + public override List GetSecurityItemQueryFilter(SaSecurityItem.Params prm) { List filter = new List(); @@ -440,7 +460,7 @@ namespace Sarand.Net.Standard.Dbas.Security return filter; } // SecurityItem sort columns. - public List GetSecurityItemSortColumns (SaSecurityItem.Params prm) + public List GetSecurityItemSortColumns(SaSecurityItem.Params prm) { // Sort sequence: List sortColumnNames = new List(); @@ -477,12 +497,12 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // SecurityItem count. - private long GetSecurityItemCount (String filter) + private long GetSecurityItemCount(String filter) { ClearErrorState(); return Database.GetRowCount(TableName_SecItem + " As " + aliasSecurityItem, filter); } - public override long GetSecurityItemCount (SaSecurityItem.Params prm) + public override long GetSecurityItemCount(SaSecurityItem.Params prm) { ClearErrorState(); return GetSecurityItemCount(GetSecurityItemQueryFilter(prm).Concat(" AND ", "(", ")")); @@ -490,7 +510,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Security Item list. - public override List GetSecurityItemList (SaSecurityItem.Params prm) + public override List GetSecurityItemList(SaSecurityItem.Params prm) { List secItems = new List(); DbQuery qry = new DbQuery(Database.DbmsType); @@ -528,7 +548,7 @@ namespace Sarand.Net.Standard.Dbas.Security //------------------------------------------------------------------- // Security Item Query. - public override DbResultSet ExecuteSecurityItemQuery (List columns, SaSecurityItem.Params prm) + public override DbResultSet ExecuteSecurityItemQuery(List columns, SaSecurityItem.Params prm) { ClearErrorState(); diff --git a/SacsStandardDbas/Dbas/UpdateLog/SaUpdateLogConsole_Dbas.cs b/SacsStandardDbas/Dbas/UpdateLog/SaUpdateLogConsole_Dbas.cs index 6d71b5e..0ecc5dd 100644 --- a/SacsStandardDbas/Dbas/UpdateLog/SaUpdateLogConsole_Dbas.cs +++ b/SacsStandardDbas/Dbas/UpdateLog/SaUpdateLogConsole_Dbas.cs @@ -27,6 +27,14 @@ namespace Sarand.Net.Standard.Dbas.UpdateLog Database = database; updateLogMgr = new SaUpdateLogMgr_Dbas(this); } + protected override void Dispose(bool disposing) + { + if (disposing) + { + if (updateLogMgr != null) updateLogMgr.Dispose(); updateLogMgr = null; + } + base.Dispose(disposing); + } //------------------------------------------------------------------- // Properties. diff --git a/SacsStandardData/Data/Excel/MsExcel.cs b/SacsStandardProc/Proc/Excel/MsExcel.cs similarity index 99% rename from SacsStandardData/Data/Excel/MsExcel.cs rename to SacsStandardProc/Proc/Excel/MsExcel.cs index 7e9eb1f..b366664 100644 --- a/SacsStandardData/Data/Excel/MsExcel.cs +++ b/SacsStandardProc/Proc/Excel/MsExcel.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Text; -namespace Sarand.Net.Standard.Data.Excel +namespace Sarand.Net.Standard.Proc.Excel { //======================================================================= // MS Excel constant definitions. diff --git a/SacsStandardData/Data/Excel/SaMsSpreadsheet-Dfn.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet-Dfn.cs similarity index 99% rename from SacsStandardData/Data/Excel/SaMsSpreadsheet-Dfn.cs rename to SacsStandardProc/Proc/Excel/SaMsSpreadsheet-Dfn.cs index 0fd0b34..dfde595 100644 --- a/SacsStandardData/Data/Excel/SaMsSpreadsheet-Dfn.cs +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet-Dfn.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Sarand.Net.Standard.Data.Excel +namespace Sarand.Net.Standard.Proc.Excel { //======================================================================= // Definitions. diff --git a/SacsStandardData/Data/Excel/SaMsSpreadsheet.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet.cs similarity index 99% rename from SacsStandardData/Data/Excel/SaMsSpreadsheet.cs rename to SacsStandardProc/Proc/Excel/SaMsSpreadsheet.cs index 84d7090..cf64316 100644 --- a/SacsStandardData/Data/Excel/SaMsSpreadsheet.cs +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet.cs @@ -5,7 +5,7 @@ using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Utils; -namespace Sarand.Net.Standard.Data.Excel +namespace Sarand.Net.Standard.Proc.Excel { //======================================================================= // Some Excel enumerated values are replaced with local integers or diff --git a/SacsStandardData/Data/Excel/SaMsSpreadsheet_Direct.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_Direct.cs similarity index 99% rename from SacsStandardData/Data/Excel/SaMsSpreadsheet_Direct.cs rename to SacsStandardProc/Proc/Excel/SaMsSpreadsheet_Direct.cs index 9f9cd38..84b36a9 100644 --- a/SacsStandardData/Data/Excel/SaMsSpreadsheet_Direct.cs +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_Direct.cs @@ -9,10 +9,10 @@ using System.Threading.Tasks; using System.Xml; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; -using Sarand.Net.Standard.Data.Xml; -using Sarand.Net.Standard.Data.Zip; +using Sarand.Net.Standard.Proc.Xml; +using Sarand.Net.Standard.Proc.Zip; -namespace Sarand.Net.Standard.Data.Excel +namespace Sarand.Net.Standard.Proc.Excel { //======================================================================= /// Style properties retrieved directly from spreadsheet xml data. diff --git a/SacsStandardData/Data/Excel/SaMsSpreadsheet_OpenXml.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs similarity index 99% rename from SacsStandardData/Data/Excel/SaMsSpreadsheet_OpenXml.cs rename to SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs index 7a2d11a..1eafb26 100644 --- a/SacsStandardData/Data/Excel/SaMsSpreadsheet_OpenXml.cs +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_OpenXml.cs @@ -11,7 +11,7 @@ using Sarand.Net.Standard.Base.App; using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Utils; -namespace Sarand.Net.Standard.Data.Excel +namespace Sarand.Net.Standard.Proc.Excel { //======================================================================= public class SaMsSpreadsheet_OpenXml : SaMsSpreadsheet diff --git a/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_POI.cs b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_POI.cs new file mode 100644 index 0000000..242efd8 --- /dev/null +++ b/SacsStandardProc/Proc/Excel/SaMsSpreadsheet_POI.cs @@ -0,0 +1,887 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using Sarand.Net.Standard.Base.Core; +using Sarand.Net.Standard.Base.Utils; +using Sarand.Net.Standard.Proc.Xml; +using Sarand.Net.Standard.Proc.Zip; + +namespace Sarand.Net.Standard.Proc.Excel +{ + + //======================================================================= + /// Excel spreadsheet read directly from xml data rather than via COM/Interop. + public class SaMsSpreadsheet_POI : SaMsSpreadsheet + { + //------------------------------------------------------------------- + // Data members. + internal class Workbook + { + internal SaMsZipArchive WorkbookArchive { get; set; } + internal SaMsXmlDocument WorkbookDoc { get; set; } + internal SaMsXmlDocument SharedStringsDoc { get; set; } + internal SaMsXmlDocument StylesDoc { get; set; } + internal uint WorksheetCount { get; set; } + internal uint ActiveSheetPos { get; set; } + internal bool IsValid () { return (WorkbookDoc != null && WorkbookDoc.GetRootElement() != null); } + } + private Workbook workbook; + private class Worksheet + { + internal uint WorksheetPos { get; set; } + internal uint WorksheetId { get; set; } + internal String WorksheetArchivePath { get; set; } + internal String WorksheetName { get; set; } + internal SaMsXmlDocument WorksheetDoc { get; set; } + internal uint ActiveColPos { get; set; } + internal uint ActiveRowPos { get; set; } + internal class NodesData + { + internal SaMsXmlElement Cols { get; set; } + internal SaMsXmlElement ActiveCol { get; set; } + internal SaMsXmlElement Rows { get; set; } + internal SaMsXmlElement ActiveRow { get; set; } + } + internal NodesData Nodes { get; } = new NodesData(); + bool IsValid () { return (WorksheetDoc != null && WorksheetDoc.GetRootElement() != null); } + + } + private Worksheet worksheet; + + //------------------------------------------------------------------- + // Construction. + public SaMsSpreadsheet_POI () : base() + { + } + protected override void Dispose (bool disposing) + { + if (disposing) + { + CloseWorkbook(); + } + base.Dispose(disposing); + } + + //------------------------------------------------------------------- + // Properties. + + //------------------------------------------------------------------- + // W o r k b o o k + //------------------------------------------------------------------- + public override bool IsWorkbookValid () + { + return (workbook != null && workbook.IsValid()); + } + public override bool CreateWorkbook () + { + CloseWorkbook(); + ClearErrorState(); + + // Create new workbook. + workbook = new Workbook(); + workbook.WorkbookArchive = new SaMsZipArchive(); + workbook.SharedStringsDoc = new SaMsXmlDocument(); + workbook.StylesDoc = new SaMsXmlDocument(); + + return SetErrorState("Creating workbook not supported"); + } + public override bool OpenWorkbook (String filePath) + { + CloseWorkbook(); + ClearErrorState(); + if (!File.Exists(filePath)) + return SetErrorState("Workbook not found"); + List validExtensions = new List() { /*".xls",*/ ".xlsx", ".xlsb", ".zip" }; + String extension = Path.GetExtension(filePath); + if (!validExtensions.ContainsCI(Path.GetExtension(filePath))) + return SetErrorState("Invalid document type (expected xlsx/xlsb)"); + + try + { + // Open workbook document. + workbook = new Workbook(); + workbook.WorkbookArchive = new SaMsZipArchive(); + if (workbook.WorkbookArchive.OpenArchive(filePath)) + { + ExtractWorkbookElementsFromArchive(); + } + else return SetErrorState("Failed to open document: " + workbook.WorkbookArchive.ErrorStateMessage); + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + return !HasErrorState(); + } + public bool OpenWorkbook (byte[] workbookData) + { + CloseWorkbook(); + ClearErrorState(); + try + { + using (MemoryStream workbookStream = new MemoryStream(workbookData)) + { + OpenWorkbook(workbookStream); + } + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + return !HasErrorState(); + } + public bool OpenWorkbook (Stream workbookStream) + { + CloseWorkbook(); + ClearErrorState(); + try + { + // From start of stream. + workbookStream.Seek(0, SeekOrigin.Begin); + // Open workbook document. + workbook = new Workbook(); + workbook.WorkbookArchive = new SaMsZipArchive(); + if (workbook.WorkbookArchive.OpenArchive(workbookStream)) + { + ExtractWorkbookElementsFromArchive(); + } + else return SetErrorState("Failed to open document: " + workbook.WorkbookArchive.ErrorStateMessage); + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + return !HasErrorState(); + } + private bool ExtractWorkbookElementsFromArchive () + { + ClearErrorState(); + try + { + // Extract the workbook data. + using (MemoryStream workbookFile = workbook.WorkbookArchive.ExtractFileToStream("xl/workbook.xml")) + { + if (workbookFile == null) return SetErrorState("Failed to load workbook data"); + workbook.WorkbookDoc = new SaMsXmlDocument(); + if (workbook.WorkbookDoc.LoadXml(workbookFile)) + { + // Workbook successfully opened. + workbook.ActiveSheetPos = 1; + // Shared strings: + using (MemoryStream sharedStringsFile = workbook.WorkbookArchive.ExtractFileToStream("xl/sharedStrings.xml")) + { + if (sharedStringsFile != null) + { + workbook.SharedStringsDoc = new SaMsXmlDocument(); + workbook.SharedStringsDoc.LoadXml(sharedStringsFile); + } + } + // Styles: + using (MemoryStream stylesFile = workbook.WorkbookArchive.ExtractFileToStream("xl/styles.xml")) + { + if (stylesFile != null) + { + workbook.StylesDoc = new SaMsXmlDocument(); + workbook.StylesDoc.LoadXml(stylesFile); + } + } + // Set worksheet count and open first worksheet. + PopulateWorksheetCount(); + OpenWorksheet(1); + } + else return SetErrorState("Failed to read workbook data"); + } + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + return !HasErrorState(); + } + public override bool SaveDocument (String filePath, int fileFormat, bool bAutomaticallyOverwrite) + { + ClearErrorState(); + if (fileFormat == 0) + fileFormat = (int)XlFileFormat.xlOpenXMLWorkbook; + if (fileFormat != (int)XlFileFormat.xlOpenXMLWorkbook) + SetErrorState("Unsupported file format: " + ((XlFileFormat)fileFormat).ToString()); + if (!HasErrorState() && !workbook.IsValid()) + SetErrorState("Workbook is not open"); + SetErrorState("Saving workbook not supported"); + return !HasErrorState(); + } + public override bool CloseWorkbook () + { + ClearErrorState(); + CloseWorksheet(); + + // Clear workbook. + if (workbook != null) + { + try + { + if (workbook.StylesDoc != null) workbook.StylesDoc.Dispose(); workbook.StylesDoc = null; + if (workbook.SharedStringsDoc != null) workbook.SharedStringsDoc.Dispose(); workbook.SharedStringsDoc = null; + if (workbook.WorkbookDoc != null) workbook.WorkbookDoc.Dispose(); workbook.WorkbookDoc = null; + if (workbook.WorkbookArchive != null) workbook.WorkbookArchive.Dispose(); workbook.WorkbookArchive = null; + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + workbook = null; + } + return !HasErrorState(); + } + + //------------------------------------------------------------------- + // W o r k s h e e t + //------------------------------------------------------------------- + public override bool IsWorksheetValid () + { + return (worksheet != null && worksheet.WorksheetDoc != null); + } + public override uint WorksheetCount { get { return workbook.WorksheetCount; } } + private void PopulateWorksheetCount () + { + if (!IsWorkbookValid()) return; + try + { + // Count worksheets in workbook. + SaMsXmlElement nodeWorkbook = workbook.WorkbookDoc.GetRootElement(); + SaMsXmlElement nodeSheets = nodeWorkbook.GetFirstChildElement("sheets"); + workbook.WorksheetCount = (uint)nodeSheets.GetChildElements("sheet").Count; + } + catch (Exception exc) { HandleException("GetWorksheetCount", exc); } + } + public override bool SetWorksheetCount (int worksheetCount) + { + ClearErrorState(); + return SetErrorState("Modifying workbook not supported"); + } + public override bool AddWorksheet(String name) + { + return SetErrorState("Modifying workbook not supported"); + } + public override bool RemoveWorksheet(uint worksheetPos) + { + return SetErrorState("Modifying workbook not supported"); + } + public override bool OpenWorksheet (uint worksheetPos) + { + ClearErrorState(); + if (!workbook.IsValid()) return SetErrorState("Workbook is not open"); + if (worksheetPos > WorksheetCount) return SetErrorState("Invalid sheet specified"); + if (worksheetPos <= 0) worksheetPos = Math.Max(1, workbook.ActiveSheetPos); + CloseWorksheet(); + try + { + worksheet = new Worksheet(); + // Locate worksheet in workbook by 0-index. + SaMsXmlElement workbookElement = workbook.WorkbookDoc.GetRootElement(); + SaMsXmlElement sheetsElement = workbookElement.GetFirstChildElement("sheets"); + long sheetCount = 0; + foreach (SaMsXmlElement sheetElement in sheetsElement.GetChildElements("sheet")) + { + sheetCount++; + if (sheetCount == worksheetPos) + { + // Extract the worksheet data. + uint sheetId = (uint)StringUtil.ToInt(sheetElement.GetAttributeValue("sheetId")); + String worksheetArchivePath = "xl/worksheets/sheet" + worksheetPos.ToString() + ".xml"; + using (MemoryStream worksheetFile = workbook.WorkbookArchive.ExtractFileToStream(worksheetArchivePath)) + { + if (worksheetFile == null) return SetErrorState("Failed to load worksheet data"); + worksheet.WorksheetDoc = new SaMsXmlDocument(); + if (worksheet.WorksheetDoc.LoadXml(worksheetFile)) + { + workbook.ActiveSheetPos = worksheetPos; + worksheet.WorksheetPos = worksheetPos; + worksheet.WorksheetId = sheetId; + worksheet.WorksheetArchivePath = worksheetArchivePath; + worksheet.WorksheetName = sheetElement.GetAttributeValue("name"); + worksheet.ActiveColPos = 1; + worksheet.ActiveRowPos = 1; + SaMsXmlElement nodeWorksheet = worksheet.WorksheetDoc.GetRootElement(); + worksheet.Nodes.Cols = nodeWorksheet.GetFirstChildElement("cols"); + worksheet.Nodes.ActiveCol = worksheet.Nodes.Cols.GetFirstChildElement("col"); + worksheet.Nodes.Rows = nodeWorksheet.GetFirstChildElement("sheetData"); + worksheet.Nodes.ActiveRow = worksheet.Nodes.Rows.GetFirstChildElement("row"); + workbook.ActiveSheetPos = worksheetPos; + } + else return SetErrorState("Failed to read data for worksheet " + worksheetPos.ToString()); + } + break; + } + } + if (worksheet.WorksheetDoc == null) return SetErrorState("Unable to load worksheet " + worksheetPos.ToString()); + } + catch (Exception exc) { HandleException("OpenWorksheet", exc); } + return !HasErrorState(); + } + public override uint WorksheetPos { get { return workbook.ActiveSheetPos; } } + public override String WorksheetName + { + get { return ""; } + set { } + } + public override bool SetWorksheetAttr (SaMsExcelItemAttr attr) + { + return SetErrorState("Not supported"); + } + public override bool CloseWorksheet () + { + ClearErrorState(); + + if (worksheet != null) + { + try + { + if (worksheet.WorksheetDoc != null) worksheet.WorksheetDoc.Dispose(); worksheet.WorksheetDoc = null; + if (worksheet.Nodes.Cols != null) worksheet.Nodes.Cols.Dispose(); worksheet.Nodes.Cols = null; + if (worksheet.Nodes.ActiveCol != null) worksheet.Nodes.ActiveCol.Dispose(); worksheet.Nodes.ActiveCol = null; + if (worksheet.Nodes.Rows != null) worksheet.Nodes.Rows.Dispose(); worksheet.Nodes.Rows = null; + if (worksheet.Nodes.ActiveRow != null) worksheet.Nodes.ActiveRow.Dispose(); worksheet.Nodes.ActiveRow = null; + } + catch (Exception exc) { SetErrorState(ExceptionUtil.GetErrorStateMessage(exc)); } + worksheet = null; + } + + return !HasErrorState(); + } + + //------------------------------------------------------------------- + // Worksheet Page Setup. + public override bool SetPageSetup (SaMsExcelPageSetup_Config pageSetupConfig) + { + return SetErrorState("Not supported"); + } + public override bool SetPageBreak (uint col, uint row) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + // C o l u m n s + //------------------------------------------------------------------- + public override uint GetActiveColPos () + { + return worksheet.ActiveColPos; + } + private SaMsXmlElement GetColElement (uint colPos) + { + ClearErrorState(); + try + { + if (worksheet.ActiveColPos == colPos) return worksheet.Nodes.ActiveCol; + int colCount = 0; + foreach (SaMsXmlElement colElement in worksheet.Nodes.Cols.GetChildElements("Col")) + { + if (++colCount == colPos) + { + if (worksheet.Nodes.ActiveCol != null) worksheet.Nodes.ActiveCol.Dispose(); + worksheet.ActiveColPos = colPos; + worksheet.Nodes.ActiveCol = colElement; + return colElement; + } + } + } + catch (Exception exc) { HandleException("GetColElement", exc); } + return new SaMsXmlElement(null); + } + public override double GetColWidth (uint colPos, SaExcelLogicalUnit unit = SaExcelLogicalUnit.Point) + { + ClearErrorState(); + try + { + // Retrieve width (in points) from column. + SaMsXmlNode nodeCol = GetColElement(colPos); + double width = nodeCol.GetAttributeValue("width").ToDouble(); + // Adjust for units. + if (unit == SaExcelLogicalUnit.Pixel) return PointsToPixels(width, false); + if (unit == SaExcelLogicalUnit.Cm) return PointsToCms(width); + if (unit == SaExcelLogicalUnit.Inch) return PointsToInches(width); + return width; + } + catch (Exception exc) { HandleException("GetColWidth", exc); } + return 0.0; + } + public override bool SetColWidth (uint colPos, double fWidth, SaExcelLogicalUnit unit = SaExcelLogicalUnit.Point) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + // R o w s + //------------------------------------------------------------------- + public override uint GetActiveRowPos () + { + return worksheet.ActiveRowPos; + } + SaMsXmlElement GetRowElement (uint rowPos) + { + ClearErrorState(); + try + { + if (worksheet.ActiveRowPos == rowPos) return worksheet.Nodes.ActiveRow; + foreach (SaMsXmlElement rowElement in worksheet.Nodes.Rows.GetChildElements("row")) + { + if (rowElement.GetAttributeValue("r").ToLong() == rowPos) + { + if (worksheet.Nodes.ActiveRow != null) worksheet.Nodes.ActiveRow.Dispose(); + worksheet.ActiveRowPos = rowPos; + worksheet.Nodes.ActiveRow = rowElement; + return rowElement; + } + } + } + catch (Exception exc) { HandleException("GetRowElement", exc); } + return new SaMsXmlElement(null); + } + public override double GetRowHeight (uint rowPos, SaExcelLogicalUnit unit = SaExcelLogicalUnit.Point) + { + ClearErrorState(); + try + { + // Retrieve height (in points) from row. + SaMsXmlElement rowElement = GetRowElement(rowPos); + double height = rowElement.GetAttributeValue("ht").ToDouble(); + // Adjust for units. + if (unit == SaExcelLogicalUnit.Pixel) return PointsToPixels(height, true); + if (unit == SaExcelLogicalUnit.Cm) return PointsToCms(height); + if (unit == SaExcelLogicalUnit.Inch) return PointsToInches(height); + return height; + } + catch (Exception exc) { HandleException("GetRowHeight", exc); } + return 0.0; + } + public override bool SetRowHeight (uint rowPos, double fHeight, SaExcelLogicalUnit unit = SaExcelLogicalUnit.Point) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + // R o w s + //------------------------------------------------------------------- + public override List GetRowDataValues (uint rowPos, int maxColumns = 0) + { + ClearErrorState(); + List values = new List(); + try + { + SaMsXmlElement rowElement = GetRowElement(rowPos); + foreach (SaMsXmlElement cellElement in rowElement.GetChildElements("c")) + { + // CellId may be needed in case cells are skipped in the data. + // Doesn't appear to be the case, even when previous cell is merged with next. + String cellId = cellElement.GetAttributeValue("r"); + values.Add(GetCellDataValue(cellElement)); + if (maxColumns > 0 && values.Count >= maxColumns) break; + } + } + catch (Exception exc) { HandleException("GetRowDataValues", exc); } + return values; + } + + //------------------------------------------------------------------- + // C e l l s + //------------------------------------------------------------------- + SaMsXmlElement GetCellElement (uint colPos, uint rowPos) + { + ClearErrorState(); + String cellId = GetCellId(colPos,rowPos); + try + { + SaMsXmlElement rowElement = GetRowElement(rowPos); + foreach (SaMsXmlElement cellElement in rowElement.GetChildElements("c")) + { + if (cellElement.GetAttributeValue("r").EqualsCI(cellId)) + return cellElement; + } + } + catch (Exception exc) { HandleException("GetCellElement", exc); } + return new SaMsXmlElement(null); + } + public override void SetActiveCell (uint colPos, uint rowPos) + { + // ToDo SetActiveCell. + SetErrorState("Not supported"); + } + //------------------------------------------------------------------- + private bool IsCellFormula (uint colPos, uint rowPos) + { + ClearErrorState(); + bool bIsFormula = false; + try + { + SaMsXmlElement cellElement = GetCellElement(colPos,rowPos); + bIsFormula = !cellElement.GetAttributeValue("f").IsEmpty(); + } + catch (Exception exc) { HandleException("IsCellFormula", exc); } + return bIsFormula; + } + private bool IsCellNumeric (uint colPos, uint rowPos) + { + ClearErrorState(); + try + { + SaMsXmlElement cellElement = GetCellElement(colPos,rowPos); + SaMsExcelStyle cellStyle = GetCellStyle(cellElement); + return IsCellNumeric(cellElement, cellStyle); + } + catch (Exception exc) { HandleException("IsCellNumeric", exc); } + return false; + } + private bool IsCellNumeric (SaMsXmlElement cellElement) + { + ClearErrorState(); + SaMsExcelStyle cellStyle = GetCellStyle(cellElement); + return IsCellNumeric(cellElement, cellStyle); + } + private bool IsCellNumeric (SaMsXmlElement cellElement, SaMsExcelStyle cellStyle) + { + ClearErrorState(); + return (cellElement.GetAttributeValue("t").IsEmpty() && !IsDateTimeStyle(cellStyle.NumFmtCode)); + } + private bool IsCellDate (uint colPos, uint rowPos) + { + ClearErrorState(); + bool bIsDate = false; + try + { + SaMsXmlElement cellElement = GetCellElement(colPos,rowPos); + SaMsExcelStyle cellStyle = GetCellStyle(cellElement); + return IsCellDate(cellElement, cellStyle); + } + catch (Exception exc) { HandleException("IsCellDate", exc); } + return bIsDate; + } + private bool IsCellDate (SaMsXmlElement cellElement) + { + return IsCellDate(cellElement, GetCellStyle(cellElement)); + } + private bool IsCellDate (SaMsXmlElement cellElement, SaMsExcelStyle cellStyle) + { + ClearErrorState(); + return IsDateTimeStyle(cellStyle.NumFmtCode); + } + //------------------------------------------------------------------- + public override String GetCellFormula (uint colPos, uint rowPos) + { + ClearErrorState(); + try + { + SaMsXmlElement cellElement = GetCellElement(colPos,rowPos); + String formula = cellElement.GetAttributeValue("f"); + if (formula.IsEmpty()) + formula = GetCellText(cellElement, true); + return formula; + } + catch (Exception exc) { HandleException("GetCellFormula", exc); } + return ""; + } + private String GetCellText (SaMsXmlElement cellElement, bool trimValue = true) + { + ClearErrorState(); + String value = ""; + try + { + if (cellElement.GetAttributeValue("t").EqualsCI("s")) + value = GetSharedString(cellElement); + else + value = cellElement.GetChildText("v"); + if (trimValue) value.TrimAll(); + } + catch (Exception exc) { HandleException("GetCellText", exc); } + return value; + } + public override DataValue GetCellDataValue (uint colPos, uint rowPos) + { + return GetCellDataValue(GetCellElement(colPos, rowPos), false); + } + private DataValue GetCellDataValue (SaMsXmlElement cellElement, bool trimTextValue = true) + { + ClearErrorState(); + try + { + SaMsExcelStyle cellStyle = GetCellStyle(cellElement); + if (cellElement.GetAttributeValue("t").EqualsCI("s")) + { + String value = GetSharedString(cellElement); + if (trimTextValue) value = value.TrimAll(); + return new DataValue(value); + } + else + { + String value = cellElement.GetChildText("v"); + if (IsDateTimeStyle(cellStyle.NumFmtCode)) + return new DataValue(DateTime.FromOADate(value.ToDouble())); + if (IsCellNumeric(cellElement, cellStyle)) + { + if (value.IsNumeric()) + return new DataValue(value.ToLong()); + if (value.IsDecimal()) + { +#if DEBUG + //if (StringUtil.ToInt(value) > 600) Debugger.Break(); +#endif + return new DataValue(value.ToDecimal()); + } + } + if (trimTextValue) value = value.TrimAll(); + return new DataValue(value); + } + } + catch (Exception exc) { HandleException("GetCellDataValue", exc); } + return new DataValue(); + } + //------------------------------------------------------------------- + // Shared string for cell. + private String GetSharedString (SaMsXmlElement nodeElement) + { + ClearErrorState(); + try + { + SaMsXmlElement sharedStringElement = GetSharedStringElement(nodeElement); + return sharedStringElement.GetChildText("t"); + } + catch (Exception exc) { HandleException("GetSharedString", exc); } + return ""; + } + private SaMsXmlElement GetSharedStringElement (SaMsXmlElement cellElement) + { + ClearErrorState(); + if (workbook.SharedStringsDoc == null || cellElement == null || !cellElement.Valid) return null; + if (!cellElement.GetAttributeValue("t").EqualsCI("s") || !cellElement.GetChildText("v").IsNumeric()) return null; + // Shared strings are indexed from 0. + long sharedStringIdx = -1; + try + { + long iIdx = cellElement.GetChildText("v").ToLong(); + SaMsXmlElement sstElement = workbook.SharedStringsDoc.GetRootElement(); + foreach (SaMsXmlElement siElement in sstElement.GetChildElements("si")) + { + if (++sharedStringIdx == iIdx) + return siElement; + } + } + catch (Exception exc) { HandleException("GetSharedStringNode", exc); } + return new SaMsXmlElement(null); + } + //------------------------------------------------------------------- + public override bool SetCellFormula (uint colPos, uint rowPos, String value) + { + return SetErrorState("Not supported"); + } + public override bool SetCellFormula (uint colPos, uint rowPos, String value, SaMsExcelItemAttr attr) + { + return SetErrorState("Not supported"); + } + public override bool SetRowFormulas (uint colPosStart, uint rowPos, List values) + { + return SetErrorState("Not supported"); + } + public override bool SetRangeFormulas (SaMsExcelRange range, List values) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + // C e l l S t y l e + //------------------------------------------------------------------- + private String GetBuiltInStyleFormat (int numFmtId) + { + // Ref. http://stackoverflow.com/questions/4730152/what-indicates-an-office-open-xml-cell-contains-a-date-time-value + switch (numFmtId) + { + // + case 0: return "General"; + case 1: return "0"; + case 2: return "0.00"; + case 3: return "#,##0"; + case 4: return "#,##0.00"; + // + case 9: return "0%"; + case 10: return "0.00%"; + case 11: return "0.00E+00"; + case 12: return "# ?/?"; + case 13: return "# ??/??"; + case 14: return "mm-dd-yy"; + case 15: return "d-mmm-yy"; + case 16: return "d-mmm"; + case 17: return "mmm-yy"; + case 18: return "h:mm AM/PM"; + case 19: return "h:mm:ss AM/PM"; + case 20: return "h:mm"; + case 21: return "h:mm:ss"; + case 22: return "m/d/yy h:mm"; + // + case 37: return "#,##0 ;(#,##0)"; + case 38: return "#,##0 ;[Red](#,##0)"; + case 39: return "#,##0.00;(#,##0.00)"; + case 40: return "#,##0.00;[Red](#,##0.00)"; + // + case 44: return "_(\"$\"* #,##0.00_);_(\"$\"* \\(#,##0.00\\);_(\"$\"* \"-\"??_);_(@_)"; + case 45: return "mm:ss"; + case 46: return "[h]:mm:ss"; + case 47: return "mmss.0"; + case 48: return "##0.0E+0"; + case 49: return "@"; + // + case 27: return "[$-404]e/m/d"; + case 30: return "m/d/yy"; + case 36: return "[$-404]e/m/d"; + case 50: return "[$-404]e/m/d"; + case 57: return "[$-404]e/m/d"; + // + case 59: return "t0"; + case 60: return "t0.00"; + case 61: return "t#,##0"; + case 62: return "t#,##0.00"; + case 67: return "t0%"; + case 68: return "t0.00%"; + case 69: return "t# ?/?"; + case 70: return "t# ??/??"; + } + return ""; + } + private SaMsExcelStyle GetCellStyle (SaMsXmlElement cellElement) + { + ClearErrorState(); + SaMsExcelStyle style = new SaMsExcelStyle(); + if (workbook.SharedStringsDoc == null || cellElement == null || !cellElement.Valid || !cellElement.GetAttributeValue("s").IsNumeric()) return style; + // Styles are indexed from 0. + long styleIdx = -1; + try + { + long cellStyleIdx = cellElement.GetAttributeValue("s").ToLong(); + SaMsXmlElement styleSheetElement = workbook.SharedStringsDoc.GetRootElement(); + SaMsXmlElement cellXfsElement = styleSheetElement.GetFirstChildElement("cellXfs"); + foreach (SaMsXmlElement xfElement in styleSheetElement.GetChildElements("xf")) + { + if (++styleIdx == cellStyleIdx) + { + // Construct style. + style.NumFmtId = (int)xfElement.GetAttributeValue("numFmtId").ToLong(); + style.FontId = (int)xfElement.GetAttributeValue("fontId").ToLong(); + style.FillId = (int)xfElement.GetAttributeValue("fillId").ToLong(); + style.BorderId = (int)xfElement.GetAttributeValue("borderId").ToLong(); + style.XfId = (int)xfElement.GetAttributeValue("xfId").ToLong(); + style.QuotePrefix = xfElement.GetAttributeValue("quotePrefix").ToBool(); + style.PivotButton = xfElement.GetAttributeValue("pivotButton").ToBool(); + style.ApplyNumberFormat = xfElement.GetAttributeValue("applyNumberFormat").ToBool(); + style.ApplyFont = xfElement.GetAttributeValue("applyFont").ToBool(); + style.ApplyFill = xfElement.GetAttributeValue("applyFill").ToBool(); + style.ApplyBorder = xfElement.GetAttributeValue("applyBorder").ToBool(); + style.ApplyAlignment = xfElement.GetAttributeValue("applyAlignment").ToBool(); + style.ApplyProtection = xfElement.GetAttributeValue("applyProtection").ToBool(); + // Alignment. + SaMsXmlNode nodeAlignment = xfElement.GetFirstChildElement("alignment"); + String sAlignHorizontal = nodeAlignment.GetAttributeValue("horizontal"); + if (sAlignHorizontal.EqualsCI("center")) style.AlignHorizontal = XlHAlign.xlHAlignCenter; + else if (sAlignHorizontal.EqualsCI("centerContinuous")) style.AlignHorizontal = XlHAlign.xlHAlignCenterAcrossSelection; + else if (sAlignHorizontal.EqualsCI("distributed")) style.AlignHorizontal = XlHAlign.xlHAlignDistributed; + else if (sAlignHorizontal.EqualsCI("fill")) style.AlignHorizontal = XlHAlign.xlHAlignFill; + else if (sAlignHorizontal.EqualsCI("justify")) style.AlignHorizontal = XlHAlign.xlHAlignJustify; + else if (sAlignHorizontal.EqualsCI("left")) style.AlignHorizontal = XlHAlign.xlHAlignLeft; + else if (sAlignHorizontal.EqualsCI("right")) style.AlignHorizontal = XlHAlign.xlHAlignRight; + String sAlignVertical = nodeAlignment.GetAttributeValue("vertical"); + if (sAlignVertical.EqualsCI("center")) style.AlignVertical = XlVAlign.xlVAlignCenter; + else if (sAlignVertical.EqualsCI("top")) style.AlignVertical = XlVAlign.xlVAlignTop; + else if (sAlignVertical.EqualsCI("bottom")) style.AlignVertical = XlVAlign.xlVAlignBottom; + else if (sAlignVertical.EqualsCI("distributed")) style.AlignVertical = XlVAlign.xlVAlignDistributed; + else if (sAlignVertical.EqualsCI("justify")) style.AlignVertical = XlVAlign.xlVAlignJustify; + // Number format. + if (style.ApplyNumberFormat) + { + if (style.NumFmtId >= 164) + { + SaMsXmlElement numFmtsElement = styleSheetElement.GetFirstChildElement("NumFmts"); + foreach (SaMsXmlElement numFmtElement in numFmtsElement.GetChildElements("numFmt")) + { + if (numFmtElement.GetAttributeValue("numFmtId").ToLong() == style.NumFmtId) + { + style.NumFmtCode = numFmtElement.GetAttributeValue("formatCode"); + break; + } + } + } + else style.NumFmtCode = GetBuiltInStyleFormat(style.NumFmtId); + } + // Font. + if (style.ApplyFont) + { + } + // Fill. + if (style.ApplyFill) + { + } + // Borders. + if (style.ApplyBorder) + { + } + // Alignment. + if (style.ApplyAlignment) + { + } + // Protection. + if (style.ApplyProtection) + { + } + break; + } + } + } + catch (Exception exc) { HandleException("GetStyleNode", exc); } + return style; + } + private bool IsDateStyle (String numFormat) + { + // Ref. http://stackoverflow.com/questions/19034805/how-to-distinguish-inline-numbers-from-ole-automation-date-numbers-in-openxml-sp/19582685#19582685 + if (IsTimeStyle(numFormat)) return false; + if (numFormat.Contains("d")) return true; + if (numFormat.Contains("m")) return true; + if (numFormat.Contains("y")) return true; + return false; + } + private bool IsTimeStyle (String numFormat) + { + if (numFormat.Contains("h")) return true; + if (numFormat.Contains(":mm")) return true; + if (numFormat.Contains("mm:")) return true; + if (numFormat.Contains(":ss")) return true; + return false; + } + private bool IsDateTimeStyle (String numFormat) + { + return (IsDateStyle(numFormat) || IsTimeStyle(numFormat)); + } + + //------------------------------------------------------------------- + // Cell attributes. + public override bool SetRangeAttr (SaMsExcelRange range, SaMsExcelItemAttr attr) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + // Add image to sheet. + public override bool InsertImage (SaMsExcelImage_Config imageConfig) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + public override bool FreezePanes (uint colPos, uint rowPos) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + public override bool AutoFit (SaMsExcelRange range) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + public override bool SelectRange (SaMsExcelRange range) + { + return SetErrorState("Not supported"); + } + + //------------------------------------------------------------------- + } + + //======================================================================= +} diff --git a/SacsStandardProc/Proc/Procs/SaProcess.cs b/SacsStandardProc/Proc/Procs/SaProcess.cs new file mode 100644 index 0000000..34ed685 --- /dev/null +++ b/SacsStandardProc/Proc/Procs/SaProcess.cs @@ -0,0 +1,65 @@ +using Sarand.Net.Standard.Base.Procs; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace Sarand.Net.Standard.Proc.Procs +{ + //======================================================================= + public abstract class SaProcess : SaProcess_Base + { + //------------------------------------------------------------------- + // Definitions. + public new class Config : SaProcess_Base.Config + { + protected Config() : base() + { } + } + + //------------------------------------------------------------------- + // Data members. + private Config config; + + //------------------------------------------------------------------- + // Construction. + protected SaProcess(Config config) : + base(config) + { + this.config = config; + } + protected override void Dispose(bool disposing) + { + if (disposing) + { + } + base.Dispose(disposing); + } + + //------------------------------------------------------------------- + // Properties. + + //------------------------------------------------------------------- + // Utilities. + //------------------------------------------------------------------- + + //------------------------------------------------------------------- + // Run asynchronous. + //------------------------------------------------------------------- + public bool RunAsync() + { + // Run on separate thread. + Thread thread = new Thread(new ThreadStart(RunOnThread)); + thread.IsBackground = true; + thread.Start(); + return true; + } + private void RunOnThread() + { + RunProcess(); + } + + //------------------------------------------------------------------- + } + //======================================================================= +} diff --git a/SacsStandardData/Data/Xml/SaMsXmlDocument.cs b/SacsStandardProc/Proc/Xml/SaMsXmlDocument.cs similarity index 98% rename from SacsStandardData/Data/Xml/SaMsXmlDocument.cs rename to SacsStandardProc/Proc/Xml/SaMsXmlDocument.cs index edd6e69..1165dbc 100644 --- a/SacsStandardData/Data/Xml/SaMsXmlDocument.cs +++ b/SacsStandardProc/Proc/Xml/SaMsXmlDocument.cs @@ -6,7 +6,7 @@ using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Utils; -namespace Sarand.Net.Standard.Data.Xml +namespace Sarand.Net.Standard.Proc.Xml { //======================================================================= public class SaMsXmlDocument : SaErrorStateItem diff --git a/SacsStandardData/Data/Xml/SaMsXmlElement.cs b/SacsStandardProc/Proc/Xml/SaMsXmlElement.cs similarity index 99% rename from SacsStandardData/Data/Xml/SaMsXmlElement.cs rename to SacsStandardProc/Proc/Xml/SaMsXmlElement.cs index 025eda9..cfbca95 100644 --- a/SacsStandardData/Data/Xml/SaMsXmlElement.cs +++ b/SacsStandardProc/Proc/Xml/SaMsXmlElement.cs @@ -8,7 +8,7 @@ using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Utils; -namespace Sarand.Net.Standard.Data.Xml +namespace Sarand.Net.Standard.Proc.Xml { //======================================================================= public class SaMsXmlElement : SaMsXmlNode diff --git a/SacsStandardData/Data/Xml/SaMsXmlNode.cs b/SacsStandardProc/Proc/Xml/SaMsXmlNode.cs similarity index 99% rename from SacsStandardData/Data/Xml/SaMsXmlNode.cs rename to SacsStandardProc/Proc/Xml/SaMsXmlNode.cs index db08440..c2bca49 100644 --- a/SacsStandardData/Data/Xml/SaMsXmlNode.cs +++ b/SacsStandardProc/Proc/Xml/SaMsXmlNode.cs @@ -8,7 +8,7 @@ using Sarand.Net.Standard.Base.Core; using Sarand.Net.Standard.Base.Bus; using Sarand.Net.Standard.Base.Utils; -namespace Sarand.Net.Standard.Data.Xml +namespace Sarand.Net.Standard.Proc.Xml { //======================================================================= public class SaMsXmlNode : SaErrorStateItem diff --git a/SacsStandardData/Data/Xml/SaMsXmlUtil.cs b/SacsStandardProc/Proc/Xml/SaMsXmlUtil.cs similarity index 99% rename from SacsStandardData/Data/Xml/SaMsXmlUtil.cs rename to SacsStandardProc/Proc/Xml/SaMsXmlUtil.cs index 11dd008..0435b86 100644 --- a/SacsStandardData/Data/Xml/SaMsXmlUtil.cs +++ b/SacsStandardProc/Proc/Xml/SaMsXmlUtil.cs @@ -8,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml; -namespace Sarand.Net.Standard.Data.Xml +namespace Sarand.Net.Standard.Proc.Xml { //======================================================================= public class SaXmlNamespace diff --git a/SacsStandardData/Data/Zip/SaMsZipArchive.cs b/SacsStandardProc/Proc/Zip/SaMsZipArchive.cs similarity index 98% rename from SacsStandardData/Data/Zip/SaMsZipArchive.cs rename to SacsStandardProc/Proc/Zip/SaMsZipArchive.cs index 97faf88..738194c 100644 --- a/SacsStandardData/Data/Zip/SaMsZipArchive.cs +++ b/SacsStandardProc/Proc/Zip/SaMsZipArchive.cs @@ -9,7 +9,7 @@ using System.IO.Compression; using System.Linq; using System.Text; -namespace Sarand.Net.Standard.Data.Zip +namespace Sarand.Net.Standard.Proc.Zip { //======================================================================= public class SaMsZipArchive : SaErrorStateItem diff --git a/SacsStandardData/SacsStandardData.csproj b/SacsStandardProc/SacsStandardProc.csproj similarity index 93% rename from SacsStandardData/SacsStandardData.csproj rename to SacsStandardProc/SacsStandardProc.csproj index 99cb6fd..b026d94 100644 --- a/SacsStandardData/SacsStandardData.csproj +++ b/SacsStandardProc/SacsStandardProc.csproj @@ -6,7 +6,7 @@ - +