Portal application - initial.
This commit is contained in:
+29
-5
@@ -20,7 +20,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SacsStandardAccounts", "..\
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusMgrStandardDbas", "SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj", "{C1C4109F-D8A0-49CD-8715-A9956EEE8928}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusMgrStandardDbas", "SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj", "{C1C4109F-D8A0-49CD-8715-A9956EEE8928}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SaBusinessMgrCoreWebOnline", "SaBusinessMgrCoreWebOnline\SaBusinessMgrCoreWebOnline.csproj", "{00ED5C97-C659-49FF-8153-CF1859954714}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusMgrCoreProcs", "SaBusMgrCoreProcs\SaBusMgrCoreProcs.csproj", "{259265C1-98A9-4AFA-9ECA-612CA3D699A1}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusMgrCoreWeb", "SaBusMgrCoreWeb\SaBusMgrCoreWeb.csproj", "{E9CB9C95-42E5-448D-8666-88B626422F4B}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SacsStandardProc", "..\..\Common-VS\Workspace\SacsStandardProc\SacsStandardProc.csproj", "{91A86CA2-15DF-432F-ACCB-BBF0AEEA2D11}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusinessMgrCoreWebControl", "SaBusinessMgrCoreWebControl\SaBusinessMgrCoreWebControl.csproj", "{EB0D8A3C-FF26-4086-84AA-597FA6DBA806}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SaBusinessMgrCoreWebPortal", "SaBusinessMgrCoreWebPortal\SaBusinessMgrCoreWebPortal.csproj", "{C7BA3DCA-5A4E-4541-899C-BF8208E276D5}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -52,10 +60,26 @@ Global
|
|||||||
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Release|Any CPU.Build.0 = Release|Any CPU
|
{C1C4109F-D8A0-49CD-8715-A9956EEE8928}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{00ED5C97-C659-49FF-8153-CF1859954714}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{259265C1-98A9-4AFA-9ECA-612CA3D699A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{00ED5C97-C659-49FF-8153-CF1859954714}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{259265C1-98A9-4AFA-9ECA-612CA3D699A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{00ED5C97-C659-49FF-8153-CF1859954714}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{259265C1-98A9-4AFA-9ECA-612CA3D699A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{00ED5C97-C659-49FF-8153-CF1859954714}.Release|Any CPU.Build.0 = Release|Any CPU
|
{259265C1-98A9-4AFA-9ECA-612CA3D699A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{E9CB9C95-42E5-448D-8666-88B626422F4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E9CB9C95-42E5-448D-8666-88B626422F4B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E9CB9C95-42E5-448D-8666-88B626422F4B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E9CB9C95-42E5-448D-8666-88B626422F4B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{91A86CA2-15DF-432F-ACCB-BBF0AEEA2D11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{91A86CA2-15DF-432F-ACCB-BBF0AEEA2D11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{91A86CA2-15DF-432F-ACCB-BBF0AEEA2D11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{91A86CA2-15DF-432F-ACCB-BBF0AEEA2D11}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{EB0D8A3C-FF26-4086-84AA-597FA6DBA806}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{EB0D8A3C-FF26-4086-84AA-597FA6DBA806}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{EB0D8A3C-FF26-4086-84AA-597FA6DBA806}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{EB0D8A3C-FF26-4086-84AA-597FA6DBA806}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{C7BA3DCA-5A4E-4541-899C-BF8208E276D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C7BA3DCA-5A4E-4541-899C-BF8208E276D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C7BA3DCA-5A4E-4541-899C-BF8208E276D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C7BA3DCA-5A4E-4541-899C-BF8208E276D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -0,0 +1,237 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Procs.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.Procs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Consoles
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmProcessConsole
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// I n t e r f a c e O p t i o n D e f i n i t i o n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static List<SaItemOptionDfn> GetInterfaceItemOptionDfns(SbmUserContext userContext, SaInterfaceCategory interfaceCategory, short interfaceType)
|
||||||
|
{
|
||||||
|
switch (interfaceCategory)
|
||||||
|
{
|
||||||
|
case SaInterfaceCategory.Website:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Accounts:
|
||||||
|
{
|
||||||
|
return new SbmAccountsDfn(userContext).GetInterfaceItemOptionDfns((Sbm.InterfaceType_Accounts)interfaceType);
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.System:
|
||||||
|
{
|
||||||
|
//if (interfaceType == (int)Sbm.InterfaceType_System.MSOutlook)
|
||||||
|
//return SbmInterface_System_MSOutlook.GetInterfaceItemOptionDfns();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.File:
|
||||||
|
{
|
||||||
|
if (interfaceType == (short)Sbm.InterfaceType_File.CommodityExport)
|
||||||
|
{
|
||||||
|
SbmInterfaceProcess_Commodity_Export.Config processConfig = new SbmInterfaceProcess_Commodity_Export.Config(userContext);
|
||||||
|
SbmInterfaceProcess_Commodity_Export process = new SbmInterfaceProcess_Commodity_Export(processConfig);
|
||||||
|
return process.GetInterfaceItemOptionDfns();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new List<SaItemOptionDfn>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g O p t i o n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static List<SaProcess_Base.GroupData> GetProcessingOptions(SbmUserContext userContext, SaInterface interfaceObj)
|
||||||
|
{
|
||||||
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return new List<SaProcess_Base.GroupData>();
|
||||||
|
List<SaProcess_Base.GroupData> optionGroups = null;
|
||||||
|
switch (interfaceObj.Category)
|
||||||
|
{
|
||||||
|
case SaInterfaceCategory.System:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Website:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Accounts:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.File:
|
||||||
|
{
|
||||||
|
if (interfaceObj.Type == (short)Sbm.InterfaceType_File.CommodityExport)
|
||||||
|
optionGroups = SbmInterfaceProcess_Commodity_Export.GetProcessingOptions(userContext, interfaceObj);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return optionGroups ?? new List<SaProcess_Base.GroupData>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// C o n f i g u r e P r o c e s s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static SbmInterfaceProcess ConfigureProcess(SbmUserContext userContext, SaInterface interfaceObj, SaProcess_Base.GroupData processGroup)
|
||||||
|
{
|
||||||
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return null;
|
||||||
|
switch (interfaceObj.Category)
|
||||||
|
{
|
||||||
|
case SaInterfaceCategory.System:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Website:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Accounts:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.File:
|
||||||
|
{
|
||||||
|
if (interfaceObj.Type == (short)Sbm.InterfaceType_File.CommodityExport)
|
||||||
|
return SbmInterfaceProcess_Commodity_Export.ConfigureProcess(userContext, interfaceObj, processGroup);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s I n t e r f a c e
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static bool ProcessInterface(SbmUserContext userContext, SaInterface interfaceObj)
|
||||||
|
{
|
||||||
|
if (interfaceObj == null || !SysId.IsValid(interfaceObj.Id)) return false;
|
||||||
|
switch (interfaceObj.Category)
|
||||||
|
{
|
||||||
|
case SaInterfaceCategory.System:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Website:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.Accounts:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SaInterfaceCategory.File:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// I n v o k e P r o c e s s D e f i n i t i o n
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Invoke process based on definition from command line argument.
|
||||||
|
public static bool InvokeProcessDefinition(SbmUserContext userContext, SacsProcessDefinition processDfn)
|
||||||
|
{
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
// Log process definition.
|
||||||
|
SaLogger.Info("Running process: " + processDfn.ProcessName + "." + (processDfn.Params.Count > 0 ? " Params: " + processDfn.Params.Concat() : ""), true);
|
||||||
|
SbmProcessConsole_Notifier processNotifier = new SbmProcessConsole_Notifier();
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
// Hapag-Lloyd EDI.
|
||||||
|
if (processDfn.ProcessName.EqualsCI("ApplicationParameterName..."))
|
||||||
|
{
|
||||||
|
String caption = "System Interface ...";
|
||||||
|
SaInterface saInterface = GetSystemInterfaceByType(userContext, (short)Sbm.InterfaceType_System.MSOutlook, caption);
|
||||||
|
if (saInterface != null)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
SbmInterface_System_HapagLloyd_Import.Config configInterface = new SbmInterface_System_HapagLloyd_Import.Config(dbUpdateInfo);
|
||||||
|
configInterface.InterfaceId = saInterface.Id;
|
||||||
|
configInterface.ImportNotifications = true;
|
||||||
|
configInterface.Automated = true;
|
||||||
|
SbmInterface_System_HapagLloyd_Import process = new SbmInterface_System_HapagLloyd_Import(configInterface);
|
||||||
|
process.ProcessNotifier = processNotifier;
|
||||||
|
process.RunProcess();
|
||||||
|
if (process.HasProcessError())
|
||||||
|
SaLogger.Warn(caption + " reported: " + process.GetProcessError(), true);
|
||||||
|
else if (process.IsInterrupted)
|
||||||
|
SaLogger.Warn(caption + " interrupted - processing may be incomplete.", true);
|
||||||
|
else
|
||||||
|
SaLogger.Info(caption + " run successfully", true);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Retrieve interface.
|
||||||
|
private static SaInterface GetSystemInterfaceByType(SbmUserContext userContext, short interfaceType, String caption)
|
||||||
|
{
|
||||||
|
return GetInterfaceByCategoryType(userContext, SaInterfaceCategory.System, interfaceType, caption);
|
||||||
|
}
|
||||||
|
private static SaInterface GetInterfaceByCategoryType(SbmUserContext userContext, SaInterfaceCategory interfaceCategory, short interfaceType, String caption)
|
||||||
|
{
|
||||||
|
SaInterface saInterface = null;
|
||||||
|
SaInterface.Params prmInterface = new SaInterface.Params();
|
||||||
|
prmInterface.InterfaceCategory = interfaceCategory;
|
||||||
|
prmInterface.IncludedInterfaceTypes.Add(interfaceType);
|
||||||
|
prmInterface.StatusCat = SaInterface.StatusCat.Any;
|
||||||
|
using (SaInterfaceConsole interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(userContext))
|
||||||
|
{
|
||||||
|
saInterface = interfaceConsole.GetInterface(prmInterface);
|
||||||
|
if (saInterface == null)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("Unable to run " + caption + " - Interface not found", true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!saInterface.Active)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("Unable to run " + caption + " - Interface is not active", true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return saInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Process Notificer for Process Console.
|
||||||
|
/// </summary>
|
||||||
|
class SbmProcessConsole_Notifier : ISacsProcessNotifier
|
||||||
|
{
|
||||||
|
public void OnStartProcess()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void OnEndProcess()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public void SetProgressInfo(List<string> progressInfo)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Procs.Procs;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.IO;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Interfaces
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmInterfaceProcess : SbmProcess_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Configuration.
|
||||||
|
public enum InterfaceProcessCreation
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
OnStartProcessing,
|
||||||
|
OnLogMessage,
|
||||||
|
}
|
||||||
|
public new class Config : SbmProcess_Base.Config
|
||||||
|
{
|
||||||
|
protected Config (SbmUserContext userContext) : base(userContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public SysId InterfaceId { get; set; }
|
||||||
|
public List<SysId> ItemIds { get; } = new List<SysId>();
|
||||||
|
public InterfaceProcessCreation InterfaceProcessCreation { get; set; } = InterfaceProcessCreation.OnLogMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
/// <summary>Interface processing groups - used for popup 'Process Interface' form.</summary>
|
||||||
|
public enum InterfaceProcessGroup
|
||||||
|
{
|
||||||
|
Import,
|
||||||
|
Export,
|
||||||
|
}
|
||||||
|
/// <summary>Interface configuration parameters.</summary>
|
||||||
|
public class InterfaceParams : SbmProcess_Base.ProcessParams
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/// <summary>Process parameters - processing control properties.</summary>
|
||||||
|
public new class ProcessParams : SbmProcess_Base.ProcessParams
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private Config config = null;
|
||||||
|
private static List<TypeCodeDesc> interfaceProcessGroups = null;
|
||||||
|
private SaInterface interfaceObj = null;
|
||||||
|
private SaInterfaceProcess interfaceProcess = null;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Static initialisation.
|
||||||
|
static SbmInterfaceProcess ()
|
||||||
|
{
|
||||||
|
// Interface process groups.
|
||||||
|
interfaceProcessGroups = new List<TypeCodeDesc>();
|
||||||
|
interfaceProcessGroups.Add(InterfaceProcessGroup.Import, "Import", "Import");
|
||||||
|
interfaceProcessGroups.Add(InterfaceProcessGroup.Export, "Export", "Export");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
protected SbmInterfaceProcess (Config config) : base(config)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
interfaceObj = InterfaceConsole.GetInterfaceById(config.InterfaceId);
|
||||||
|
}
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (interfaceProcess != null) interfaceProcess.Dispose(); interfaceProcess = null;
|
||||||
|
if (interfaceObj != null) interfaceObj.Dispose(); interfaceObj = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
protected String InterfaceCaptionSuffix { get; set; } = " [Interface]";
|
||||||
|
protected static List<TypeCodeDesc> InterfaceProcessGroups { get { return new List<TypeCodeDesc>(interfaceProcessGroups); } }
|
||||||
|
protected SaInterface Interface { get { return interfaceObj; } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Validate configuration.
|
||||||
|
protected virtual bool ValidateConfig ()
|
||||||
|
{
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override void ResetProcess ()
|
||||||
|
{
|
||||||
|
base.ResetProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// I t e m O p t i o n D e f i n i t i o n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected static SaItemOptionDfn InitItemOptionDfn (String itemOptionName, String itemOptionCaption, List<TypeCodeDesc> optionContexts = null)
|
||||||
|
{
|
||||||
|
SaItemOptionDfn itemOptionDfn = new SaItemOptionDfn();
|
||||||
|
itemOptionDfn.Name = itemOptionName;
|
||||||
|
itemOptionDfn.DisplayOptions.Caption = itemOptionCaption;
|
||||||
|
if (optionContexts != null)
|
||||||
|
{
|
||||||
|
itemOptionDfn.DisplayOptions.Contexts.AddRange(optionContexts);
|
||||||
|
itemOptionDfn.DisplayOptions.RequiresContext = true;
|
||||||
|
}
|
||||||
|
itemOptionDfn.DisplayOptions.NonDisplayTemplate = true;
|
||||||
|
itemOptionDfn.DisplayOptions.CanAddOption = true;
|
||||||
|
itemOptionDfn.DisplayOptions.CanRemoveOption = true;
|
||||||
|
return itemOptionDfn;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g E v e n t s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override void OnProcessStarting ()
|
||||||
|
{
|
||||||
|
base.OnProcessStarting();
|
||||||
|
if (config.InterfaceProcessCreation == InterfaceProcessCreation.OnStartProcessing)
|
||||||
|
OpenInterfaceProcess();
|
||||||
|
}
|
||||||
|
protected override void OnProcessEnding ()
|
||||||
|
{
|
||||||
|
CloseInterfaceProcess();
|
||||||
|
base.OnProcessEnding();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// I n t e r f a c e P r o c e s s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private bool OpenInterfaceProcess ()
|
||||||
|
{
|
||||||
|
if (!SysId.IsValid(config.InterfaceId)) return false;
|
||||||
|
|
||||||
|
// Check if interface process already created.
|
||||||
|
if (interfaceProcess != null && interfaceProcess.InterfaceId.Equals(config.InterfaceId)) return true;
|
||||||
|
|
||||||
|
// Create interface process.
|
||||||
|
SaInterfaceProcessDirection processDirection = SaInterfaceProcessDirection.Inbound;
|
||||||
|
if (config.Export) processDirection = SaInterfaceProcessDirection.Outbound;
|
||||||
|
int processSequence = (InterfaceConsole.GetMaxProcessSequence(config.InterfaceId, processDirection, false) + 1);
|
||||||
|
interfaceProcess = InterfaceConsole.StartInterfaceProcess(config.InterfaceId, processDirection, DateUtil.Format(StartedAt, "yyyyMMddHHmmss"), StartedAt, processSequence, DbUpdateInfo);
|
||||||
|
|
||||||
|
return (interfaceProcess != null && interfaceProcess.InterfaceId.Equals(config.InterfaceId));
|
||||||
|
}
|
||||||
|
private bool CloseInterfaceProcess ()
|
||||||
|
{
|
||||||
|
if (interfaceProcess == null) return false;
|
||||||
|
|
||||||
|
interfaceProcess.ElapseSecs = ElapsedSecs;
|
||||||
|
if (OK)
|
||||||
|
{
|
||||||
|
interfaceProcess.Status = SaStatus.Completed;
|
||||||
|
LogInterfaceProcessMessage("Processing completed successfully");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Process has not completed.
|
||||||
|
interfaceProcess.Status = SaStatus.Cancelled;
|
||||||
|
if (HasProcessError()) LogInterfaceProcessMessage(GetProcessError(), SaMessageLevel.Error);
|
||||||
|
if (IsInterrupted) LogInterfaceProcessMessage("Processing cancelled by user", SaMessageLevel.Warning);
|
||||||
|
}
|
||||||
|
if (InterfaceConsole.StoreInterfaceProcess(interfaceProcess, DbUpdateInfo))
|
||||||
|
{ }
|
||||||
|
else if (!HasProcessError())
|
||||||
|
SetProcessError("Failed to store interface process: " + InterfaceConsole.ErrorStateMessage);
|
||||||
|
|
||||||
|
// Clean-up.
|
||||||
|
interfaceProcess.Dispose();
|
||||||
|
interfaceProcess = null;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool LogInterfaceProcessMessage (String message, SaMessageLevel messageLevel = SaMessageLevel.Info)
|
||||||
|
{
|
||||||
|
if (!OpenInterfaceProcess()) return false;
|
||||||
|
|
||||||
|
// Log interface process message.
|
||||||
|
InterfaceConsole.LogInterfaceProcessMessage(interfaceProcess.Id, DbUpdateInfo, message, messageLevel);
|
||||||
|
|
||||||
|
// Errors and warnings wil retunr false.
|
||||||
|
return (messageLevel == SaMessageLevel.Info || messageLevel == SaMessageLevel.Debug || messageLevel == SaMessageLevel.Trace);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// I n t e r f a c e D a t a I t e m s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool StoreInterfaceDataItem (SaInterfaceDataItem interfaceDataItem, SaStatus processStatus, SaStatus itemStatus, String itemCaption)
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
DateTime now = DateTime.Now;
|
||||||
|
|
||||||
|
// Process status.
|
||||||
|
if ((int)processStatus > 0)
|
||||||
|
{
|
||||||
|
interfaceDataItem.ProcessStatus = processStatus;
|
||||||
|
interfaceDataItem.ProcessStatusAt = now;
|
||||||
|
interfaceDataItem.ProcessStatusBy = DbUpdateInfo.UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Item status.
|
||||||
|
if ((int)itemStatus > 0)
|
||||||
|
{
|
||||||
|
interfaceDataItem.ItemStatus = itemStatus;
|
||||||
|
interfaceDataItem.ItemStatusAt = now;
|
||||||
|
interfaceDataItem.ItemStatusBy = DbUpdateInfo.UserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store interface data item.
|
||||||
|
if (!InterfaceConsole.StoreInterfaceDataItem(interfaceDataItem, DbUpdateInfo))
|
||||||
|
SetProcessError("Failed to save Interface data item" + (!StringUtil.IsEmpty(itemCaption) ? " for " + itemCaption : "") + " - " + InterfaceConsole.ErrorStateMessage);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// A r c h i v e F i l e
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool SaveFileDataToArchive (String archiveRootFolder, String fileName, String fileExtension, String fileData, String fn)
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
|
||||||
|
DateTime today = DateTime.Today;
|
||||||
|
String archiveFolder =
|
||||||
|
archiveRootFolder.TrimEnd(new char[] { Path.DirectorySeparatorChar }) + Path.DirectorySeparatorChar +
|
||||||
|
DateUtil.Format(today, "yyyy") + Path.DirectorySeparatorChar +
|
||||||
|
DateUtil.Format(today, "yyyyMM");
|
||||||
|
SaLogger.Debug(fn + " Archive folder: " + archiveFolder);
|
||||||
|
if (FileUtil.ValidateDirectory(archiveFolder, true))
|
||||||
|
{
|
||||||
|
for (int fileIdx = 0; fileIdx < 10000; fileIdx++)
|
||||||
|
{
|
||||||
|
String archiveFilename = fileName + (fileIdx > 0 ? "." + StringUtil.PadLeft(fileIdx.ToString(), 4, '0') : "") + (!StringUtil.IsEmpty(fileExtension) ? "." + fileExtension : "");
|
||||||
|
String archivePath = archiveFolder + Path.DirectorySeparatorChar + archiveFilename;
|
||||||
|
SaLogger.Debug(fn + " Archive path: " + archivePath);
|
||||||
|
if (!FileUtil.IsFile(archivePath))
|
||||||
|
{
|
||||||
|
File.WriteAllText(archivePath, fileData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return LogInterfaceProcessMessage("Failed to validate archive folder '" + archiveFolder + "'.", SaMessageLevel.Warning);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
|||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using Sarand.Net.Standard.Proc.Excel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Procs
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
// D a t a E x p o r t P r o c e s s
|
||||||
|
//=======================================================================
|
||||||
|
partial class SbmProcess_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Open Excel worksheet.
|
||||||
|
/// <para>Additional sheets are added up to the position specified if less are currently populated.</para>
|
||||||
|
/// </summary>
|
||||||
|
protected bool OpenWorkSheet (SaMsSpreadsheet spreadsheet, uint worksheetPos = 1, String worksheetName = "")
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
if (worksheetPos < 1) worksheetPos = 1;
|
||||||
|
|
||||||
|
while (spreadsheet.WorksheetCount < worksheetPos)
|
||||||
|
spreadsheet.AddWorksheet("Sheet " + (spreadsheet.WorksheetCount + 1));
|
||||||
|
spreadsheet.OpenWorksheet(worksheetPos);
|
||||||
|
if (!StringUtil.IsEmpty(StringUtil.TrimAll(worksheetName, new char[] { ' ' })))
|
||||||
|
spreadsheet.WorksheetName = worksheetName;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,276 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Core.Procs.Procs;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Procs
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
// F T P
|
||||||
|
//=======================================================================
|
||||||
|
partial class SbmProcess_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
public class FtpConfig
|
||||||
|
{
|
||||||
|
public String Host { get; set; }
|
||||||
|
public String Username { get; set; }
|
||||||
|
public String Password { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// F T P U t i l i t i e s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private String GetFtpUrl (FtpConfig ftpConfig, String path)
|
||||||
|
{
|
||||||
|
return "ftp://" + ftpConfig.Host + "/" + FtpUtil.CleansePath(path);
|
||||||
|
}
|
||||||
|
private FtpWebRequest CreateFtpRequest (FtpConfig ftpConfig, String path, bool keepAlive = true)
|
||||||
|
{
|
||||||
|
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(GetFtpUrl(ftpConfig, path));
|
||||||
|
// Credentials.
|
||||||
|
if (!StringUtil.IsEmpty(ftpConfig.Username) || StringUtil.IsEmpty(ftpConfig.Password))
|
||||||
|
ftpRequest.Credentials = new NetworkCredential(ftpConfig.Username, ftpConfig.Password);
|
||||||
|
ftpRequest.UseBinary = true;
|
||||||
|
// Keep alive = true will reuse the connection (behind the scenes) even though
|
||||||
|
// a new FTP Web Request is created for each request. Don't know how!
|
||||||
|
// Ref. https://stackoverflow.com/questions/7132246/how-to-reuse-ftpwebrequest-connection/7132428#7132428
|
||||||
|
// Network tracing: https://stackoverflow.com/questions/9664650/output-log-using-ftpwebrequest/9666598#9666598
|
||||||
|
ftpRequest.KeepAlive = keepAlive;
|
||||||
|
ftpRequest.Timeout = 5000;
|
||||||
|
ftpRequest.UsePassive = true;
|
||||||
|
return ftpRequest;
|
||||||
|
}
|
||||||
|
private WebClient CreateFtpWebClient (FtpConfig ftpConfig)
|
||||||
|
{
|
||||||
|
WebClient webClient = new WebClient();
|
||||||
|
// Credentials.
|
||||||
|
if (!StringUtil.IsEmpty(ftpConfig.Username) || StringUtil.IsEmpty(ftpConfig.Password))
|
||||||
|
webClient.Credentials = new NetworkCredential(ftpConfig.Username, ftpConfig.Password);
|
||||||
|
return webClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Test connection.
|
||||||
|
protected bool TestFtpConnection (FtpConfig ftpConfig)
|
||||||
|
{
|
||||||
|
String fn = GetType().Name + ".TestFtpConnection";
|
||||||
|
WebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// FTP request.
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, "");
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
|
||||||
|
// Send request.
|
||||||
|
response = ftpRequest.GetResponse();
|
||||||
|
using (Stream responseStream = response.GetResponseStream())
|
||||||
|
using (StreamReader reader = new StreamReader(responseStream))
|
||||||
|
{
|
||||||
|
String responseData = reader.ReadToEnd();
|
||||||
|
SaLogger.Debug(fn + ": Items in root: " + responseData.ReplaceAll("\r\n", ", "));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
return SetProcessError("Unable to connect to FTP host");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
protected bool CloseFtpConnection (FtpConfig ftpConfig)
|
||||||
|
{
|
||||||
|
WebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// FTP request with KeepAlive=false to close connection.
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, "", false);
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectory;
|
||||||
|
response = ftpRequest.GetResponse();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool FtpFolderExists (FtpConfig ftpConfig, String folder)
|
||||||
|
{
|
||||||
|
String fn = GetType().Name + ".FtpFolderExists";
|
||||||
|
WebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String parentFolder = FtpUtil.GetParentFolder(folder);
|
||||||
|
String itemName = FtpUtil.GetItemName(folder);
|
||||||
|
// FTP request.
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, parentFolder);
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
|
||||||
|
// Send request.
|
||||||
|
String data = "";
|
||||||
|
response = ftpRequest.GetResponse();
|
||||||
|
using (Stream responseStream = response.GetResponseStream())
|
||||||
|
using (StreamReader reader = new StreamReader(responseStream))
|
||||||
|
{
|
||||||
|
data = reader.ReadToEnd().Replace("\r", "");
|
||||||
|
}
|
||||||
|
String[] directoryItems = data.Split(new String[] { "\n" }, StringSplitOptions.None);
|
||||||
|
foreach (String directoryItemData in directoryItems)
|
||||||
|
{
|
||||||
|
FtpUtil.FtpDirectoryItem directoryItem = FtpUtil.GetDirectoryItem(directoryItemData);
|
||||||
|
if (directoryItem != null && directoryItem.Name.EqualsCI(itemName))
|
||||||
|
return directoryItem.IsDirectory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Get list of items in remote FTP folder.</summary>
|
||||||
|
protected List<FtpUtil.FtpDirectoryItem> GetFtpFileItems (FtpConfig ftpConfig, String folder)
|
||||||
|
{
|
||||||
|
return GetFtpItems(ftpConfig, folder).FindAll(item => !item.IsDirectory);
|
||||||
|
}
|
||||||
|
/// <summary>Get list of items in remote FTP folder.</summary>
|
||||||
|
protected List<FtpUtil.FtpDirectoryItem> GetFtpItems (FtpConfig ftpConfig, String folder)
|
||||||
|
{
|
||||||
|
String fn = this.GetType().Name + ".GetFtpItems";
|
||||||
|
List<FtpUtil.FtpDirectoryItem> files = new List<FtpUtil.FtpDirectoryItem>();
|
||||||
|
WebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// FTP request.
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, folder);
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
|
||||||
|
// Send request.
|
||||||
|
// Send request.
|
||||||
|
response = ftpRequest.GetResponse();
|
||||||
|
String data = "";
|
||||||
|
using (Stream responseStream = response.GetResponseStream())
|
||||||
|
using (StreamReader reader = new StreamReader(responseStream))
|
||||||
|
{
|
||||||
|
data = reader.ReadToEnd().Replace("\r", "");
|
||||||
|
}
|
||||||
|
String[] directoryItems = data.Split(new String[] { "\n" }, StringSplitOptions.None);
|
||||||
|
foreach (String directoryItemData in directoryItems)
|
||||||
|
{
|
||||||
|
FtpUtil.FtpDirectoryItem directoryItem = FtpUtil.GetDirectoryItem(directoryItemData);
|
||||||
|
if (directoryItem != null)
|
||||||
|
files.Add(directoryItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected String GetFtpFileData (FtpConfig ftpConfig, String folder, String filename)
|
||||||
|
{
|
||||||
|
String fn = GetType() + ".GetFtpFileData";
|
||||||
|
WebClient ftpClient = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ftpClient = CreateFtpWebClient(ftpConfig);
|
||||||
|
String ftpUrl = GetFtpUrl(ftpConfig, folder + "/" + filename);
|
||||||
|
byte[] fileData = ftpClient.DownloadData(ftpUrl);
|
||||||
|
return System.Text.Encoding.UTF8.GetString(fileData);
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (ftpClient != null) ftpClient.Dispose();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool WriteDataToFtpFile (FtpConfig ftpConfig, String folder, String filename, String data)
|
||||||
|
{
|
||||||
|
String fn = GetType() + ".WriteDataToFtpFile";
|
||||||
|
bool dataWrittenToFile = false;
|
||||||
|
FtpWebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, folder + Path.DirectorySeparatorChar + filename);
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
|
||||||
|
ftpRequest.ContentLength = data.Length;
|
||||||
|
using (Stream request_stream = ftpRequest.GetRequestStream())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(data);
|
||||||
|
request_stream.Write(bytes, 0, data.Length);
|
||||||
|
request_stream.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return dataWrittenToFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected bool DeleteFtpFile (FtpConfig ftpConfig, String folder, String filename)
|
||||||
|
{
|
||||||
|
String fn = GetType() + ".DeleteFtpData";
|
||||||
|
bool fileDeleted = false;
|
||||||
|
FtpWebResponse response = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// FTP request.
|
||||||
|
FtpWebRequest ftpRequest = CreateFtpRequest(ftpConfig, folder + Path.DirectorySeparatorChar + filename);
|
||||||
|
ftpRequest.Method = WebRequestMethods.Ftp.DeleteFile;
|
||||||
|
response = (FtpWebResponse)ftpRequest.GetResponse();
|
||||||
|
if (EnhancedLogging) SaLogger.Info(ProcessDescription + " - Delete FTP file: Response: " + response.StatusDescription, true);
|
||||||
|
fileDeleted = true;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + exc.GetType().Name + ": " + exc.Message, true);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (response != null) response.Dispose();
|
||||||
|
}
|
||||||
|
return fileDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,300 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.UpdateLog;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using Sarand.Net.Standard.Proc.Procs;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Procs
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract partial class SbmProcess_Base : SaProcess
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Configuration.
|
||||||
|
public enum DataFormatType
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
Flat,
|
||||||
|
Csv,
|
||||||
|
Excel,
|
||||||
|
Word,
|
||||||
|
}
|
||||||
|
public new class Config : SaProcess.Config
|
||||||
|
{
|
||||||
|
protected Config (SbmUserContext userContext) : base()
|
||||||
|
{
|
||||||
|
UserContext = userContext;
|
||||||
|
}
|
||||||
|
public SbmUserContext UserContext { get; }
|
||||||
|
/// <summary>Specific type of data item being handled.</summary>
|
||||||
|
public Sbm.ItemType ItemType { get; set; } = Sbm.ItemType.Unknown;
|
||||||
|
/// <summary>Format to import/export data.</summary>
|
||||||
|
public DataFormatType DataFormat { get; set; } = DataFormatType.Unknown;
|
||||||
|
/// <summary>Application managers and consoles - to share parent's internals.</summary>
|
||||||
|
public SbmInternals Internals { get; set; }
|
||||||
|
/// <summary>Extended logging messages.</summary>
|
||||||
|
public bool EnhancedLogging { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
/// <summary>Process parameters - processing control properties</summary>
|
||||||
|
public class ProcessParams
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private Config config;
|
||||||
|
private SbmInternals internals = null;
|
||||||
|
private List<SaItemOption> processingOptions = null;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
protected SbmProcess_Base (Config config) : base(config)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
if (!EnhancedLogging) EnhancedLogging = config.EnhancedLogging;
|
||||||
|
}
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (internals != null) internals.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
protected bool EnhancedLogging { get; set; }
|
||||||
|
/// <summary>Comments are populated with list of processing options by default.</summary>
|
||||||
|
public override List<string> ProcessComments
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
List<String> comments = new List<string>(base.ProcessComments);
|
||||||
|
List<SaItemOptionDfn> optionDfns = GetProcessingOptionDfns();
|
||||||
|
foreach (SaItemOption itemOption in GetProcessingOptions())
|
||||||
|
{
|
||||||
|
SaItemOptionDfn optionDfn = optionDfns.GetItemOptionDfnByName(itemOption.Name);
|
||||||
|
String context = optionDfn?.GetContextDesc(itemOption.Context) ?? itemOption.Context;
|
||||||
|
String caption = itemOption.Name + (!StringUtil.IsEmpty(context) ? " - " + context : "");
|
||||||
|
String value = StringUtil.EmptyOnNull(itemOption.Value);
|
||||||
|
comments.Add(caption + ": " + value);
|
||||||
|
}
|
||||||
|
return comments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Context.
|
||||||
|
public SbmUserContext UserContext { get { return config.UserContext; } }
|
||||||
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
|
protected SbmInternals Internals
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Use supplied internals if available.
|
||||||
|
if (config.Internals != null) return config.Internals;
|
||||||
|
// Otherwise use local instance.
|
||||||
|
if (internals == null)
|
||||||
|
internals = new SbmInternals(UserContext);
|
||||||
|
return internals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected SbmAccountsDfn AccountsDfn { get { return Internals.AccountsDfn; } }
|
||||||
|
protected DbUpdateInfo DbUpdateInfo { get { return Internals.DbUpdateInfo; } }
|
||||||
|
// Excel export.
|
||||||
|
public static Color ExcelColumnHeadingColor { get; } = Color.LightYellow;
|
||||||
|
// Security.
|
||||||
|
protected SbmSecurityProfile SecurityProfile { get { return Internals.SecurityProfile; } }
|
||||||
|
protected bool UserCanUpdateContacts { get { return (SecurityProfile != null && SecurityProfile.Contacts.CanUpdate); } }
|
||||||
|
protected bool UserCanCreateContacts { get { return (SecurityProfile != null && SecurityProfile.Contacts.CanCreate); } }
|
||||||
|
protected bool UserCanViewFinancials { get { return (SecurityProfile != null && SecurityProfile.Financial.CanViewFinancials); } }
|
||||||
|
protected bool UserCanUpdateFinancials { get { return (SecurityProfile != null && SecurityProfile.Financial.CanUpdateFinancials); } }
|
||||||
|
protected bool UserCanManageFinancials { get { return (SecurityProfile != null && SecurityProfile.Financial.CanViewFinancials); } }
|
||||||
|
// ToDo SbmForm SecurityProfile Assets.
|
||||||
|
/*
|
||||||
|
protected bool UserCanManageAssets { get { return (SecurityProfile != null && SecurityProfile.Assets.CanManage); } }
|
||||||
|
protected bool UserCanUpdateAssets { get { return (SecurityProfile != null && SecurityProfile.Assets.CanUpdate); } }
|
||||||
|
protected bool UserCanViewAssets { get { return (SecurityProfile != null && SecurityProfile.Assets.CanView); } }
|
||||||
|
*/
|
||||||
|
// Managers.
|
||||||
|
protected SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||||
|
protected SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||||
|
protected SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||||
|
protected SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||||
|
protected SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||||
|
protected SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||||
|
protected SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||||
|
// Consoles.
|
||||||
|
protected SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
||||||
|
protected SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||||
|
protected SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||||
|
protected SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||||
|
protected SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||||
|
protected SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||||
|
protected SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||||
|
protected SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||||
|
// Configurations.
|
||||||
|
protected SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||||
|
protected SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||||
|
// Currencies.
|
||||||
|
protected List<SaCurrency> GetCurrencies ()
|
||||||
|
{
|
||||||
|
return Internals.GetCurrencies();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected SaCurrency GetCurrencyById (SysId currencyId)
|
||||||
|
{
|
||||||
|
return Internals.GetCurrencyById(currencyId);
|
||||||
|
}
|
||||||
|
protected SaCurrency GetCurrencyByCode (String currencyCode)
|
||||||
|
{
|
||||||
|
return Internals.GetCurrencyByCode(currencyCode);
|
||||||
|
}
|
||||||
|
protected static byte CurrencyDecimalsDefault { get { return SbmInternals.CurrencyDecimalsDefault; } }
|
||||||
|
protected byte GetCurrencyDecimalsForCurrencyById (SysId currencyId)
|
||||||
|
{
|
||||||
|
return Internals.GetCurrencyDecimalsForCurrencyById(currencyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected virtual void ResetProcess ()
|
||||||
|
{
|
||||||
|
ClearStatistics();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g O p t i o n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Are options supported - False by default.</summary>
|
||||||
|
public virtual bool HasProcessingOptions ()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>Are required options populated - True by default.</summary>
|
||||||
|
public virtual bool AreProcessingOptionsComplete ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>Processing option definitions.</summary>
|
||||||
|
public virtual List<SaItemOptionDfn> GetProcessingOptionDfns ()
|
||||||
|
{
|
||||||
|
return new List<SaItemOptionDfn>();
|
||||||
|
}
|
||||||
|
/// <summary>Processing options.</summary>
|
||||||
|
public virtual List<SaItemOption> GetProcessingOptions ()
|
||||||
|
{
|
||||||
|
return new List<SaItemOption>(processingOptions ?? new List<SaItemOption>());
|
||||||
|
}
|
||||||
|
public String GetProcessingOptionValue (String name, String context, String defaultValue = "")
|
||||||
|
{
|
||||||
|
if (processingOptions == null)
|
||||||
|
SetProcessingOptions(GetProcessingOptions());
|
||||||
|
SaItemOption itemOption = processingOptions.Find(item => item.Name.EqualsCI(name) && item.Context.EqualsCI(context));
|
||||||
|
return itemOption?.Value ?? defaultValue;
|
||||||
|
}
|
||||||
|
/// <summary>Store processing options.</summary>
|
||||||
|
public virtual bool SetProcessingOptions (List<SaItemOption> processingOptions)
|
||||||
|
{
|
||||||
|
this.processingOptions = new List<SaItemOption>(processingOptions);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>Allow process to update its own options.</summary>
|
||||||
|
public virtual bool UpdateProcessingOptions ()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
/// <summary>Allow process to update its own options.</summary>
|
||||||
|
public virtual bool UpdateOptions ()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g S t a t i s t i c s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected class StatisticsData
|
||||||
|
{
|
||||||
|
public class Stat
|
||||||
|
{
|
||||||
|
public Stat (int statType, int initialValue = 0)
|
||||||
|
{
|
||||||
|
StatType = statType;
|
||||||
|
InitialValue = initialValue;
|
||||||
|
}
|
||||||
|
public int StatType { get; }
|
||||||
|
public int InitialValue { get; }
|
||||||
|
}
|
||||||
|
public void Clear () { }
|
||||||
|
public Dictionary<int, int> Statistics { get; } = new Dictionary<int, int>();
|
||||||
|
}
|
||||||
|
private readonly StatisticsData stats = new StatisticsData();
|
||||||
|
protected int GetStatistic (int statisticType)
|
||||||
|
{
|
||||||
|
return stats.Statistics.GetValue(statisticType, 0);
|
||||||
|
}
|
||||||
|
protected int GetStatistic<T> (T statisticType) where T : struct, IConvertible
|
||||||
|
{
|
||||||
|
if (!(statisticType is Enum))
|
||||||
|
throw new ArgumentException(this.GetFn("GetStatistic") + " parameter must be an enumerated type. Type supplied: " + typeof(T).Name);
|
||||||
|
return GetStatistic((int)(statisticType as IConvertible));
|
||||||
|
}
|
||||||
|
protected int SetStatistic (int statisticType, int value)
|
||||||
|
{
|
||||||
|
return stats.Statistics[statisticType] = value;
|
||||||
|
}
|
||||||
|
protected int SetStatistic<T> (T statisticType, int value) where T : struct, IConvertible
|
||||||
|
{
|
||||||
|
if (!(statisticType is Enum))
|
||||||
|
throw new ArgumentException(this.GetFn("SetStatistic") + " parameter must be an enumerated type. Type supplied: " + typeof(T).Name);
|
||||||
|
return SetStatistic((int)(statisticType as IConvertible), value);
|
||||||
|
}
|
||||||
|
protected int IncrementStatistic (int statisticType, int increment = 1)
|
||||||
|
{
|
||||||
|
return stats.Statistics[statisticType] = GetStatistic(statisticType) + increment;
|
||||||
|
}
|
||||||
|
protected int IncrementStatistic<T> (T statisticType, int increment = 1) where T : struct, IConvertible
|
||||||
|
{
|
||||||
|
if (!(statisticType is Enum))
|
||||||
|
throw new ArgumentException(this.GetFn("IncrementStatistic") + " parameter must be an enumerated type. Type supplied: " + typeof(T).Name);
|
||||||
|
return IncrementStatistic((int)(statisticType as IConvertible), increment);
|
||||||
|
}
|
||||||
|
protected void ClearStatistic (int statisticType)
|
||||||
|
{
|
||||||
|
if (stats.Statistics.ContainsKey(statisticType))
|
||||||
|
stats.Statistics.Remove(statisticType);
|
||||||
|
}
|
||||||
|
protected void ClearStatistic<T> (T statisticType) where T : struct, IConvertible
|
||||||
|
{
|
||||||
|
if (!(statisticType is Enum))
|
||||||
|
throw new ArgumentException(this.GetFn("ClearStatistic") + " parameter must be an enumerated type. Type supplied: " + typeof(T).Name);
|
||||||
|
ClearStatistic((int)(statisticType as IConvertible));
|
||||||
|
}
|
||||||
|
private void ClearStatistics ()
|
||||||
|
{
|
||||||
|
stats.Statistics.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,859 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.IO;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using Sarand.Net.Standard.Proc.Excel;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Procs
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmProcess_Commodity_Export : SbmProcess_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Configuration.
|
||||||
|
public new class Config : SbmProcess_Base.Config
|
||||||
|
{
|
||||||
|
public Config (SbmUserContext userContext) : base(userContext)
|
||||||
|
{
|
||||||
|
ItemType = Sbm.ItemType.Commodity;
|
||||||
|
DataFormat = DataFormatType.Excel;
|
||||||
|
ProcessType = ProcessType.ExportData;
|
||||||
|
ConfirmInterruption = true;
|
||||||
|
}
|
||||||
|
public ExportType ExportType { get; set; } = ExportType.Overview;
|
||||||
|
public SbmCommodity.Params CommodityParams { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
public enum ExportType
|
||||||
|
{
|
||||||
|
Overview,
|
||||||
|
StockControl,
|
||||||
|
PurchasePlanning,
|
||||||
|
PurchasePlanning_ImminentStock,
|
||||||
|
ActualSales,
|
||||||
|
ProjectedSales,
|
||||||
|
};
|
||||||
|
public enum ProcessOptionFlag
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
IncludeCol_MaterialCost,
|
||||||
|
IncludeCol_CostPrice,
|
||||||
|
IncludeCol_RetailPrice,
|
||||||
|
IncludeCol_StockCurrent,
|
||||||
|
IncludeCol_StockAvailable,
|
||||||
|
IncludeCol_StockDue_MonthTo03,
|
||||||
|
IncludeCol_StockDue_MonthTo06,
|
||||||
|
};
|
||||||
|
/// <summary>Process parameters - processing control properties</summary>
|
||||||
|
public new class ProcessParams : SbmProcess_Base.ProcessParams
|
||||||
|
{
|
||||||
|
public bool CommodityProcessesExist { get; set; } = false;
|
||||||
|
public uint HomeColumn { get; set; } = 1;
|
||||||
|
public uint HomeRow { get; set; } = 1;
|
||||||
|
public long CommodityCountTotal { get; set; } = -1;
|
||||||
|
public uint HeaderCaptionRow { get; set; } = 1;
|
||||||
|
public uint FirstDataRow { get; set; } = 2;
|
||||||
|
public uint FirstDataColumn { get; set; } = 1;
|
||||||
|
// Processing options.
|
||||||
|
public bool IncludeCol_MaterialCost { get; set; }
|
||||||
|
public bool IncludeCol_CostPrice { get; set; }
|
||||||
|
public bool IncludeCol_RetailPrice { get; set; }
|
||||||
|
public bool IncludeCol_StockCurrent { get; set; }
|
||||||
|
public bool IncludeCol_StockAvailable { get; set; }
|
||||||
|
public bool IncludeCol_StockDue_3Months { get; set; }
|
||||||
|
public bool IncludeCol_StockDue_6Months { get; set; }
|
||||||
|
}
|
||||||
|
/// <summary>Processing statistics - keep track of number of items actioned.</summary>
|
||||||
|
public enum ProcessingStatistic
|
||||||
|
{
|
||||||
|
CommoditiesExported,
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private Config config;
|
||||||
|
private static String OptionName_Flag = "Flag";
|
||||||
|
private List<TypeCodeDesc> optionContexts_Flag = new List<TypeCodeDesc>();
|
||||||
|
private List<SaItemOptionDfn> processingOptionDfns = new List<SaItemOptionDfn>();
|
||||||
|
private List<SaItemOption> processingOptions = new List<SaItemOption>();
|
||||||
|
private readonly List<ColumnDfn> displayColumns = new List<ColumnDfn>();
|
||||||
|
private readonly List<ColumnDfn> additionalQueryColumns = new List<ColumnDfn>();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmProcess_Commodity_Export (Config config) : base(config)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
Params.CommodityProcessesExist = ProcessMgr.HasProcesses(Sbm.ProcessCategory.Commodity);
|
||||||
|
}
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
protected ProcessParams Params { get; } = new ProcessParams();
|
||||||
|
public override string ProcessDescription
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
String processDescription = "Commodities to Excel";
|
||||||
|
if (config.ExportType == ExportType.Overview)
|
||||||
|
processDescription += " - Overview";
|
||||||
|
else if (config.ExportType == ExportType.StockControl)
|
||||||
|
processDescription += " - Stock";
|
||||||
|
else if (config.ExportType == ExportType.PurchasePlanning)
|
||||||
|
processDescription += " - Purchasing";
|
||||||
|
else if (config.ExportType == ExportType.PurchasePlanning_ImminentStock)
|
||||||
|
processDescription += " - Purchasing (imminent stock)";
|
||||||
|
else if (config.ExportType == ExportType.ActualSales)
|
||||||
|
processDescription += " - Actual Sales";
|
||||||
|
else if (config.ExportType == ExportType.ProjectedSales)
|
||||||
|
processDescription += " - Projected Sales";
|
||||||
|
return processDescription;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override List<String> ProcessComments
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
List<String> processComments = new List<string>();
|
||||||
|
CalculateItemCount();
|
||||||
|
processComments.Add("Commodities to export: " + Params.CommodityCountTotal);
|
||||||
|
processComments.AddRange(config.CommodityParams.GetDisplayValues(UserContext).Concat("="));
|
||||||
|
processComments.AddRange(base.ProcessComments);
|
||||||
|
return processComments;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>Processing statistics.</summary>
|
||||||
|
public override List<StringPair> ProcessingStatistics
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
List<StringPair> stats = new List<StringPair>();
|
||||||
|
if (GetStatistic(ProcessingStatistic.CommoditiesExported) > 0) stats.Add("Commodities exported", GetStatistic(ProcessingStatistic.CommoditiesExported).ToString());
|
||||||
|
return stats;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Control values.
|
||||||
|
public static decimal ReorderPercGreen { get; } = 125.0m;
|
||||||
|
public static decimal ReorderPercRed { get; } = 75.0m;
|
||||||
|
public static decimal BudgetPercGreen { get; } = 125.0m;
|
||||||
|
public static decimal BudgetPercRed { get; } = 75.0m;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Utilities.
|
||||||
|
private void CalculateItemCount ()
|
||||||
|
{
|
||||||
|
if (Params.CommodityCountTotal >= 0 || !OK) return;
|
||||||
|
Params.CommodityCountTotal = CommodityMgr.GetCommodityCount(config.CommodityParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g O p t i o n s
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public override bool HasProcessingOptions ()
|
||||||
|
{
|
||||||
|
PopulateProcessingOptionDfns();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
private void PopulateProcessingOptionDfns ()
|
||||||
|
{
|
||||||
|
if (processingOptionDfns.Count > 0) return;
|
||||||
|
if (config.ExportType == ExportType.ActualSales || config.ExportType == ExportType.ProjectedSales)
|
||||||
|
{
|
||||||
|
// Processing options - flags.
|
||||||
|
if (optionContexts_Flag.Count == 0)
|
||||||
|
{
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_MaterialCost, "IncludeCol_MaterialCost", "Include column - " + ConfigConsole.GetAttributeCaption(UserContext, SbmDbDfn.ColumnIdx.Commodity_MaterialCost, "Material cost"));
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_CostPrice, "IncludeCol_CostPrice", "Include column - " + ConfigConsole.GetAttributeCaption(UserContext, SbmDbDfn.ColumnIdx.Commodity_CostPrice, "Cost price"));
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_RetailPrice, "IncludeCol_RetailPrice", "Include column - " + ConfigConsole.GetAttributeCaption(UserContext, SbmDbDfn.ColumnIdx.Commodity_RetailPrice, "Retail price"));
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_StockCurrent, "IncludeCol_StockCurrent", "Include column - Stock: current");
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_StockAvailable, "IncludeCol_StockAvailable", "Include column - Stock: available");
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_StockDue_MonthTo03, "IncludeCol_StockDue_MonthTo03", "Include column - Stock: due to 3 months");
|
||||||
|
optionContexts_Flag.Add(ProcessOptionFlag.IncludeCol_StockDue_MonthTo06, "IncludeCol_StockDue_MonthTo06", "Include column - Stock: due to 6 months");
|
||||||
|
}
|
||||||
|
SaItemOptionDfn optionDfn = new SaItemOptionDfn();
|
||||||
|
optionDfn.Name = OptionName_Flag;
|
||||||
|
optionDfn.DisplayOptions.Contexts.AddRange(optionContexts_Flag.ToCodeDescList());
|
||||||
|
optionDfn.DisplayOptions.RequiresContext = true;
|
||||||
|
optionDfn.DisplayOptions.Values.AddRange(Sbm.ValuesYesNo);
|
||||||
|
optionDfn.DefaultValue = Sbm.ValueNo;
|
||||||
|
processingOptionDfns.Add(optionDfn);
|
||||||
|
// Item options - flags.
|
||||||
|
foreach (TypeCodeDesc optionContext_Flag in optionContexts_Flag)
|
||||||
|
{
|
||||||
|
// Ignore option if already defined.
|
||||||
|
if (processingOptions.IsOptionDefined(OptionName_Flag, optionContext_Flag.Code)) continue;
|
||||||
|
SaItemOption option = ItemOptionConsole.CreateItemOption(null, OptionName_Flag, optionContext_Flag.Code);
|
||||||
|
option.Value = Sbm.ValueNo;
|
||||||
|
processingOptions.Add(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r o c e s s i n g
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override bool Run ()
|
||||||
|
{
|
||||||
|
SetProgressInfo("Preparing to export data to Excel.");
|
||||||
|
ResetProcess();
|
||||||
|
ValidateConfig();
|
||||||
|
|
||||||
|
// ToDo Save Folder...
|
||||||
|
String saveFolder = ""; //GetOption_SaveFolder();
|
||||||
|
if (OK && !StringUtil.IsEmpty(saveFolder) && !DirectoryUtil.DirectoryExists(saveFolder))
|
||||||
|
SetProcessError("Invalid output folder specified.");
|
||||||
|
|
||||||
|
// Perform export.
|
||||||
|
if (OK)
|
||||||
|
ExportData();
|
||||||
|
|
||||||
|
SetProgressInfo("Cleaning up ...");
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override void ResetProcess ()
|
||||||
|
{
|
||||||
|
base.ResetProcess();
|
||||||
|
|
||||||
|
// Reset parameters.
|
||||||
|
Params.HomeColumn = 1;
|
||||||
|
Params.HomeRow = Params.FirstDataRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private bool ValidateConfig ()
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
|
||||||
|
// Validate environment.
|
||||||
|
if (CommodityMgr == null) return SetProcessError("Unable to initialise commodity manager");
|
||||||
|
if (ProcessMgr == null) return SetProcessError("Unable to initialise process manager");
|
||||||
|
if (ReferenceDataConsole == null) return SetProcessError("Reference data console not available");
|
||||||
|
|
||||||
|
if (config.DataFormat != DataFormatType.Excel) return SetProcessError("Only Excel export format supported.");
|
||||||
|
|
||||||
|
// Data field columns.
|
||||||
|
Params.IncludeCol_MaterialCost = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_MaterialCost)));
|
||||||
|
Params.IncludeCol_CostPrice = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_CostPrice)));
|
||||||
|
Params.IncludeCol_RetailPrice = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_RetailPrice)));
|
||||||
|
Params.IncludeCol_StockCurrent = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_StockCurrent)));
|
||||||
|
Params.IncludeCol_StockAvailable = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_StockAvailable)));
|
||||||
|
Params.IncludeCol_StockDue_3Months = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_StockDue_MonthTo03)));
|
||||||
|
Params.IncludeCol_StockDue_6Months = StringUtil.ToBool(GetProcessingOptionValue(OptionName_Flag, optionContexts_Flag.GetCodeForType(ProcessOptionFlag.IncludeCol_StockDue_MonthTo06)));
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// E x p o r t D a t a
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private bool ExportData ()
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
String fn = this.GetFn("ExportData");
|
||||||
|
String progressPrefix = "Preparing worksheet";
|
||||||
|
|
||||||
|
//String saveFolder = ""; //GetOption_SaveFolder();
|
||||||
|
|
||||||
|
// Create a new spreadsheet.
|
||||||
|
SetProgressInfo("Opening Excel application.");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (SaMsSpreadsheet spreadsheet = new SaMsSpreadsheet_POI())
|
||||||
|
{
|
||||||
|
spreadsheet.CreateWorkbook();
|
||||||
|
SetProgressInfo(progressPrefix);
|
||||||
|
spreadsheet.SetWorksheetCount(1);
|
||||||
|
OpenWorkSheet(spreadsheet, 1, "Commodities");
|
||||||
|
|
||||||
|
PrepareColumns();
|
||||||
|
|
||||||
|
// Headings.
|
||||||
|
SetProgressInfo(progressPrefix + " - Populating headings");
|
||||||
|
SaMsExcelColumnHeading_Config configHeadings = new SaMsExcelColumnHeading_Config();
|
||||||
|
configHeadings.HeadingFontSize = 10;
|
||||||
|
configHeadings.FirstHeadingRow = 1;
|
||||||
|
configHeadings.InteriorColour = ColorTranslator.ToOle(ExcelColumnHeadingColor);
|
||||||
|
configHeadings.BorderWeight = SaXlBorderWeight.Thin;
|
||||||
|
configHeadings.FreezeColumn = (uint)(displayColumns.GetPosForId(SbmCommodity.Column.Code) + 1);
|
||||||
|
spreadsheet.SetColumnHeadings(displayColumns, configHeadings);
|
||||||
|
|
||||||
|
Params.HomeColumn = configHeadings.FreezeColumn + 1;
|
||||||
|
Params.HomeRow = Params.FirstDataRow;
|
||||||
|
|
||||||
|
ExportCommoditiesToExcel(spreadsheet);
|
||||||
|
|
||||||
|
// Complete worksheet and make visible.
|
||||||
|
SetProgressInfo("Releasing document and opening Excel.");
|
||||||
|
spreadsheet.OpenWorksheet(1);
|
||||||
|
spreadsheet.SetActiveCell(Params.HomeColumn, Params.HomeRow);
|
||||||
|
//spreadsheet.MakeVisible(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Error(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
||||||
|
return SetProcessError(exc.GetType().Name + " exporting data to Excel.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private void PrepareColumns ()
|
||||||
|
{
|
||||||
|
displayColumns.Clear();
|
||||||
|
additionalQueryColumns.Clear();
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Pos));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Code, "Code", 140));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DescBrief, "Description", 240));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityCategory))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Category1_Desc));
|
||||||
|
if (UserContext.GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn.Commodity_CatalogRef))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.CatalogRef));
|
||||||
|
|
||||||
|
if (config.ExportType == ExportType.StockControl)
|
||||||
|
{
|
||||||
|
// Stock control:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Available));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderQty));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentVsReorder));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_AvailVsReorder));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesYtdCalendar));
|
||||||
|
// Stock movements by future weeks.
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week1));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week1));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week2));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week2));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week3To4));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week3To4));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week5To6));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week5To6));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week7To8));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week7To8));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week9To10));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week9To10));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week11To12));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week11To12));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week13On));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_Week13On));
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.PurchasePlanning || config.ExportType == ExportType.PurchasePlanning_ImminentStock)
|
||||||
|
{
|
||||||
|
// Purchasing planning:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesYtdCalendar));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderQty));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.StockTake_Date));
|
||||||
|
if (config.ExportType == ExportType.PurchasePlanning)
|
||||||
|
{
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Available));
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.PurchasePlanning_ImminentStock)
|
||||||
|
{
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_ImminentLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_ImminentVsReorder));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_ImminentAvailable));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_ImminentAvailVsReorder));
|
||||||
|
// Stock sold in past 12 weeks:
|
||||||
|
config.CommodityParams.ProjectedSalesFrom = DateTime.Today.StartOfWeek().IncrementDate(-12 * 7);
|
||||||
|
config.CommodityParams.StockSoldFrom = config.CommodityParams.ProjectedSalesFrom;
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesProj_Period, "Budget since " + DateUtil.Format(config.CommodityParams.ProjectedSalesFrom, "dd-MMM")));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.StockSold_Period, "Sold since " + DateUtil.Format(config.CommodityParams.StockSoldFrom, "dd-MMM")));
|
||||||
|
}
|
||||||
|
// Stock due by week from today.
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week1));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week2));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week3));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week4));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week5));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week6));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week7));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week8));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week9));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week10));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week11));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week12));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Week13On));
|
||||||
|
// Other commodity details:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Supplier_Name));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Supplier_Ref));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.MaterialCost_Fmt));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.CostPrice));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesPrice));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.RetailPrice));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.PackQtySale));
|
||||||
|
if (UserContext.GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn.Commodity_Weight))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Weight_ValueUnits));
|
||||||
|
if (UserContext.GetOwnerOption_ShowColumn(Sbm.OrgOption_ShowColumn.Commodity_PackQtySale))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.PackQtySale));
|
||||||
|
if (ConfigConsole.DisplayAttribute(UserContext, SbmDbDfn.ColumnIdx.Commodity_Volume))
|
||||||
|
{
|
||||||
|
// Aug16 Cadix Was just SbmCommodity.Column.Volume_ValueUnits
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Volume));
|
||||||
|
//displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Volume_Unit));
|
||||||
|
}
|
||||||
|
if (ConfigConsole.DisplayAttribute(UserContext, SbmDbDfn.ColumnIdx.Commodity_BoxQuantity))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.BoxQuantity_ValueUnits));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Dimensions));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityMaterial)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.MaterialDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityFinish)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.FinishDesc));
|
||||||
|
if (ConfigConsole.DisplayAttribute(UserContext, SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ICNTariffCode));
|
||||||
|
|
||||||
|
if (config.ExportType == ExportType.PurchasePlanning)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.PurchasePlanning_ImminentStock)
|
||||||
|
{
|
||||||
|
// Additional columns required for query:
|
||||||
|
additionalQueryColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel));
|
||||||
|
additionalQueryColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Due_Imminently));
|
||||||
|
// Sales budget:
|
||||||
|
if (UserContext.GetOwnerOption_AllowOption(Sbm.OrgOption_AllowOption.Commodity_SalesBudget))
|
||||||
|
{
|
||||||
|
for (int monthIdx = 0; monthIdx < 12; monthIdx++)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesProj_Jan + monthIdx)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DescDetail));
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.ActualSales)
|
||||||
|
{
|
||||||
|
// Optional columns:
|
||||||
|
if (Params.IncludeCol_MaterialCost)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.MaterialCost));
|
||||||
|
if (Params.IncludeCol_CostPrice)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.CostPrice));
|
||||||
|
if (Params.IncludeCol_RetailPrice)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.RetailPrice));
|
||||||
|
if (Params.IncludeCol_StockCurrent)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel_All));
|
||||||
|
if (Params.IncludeCol_StockAvailable)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_All));
|
||||||
|
if (Params.IncludeCol_StockDue_3Months)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_MonthTo03));
|
||||||
|
if (Params.IncludeCol_StockDue_6Months)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_MonthTo06));
|
||||||
|
// Standard columns:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderQty));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesProj_Annual));
|
||||||
|
|
||||||
|
// Derive appropriate columns for the current month and previous 11 months.
|
||||||
|
int iMonthCount = 0;
|
||||||
|
for (DateTime columnDate = DateTime.Today.StartOfMonth(); iMonthCount < 12; columnDate.EndOfMonth().IncrementDate(1), iMonthCount++)
|
||||||
|
{
|
||||||
|
// Actual sales.
|
||||||
|
if (iMonthCount == 0)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesMonthCurrent, "Sales " + DateUtil.Format(columnDate, "MMM-yy")));
|
||||||
|
else if (iMonthCount <= 12)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesMonthPast01 + iMonthCount - 1), "Sales " + DateUtil.Format(columnDate, "MMM-yy")));
|
||||||
|
// Sales budget.
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesProj_Jan + columnDate.Month - 1), "Budget " + DateUtil.Format(columnDate, "MMM-yy")));
|
||||||
|
}
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesYtdCalendar));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesPyCalendar));
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.ProjectedSales)
|
||||||
|
{
|
||||||
|
// Optional columns:
|
||||||
|
if (Params.IncludeCol_MaterialCost)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.MaterialCost));
|
||||||
|
if (Params.IncludeCol_CostPrice)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.CostPrice));
|
||||||
|
if (Params.IncludeCol_RetailPrice)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.RetailPrice));
|
||||||
|
if (Params.IncludeCol_StockCurrent)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel_All));
|
||||||
|
if (Params.IncludeCol_StockAvailable)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated_All));
|
||||||
|
if (Params.IncludeCol_StockDue_3Months)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_MonthTo03));
|
||||||
|
if (Params.IncludeCol_StockDue_6Months)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_MonthTo06));
|
||||||
|
// Fixed columns:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderLevel));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderQty));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesProj_Annual));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel));
|
||||||
|
|
||||||
|
// 'Purchase budget' to be total of the proposed 'planned' status for containers.
|
||||||
|
// For each month: Projected sales, Due in, End of month stock:
|
||||||
|
int iMonthCount = 0;
|
||||||
|
for (DateTime columnDate = DateTime.Today.StartOfMonth(); iMonthCount < 12; columnDate.EndOfMonth().IncrementDate(1), iMonthCount++)
|
||||||
|
{
|
||||||
|
// Projected sales:
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesProj_Jan + columnDate.Month - 1), "Sales " + DateUtil.Format(columnDate, "MMM-yy")));
|
||||||
|
|
||||||
|
// Allocations - to be queried to check whether they are greater than the budget:
|
||||||
|
if (iMonthCount <= 12) // Allows for current month and up to 12 in the future.
|
||||||
|
{
|
||||||
|
additionalQueryColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.Stock_Allocated_MonthCurrent + iMonthCount)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Due in:
|
||||||
|
if (iMonthCount <= 12) // Allows for current month and up to 12 in the future.
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.Stock_DueIn_MonthCurrent + iMonthCount)));
|
||||||
|
|
||||||
|
// End of month stock:
|
||||||
|
if (iMonthCount <= 12) // Allows for current month and up to 12 in the future.
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.Stock_EndOfMonth_Current + iMonthCount)));
|
||||||
|
}
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_DueIn_Provisional));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Standard column list.
|
||||||
|
if (ConfigConsole.DisplayAttribute(UserContext, SbmDbDfn.ColumnIdx.Commodity_DrawingIssue))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DrawingIssue));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Status_Current_X));
|
||||||
|
// Only show 'Type' column if type not selected:
|
||||||
|
if (config.CommodityParams.CommodityType <= 0)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Type_Desc));
|
||||||
|
if (ConfigConsole.AllowOption(UserContext, Sbm.ConfigOption.CommodityExclusiveToCustomer))
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Customer_Name));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SalesPrice));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityRange)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.RangeDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityColour)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ColourDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommoditySource)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SourceDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommoditySupplyMethod)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.SupplyMethodDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityHandling)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.HandlingDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityDelivery)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DeliveryDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityMaterial)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.MaterialDesc));
|
||||||
|
if (CommodityMgr.CodeTypeHasCodes(Sbm.ApplCodeType.CommodityFinish)) displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.FinishDesc));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.CostPrice));
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Supplier_Name));
|
||||||
|
//displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.UnitOfSale));
|
||||||
|
//displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.TaxCode));
|
||||||
|
//displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.TaxRate));
|
||||||
|
if (Params.CommodityProcessesExist)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Process_Count));
|
||||||
|
}
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Notes));
|
||||||
|
if (DebugMode)
|
||||||
|
displayColumns.Add(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Id));
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private class ProjectedSalesData
|
||||||
|
{
|
||||||
|
public void Clear ()
|
||||||
|
{
|
||||||
|
SalesBudget = 0.0m;
|
||||||
|
Allocated = 0.0m;
|
||||||
|
ProjectedSales = DueIn = 0.0m;
|
||||||
|
EndOfMonth = 0.0m;
|
||||||
|
}
|
||||||
|
public decimal SalesBudget { get; set; }
|
||||||
|
public decimal Allocated { get; set; }
|
||||||
|
public decimal ProjectedSales { get; set; }
|
||||||
|
public decimal DueIn { get; set; }
|
||||||
|
public decimal EndOfMonth { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// E x p o r t C o m m o d i t i e s T o E x c e l
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private bool ExportCommoditiesToExcel (SaMsSpreadsheet spreadsheet)
|
||||||
|
{
|
||||||
|
if (!OK) return false;
|
||||||
|
String fn = this.GetFn("ExportCommoditiesToExcel");
|
||||||
|
String progressPrefix = "Exporting commodities";
|
||||||
|
SetProgressInfo(progressPrefix + " - Preparing data");
|
||||||
|
|
||||||
|
// Projected sales.
|
||||||
|
ProjectedSalesData[] projectedSales = new ProjectedSalesData [12];
|
||||||
|
for (int projectedSaleIdx = 0; projectedSaleIdx < projectedSales.Length; projectedSaleIdx++)
|
||||||
|
projectedSales[projectedSaleIdx] = new ProjectedSalesData();
|
||||||
|
decimal[]projectedSalesBudget = new decimal[12];
|
||||||
|
|
||||||
|
// Columns to query.
|
||||||
|
List<ColumnDfn> queryColumns = new List<ColumnDfn> (displayColumns);
|
||||||
|
foreach (ColumnDfn column in additionalQueryColumns)
|
||||||
|
{
|
||||||
|
if (!queryColumns.HasId(column.Id))
|
||||||
|
queryColumns.Add(column);
|
||||||
|
}
|
||||||
|
bool bHasProjSalesData = queryColumns.HasId(SbmCommodity.Column.SalesProj_Jan);
|
||||||
|
|
||||||
|
// Common column data names.
|
||||||
|
String col_Code = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Code).DataName;
|
||||||
|
String col_Status = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Status).DataName;
|
||||||
|
String col_DescDetail = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.DescDetail).DataName;
|
||||||
|
String col_Notes = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Notes).DataName;
|
||||||
|
String col_Type = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Type_Desc).DataName;
|
||||||
|
String col_LastStockTake = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.StockTake_Date).DataName;
|
||||||
|
String col_CurrentLevel = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel).DataName;
|
||||||
|
String col_DueImminently = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Due_Imminently).DataName;
|
||||||
|
String col_ReorderLevel = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.ReorderLevel).DataName;
|
||||||
|
String col_TotalAllocated = CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_Allocated).DataName;
|
||||||
|
|
||||||
|
// Progress is refreshed every few rows.
|
||||||
|
long commodityCount = 0;
|
||||||
|
Params.CommodityCountTotal = CommodityMgr.GetCommodityCount(config.CommodityParams);
|
||||||
|
int progressRefreshRows = (int)Math.Max(5,Params.CommodityCountTotal/(Params.CommodityCountTotal>1000?1000:100));
|
||||||
|
|
||||||
|
using (DbResultSet resultSet = CommodityMgr.ExecuteCommodityQuery(queryColumns, config.CommodityParams))
|
||||||
|
{
|
||||||
|
if (resultSet.HasErrorState()) return SetProcessError(resultSet.ErrorState.Message);
|
||||||
|
if (resultSet == null) return SetProcessError("Failed to query commodity data");
|
||||||
|
while (OK && resultSet != null && resultSet.NextRecord())
|
||||||
|
{
|
||||||
|
if (++commodityCount % progressRefreshRows == 0 || commodityCount == 1)
|
||||||
|
SetProgressInfo(progressPrefix + " - Populating data" + (Params.CommodityCountTotal > 0 ? " [" + (commodityCount * 100.0 / Params.CommodityCountTotal).ToString("N0") + "%]" : ""));
|
||||||
|
NamedValue.Map values = resultSet.GetRecordValues();
|
||||||
|
uint iRow = (uint)(Params.FirstDataRow + commodityCount - 1);
|
||||||
|
|
||||||
|
String commodityCode = values.GetValue(col_Code).ToString();
|
||||||
|
|
||||||
|
if (config.ExportType == ExportType.ProjectedSales)
|
||||||
|
{
|
||||||
|
// For each month: Projected sales, Due in, End of month stock:
|
||||||
|
for (int monthIdx = 0; monthIdx < 12; monthIdx++)
|
||||||
|
{
|
||||||
|
DateTime monthDate = DateTime.Today.StartOfMonth().IncrementMonth(monthIdx);
|
||||||
|
ProjectedSalesData projSales = projectedSales[monthIdx];
|
||||||
|
projSales.Clear();
|
||||||
|
projSales.SalesBudget = values.GetDecimal(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesProj_Jan + monthDate.Month - 1)).DataName);
|
||||||
|
projSales.Allocated = values.GetDecimal(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.Stock_Allocated_MonthCurrent + monthIdx)).DataName);
|
||||||
|
projSales.ProjectedSales = Math.Max(projSales.SalesBudget, projSales.Allocated);
|
||||||
|
projSales.DueIn = values.GetDecimal(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.Stock_DueIn_MonthCurrent + monthIdx)).DataName);
|
||||||
|
projSales.EndOfMonth = monthIdx > 0 ? projectedSales[monthIdx - 1].EndOfMonth : values.GetDecimal(CommodityMgr.GetCommodityColumnDfn(SbmCommodity.Column.Stock_CurrentLevel).DataName);
|
||||||
|
projSales.EndOfMonth += projSales.DueIn - projSales.ProjectedSales;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Retrieve budget sales figures by calendar month.
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
projectedSalesBudget[i] = bHasProjSalesData ? values.GetDecimal(CommodityMgr.GetCommodityColumnDfn((SbmCommodity.Column)(SbmCommodity.Column.SalesProj_Jan + i)).DataName) : 0.0m;
|
||||||
|
|
||||||
|
// Common values used in calculations.
|
||||||
|
// Currently in stock.
|
||||||
|
decimal currentStock = !col_CurrentLevel.IsEmpty() ? values.GetDecimal(col_CurrentLevel) : 0.0m;
|
||||||
|
// Stock due imminently.
|
||||||
|
decimal imminentStock = Math.Max(0.0m, !col_DueImminently.IsEmpty() ? values.GetDecimal(col_DueImminently) : 0.0m);
|
||||||
|
decimal reorderLevel = !col_ReorderLevel.IsEmpty() ? values.GetDecimal(col_ReorderLevel) : 0.0m;
|
||||||
|
decimal allocatedStock = !col_TotalAllocated.IsEmpty() ? values.GetDecimal(col_TotalAllocated) : 0.0m;
|
||||||
|
decimal availableStock = currentStock - allocatedStock;
|
||||||
|
|
||||||
|
// Output the value for each column in turn.
|
||||||
|
List<DataValue> cellValues = new List<DataValue>();
|
||||||
|
for (int columnIdx = 0; columnIdx < displayColumns.Count; columnIdx++)
|
||||||
|
{
|
||||||
|
ColumnDfn column = displayColumns[columnIdx];
|
||||||
|
SaMsExcelItemAttr attrCell = new SaMsExcelItemAttr();
|
||||||
|
bool cellAttributesPopulated = false;
|
||||||
|
|
||||||
|
// Intercept specific values.
|
||||||
|
DataValue value = new DataValue();
|
||||||
|
if (column.Id == (int)SbmCommodity.Column.Pos)
|
||||||
|
{
|
||||||
|
value = new DataValue("'" + commodityCount + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Status_Current_X)
|
||||||
|
{
|
||||||
|
String statusCode = values.GetString(col_Status);
|
||||||
|
if (SacsSystem.GetStatusForCode(statusCode) != SaStatus.Current)
|
||||||
|
{
|
||||||
|
value = new DataValue("X");
|
||||||
|
attrCell.Bold = true;
|
||||||
|
attrCell.FontColourIndex = SaXlColourIndex.Red;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// Stock take:
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.StockTake_Date)
|
||||||
|
{
|
||||||
|
value = values.GetValue(col_LastStockTake);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// Stock levels:
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_Available)
|
||||||
|
{
|
||||||
|
value = new DataValue(availableStock);
|
||||||
|
if (availableStock < -0.001m)
|
||||||
|
{
|
||||||
|
attrCell.Bold = true;
|
||||||
|
attrCell.FontColourIndex = SaXlColourIndex.Red; //38; // Pale red (pink).
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_CurrentVsReorder)
|
||||||
|
{
|
||||||
|
decimal currentPropReorder = (reorderLevel > 0.0m ? currentStock * 100.0m / reorderLevel : 0.0m);
|
||||||
|
value = new DataValue(currentPropReorder);
|
||||||
|
}
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_AvailVsReorder)
|
||||||
|
{
|
||||||
|
decimal availPropReorder = (reorderLevel > 0.0m ? Math.Max(0,availableStock) * 100.0m / reorderLevel : 0.0m);
|
||||||
|
value = new DataValue(availPropReorder);
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// Stock levels taking imminent stock into account:
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_ImminentLevel)
|
||||||
|
{
|
||||||
|
value = new DataValue(currentStock + imminentStock);
|
||||||
|
}
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_ImminentAvailable)
|
||||||
|
{
|
||||||
|
decimal imminentAvailable = Math.Max(0, (currentStock + imminentStock) - allocatedStock);
|
||||||
|
value = new DataValue(imminentAvailable);
|
||||||
|
}
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_ImminentVsReorder)
|
||||||
|
{
|
||||||
|
decimal imminentPropReorder = (reorderLevel > 0.0m ? (currentStock + imminentStock) * 100.0m / reorderLevel : 0.0m);
|
||||||
|
value = new DataValue(imminentPropReorder);
|
||||||
|
}
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.Stock_ImminentAvailVsReorder)
|
||||||
|
{
|
||||||
|
if (reorderLevel > 0.0m)
|
||||||
|
{
|
||||||
|
decimal imminentAvailable = Math.Max(0, (currentStock + imminentStock) - allocatedStock);
|
||||||
|
decimal imminentAvailablePropReorder = (imminentAvailable * 100.0m) / reorderLevel;
|
||||||
|
value = new DataValue(imminentAvailablePropReorder);
|
||||||
|
if (imminentAvailablePropReorder < ReorderPercRed)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Rose;
|
||||||
|
else if (imminentAvailablePropReorder < ReorderPercGreen)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Tan;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// Projected sales:
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.SalesProj_Period || column.Id == (int)SbmCommodity.Column.StockSold_Period)
|
||||||
|
{
|
||||||
|
// Calculate the projected sales for the specified period:
|
||||||
|
decimal salesProjPeriod = 0.0m;
|
||||||
|
DateTime dTo = DateTime.Today;
|
||||||
|
if (DateUtil.IsValid(config.CommodityParams.ProjectedSalesTo)) dTo = config.CommodityParams.ProjectedSalesTo;
|
||||||
|
for (DateTime d = config.CommodityParams.ProjectedSalesFrom; DateUtil.IsValid(d) && d <= dTo; d.IncrementDate(1))
|
||||||
|
{
|
||||||
|
decimal salesProjMonth = projectedSalesBudget[d.Month-1];
|
||||||
|
salesProjPeriod += salesProjMonth / d.EndOfMonth().Day;
|
||||||
|
}
|
||||||
|
if (column.Id == (int)SbmCommodity.Column.SalesProj_Period)
|
||||||
|
value = new DataValue(salesProjPeriod);
|
||||||
|
else if (column.Id == (int)SbmCommodity.Column.StockSold_Period)
|
||||||
|
{
|
||||||
|
decimal stockSoldPeriod = values.GetDecimal(column.DataName);
|
||||||
|
decimal percSoldVsBudget = salesProjPeriod > 0.0m ? stockSoldPeriod / salesProjPeriod * 100.0m : 0.0m;
|
||||||
|
value = new DataValue(stockSoldPeriod);
|
||||||
|
if (percSoldVsBudget < BudgetPercRed)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Rose;
|
||||||
|
else if (percSoldVsBudget < BudgetPercGreen)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Tan;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.ProjectedSales &&
|
||||||
|
(column.Id >= (int)SbmCommodity.Column.SalesProj_Jan && column.Id <= (int)SbmCommodity.Column.SalesProj_Dec))
|
||||||
|
{
|
||||||
|
// Projected sales - the greater of either allocations or budget for the month:
|
||||||
|
int iMonth = column.Id - (int)SbmCommodity.Column.SalesProj_Jan;
|
||||||
|
if (iMonth >= 0 && iMonth <= 12)
|
||||||
|
{
|
||||||
|
ProjectedSalesData projSales = projectedSales[iMonth];
|
||||||
|
value = new DataValue(projSales.ProjectedSales);
|
||||||
|
attrCell.BorderLeft.Weight = SaXlBorderWeight.Thin;
|
||||||
|
attrCell.BorderLeft.LineStyle = SaXlLineStyle.Continuous;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.ProjectedSales &&
|
||||||
|
(column.Id >= (int)SbmCommodity.Column.Stock_EndOfMonth_Current && column.Id <= (int)SbmCommodity.Column.Stock_EndOfMonth_12))
|
||||||
|
{
|
||||||
|
// End of month projected stock level:
|
||||||
|
int iMonth = column.Id - (int)SbmCommodity.Column.Stock_EndOfMonth_Current;
|
||||||
|
if (iMonth >= 0 && iMonth <= 12)
|
||||||
|
{
|
||||||
|
ProjectedSalesData projSales = projectedSales[iMonth];
|
||||||
|
value = new DataValue(projSales.EndOfMonth);
|
||||||
|
|
||||||
|
// Check month end stock level against reorder level.
|
||||||
|
if (projSales.EndOfMonth < 0.0m)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Rose;
|
||||||
|
else if (reorderLevel > 0.0m && projSales.EndOfMonth <= reorderLevel)
|
||||||
|
attrCell.InteriorColourIndex = SaXlColourIndex.Tan;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (config.ExportType == ExportType.ProjectedSales && column.Id == (int)SbmCommodity.Column.Stock_DueIn_Provisional)
|
||||||
|
{
|
||||||
|
attrCell.BorderLeft.Weight = SaXlBorderWeight.Thin;
|
||||||
|
attrCell.BorderLeft.LineStyle = SaXlLineStyle.Continuous;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
//---------------------------------------------------------
|
||||||
|
// General cell value handling.
|
||||||
|
if (!value.IsValid())
|
||||||
|
{
|
||||||
|
value = CommodityMgr.GetCommodityDataValue(column, values);
|
||||||
|
if (!value.IsValid())
|
||||||
|
{
|
||||||
|
// General data value directly from the database:
|
||||||
|
value = values.GetValue(column.DataName);
|
||||||
|
}
|
||||||
|
if (config.ExportType == ExportType.ProjectedSales && column.Id == (int)SbmCommodity.Column.Stock_DueIn_Provisional)
|
||||||
|
{
|
||||||
|
attrCell.BorderLeft.Weight = SaXlBorderWeight.Thin;
|
||||||
|
attrCell.BorderLeft.LineStyle = SaXlLineStyle.Continuous;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!column.ShowZeroValues && value.IsNumeric() && value.ToNumeric() == 0.0)
|
||||||
|
value = new DataValue();
|
||||||
|
cellValues.Add(value);
|
||||||
|
|
||||||
|
// Populate the cell's attributes.
|
||||||
|
if (attrCell.InteriorColourIndex != SaXlColourIndex.NotSpecified)
|
||||||
|
{
|
||||||
|
attrCell.InteriorPattern = SaXlPattern.Solid;
|
||||||
|
attrCell.InteriorPatternColourIndex = SaXlColourIndex.Automatic;
|
||||||
|
cellAttributesPopulated = true;
|
||||||
|
}
|
||||||
|
if (cellAttributesPopulated)
|
||||||
|
spreadsheet.SetRangeAttr(new SaMsExcelRange(Params.FirstDataColumn + (uint)columnIdx, iRow), attrCell);
|
||||||
|
}
|
||||||
|
spreadsheet.SetRangeFormulas(new SaMsExcelRange(Params.FirstDataColumn, iRow, Params.FirstDataColumn + (uint)cellValues.Count - 1, iRow), cellValues.ToObjectList());
|
||||||
|
IncrementStatistic(ProcessingStatistic.CommoditiesExported);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,121 @@
|
|||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Reports
|
||||||
|
{
|
||||||
|
//==========================================================================
|
||||||
|
public class SbmPrinter_Footer : SacsDisposable
|
||||||
|
{
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Configuration.
|
||||||
|
public class Config
|
||||||
|
{
|
||||||
|
public Graphics Graphics { get; set; }
|
||||||
|
public Rectangle PrintArea { get; set; }
|
||||||
|
public int PageNumber { get; set; } = 0;
|
||||||
|
public int PageCount { get; set; } = 0;
|
||||||
|
public float PosY { get; set; } = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private String footerLeft = "";
|
||||||
|
// Drawing tools.
|
||||||
|
private Font fontFooter;
|
||||||
|
private Brush brushFooter = new SolidBrush(SbmReport.PrintColor);
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmPrinter_Footer ()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
// Data members.
|
||||||
|
// Drawing tools.
|
||||||
|
if (fontFooter != null) fontFooter.Dispose();
|
||||||
|
if (brushFooter != null) brushFooter.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Initialise tools.
|
||||||
|
private void InitialiseTools (Config config)
|
||||||
|
{
|
||||||
|
// Font proprtional to width of page.
|
||||||
|
float fontFooterHeight = 12.0f * (config.PrintArea.Width * 0.00080f);
|
||||||
|
if (fontFooter == null || fontFooter.Size != fontFooterHeight)
|
||||||
|
{
|
||||||
|
if (fontFooter != null) fontFooter.Dispose();
|
||||||
|
fontFooter = new Font(SbmReport.FontFamilyName, fontFooterHeight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
// Project info printing.
|
||||||
|
public void PrintFooter (Config config)
|
||||||
|
{
|
||||||
|
// Initialise tools.
|
||||||
|
InitialiseTools(config);
|
||||||
|
GraphicsUnit graphicsUnit = config.Graphics.PageUnit;
|
||||||
|
SmoothingMode smoothingMode = config.Graphics.SmoothingMode;
|
||||||
|
TextRenderingHint textRenderingHint = config.Graphics.TextRenderingHint;
|
||||||
|
|
||||||
|
// Construct footer text.
|
||||||
|
if (StringUtil.IsEmpty(footerLeft))
|
||||||
|
footerLeft = "Sarand::LogisticsMgr";
|
||||||
|
|
||||||
|
// Print footer - Format.
|
||||||
|
StringFormat footerLabelFormat = new StringFormat();
|
||||||
|
footerLabelFormat.Alignment = StringAlignment.Near;
|
||||||
|
footerLabelFormat.LineAlignment = StringAlignment.Far;
|
||||||
|
|
||||||
|
// Calculate text height to offset from bottom of page.
|
||||||
|
SizeF footerTextSize = config.Graphics.MeasureString("ABC", fontFooter);
|
||||||
|
float footerIndentX = config.PrintArea.Width * 0.02f;
|
||||||
|
float footerIndentY = config.PrintArea.Height * 0.02f;
|
||||||
|
float posYFooter = config.PrintArea.Bottom - footerIndentY;
|
||||||
|
|
||||||
|
// By default, footer wil be printed at bottom of page bounds (less a margin).
|
||||||
|
// Specific position - footer position has been stated by caling proc.
|
||||||
|
if (config.PosY > 0.0f)
|
||||||
|
{
|
||||||
|
// Footer will be printed with this position at the top.
|
||||||
|
posYFooter = config.PosY;
|
||||||
|
footerLabelFormat.LineAlignment = StringAlignment.Near;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print footer - Left.
|
||||||
|
PointF posFooterLeft = new PointF(config.PrintArea.Left + footerIndentX, posYFooter);
|
||||||
|
config.Graphics.DrawString(footerLeft, fontFooter, brushFooter, posFooterLeft, footerLabelFormat);
|
||||||
|
|
||||||
|
// Print footer - Center.
|
||||||
|
if (config.PageNumber > 0 && config.PageCount > 1)
|
||||||
|
{
|
||||||
|
String footerCenter = "Page " + config.PageNumber + (config.PageCount > 0 ? " of " + config.PageCount : "");
|
||||||
|
PointF posFooterCenter = new PointF(config.PrintArea.Left + (config.PrintArea.Width / 2.0f), posFooterLeft.Y);
|
||||||
|
footerLabelFormat.Alignment = StringAlignment.Center;
|
||||||
|
config.Graphics.DrawString(footerCenter, fontFooter, brushFooter, posFooterCenter, footerLabelFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print footer - Right.
|
||||||
|
String footerRight = "Printed: " + DateTime.Now.Format("ddd d-MMM-yyyy HH:mm");
|
||||||
|
PointF posFooterRight = new PointF(config.PrintArea.Right - footerIndentX, posFooterLeft.Y);
|
||||||
|
footerLabelFormat.Alignment = StringAlignment.Far;
|
||||||
|
config.Graphics.DrawString(footerRight, fontFooter, brushFooter, posFooterRight, footerLabelFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//==========================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,335 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Procs;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Procs;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Printing;
|
||||||
|
using System.Drawing.Text;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Procs.Reports
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmReport : SbmReport_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
public enum PrintPageResult
|
||||||
|
{
|
||||||
|
HasMorePages,
|
||||||
|
NoMorePages,
|
||||||
|
}
|
||||||
|
protected class PrintPageConfig
|
||||||
|
{
|
||||||
|
public PrintPageConfig (Graphics graphics, PageSettings pageSettings, Rectangle pageBounds, Rectangle marginBounds, int pageNumber, int pageCount)
|
||||||
|
{
|
||||||
|
// Graphics for printing to physical device (printer or print preview control).
|
||||||
|
Graphics = graphics;
|
||||||
|
// Printing configuration.
|
||||||
|
PageSettings = pageSettings;
|
||||||
|
PageBounds = pageBounds;
|
||||||
|
Bounds = marginBounds;
|
||||||
|
PixelsPerInch = new SizeF(Graphics.DpiX, Graphics.DpiY);
|
||||||
|
TabX = (int)Math.Ceiling(Bounds.Width * 0.025f);
|
||||||
|
PageNumber = pageNumber;
|
||||||
|
}
|
||||||
|
/// <summary>Current graphics for printing on page.</summary>
|
||||||
|
public Graphics Graphics { get; private set; }
|
||||||
|
/// <summary>Current page number</summary>
|
||||||
|
public int PageNumber { get; }
|
||||||
|
/// <summary>Virtual page number</summary>
|
||||||
|
public int PageNumberVirtual { get; set; } = 1;
|
||||||
|
/// <summary>Total number of pages</summary>
|
||||||
|
public int PageCount { get; }
|
||||||
|
/// <summary>Page settings from PrintPage event - eg. to modify page length for continuous feed.</summary>
|
||||||
|
public PageSettings PageSettings { get; }
|
||||||
|
/// <summary>Page bounds from PrintPage event - eg. to modify page length for continuous feed.</summary>
|
||||||
|
public Rectangle PageBounds { get; }
|
||||||
|
// Page bounds.
|
||||||
|
public Rectangle Bounds { get; set; }
|
||||||
|
// Pixel sizes.
|
||||||
|
public SizeF PixelsPerInch { get; }
|
||||||
|
// Horizontal printing positions.
|
||||||
|
public int PosXLeft { get { return Bounds.Left; } }
|
||||||
|
public int PosXCenter { get { return (int)(Bounds.Left + (Bounds.Width * 0.5f)); } }
|
||||||
|
public int PosXRight { get { return Bounds.Right; } }
|
||||||
|
public int TabX { get; set; }
|
||||||
|
public int[] ColsX { get; set; }
|
||||||
|
// Current vertical print position.
|
||||||
|
public int PosY { get; set; }
|
||||||
|
public int PosYBodyTop { get; set; }
|
||||||
|
public int PosYBodyBottom { get; set; }
|
||||||
|
public int PosYFooterTop { get; set; }
|
||||||
|
// Line spacing - proportional to font size.
|
||||||
|
public float HeadingTextLineSpacing { get; set; } = 1.25f;
|
||||||
|
public float IntroTextLineSpacing { get; set; } = 1.20f;
|
||||||
|
public float DetailTextLineSpacing { get; set; } = 1.15f;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Configuration.
|
||||||
|
public new class Config : SbmReport_Base.Config
|
||||||
|
{
|
||||||
|
protected Config (SbmUserContext userContext) :
|
||||||
|
base(userContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
protected SbmSystem system = SbmGlobals.System;
|
||||||
|
private Config config;
|
||||||
|
/// <summary>Print mode controls whether physical printing to printer or preview control or to dummy device to determine page size.</summary>
|
||||||
|
private enum PrintMode { Physical, Virtual }
|
||||||
|
private PrintMode printMode = PrintMode.Physical;
|
||||||
|
// Printing tools.
|
||||||
|
private StringFormat stringFormat = StringFormat.GenericTypographic;
|
||||||
|
private static ColorConverter colorConverter = new ColorConverter();
|
||||||
|
private SbmPrinter_Footer footerPrinter = new SbmPrinter_Footer();
|
||||||
|
protected Brush brushBlack = new SolidBrush(Color.Black);
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
protected SbmReport (Config config) : base(config)
|
||||||
|
{
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
protected override void Dispose (bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
stringFormat.Dispose();
|
||||||
|
footerPrinter.Dispose();
|
||||||
|
brushBlack.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public static String FontFamilyName { get; } = "Arial";
|
||||||
|
public static Color PrintColor { get; } = Color.Black;
|
||||||
|
protected StringFormat StringFormat { get { return stringFormat; } }
|
||||||
|
protected static ColorConverter ColorConverter { get { return colorConverter; } }
|
||||||
|
// Report printing progress.
|
||||||
|
/// <summary>Check if currently printing to the preview device.</summary>
|
||||||
|
protected bool PreviewPrinting { get; private set; }
|
||||||
|
/// <summary>Check if the current print mode is 'Physical', ie. actually printing to the page.</summary>
|
||||||
|
protected bool PhysicalPrinting { get { return printMode == PrintMode.Physical; } }
|
||||||
|
/// <summary>Check if currently printing to file.</summary>
|
||||||
|
protected bool FilePrinting { get; private set; }
|
||||||
|
/// <summary>Total number of items to be printed</summary>
|
||||||
|
public virtual int ItemCount { get; protected set; }
|
||||||
|
/// <summary>Position of item currently being published in the list.</summary>
|
||||||
|
public virtual int ItemNumber { get; protected set; }
|
||||||
|
/// <summary>Progress based on the item being printed against the total number to be printed.</summary>
|
||||||
|
public override decimal ProgressPercent { get { return (ItemCount > 0 ? (decimal)ItemNumber / ItemCount : 0); } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Text utilities.
|
||||||
|
protected SizeF DrawString (Graphics graphics, String text, Font font, Brush brush, PointF position, StringFormat format)
|
||||||
|
{
|
||||||
|
if (!VirtualPrint)
|
||||||
|
graphics.DrawString(text, font, brush, position, format);
|
||||||
|
// Calculate size of text.
|
||||||
|
SizeF sizeText = graphics.MeasureString(text, font);
|
||||||
|
return sizeText;
|
||||||
|
}
|
||||||
|
protected SizeF DrawString (Graphics graphics, String text, Font font, Brush brush, RectangleF position, StringFormat format)
|
||||||
|
{
|
||||||
|
if (!VirtualPrint)
|
||||||
|
graphics.DrawString(text, font, brush, position, format);
|
||||||
|
// For single lines of text, the height can be different for Physical (printing) and
|
||||||
|
// Virtual (dummy) graphics even though they appear to be all but identical.
|
||||||
|
// Closest issue description: https://social.msdn.microsoft.com/Forums/windows/en-US/7a431b8c-3ad5-49d8-b012-f56a21c5cec5/measurestring-returns-different-height-after-text-width-exceeds-layout-width?forum=winforms
|
||||||
|
SizeF sizeText = graphics.MeasureString(text, font, (int)position.Width, format);
|
||||||
|
if (sizeText.Height < font.GetHeight(graphics))
|
||||||
|
// Aug-2018 Temporary fix.
|
||||||
|
sizeText.Height = font.GetHeight(graphics);
|
||||||
|
return sizeText;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Printer configuration.
|
||||||
|
public abstract void ConfigurePrinter (PageSettings pageSettings);
|
||||||
|
public abstract void ConfigurePrintPreview (PageSettings pageSettings);
|
||||||
|
public abstract void ConfigurePageMargins (PageSettings pageSettings);
|
||||||
|
protected abstract void InitDrawingTools (Graphics graphics, Rectangle bounds);
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r i n t P a g e S e c t i o n
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Solution to how to determine the number of pages in a report and
|
||||||
|
// print the report across multiple pages even though all printing is
|
||||||
|
// done via PrintPage() which prints a single page at a time.
|
||||||
|
/// <summary>
|
||||||
|
/// Print page section - portion of the report that is printed as a contiguous section, ie. all on one page.
|
||||||
|
/// <para>NB Page sections should be kept short for reports that may run over one page to ensure that the section doesn't overflow a page.</para>
|
||||||
|
/// <para>eg. A single row in a printed table with optional headings.</para>
|
||||||
|
/// <para>Method can be anonymous to allow other parameters to be passed in the context of the report's page printing, rathe rthan just relying on the Page Config.</para>
|
||||||
|
/// </summary>
|
||||||
|
protected delegate void PrintPageSectionFn ();
|
||||||
|
/// <summary> Print mode is either physical - printing to printer or preview control - or virtual - to test whether section fits on page. </summary>
|
||||||
|
protected bool VirtualPrint { get { return printMode == PrintMode.Virtual; } }
|
||||||
|
private void SwitchPrintMode (PrintMode mode, PrintPageConfig cfg)
|
||||||
|
{
|
||||||
|
printMode = mode;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Test print the page section to verify that it fits on the page, before printing to the physical device.
|
||||||
|
/// <para>Returns false if section doesn't fit on the page.</para>
|
||||||
|
/// </summary>
|
||||||
|
protected bool PrintPageSectionIfSpace (PrintPageConfig cfg, PrintPageSectionFn printPageSectionFn)
|
||||||
|
{
|
||||||
|
// Make a note of the current print position and test print the section to the virtual page.
|
||||||
|
int posYInitial = cfg.PosY;
|
||||||
|
SwitchPrintMode(PrintMode.Virtual, cfg);
|
||||||
|
printPageSectionFn();
|
||||||
|
// Check if the section fits on the page.
|
||||||
|
if (cfg.PosY >= cfg.PosYBodyBottom)
|
||||||
|
{
|
||||||
|
// If the virtual page is the same or greater (shouldn't happen)
|
||||||
|
// than the current page, a new page is required.
|
||||||
|
if (cfg.PageNumberVirtual >= cfg.PageNumber)
|
||||||
|
{
|
||||||
|
SwitchPrintMode(PrintMode.Physical, cfg);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Otherwise, we can increment the virtual page and reset printing to the top before reprinting the section.
|
||||||
|
cfg.PageNumberVirtual++;
|
||||||
|
cfg.PosY = cfg.PosYBodyTop;
|
||||||
|
if (cfg.PageNumberVirtual == cfg.PageNumber)
|
||||||
|
SwitchPrintMode(PrintMode.Physical, cfg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Section fits on virtual page.
|
||||||
|
if (cfg.PageNumberVirtual != cfg.PageNumber)
|
||||||
|
// Not yet on current page so no need to reprint section.
|
||||||
|
return true;
|
||||||
|
// On current page and section needs to be printed at original position to the physical device.
|
||||||
|
cfg.PosY = posYInitial;
|
||||||
|
SwitchPrintMode(PrintMode.Physical, cfg);
|
||||||
|
}
|
||||||
|
printPageSectionFn();
|
||||||
|
SwitchPrintMode(PrintMode.Physical, cfg);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// P r i n t i n g
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public virtual void BeginPrint (PrintAction printAction, int pageNumberFrom = 0, int pageNumberTo = 0)
|
||||||
|
{
|
||||||
|
String fn = GetType().Name + ".BeginPrint";
|
||||||
|
if (DebugMode) SaLogger.Debug(fn + " PrintAction: " + printAction + ". Page range: " + pageNumberFrom + "-" + pageNumberTo + ". Page count: " + PageCount);
|
||||||
|
PageNumberFrom = PageNumberFrom;
|
||||||
|
PageNumberTo = pageNumberTo;
|
||||||
|
PageNumber = Math.Max(1, pageNumberFrom) - 1;
|
||||||
|
ItemCount = 0;
|
||||||
|
ItemNumber = 0;
|
||||||
|
PreviewPrinting = printAction == PrintAction.PrintToPreview;
|
||||||
|
FilePrinting = printAction == PrintAction.PrintToFile;
|
||||||
|
}
|
||||||
|
public virtual void QueryPageSettings (PageSettings pageSettings, PrintAction printAction) { }
|
||||||
|
public PrintPageResult PrintPage (Graphics graphics, PageSettings pageSettings, Rectangle pageBounds, Rectangle marginBounds)
|
||||||
|
{
|
||||||
|
String fn = GetType().Name + ".PrintPage";
|
||||||
|
PageNumber++;
|
||||||
|
|
||||||
|
// Configure graphics for printing document.
|
||||||
|
// NB Graphics properties set here muust also be copied to virtual device graphics in PrintPageConfig above.
|
||||||
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
|
||||||
|
InitDrawingTools(graphics, marginBounds);
|
||||||
|
// Configure default String Format.
|
||||||
|
StringFormat.Alignment = StringAlignment.Near;
|
||||||
|
StringFormat.LineAlignment = StringAlignment.Near;
|
||||||
|
StringFormat.FormatFlags = StringFormatFlags.FitBlackBox | StringFormatFlags.LineLimit | StringFormatFlags.NoClip /*| StringFormatFlags.NoWrap */;
|
||||||
|
StringFormat.Trimming = StringTrimming.Character;
|
||||||
|
|
||||||
|
// Page configuration.
|
||||||
|
PrintPageConfig cfg = new PrintPageConfig(graphics, pageSettings, pageBounds, marginBounds, PageNumber, PageCount);
|
||||||
|
cfg.Bounds = marginBounds;
|
||||||
|
cfg.PosY = marginBounds.Top;
|
||||||
|
cfg.PosYBodyTop = marginBounds.Top;
|
||||||
|
cfg.PosYBodyBottom = marginBounds.Bottom;
|
||||||
|
if (DebugMode) SaLogger.Debug(fn + " Page: " + PageNumber);
|
||||||
|
SwitchPrintMode(PrintMode.Physical, cfg);
|
||||||
|
|
||||||
|
// Log print configuration.
|
||||||
|
if (SbmGlobals.System.IsExtendedLogging(SbmSystem.ExtendedLogginOption.Printing))
|
||||||
|
LogPageSettings(graphics, pageSettings, pageBounds, marginBounds);
|
||||||
|
|
||||||
|
// Print page and interpret result.
|
||||||
|
PrintPageResult printPageResult = PrintPage(cfg);
|
||||||
|
// Update page range information depending on whether this is the last page in the report.
|
||||||
|
if (printPageResult == PrintPageResult.HasMorePages)
|
||||||
|
{
|
||||||
|
PageNumberMaxKnown = Math.Max(PageNumberMaxKnown, PageNumber + 1);
|
||||||
|
}
|
||||||
|
else if (printPageResult == PrintPageResult.NoMorePages)
|
||||||
|
{
|
||||||
|
PageNumberMaxKnown = PageNumber;
|
||||||
|
PageCount = PageNumber;
|
||||||
|
}
|
||||||
|
// Always return 'No more pages' if finished printing page range.
|
||||||
|
if (PageNumberTo > 0 && PageNumber + 1 > PageNumberTo) return PrintPageResult.NoMorePages;
|
||||||
|
return printPageResult;
|
||||||
|
}
|
||||||
|
protected abstract PrintPageResult PrintPage (PrintPageConfig cfg);
|
||||||
|
public virtual void EndPrint (PrintAction printAction) { }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected void LogPageSettings (Graphics graphics, PageSettings pageSettings, Rectangle pageBounds, Rectangle marginBounds)
|
||||||
|
{
|
||||||
|
// Log print configuration.
|
||||||
|
List<StringPair> info = new List<StringPair>();
|
||||||
|
// Color=True, Landscape=False, Margins=[Margins Left=36 Right=36 Top=36 Bottom=36], PaperSize=[PaperSize Custom Kind=Custom Height=3600 Width=1800], PaperSource=[PaperSource unknown Kind=FormSource], PrinterResolution=[PrinterResolution X=600 Y=600]]
|
||||||
|
info.Add("Bounds", pageSettings.Bounds.ToString());
|
||||||
|
info.Add("Color", pageSettings.Color.ToString());
|
||||||
|
info.Add("Landscape", pageSettings.Landscape.ToString());
|
||||||
|
info.Add("Margins", pageSettings.Margins.ToString());
|
||||||
|
info.Add("PaperSize", pageSettings.PaperSize.ToString());
|
||||||
|
info.Add("PaperSource", pageSettings.PaperSource.ToString());
|
||||||
|
info.Add("PrintableArea", pageSettings.PrintableArea.ToString());
|
||||||
|
info.Add("PrinterResolution", pageSettings.PrinterResolution.ToString());
|
||||||
|
SaLogger.Info(GetType().Name + "Report: " + Caption + ". Page settings" + (PreviewPrinting ? " [preview]:" : "\n\tPrinter: " + pageSettings.PrinterSettings.PrinterName) + "\n\tPage bounds: " + pageBounds + "\n\tMargin bounds: " + marginBounds + "\n\tPage settings:" + info.Concat(": ").Concat("", "\n\t\t"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// H e a d e r a n d F o o t e r
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected virtual void PrintHeader (PrintPageConfig cfg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Printing - Footer.
|
||||||
|
protected virtual void PrintFooter (PrintPageConfig cfg)
|
||||||
|
{
|
||||||
|
// Print footer - Format.
|
||||||
|
SbmPrinter_Footer.Config footerConfig = new SbmPrinter_Footer.Config();
|
||||||
|
footerConfig.Graphics = cfg.Graphics;
|
||||||
|
footerConfig.PrintArea = cfg.Bounds;
|
||||||
|
footerConfig.PosY = cfg.PosYFooterTop;
|
||||||
|
footerConfig.PageNumber = PageNumber;
|
||||||
|
footerConfig.PageCount = PageCount;
|
||||||
|
footerPrinter.PrintFooter(footerConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<RootNamespace>Sarand.BusinessMgr.Net.Core</RootNamespace>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardProc\SacsStandardProc.csproj" />
|
||||||
|
<ProjectReference Include="..\SaBusMgrStandardBase\SaBusMgrStandardBase.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Procs\DataHelpers\" />
|
||||||
|
<Folder Include="Procs\Utils\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
+9
-3
@@ -1,19 +1,25 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
|
<RootNamespace>Sarand.BusinessMgr.Net.Core</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.14" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.16" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsCoreWeb\SacsCoreWeb.csproj" />
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsCoreWeb\SacsCoreWeb.csproj" />
|
||||||
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardDbas\SacsStandardDbas.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardProc\SacsStandardProc.csproj" />
|
||||||
<ProjectReference Include="..\SaBusMgrStandardBase\SaBusMgrStandardBase.csproj" />
|
<ProjectReference Include="..\SaBusMgrStandardBase\SaBusMgrStandardBase.csproj" />
|
||||||
<ProjectReference Include="..\SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj" />
|
<ProjectReference Include="..\SaBusMgrStandardDbas\SaBusMgrStandardDbas.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Web\Core\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.Consoles;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Diary;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.IO;
|
||||||
|
using Sarand.Net.Standard.Base.ItemData;
|
||||||
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.UpdateLog;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using Sarand.Net.Standard.Dbas.Data;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmApplication_Web : SbmApplication
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
protected Sbm.InstanceType instanceType;
|
||||||
|
protected String environmentName = "";
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmApplication_Web() : base(new PropertySet())
|
||||||
|
{
|
||||||
|
WebApp = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public override SbmSystem System { get { return System_Web; } }
|
||||||
|
public SbmSystem_Web System_Web { get; protected set; }
|
||||||
|
public static SbmApplication_Web WebApp { get; private set; }
|
||||||
|
// Application instance.
|
||||||
|
public override Sbm.InstanceType InstanceType { get { return instanceType; } }
|
||||||
|
public override String EnvironmentName { get { return environmentName; } }
|
||||||
|
public bool Development { get; protected set; }
|
||||||
|
public String LoggingRootFolder { get; protected set; } = "";
|
||||||
|
// Application components.
|
||||||
|
public abstract String SessionCookieName { get; }
|
||||||
|
public virtual SbmSessionContext SessionContext { get; protected set; }
|
||||||
|
public abstract SbmSessionConfig SessionConfig { get; }
|
||||||
|
public override IDatabaseInfo CreateBusMgrDbInfo(SbmSessionContext sessionContext) { return new DbDataItem.DatabaseInfo(GetBusMgrDatabase(sessionContext)); }
|
||||||
|
// Configuration.
|
||||||
|
public IConfiguration Configuration { get; protected set; }
|
||||||
|
public IConfiguration SbmConfiguration { get; protected set; }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Logging.
|
||||||
|
protected void LogApplicationStart(String fn)
|
||||||
|
{
|
||||||
|
// Log application start.
|
||||||
|
List<StringPair> applicationParams = new List<StringPair>();
|
||||||
|
applicationParams.Add("Host", SbmSystem.ComputerName);
|
||||||
|
applicationParams.Add("Version", Sbm.Version.GetFullVersion());
|
||||||
|
applicationParams.Add("Instance", InstanceType.ToString() + (!StringUtil.IsEmpty(SessionConfig.Instance) ? " [" + SessionConfig.Instance + "]" : ""));
|
||||||
|
applicationParams.Add("Configuration", SbmSystem.DebugMode ? "Debug" : "Release");
|
||||||
|
applicationParams.Add("Environment", EnvironmentName);
|
||||||
|
applicationParams.Add("Database", SessionConfig.BusMgrDatabase.Location);
|
||||||
|
applicationParams.Add("Application root", SbmSystem.ApplicationFolder);
|
||||||
|
if (!StringUtil.IsEmpty(SessionConfig.Documents.RootFolder))
|
||||||
|
applicationParams.Add("Documents root", SessionConfig.Documents.RootFolder);
|
||||||
|
applicationParams.Add("Email context", SessionConfig.Email.Context + (!StringUtil.IsEmpty(EmailConfig.SMTP.Server) ? " [" + EmailConfig.SMTP.Server + "]" : ""));
|
||||||
|
SaLogger.Info(fn + " Application start." + applicationParams.Select(item => StringUtil.PadRight(item.Item1 + ":", 20, ' ') + item.Item2).Concat("", "\n\t"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected void InitialiseTemporaryLoggingFolder()
|
||||||
|
{
|
||||||
|
// Default logging folder - in case of startup failure.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (String folder in new String[] { @"D:\Sarand\Projects\User\AHoward\VS2017\Sbmonite\Logs" })
|
||||||
|
{
|
||||||
|
if (DirectoryUtil.DirectoryExists(folder))
|
||||||
|
{
|
||||||
|
SaLogger.LogFolder = folder;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Create consoles.
|
||||||
|
public override SbmConfigConsole CreateConfigConsole(SbmSessionContext sessionContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaDiaryConsole CreateDiaryConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaSecurityConsole CreateSecurityConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaCodeTypeConsole CreateCodeTypeConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaReferenceDataConsole CreateReferenceDataConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaItemDataConsole CreateItemDataConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaItemDocConsole CreateItemDocConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaItemOptionConsole CreateItemOptionConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaInterfaceConsole CreateInterfaceConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SaUpdateLogConsole CreateUpdateLogConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override SbmEmailConsole CreateEmailConsole(SbmUserContext userContext)
|
||||||
|
{
|
||||||
|
return new SbmEmailConsole_Web(EmailConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
using Microsoft.AspNetCore.Html;
|
||||||
|
using Microsoft.Extensions.Localization;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmLocaliser
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Localisers are supplied by derived object.
|
||||||
|
/// </summary>
|
||||||
|
protected SbmLocaliser()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public abstract IStringLocalizer MainProperties { get; }
|
||||||
|
public virtual List<IStringLocalizer> AlternativeProperties { get; } = new List<IStringLocalizer>();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Generic phrase translation.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Retrieve localised text.</summary>
|
||||||
|
public LocalizedString GetText(string key)
|
||||||
|
{
|
||||||
|
return GetText(key, new object[] { });
|
||||||
|
}
|
||||||
|
public LocalizedString GetText(string key, object param)
|
||||||
|
{
|
||||||
|
return GetText(key, new object[] { param });
|
||||||
|
}
|
||||||
|
public LocalizedString GetText(string key, object param1, object param2)
|
||||||
|
{
|
||||||
|
return GetText(key, new object[] { param1, param2 });
|
||||||
|
}
|
||||||
|
public LocalizedString GetText(string key, object[] parameters)
|
||||||
|
{
|
||||||
|
LocalizedString text = MainProperties.GetString(key, parameters);
|
||||||
|
if (text.ResourceNotFound)
|
||||||
|
{
|
||||||
|
SaLogger.Debug(GetType().Name + ".GetText Key not found: " + key);
|
||||||
|
// Look up key in alternative property files.
|
||||||
|
foreach (IStringLocalizer properties in AlternativeProperties ?? new List<IStringLocalizer>())
|
||||||
|
{
|
||||||
|
text = properties.GetString(key, parameters);
|
||||||
|
if (!text.ResourceNotFound)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Square bracket indexing.
|
||||||
|
public LocalizedString this[String key]
|
||||||
|
{
|
||||||
|
get { return GetText(key); }
|
||||||
|
}
|
||||||
|
public LocalizedString this[String key, object param]
|
||||||
|
{
|
||||||
|
get { return GetText(key, param); }
|
||||||
|
}
|
||||||
|
public LocalizedString this[String key, object param1, object param2]
|
||||||
|
{
|
||||||
|
get { return GetText(key, param1, param2); }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Localised HTML text.
|
||||||
|
/// <para>Line delimiters changed to '<br/>'.</para>
|
||||||
|
/// </summary>
|
||||||
|
public HtmlString GetHtmlText(string key, String param1 = "", String param2 = "")
|
||||||
|
{
|
||||||
|
return GetHtmlText(key, new Object[] { param1, param2 });
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Localised HTML text.
|
||||||
|
/// <para>Line delimiters changed to '<br/>'.</para>
|
||||||
|
/// </summary>
|
||||||
|
public HtmlString GetHtmlText(string key, object[] parameters)
|
||||||
|
{
|
||||||
|
LocalizedString localisedText = GetText(key, parameters);
|
||||||
|
String value = localisedText.Value;
|
||||||
|
// Replace all line delimiters.
|
||||||
|
value = value.Replace("\r\n", "\n").Replace("\n", "<br/>").Replace("\r", "<br/>");
|
||||||
|
return new HtmlString(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Localised javascript string.
|
||||||
|
/// <para>All quotes are escaped.</para>
|
||||||
|
/// </summary>
|
||||||
|
public LocalizedString GetJavascriptText(string key, String param1 = "", String param2 = "")
|
||||||
|
{
|
||||||
|
LocalizedString localisedText = GetText(key, param1, param2);
|
||||||
|
return new LocalizedString(localisedText, EscapeJavascriptText(localisedText.Value), localisedText.ResourceNotFound);
|
||||||
|
}
|
||||||
|
public String EscapeJavascriptText(string value)
|
||||||
|
{
|
||||||
|
// Escape all quotes.
|
||||||
|
value = value.Replace("'", "\\'").Replace("\"", "\\\"");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Numeric and datetime formatting
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static String DateFormat_Default { get; } = "d-MMM-yyyy";
|
||||||
|
public static String DateWithWeekdayFormat_Default { get; } = "ddd d-MMM-yyyy";
|
||||||
|
public String FormatDate(DateTime value, Boolean includeWeekday = true)
|
||||||
|
{
|
||||||
|
String dateFormat = includeWeekday ? DateWithWeekdayFormat_Default : DateFormat_Default;
|
||||||
|
return DateUtil.Format(value, dateFormat);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Specific phrase translation.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private class CodeCache
|
||||||
|
{
|
||||||
|
public List<TypeCodeDesc> affiliateTypeCodes;
|
||||||
|
// To be completed.
|
||||||
|
}
|
||||||
|
private CodeCache codes = new CodeCache();
|
||||||
|
|
||||||
|
// Status.
|
||||||
|
public String GetStatusCaption(SaStatus status)
|
||||||
|
{
|
||||||
|
// ToDo Status description localisation.
|
||||||
|
return SacsSystem.GetStatusDesc(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Affiliate Type.
|
||||||
|
public String GetAffiliateTypeTypeCaption(Sbm.AffiliateType participation)
|
||||||
|
{
|
||||||
|
if ((int)participation < 1) return "";
|
||||||
|
if (codes.affiliateTypeCodes == null)
|
||||||
|
codes.affiliateTypeCodes = SbmSystem.GetCodesOfType(null, Sbm.SystemCode.AffiliateType);
|
||||||
|
// ToDo Affiliate Type localisation.
|
||||||
|
return codes.affiliateTypeCodes.GetDescForType(participation);
|
||||||
|
}
|
||||||
|
|
||||||
|
// To be completed.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,199 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmSessionConfig
|
||||||
|
{
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private readonly List<String> environments = new List<string>();
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmSessionConfig(String context, ConfigurationSection configSection, SbmSessionConfig defaultConfig)
|
||||||
|
{
|
||||||
|
Context = context;
|
||||||
|
populateDefaults(defaultConfig);
|
||||||
|
PopulateConfig(configSection);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
private void populateDefaults(SbmSessionConfig defaultConfig)
|
||||||
|
{
|
||||||
|
if (defaultConfig == null) return;
|
||||||
|
Security.Password.MinLength = defaultConfig.Security.Password.MinLength;
|
||||||
|
Security.SignIn.KeepLoggedIn.Allowed = defaultConfig.Security.SignIn.KeepLoggedIn.Allowed;
|
||||||
|
Security.SignIn.KeepLoggedIn.CookieExpiresDays = defaultConfig.Security.SignIn.KeepLoggedIn.CookieExpiresDays;
|
||||||
|
}
|
||||||
|
private void PopulateConfig(ConfigurationSection configSection)
|
||||||
|
{
|
||||||
|
if (configSection != null)
|
||||||
|
{
|
||||||
|
// Environments.
|
||||||
|
foreach (ConfigurationSection environment in configSection.GetSection("Environments").GetChildren())
|
||||||
|
environments.Add(StringUtil.TrimAll(environment.Value));
|
||||||
|
Instance = StringUtil.OnEmpty(configSection["Instance"], Instance);
|
||||||
|
// Security.
|
||||||
|
IConfigurationSection security = configSection.GetSection("Security");
|
||||||
|
if (security.Exists())
|
||||||
|
{
|
||||||
|
// Security - Password.
|
||||||
|
IConfigurationSection securityPassword = security.GetSection("Password");
|
||||||
|
if (securityPassword.Exists())
|
||||||
|
{
|
||||||
|
Security.Password.MinLength = StringUtil.ToInt(securityPassword["MinLength"], Security.Password.MinLength);
|
||||||
|
}
|
||||||
|
// Security - Sign-Up.
|
||||||
|
IConfigurationSection securitySignUp = security.GetSection("SignUp");
|
||||||
|
if (securitySignUp.Exists())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// Security - Sign-In.
|
||||||
|
IConfigurationSection securitySignIn = security.GetSection("SignIn");
|
||||||
|
if (securitySignIn.Exists())
|
||||||
|
{
|
||||||
|
IConfigurationSection keepLoggedIn = securitySignIn.GetSection("SignIn");
|
||||||
|
if (keepLoggedIn.Exists())
|
||||||
|
{
|
||||||
|
Security.SignIn.KeepLoggedIn.Allowed = StringUtil.ToBool(StringUtil.OnEmpty(keepLoggedIn["Allowed"], Security.SignIn.KeepLoggedIn.Allowed.ToString()));
|
||||||
|
Security.SignIn.KeepLoggedIn.CookieExpiresDays = StringUtil.ToInt(keepLoggedIn["CookieExpiresDays"], Security.SignIn.KeepLoggedIn.CookieExpiresDays);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Email.
|
||||||
|
IConfigurationSection email = configSection.GetSection("Email");
|
||||||
|
if (email.Exists())
|
||||||
|
{
|
||||||
|
Email.Context = email["Context"];
|
||||||
|
PopulateEmailConfig(Email.ContactUs, email.GetSection("ContactUs"));
|
||||||
|
PopulateEmailConfig(Email.Signup_Activate, email.GetSection("Signup").GetSection("Activate"));
|
||||||
|
PopulateEmailConfig(Email.Signup_Welcome, email.GetSection("Signup").GetSection("Welcome"));
|
||||||
|
}
|
||||||
|
// Documents.
|
||||||
|
IConfigurationSection documents = configSection.GetSection("Documents");
|
||||||
|
if (documents.Exists())
|
||||||
|
{
|
||||||
|
Documents.RootFolder = StringUtil.OnEmpty(documents["RootFolder"], Documents.RootFolder);
|
||||||
|
}
|
||||||
|
// Logging.
|
||||||
|
IConfigurationSection logging = configSection.GetSection("Logging");
|
||||||
|
if (logging.Exists())
|
||||||
|
{
|
||||||
|
Logging.RootFolder = StringUtil.OnEmpty(logging["RootFolder"], Logging.RootFolder);
|
||||||
|
}
|
||||||
|
// Database.
|
||||||
|
extractDatabaseConfig(BusMgrDatabase, configSection.GetSection("CoreDatabase"));
|
||||||
|
// Variants.
|
||||||
|
foreach (ConfigurationSection variantSection in configSection.GetSection("Variants").GetChildren())
|
||||||
|
{
|
||||||
|
// Variants override selected values but must match the application root folder to identify a specific instance.
|
||||||
|
String applicationRootPath = variantSection["ApplicationRootFolder"];
|
||||||
|
if (StringUtil.IsEmpty(applicationRootPath)) continue;
|
||||||
|
if (!SbmSystem.ApplicationFolder.EqualsCI(applicationRootPath)) continue;
|
||||||
|
PopulateConfig(variantSection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void PopulateEmailConfig(EmailConfig.SpecificEmailConfig config, IConfigurationSection emailSection)
|
||||||
|
{
|
||||||
|
if (!emailSection.Exists()) return;
|
||||||
|
foreach (var addressTo in emailSection.GetSection("AddressesTo").GetChildren())
|
||||||
|
config.AddressesTo.Add(StringUtil.TrimAll(addressTo.Value));
|
||||||
|
foreach (var addressCc in emailSection.GetSection("AddressesCc").GetChildren())
|
||||||
|
config.AddressesCc.Add(StringUtil.TrimAll(addressCc.Value));
|
||||||
|
foreach (var addressBcc in emailSection.GetSection("AddressesBcc").GetChildren())
|
||||||
|
config.AddressesBcc.Add(StringUtil.TrimAll(addressBcc.Value));
|
||||||
|
}
|
||||||
|
private void extractDatabaseConfig(DatabaseConfig database, IConfigurationSection databaseSection)
|
||||||
|
{
|
||||||
|
if (!databaseSection.Exists()) return;
|
||||||
|
database.Location = StringUtil.OnEmpty(databaseSection["Location"], database.Location);
|
||||||
|
database.User = StringUtil.OnEmpty(databaseSection["User"], database.User);
|
||||||
|
database.Password = StringUtil.OnEmpty(databaseSection["Password"], database.Password);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public String Context { get; }
|
||||||
|
public List<String> Environments { get { return new List<String>(environments); } }
|
||||||
|
public String Instance { get; set; } = "";
|
||||||
|
// Security.
|
||||||
|
public class SecurityConfig
|
||||||
|
{
|
||||||
|
public class PasswordConfig
|
||||||
|
{
|
||||||
|
public int MinLength { get; set; }
|
||||||
|
}
|
||||||
|
public PasswordConfig Password { get; } = new PasswordConfig();
|
||||||
|
public class SignUpConfig
|
||||||
|
{
|
||||||
|
public class ActivationConfig
|
||||||
|
{
|
||||||
|
public int EmailLinkExpiresMins = Sbm.Config.Security.Activation.EmailLinkExpiresMins_Default;
|
||||||
|
}
|
||||||
|
public ActivationConfig Activation { get; } = new ActivationConfig();
|
||||||
|
}
|
||||||
|
public SignUpConfig SignUp { get; } = new SignUpConfig();
|
||||||
|
public class SignInConfig
|
||||||
|
{
|
||||||
|
public class PasswordRequestConfig
|
||||||
|
{
|
||||||
|
public int EmailLinkExpiresMins = Sbm.Config.Security.Activation.EmailLinkExpiresMins_Default;
|
||||||
|
}
|
||||||
|
public PasswordRequestConfig PasswordRequest { get; } = new PasswordRequestConfig();
|
||||||
|
public class KeepLoggedInConfig
|
||||||
|
{
|
||||||
|
public bool Allowed { get; set; } = Sbm.Config.Security.SignIn.KeepLoggedIn.Allowed_Default;
|
||||||
|
public int CookieExpiresDays { get; set; } = Sbm.Config.Security.SignIn.KeepLoggedIn.CookieExpiresDays_Default;
|
||||||
|
}
|
||||||
|
public KeepLoggedInConfig KeepLoggedIn { get; } = new KeepLoggedInConfig();
|
||||||
|
}
|
||||||
|
public SignInConfig SignIn { get; } = new SignInConfig();
|
||||||
|
}
|
||||||
|
public SecurityConfig Security { get; } = new SecurityConfig();
|
||||||
|
// Email.
|
||||||
|
public class EmailConfig
|
||||||
|
{
|
||||||
|
public class SpecificEmailConfig
|
||||||
|
{
|
||||||
|
public List<String> AddressesTo { get; } = new List<string>();
|
||||||
|
public List<String> AddressesCc { get; } = new List<string>();
|
||||||
|
public List<String> AddressesBcc { get; } = new List<string>();
|
||||||
|
}
|
||||||
|
public SpecificEmailConfig ContactUs { get; } = new SpecificEmailConfig();
|
||||||
|
public SpecificEmailConfig Signup_Activate { get; } = new SpecificEmailConfig();
|
||||||
|
public SpecificEmailConfig Signup_Welcome { get; } = new SpecificEmailConfig();
|
||||||
|
public String Context { get; internal set; }
|
||||||
|
}
|
||||||
|
public EmailConfig Email { get; } = new EmailConfig();
|
||||||
|
// Databases.
|
||||||
|
public class DatabaseConfig
|
||||||
|
{
|
||||||
|
public String Location { get; internal set; }
|
||||||
|
public String User { get; internal set; }
|
||||||
|
public String Password { get; internal set; }
|
||||||
|
}
|
||||||
|
public DatabaseConfig BusMgrDatabase { get; } = new DatabaseConfig();
|
||||||
|
// Documents.
|
||||||
|
public class DocumentsConfig
|
||||||
|
{
|
||||||
|
public String RootFolder { get; internal set; }
|
||||||
|
}
|
||||||
|
public DocumentsConfig Documents { get; } = new DocumentsConfig();
|
||||||
|
// Logging.
|
||||||
|
public class LoggingConfig
|
||||||
|
{
|
||||||
|
public String RootFolder { get; internal set; }
|
||||||
|
}
|
||||||
|
public LoggingConfig Logging { get; } = new LoggingConfig();
|
||||||
|
|
||||||
|
//---------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmSessionContext_Web : SbmSessionContext
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Blank construction - used for deserilisation of session data.</summary>
|
||||||
|
protected SbmSessionContext_Web(Sbm.Application application) : base(0, application) { }
|
||||||
|
public SbmSessionContext_Web(ushort sesionContextIndex, Sbm.Application application) :
|
||||||
|
base(sesionContextIndex, application)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmSessionData_Web : SbmSessionData
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Private construction - for JSON deserialisation.
|
||||||
|
protected SbmSessionData_Web(long sessionIdx, int itemIdx, SbmSessionContext sessionContext) :
|
||||||
|
base(sessionIdx, itemIdx, sessionContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmSessionData_Web(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser) :
|
||||||
|
base(sessionContext, securityItemUser, affiliateUser)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// User Context.
|
||||||
|
public SbmUserContext UserContext
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
SbmUserContext userContext = new SbmUserContext_Web(SessionContext);
|
||||||
|
return userContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Localization;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Razor;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.Middleware;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmStartup_Web
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
// Localisation.
|
||||||
|
private static RequestCulture defaultRequestCulture = new RequestCulture("en-GB", "en-GB");
|
||||||
|
private static List<CultureInfo> supportedCultures = new List<CultureInfo>
|
||||||
|
{
|
||||||
|
new CultureInfo("en-GB"),
|
||||||
|
new CultureInfo("en-US"),
|
||||||
|
new CultureInfo("en"),
|
||||||
|
new CultureInfo("fr-FR"),
|
||||||
|
new CultureInfo("fr"),
|
||||||
|
};
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmStartup_Web(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public IConfiguration Configuration { get; }
|
||||||
|
public static RequestCulture DefaultRequestCulture { get { return defaultRequestCulture; } }
|
||||||
|
public static List<CultureInfo> SupportedCultures { get { return new List<CultureInfo>(supportedCultures); } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
|
protected class ConfigureServicesConfig
|
||||||
|
{
|
||||||
|
public IServiceCollection services;
|
||||||
|
public String sessionCookieName;
|
||||||
|
public bool sessionCookieHttpOnly;
|
||||||
|
public TimeSpan sessionIdleTimeout;
|
||||||
|
}
|
||||||
|
protected void ConfigureServices(ConfigureServicesConfig config)
|
||||||
|
{
|
||||||
|
// Authentication service.
|
||||||
|
// Required to handle 'Forbidden' responses etc.
|
||||||
|
config.services
|
||||||
|
.AddAuthentication(options => {
|
||||||
|
options.DefaultAuthenticateScheme = "forbidScheme";
|
||||||
|
options.DefaultForbidScheme = "forbidScheme";
|
||||||
|
options.AddScheme<SbmAuthenticationHandler>("forbidScheme", "Handle Forbidden");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Added to support memory caching of sessions.
|
||||||
|
config.services.AddMemoryCache();
|
||||||
|
//config.services.AddDistributedMemoryCache(); - for multiple web servers.
|
||||||
|
// Online web application cookie definition.
|
||||||
|
config.services.AddSession
|
||||||
|
(options =>
|
||||||
|
{
|
||||||
|
options.Cookie.Name = config.sessionCookieName;
|
||||||
|
options.Cookie.HttpOnly = config.sessionCookieHttpOnly;
|
||||||
|
options.IdleTimeout = config.sessionIdleTimeout;
|
||||||
|
// Override cookie policy for session cookie. Ref. config.app.UseCookiePolicy()
|
||||||
|
options.Cookie.IsEssential = true;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Localisation properties folder.
|
||||||
|
String resourcesPath = "Localisation";
|
||||||
|
config.services.AddLocalization(opts => { opts.ResourcesPath = resourcesPath; });
|
||||||
|
|
||||||
|
// Modify pages during debug.
|
||||||
|
#if DEBUG
|
||||||
|
if (SbmSystem.DebugMode)
|
||||||
|
// If the following line throws an error such as:
|
||||||
|
// 'imvcbuilder' does not contain a definition for 'addrazorruntimecompilation'
|
||||||
|
// Revert the NuGet Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package
|
||||||
|
// to a previous version and then reinstal the latest version.
|
||||||
|
config.services.AddRazorPages().AddRazorRuntimeCompilation();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
config.services.AddMvc
|
||||||
|
(options =>
|
||||||
|
{
|
||||||
|
// Model binding - intercepting form values being bound to models.
|
||||||
|
options.ModelBinderProviders.Insert(0, new SbmModelBinderProvider());
|
||||||
|
// Blank form values to be populated to model as empty strings rather than null values.
|
||||||
|
options.ModelMetadataDetailsProviders.Add(new SbmMetadataProvider());
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// View and data annotation localisations.
|
||||||
|
.AddViewLocalization(
|
||||||
|
LanguageViewLocationExpanderFormat.Suffix,
|
||||||
|
opts => { opts.ResourcesPath = resourcesPath; })
|
||||||
|
.AddDataAnnotationsLocalization();
|
||||||
|
|
||||||
|
// Configure localisation middleware.
|
||||||
|
config.services.Configure<RequestLocalizationOptions>
|
||||||
|
(opts =>
|
||||||
|
{
|
||||||
|
// Default culture to use for requests.
|
||||||
|
opts.DefaultRequestCulture = DefaultRequestCulture;
|
||||||
|
// Cultures supported by the application. Formatting numbers, dates, etc.
|
||||||
|
opts.SupportedCultures = SupportedCultures;
|
||||||
|
// UI cultures supported by the application. UI strings that have been localized.
|
||||||
|
opts.SupportedUICultures = SupportedCultures;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Allows access to the HttpContext inside a service.
|
||||||
|
config.services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
protected class ConfigureConfig
|
||||||
|
{
|
||||||
|
public IApplicationBuilder app;
|
||||||
|
public IHostApplicationLifetime hostApplicationLifetime;
|
||||||
|
public IWebHostEnvironment env;
|
||||||
|
}
|
||||||
|
protected void Configure(ConfigureConfig config)
|
||||||
|
{
|
||||||
|
if (config.env.IsDevelopment())
|
||||||
|
{
|
||||||
|
config.app.UseDeveloperExceptionPage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.app.UseExceptionHandler("/Home/Error");
|
||||||
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||||
|
config.app.UseHsts();
|
||||||
|
}
|
||||||
|
|
||||||
|
config.app.UseHttpsRedirection();
|
||||||
|
config.app.UseStaticFiles();
|
||||||
|
config.app.UseCookiePolicy();
|
||||||
|
config.app.UseSession();
|
||||||
|
config.app.UseRouting();
|
||||||
|
//config.app.UseAuthorization();
|
||||||
|
config.app.UseAntiforgeryTokens();
|
||||||
|
|
||||||
|
config.app.UseEndpoints(endpoints =>
|
||||||
|
{
|
||||||
|
endpoints.MapControllerRoute(
|
||||||
|
name: "default",
|
||||||
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
});
|
||||||
|
|
||||||
|
// Application events.
|
||||||
|
// NB The shutdown events only fire if he application stops 'gracefully'.
|
||||||
|
config.hostApplicationLifetime.ApplicationStarted.Register(OnApplicationStarted);
|
||||||
|
config.hostApplicationLifetime.ApplicationStopping.Register(OnApplicationStopping);
|
||||||
|
config.hostApplicationLifetime.ApplicationStopped.Register(OnApplicationStopped);
|
||||||
|
|
||||||
|
config.app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
if (context.Request.Method.Equals(HttpMethod.Get.Method))
|
||||||
|
{
|
||||||
|
context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
|
||||||
|
{
|
||||||
|
Public = true,
|
||||||
|
MaxAge = TimeSpan.FromSeconds(10)
|
||||||
|
};
|
||||||
|
//context.Response.Headers[HeaderNames.Vary] = new string[] { "Accept-Encoding" };
|
||||||
|
}
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Application events.
|
||||||
|
private readonly static String ApplicationEventLogPrefix = "### ";
|
||||||
|
private void OnApplicationStarted()
|
||||||
|
{
|
||||||
|
SaLogger.Info(ApplicationEventLogPrefix + "Application started");
|
||||||
|
}
|
||||||
|
private void OnApplicationStopping()
|
||||||
|
{
|
||||||
|
SaLogger.Info(ApplicationEventLogPrefix + "Application stopping");
|
||||||
|
}
|
||||||
|
private void OnApplicationStopped()
|
||||||
|
{
|
||||||
|
SaLogger.Info(ApplicationEventLogPrefix + "Application stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Dbas.App;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmSystem_Web : SbmSystem_Dbas
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Static initialisation.</summary>
|
||||||
|
static SbmSystem_Web()
|
||||||
|
{
|
||||||
|
InitComputerName();
|
||||||
|
InitUserName();
|
||||||
|
InitApplicationPath();
|
||||||
|
InitApplicationFolder();
|
||||||
|
InitAssemblyBuildAt();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmSystem_Web(PropertySet properties) : base(properties)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Computer name
|
||||||
|
/// <para>Windows: System.Environment.MachineName</para>
|
||||||
|
/// <para>Web: HttpContext.Current.Server.MachineName</para>
|
||||||
|
/// <para>FQDN: System.Net.Dns.GetHostName()</para>
|
||||||
|
/// </summary>
|
||||||
|
private static void InitComputerName()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ComputerName = System.Environment.MachineName;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitComputerName Failed to initialise computer name from environment. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (StringUtil.IsEmpty(ComputerName))
|
||||||
|
ComputerName = Environment.GetEnvironmentVariable("CUMPUTERNAME") ?? Environment.GetEnvironmentVariable("HOSTNAME");
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitComputerName Failed to initialise computer name from environment variable. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>To be populated by application<para>Windows: Environment.UserName</para></summary>
|
||||||
|
private static void InitUserName()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
UserName = Environment.UserName;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitUserName Failed to initialise user name. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Application Path.
|
||||||
|
/// <para>Windows: System.Reflection.Assembly.GetEntryAssembly().Location;</para>
|
||||||
|
/// </summary>
|
||||||
|
private static void InitApplicationPath()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApplicationPath = Assembly.GetEntryAssembly().Location;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitApplicationPath Failed to initialise application path. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Application folder.
|
||||||
|
/// <para>Windows: System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);</para>
|
||||||
|
/// </summary>
|
||||||
|
private static void InitApplicationFolder()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ApplicationFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitApplicationFolder Failed to initialise application folder. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// DateTime when the executing assembly was built.
|
||||||
|
/// </summary>
|
||||||
|
private static void InitAssemblyBuildAt()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Assembly build date.
|
||||||
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
|
AssemblyBuildAt = File.GetLastWriteTime(assembly.Location);
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn("SbmSystem.InitAssemblyBuildAt Failed to initialise assembly build date. " + ExceptionUtil.GetErrorStateMessage(exc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmUserContext_Web : SbmUserContext
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data memebrs.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmUserContext_Web(SbmSessionContext sessionContext) : base(sessionContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Consoles
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmEmailConsole_Web : SbmEmailConsole
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
public SbmEmailConsole_Web(SbmEmailConfig emailConfig) :
|
||||||
|
base(emailConfig)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,523 @@
|
|||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Localization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
using Microsoft.AspNetCore.Routing;
|
||||||
|
using Microsoft.Net.Http.Headers;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Serialization;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.Models;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Diary;
|
||||||
|
using Sarand.Net.Standard.Base.Email;
|
||||||
|
using Sarand.Net.Standard.Base.Helpers;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemData;
|
||||||
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.UpdateLog;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Specialized;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Controllers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmController_Base : Controller
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private SbmInternals internals;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmController_Base(SbmLocaliser localiser)
|
||||||
|
{
|
||||||
|
Localiser = localiser;
|
||||||
|
|
||||||
|
// Initialise console (debug) logging listener.
|
||||||
|
//if (Directory.Exists(App.LoggingRootFolder) && SbmSystem.DebugMode)
|
||||||
|
// SbmConsoleListener.ConfigureDebugListener(App.LoggingRootFolder);
|
||||||
|
if (DebugMode) SaLogger.Trace(GetType().Name + ".CTR");
|
||||||
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public bool DebugMode { get; } = SacsSystem.DebugMode;
|
||||||
|
protected SbmApplication_Web App { get { return SbmApplication_Web.WebApp; } }
|
||||||
|
public SbmSessionConfig SessionConfig { get { return App.SessionConfig; } }
|
||||||
|
public SbmSessionContext SessionContext { get { return App.SessionContext; } }
|
||||||
|
public SbmUserContext UserContext { get { return SessionData.UserContext; } }
|
||||||
|
protected SbmLocaliser Localiser { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// Indicate whether session data should be stored by action.
|
||||||
|
/// <para>Any action that might modify the session data must store it.</para>
|
||||||
|
/// <para>Some actions such as scoring a password's complexity don't need to.</para>
|
||||||
|
/// </summary>
|
||||||
|
public virtual bool StoreSessionData { get; protected set; } = true;
|
||||||
|
// Culture.
|
||||||
|
private string LanguageIso2
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var feature = HttpContext.Features.Get<IRequestCultureFeature>();
|
||||||
|
return feature.RequestCulture.UICulture.TwoLetterISOLanguageName.ToLower();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Business components.
|
||||||
|
public SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(UserContext); return internals; } }
|
||||||
|
// Managers.
|
||||||
|
public SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||||
|
public SbmAssetMgr AssetMgr { get { return Internals.AssetMgr; } }
|
||||||
|
public SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||||
|
public SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||||
|
public SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||||
|
public SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||||
|
public SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||||
|
public SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||||
|
// Consoles.
|
||||||
|
public SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
||||||
|
public SaDiaryConsole DiaryConsole { get { return Internals.DiaryConsole; } }
|
||||||
|
public SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||||
|
public SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||||
|
public SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||||
|
public SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||||
|
public SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||||
|
public SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||||
|
public SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||||
|
public SaItemDataConsole ItemDataConsole { get { return Internals.ItemDataConsole; } }
|
||||||
|
// Configurations.
|
||||||
|
public SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||||
|
public SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||||
|
// System codes.
|
||||||
|
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode) { return Internals.GetCodesOfType(systemCode); }
|
||||||
|
// Email.
|
||||||
|
public SaEmailConfig EmailConfig { get { return Internals.EmailConfig; } }
|
||||||
|
public SbmEmailConsole EmailConsole { get { return Internals.EmailConsole; } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Redirection locations.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static readonly String ParamName_SessionExpired = "SessionExpired";
|
||||||
|
protected enum RedirectLocation
|
||||||
|
{
|
||||||
|
WebAppBase,
|
||||||
|
WebAppHome,
|
||||||
|
WebAppHome_SessionExpired,
|
||||||
|
}
|
||||||
|
protected String GetRedirectLocation(RedirectLocation redirectLocation)
|
||||||
|
{
|
||||||
|
string protocol = Request.Scheme;
|
||||||
|
var parameters = new RouteValueDictionary();
|
||||||
|
String homeAction = Url.Action("Index", "Home", parameters, protocol);
|
||||||
|
switch (redirectLocation)
|
||||||
|
{
|
||||||
|
case RedirectLocation.WebAppBase:
|
||||||
|
return Regex.Replace(homeAction, "\\/$", "") + "/";
|
||||||
|
case RedirectLocation.WebAppHome:
|
||||||
|
return homeAction;
|
||||||
|
case RedirectLocation.WebAppHome_SessionExpired:
|
||||||
|
// Set the session expired parameter so that the page can report it.
|
||||||
|
// NB Paramater must have a value to be included in the URL query string.
|
||||||
|
parameters.Add(ParamName_SessionExpired, "1");
|
||||||
|
return homeAction;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Action execution events.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||||
|
{
|
||||||
|
if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuting" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||||
|
|
||||||
|
// Refreh model properties.
|
||||||
|
SbmModel_Base baseModel = ViewData.Model as SbmModel_Base;
|
||||||
|
RefreshModel(baseModel);
|
||||||
|
|
||||||
|
base.OnActionExecuting(filterContext);
|
||||||
|
}
|
||||||
|
public override void OnActionExecuted(ActionExecutedContext filterContext)
|
||||||
|
{
|
||||||
|
if (DebugMode) SaLogger.Debug(GetType().Name + ".OnActionExecuted" + (ViewData.Model != null ? " Model: " + ViewData.Model : ""));
|
||||||
|
|
||||||
|
// Refreh model properties.
|
||||||
|
SbmModel_Base baseModel = ViewData.Model as SbmModel_Base;
|
||||||
|
RefreshModel(baseModel);
|
||||||
|
|
||||||
|
// Store session data if present - as potentially modfied.
|
||||||
|
if (SessionData != null)
|
||||||
|
{
|
||||||
|
// Most actions will store the session data in case it's been modified.
|
||||||
|
// Some actions (eg. score password) don't need to.
|
||||||
|
if (StoreSessionData)
|
||||||
|
{
|
||||||
|
String sessionDataJson = JsonConvert.SerializeObject(SessionData);
|
||||||
|
HttpContext.Session.Set(SessionStorage.SessionKey_SessionConfig, SessionStorage.sessionDataEncoding.GetBytes(sessionDataJson));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else HttpContext.Session.Remove(SessionStorage.SessionKey_SessionConfig);
|
||||||
|
|
||||||
|
// Response headers.
|
||||||
|
if (baseModel != null && baseModel.ProhibitCache)
|
||||||
|
{
|
||||||
|
if (Response.Headers.ContainsKey(HeaderNames.CacheControl))
|
||||||
|
Response.Headers.Remove(HeaderNames.CacheControl);
|
||||||
|
Response.Headers.Add(HeaderNames.CacheControl, "no-cache, no-store, must-revalidate");
|
||||||
|
Response.Headers.Add(HeaderNames.Pragma, "no-cache");
|
||||||
|
Response.Headers.Add(HeaderNames.Expires, "0");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
base.OnActionExecuted(filterContext);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Model.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected void RefreshModel(SbmModel_Base model)
|
||||||
|
{
|
||||||
|
if (model == null) return;
|
||||||
|
|
||||||
|
// Session data.
|
||||||
|
model.SessionData_Web = SessionData;
|
||||||
|
|
||||||
|
// Redirect locations.
|
||||||
|
model.RedirectLocation.Base = GetRedirectLocation(RedirectLocation.WebAppBase);
|
||||||
|
model.RedirectLocation.Home = GetRedirectLocation(RedirectLocation.WebAppHome);
|
||||||
|
model.RedirectLocation.Home_SessionExpired = GetRedirectLocation(RedirectLocation.WebAppHome_SessionExpired);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Parameters.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public String EncryptParameters(NameValueCollection parameters, String base64IV, String base64Key)
|
||||||
|
{
|
||||||
|
String fn = nameof(ControllerBase) + ".EncryptParameters";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Copy the list of parameters, adding a random name/value pair to randomise the encryption.
|
||||||
|
NameValueCollection parametersToEncrypt = new NameValueCollection(parameters);
|
||||||
|
// NB Range 10-189 intended to have equal chance of 2 or 3 digit number.
|
||||||
|
parametersToEncrypt.Add("!" + SacsRandomHelper.GetInt32(10, 190).ToString(), SacsRandomHelper.GetInt32(10, 190).ToString());
|
||||||
|
|
||||||
|
// Sort the keys to ensure that the random '!' param is first in the query string.
|
||||||
|
String[] paramKeys = parametersToEncrypt.AllKeys;
|
||||||
|
Array.Sort(paramKeys);
|
||||||
|
|
||||||
|
// Serialise parameters as if in a URL query string - so that they can be deserialised in DecryptParameters() below.
|
||||||
|
string queryString = String.Join("&", paramKeys.Select(a => a + "=" + HttpUtility.UrlEncode(parametersToEncrypt[a])));
|
||||||
|
String encrypted = SacsEncryptionHelper.Encrypt(queryString, base64IV, base64Key);
|
||||||
|
if (DebugMode)
|
||||||
|
{
|
||||||
|
SaLogger.Debug(fn + " Encrypted: " + encrypted);
|
||||||
|
NameValueCollection decryptedParams = DecryptParameters(encrypted, base64IV, base64Key);
|
||||||
|
}
|
||||||
|
return encrypted;
|
||||||
|
}
|
||||||
|
catch (Exception exc) { SaLogger.Warn(fn + " " + ExceptionUtil.GetErrorStateMessage(exc)); }
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
public NameValueCollection DecryptParameters(String encrypted, String base64IV, String base64Key)
|
||||||
|
{
|
||||||
|
String fn = nameof(ControllerBase) + ".DecryptParameters";
|
||||||
|
if (DebugMode) SaLogger.Debug(fn + " \n\tEncrypted: " + encrypted + "\n\tIV: " + base64IV + "\n\tKey: " + base64Key);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
String queryString = SacsEncryptionHelper.Decrypt(encrypted, base64IV, base64Key);
|
||||||
|
return HttpUtility.ParseQueryString(queryString);
|
||||||
|
}
|
||||||
|
catch (Exception exc) { SaLogger.Warn(fn + " " + ExceptionUtil.GetErrorStateMessage(exc)); }
|
||||||
|
return new NameValueCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Cookies.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Retrieve the value from the named request cookie.</summary>
|
||||||
|
public String GetRequestCookie(String key)
|
||||||
|
{
|
||||||
|
if (Request.Cookies.ContainsKey(key))
|
||||||
|
return Request.Cookies[key];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
/// <summary>Set the value against the named response cookie.</summary>
|
||||||
|
public void SetResponseCookie(string key, string value, DateTime? expiresAt = null, bool isEssential = false)
|
||||||
|
{
|
||||||
|
CookieOptions options = new CookieOptions();
|
||||||
|
options.HttpOnly = true;
|
||||||
|
options.Secure = true;
|
||||||
|
options.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Strict;
|
||||||
|
if (expiresAt.HasValue)
|
||||||
|
options.Expires = expiresAt;
|
||||||
|
if (isEssential)
|
||||||
|
options.IsEssential = true;
|
||||||
|
Response.Cookies.Append(key, value, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Session.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } }
|
||||||
|
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SbmSystem.ComputerName); } }
|
||||||
|
// Referrer.
|
||||||
|
public String Referer { get { return Request.Headers["Referer"].ToString(); } }
|
||||||
|
public bool ValidReferer { get { return !StringUtil.IsEmpty(Referer); } }
|
||||||
|
/// <summary>Store session data, eg. to start a new user session on sign-in.</summary>
|
||||||
|
protected bool SetSessionData(SbmSessionData_Web sessionData)
|
||||||
|
{
|
||||||
|
if (sessionStorage.SessionData != null) return false;
|
||||||
|
sessionStorage.SessionData = sessionData;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
protected void ClearSessionData()
|
||||||
|
{
|
||||||
|
if (HttpContext.Session.IsAvailable)
|
||||||
|
HttpContext.Session.Clear();
|
||||||
|
sessionStorage.SessionData = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Session storage.
|
||||||
|
public class SessionStorage
|
||||||
|
{
|
||||||
|
public SbmSessionData_Web SessionData { get; set; }
|
||||||
|
public static String SessionKey_SessionConfig { get; } = "SbmSessionData";
|
||||||
|
public static Encoding sessionDataEncoding { get; } = Encoding.UTF8;
|
||||||
|
//JSON Serialisation.
|
||||||
|
public class SbmSessionDataContractResolver : DefaultContractResolver
|
||||||
|
{
|
||||||
|
// To allow private properties to be deserialised.
|
||||||
|
// NB Only applies to top level properties in the serialised object.
|
||||||
|
protected override List<MemberInfo> GetSerializableMembers(Type objectType)
|
||||||
|
{
|
||||||
|
var flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
MemberInfo[] fields = objectType.GetFields(flags);
|
||||||
|
return fields
|
||||||
|
.Concat(objectType.GetProperties(flags).Where(propInfo => propInfo.CanWrite))
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||||
|
{
|
||||||
|
return base.CreateProperties(type, MemberSerialization.Fields);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static JsonSerializerSettings JsonDeserialisationSettings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
ContractResolver = new SbmSessionDataContractResolver(),
|
||||||
|
// Force all deserialised objects to be replaced - to avoid proxy lists not populating.
|
||||||
|
ObjectCreationHandling = ObjectCreationHandling.Replace
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private readonly SessionStorage sessionStorage = new SessionStorage();
|
||||||
|
protected JsonSerializerSettings SbmSessionDataJsonSerializerSettings { get { return SessionStorage.JsonDeserialisationSettings; } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public SbmSessionData_Web SessionData
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Retrieve session data if not already in controller.
|
||||||
|
if (sessionStorage.SessionData == null)
|
||||||
|
{
|
||||||
|
byte[] sessionDataBytes = null;
|
||||||
|
HttpContext.Session.TryGetValue(SessionStorage.SessionKey_SessionConfig, out sessionDataBytes);
|
||||||
|
if (sessionDataBytes != null)
|
||||||
|
{
|
||||||
|
String sessionDataJson = SessionStorage.sessionDataEncoding.GetString(sessionDataBytes);
|
||||||
|
sessionStorage.SessionData = DeserializeSessionData(sessionDataJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sessionStorage.SessionData;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(GetType().Name + ".SessionData " + exc.GetType().Name + " - " + exc.Message + exc.GetStackEntries().Concat("", "\n\t"));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected abstract SbmSessionData_Web DeserializeSessionData(String sessionDataJson);
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Ajax actions.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected static readonly Encoding ajaxResponseEncoding = Encoding.UTF8;
|
||||||
|
protected IActionResult GetAjaxResult_GoHome(AjaxResponse_Base responseData)
|
||||||
|
{
|
||||||
|
responseData.SetGoHome();
|
||||||
|
return Json(responseData);
|
||||||
|
}
|
||||||
|
protected IActionResult GetAjaxResult_InvalidSession(AjaxResponse_Base responseData)
|
||||||
|
{
|
||||||
|
responseData.SetGoHome();
|
||||||
|
return Json(responseData);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public class AjaxResponse_Base
|
||||||
|
{
|
||||||
|
// Response status.
|
||||||
|
public bool Success { get; set; } = false;
|
||||||
|
public bool Error { get; set; } = false;
|
||||||
|
public bool SessionExpired { get; protected set; } = false;
|
||||||
|
public bool GoHome { get; protected set; } = false;
|
||||||
|
public AjaxResponse_Base SetSessionExpired(String title, String text)
|
||||||
|
{
|
||||||
|
SessionExpired = true;
|
||||||
|
return SetMessage(title, text);
|
||||||
|
}
|
||||||
|
public AjaxResponse_Base SetGoHome()
|
||||||
|
{
|
||||||
|
GoHome = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
public AjaxResponse_Base SetGoHome(String title, String text)
|
||||||
|
{
|
||||||
|
GoHome = true;
|
||||||
|
return SetMessage(title, text);
|
||||||
|
}
|
||||||
|
// Message - displays alert popup.
|
||||||
|
public class MessageData
|
||||||
|
{
|
||||||
|
public String Title { get; set; }
|
||||||
|
public String Text { get; set; }
|
||||||
|
}
|
||||||
|
public MessageData Message { get; private set; }
|
||||||
|
public AjaxResponse_Base SetMessage(String title, String text)
|
||||||
|
{
|
||||||
|
if (!StringUtil.IsEmpty(text))
|
||||||
|
Message = new MessageData() { Title = title, Text = text };
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public class AjaxResponse_Data : AjaxResponse_Base
|
||||||
|
{
|
||||||
|
// Construction.
|
||||||
|
protected AjaxResponse_Data(SbmModel_Base model)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// Form data.
|
||||||
|
public class FormControlValue
|
||||||
|
{
|
||||||
|
public FormControlValue(String controlName, String value, String error)
|
||||||
|
{
|
||||||
|
ControlName = controlName;
|
||||||
|
Value = value;
|
||||||
|
Error = error;
|
||||||
|
}
|
||||||
|
public String ControlName { get; }
|
||||||
|
public String Value { get; set; }
|
||||||
|
public String Error { get; set; }
|
||||||
|
}
|
||||||
|
private readonly Dictionary<String, FormControlValue> controlValues = new Dictionary<String, FormControlValue>();
|
||||||
|
public List<FormControlValue> ControlValues { get { return controlValues.Values.ToList(); } }
|
||||||
|
public void SetControlValue(String controlName, String value, String error = null)
|
||||||
|
{
|
||||||
|
if (controlValues.ContainsKey(controlName))
|
||||||
|
{
|
||||||
|
// Modify existing entry in the list.
|
||||||
|
FormControlValue controlValue = controlValues[controlName];
|
||||||
|
if (value != null) controlValue.Value = value;
|
||||||
|
if (error != null) controlValue.Error = error;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Add new control to list.
|
||||||
|
controlValues.Add(controlName, new FormControlValue(controlName, value, error));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>Assign the error to the control by name and return this response data.</summary>
|
||||||
|
public AjaxResponse_Data SetControlError(String controlName, String error)
|
||||||
|
{
|
||||||
|
return SetControlError(controlName, error, this);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Assign the error to the control by name and return the specified value.
|
||||||
|
/// <para>- Allows alternative return values to be specified (eg. 'false') to avoid separate return statement in calling routine.</para>
|
||||||
|
/// </summary>
|
||||||
|
public T SetControlError<T>(String controlName, String error, T returnValue)
|
||||||
|
{
|
||||||
|
SetControlValue(controlName, null, error);
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
public bool HasControlErrors()
|
||||||
|
{
|
||||||
|
foreach (FormControlValue controlValue in controlValues.Values)
|
||||||
|
{
|
||||||
|
if (!StringUtil.IsEmpty(controlValue.Error)) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Notification - briefly displays after response received.
|
||||||
|
public class NotificationData
|
||||||
|
{
|
||||||
|
public String Title { get; set; }
|
||||||
|
public String Message { get; set; }
|
||||||
|
}
|
||||||
|
public NotificationData Notification { get; private set; }
|
||||||
|
public bool HasNotification { get { return Notification != null; } }
|
||||||
|
public AjaxResponse_Data SetNotification(String title, String message)
|
||||||
|
{
|
||||||
|
Notification = new NotificationData() { Title = title, Message = message };
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
// Paged data.
|
||||||
|
public class PagingData
|
||||||
|
{
|
||||||
|
public PagingData(SbmModel_Base model) :
|
||||||
|
this(model.Paging.PageNo, model.Paging.PageLength, model.Paging.ItemCount, model.Paging.ItemTotal)
|
||||||
|
{ }
|
||||||
|
public PagingData(uint pageNo, ushort pageLength, ushort itemCount, ulong itemTotal)
|
||||||
|
{
|
||||||
|
PageNo = pageNo;
|
||||||
|
PageLength = pageLength;
|
||||||
|
ItemCount = itemCount;
|
||||||
|
ItemTotal = itemTotal;
|
||||||
|
}
|
||||||
|
public bool Paged { get { return (PageNo > 0 && PageLength > 0 && ItemTotal > PageLength); } }
|
||||||
|
public uint PageNo { get; } = 0;
|
||||||
|
public ushort PageLength { get; } = 0;
|
||||||
|
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / PageLength) : 0); } }
|
||||||
|
public ushort ItemCount { get; } = 0;
|
||||||
|
public ulong ItemTotal { get; } = 0;
|
||||||
|
}
|
||||||
|
public PagingData Paging { get; private set; }
|
||||||
|
public void SetPaging(SbmModel_Base model)
|
||||||
|
{
|
||||||
|
Paging = new PagingData(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
|
using Sarand.Net.Standard.Base.Email;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public static class SbmEmailConfigHelper
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Extract the email configurations from the application settings.</summary>
|
||||||
|
public static Dictionary<String, SbmEmailConfig> ExtractEmailConfigs(IConfigurationSection emailConfigsSection)
|
||||||
|
{
|
||||||
|
Dictionary<String, SbmEmailConfig> emailConfigs = new Dictionary<String, SbmEmailConfig>();
|
||||||
|
foreach (ConfigurationSection emailConfigSection in emailConfigsSection.GetChildren())
|
||||||
|
{
|
||||||
|
if (!StringUtil.IsEmpty(emailConfigSection.Key))
|
||||||
|
emailConfigs.Add(emailConfigSection.Key, CreateEmailConfig(emailConfigSection.Key, emailConfigSection));
|
||||||
|
}
|
||||||
|
return emailConfigs;
|
||||||
|
}
|
||||||
|
private static SbmEmailConfig CreateEmailConfig(String context, ConfigurationSection emailConfigSection)
|
||||||
|
{
|
||||||
|
SbmEmailConfig emailConfig = new SbmEmailConfig(context);
|
||||||
|
if (emailConfigSection != null)
|
||||||
|
{
|
||||||
|
IConfigurationSection message = emailConfigSection.GetSection("Message");
|
||||||
|
emailConfig.Message.AddressFrom = message["AddressFrom"];
|
||||||
|
foreach (var addressBcc in message.GetSection("AddressesBcc").GetChildren())
|
||||||
|
emailConfig.Message.AddressesBcc.Add(StringUtil.TrimAll(addressBcc.Value));
|
||||||
|
IConfigurationSection smtp = emailConfigSection.GetSection("SMTP");
|
||||||
|
emailConfig.SMTP.Server = smtp["Server"];
|
||||||
|
emailConfig.SMTP.ServerPort = StringUtil.ToInt(smtp["ServerPort"]);
|
||||||
|
emailConfig.SMTP.UseSSL = StringUtil.ToBool(smtp["UseSSL"]);
|
||||||
|
IConfigurationSection send = emailConfigSection.GetSection("Send");
|
||||||
|
emailConfig.Send.Using = send["Using"];
|
||||||
|
emailConfig.Send.UserName = send["UserName"];
|
||||||
|
emailConfig.Send.Password = send["Password"];
|
||||||
|
}
|
||||||
|
return emailConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Send email.
|
||||||
|
public static bool SendEmail(SaEmailData emailData)
|
||||||
|
{
|
||||||
|
// ToDo return EmailConsole.SendEmail(emailData);
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Replace dynamic tags in email message body.
|
||||||
|
/// <para></para>
|
||||||
|
/// </summary>
|
||||||
|
public static void ReplaceDynamicEmailBodyTags(SaEmailData emailData, SbmSessionData sessionData, SbmAffiliate affiliateUser)
|
||||||
|
{
|
||||||
|
// Replace core tags, eg. main stylesheet.
|
||||||
|
// ToDo. EmailConsole.ReplaceDynamicEmailTags(emailData);
|
||||||
|
|
||||||
|
// Replace tags known to the web application.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
public static class EmailConfigList
|
||||||
|
{
|
||||||
|
public static SbmEmailConfig getConfigForSession(this List<SbmEmailConfig> emailConfigs, SbmSessionConfig sessionConfig)
|
||||||
|
{
|
||||||
|
if (sessionConfig != null && !StringUtil.IsEmpty(sessionConfig.Email.Context))
|
||||||
|
{
|
||||||
|
foreach (SbmEmailConfig emailConfig in emailConfigs)
|
||||||
|
{
|
||||||
|
if (emailConfig.Context.EqualsCI(sessionConfig.Email.Context))
|
||||||
|
return emailConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new SbmEmailConfig("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Helpers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public static class SbmSessionConfigHelper
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static Dictionary<String, SbmSessionConfig> ExtractSessionConfigs(IConfigurationSection sessionConfigsSection)
|
||||||
|
{
|
||||||
|
// NB The set of configurations will only allow one per context.
|
||||||
|
// Only the last configuration found for each context will be stored (NB usually only one of each apart from 'Defaults').
|
||||||
|
Dictionary<String, SbmSessionConfig> sessionConfigs = new Dictionary<String, SbmSessionConfig>();
|
||||||
|
|
||||||
|
// Start the list with a default 'Defaults' configuration - values set to application defaults (defined in Sbm).
|
||||||
|
// NB This can be overridden in each level of configuration.
|
||||||
|
// Settings from the 'Defaults' configuration provide values where they are missing from other configurations.
|
||||||
|
// NB Coverage may not be 100% - just where it's proven needed.
|
||||||
|
SbmSessionConfig defaultsSessionConfig = new SbmSessionConfig(Sbm.Config.Context_Defaults, null, null);
|
||||||
|
sessionConfigs.Add(defaultsSessionConfig.Context, defaultsSessionConfig);
|
||||||
|
|
||||||
|
// Load session configurations.
|
||||||
|
foreach (ConfigurationSection sessionConfigSection in sessionConfigsSection.GetChildren())
|
||||||
|
{
|
||||||
|
if (StringUtil.IsEmpty(sessionConfigSection.Key)) continue;
|
||||||
|
|
||||||
|
// Extract the configuration, supplying current 'Defaults' to supply missing values, and add to the list.
|
||||||
|
SbmSessionConfig sessionConfig = new SbmSessionConfig(sessionConfigSection.Key, sessionConfigSection, defaultsSessionConfig);
|
||||||
|
sessionConfigs.Remove(sessionConfigSection.Key);
|
||||||
|
sessionConfigs.Add(sessionConfigSection.Key, sessionConfig);
|
||||||
|
|
||||||
|
// Replace the 'Defaults' configuration if this one matches the context.
|
||||||
|
if (sessionConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||||
|
defaultsSessionConfig = sessionConfig;
|
||||||
|
}
|
||||||
|
return sessionConfigs;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
public static class SessionConfigList
|
||||||
|
{
|
||||||
|
public static SbmSessionConfig getConfigForApplication(this List<SbmSessionConfig> sessionConfigs)
|
||||||
|
{
|
||||||
|
SbmSessionConfig defaultsSessionConfig = new SbmSessionConfig("", null, null);
|
||||||
|
SbmApplication app = SbmGlobals.Application;
|
||||||
|
if (app != null)
|
||||||
|
{
|
||||||
|
foreach (SbmSessionConfig sessionConfig in sessionConfigs)
|
||||||
|
{
|
||||||
|
if (sessionConfig.Environments.ContainsCI(app.EnvironmentName))
|
||||||
|
return sessionConfig;
|
||||||
|
if (sessionConfig.Context.EqualsCI(Sbm.Config.Context_Defaults))
|
||||||
|
defaultsSessionConfig = sessionConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultsSessionConfig;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Encodings.Web;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Middleware
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
// Authentication handler required to allow actions to issue Forbid() responses.
|
||||||
|
// Ref. https://stackoverflow.com/questions/54578426/why-do-i-need-to-set-a-defaultforbidscheme/54587054#54587054
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public SbmAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) :
|
||||||
|
base(options, logger, encoder, clock)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override Task HandleForbiddenAsync(AuthenticationProperties properties)
|
||||||
|
{
|
||||||
|
Context.Response.StatusCode = (int)HttpStatusCode.Forbidden;
|
||||||
|
return base.HandleForbiddenAsync(properties);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
|
||||||
|
{
|
||||||
|
Context.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
|
||||||
|
return AuthenticateResult.NoResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Metadata;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Middleware
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Force blank form values to be populated to the model as empty strings rather than null values.
|
||||||
|
/// </summary>
|
||||||
|
public class SbmMetadataProvider : IMetadataDetailsProvider, IDisplayMetadataProvider
|
||||||
|
{
|
||||||
|
public void CreateDisplayMetadata(DisplayMetadataProviderContext context)
|
||||||
|
{
|
||||||
|
if (context.Key.MetadataKind == ModelMetadataKind.Property)
|
||||||
|
{
|
||||||
|
context.DisplayMetadata.ConvertEmptyStringToNull = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Middleware
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Maps a browser request to a data object. Default class provides a base implementation of a model binder.
|
||||||
|
/// <para>Overridden to trim whitespace from input values.</para>
|
||||||
|
/// </summary>
|
||||||
|
public class SbmModelBinder : ComplexTypeModelBinder
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmModelBinder(IDictionary<ModelMetadata, IModelBinder> propertyBinders, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) :
|
||||||
|
base(propertyBinders, loggerFactory)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Creates the model with one (or more) injected service parameters.
|
||||||
|
/// </summary>
|
||||||
|
protected override object CreateModel(ModelBindingContext bindingContext)
|
||||||
|
{
|
||||||
|
var services = bindingContext.HttpContext.RequestServices;
|
||||||
|
var modelType = bindingContext.ModelType;
|
||||||
|
var ctors = modelType.GetConstructors();
|
||||||
|
foreach (var ctor in ctors)
|
||||||
|
{
|
||||||
|
var paramTypes = ctor.GetParameters().Select(p => p.ParameterType).ToList();
|
||||||
|
var parameters = paramTypes.Select(p => services.GetService(p)).ToArray();
|
||||||
|
if (parameters.All(p => p != null))
|
||||||
|
{
|
||||||
|
var model = ctor.Invoke(parameters);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Intercept String properties and trim whitespace.
|
||||||
|
/// </summary>
|
||||||
|
protected override void SetProperty(ModelBindingContext bindingContext, string modelName, ModelMetadata propertyMetadata, ModelBindingResult result)
|
||||||
|
{
|
||||||
|
string fn = GetType().Name + ".SetProperty";
|
||||||
|
//if (SbmSystem.DebugMode) Logger.Debug(fn + " Form property " + modelName + ": '" + result.Model.ToString() + ".");
|
||||||
|
object originalValue = result.Model;
|
||||||
|
// Exclude properties that retain leading/trailing whitespace.
|
||||||
|
if (result.Model is string)
|
||||||
|
{
|
||||||
|
if (!modelName.ContainsCI("Password"))
|
||||||
|
{
|
||||||
|
string value = result.Model as string;
|
||||||
|
|
||||||
|
// Trim leading and trailing whitespace.
|
||||||
|
value = StringUtil.TrimAll(value);
|
||||||
|
|
||||||
|
// Check for multi-line.
|
||||||
|
if (value.Contains('\n'))
|
||||||
|
{
|
||||||
|
// Simplify line delimiters.
|
||||||
|
value = Regex.Replace(value, "\\r\\n", "\n");
|
||||||
|
// Remove white space in front of newlines.
|
||||||
|
value = Regex.Replace(value, "\\s+\\n", "\n");
|
||||||
|
// Remove multiple newlines.
|
||||||
|
value = Regex.Replace(value, "\\n+", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Email addresses must be lowercase to ensure match to encrypted data.
|
||||||
|
if (modelName.EqualsCI("EmailAddress") || modelName.EqualsCI("AccountEmailAddress"))
|
||||||
|
value = value.ToLower();
|
||||||
|
|
||||||
|
// Uppercase selected values.
|
||||||
|
if (modelName.EqualsCI("Postcode") || modelName.EqualsCI("AccountPostcode") || modelName.EqualsCI("RegisteredAddressPostcode"))
|
||||||
|
value = value.ToUpper();
|
||||||
|
|
||||||
|
// Assign resulting value.
|
||||||
|
result = ModelBindingResult.Success(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result.Model != null && SbmSystem.DebugMode)
|
||||||
|
SaLogger.Debug(fn + " Form property " + modelName + ": '" + result.Model.ToString() + "'." + (originalValue != null && !originalValue.Equals(result.Model) ? " Original value: '" + originalValue.ToString() + "'" : ""));
|
||||||
|
base.SetProperty(bindingContext, modelName, propertyMetadata, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Middleware
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Maps a browser request to a data object. Default class provides a base implementation of a model binder.
|
||||||
|
/// <para>Overridden to trim whitespace from input values.</para>
|
||||||
|
/// </summary>
|
||||||
|
public class SbmModelBinderProvider : IModelBinderProvider
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmModelBinderProvider()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public IModelBinder GetBinder(ModelBinderProviderContext context)
|
||||||
|
{
|
||||||
|
if (context == null) throw new ArgumentNullException(nameof(context));
|
||||||
|
|
||||||
|
if (context.Metadata.IsComplexType && !context.Metadata.IsCollectionType)
|
||||||
|
{
|
||||||
|
var propertyBinders = context.Metadata.Properties.ToDictionary(property => property, context.CreateBinder);
|
||||||
|
ILoggerFactory loggerFactory = (ILoggerFactory)context.Services.GetService(typeof(ILoggerFactory));
|
||||||
|
return new SbmModelBinder(propertyBinders, loggerFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default - return null so that default binding provider is used.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using Microsoft.AspNetCore.Antiforgery;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Middleware
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Extend IApplicationBuilder class to use the anit-forgery token validation middleware.
|
||||||
|
/// </summary>
|
||||||
|
public static class ApplicationBuilderExtensions
|
||||||
|
{
|
||||||
|
public static IApplicationBuilder UseAntiforgeryTokens(this IApplicationBuilder app)
|
||||||
|
{
|
||||||
|
return app.UseMiddleware<ValidateAntiForgeryTokenMiddleware>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Ensure relevant actions validate the anti-forgery token, eg. post requests.
|
||||||
|
/// </summary>
|
||||||
|
public class ValidateAntiForgeryTokenMiddleware
|
||||||
|
{
|
||||||
|
private readonly RequestDelegate _next;
|
||||||
|
private readonly IAntiforgery _antiforgery;
|
||||||
|
|
||||||
|
public ValidateAntiForgeryTokenMiddleware(RequestDelegate next, IAntiforgery antiforgery)
|
||||||
|
{
|
||||||
|
_next = next;
|
||||||
|
_antiforgery = antiforgery;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Invoke(HttpContext context)
|
||||||
|
{
|
||||||
|
String fn = GetType().Name + ".Invoke";
|
||||||
|
|
||||||
|
// Log action.
|
||||||
|
//String rawTarget = context.Features.Get<IHttpRequestFeature>().RawTarget;
|
||||||
|
if (SbmSystem.DebugMode) SaLogger.Debug(fn + " Action: '" + Regex.Replace(context.Request.Path.ToString(), "^/", "") + "'. Method: " + context.Request.Method);
|
||||||
|
|
||||||
|
// Intercept POST requests and apply anti-forgery test.
|
||||||
|
if (HttpMethods.IsPost(context.Request.Method))
|
||||||
|
{
|
||||||
|
await _antiforgery.ValidateRequestAsync(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _next(context);
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Warn(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
||||||
|
throw exc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
using Microsoft.AspNetCore.Html;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||||
|
using Sarand.BusinessMgr.Net.Core.Web.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Diary;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemData;
|
||||||
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.UpdateLog;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Core.Web.Models
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmModel_Base
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private SbmInternals internals;
|
||||||
|
private readonly List<String> infoMessages = new List<string>();
|
||||||
|
private readonly List<String> warningMessages = new List<string>();
|
||||||
|
private readonly List<String> errorMessages = new List<string>();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmModel_Base(SbmLocaliser localiser)
|
||||||
|
{
|
||||||
|
Localiser = localiser;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Application properties.
|
||||||
|
private SbmApplication_Web App { get { return SbmApplication_Web.WebApp; } }
|
||||||
|
protected SbmSessionConfig SessionConfig { get { return App.SessionConfig; } }
|
||||||
|
protected SbmSystem_Web System { get { return App.System_Web; } }
|
||||||
|
public String SessionCookieName { get { return App.SessionCookieName; } }
|
||||||
|
public SbmSessionData SessionData { get { return SessionData_Web; } }
|
||||||
|
public SbmSessionData_Web SessionData_Web { get; set; }
|
||||||
|
public SbmSessionContext SessionContext { get { return SessionData?.SessionContext ?? App.SessionContext; } }
|
||||||
|
public DbUpdateInfo DbUpdateInfo { get { return SessionData?.DbUpdateInfo ?? new DbUpdateInfo(null, "", SbmSystem.ComputerName); } }
|
||||||
|
public bool DebugMode { get { return SbmSystem.DebugMode; } }
|
||||||
|
public SbmLocaliser Localiser { get; }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Page configuration.
|
||||||
|
public bool OK { get { return !HasMessages(); } }
|
||||||
|
public virtual bool ProhibitCache { get; set; } = true;
|
||||||
|
public String PageCaption { get; set; }
|
||||||
|
public String InstanceVersion { get { return !StringUtil.IsEmpty(App.SessionConfig.Instance) ? App.SessionConfig.Instance + " v" + Sbm.Version.GetFullVersion() : "v" + Sbm.Version.GetAppVersion(); } }
|
||||||
|
public bool IncludeGoogleAnalytics { get; set; } = false;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Business components.
|
||||||
|
protected SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(SessionData_Web.UserContext); return internals; } }
|
||||||
|
// Managers.
|
||||||
|
public SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||||
|
public SbmAssetMgr AssetMgr { get { return Internals.AssetMgr; } }
|
||||||
|
public SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||||
|
public SbmPriceMgr PriceMgr { get { return Internals.PriceMgr; } }
|
||||||
|
public SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||||
|
public SbmStockMgr StockMgr { get { return Internals.StockMgr; } }
|
||||||
|
public SbmProcessMgr ProcessMgr { get { return Internals.ProcessMgr; } }
|
||||||
|
public SbmDataItemMgr DataItemMgr { get { return Internals.DataItemMgr; } }
|
||||||
|
// Consoles.
|
||||||
|
public SbmConfigConsole ConfigConsole { get { return Internals.ConfigConsole; } }
|
||||||
|
public SaDiaryConsole DiaryConsole { get { return Internals.DiaryConsole; } }
|
||||||
|
public SaSecurityConsole SecurityConsole { get { return Internals.SecurityConsole; } }
|
||||||
|
public SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||||
|
public SaReferenceDataConsole ReferenceDataConsole { get { return Internals.ReferenceDataConsole; } }
|
||||||
|
public SaUpdateLogConsole UpdateLogConsole { get { return Internals.UpdateLogConsole; } }
|
||||||
|
public SaInterfaceConsole InterfaceConsole { get { return Internals.InterfaceConsole; } }
|
||||||
|
public SaItemDocConsole ItemDocConsole { get { return Internals.ItemDocConsole; } }
|
||||||
|
public SaItemOptionConsole ItemOptionConsole { get { return Internals.ItemOptionConsole; } }
|
||||||
|
public SaItemDataConsole ItemDataConsole { get { return Internals.ItemDataConsole; } }
|
||||||
|
// Configurations.
|
||||||
|
public SbmStockControlConfig StockControlConfig { get { return Internals.StockControlConfig; } }
|
||||||
|
public SbmRequirementCostingConfig RequirementCostingConfig { get { return Internals.RequirementCostingConfig; } }
|
||||||
|
// System codes.
|
||||||
|
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode) { return Internals.GetCodesOfType(systemCode); }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Security.
|
||||||
|
public bool ValidUserSession { get { return SessionData?.ValidUserSession ?? false; } }
|
||||||
|
public bool AwaitingLogin { get { return !ValidUserSession; } }
|
||||||
|
public bool KeepLoggedIn { get { return !AwaitingLogin && SessionData.User.KeepLoggedIn; } }
|
||||||
|
/// <summary>Maximum length allowed for password entry: sign-up, change password etc.</summary>
|
||||||
|
public int PasswordMaxLength { get; } = 32;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Form control value max length.
|
||||||
|
/// <para>In many cases the database columns allow plenty of extra space for the value, in case they need to be encrypted.</para>
|
||||||
|
/// <para>Hence, several cases where the value entered in the control isn't allowed the full database length.</para>
|
||||||
|
/// </summary>
|
||||||
|
public int GetControlMaxLength(SbmDbDfn.ColumnIdx column)
|
||||||
|
{
|
||||||
|
int maxLength = (int)SbmDbDfn.GetColTextLen(column);
|
||||||
|
switch (column)
|
||||||
|
{
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_Email:
|
||||||
|
return Math.Min(maxLength, 60);
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_FirstName:
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_LastName:
|
||||||
|
return Math.Min(maxLength, 40);
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_Name:
|
||||||
|
return Math.Min(maxLength, 80);
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMain:
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneMobile:
|
||||||
|
case SbmDbDfn.ColumnIdx.Affiliate_PhoneAlt:
|
||||||
|
return Math.Min(maxLength, 20);
|
||||||
|
case SbmDbDfn.ColumnIdx.Address_Postcode:
|
||||||
|
return Math.Min(maxLength, 16);
|
||||||
|
}
|
||||||
|
return maxLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Copyright notice.
|
||||||
|
public HtmlString CopyrightNotice
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
int initialYear = 2020;
|
||||||
|
int currentYear = DateTime.Today.Year;
|
||||||
|
return Localiser.GetHtmlText("copyright.symbol.year.html", (initialYear != currentYear ? initialYear + "-" : "") + currentYear.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Form data - Dates.
|
||||||
|
// Format may depend on locale, but as long as these methods are used consistently,
|
||||||
|
// there should be consistent formatting, display and parsing of date values.
|
||||||
|
public String CalendarDateFormat
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// JQuery-UI DatePicker date format.
|
||||||
|
// Format:
|
||||||
|
// d Single digit day of month
|
||||||
|
// dd Double digit day of month
|
||||||
|
// D 3 letter day of week abbreviation.
|
||||||
|
// DD Day of week.
|
||||||
|
// m Single digit month.
|
||||||
|
// mm Double digit month.
|
||||||
|
// M 3 letter month abbreviation.
|
||||||
|
// MM Month name.
|
||||||
|
// yy 4 digit year.
|
||||||
|
// Examples:
|
||||||
|
// dd/mm/yy 07/04/2012
|
||||||
|
// dd-M-yy 07-Apr-2012
|
||||||
|
// d-M-yy 7-Apr-2012
|
||||||
|
return "dd-M-yy";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public String FormatDateForForm(DateTime value)
|
||||||
|
{
|
||||||
|
return DateUtil.Format(value, "dd-MMM-yyyy");
|
||||||
|
}
|
||||||
|
public DateTime ParseDateFromForm(String value)
|
||||||
|
{
|
||||||
|
return DateUtil.ParseExact(value, "dd-MMM-yyyy");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Link URLs.
|
||||||
|
public class LinksData
|
||||||
|
{
|
||||||
|
public String Facebook { get; } = "https://www.facebook.com/BusinessMgr/";
|
||||||
|
public String LinkedIn { get; } = "https://www.linkedin.com/company/BusinessMgr/about/";
|
||||||
|
}
|
||||||
|
public LinksData Links { get; } = new LinksData();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Form data.
|
||||||
|
|
||||||
|
/// <summary>List of Address Types for dropdown.</summary>
|
||||||
|
public IEnumerable<SelectListItem> AddressTypeCodesForSelect
|
||||||
|
{
|
||||||
|
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AddressType), "Code", "Desc"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>List of Affiliate Types for dropdown.</summary>
|
||||||
|
public IEnumerable<SelectListItem> AffiliateTypeCodesForSelect
|
||||||
|
{
|
||||||
|
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AffiliateType), "Code", "Desc"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>List of Association Types for dropdown.</summary>
|
||||||
|
public IEnumerable<SelectListItem> AssociationTypeCodesForSelect
|
||||||
|
{
|
||||||
|
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.AssociationType), "Code", "Desc"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>List of Commodity Types for dropdown.</summary>
|
||||||
|
public IEnumerable<SelectListItem> CommodityTypeCodesForSelect
|
||||||
|
{
|
||||||
|
get { return new SelectList(GetCodesOfType(Sbm.SystemCode.CommodityType), "Code", "Desc"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Version parameter for includes.
|
||||||
|
public String HrefVersion
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
DateTime versionDate = SbmSystem.AssemblyBuildAt;
|
||||||
|
if (!DateUtil.IsValid(versionDate) || SbmSystem.DebugMode)
|
||||||
|
versionDate = DateTime.Now;
|
||||||
|
return DateUtil.Format(versionDate, "yyyyMMdd" /*+ (SacsSystem.Debug ? "HHmm" : "")*/);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Additional includes.
|
||||||
|
public List<String> AdditionalFiles_CSS { get; set; } = new List<string>();
|
||||||
|
public List<String> AdditionalFiles_JS { get; set; } = new List<string>();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Redirection locations.
|
||||||
|
public class RedirectLocationData
|
||||||
|
{
|
||||||
|
// Properties populated in Controller_Base.OnActionExecuted.
|
||||||
|
public String Base { get; internal set; }
|
||||||
|
public String Home { get; internal set; }
|
||||||
|
public String Home_SessionExpired { get; internal set; }
|
||||||
|
}
|
||||||
|
public RedirectLocationData RedirectLocation { get; } = new RedirectLocationData();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Paging properties.
|
||||||
|
public class DataPaging
|
||||||
|
{
|
||||||
|
private DbQuery.Paging paging { get; } = new DbQuery.Paging();
|
||||||
|
public void PopulatePagingTo(DbQuery.Paging resultsPaging)
|
||||||
|
{
|
||||||
|
resultsPaging.PageLength = paging.PageLength;
|
||||||
|
resultsPaging.PageNo = paging.PageNo;
|
||||||
|
}
|
||||||
|
public bool IsPaged { get { return paging.Paged; } }
|
||||||
|
public uint PageNo { get { return paging.PageNo; } set { paging.PageNo = value; } }
|
||||||
|
public ushort PageLength { get { return paging.PageLength; } set { paging.PageLength = value; } }
|
||||||
|
public uint PageCount { get { return (PageLength > 0 ? (uint)Math.Ceiling((decimal)ItemTotal / PageLength) : 0); } }
|
||||||
|
public ushort ItemCount { get; set; }
|
||||||
|
private ulong itemTotal = 0;
|
||||||
|
public ulong ItemTotal
|
||||||
|
{
|
||||||
|
get { return itemTotal; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
itemTotal = value;
|
||||||
|
// Check whether the total number of items is less than the current page and reduce page no if needed.
|
||||||
|
if (IsPaged && (PageNo - 1) * PageLength > itemTotal)
|
||||||
|
PageNo = (uint)((itemTotal - 1) / PageLength + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public DataPaging Paging { get; } = new DataPaging();
|
||||||
|
public void PopulatePagingTo(DbQuery.Paging resultsPaging)
|
||||||
|
{
|
||||||
|
Paging.PopulatePagingTo(resultsPaging);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Form properties.
|
||||||
|
/// <summary>
|
||||||
|
/// User session index to identify the site resources, eg. database.
|
||||||
|
/// <para>Equivalent to the Site index on the login form.</para>
|
||||||
|
/// <para>Populates value on logout form to identify default site for next login.</para>
|
||||||
|
/// </summary>
|
||||||
|
public ushort SessionIdx { get { return SessionContext.Index; } }
|
||||||
|
public String FormAction { get; set; }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Messages.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public bool HasMessages()
|
||||||
|
{
|
||||||
|
return infoMessages.Count > 0 || warningMessages.Count > 0 || errorMessages.Count > 0;
|
||||||
|
}
|
||||||
|
public List<String> InfoMessages { get { return new List<string>(infoMessages); } }
|
||||||
|
public List<String> WarningMessages { get { return new List<string>(warningMessages); } }
|
||||||
|
public List<String> ErrorMessages { get { return new List<string>(errorMessages); } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Form messages.
|
||||||
|
public void AddInfoMessage(String message)
|
||||||
|
{
|
||||||
|
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||||
|
infoMessages.Add(message);
|
||||||
|
}
|
||||||
|
public void AddWarningMessage(String message)
|
||||||
|
{
|
||||||
|
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||||
|
warningMessages.Add(message);
|
||||||
|
}
|
||||||
|
public void AddErrorMessage(String message)
|
||||||
|
{
|
||||||
|
if (StringUtil.IsEmpty(StringUtil.TrimAll(message))) return;
|
||||||
|
errorMessages.Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
static partial class Sbm
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Application version.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public static class Version
|
||||||
|
{
|
||||||
|
private static String version { get; } = "3.0.0.0";
|
||||||
|
// Retrieve version.
|
||||||
|
public static String GetFullVersion() { return version; }
|
||||||
|
public static String GetAppVersion()
|
||||||
|
{
|
||||||
|
if (!SbmSystem.DebugMode)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Live instance version is only first 3 elements.
|
||||||
|
String[] versionElements = version.Split('.');
|
||||||
|
return String.Join(".", versionElements.Take(3));
|
||||||
|
}
|
||||||
|
catch (Exception exc) { SaLogger.Warn("Sbm.Version.ToString " + ExceptionUtil.GetErrorStateMessage(exc)); }
|
||||||
|
}
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Version history.
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// 3.0.0 ?-Jul-2021 Initial demo test version.
|
||||||
|
// - .
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -1,21 +1,106 @@
|
|||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||||
{
|
{
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
public static class Sbm
|
public static partial class Sbm
|
||||||
{
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Application configuration defaults.
|
||||||
|
public static class Config
|
||||||
|
{
|
||||||
|
public static String Context_Defaults { get; } = "Defaults";
|
||||||
|
public static class Security
|
||||||
|
{
|
||||||
|
public static class Password
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public static class Activation
|
||||||
|
{
|
||||||
|
public static int EmailLinkExpiresMins_Default { get; } = 60;
|
||||||
|
public static int EmailLinkExpiresMins_Min { get; } = 30;
|
||||||
|
public static int EmailLinkExpiresMins_Max { get; } = 60 * 24;
|
||||||
|
}
|
||||||
|
public static class SignIn
|
||||||
|
{
|
||||||
|
public static class PasswordRequest
|
||||||
|
{
|
||||||
|
public static int EmailLinkExpiresMins_Default { get; } = 60;
|
||||||
|
public static int EmailLinkExpiresMins_Min { get; } = 30;
|
||||||
|
public static int EmailLinkExpiresMins_Max { get; } = 60 * 24;
|
||||||
|
}
|
||||||
|
public static class KeepLoggedIn
|
||||||
|
{
|
||||||
|
public static bool Allowed_Default { get; } = true;
|
||||||
|
public static int CookieExpiresDays_Default { get; } = 10;
|
||||||
|
public static int CookieExpiresDays_Min { get; } = 1;
|
||||||
|
public static int CookieExpiresDays_Max { get; } = 30;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class Online
|
||||||
|
{
|
||||||
|
public static class Session
|
||||||
|
{
|
||||||
|
public static class Cookie
|
||||||
|
{
|
||||||
|
/// <summary>Default cookie name: '.AspNetCore.Session'</summary>
|
||||||
|
public static String Name { get; } = "BusinessMgr.Online.Session";
|
||||||
|
public static bool HttpOnly { get; } = true;
|
||||||
|
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(60);
|
||||||
|
public static long RememberMeTimeoutMilis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static class DataCache
|
||||||
|
{
|
||||||
|
public static class RefreshIntervalSecs
|
||||||
|
{
|
||||||
|
public static int Initial { get; } = SacsSystem.DebugMode ? 2 : 5;
|
||||||
|
public static int Periodic { get; } = SacsSystem.DebugMode ? 60 : 1800;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class Admin
|
||||||
|
{
|
||||||
|
public static class Session
|
||||||
|
{
|
||||||
|
public static class Cookie
|
||||||
|
{
|
||||||
|
/// <summary>Default cookie name: '.AspNetCore.Session'</summary>
|
||||||
|
public static String Name { get; } = "BusinessMgr.Admin.Session";
|
||||||
|
public static bool HttpOnly { get; } = true;
|
||||||
|
public static TimeSpan IdleTimeout { get; } = SacsSystem.DebugMode ? TimeSpan.FromMinutes(5) : TimeSpan.FromMinutes(15);
|
||||||
|
public static long KeepLoggedInTimeoutMillis { get; } = (long)(SacsSystem.DebugMode ? TimeSpan.FromMinutes(2) : TimeSpan.FromMinutes(10)).TotalMilliseconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Definitions.
|
// Definitions.
|
||||||
public static String Version { get; } = "3.0.0.0";
|
|
||||||
public static String ApplicationCaption { get; } = "Sarand BusinessMgr";
|
public static String ApplicationCaption { get; } = "Sarand BusinessMgr";
|
||||||
// Option values.
|
// Option values.
|
||||||
public static String ValueYes { get; } = "YES";
|
public static String ValueYes { get; } = "YES";
|
||||||
public static String ValueNo { get; } = "NO";
|
public static String ValueNo { get; } = "NO";
|
||||||
public static List<CodeDesc> ValuesYesNo { get; } = new List<CodeDesc>() { new CodeDesc(ValueYes, "Yes"), new CodeDesc(ValueNo, "No") };
|
public static List<CodeDesc> ValuesYesNo { get; } = new List<CodeDesc>() { new CodeDesc(ValueYes, "Yes"), new CodeDesc(ValueNo, "No") };
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
public enum Application
|
||||||
|
{
|
||||||
|
WebControl,
|
||||||
|
WebPortal,
|
||||||
|
}
|
||||||
|
public enum InstanceType
|
||||||
|
{
|
||||||
|
Production,
|
||||||
|
UAT,
|
||||||
|
QC,
|
||||||
|
Dev
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Configuration console.
|
// Configuration console.
|
||||||
public enum ConfigConsole
|
public enum ConfigConsole
|
||||||
@@ -12,9 +12,10 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// A p p l i c a t i o n V i e w s
|
// A p p l i c a t i o n V i e w s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static bool IsViewApplicable(SbmUserContext userContext, Sbm.View view)
|
// Jul-2021 ConfigConsole parameter added to avoid local creation. To be reviewed/replaced.
|
||||||
|
public static bool IsViewApplicable(SbmUserContext userContext, SbmConfigConsole configConsole, Sbm.View view)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
//SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
||||||
SbmSecurityProfile securityProfile = userContext.SecurityProfile;
|
SbmSecurityProfile securityProfile = userContext.SecurityProfile;
|
||||||
switch (view)
|
switch (view)
|
||||||
{
|
{
|
||||||
@@ -223,11 +224,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
case Sbm.View.SystemUsers:
|
case Sbm.View.SystemUsers:
|
||||||
if (!configConsole.AllowOption(userContext, Sbm.ConfigOption.AllowContacts)) return false;
|
if (!configConsole.AllowOption(userContext, Sbm.ConfigOption.AllowContacts)) return false;
|
||||||
// Interfaces must be available.
|
// Interfaces must be available.
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
using (SaInterfaceConsole interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(userContext))
|
||||||
if (interfaceConsole == null || !interfaceConsole.DatabaseIsValid) return false;
|
{
|
||||||
// System Account & User tables must be available.
|
if (interfaceConsole == null || !interfaceConsole.DatabaseIsValid) return false;
|
||||||
if (!SbmGlobals.Application.TableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemAccount)) return false;
|
// System Account & User tables must be available.
|
||||||
if (!SbmGlobals.Application.TableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemUser)) return false;
|
if (!SbmGlobals.Application.BusMgrTableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemAccount)) return false;
|
||||||
|
if (!SbmGlobals.Application.BusMgrTableExists(userContext.SessionContext, SbmDbDfn.TableIdx.SystemUser)) return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -257,7 +260,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// A p p l i c a t i o n M e n u
|
// A p p l i c a t i o n M e n u
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static bool IsMenuOptionApplicable(SbmUserContext userContext, Sbm.MenuOption menuOption)
|
public static bool IsMenuOptionApplicable(SbmUserContext userContext, SbmConfigConsole configConsole, Sbm.MenuOption menuOption)
|
||||||
{
|
{
|
||||||
String fn = ClassName + ".IsMenuOptionApplicable";
|
String fn = ClassName + ".IsMenuOptionApplicable";
|
||||||
if (!userContext.ValidUser)
|
if (!userContext.ValidUser)
|
||||||
@@ -268,7 +271,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
Sbm.View view = GetViewForMenuOption(userContext.SessionContext, menuOption);
|
Sbm.View view = GetViewForMenuOption(userContext.SessionContext, menuOption);
|
||||||
if (view != Sbm.View.Unknown)
|
if (view != Sbm.View.Unknown)
|
||||||
// View options.
|
// View options.
|
||||||
return IsViewApplicable(userContext, GetViewForMenuOption(userContext.SessionContext, menuOption));
|
return IsViewApplicable(userContext, configConsole, GetViewForMenuOption(userContext.SessionContext, menuOption));
|
||||||
|
|
||||||
// Non-view options.
|
// Non-view options.
|
||||||
switch (menuOption)
|
switch (menuOption)
|
||||||
@@ -278,16 +281,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
case Sbm.MenuOption.Config_Organisation:
|
case Sbm.MenuOption.Config_Organisation:
|
||||||
return true;
|
return true;
|
||||||
case Sbm.MenuOption.Config_CodeTypes:
|
case Sbm.MenuOption.Config_CodeTypes:
|
||||||
return (SbmGlobals.Application.GetCodeTypeConsole(userContext) != null);
|
return true; // (SbmGlobals.Application.GetCodeTypeConsole(userContext) != null);
|
||||||
case Sbm.MenuOption.Config_Interfaces:
|
case Sbm.MenuOption.Config_Interfaces:
|
||||||
return (SbmGlobals.Application.GetInterfaceConsole(userContext) != null);
|
return true; // (SbmGlobals.Application.GetInterfaceConsole(userContext) != null);
|
||||||
case Sbm.MenuOption.Security_Manage:
|
case Sbm.MenuOption.Security_Manage:
|
||||||
return (SbmGlobals.Application.GetSecurityConsole(userContext) != null);
|
return true; // (SbmGlobals.Application.GetSecurityConsole(userContext) != null);
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
// Actions.
|
// Actions.
|
||||||
case Sbm.MenuOption.Timesheet:
|
case Sbm.MenuOption.Timesheet:
|
||||||
return SbmGlobals.Application.GetConfigConsole(userContext.SessionContext).AllowOption(userContext, Sbm.ConfigOption.TimeRecording);
|
return configConsole.AllowOption(userContext, Sbm.ConfigOption.TimeRecording);
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
}
|
}
|
||||||
SaLogger.Warn(fn + " Unsupport menu option - " + menuOption.ToString());
|
SaLogger.Warn(fn + " Unsupport menu option - " + menuOption.ToString());
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
using Sarand.Net.Standard.Base.CodeTypes;
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using Sarand.Net.Standard.Base.Dbas;
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
using Sarand.Net.Standard.Base.Diary;
|
using Sarand.Net.Standard.Base.Diary;
|
||||||
using Sarand.Net.Standard.Base.Interfaces;
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemData;
|
||||||
using Sarand.Net.Standard.Base.ItemDocs;
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
using Sarand.Net.Standard.Base.ItemOptions;
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
using Sarand.Net.Standard.Base.ReferenceData;
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
@@ -42,55 +43,43 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public abstract SbmSystem System { get; }
|
||||||
// Database.
|
// Database.
|
||||||
public abstract ISacsDatabase GetDatabase(SbmSessionContext sessionContext);
|
public abstract ISacsDatabase GetBusMgrDatabase(SbmSessionContext sessionContext);
|
||||||
public abstract bool TableExists(SbmSessionContext sessionContext, SbmDbDfn.TableIdx tableIdx);
|
public abstract IDatabaseInfo CreateBusMgrDbInfo(SbmSessionContext sessionContext);
|
||||||
public abstract bool ColumnExists(SbmSessionContext sessionContext, SbmDbDfn.ColumnIdx columnIdx);
|
public bool BusMgrTableExists(SbmSessionContext sessionContext, SbmDbDfn.TableIdx tableIdx)
|
||||||
|
{
|
||||||
|
ISacsDatabase db = GetBusMgrDatabase(sessionContext);
|
||||||
|
return db?.TableExists(SbmDbDfn.GetTableName(tableIdx)) ?? false;
|
||||||
|
}
|
||||||
|
public bool BusMgrColumnExists(SbmSessionContext sessionContext, SbmDbDfn.ColumnIdx columnIdx)
|
||||||
|
{
|
||||||
|
ISacsDatabase db = GetBusMgrDatabase(sessionContext);
|
||||||
|
return db?.ColumnExists(SbmDbDfn.GetTableName(SbmDbDfn.GetTableForColumn(columnIdx)), SbmDbDfn.GetColumnName(columnIdx, false)) ?? false;
|
||||||
|
}
|
||||||
|
// Application instance.
|
||||||
|
public abstract Sbm.InstanceType InstanceType { get; }
|
||||||
|
public bool IsLiveHost() { return InstanceType == Sbm.InstanceType.Production; }
|
||||||
|
public bool IsTestHost() { return InstanceType != Sbm.InstanceType.Production; }
|
||||||
|
public bool IsDevHost() { return InstanceType == Sbm.InstanceType.Dev; }
|
||||||
|
public abstract String EnvironmentName { get; }
|
||||||
|
// Email configuration.
|
||||||
|
public abstract SbmEmailConfig EmailConfig { get; }
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Config Console.
|
// Create consoles.
|
||||||
public abstract SbmConfigConsole GetConfigConsole(SbmSessionContext sessionContext);
|
public abstract SbmConfigConsole CreateConfigConsole(SbmSessionContext sessionContext);
|
||||||
|
public abstract SaDiaryConsole CreateDiaryConsole(SbmUserContext userContext);
|
||||||
//-------------------------------------------------------------------
|
public abstract SaSecurityConsole CreateSecurityConsole(SbmUserContext userContext);
|
||||||
// Managers.
|
public abstract SaCodeTypeConsole CreateCodeTypeConsole(SbmUserContext userContext);
|
||||||
public abstract SbmAccountMgr CreateAccountMgr(SbmUserContext userContext);
|
public abstract SaReferenceDataConsole CreateReferenceDataConsole(SbmUserContext userContext);
|
||||||
public abstract SbmTransactionMgr CreateTransactionMgr(SbmUserContext userContext);
|
public abstract SaItemDataConsole CreateItemDataConsole(SbmUserContext userContext);
|
||||||
|
public abstract SaItemDocConsole CreateItemDocConsole(SbmUserContext userContext);
|
||||||
//-------------------------------------------------------------------
|
public abstract SaItemOptionConsole CreateItemOptionConsole(SbmUserContext userContext);
|
||||||
// Diary console.
|
public abstract SaInterfaceConsole CreateInterfaceConsole(SbmUserContext userContext);
|
||||||
public abstract SaDiaryConsole GetDiaryConsole(SbmUserContext userContext);
|
public abstract SaUpdateLogConsole CreateUpdateLogConsole(SbmUserContext userContext);
|
||||||
|
public abstract SbmEmailConsole CreateEmailConsole(SbmUserContext userContext);
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Security console.
|
|
||||||
public abstract SaSecurityConsole GetSecurityConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Code Type console.
|
|
||||||
public abstract SaCodeTypeConsole GetCodeTypeConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Reference Data console.
|
|
||||||
public abstract SaReferenceDataConsole GetReferenceDataConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Data console.
|
|
||||||
public abstract Sarand.Net.Standard.Base.ItemData.SaItemDataConsole GetItemDataConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Doc console.
|
|
||||||
public abstract SaItemDocConsole GetItemDocConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Option console.
|
|
||||||
public abstract SaItemOptionConsole GetItemOptionConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Interface console.
|
|
||||||
public abstract SaInterfaceConsole GetInterfaceConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Update Log console.
|
|
||||||
public abstract SaUpdateLogConsole GetUpdateLogConsole(SbmUserContext userContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
protected SbmConfigConsole(Sbm.ConfigConsole configConsole, SbmVersion consoleVersion, SbmSessionContext sessionContext)
|
protected SbmConfigConsole(Sbm.ConfigConsole configConsole, SbmVersion consoleVersion, SbmSessionContext sessionContext)
|
||||||
{
|
{
|
||||||
ConfigConsole = configConsole;
|
ConfigConsole = configConsole;
|
||||||
AppVersion = new SbmVersion("BusinessMgr", Sbm.Version, SbmSystem.AssemblyBuildAt);
|
AppVersion = new SbmVersion("BusinessMgr", Sbm.Version.GetFullVersion(), SbmSystem.AssemblyBuildAt);
|
||||||
ConsoleVersion = consoleVersion;
|
ConsoleVersion = consoleVersion;
|
||||||
SessionContext = sessionContext;
|
SessionContext = sessionContext;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
String fn = "SbmConfigConsole.CreateConsole";
|
String fn = "SbmConfigConsole.CreateConsole";
|
||||||
SaLogger.Warn(fn + ".CreateConsole Creating default configuration console.");
|
SaLogger.Warn(fn + ".CreateConsole Creating default configuration console.");
|
||||||
// Default console.
|
// Default console.
|
||||||
SbmVersion consoleVersion = new SbmVersion("Standard", Sbm.Version, SbmSystem.AssemblyBuildAt);
|
SbmVersion consoleVersion = new SbmVersion("Standard", Sbm.Version.GetFullVersion(), SbmSystem.AssemblyBuildAt);
|
||||||
return new SbmConfigConsole(Sbm.ConfigConsole.Generic, consoleVersion, sessionContext);
|
return new SbmConfigConsole(Sbm.ConfigConsole.Generic, consoleVersion, sessionContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -593,7 +593,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
public virtual bool SetMinTransactionId(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes, long iId)
|
public virtual bool SetMinTransactionId(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes, long iId)
|
||||||
{
|
{
|
||||||
bool set = false;
|
bool set = false;
|
||||||
if (SbmGlobals.Application.GetDatabase(SessionContext) != null)
|
if (SbmGlobals.Application.GetBusMgrDatabase(SessionContext) != null)
|
||||||
{
|
{
|
||||||
String nextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
|
String nextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
|
||||||
// ToDo set = SbmGlobals.Database.SetMinNextId(nextIdKey, iId, false);
|
// ToDo set = SbmGlobals.Database.SetMinNextId(nextIdKey, iId, false);
|
||||||
@@ -607,7 +607,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes)
|
(SbmUserContext userContext, SysId AffiliateId_Owner, SysId idAssoc, Sbm.TransactionType transTypes)
|
||||||
{
|
{
|
||||||
String Ref = "";
|
String Ref = "";
|
||||||
if (SbmGlobals.Application.GetDatabase(SessionContext) != null)
|
if (SbmGlobals.Application.GetBusMgrDatabase(SessionContext) != null)
|
||||||
{
|
{
|
||||||
String NextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
|
String NextIdKey = GetTransactionNextIdKey(userContext, AffiliateId_Owner, idAssoc, transTypes);
|
||||||
// ToDo long iRefNext = SbmGlobals.Database.GetNextId(NextIdKey, false);
|
// ToDo long iRefNext = SbmGlobals.Database.GetNextId(NextIdKey, false);
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
using Sarand.Net.Standard.Base.CodeTypes;
|
|
||||||
using Sarand.Net.Standard.Base.Dbas;
|
|
||||||
using Sarand.Net.Standard.Base.Interfaces;
|
|
||||||
using Sarand.Net.Standard.Base.ItemOptions;
|
|
||||||
using Sarand.Net.Standard.Base.ReferenceData;
|
|
||||||
using Sarand.Net.Standard.Base.Security;
|
|
||||||
using Sarand.Net.Standard.Base.UpdateLog;
|
|
||||||
|
|
||||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|
||||||
{
|
|
||||||
//=======================================================================
|
|
||||||
public abstract class SbmConsoleHelper
|
|
||||||
{
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Protected construction - use derived objects.
|
|
||||||
protected SbmConsoleHelper()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Database.
|
|
||||||
public abstract ISacsDatabase GetDatabase(SbmSessionContext sessionContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Create local consoles.
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Retrieve Global Consoles by session context.
|
|
||||||
public abstract SaSecurityConsole GetSecurityConsole(SbmSessionContext sessionContext);
|
|
||||||
public abstract SaCodeTypeConsole GetCodeTypeConsole(SbmSessionContext sessionContext);
|
|
||||||
public abstract SaReferenceDataConsole GetReferenceDataConsole(SbmSessionContext sessionContext);
|
|
||||||
public abstract SaItemOptionConsole GetItemOptionConsole(SbmSessionContext sessionContext);
|
|
||||||
public abstract SaInterfaceConsole GetInterfaceConsole(SbmSessionContext sessionContext);
|
|
||||||
public abstract SaUpdateLogConsole GetUpdateLogConsole(SbmSessionContext sessionContext);
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
}
|
|
||||||
//=======================================================================
|
|
||||||
}
|
|
||||||
@@ -24,79 +24,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Database.
|
// Database.
|
||||||
public static ISacsDatabase GetDatabase(SbmSessionContext sessionContext)
|
public static ISacsDatabase GetBusMgrDatabase(SbmSessionContext sessionContext)
|
||||||
{
|
{
|
||||||
return Application != null ? Application.GetDatabase(sessionContext) : null;
|
return Application != null ? Application.GetBusMgrDatabase(sessionContext) : null;
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Configuration console.
|
|
||||||
public static SbmConfigConsole GetConfigConsole(SbmSessionContext sessionContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetConfigConsole(sessionContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Diary.
|
|
||||||
public static SaDiaryConsole GetDiaryConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetDiaryConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Security console.
|
|
||||||
public static SaSecurityConsole GetSecurityConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetSecurityConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Code Type console.
|
|
||||||
public static SaCodeTypeConsole GetCodeTypeConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetCodeTypeConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Reference Data console.
|
|
||||||
public static SaReferenceDataConsole GetReferenceDataConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetReferenceDataConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Data console.
|
|
||||||
public static SaItemDataConsole GetItemDataConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetItemDataConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Doc console.
|
|
||||||
public static SaItemDocConsole GetItemDocConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetItemDocConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Item Option console.
|
|
||||||
public static SaItemOptionConsole GetItemOptionConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetItemOptionConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Interface console.
|
|
||||||
public static SaInterfaceConsole GetInterfaceConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetInterfaceConsole(userContext) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Update Log console.
|
|
||||||
public static SaUpdateLogConsole GetUpdateLogConsole(SbmUserContext userContext)
|
|
||||||
{
|
|
||||||
return Application != null ? Application.GetUpdateLogConsole(userContext) : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Consoles;
|
||||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
using Sarand.Net.Standard.Base.Bus;
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
using Sarand.Net.Standard.Base.CodeTypes;
|
using Sarand.Net.Standard.Base.CodeTypes;
|
||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using Sarand.Net.Standard.Base.Dbas;
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Diary;
|
||||||
|
using Sarand.Net.Standard.Base.Email;
|
||||||
using Sarand.Net.Standard.Base.Interfaces;
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
|
using Sarand.Net.Standard.Base.ItemData;
|
||||||
using Sarand.Net.Standard.Base.ItemDocs;
|
using Sarand.Net.Standard.Base.ItemDocs;
|
||||||
using Sarand.Net.Standard.Base.ItemOptions;
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
using Sarand.Net.Standard.Base.ReferenceData;
|
using Sarand.Net.Standard.Base.ReferenceData;
|
||||||
@@ -34,6 +38,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
private SbmDataItemMgr dataItemMgr;
|
private SbmDataItemMgr dataItemMgr;
|
||||||
// Consoles.
|
// Consoles.
|
||||||
private SbmConfigConsole configConsole;
|
private SbmConfigConsole configConsole;
|
||||||
|
private SaDiaryConsole diaryConsole;
|
||||||
private SaSecurityConsole securityConsole;
|
private SaSecurityConsole securityConsole;
|
||||||
private SaCodeTypeConsole codeTypeConsole;
|
private SaCodeTypeConsole codeTypeConsole;
|
||||||
private SaReferenceDataConsole referenceDataConsole;
|
private SaReferenceDataConsole referenceDataConsole;
|
||||||
@@ -41,6 +46,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
private SaInterfaceConsole interfaceConsole;
|
private SaInterfaceConsole interfaceConsole;
|
||||||
private SaItemDocConsole itemDocConsole;
|
private SaItemDocConsole itemDocConsole;
|
||||||
private SaItemOptionConsole itemOptionConsole;
|
private SaItemOptionConsole itemOptionConsole;
|
||||||
|
private SaItemDataConsole itemDataConsole;
|
||||||
|
public SbmEmailConsole emailConsole;
|
||||||
// Configurations.
|
// Configurations.
|
||||||
private SbmStockControlConfig stockControlConfig;
|
private SbmStockControlConfig stockControlConfig;
|
||||||
private SbmRequirementCostingConfig requirementCostingConfig;
|
private SbmRequirementCostingConfig requirementCostingConfig;
|
||||||
@@ -59,6 +66,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// Managers.
|
||||||
if (accountMgr != null) accountMgr.Dispose();
|
if (accountMgr != null) accountMgr.Dispose();
|
||||||
if (assetMgr != null) assetMgr.Dispose();
|
if (assetMgr != null) assetMgr.Dispose();
|
||||||
if (commodityMgr != null) commodityMgr.Dispose();
|
if (commodityMgr != null) commodityMgr.Dispose();
|
||||||
@@ -70,17 +78,42 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
if (currencies != null) currencies.ClearAndDispose();
|
if (currencies != null) currencies.ClearAndDispose();
|
||||||
if (taxCodes != null) taxCodes.ClearAndDispose();
|
if (taxCodes != null) taxCodes.ClearAndDispose();
|
||||||
if (unitsOfMeasure != null) unitsOfMeasure.ClearAndDispose();
|
if (unitsOfMeasure != null) unitsOfMeasure.ClearAndDispose();
|
||||||
|
// Consoles.
|
||||||
|
if (configConsole != null) configConsole.Dispose();
|
||||||
|
if (diaryConsole != null) diaryConsole.Dispose();
|
||||||
|
if (securityConsole != null) securityConsole.Dispose();
|
||||||
|
if (codeTypeConsole != null) codeTypeConsole.Dispose();
|
||||||
|
if (referenceDataConsole != null) referenceDataConsole.Dispose();
|
||||||
|
if (updateLogConsole != null) updateLogConsole.Dispose();
|
||||||
|
if (interfaceConsole != null) interfaceConsole.Dispose();
|
||||||
|
if (itemDocConsole != null) itemDocConsole.Dispose();
|
||||||
|
if (itemOptionConsole != null) itemOptionConsole.Dispose();
|
||||||
|
if (itemDataConsole != null) itemDataConsole.Dispose();
|
||||||
|
if (itemDataConsole != null) itemDataConsole.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Session properties.
|
// Session properties.
|
||||||
|
public SbmApplication Application { get { return SbmGlobals.Application; } }
|
||||||
public SbmUserContext UserContext { get; }
|
public SbmUserContext UserContext { get; }
|
||||||
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
public SbmSecurityProfile SecurityProfile { get { return UserContext.SecurityProfile; } }
|
public SbmSecurityProfile SecurityProfile { get { return UserContext.SecurityProfile; } }
|
||||||
public SbmAccountsDfn AccountsDfn { get { if (accountsDfn == null) accountsDfn = new SbmAccountsDfn(UserContext); { return accountsDfn; } } }
|
public SbmAccountsDfn AccountsDfn { get { if (accountsDfn == null) accountsDfn = new SbmAccountsDfn(UserContext); { return accountsDfn; } } }
|
||||||
|
// Database.
|
||||||
|
public ISacsDatabase BusMgrDatabase { get { return Application.GetBusMgrDatabase(SessionContext); } }
|
||||||
public DbUpdateInfo DbUpdateInfo { get { return UserContext.DbUpdateInfo; } }
|
public DbUpdateInfo DbUpdateInfo { get { return UserContext.DbUpdateInfo; } }
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// System codes.
|
||||||
|
private Dictionary<Sbm.SystemCode, List<TypeCodeDesc>> systemCodeCache = new Dictionary<Sbm.SystemCode, List<TypeCodeDesc>>();
|
||||||
|
public List<TypeCodeDesc> GetCodesOfType(Sbm.SystemCode systemCode)
|
||||||
|
{
|
||||||
|
if (!systemCodeCache.ContainsKey(systemCode))
|
||||||
|
systemCodeCache.Add(systemCode, SbmSystem.GetCodesOfType(UserContext, systemCode));
|
||||||
|
return systemCodeCache.GetValueOrDefault(systemCode, new List<TypeCodeDesc>());
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Managers.
|
// Managers.
|
||||||
public SbmAccountMgr AccountMgr
|
public SbmAccountMgr AccountMgr
|
||||||
@@ -163,16 +196,25 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (configConsole == null)
|
if (configConsole == null)
|
||||||
configConsole = SbmGlobals.GetConfigConsole(SessionContext);
|
configConsole = Application.CreateConfigConsole(SessionContext);
|
||||||
return configConsole;
|
return configConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public SaDiaryConsole DiaryConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (diaryConsole == null)
|
||||||
|
diaryConsole = Application.CreateDiaryConsole(UserContext);
|
||||||
|
return DiaryConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
public SaSecurityConsole SecurityConsole
|
public SaSecurityConsole SecurityConsole
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (securityConsole == null)
|
if (securityConsole == null)
|
||||||
securityConsole = SbmGlobals.GetSecurityConsole(UserContext);
|
securityConsole = Application.CreateSecurityConsole(UserContext);
|
||||||
return securityConsole;
|
return securityConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -181,7 +223,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (codeTypeConsole == null)
|
if (codeTypeConsole == null)
|
||||||
codeTypeConsole = SbmGlobals.GetCodeTypeConsole(UserContext);
|
codeTypeConsole = Application.CreateCodeTypeConsole(UserContext);
|
||||||
return codeTypeConsole;
|
return codeTypeConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,7 +232,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (referenceDataConsole == null)
|
if (referenceDataConsole == null)
|
||||||
referenceDataConsole = SbmGlobals.GetReferenceDataConsole(UserContext);
|
referenceDataConsole = Application.CreateReferenceDataConsole(UserContext);
|
||||||
return referenceDataConsole;
|
return referenceDataConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,7 +241,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (updateLogConsole == null)
|
if (updateLogConsole == null)
|
||||||
updateLogConsole = SbmGlobals.GetUpdateLogConsole(UserContext);
|
updateLogConsole = Application.CreateUpdateLogConsole(UserContext);
|
||||||
return updateLogConsole;
|
return updateLogConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -208,7 +250,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (interfaceConsole == null)
|
if (interfaceConsole == null)
|
||||||
interfaceConsole = SbmGlobals.GetInterfaceConsole(UserContext);
|
interfaceConsole = Application.CreateInterfaceConsole(UserContext);
|
||||||
return interfaceConsole;
|
return interfaceConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -217,7 +259,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (itemDocConsole == null)
|
if (itemDocConsole == null)
|
||||||
itemDocConsole = SbmGlobals.GetItemDocConsole(UserContext);
|
itemDocConsole = Application.CreateItemDocConsole(UserContext);
|
||||||
return itemDocConsole;
|
return itemDocConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -226,10 +268,32 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (itemOptionConsole == null)
|
if (itemOptionConsole == null)
|
||||||
itemOptionConsole = SbmGlobals.GetItemOptionConsole(UserContext);
|
itemOptionConsole = Application.CreateItemOptionConsole(UserContext);
|
||||||
return itemOptionConsole;
|
return itemOptionConsole;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public SaItemDataConsole ItemDataConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (itemDataConsole == null)
|
||||||
|
itemDataConsole = Application.CreateItemDataConsole(UserContext);
|
||||||
|
return itemDataConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Email.
|
||||||
|
public SaEmailConfig EmailConfig { get { return Application.EmailConfig; } }
|
||||||
|
public SbmEmailConsole EmailConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (emailConsole == null)
|
||||||
|
emailConsole = Application.CreateEmailConsole(UserContext);
|
||||||
|
return emailConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Configurations.
|
// Configurations.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Refresh profile.
|
// Refresh profile.
|
||||||
public void RefreshProfile(SaSecurityConsole securityConsole, SysId userId, List<TypeCodeDesc> securityRights)
|
public void RefreshProfile(SbmConfigConsole configConsole, SaSecurityConsole securityConsole, SysId userId, List<TypeCodeDesc> securityRights)
|
||||||
{
|
{
|
||||||
String fn = GetType().Name + ".RefreshProfile";
|
String fn = GetType().Name + ".RefreshProfile";
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
@@ -62,53 +62,33 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
SaLogger.Debug(fn + " User: '" + UserDisplayName + "' [Id: " + UserId + "]" + (SysId.IsValid(previousUserId) ? ". Previous UserId: " + SysId.ToString(previousUserId) : ""));
|
SaLogger.Debug(fn + " User: '" + UserDisplayName + "' [Id: " + UserId + "]" + (SysId.IsValid(previousUserId) ? ". Previous UserId: " + SysId.ToString(previousUserId) : ""));
|
||||||
|
|
||||||
RefreshProfileSettings();
|
RefreshProfileSettings(configConsole);
|
||||||
|
|
||||||
}
|
}
|
||||||
protected void RefreshProfile(SaSecurityProfile userSecurityProfile, SaSecurityProfile hostSecurityProfile)
|
protected void RefreshProfile(SbmConfigConsole configConsole, SaSecurityProfile userSecurityProfile, SaSecurityProfile hostSecurityProfile)
|
||||||
{
|
{
|
||||||
this.userSecurityProfile = userSecurityProfile;
|
this.userSecurityProfile = userSecurityProfile;
|
||||||
this.hostSecurityProfile = hostSecurityProfile;
|
this.hostSecurityProfile = hostSecurityProfile;
|
||||||
RefreshProfileSettings();
|
RefreshProfileSettings(configConsole);
|
||||||
}
|
}
|
||||||
private void RefreshProfileSettings()
|
private void RefreshProfileSettings(SbmConfigConsole configConsole)
|
||||||
{
|
{
|
||||||
// Admin.
|
RefreshAdminProfile(configConsole);
|
||||||
Admin.CanManageSecurity = UserHasSecurityRight(Sbm.SecurityRight.Security_Admin);
|
RefreshManageProfile(configConsole);
|
||||||
Admin.CanManageDatabase = UserHasSecurityRight(Sbm.SecurityRight.Database_Admin);
|
RefreshFinancialProfile(configConsole);
|
||||||
Admin.CanManageReferenceData = UserHasSecurityRight(Sbm.SecurityRight.ReferenceData_Admin);
|
RefreshContactsProfile(configConsole);
|
||||||
Admin.CanManageInterfaces = UserHasSecurityRight(Sbm.SecurityRight.InterfaceConfig);
|
RefreshTransactionProfile(configConsole);
|
||||||
|
RefreshItemTypeProfile(configConsole);
|
||||||
// Manage.
|
|
||||||
Manage.CanManageTasks = UserHasSecurityRight(Sbm.SecurityRight.TaskManager);
|
|
||||||
Manage.CanManageTimesheets = UserHasSecurityRight(Sbm.SecurityRight.TimesheetManager);
|
|
||||||
|
|
||||||
//Financials.
|
|
||||||
Financial.CanViewFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_View);
|
|
||||||
Financial.CanUpdateFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_Update);
|
|
||||||
Financial.CanViewCommoditySupplyFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySupply);
|
|
||||||
Financial.CanUpdateCommoditySupplyFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySupply);
|
|
||||||
Financial.CanViewCommoditySalesFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySales);
|
|
||||||
Financial.CanUpdateCommoditySalesFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySales);
|
|
||||||
|
|
||||||
// Contacts.
|
|
||||||
Contacts.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Update));
|
|
||||||
Contacts.CanCreate = (Contacts.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Create));
|
|
||||||
|
|
||||||
// Transactions.
|
|
||||||
Transaction.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Transaction_Update));
|
|
||||||
Transaction.CanCreate = (Transaction.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Transaction_View));
|
|
||||||
|
|
||||||
// ToDo Commodities.
|
// ToDo Commodities.
|
||||||
}
|
}
|
||||||
private void ClearProfile()
|
private void ClearProfile()
|
||||||
{
|
{
|
||||||
// Reset security profiles.
|
// Reset security profiles.
|
||||||
Admin.Clear();
|
Admin = new AdminProfile(this);
|
||||||
Manage.Clear();
|
Manage = new ManageProfile(this);
|
||||||
Financial.Clear();
|
Financial = new FinancialProfile(this);
|
||||||
Contacts.Clear();
|
Contacts = new ContactsProfile(this);
|
||||||
Transaction.Clear();
|
Transaction = new TransactionsProfile(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@@ -152,15 +132,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
public bool CanManageDatabase { get; internal set; } = false;
|
public bool CanManageDatabase { get; internal set; } = false;
|
||||||
public bool CanManageReferenceData { get; internal set; } = false;
|
public bool CanManageReferenceData { get; internal set; } = false;
|
||||||
public bool CanManageInterfaces { get; internal set; } = false;
|
public bool CanManageInterfaces { get; internal set; } = false;
|
||||||
internal void Clear()
|
|
||||||
{
|
|
||||||
CanManageSecurity = false;
|
|
||||||
CanManageDatabase = false;
|
|
||||||
CanManageReferenceData = false;
|
|
||||||
CanManageInterfaces = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public AdminProfile Admin { get; }
|
public AdminProfile Admin { get; internal set; }
|
||||||
|
private void RefreshAdminProfile(SbmConfigConsole configConsole)
|
||||||
|
{
|
||||||
|
Admin.CanManageSecurity = UserHasSecurityRight(Sbm.SecurityRight.Security_Admin);
|
||||||
|
Admin.CanManageDatabase = UserHasSecurityRight(Sbm.SecurityRight.Database_Admin);
|
||||||
|
Admin.CanManageReferenceData = UserHasSecurityRight(Sbm.SecurityRight.ReferenceData_Admin);
|
||||||
|
Admin.CanManageInterfaces = UserHasSecurityRight(Sbm.SecurityRight.InterfaceConfig);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Security rights - Manage.
|
// Security rights - Manage.
|
||||||
@@ -173,12 +153,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
public bool CanManageTasks { get; internal set; } = false;
|
public bool CanManageTasks { get; internal set; } = false;
|
||||||
public bool CanManageTimesheets { get; internal set; } = false;
|
public bool CanManageTimesheets { get; internal set; } = false;
|
||||||
internal void Clear()
|
|
||||||
{
|
|
||||||
CanManageTasks = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public ManageProfile Manage { get; }
|
public ManageProfile Manage { get; internal set; }
|
||||||
|
private void RefreshManageProfile(SbmConfigConsole configConsole)
|
||||||
|
{
|
||||||
|
Manage.CanManageTasks = UserHasSecurityRight(Sbm.SecurityRight.TaskManager);
|
||||||
|
Manage.CanManageTimesheets = UserHasSecurityRight(Sbm.SecurityRight.TimesheetManager);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Security rights - Financials.
|
// Security rights - Financials.
|
||||||
@@ -189,28 +170,30 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
{
|
{
|
||||||
this.securityProfile = securityProfile;
|
this.securityProfile = securityProfile;
|
||||||
}
|
}
|
||||||
public bool CanViewFinancials { get; internal set; } = false;
|
public bool CanViewFinancials { get; internal set; }
|
||||||
public bool CanUpdateFinancials { get; internal set; } = false;
|
public bool CanUpdateFinancials { get; internal set; }
|
||||||
public bool CanViewCommoditySupplyFinancials { get; internal set; } = false;
|
public bool CanViewCommoditySupplyFinancials { get; internal set; }
|
||||||
public bool CanUpdateCommoditySupplyFinancials { get; internal set; } = false;
|
public bool CanUpdateCommoditySupplyFinancials { get; internal set; }
|
||||||
public bool CanViewCommoditySalesFinancials { get; internal set; } = false;
|
public bool CanViewCommoditySalesFinancials { get; internal set; }
|
||||||
public bool CanUpdateCommoditySalesFinancials { get; internal set; } = false;
|
public bool CanUpdateCommoditySalesFinancials { get; internal set; }
|
||||||
internal void Clear()
|
public bool ConfigOption_AllowFinancialsAccessControl { get; internal set; }
|
||||||
{
|
}
|
||||||
CanViewFinancials = false;
|
public FinancialProfile Financial { get; internal set; }
|
||||||
CanUpdateFinancials = false;
|
private void RefreshFinancialProfile(SbmConfigConsole configConsole)
|
||||||
CanViewCommoditySupplyFinancials = false;
|
{
|
||||||
CanUpdateCommoditySupplyFinancials = false;
|
Financial.CanViewFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_View);
|
||||||
CanViewCommoditySalesFinancials = false;
|
Financial.CanUpdateFinancials = UserHasSecurityRight(Sbm.SecurityRight.Financial_Update);
|
||||||
CanUpdateCommoditySalesFinancials = false;
|
Financial.CanViewCommoditySupplyFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySupply);
|
||||||
}
|
Financial.CanUpdateCommoditySupplyFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySupply);
|
||||||
|
Financial.CanViewCommoditySalesFinancials = UserCanAccessFinancialViewOfType(Sbm.FinancialType.CommoditySales);
|
||||||
|
Financial.CanUpdateCommoditySalesFinancials = UserCanAccessFinancialUpdateOfType(Sbm.FinancialType.CommoditySales);
|
||||||
|
// Config options.
|
||||||
|
Financial.ConfigOption_AllowFinancialsAccessControl = (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl));
|
||||||
}
|
}
|
||||||
public FinancialProfile Financial { get; }
|
|
||||||
|
|
||||||
public bool UserCanViewFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
|
public bool UserCanViewFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
|
if (Financial.ConfigOption_AllowFinancialsAccessControl) return true;
|
||||||
if (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl)) return true;
|
|
||||||
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update) || IsSecurityRightGranted(Sbm.SecurityRight.Financial_View))
|
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update) || IsSecurityRightGranted(Sbm.SecurityRight.Financial_View))
|
||||||
{
|
{
|
||||||
// If specific type of financial is requested, check that view is not denied.
|
// If specific type of financial is requested, check that view is not denied.
|
||||||
@@ -223,8 +206,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
|
|
||||||
public bool UserCanUpdateFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
|
public bool UserCanUpdateFinancials(Sbm.FinancialType financialType = Sbm.FinancialType.Any)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
|
if (Financial.ConfigOption_AllowFinancialsAccessControl) return true;
|
||||||
if (configConsole != null && !configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowFinancialsAccessControl)) return true;
|
|
||||||
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update))
|
if (IsSecurityRightGranted(Sbm.SecurityRight.Financial_Update))
|
||||||
{
|
{
|
||||||
// If specific type of financial is requested, check that update is not denied.
|
// If specific type of financial is requested, check that update is not denied.
|
||||||
@@ -264,13 +246,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
public bool CanCreate { get; internal set; } = false;
|
public bool CanCreate { get; internal set; } = false;
|
||||||
public bool CanUpdate { get; internal set; } = false;
|
public bool CanUpdate { get; internal set; } = false;
|
||||||
internal void Clear()
|
|
||||||
{
|
|
||||||
CanCreate = false;
|
|
||||||
CanUpdate = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public ContactsProfile Contacts { get; }
|
public ContactsProfile Contacts { get; internal set; }
|
||||||
|
private void RefreshContactsProfile(SbmConfigConsole configConsole)
|
||||||
|
{
|
||||||
|
Contacts.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Update));
|
||||||
|
Contacts.CanCreate = (Contacts.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Affiliate_Create));
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Security rights - Transactions.
|
// Security rights - Transactions.
|
||||||
@@ -308,13 +290,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
internal void Clear()
|
|
||||||
{
|
|
||||||
CanCreate = false;
|
|
||||||
CanUpdate = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public TransactionsProfile Transaction { get; }
|
public TransactionsProfile Transaction { get; internal set; }
|
||||||
|
private void RefreshTransactionProfile(SbmConfigConsole configConsole)
|
||||||
|
{
|
||||||
|
Transaction.CanUpdate = (UserHasSecurityRight(Sbm.SecurityRight.Transaction_Update));
|
||||||
|
Transaction.CanCreate = (Transaction.CanUpdate || UserHasSecurityRight(Sbm.SecurityRight.Transaction_View));
|
||||||
|
}
|
||||||
|
|
||||||
public bool UserCanAccessTransactionsOfType(Sbm.TransactionType transactionType)
|
public bool UserCanAccessTransactionsOfType(Sbm.TransactionType transactionType)
|
||||||
{
|
{
|
||||||
if ((int)transactionType < 1) return false;
|
if ((int)transactionType < 1) return false;
|
||||||
@@ -329,22 +312,44 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
public class ItemTypesProfile
|
public class ItemTypesProfile
|
||||||
{
|
{
|
||||||
internal ItemTypesProfile() { }
|
internal ItemTypesProfile() { }
|
||||||
public bool CanCreate { get; internal set; } = false;
|
public bool CanCreate { get; internal set; }
|
||||||
public bool CanUpdate { get; internal set; } = false;
|
public bool CanUpdate { get; internal set; }
|
||||||
public bool CanRemove { get; internal set; } = false;
|
public bool CanRemove { get; internal set; }
|
||||||
internal void Clear()
|
// Config options.
|
||||||
{
|
public bool ConfigOption_AllowProcesses { get; internal set; }
|
||||||
CanCreate = false;
|
public bool ConfigOption_AllowContacts { get; internal set; }
|
||||||
CanUpdate = false;
|
public bool ConfigOption_AllowCommodities { get; internal set; }
|
||||||
CanRemove = false;
|
public bool ConfigOption_AllowPortfolios { get; internal set; }
|
||||||
}
|
public bool ConfigOption_AllowPriceSets { get; internal set; }
|
||||||
|
public bool ConfigOption_CommodityCustomers { get; internal set; }
|
||||||
|
public bool ConfigOption_CommoditySuppliers { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowTransactions { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowAssets { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowVehicles { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowStockLocations { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowStockContainers { get; internal set; }
|
||||||
|
public bool ConfigOption_AllowStockControl { get; internal set; }
|
||||||
}
|
}
|
||||||
public ItemTypesProfile ItemType { get; } = new ItemTypesProfile();
|
public ItemTypesProfile ItemType { get; } = new ItemTypesProfile();
|
||||||
|
private void RefreshItemTypeProfile(SbmConfigConsole configConsole)
|
||||||
|
{
|
||||||
|
ItemType.ConfigOption_AllowProcesses = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
|
||||||
|
ItemType.ConfigOption_AllowContacts = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowContacts);
|
||||||
|
ItemType.ConfigOption_AllowCommodities = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowCommodities);
|
||||||
|
ItemType.ConfigOption_AllowPortfolios = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPortfolios);
|
||||||
|
ItemType.ConfigOption_AllowPriceSets = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPriceSets);
|
||||||
|
ItemType.ConfigOption_CommodityCustomers = configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommodityCustomers);
|
||||||
|
ItemType.ConfigOption_CommoditySuppliers = configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommoditySuppliers);
|
||||||
|
ItemType.ConfigOption_AllowTransactions = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowTransactions);
|
||||||
|
ItemType.ConfigOption_AllowAssets = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowAssets);
|
||||||
|
ItemType.ConfigOption_AllowVehicles = configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowVehicles);
|
||||||
|
ItemType.ConfigOption_AllowStockLocations = configConsole.GetStockControlConfig(UserContext).AllowStockLocations();
|
||||||
|
ItemType.ConfigOption_AllowStockContainers = configConsole.GetStockControlConfig(UserContext).AllowStockContainers();
|
||||||
|
ItemType.ConfigOption_AllowStockControl = configConsole.GetStockControlConfig(UserContext).AllowStockControl();
|
||||||
|
}
|
||||||
|
|
||||||
public bool ItemTypeIsAllowed(Sbm.ItemType itemType)
|
public bool ItemTypeIsAllowed(Sbm.ItemType itemType)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
|
|
||||||
if (configConsole == null) return false;
|
|
||||||
switch (itemType)
|
switch (itemType)
|
||||||
{
|
{
|
||||||
//case Sbm.ItemType.SecItem:
|
//case Sbm.ItemType.SecItem:
|
||||||
@@ -353,37 +358,37 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
//case Sbm.ItemType.Language:
|
//case Sbm.ItemType.Language:
|
||||||
//case Sbm.ItemType.TaxCode:
|
//case Sbm.ItemType.TaxCode:
|
||||||
//case Sbm.ItemType.UnitMeasure:
|
//case Sbm.ItemType.UnitMeasure:
|
||||||
case Sbm.ItemType.Process: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
|
case Sbm.ItemType.Process: return ItemType.ConfigOption_AllowProcesses;
|
||||||
case Sbm.ItemType.Affiliate:
|
case Sbm.ItemType.Affiliate:
|
||||||
case Sbm.ItemType.Address: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowContacts);
|
case Sbm.ItemType.Address: return ItemType.ConfigOption_AllowContacts;
|
||||||
case Sbm.ItemType.Commodity: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowCommodities);
|
case Sbm.ItemType.Commodity: return ItemType.ConfigOption_AllowCommodities;
|
||||||
case Sbm.ItemType.PortfolioItem: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPortfolios);
|
case Sbm.ItemType.PortfolioItem: return ItemType.ConfigOption_AllowPortfolios;
|
||||||
case Sbm.ItemType.Location: return configConsole.GetStockControlConfig(UserContext).AllowStockLocations();
|
case Sbm.ItemType.Location: return ItemType.ConfigOption_AllowStockLocations;
|
||||||
case Sbm.ItemType.Container:
|
case Sbm.ItemType.Container:
|
||||||
case Sbm.ItemType.ContainerItem: return configConsole.GetStockControlConfig(UserContext).AllowStockContainers();
|
case Sbm.ItemType.ContainerItem: return ItemType.ConfigOption_AllowStockContainers;
|
||||||
case Sbm.ItemType.Movement:
|
case Sbm.ItemType.Movement:
|
||||||
case Sbm.ItemType.StockLevel: return configConsole.GetStockControlConfig(UserContext).AllowStockControl();
|
case Sbm.ItemType.StockLevel: return ItemType.ConfigOption_AllowStockControl;
|
||||||
case Sbm.ItemType.PriceSet:
|
case Sbm.ItemType.PriceSet:
|
||||||
case Sbm.ItemType.Price: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowPriceSets);
|
case Sbm.ItemType.Price: return ItemType.ConfigOption_AllowPriceSets;
|
||||||
case Sbm.ItemType.CommodityCustomer: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommodityCustomers);
|
case Sbm.ItemType.CommodityCustomer: return ItemType.ConfigOption_CommodityCustomers;
|
||||||
case Sbm.ItemType.CommoditySupplier: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.CommoditySuppliers);
|
case Sbm.ItemType.CommoditySupplier: return ItemType.ConfigOption_CommoditySuppliers;
|
||||||
//case Sbm.ItemType.Association:
|
//case Sbm.ItemType.Association:
|
||||||
case Sbm.ItemType.Transaction:
|
case Sbm.ItemType.Transaction:
|
||||||
case Sbm.ItemType.Requirement:
|
case Sbm.ItemType.Requirement:
|
||||||
case Sbm.ItemType.Constituent: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowTransactions);
|
case Sbm.ItemType.Constituent: return ItemType.ConfigOption_AllowTransactions;
|
||||||
//case Sbm.ItemType.SystemAccount:
|
//case Sbm.ItemType.SystemAccount:
|
||||||
//case Sbm.ItemType.SystemUser:
|
//case Sbm.ItemType.SystemUser:
|
||||||
//case Sbm.ItemType.SystemAccountUser:
|
//case Sbm.ItemType.SystemAccountUser:
|
||||||
case Sbm.ItemType.AssetCategory:
|
case Sbm.ItemType.AssetCategory:
|
||||||
case Sbm.ItemType.AssetCategoryProcess:
|
case Sbm.ItemType.AssetCategoryProcess:
|
||||||
case Sbm.ItemType.Asset:
|
case Sbm.ItemType.Asset:
|
||||||
case Sbm.ItemType.AssetProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowAssets);
|
case Sbm.ItemType.AssetProcess: return ItemType.ConfigOption_AllowAssets;
|
||||||
case Sbm.ItemType.VehicleClass:
|
case Sbm.ItemType.VehicleClass:
|
||||||
case Sbm.ItemType.Vehicle:
|
case Sbm.ItemType.Vehicle:
|
||||||
case Sbm.ItemType.VehicleEvent:
|
case Sbm.ItemType.VehicleEvent:
|
||||||
case Sbm.ItemType.VehicleFeature: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowVehicles);
|
case Sbm.ItemType.VehicleFeature: return ItemType.ConfigOption_AllowVehicles;
|
||||||
case Sbm.ItemType.CommodityProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
|
case Sbm.ItemType.CommodityProcess: return ItemType.ConfigOption_AllowProcesses;
|
||||||
case Sbm.ItemType.RequirementProcess: return configConsole.AllowOption(UserContext, Sbm.ConfigOption.AllowProcesses);
|
case Sbm.ItemType.RequirementProcess: return ItemType.ConfigOption_AllowProcesses;
|
||||||
//case Sbm.ItemType.Interface:
|
//case Sbm.ItemType.Interface:
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,19 +1,21 @@
|
|||||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||||
{
|
{
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
public class SbmSessionContext
|
public class SbmSessionContext : SacsSessionContext
|
||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmSessionContext(ushort index)
|
protected SbmSessionContext(ushort index, Sbm.Application application) : base(index)
|
||||||
{
|
{
|
||||||
Index = index;
|
Index = index;
|
||||||
|
Application = application;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public ushort Index { get; }
|
public Sbm.Application Application { get; private set; }
|
||||||
//public Sbm.Instance Instance { get; protected set; }
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
using Newtonsoft.Json;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
|
using Sarand.Net.Standard.Base.Helpers;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmSessionData
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private static long sessionIdxRoot = SacsRandomHelper.GetInt32(1000, 1999);
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
/// <summary>Protected constructor for deserialisation only.</summary>
|
||||||
|
protected SbmSessionData(long sessionIdx, int itemIdx, SbmSessionContext sessionContext)
|
||||||
|
{
|
||||||
|
SessionIdx = sessionIdx;
|
||||||
|
ItemIdx = itemIdx;
|
||||||
|
SessionContext = sessionContext;
|
||||||
|
userData = CreateUserData(SessionContext, null, null);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Primary constructor - on user login.
|
||||||
|
/// <para>SessionContext and UserAccount must be supplied.</para>
|
||||||
|
/// <para>Roles list is optional.</para>
|
||||||
|
/// </summary>
|
||||||
|
protected SbmSessionData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
|
||||||
|
{
|
||||||
|
SessionIdx = ++sessionIdxRoot;
|
||||||
|
ItemIdx = 1000;
|
||||||
|
SessionContext = sessionContext;
|
||||||
|
userData = CreateUserData(SessionContext, securityItemUser, affiliateUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
// Session and Item indexers.
|
||||||
|
public long SessionIdx { get; }
|
||||||
|
public int ItemIdx { get; private set; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public int NextItemIdx { get { return ++ItemIdx; } }
|
||||||
|
// Session context.
|
||||||
|
public SbmSessionContext SessionContext { get; }
|
||||||
|
[JsonIgnore]
|
||||||
|
public bool ValidUserSession { get { return SysId.IsValid(User.AffiliateId) && SysId.IsValid(User.AffiliateId); } }
|
||||||
|
[JsonIgnore]
|
||||||
|
public DbUpdateInfo DbUpdateInfo
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new DbUpdateInfo(User.AffiliateId, StringUtil.OnEmpty(User.DisplayName, User.EmailAddress), SbmSystem.ComputerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// User.
|
||||||
|
public class UserData
|
||||||
|
{
|
||||||
|
protected UserData() { }
|
||||||
|
protected UserData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
|
||||||
|
{
|
||||||
|
if (securityItemUser != null)
|
||||||
|
{
|
||||||
|
SecurityItemId = securityItemUser.Id;
|
||||||
|
}
|
||||||
|
if (affiliateUser != null)
|
||||||
|
{
|
||||||
|
AffiliateId = affiliateUser.Id;
|
||||||
|
Refresh(securityItemUser, affiliateUser);
|
||||||
|
if (sessionContext.Application == Sbm.Application.WebControl)
|
||||||
|
KeepLoggedIn = affiliateUser.KeepLoggedIn_Control;
|
||||||
|
else if (sessionContext.Application == Sbm.Application.WebPortal)
|
||||||
|
KeepLoggedIn = affiliateUser.KeepLoggedIn_Portal;
|
||||||
|
else Debugger.Break();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected UserData(UserData userData)
|
||||||
|
{
|
||||||
|
SecurityItemId = userData.SecurityItemId;
|
||||||
|
AffiliateId = userData.AffiliateId;
|
||||||
|
Title = userData.Title;
|
||||||
|
FirstName = userData.FirstName;
|
||||||
|
LastName = userData.LastName;
|
||||||
|
DisplayName = userData.DisplayName;
|
||||||
|
EmailAddress = userData.EmailAddress;
|
||||||
|
KeepLoggedIn = userData.KeepLoggedIn;
|
||||||
|
}
|
||||||
|
// Properties.
|
||||||
|
public SysId SecurityItemId { get; protected set; }
|
||||||
|
public SysId AffiliateId { get; protected set; }
|
||||||
|
public String Title { get; protected set; }
|
||||||
|
public String FirstName { get; protected set; }
|
||||||
|
public String LastName { get; protected set; }
|
||||||
|
public String DisplayName { get; protected set; }
|
||||||
|
public String EmailAddress { get; protected set; }
|
||||||
|
public bool KeepLoggedIn { get; protected set; }
|
||||||
|
public bool UserAccountSupplied { get; protected set; }
|
||||||
|
// Refresh properties.
|
||||||
|
protected bool Refresh(SaSecurityItem securityItemUser, SbmAffiliate affiliateUser)
|
||||||
|
{
|
||||||
|
// Check that user matches the session.
|
||||||
|
if (!SysId.IsValid(SecurityItemId) || !SysId.IsValid(securityItemUser?.Id ?? null) || !SecurityItemId.Equals(securityItemUser.Id)) return false;
|
||||||
|
if (!SysId.IsValid(AffiliateId) || !SysId.IsValid(affiliateUser?.Id ?? null) || !AffiliateId.Equals(affiliateUser.Id)) return false;
|
||||||
|
// Refresh properties.
|
||||||
|
EmailAddress = securityItemUser.EmailAddress;
|
||||||
|
Title = affiliateUser.Title;
|
||||||
|
FirstName = affiliateUser.FirstName;
|
||||||
|
LastName = affiliateUser.LastName;
|
||||||
|
DisplayName = affiliateUser.GetDisplayName();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
protected abstract UserData CreateUserData(SbmSessionContext sessionContext, SaSecurityItem securityItemUser, SbmAffiliate affiliateUser);
|
||||||
|
private UserData userData;
|
||||||
|
public UserData User { get { return userData; } }
|
||||||
|
/// <summary>User - JSON deserialisation route.</summary>
|
||||||
|
protected void SetUser(UserData user)
|
||||||
|
{
|
||||||
|
if (this.userData != null && User.UserAccountSupplied)
|
||||||
|
throw new NotSupportedException("Session User cannot be replaced.");
|
||||||
|
this.userData = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ using Sarand.Net.Standard.Base.Bus;
|
|||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using Sarand.Net.Standard.Base.Dbas;
|
using Sarand.Net.Standard.Base.Dbas;
|
||||||
using Sarand.Net.Standard.Base.ItemOptions;
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
||||||
@@ -96,7 +97,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
userContext.RefreshUser(affiliateUser, userSupervisedOwners);
|
userContext.RefreshUser(affiliateUser, userSupervisedOwners);
|
||||||
|
|
||||||
// Populate security rights.
|
// Populate security rights.
|
||||||
SecurityProfile.RefreshProfile(SbmGlobals.Application.GetSecurityConsole(UserContext), userId, securityRights);
|
using (SbmConfigConsole configConsole = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext))
|
||||||
|
using (SaSecurityConsole securityConsole = SbmGlobals.Application.CreateSecurityConsole(UserContext))
|
||||||
|
{
|
||||||
|
SecurityProfile.RefreshProfile(configConsole, securityConsole, userId, securityRights);
|
||||||
|
}
|
||||||
|
|
||||||
// Reinstate previous owner if defined and verify that it is in the supervised list.
|
// Reinstate previous owner if defined and verify that it is in the supervised list.
|
||||||
SysId affiliateIdOwner = UserContext.Organisation.AffiliateId;
|
SysId affiliateIdOwner = UserContext.Organisation.AffiliateId;
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// R e g i s t e r C o d e T y p e s
|
// R e g i s t e r C o d e T y p e s
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public static void RegisterCodeTypes(SaCodeTypeConsole codeTypeConsole, SbmUserContext userContext)
|
public static void RegisterCodeTypes(SbmConfigConsole configConsole, SaCodeTypeConsole codeTypeConsole, SbmUserContext userContext)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.Application.GetConfigConsole(userContext.SessionContext);
|
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// C o m m o d i t i e s
|
// C o m m o d i t i e s
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
}
|
}
|
||||||
public static List<TypeCodeDesc> GetCodesOfType(SbmUserContext userContext, Sbm.SystemCode systemCode)
|
public static List<TypeCodeDesc> GetCodesOfType(SbmUserContext userContext, Sbm.SystemCode systemCode)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
SbmConfigConsole configConsole = null; // SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
||||||
switch (systemCode)
|
switch (systemCode)
|
||||||
{
|
{
|
||||||
case Sbm.SystemCode.ItemType:
|
case Sbm.SystemCode.ItemType:
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmUserContext(SbmSessionContext sessionContext)
|
protected SbmUserContext(SbmSessionContext sessionContext)
|
||||||
{
|
{
|
||||||
SessionContext = sessionContext;
|
SessionContext = sessionContext;
|
||||||
organisationData = new OrganisationData_Internal();
|
organisationData = new OrganisationData_Internal();
|
||||||
@@ -307,14 +307,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.App
|
|||||||
ItemId associationItemId_Owner = new ItemId((short)Sbm.ItemType.Association, organisationData.AssociationId);
|
ItemId associationItemId_Owner = new ItemId((short)Sbm.ItemType.Association, organisationData.AssociationId);
|
||||||
if (!organisationData.configOptionsCache.ItemIdRef.Id.Equals(affiliateItemId_Owner))
|
if (!organisationData.configOptionsCache.ItemIdRef.Id.Equals(affiliateItemId_Owner))
|
||||||
{
|
{
|
||||||
SaItemOptionConsole itemOptionConsole = SbmGlobals.Application.GetItemOptionConsole(this);
|
using (SaItemOptionConsole itemOptionConsole = SbmGlobals.Application.CreateItemOptionConsole(this))
|
||||||
organisationData.configOptionsCache.Clear();
|
|
||||||
if (itemOptionConsole != null)
|
|
||||||
{
|
{
|
||||||
// Retrieve the options for this association.
|
organisationData.configOptionsCache.Clear();
|
||||||
organisationData.configOptionsCache.Reset(associationItemId_Owner, affiliateItemId_Owner);
|
if (itemOptionConsole != null)
|
||||||
organisationData.configOptionsCache.ItemOptions.AddRange(itemOptionConsole.GetItemOptionsForItem(associationItemId_Owner));
|
{
|
||||||
SaLogger.Debug(fn + " Populated organisation options: " + organisationData.configOptionsCache.ItemOptions.Count);
|
// Retrieve the options for this association.
|
||||||
|
organisationData.configOptionsCache.Reset(associationItemId_Owner, affiliateItemId_Owner);
|
||||||
|
organisationData.configOptionsCache.ItemOptions.AddRange(itemOptionConsole.GetItemOptionsForItem(associationItemId_Owner));
|
||||||
|
SaLogger.Debug(fn + " Populated organisation options: " + organisationData.configOptionsCache.ItemOptions.Count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,13 +280,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|||||||
{
|
{
|
||||||
// Only populated when needed as reads Code Types from db.
|
// Only populated when needed as reads Code Types from db.
|
||||||
contexts_StockCategoryAction = new List<CodeDesc>();
|
contexts_StockCategoryAction = new List<CodeDesc>();
|
||||||
codes_StockCategoryAction = SbmGlobals.GetCodeTypeConsole(UserContext).GetCodeDescsForCodeType(SbmSystem.GetCodeTypeCode(Sbm.ApplCodeType.CommodityCategory));
|
using (SaCodeTypeConsole codeTypeConsole = SbmGlobals.Application.CreateCodeTypeConsole(UserContext))
|
||||||
foreach (CodeDesc commodityCategory in codes_StockCategoryAction)
|
|
||||||
{
|
{
|
||||||
// Ignore categories where code is same as description.
|
codes_StockCategoryAction = codeTypeConsole.GetCodeDescsForCodeType(SbmSystem.GetCodeTypeCode(Sbm.ApplCodeType.CommodityCategory));
|
||||||
// We're only interested in the ones which have been given a description.
|
foreach (CodeDesc commodityCategory in codes_StockCategoryAction)
|
||||||
if (commodityCategory.Code.EqualsCI(commodityCategory.Desc)) continue;
|
{
|
||||||
contexts_StockCategoryAction.Add(commodityCategory);
|
// Ignore categories where code is same as description.
|
||||||
|
// We're only interested in the ones which have been given a description.
|
||||||
|
if (commodityCategory.Code.EqualsCI(commodityCategory.Desc)) continue;
|
||||||
|
contexts_StockCategoryAction.Add(commodityCategory);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new List<CodeDesc>(contexts_StockCategoryAction);
|
return new List<CodeDesc>(contexts_StockCategoryAction);
|
||||||
|
|||||||
@@ -329,6 +329,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|||||||
// Data members.
|
// Data members.
|
||||||
private readonly Data data = new Data();
|
private readonly Data data = new Data();
|
||||||
public static readonly Byte Flag_Prospect = 0x01;
|
public static readonly Byte Flag_Prospect = 0x01;
|
||||||
|
public static readonly Byte Flag_KeepLoggedIn_Portal = 0x02;
|
||||||
|
public static readonly Byte Flag_KeepLoggedIn_Control = 0x03;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -697,6 +699,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|||||||
get { return GetFlag(Flag_Prospect); }
|
get { return GetFlag(Flag_Prospect); }
|
||||||
set { SetFlag(Flag_Prospect, value); }
|
set { SetFlag(Flag_Prospect, value); }
|
||||||
}
|
}
|
||||||
|
public bool KeepLoggedIn_Portal
|
||||||
|
{
|
||||||
|
get { return GetFlag(Flag_KeepLoggedIn_Portal); }
|
||||||
|
set { SetFlag(Flag_KeepLoggedIn_Portal, value); }
|
||||||
|
}
|
||||||
|
public bool KeepLoggedIn_Control
|
||||||
|
{
|
||||||
|
get { return GetFlag(Flag_KeepLoggedIn_Control); }
|
||||||
|
set { SetFlag(Flag_KeepLoggedIn_Control, value); }
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// A s s o c i a t e d D a t a E l e m e n t s
|
// A s s o c i a t e d D a t a E l e m e n t s
|
||||||
|
|||||||
@@ -1872,83 +1872,85 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|||||||
// Utilities.
|
// Utilities.
|
||||||
public List<StringPair> GetDisplayValues(SbmUserContext userContext)
|
public List<StringPair> GetDisplayValues(SbmUserContext userContext)
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.Application.GetConfigConsole(userContext.SessionContext);
|
|
||||||
SbmAccountMgr accountMgr = null;
|
SbmAccountMgr accountMgr = null;
|
||||||
List<StringPair> lValue = new List<StringPair>();
|
List<StringPair> lValue = new List<StringPair>();
|
||||||
// Commodities to exclude.
|
using (SbmConfigConsole configConsole = SbmGlobals.Application.CreateConfigConsole(userContext.SessionContext))
|
||||||
if (IncludedIds.Count > 0) lValue.Add("Included commodities", IncludedIds.Count.ToString());
|
|
||||||
if (ExcludedIds.Count > 0) lValue.Add("Excluded commodities", ExcludedIds.Count.ToString());
|
|
||||||
// Commodity type.
|
|
||||||
if (CommodityType > 0) lValue.Add("Type", SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.CommodityType).GetDescForType(CommodityType, CommodityType.ToString()));
|
|
||||||
else if (CommodityType == Sbm.CommodityType.AnyProduct) lValue.Add("Type", "Any product");
|
|
||||||
if (StockItemsOnly) lValue.Add("Stock items only", "True");
|
|
||||||
// Commodity code.
|
|
||||||
if (!StringUtil.IsEmpty(CodeFull)) lValue.Add("Code", CodeFull);
|
|
||||||
else if (!StringUtil.IsEmpty(CodePartial)) lValue.Add("Code contains", CodePartial);
|
|
||||||
// Drawing number.
|
|
||||||
if (!StringUtil.IsEmpty(DrawingNoFull)) lValue.Add("Drawing no", DrawingNoFull);
|
|
||||||
else if (!StringUtil.IsEmpty(DrawingNoPartial)) lValue.Add("Drawing no starts", DrawingNoPartial);
|
|
||||||
if (!StringUtil.IsEmpty(DrawingIssueFull)) lValue.Add("Drawing issue", DrawingIssueFull);
|
|
||||||
else if (!StringUtil.IsEmpty(DrawingIssuePartial)) lValue.Add("Drawing issue starts", DrawingIssuePartial);
|
|
||||||
// Commodity description.
|
|
||||||
if (!StringUtil.IsEmpty(DescBriefFull)) lValue.Add("Description", DescBriefFull);
|
|
||||||
if (!StringUtil.IsEmpty(DescBriefPartial)) lValue.Add("Description starts", DescBriefPartial);
|
|
||||||
// Category.
|
|
||||||
if (Categories.Count > 0) lValue.Add("Categories", Categories.Concat(","));
|
|
||||||
// Catalog reference.
|
|
||||||
if (!StringUtil.IsEmpty(CatalogRefPartial)) lValue.Add("Catalog ref start", CatalogRefPartial);
|
|
||||||
// Codings.
|
|
||||||
if (!StringUtil.IsEmpty(RangeCode)) lValue.Add("Range code", RangeCode);
|
|
||||||
if (!StringUtil.IsEmpty(ColourCode)) lValue.Add("Colour code", ColourCode);
|
|
||||||
if (!StringUtil.IsEmpty(SourceCode)) lValue.Add("Source code", SourceCode);
|
|
||||||
if (!StringUtil.IsEmpty(SupplyMethodCode)) lValue.Add("SupplyMethod code", SupplyMethodCode);
|
|
||||||
if (!StringUtil.IsEmpty(HandlingCode)) lValue.Add("Handling code", HandlingCode);
|
|
||||||
if (!StringUtil.IsEmpty(DeliveryCode)) lValue.Add("Delivery code", DeliveryCode);
|
|
||||||
if (!StringUtil.IsEmpty(MaterialCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_MaterialCode, "Material") + " code", MaterialCode);
|
|
||||||
if (!StringUtil.IsEmpty(FinishCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_FinishCode, "Finish") + " code", FinishCode);
|
|
||||||
if (!StringUtil.IsEmpty(PromotionCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_PromotionCode, "Promotion") + " code", PromotionCode);
|
|
||||||
// Price sets.
|
|
||||||
if (PriceSetIdsIncluded.Count > 0) lValue.Add("Included in price sets", PriceSetIdsIncluded.Count.ToString());
|
|
||||||
if (PriceSetIdsExcluded.Count > 0) lValue.Add("Excluded from price sets", PriceSetIdsExcluded.Count.ToString());
|
|
||||||
// Customer.
|
|
||||||
if (SysId.IsValid(AssociationIdCustomer))
|
|
||||||
{
|
{
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
// Commodities to exclude.
|
||||||
lValue.Add("Customer", accountMgr.GetAssociationTargetName(AssociationIdCustomer));
|
if (IncludedIds.Count > 0) lValue.Add("Included commodities", IncludedIds.Count.ToString());
|
||||||
|
if (ExcludedIds.Count > 0) lValue.Add("Excluded commodities", ExcludedIds.Count.ToString());
|
||||||
|
// Commodity type.
|
||||||
|
if (CommodityType > 0) lValue.Add("Type", SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.CommodityType).GetDescForType(CommodityType, CommodityType.ToString()));
|
||||||
|
else if (CommodityType == Sbm.CommodityType.AnyProduct) lValue.Add("Type", "Any product");
|
||||||
|
if (StockItemsOnly) lValue.Add("Stock items only", "True");
|
||||||
|
// Commodity code.
|
||||||
|
if (!StringUtil.IsEmpty(CodeFull)) lValue.Add("Code", CodeFull);
|
||||||
|
else if (!StringUtil.IsEmpty(CodePartial)) lValue.Add("Code contains", CodePartial);
|
||||||
|
// Drawing number.
|
||||||
|
if (!StringUtil.IsEmpty(DrawingNoFull)) lValue.Add("Drawing no", DrawingNoFull);
|
||||||
|
else if (!StringUtil.IsEmpty(DrawingNoPartial)) lValue.Add("Drawing no starts", DrawingNoPartial);
|
||||||
|
if (!StringUtil.IsEmpty(DrawingIssueFull)) lValue.Add("Drawing issue", DrawingIssueFull);
|
||||||
|
else if (!StringUtil.IsEmpty(DrawingIssuePartial)) lValue.Add("Drawing issue starts", DrawingIssuePartial);
|
||||||
|
// Commodity description.
|
||||||
|
if (!StringUtil.IsEmpty(DescBriefFull)) lValue.Add("Description", DescBriefFull);
|
||||||
|
if (!StringUtil.IsEmpty(DescBriefPartial)) lValue.Add("Description starts", DescBriefPartial);
|
||||||
|
// Category.
|
||||||
|
if (Categories.Count > 0) lValue.Add("Categories", Categories.Concat(","));
|
||||||
|
// Catalog reference.
|
||||||
|
if (!StringUtil.IsEmpty(CatalogRefPartial)) lValue.Add("Catalog ref start", CatalogRefPartial);
|
||||||
|
// Codings.
|
||||||
|
if (!StringUtil.IsEmpty(RangeCode)) lValue.Add("Range code", RangeCode);
|
||||||
|
if (!StringUtil.IsEmpty(ColourCode)) lValue.Add("Colour code", ColourCode);
|
||||||
|
if (!StringUtil.IsEmpty(SourceCode)) lValue.Add("Source code", SourceCode);
|
||||||
|
if (!StringUtil.IsEmpty(SupplyMethodCode)) lValue.Add("SupplyMethod code", SupplyMethodCode);
|
||||||
|
if (!StringUtil.IsEmpty(HandlingCode)) lValue.Add("Handling code", HandlingCode);
|
||||||
|
if (!StringUtil.IsEmpty(DeliveryCode)) lValue.Add("Delivery code", DeliveryCode);
|
||||||
|
if (!StringUtil.IsEmpty(MaterialCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_MaterialCode, "Material") + " code", MaterialCode);
|
||||||
|
if (!StringUtil.IsEmpty(FinishCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_FinishCode, "Finish") + " code", FinishCode);
|
||||||
|
if (!StringUtil.IsEmpty(PromotionCode)) lValue.Add(configConsole.GetAttributeCaption(userContext, SbmDbDfn.ColumnIdx.Commodity_PromotionCode, "Promotion") + " code", PromotionCode);
|
||||||
|
// Price sets.
|
||||||
|
if (PriceSetIdsIncluded.Count > 0) lValue.Add("Included in price sets", PriceSetIdsIncluded.Count.ToString());
|
||||||
|
if (PriceSetIdsExcluded.Count > 0) lValue.Add("Excluded from price sets", PriceSetIdsExcluded.Count.ToString());
|
||||||
|
// Customer.
|
||||||
|
if (SysId.IsValid(AssociationIdCustomer))
|
||||||
|
{
|
||||||
|
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
||||||
|
lValue.Add("Customer", accountMgr.GetAssociationTargetName(AssociationIdCustomer));
|
||||||
|
}
|
||||||
|
if (!StringUtil.IsEmpty(CustomerName)) lValue.Add("Customer name starts", CustomerName);
|
||||||
|
if (!StringUtil.IsEmpty(SupplierName)) lValue.Add("Supplier name starts", SupplierName);
|
||||||
|
if (!StringUtil.IsEmpty(SalesOrderRef)) lValue.Add("SO reference starts", SalesOrderRef);
|
||||||
|
if (!StringUtil.IsEmpty(PurchaseOrderRef)) lValue.Add("PO reference starts", PurchaseOrderRef);
|
||||||
|
|
||||||
|
// Transaction.
|
||||||
|
if (!StringUtil.IsEmpty(OrderRef)) lValue.Add("Transaction reference", OrderRef);
|
||||||
|
|
||||||
|
// Stock:
|
||||||
|
if (StockLocationFilter == Sbm.LocationFilter.Sales) lValue.Add("Stock location", "Sales locations only");
|
||||||
|
else if (StockLocationFilter == Sbm.LocationFilter.Calc) lValue.Add("Stock location", "Calculated locations only");
|
||||||
|
else if (StockLocationFilter == Sbm.LocationFilter.All) lValue.Add("Stock location", "All locations");
|
||||||
|
if (SysId.IsValid(LocationIdStock)) lValue.Add("Stock location", SysId.ToString(LocationIdStock));
|
||||||
|
if (DateUtil.IsValid(StockSoldFrom)) lValue.Add("Stock sold from", DateUtil.Format(StockSoldFrom, "d-MMM-yyyy"));
|
||||||
|
if (DateUtil.IsValid(StockSoldTo)) lValue.Add("Stock sold to", DateUtil.Format(StockSoldTo, "d-MMM-yyyy"));
|
||||||
|
if (DateUtil.IsValid(ProjectedSalesFrom)) lValue.Add("Proj sales from", DateUtil.Format(ProjectedSalesFrom, "d-MMM-yyyy"));
|
||||||
|
if (DateUtil.IsValid(ProjectedSalesTo)) lValue.Add("Proj sales to", DateUtil.Format(ProjectedSalesTo, "d-MMM-yyyy"));
|
||||||
|
|
||||||
|
if (StockLevelMin > decimal.MinValue) lValue.Add("Stock level >= ", StockLevelMin.ToString("N2"));
|
||||||
|
if (StockLevelMax > decimal.MinValue) lValue.Add("Stock level <= ", StockLevelMax.ToString("N2"));
|
||||||
|
|
||||||
|
// Commodities with definitions for Customer.
|
||||||
|
if (SysId.IsValid(AssociationIdCommodityCustomer))
|
||||||
|
{
|
||||||
|
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
||||||
|
lValue.Add("Commodity definitions for customer", accountMgr.GetAssociationTargetName(AssociationIdCommodityCustomer));
|
||||||
|
}
|
||||||
|
if (!StringUtil.IsEmpty(AccountCodeCommodityCustomer))
|
||||||
|
lValue.Add("Commodity definitions for customer", AccountCodeCommodityCustomer);
|
||||||
|
|
||||||
|
// Commodity status category.
|
||||||
|
if (StatusCat == StatusCat.Current)
|
||||||
|
lValue.Add("Status", "Current");
|
||||||
}
|
}
|
||||||
if (!StringUtil.IsEmpty(CustomerName)) lValue.Add("Customer name starts", CustomerName);
|
|
||||||
if (!StringUtil.IsEmpty(SupplierName)) lValue.Add("Supplier name starts", SupplierName);
|
|
||||||
if (!StringUtil.IsEmpty(SalesOrderRef)) lValue.Add("SO reference starts", SalesOrderRef);
|
|
||||||
if (!StringUtil.IsEmpty(PurchaseOrderRef)) lValue.Add("PO reference starts", PurchaseOrderRef);
|
|
||||||
|
|
||||||
// Transaction.
|
|
||||||
if (!StringUtil.IsEmpty(OrderRef)) lValue.Add("Transaction reference", OrderRef);
|
|
||||||
|
|
||||||
// Stock:
|
|
||||||
if (StockLocationFilter == Sbm.LocationFilter.Sales) lValue.Add("Stock location", "Sales locations only");
|
|
||||||
else if (StockLocationFilter == Sbm.LocationFilter.Calc) lValue.Add("Stock location", "Calculated locations only");
|
|
||||||
else if (StockLocationFilter == Sbm.LocationFilter.All) lValue.Add("Stock location", "All locations");
|
|
||||||
if (SysId.IsValid(LocationIdStock)) lValue.Add("Stock location", SysId.ToString(LocationIdStock));
|
|
||||||
if (DateUtil.IsValid(StockSoldFrom)) lValue.Add("Stock sold from", DateUtil.Format(StockSoldFrom, "d-MMM-yyyy"));
|
|
||||||
if (DateUtil.IsValid(StockSoldTo)) lValue.Add("Stock sold to", DateUtil.Format(StockSoldTo, "d-MMM-yyyy"));
|
|
||||||
if (DateUtil.IsValid(ProjectedSalesFrom)) lValue.Add("Proj sales from", DateUtil.Format(ProjectedSalesFrom, "d-MMM-yyyy"));
|
|
||||||
if (DateUtil.IsValid(ProjectedSalesTo)) lValue.Add("Proj sales to", DateUtil.Format(ProjectedSalesTo, "d-MMM-yyyy"));
|
|
||||||
|
|
||||||
if (StockLevelMin > decimal.MinValue) lValue.Add("Stock level >= ", StockLevelMin.ToString("N2"));
|
|
||||||
if (StockLevelMax > decimal.MinValue) lValue.Add("Stock level <= ", StockLevelMax.ToString("N2"));
|
|
||||||
|
|
||||||
// Commodities with definitions for Customer.
|
|
||||||
if (SysId.IsValid(AssociationIdCommodityCustomer))
|
|
||||||
{
|
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
|
||||||
lValue.Add("Commodity definitions for customer", accountMgr.GetAssociationTargetName(AssociationIdCommodityCustomer));
|
|
||||||
}
|
|
||||||
if (!StringUtil.IsEmpty(AccountCodeCommodityCustomer))
|
|
||||||
lValue.Add("Commodity definitions for customer", AccountCodeCommodityCustomer);
|
|
||||||
|
|
||||||
// Commodity status category.
|
|
||||||
if (StatusCat == StatusCat.Current)
|
|
||||||
lValue.Add("Status", "Current");
|
|
||||||
|
|
||||||
// Portfolio:
|
// Portfolio:
|
||||||
//PortfolioIdInclude;
|
//PortfolioIdInclude;
|
||||||
|
|||||||
@@ -857,9 +857,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Bus
|
|||||||
// Nov-08 Current thinking is that the only differences is whether the 'In Progress' date has been specified and whether that should be used in preference to the 'Raised' date.
|
// Nov-08 Current thinking is that the only differences is whether the 'In Progress' date has been specified and whether that should be used in preference to the 'Raised' date.
|
||||||
if (DateUtil.IsValid(inProgress) && (transactionStatusCat == SbmTransaction.StatusCat.Open || transactionStatusCat == SbmTransaction.StatusCat.Closed))
|
if (DateUtil.IsValid(inProgress) && (transactionStatusCat == SbmTransaction.StatusCat.Open || transactionStatusCat == SbmTransaction.StatusCat.Closed))
|
||||||
{
|
{
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
using (SbmConfigConsole configConsole = SbmGlobals.Application.CreateConfigConsole(userContext.SessionContext))
|
||||||
if (configConsole != null && configConsole.UseInProgressTaxDateAsTaxPoint(userContext, transactionType))
|
{
|
||||||
return inProgress;
|
if (configConsole != null && configConsole.UseInProgressTaxDateAsTaxPoint(userContext, transactionType))
|
||||||
|
return inProgress;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, use 'Raised' date.
|
// Otherwise, use 'Raised' date.
|
||||||
if (DateUtil.IsValid(raised))
|
if (DateUtil.IsValid(raised))
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Helpers;
|
||||||
|
using Sarand.Net.Standard.Base.Email;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Consoles
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmEmailConfig : SaEmailConfig
|
||||||
|
{
|
||||||
|
public SbmEmailConfig(String context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
public abstract class SbmEmailConsole : SaEmailConsole
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Protected construction.
|
||||||
|
protected SbmEmailConsole(SbmEmailConfig emailConfig)
|
||||||
|
{
|
||||||
|
EmailConfig = emailConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Properties.
|
||||||
|
public SbmEmailConfig EmailConfig { get; }
|
||||||
|
public static String EmailTag_Header { get; } = "[#Email.Header]";
|
||||||
|
public static String EmailTag_Footer { get; } = "[#Email.Footer]";
|
||||||
|
public static String EmailTag_Caption { get; } = "[#Email.Caption]";
|
||||||
|
public static String EmailTag_MainStylesheet { get; } = "[#Email.MainStylesheet]";
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>
|
||||||
|
/// Replace dynamic tags in email message body.
|
||||||
|
/// <para></para>
|
||||||
|
/// </summary>
|
||||||
|
public void ReplaceDynamicEmailBodyTags(SaEmailData emailData, SbmSessionData sessionData)
|
||||||
|
{
|
||||||
|
// Replace core tags, eg. main stylesheet.
|
||||||
|
SaEmailConsole.ReplaceDynamicEmailTags(emailData);
|
||||||
|
|
||||||
|
// Replace tags known to the web application.
|
||||||
|
// Main stylesheet.
|
||||||
|
if (EmailContainsTag(emailData, EmailTag_MainStylesheet))
|
||||||
|
{
|
||||||
|
// Tag replacement is expanded to avoid reading main stylesheet resource unless required.
|
||||||
|
ReplaceDynamicEmailTag(emailData, EmailTag_MainStylesheet, "<style>\n" + SbmResourceHelper.GetTextResource(SbmResourceHelper.TextResource.Email_Main_Css) + "</style>");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Partial content - Header.
|
||||||
|
if (EmailContainsTag(emailData, EmailTag_Header))
|
||||||
|
{
|
||||||
|
// Tag replacement is expanded to avoid reading Header resource unless required.
|
||||||
|
ReplaceDynamicEmailTag(emailData, EmailTag_Header, SbmResourceHelper.GetTextResource(SbmResourceHelper.TextResource.Email_Header_Html));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Partial content - Footer.
|
||||||
|
if (EmailContainsTag(emailData, EmailTag_Footer))
|
||||||
|
{
|
||||||
|
// Tag replacement is expanded to avoid reading Footer resource unless required.
|
||||||
|
ReplaceDynamicEmailTag(emailData, EmailTag_Footer, SbmResourceHelper.GetTextResource(SbmResourceHelper.TextResource.Email_Footer_Html));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
using Microsoft.AspNetCore.Identity;
|
||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.App;
|
||||||
|
using Sarand.Net.Standard.Base.Security;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Helpers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public class SbmPasswordHelper
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Configuration parameters.
|
||||||
|
public class PasswordParams
|
||||||
|
{
|
||||||
|
public int MinLength = 8;
|
||||||
|
public int MinLengthNoComplexity = 12;
|
||||||
|
}
|
||||||
|
public static PasswordParams Params { get; } = new PasswordParams();
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
/// <summary>Validate password against parameters.</summary>
|
||||||
|
public static bool IsValidPassword(String password)
|
||||||
|
{
|
||||||
|
return GetPasswordStrength(password) >= 4;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Assess the password strength - 4+ is valid.
|
||||||
|
/// <para>0 - Blank</para>
|
||||||
|
/// <para>1 - < min length - 2 [red]</para>
|
||||||
|
/// <para>1 - < min length and only 1 character type [red]</para>
|
||||||
|
/// <para>2 - < min length and only 2 character types [red]</para>
|
||||||
|
/// <para>2 - < min length without complexity - 2 and only 1 character type [red]</para>
|
||||||
|
/// <para>3 - < min length, min length with 3 character types [amber]</para>
|
||||||
|
/// <para>3 - Min length without complexity - 2 [amber]</para>
|
||||||
|
/// <para>3 - Other invalid passwords [amber]</para>
|
||||||
|
/// <para>4 - Min length with 4 character types [green]</para>
|
||||||
|
/// <para>4 - Min length without complexity [green]</para>
|
||||||
|
/// <para>5 - Min lenth + 2 with 4 character types [green]</para>
|
||||||
|
/// <para>5 - Min length without complexity with 3 character types [green]</para>
|
||||||
|
/// </summary>
|
||||||
|
public static int GetPasswordStrength(String password)
|
||||||
|
{
|
||||||
|
String fn = "PasswordHelper.GetPasswordStrength";
|
||||||
|
|
||||||
|
// 0 - Blank.
|
||||||
|
if (StringUtil.IsEmpty(password)) return 0;
|
||||||
|
|
||||||
|
// Count number of different types of character.
|
||||||
|
int characterTypeCount = 0;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (Regex.Matches(password, "[A-Z]").Count > 0) characterTypeCount++;
|
||||||
|
if (Regex.Matches(password, "[a-z]").Count > 0) characterTypeCount++;
|
||||||
|
if (Regex.Matches(password, "[0-9]").Count > 0) characterTypeCount++;
|
||||||
|
if (Regex.Matches(password, "[^a-zA-Z0-9]").Count > 0) characterTypeCount++;
|
||||||
|
}
|
||||||
|
catch (Exception exc)
|
||||||
|
{
|
||||||
|
SaLogger.Debug(fn + " " + ExceptionUtil.GetLogMessage(exc));
|
||||||
|
}
|
||||||
|
int passwordLength = StringUtil.GetLength(password);
|
||||||
|
|
||||||
|
// 1 - Less than min length - 2;
|
||||||
|
if (passwordLength < Params.MinLength - 2)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// 1 - Less than min length and only 1 character type.
|
||||||
|
if (passwordLength < Params.MinLength && characterTypeCount == 1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// 2 - Less than min length and only 2 character types.
|
||||||
|
if (passwordLength < Params.MinLength && characterTypeCount == 2)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
// 2 - Less than min length without complexity - 2 and only 1 character type.
|
||||||
|
if (passwordLength < Params.MinLengthNoComplexity - 2 && characterTypeCount == 1)
|
||||||
|
return 2;
|
||||||
|
|
||||||
|
// 3 - Less than minimum length.
|
||||||
|
if (passwordLength < Params.MinLength)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
// 3 - Minimum length with only 3 character types.
|
||||||
|
if (passwordLength >= Params.MinLength && passwordLength < Params.MinLengthNoComplexity && characterTypeCount == 3)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
// 3 - Minimum length without complexity - 2 with less than 4 character types.
|
||||||
|
if (passwordLength >= Params.MinLengthNoComplexity - 2 && passwordLength < Params.MinLengthNoComplexity && characterTypeCount < 4)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
// 3 Catch-all - ensure only valid passwords score 4 or more.
|
||||||
|
if (passwordLength < Params.MinLengthNoComplexity && characterTypeCount < 4)
|
||||||
|
return 3;
|
||||||
|
|
||||||
|
// 4 - Min length with 4 character types.
|
||||||
|
if (passwordLength < Params.MinLengthNoComplexity)
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
// 4 - Min length without complexity.
|
||||||
|
if (passwordLength >= Params.MinLengthNoComplexity && passwordLength < Params.MinLengthNoComplexity + 2 && characterTypeCount < 4)
|
||||||
|
return 4;
|
||||||
|
|
||||||
|
// 5 - Anything more complex.
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
private static PasswordHasher<SaSecurityItem> passwordHasher = new PasswordHasher<SaSecurityItem>();
|
||||||
|
/// <summary>Get the hashed value that corresponds to the password.</summary>
|
||||||
|
public static String GetPasswordHash(SaSecurityItem securityItemUser, String password)
|
||||||
|
{
|
||||||
|
return passwordHasher.HashPassword(securityItemUser, password);
|
||||||
|
}
|
||||||
|
/// <summary>Verify password against hashed value stored against user account.</summary>
|
||||||
|
public static bool VerifyHashedPassword(SaSecurityItem securityItemUser, String password)
|
||||||
|
{
|
||||||
|
return passwordHasher.VerifyHashedPassword(securityItemUser, securityItemUser.PasswordHash, password) != PasswordVerificationResult.Failed;
|
||||||
|
}
|
||||||
|
/// <summary>Verify password against hashed value with user account as reference.</summary>
|
||||||
|
public static bool VerifyHashedPassword(SaSecurityItem securityItemUser, String password, String passwordHashed)
|
||||||
|
{
|
||||||
|
return passwordHasher.VerifyHashedPassword(securityItemUser, passwordHashed, password) != PasswordVerificationResult.Failed;
|
||||||
|
}
|
||||||
|
/// <summary>Check whether the password needs rehashing.</summary>
|
||||||
|
public static bool PasswordRequiresRehash(SaSecurityItem securityItemUser, String password)
|
||||||
|
{
|
||||||
|
return passwordHasher.VerifyHashedPassword(securityItemUser, securityItemUser.PasswordHash, password) == PasswordVerificationResult.SuccessRehashNeeded;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
using Sarand.Net.Standard.Base.Helpers;
|
||||||
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Helpers
|
||||||
|
{
|
||||||
|
//=======================================================================
|
||||||
|
public static class SbmResourceHelper
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Definitions.
|
||||||
|
public enum TextResource
|
||||||
|
{
|
||||||
|
// Email stylesheets.
|
||||||
|
Email_Main_Css,
|
||||||
|
// Email partial content.
|
||||||
|
Email_Header_Html,
|
||||||
|
Email_Footer_Html,
|
||||||
|
// Email templates.
|
||||||
|
Email_ContactUs_Html,
|
||||||
|
Email_Signup_Activate_Html,
|
||||||
|
Email_Signup_Welcome_Html,
|
||||||
|
Email_RequestPassword_Html,
|
||||||
|
// Data - CSV files etc.
|
||||||
|
}
|
||||||
|
public enum ImageResource
|
||||||
|
{
|
||||||
|
BusinessMgr_logo_h75_png,
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Text resources.
|
||||||
|
public static String GetTextResource(TextResource textResource)
|
||||||
|
{
|
||||||
|
String partialPath = "";
|
||||||
|
String resourceFilename = "";
|
||||||
|
switch (textResource)
|
||||||
|
{
|
||||||
|
// Email stylesheet.
|
||||||
|
case TextResource.Email_Main_Css:
|
||||||
|
resourceFilename = "sax-email-main.css";
|
||||||
|
break;
|
||||||
|
// Email partial content.
|
||||||
|
case TextResource.Email_Header_Html:
|
||||||
|
resourceFilename = "sax-email-header.html";
|
||||||
|
break;
|
||||||
|
case TextResource.Email_Footer_Html:
|
||||||
|
resourceFilename = "sax-email-footer.html";
|
||||||
|
break;
|
||||||
|
// Email templates.
|
||||||
|
case TextResource.Email_ContactUs_Html:
|
||||||
|
resourceFilename = "sax-email-contact-us.html";
|
||||||
|
break;
|
||||||
|
case TextResource.Email_Signup_Activate_Html:
|
||||||
|
resourceFilename = "sax-email-signup-activate.html";
|
||||||
|
break;
|
||||||
|
case TextResource.Email_Signup_Welcome_Html:
|
||||||
|
resourceFilename = "sax-email-signup-welcome.html";
|
||||||
|
break;
|
||||||
|
case TextResource.Email_RequestPassword_Html:
|
||||||
|
resourceFilename = "sax-email-request-password.html";
|
||||||
|
break;
|
||||||
|
// Data.
|
||||||
|
}
|
||||||
|
if (!StringUtil.IsEmpty(resourceFilename))
|
||||||
|
{
|
||||||
|
var assembly = typeof(SbmResourceHelper).GetTypeInfo().Assembly;
|
||||||
|
String resourceText = SacsResourceHelper.GetManifestResourceAsText(assembly, partialPath, resourceFilename);
|
||||||
|
if (!StringUtil.IsEmpty(resourceText))
|
||||||
|
return resourceText;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Image resources.
|
||||||
|
public static byte[] GetImageResource(ImageResource imageResource)
|
||||||
|
{
|
||||||
|
String partialPath = "";
|
||||||
|
String resourceFilename = "";
|
||||||
|
switch (imageResource)
|
||||||
|
{
|
||||||
|
case ImageResource.BusinessMgr_logo_h75_png:
|
||||||
|
resourceFilename = "BusinessMgr-logo-h75.png";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!StringUtil.IsEmpty(resourceFilename))
|
||||||
|
{
|
||||||
|
var assembly = typeof(SbmResourceHelper).GetTypeInfo().Assembly;
|
||||||
|
byte[] resourceData = SacsResourceHelper.GetManifestResourceAsBinary(assembly, partialPath, resourceFilename);
|
||||||
|
if (resourceData != null)
|
||||||
|
return resourceData;
|
||||||
|
}
|
||||||
|
return new byte[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
//=======================================================================
|
||||||
|
}
|
||||||
@@ -217,344 +217,345 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|||||||
private OrganisationOptionData InitOrganisationOptionData()
|
private OrganisationOptionData InitOrganisationOptionData()
|
||||||
{
|
{
|
||||||
OrganisationOptionData orgOptData = new OrganisationOptionData();
|
OrganisationOptionData orgOptData = new OrganisationOptionData();
|
||||||
SbmConfigConsole console = SbmGlobals.GetConfigConsole(UserContext.SessionContext);
|
using (SbmConfigConsole console = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext))
|
||||||
SbmAccountsDfn accounts = new SbmAccountsDfn(UserContext);
|
using (SbmAccountsDfn accounts = new SbmAccountsDfn(UserContext))
|
||||||
|
|
||||||
// Option types.
|
|
||||||
orgOptData.associationOptionTypes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.AssociationOption));
|
|
||||||
|
|
||||||
// Yes/No.
|
|
||||||
orgOptData.Values_YesNo.Add(orgOptData.Value_Yes, "Yes");
|
|
||||||
orgOptData.Values_YesNo.Add(orgOptData.Value_No, "No");
|
|
||||||
|
|
||||||
// Organisation configuration.
|
|
||||||
bool bAllowContacts = (AllowConfigOption(Sbm.ConfigOption.AllowContacts));
|
|
||||||
bool bAllowCustomers = (AllowAssociationType(Sbm.AssociationType.Customer));
|
|
||||||
bool bAllowStockists = (AllowAssociationType(Sbm.AssociationType.Stockist));
|
|
||||||
bool bAllowFinanceAgencies = (AllowAssociationType(Sbm.AssociationType.FinanceAgency));
|
|
||||||
bool bAllowCommodities = (AllowConfigOption(Sbm.ConfigOption.AllowCommodities));
|
|
||||||
bool bAllowVehicles = (AllowConfigOption(Sbm.ConfigOption.AllowVehicles));
|
|
||||||
bool bAllowAssets = (AllowConfigOption(Sbm.ConfigOption.AllowAssets));
|
|
||||||
bool bAllowTransactions = (AllowConfigOption(Sbm.ConfigOption.AllowTransactions));
|
|
||||||
bool bAllowSalesOrders = ((AllowTransactionType(Sbm.TransactionType.SalesOrder) || AllowTransactionType(Sbm.TransactionType.ProformaSalesOrder)));
|
|
||||||
bool bAllowSalesDispatches = (AllowTransactionType(Sbm.TransactionType.SalesDispatch));
|
|
||||||
bool bAllowSalesInvoices = ((AllowTransactionType(Sbm.TransactionType.SalesInvoice) || AllowTransactionType(Sbm.TransactionType.ProformaSalesInvoice)));
|
|
||||||
bool bAllowPurchaseOrders = ((AllowTransactionType(Sbm.TransactionType.PurchaseOrder) || AllowTransactionType(Sbm.TransactionType.ProformaPurchaseOrder)));
|
|
||||||
bool bAllowInterfaces = (console.AllowInterfaces(UserContext));
|
|
||||||
bool bAllowInterfaces_File = (bAllowInterfaces && console.AllowInterfaceCategory(UserContext, SaInterfaceCategory.File));
|
|
||||||
|
|
||||||
// Values:
|
|
||||||
List<TypeCodeDesc> orgOptionValues = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Value);
|
|
||||||
if (bAllowTransactions)
|
|
||||||
{
|
{
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.MaxTransactionsQueriedForEmptyFilter));
|
// Option types.
|
||||||
if (CodeTypeHasCodes(Sbm.ApplCodeType.CommodityPromotion))
|
orgOptData.associationOptionTypes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.AssociationOption));
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.AlternativePromotionText));
|
|
||||||
if (console.GetRequirementCostingConfig(UserContext).AllowRequirementCosting(Sbm.TransactionType.SalesOrder))
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.CostLabourRateDefault));
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.CommoditiesAllowedNegativePrice));
|
|
||||||
if (AllowConfigOption(Sbm.ConfigOption.TransactionSplitTimes))
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.TransTimeChunk1Caption));
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.TransTimeChunk2Caption));
|
|
||||||
}
|
|
||||||
// Default Email content.
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.EmailSubject));
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.EmailBody));
|
|
||||||
}
|
|
||||||
if (accounts.IsUsingSageInterface())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.DefaultSalesCarriageNominal));
|
|
||||||
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.DefaultPurchaseCarriageNominal));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Folders:
|
// Yes/No.
|
||||||
List<TypeCodeDesc> lOrgOptionFolder = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Folder);
|
orgOptData.Values_YesNo.Add(orgOptData.Value_Yes, "Yes");
|
||||||
if (bAllowCommodities)
|
orgOptData.Values_YesNo.Add(orgOptData.Value_No, "No");
|
||||||
{
|
|
||||||
orgOptData.Contexts_Folder.Add(lOrgOptionFolder.GetCodeDescForType(Sbm.OrgOption_Folder.CommodityImage));
|
|
||||||
orgOptData.Contexts_Folder.Add(lOrgOptionFolder.GetCodeDescForType(Sbm.OrgOption_Folder.CommodityBarcodeImage));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Allow option contexts:
|
// Organisation configuration.
|
||||||
List<TypeCodeDesc> lAllowOption = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_AllowOption);
|
bool bAllowContacts = (AllowConfigOption(Sbm.ConfigOption.AllowContacts));
|
||||||
if (bAllowContacts)
|
bool bAllowCustomers = (AllowAssociationType(Sbm.AssociationType.Customer));
|
||||||
{
|
bool bAllowStockists = (AllowAssociationType(Sbm.AssociationType.Stockist));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.UpdateAssociationCode));
|
bool bAllowFinanceAgencies = (AllowAssociationType(Sbm.AssociationType.FinanceAgency));
|
||||||
if (bAllowCustomers)
|
bool bAllowCommodities = (AllowConfigOption(Sbm.ConfigOption.AllowCommodities));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.CustomerAccountDetails));
|
bool bAllowVehicles = (AllowConfigOption(Sbm.ConfigOption.AllowVehicles));
|
||||||
if (bAllowStockists)
|
bool bAllowAssets = (AllowConfigOption(Sbm.ConfigOption.AllowAssets));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.StockistAssociations));
|
bool bAllowTransactions = (AllowConfigOption(Sbm.ConfigOption.AllowTransactions));
|
||||||
if (bAllowFinanceAgencies)
|
bool bAllowSalesOrders = ((AllowTransactionType(Sbm.TransactionType.SalesOrder) || AllowTransactionType(Sbm.TransactionType.ProformaSalesOrder)));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.FinanceAgencyAssociations));
|
bool bAllowSalesDispatches = (AllowTransactionType(Sbm.TransactionType.SalesDispatch));
|
||||||
}
|
bool bAllowSalesInvoices = ((AllowTransactionType(Sbm.TransactionType.SalesInvoice) || AllowTransactionType(Sbm.TransactionType.ProformaSalesInvoice)));
|
||||||
if (bAllowCommodities)
|
bool bAllowPurchaseOrders = ((AllowTransactionType(Sbm.TransactionType.PurchaseOrder) || AllowTransactionType(Sbm.TransactionType.ProformaPurchaseOrder)));
|
||||||
{
|
bool bAllowInterfaces = (console.AllowInterfaces(UserContext));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_SalesBudget));
|
bool bAllowInterfaces_File = (bAllowInterfaces && console.AllowInterfaceCategory(UserContext, SaInterfaceCategory.File));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_PartialCodeFilter));
|
|
||||||
|
// Values:
|
||||||
|
List<TypeCodeDesc> orgOptionValues = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Value);
|
||||||
if (bAllowTransactions)
|
if (bAllowTransactions)
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_EditHistoryItem));
|
{
|
||||||
}
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.MaxTransactionsQueriedForEmptyFilter));
|
||||||
if (bAllowTransactions)
|
if (CodeTypeHasCodes(Sbm.ApplCodeType.CommodityPromotion))
|
||||||
{
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.AlternativePromotionText));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_AnyStatus));
|
if (console.GetRequirementCostingConfig(UserContext).AllowRequirementCosting(Sbm.TransactionType.SalesOrder))
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_RetainRef));
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.CostLabourRateDefault));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_RetainRefExt));
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.CommoditiesAllowedNegativePrice));
|
||||||
if (bAllowInterfaces_File)
|
if (AllowConfigOption(Sbm.ConfigOption.TransactionSplitTimes))
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionExport_FixedContent));
|
{
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Order_BillingAddress));
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.TransTimeChunk1Caption));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ModifyCommodityDescription));
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.TransTimeChunk2Caption));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ShowCommodityDetails));
|
}
|
||||||
|
// Default Email content.
|
||||||
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.EmailSubject));
|
||||||
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.EmailBody));
|
||||||
|
}
|
||||||
|
if (accounts.IsUsingSageInterface())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.DefaultSalesCarriageNominal));
|
||||||
|
orgOptData.Contexts_Value.Add(orgOptionValues.GetCodeDescForType(Sbm.OrgOption_Value.DefaultPurchaseCarriageNominal));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Folders:
|
||||||
|
List<TypeCodeDesc> lOrgOptionFolder = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Folder);
|
||||||
|
if (bAllowCommodities)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_Folder.Add(lOrgOptionFolder.GetCodeDescForType(Sbm.OrgOption_Folder.CommodityImage));
|
||||||
|
orgOptData.Contexts_Folder.Add(lOrgOptionFolder.GetCodeDescForType(Sbm.OrgOption_Folder.CommodityBarcodeImage));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow option contexts:
|
||||||
|
List<TypeCodeDesc> lAllowOption = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_AllowOption);
|
||||||
|
if (bAllowContacts)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.UpdateAssociationCode));
|
||||||
|
if (bAllowCustomers)
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.CustomerAccountDetails));
|
||||||
|
if (bAllowStockists)
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.StockistAssociations));
|
||||||
|
if (bAllowFinanceAgencies)
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.FinanceAgencyAssociations));
|
||||||
|
}
|
||||||
|
if (bAllowCommodities)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_SalesBudget));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_PartialCodeFilter));
|
||||||
|
if (bAllowTransactions)
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Commodity_EditHistoryItem));
|
||||||
|
}
|
||||||
|
if (bAllowTransactions)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_AnyStatus));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_RetainRef));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionFilter_RetainRefExt));
|
||||||
|
if (bAllowInterfaces_File)
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.TransactionExport_FixedContent));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Order_BillingAddress));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ModifyCommodityDescription));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ShowCommodityDetails));
|
||||||
|
if (StockControlConfig.AllowStockControl())
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ShowStockDetails));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Transaction_RetainCurrentViewOnRaise));
|
||||||
|
}
|
||||||
|
if (bAllowSalesOrders)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_OnHold));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_ReplacementOrders));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_DispatchDetails));
|
||||||
|
if (bAllowSalesInvoices)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_PartialInvoice));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_RaiseInvoiceOnCompletion));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bAllowSalesOrders && bAllowPurchaseOrders)
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.PurchaseItem_AssociatedSalesItems));
|
||||||
|
}
|
||||||
if (StockControlConfig.AllowStockControl())
|
if (StockControlConfig.AllowStockControl())
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.OrderItem_ShowStockDetails));
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Transaction_RetainCurrentViewOnRaise));
|
|
||||||
}
|
|
||||||
if (bAllowSalesOrders)
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_OnHold));
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_ReplacementOrders));
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_DispatchDetails));
|
|
||||||
if (bAllowSalesInvoices)
|
|
||||||
{
|
{
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_PartialInvoice));
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.ImminentStock));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.SalesOrder_RaiseInvoiceOnCompletion));
|
if (StockControlConfig.AllowStockContainers())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.ManageContainerMovemements));
|
||||||
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.AwaitingContainersInImminentStock));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if (bAllowAssets)
|
||||||
if (bAllowSalesOrders && bAllowPurchaseOrders)
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.PurchaseItem_AssociatedSalesItems));
|
|
||||||
}
|
|
||||||
if (StockControlConfig.AllowStockControl())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.ImminentStock));
|
|
||||||
if (StockControlConfig.AllowStockContainers())
|
|
||||||
{
|
{
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.ManageContainerMovemements));
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Asset_Sale));
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.AwaitingContainersInImminentStock));
|
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Asset_Rental));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (bAllowAssets)
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Asset_Sale));
|
|
||||||
orgOptData.Contexts_AllowOption.Add(lAllowOption.GetCodeDescForType(Sbm.OrgOption_AllowOption.Asset_Rental));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Caption contexts:
|
// Caption contexts:
|
||||||
orgOptData.Contexts_Caption.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Caption));
|
orgOptData.Contexts_Caption.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Caption));
|
||||||
|
|
||||||
// Show field contexts.
|
// Show field contexts.
|
||||||
// NB This list must be kept up to date with equivalent in 'SapphireConsole::DisplayAttribute':
|
// NB This list must be kept up to date with equivalent in 'SapphireConsole::DisplayAttribute':
|
||||||
List<TypeCodeDesc> lShowField = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ShowField);
|
List<TypeCodeDesc> lShowField = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ShowField);
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Address_LastVisitOn))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Address_LastVisitOn));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DrawingIssue));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DrawingNo));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Department));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CatalogRef));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Volume));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Density));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_BoxQuantity));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_MaterialCost))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCost));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_CarriageCostIndicative))
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CarriageCostIndicative));
|
|
||||||
if (StockControlConfig.AllowStockControl())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay1));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay2));
|
|
||||||
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay3));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show column contexts:
|
|
||||||
List<TypeCodeDesc> lShowColumn = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ShowColumn);
|
|
||||||
if (bAllowSalesOrders)
|
|
||||||
{
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget))
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget))
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_AnnualSalesTarget));
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget));
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_LastSaleRaised));
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Address_LastVisitOn))
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Open));
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Address_LastVisitOn));
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Cytd));
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DrawingIssue));
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Lcy));
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DrawingNo));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Department));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CatalogRef));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Volume));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Density));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_BoxQuantity));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin))
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_MaterialCost))
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCost));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost))
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned))
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_CarriageCostIndicative))
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CarriageCostIndicative));
|
||||||
|
if (StockControlConfig.AllowStockControl())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay1));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay2));
|
||||||
|
orgOptData.Contexts_ShowField.Add(lShowField.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay3));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show column contexts:
|
||||||
|
List<TypeCodeDesc> lShowColumn = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ShowColumn);
|
||||||
|
if (bAllowSalesOrders)
|
||||||
|
{
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_AnnualSalesTarget))
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_AnnualSalesTarget));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_LastSaleRaised));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Open));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Cytd));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Trans_SalesValue_Lcy));
|
||||||
|
}
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_Group))
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Group));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_CatalogRef));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_Weight));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_PackQtySale));
|
||||||
|
if (StockControlConfig.AllowStockControl())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockAllocated));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockLevelSales));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockAvailable));
|
||||||
|
}
|
||||||
|
if ((bAllowSalesOrders || bAllowPurchaseOrders) && StockControlConfig.AllowStockControl())
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Order_AllocationInd));
|
||||||
|
if (bAllowSalesOrders && CodeTypeHasCodes(Sbm.ApplCodeType.DeliveryCourier))
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrder_DeliveryCourier));
|
||||||
|
if (bAllowSalesOrders || bAllowSalesInvoices)
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrder_HasInvoice));
|
||||||
|
if (bAllowSalesInvoices)
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Transaction_ContactArea));
|
||||||
|
if (bAllowSalesInvoices && accounts.IsTransactionTypeManagedByAccounts(Sbm.TransactionType.SalesInvoice))
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Accounts_InvoiceRef));
|
||||||
|
if ((bAllowSalesOrders || bAllowPurchaseOrders) && StockControlConfig.AllowStockControl())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_AllocationInd));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_Current));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_Available));
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_BySalesLocation));
|
||||||
|
}
|
||||||
|
if (bAllowSalesDispatches)
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_QtyDispatched));
|
||||||
|
if (bAllowSalesInvoices)
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_QtyInvoiced));
|
||||||
|
// Check for processes:
|
||||||
|
if (ProcessMgr.HasProcesses(Sbm.ProcessCategory.Commodity))
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_NextProcess));
|
||||||
|
// Check for vehicles:
|
||||||
|
if (bAllowVehicles)
|
||||||
|
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Vehicle_KeyLocation));
|
||||||
|
|
||||||
|
// Field label contexts:
|
||||||
|
List<TypeCodeDesc> lFieldLabel = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_FieldLabel);
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CatalogRef));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Dimensions));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CostPrice));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin))
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCost));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdMaterial));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost))
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdExWorks))
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdExWorks));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_SpecSummary));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_FinishCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DescDetail));
|
||||||
|
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned))
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Affiliate_Abbrev));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Affiliate_Nature));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_Location));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountManagerCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountHandlerCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountTypeCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountRatingCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactAreaCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactHandlerCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactMethodCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactCallCycleCode));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Transaction_Ref));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Transaction_RefExt));
|
||||||
|
if (StockControlConfig.AllowStockControl())
|
||||||
|
{
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay1));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay2));
|
||||||
|
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay3));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commodity status filter.
|
||||||
|
List<TypeCodeDesc> lCmdStatusCat = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityStatusCat);
|
||||||
|
orgOptData.Values_CommodityStatusCat.Add(lCmdStatusCat.GetCodeDescForType(SbmCommodity.StatusCat.Any));
|
||||||
|
orgOptData.Values_CommodityStatusCat.Add(lCmdStatusCat.GetCodeDescForType(SbmCommodity.StatusCat.Current));
|
||||||
|
|
||||||
|
// Commodity Stock Category filter.
|
||||||
|
List<CodeDesc> commodityCategories = GetCodeDescsForCodeType(Sbm.ApplCodeType.CommodityCategory, true);
|
||||||
|
orgOptData.Values_CommodityStockCat.AddRange(commodityCategories);
|
||||||
|
|
||||||
|
// Container status caption.
|
||||||
|
if (CommodityMgr.ContainerDatabaseIsValid && StockControlConfig.AllowStockContainers())
|
||||||
|
orgOptData.Contexts_ContainerStatus.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ContainerStatusCaption));
|
||||||
|
|
||||||
|
// Generic options:
|
||||||
|
orgOptData.Contexts_Minutes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Minutes));
|
||||||
|
orgOptData.Contexts_PeriodDays.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_PeriodDays));
|
||||||
|
orgOptData.Contexts_PeriodWeeks.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_PeriodWeeks));
|
||||||
|
|
||||||
|
// Minutes.
|
||||||
|
for (int iMins = 0; iMins <= 30; iMins++)
|
||||||
|
orgOptData.Values_Minutes.Add(iMins.ToString(), iMins.ToString() + " min" + (iMins == 1 ? "" : "s"));
|
||||||
|
|
||||||
|
// Period - days.
|
||||||
|
orgOptData.Values_PeriodDays.Add("1", "1 day");
|
||||||
|
orgOptData.Values_PeriodDays.Add("2", "2 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("3", "3 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("7", "1 week");
|
||||||
|
orgOptData.Values_PeriodDays.Add("14", "2 weeks");
|
||||||
|
orgOptData.Values_PeriodDays.Add("21", "3 weeks");
|
||||||
|
orgOptData.Values_PeriodDays.Add("30", "30 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("60", "60 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("90", "90 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("120", "120 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("150", "150 days");
|
||||||
|
orgOptData.Values_PeriodDays.Add("300", "300 days");
|
||||||
|
|
||||||
|
// Period - weeks.
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("0", "0 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("1", "1 week");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("2", "2 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("3", "3 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("4", "4 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("5", "5 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("6", "6 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("7", "7 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("8", "8 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("9", "9 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("10", "10 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("11", "11 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("12", "12 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("13", "13 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("14", "14 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("15", "15 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("16", "16 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("17", "17 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("18", "18 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("19", "19 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("20", "20 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("21", "21 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("22", "22 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("23", "23 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("24", "24 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("25", "25 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("26", "26 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("27", "27 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("28", "28 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("29", "29 weeks");
|
||||||
|
orgOptData.Values_PeriodWeeks.Add("30", "30 weeks");
|
||||||
|
|
||||||
|
// Numeric Decimals:
|
||||||
|
orgOptData.Contexts_NumericDecimals.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_NumericDecimals));
|
||||||
|
orgOptData.Values_Decimals_0To2.Add("0", "None");
|
||||||
|
orgOptData.Values_Decimals_0To2.Add("1", "1 places");
|
||||||
|
orgOptData.Values_Decimals_0To2.Add("2", "2 places");
|
||||||
|
orgOptData.Values_Decimals_0To4.Add("0", "None");
|
||||||
|
orgOptData.Values_Decimals_0To4.Add("1", "1 places");
|
||||||
|
orgOptData.Values_Decimals_0To4.Add("2", "2 places");
|
||||||
|
orgOptData.Values_Decimals_0To4.Add("3", "3 places");
|
||||||
|
orgOptData.Values_Decimals_0To4.Add("4", "4 places");
|
||||||
|
|
||||||
|
// Commodity types.
|
||||||
|
orgOptData.Contexts_CommodityType.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityType));
|
||||||
|
orgOptData.Values_CommodityTypes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityType));
|
||||||
|
|
||||||
|
// Sales locations.
|
||||||
|
orgOptData.Contexts_SalesLocation.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_StockLocation));
|
||||||
|
SbmLocation.Params prmLocation = new SbmLocation.Params();
|
||||||
|
prmLocation.RestrictToSalesStock = true;
|
||||||
|
prmLocation.StatusCat = SbmLocation.StatusCat.ActiveOnly;
|
||||||
|
foreach (SbmLocation location in StockMgr.GetLocationList(prmLocation))
|
||||||
|
orgOptData.Values_SalesLocation.Add(SysId.ToString(location.Id), location.Name);
|
||||||
}
|
}
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Association_Group))
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Association_Group));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_CatalogRef));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_Weight));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_PackQtySale));
|
|
||||||
if (StockControlConfig.AllowStockControl())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockAllocated));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockLevelSales));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Commodity_StockAvailable));
|
|
||||||
}
|
|
||||||
if ((bAllowSalesOrders || bAllowPurchaseOrders) && StockControlConfig.AllowStockControl())
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Order_AllocationInd));
|
|
||||||
if (bAllowSalesOrders && CodeTypeHasCodes(Sbm.ApplCodeType.DeliveryCourier))
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrder_DeliveryCourier));
|
|
||||||
if (bAllowSalesOrders || bAllowSalesInvoices)
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrder_HasInvoice));
|
|
||||||
if (bAllowSalesInvoices)
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Transaction_ContactArea));
|
|
||||||
if (bAllowSalesInvoices && accounts.IsTransactionTypeManagedByAccounts(Sbm.TransactionType.SalesInvoice))
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Accounts_InvoiceRef));
|
|
||||||
if ((bAllowSalesOrders || bAllowPurchaseOrders) && StockControlConfig.AllowStockControl())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_AllocationInd));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_Current));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_Available));
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.OrderItem_Stock_BySalesLocation));
|
|
||||||
}
|
|
||||||
if (bAllowSalesDispatches)
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_QtyDispatched));
|
|
||||||
if (bAllowSalesInvoices)
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_QtyInvoiced));
|
|
||||||
// Check for processes:
|
|
||||||
if (ProcessMgr.HasProcesses(Sbm.ProcessCategory.Commodity))
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.SalesOrderItem_NextProcess));
|
|
||||||
// Check for vehicles:
|
|
||||||
if (bAllowVehicles)
|
|
||||||
orgOptData.Contexts_ShowColumn.Add(lShowColumn.GetCodeDescForType(Sbm.OrgOption_ShowColumn.Vehicle_KeyLocation));
|
|
||||||
|
|
||||||
// Field label contexts:
|
|
||||||
List<TypeCodeDesc> lFieldLabel = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_FieldLabel);
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CatalogRef));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_Dimensions));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ICNTariffCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CostPrice));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin))
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_PlaceOfOrigin));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCost));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdMaterial));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost))
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_ExWorksCost));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdExWorks))
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_CurrencyIdExWorks));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_SpecSummary));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_MaterialCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_FinishCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_DescDetail));
|
|
||||||
if (ColumnExists(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned))
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Commodity_RetailPricePlanned));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Affiliate_Abbrev));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Affiliate_Nature));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_Location));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountManagerCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountHandlerCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountTypeCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_AccountRatingCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactAreaCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactHandlerCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactMethodCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Association_ContactCallCycleCode));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Transaction_Ref));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.Transaction_RefExt));
|
|
||||||
if (StockControlConfig.AllowStockControl())
|
|
||||||
{
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay1));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay2));
|
|
||||||
orgOptData.Contexts_FieldLabelAssoc.Add(lFieldLabel.GetCodeDescForType(SbmDbDfn.ColumnIdx.StockLevel_Bay3));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Commodity status filter.
|
|
||||||
List<TypeCodeDesc> lCmdStatusCat = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityStatusCat);
|
|
||||||
orgOptData.Values_CommodityStatusCat.Add(lCmdStatusCat.GetCodeDescForType(SbmCommodity.StatusCat.Any));
|
|
||||||
orgOptData.Values_CommodityStatusCat.Add(lCmdStatusCat.GetCodeDescForType(SbmCommodity.StatusCat.Current));
|
|
||||||
|
|
||||||
// Commodity Stock Category filter.
|
|
||||||
List<CodeDesc> commodityCategories = GetCodeDescsForCodeType(Sbm.ApplCodeType.CommodityCategory, true);
|
|
||||||
orgOptData.Values_CommodityStockCat.AddRange(commodityCategories);
|
|
||||||
|
|
||||||
// Container status caption.
|
|
||||||
if (CommodityMgr.ContainerDatabaseIsValid && StockControlConfig.AllowStockContainers())
|
|
||||||
orgOptData.Contexts_ContainerStatus.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_ContainerStatusCaption));
|
|
||||||
|
|
||||||
// Generic options:
|
|
||||||
orgOptData.Contexts_Minutes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_Minutes));
|
|
||||||
orgOptData.Contexts_PeriodDays.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_PeriodDays));
|
|
||||||
orgOptData.Contexts_PeriodWeeks.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_PeriodWeeks));
|
|
||||||
|
|
||||||
// Minutes.
|
|
||||||
for (int iMins = 0; iMins <= 30; iMins++)
|
|
||||||
orgOptData.Values_Minutes.Add(iMins.ToString(), iMins.ToString() + " min" + (iMins == 1 ? "" : "s"));
|
|
||||||
|
|
||||||
// Period - days.
|
|
||||||
orgOptData.Values_PeriodDays.Add("1", "1 day");
|
|
||||||
orgOptData.Values_PeriodDays.Add("2", "2 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("3", "3 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("7", "1 week");
|
|
||||||
orgOptData.Values_PeriodDays.Add("14", "2 weeks");
|
|
||||||
orgOptData.Values_PeriodDays.Add("21", "3 weeks");
|
|
||||||
orgOptData.Values_PeriodDays.Add("30", "30 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("60", "60 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("90", "90 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("120", "120 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("150", "150 days");
|
|
||||||
orgOptData.Values_PeriodDays.Add("300", "300 days");
|
|
||||||
|
|
||||||
// Period - weeks.
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("0", "0 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("1", "1 week");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("2", "2 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("3", "3 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("4", "4 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("5", "5 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("6", "6 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("7", "7 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("8", "8 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("9", "9 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("10", "10 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("11", "11 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("12", "12 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("13", "13 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("14", "14 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("15", "15 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("16", "16 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("17", "17 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("18", "18 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("19", "19 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("20", "20 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("21", "21 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("22", "22 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("23", "23 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("24", "24 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("25", "25 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("26", "26 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("27", "27 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("28", "28 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("29", "29 weeks");
|
|
||||||
orgOptData.Values_PeriodWeeks.Add("30", "30 weeks");
|
|
||||||
|
|
||||||
// Numeric Decimals:
|
|
||||||
orgOptData.Contexts_NumericDecimals.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_NumericDecimals));
|
|
||||||
orgOptData.Values_Decimals_0To2.Add("0", "None");
|
|
||||||
orgOptData.Values_Decimals_0To2.Add("1", "1 places");
|
|
||||||
orgOptData.Values_Decimals_0To2.Add("2", "2 places");
|
|
||||||
orgOptData.Values_Decimals_0To4.Add("0", "None");
|
|
||||||
orgOptData.Values_Decimals_0To4.Add("1", "1 places");
|
|
||||||
orgOptData.Values_Decimals_0To4.Add("2", "2 places");
|
|
||||||
orgOptData.Values_Decimals_0To4.Add("3", "3 places");
|
|
||||||
orgOptData.Values_Decimals_0To4.Add("4", "4 places");
|
|
||||||
|
|
||||||
// Commodity types.
|
|
||||||
orgOptData.Contexts_CommodityType.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityType));
|
|
||||||
orgOptData.Values_CommodityTypes.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.CommodityType));
|
|
||||||
|
|
||||||
// Sales locations.
|
|
||||||
orgOptData.Contexts_SalesLocation.AddRange(SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.OrgOption_StockLocation));
|
|
||||||
SbmLocation.Params prmLocation = new SbmLocation.Params();
|
|
||||||
prmLocation.RestrictToSalesStock = true;
|
|
||||||
prmLocation.StatusCat = SbmLocation.StatusCat.ActiveOnly;
|
|
||||||
foreach (SbmLocation location in StockMgr.GetLocationList(prmLocation))
|
|
||||||
orgOptData.Values_SalesLocation.Add(SysId.ToString(location.Id), location.Name);
|
|
||||||
|
|
||||||
return orgOptData;
|
return orgOptData;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,14 +232,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|||||||
{
|
{
|
||||||
SbmApplication application = SbmGlobals.Application;
|
SbmApplication application = SbmGlobals.Application;
|
||||||
if (application != null)
|
if (application != null)
|
||||||
return application.TableExists(SessionContext, tableIdx);
|
return application.BusMgrTableExists(SessionContext, tableIdx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public bool ColumnExists(SbmDbDfn.ColumnIdx columnIdx)
|
public bool ColumnExists(SbmDbDfn.ColumnIdx columnIdx)
|
||||||
{
|
{
|
||||||
SbmApplication application = SbmGlobals.Application;
|
SbmApplication application = SbmGlobals.Application;
|
||||||
if (application != null)
|
if (application != null)
|
||||||
return application.ColumnExists(SessionContext, columnIdx);
|
return application.BusMgrColumnExists(SessionContext, columnIdx);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|||||||
// Standard notes length:
|
// Standard notes length:
|
||||||
maxTranNotesLength = (int)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.Transaction_Notes);
|
maxTranNotesLength = (int)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.Transaction_Notes);
|
||||||
// Check if this database allows longer notes:
|
// Check if this database allows longer notes:
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(SessionContext);
|
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(SessionContext);
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
DbDfnTable tableDfn = db.GetTableDfn(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction, false));
|
DbDfnTable tableDfn = db.GetTableDfn(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Transaction, false));
|
||||||
|
|||||||
@@ -7,27 +7,23 @@ using Sarand.Net.Standard.Base.Procs;
|
|||||||
namespace Sarand.BusinessMgr.Net.Standard.Base.Procs
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Procs
|
||||||
{
|
{
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
public abstract class SbmReport_Base : SacsReport
|
public abstract class SbmReport_Base : SaReport_Base
|
||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Configuration.
|
// Configuration.
|
||||||
public new class Config : SacsReport.Config
|
public new class Config : SaReport_Base.Config
|
||||||
{
|
{
|
||||||
protected Config(SbmUserContext userContext, DbUpdateInfo dbUpdateInfo)
|
protected Config(SbmUserContext userContext)
|
||||||
{
|
{
|
||||||
UserContext = userContext;
|
UserContext = userContext;
|
||||||
DbUpdateInfo = dbUpdateInfo;
|
|
||||||
}
|
}
|
||||||
public SbmUserContext UserContext { get; }
|
public SbmUserContext UserContext { get; }
|
||||||
public DbUpdateInfo DbUpdateInfo { get; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private Config config;
|
private Config config;
|
||||||
private SbmAccountMgr accountMgr = null;
|
private SbmInternals internals = null;
|
||||||
private SbmCommodityMgr commodityMgr = null;
|
|
||||||
private SbmTransactionMgr transactionMgr = null;
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
@@ -39,44 +35,19 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.Procs
|
|||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (accountMgr != null) accountMgr.Dispose();
|
if (internals != null) internals.Dispose();
|
||||||
if (commodityMgr != null) commodityMgr.Dispose();
|
|
||||||
if (transactionMgr != null) transactionMgr.Dispose();
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
protected SaCodeTypeConsole CodeTypeConsole { get { return SbmGlobals.Application.GetCodeTypeConsole(config.UserContext); } }
|
protected SbmInternals Internals { get { if (internals == null) internals = new SbmInternals(config.UserContext); return internals; } }
|
||||||
protected SbmAccountMgr AccountMgr
|
protected SaCodeTypeConsole CodeTypeConsole { get { return Internals.CodeTypeConsole; } }
|
||||||
{
|
protected SbmAccountMgr AccountMgr { get { return Internals.AccountMgr; } }
|
||||||
get
|
protected SbmCommodityMgr CommodityMgr { get { return Internals.CommodityMgr; } }
|
||||||
{
|
protected SbmTransactionMgr TransactionMgr { get { return Internals.TransactionMgr; } }
|
||||||
if (accountMgr == null)
|
protected DbUpdateInfo DbUpdateInfo { get { return Internals.DbUpdateInfo; } }
|
||||||
accountMgr = SbmGlobals.System.CreateAccountMgr(config.UserContext);
|
|
||||||
return accountMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected SbmCommodityMgr CommodityMgr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (commodityMgr == null)
|
|
||||||
commodityMgr = SbmGlobals.System.CreateCommodityMgr(config.UserContext);
|
|
||||||
return commodityMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected SbmTransactionMgr TransactionMgr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (transactionMgr == null)
|
|
||||||
transactionMgr = SbmGlobals.System.CreateTransactionMgr(config.UserContext);
|
|
||||||
return transactionMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
protected DbUpdateInfo DbUpdateInfo { get { return config.DbUpdateInfo; } }
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.UpdateLog
|
|||||||
// Configuration.
|
// Configuration.
|
||||||
public new class Config : SaUpdateLogItemMonitor.Config
|
public new class Config : SaUpdateLogItemMonitor.Config
|
||||||
{
|
{
|
||||||
public Config(SbmUserContext userContext) :
|
public Config(SbmInternals internals) :
|
||||||
base(SbmGlobals.Application.GetUpdateLogConsole(userContext), userContext.DbUpdateInfo)
|
base(internals.UpdateLogConsole, internals.DbUpdateInfo)
|
||||||
{
|
{
|
||||||
UserContext = userContext;
|
Internals = internals;
|
||||||
}
|
}
|
||||||
public SbmUserContext UserContext { get; }
|
public SbmInternals Internals { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@@ -35,7 +35,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.UpdateLog
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public SbmUserContext UserContext { get { return config.UserContext; } }
|
public SbmUserContext UserContext { get { return config.Internals.UserContext; } }
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Internal utilities.
|
// Internal utilities.
|
||||||
@@ -43,7 +43,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Base.UpdateLog
|
|||||||
{
|
{
|
||||||
if (!config.UpdateLogConsole.CanUpdateDatabase) return false;
|
if (!config.UpdateLogConsole.CanUpdateDatabase) return false;
|
||||||
if (configConsole == null)
|
if (configConsole == null)
|
||||||
configConsole = SbmGlobals.Application.GetConfigConsole(config.UserContext.SessionContext);
|
configConsole = config.Internals.ConfigConsole;
|
||||||
if (!configConsole.IsColumnChangeLogged(UserContext, columnIdx)) return false;
|
if (!configConsole.IsColumnChangeLogged(UserContext, columnIdx)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ using Sarand.Net.Standard.Base.Data;
|
|||||||
using Sarand.Net.Standard.Base.Net;
|
using Sarand.Net.Standard.Base.Net;
|
||||||
using Sarand.Net.Standard.Base.Tasks;
|
using Sarand.Net.Standard.Base.Tasks;
|
||||||
using Sarand.Net.Standard.Base.Utils;
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
using Sarand.Net.Standard.Base.Xml;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using Sarand.Net.Standard.Base.Bus;
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using Sarand.Net.Standard.Base.Utils;
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
using Sarand.Net.Standard.Base.Xml;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Sarand.Net.Standard.Base.App;
|
|||||||
using Sarand.Net.Standard.Base.Core;
|
using Sarand.Net.Standard.Base.Core;
|
||||||
using Sarand.Net.Standard.Base.Net;
|
using Sarand.Net.Standard.Base.Net;
|
||||||
using Sarand.Net.Standard.Base.Utils;
|
using Sarand.Net.Standard.Base.Utils;
|
||||||
using Sarand.Net.Standard.Base.Xml;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
<RootNamespace>Sarand.BusinessMgr.Net.Standard</RootNamespace>
|
<RootNamespace>Sarand.BusinessMgr.Net.Standard</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardAccounts\SacsStandardAccounts.csproj" />
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardAccounts\SacsStandardAccounts.csproj" />
|
||||||
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
|
<ProjectReference Include="..\..\..\Common-VS\Workspace\SacsStandardBase\SacsStandardBase.csproj" />
|
||||||
|
|||||||
+2
-2
@@ -13,7 +13,7 @@ using System.IO;
|
|||||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.App
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.App
|
||||||
{
|
{
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
public class SbmSystem_WinDbas : SbmSystem
|
public class SbmSystem_Dbas : SbmSystem
|
||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Static initialisation.
|
// Static initialisation.
|
||||||
@@ -32,7 +32,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.App
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmSystem_WinDbas(PropertySet properties) : base(properties)
|
public SbmSystem_Dbas(PropertySet properties) : base(properties)
|
||||||
{
|
{
|
||||||
if (IsExtendedLogging(ExtendedLogginOption.DbQueryExecution))
|
if (IsExtendedLogging(ExtendedLogginOption.DbQueryExecution))
|
||||||
{
|
{
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.App
|
||||||
|
{
|
||||||
|
public class SbmUserContext_Dbas : SbmUserContext
|
||||||
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Construction.
|
||||||
|
public SbmUserContext_Dbas(SbmSessionContext sessionContext) : base(sessionContext)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,7 +27,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Base
|
|||||||
public bool CreateDbIndices(IndexStats indexStats)
|
public bool CreateDbIndices(IndexStats indexStats)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
ISacsDatabase database = SbmGlobals.Application.GetDatabase(sessionContext);
|
ISacsDatabase database = SbmGlobals.Application.GetBusMgrDatabase(sessionContext);
|
||||||
if (database == null || database.DbmsType != DbmsType.MsSql) return SetErrorState("");
|
if (database == null || database.DbmsType != DbmsType.MsSql) return SetErrorState("");
|
||||||
|
|
||||||
// Turn off database exceptions.
|
// Turn off database exceptions.
|
||||||
|
|||||||
@@ -12,20 +12,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAddress_Dbas(SbmUserContext userContext, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.AddressType addressType, ushort flags) :
|
public SbmAddress_Dbas(SbmInternals internals, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.AddressType addressType, ushort flags) :
|
||||||
base(userContext, id, itemType, itemId, addressType)
|
base(internals.UserContext, id, itemType, itemId, addressType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -39,7 +40,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null) return false;
|
if (interfaceConsole != null) return false;
|
||||||
bool has = interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Address, Id));
|
bool has = interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Address, Id));
|
||||||
return has;
|
return has;
|
||||||
@@ -49,16 +50,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null) return SetErrorState("Database is not available");
|
if (db != null) return SetErrorState("Database is not available");
|
||||||
|
|
||||||
// Delete interface data items.
|
// Delete interface data items.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("failed to initialise interface console");
|
else SetErrorState("failed to initialise interface console");
|
||||||
@@ -67,15 +68,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Remove data item references.
|
// Remove data item references.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
using (SbmDataItemMgr dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext))
|
SbmDataItemMgr dataItemMgr = internals.DataItemMgr;
|
||||||
|
if (dataItemMgr != null)
|
||||||
{
|
{
|
||||||
if (dataItemMgr != null)
|
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Address, Id))
|
||||||
{
|
SetErrorState(dataItemMgr.ErrorState.ToString());
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Address, Id))
|
|
||||||
SetErrorState(dataItemMgr.ErrorState.ToString());
|
|
||||||
}
|
|
||||||
else SetErrorState("Data item manager is not available");
|
|
||||||
}
|
}
|
||||||
|
else SetErrorState("Data item manager is not available");
|
||||||
}
|
}
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,22 +14,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmAccountMgr accountMgr;
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAffiliate_Dbas(SbmUserContext userContext, SysId id, Sbm.AffiliateType affiliateType, ushort flags) :
|
public SbmAffiliate_Dbas(SbmInternals internals, SysId id, Sbm.AffiliateType affiliateType, ushort flags) :
|
||||||
base(userContext, id, affiliateType)
|
base(internals.UserContext, id, affiliateType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (accountMgr != null) accountMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -42,7 +41,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override long GetChildAffiliates()
|
public override long GetChildAffiliates()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return 0;
|
if (!SysId.IsValid(Id)) return 0;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Affiliate_AffIdParent) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Affiliate_AffIdParent) + "=" + Id.ToString();
|
||||||
@@ -58,28 +57,24 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
|
|
||||||
public override long OwnerOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
public override long OwnerOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
||||||
{
|
{
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
return internals.AccountMgr.OwnerAssociationCount(Id, associationType, currentOnly);
|
||||||
return accountMgr.OwnerAssociationCount(Id, associationType, currentOnly);
|
|
||||||
}
|
}
|
||||||
public override bool OwnerOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
public override bool OwnerOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
||||||
{
|
{
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
return internals.AccountMgr.OwnerHasAssociations(Id, associationType, currentOnly);
|
||||||
return accountMgr.OwnerHasAssociations(Id, associationType, currentOnly);
|
|
||||||
}
|
}
|
||||||
public override long TargetOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
public override long TargetOfAssociationsCount(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
||||||
{
|
{
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
return internals.AccountMgr.TargetAssociationCount(Id, associationType, currentOnly);
|
||||||
return accountMgr.TargetAssociationCount(Id, associationType, currentOnly);
|
|
||||||
}
|
}
|
||||||
public override bool TargetOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
public override bool TargetOfAssociations(Sbm.AssociationType associationType = Sbm.AssociationType.Any, bool currentOnly = true)
|
||||||
{
|
{
|
||||||
if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
return internals.AccountMgr.TargetHasAssociations(Id, associationType, currentOnly);
|
||||||
return accountMgr.TargetHasAssociations(Id, associationType, currentOnly);
|
|
||||||
}
|
}
|
||||||
public override bool HasSystemUsers()
|
public override bool HasSystemUsers()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SystemUser_AffiliateId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.SystemUser_AffiliateId) + "=" + Id.ToString();
|
||||||
@@ -106,16 +101,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext);
|
||||||
if (db != null) return SetErrorState("Database is not available");
|
if (db != null) return SetErrorState("Database is not available");
|
||||||
|
|
||||||
// Delete interface data items.
|
// Delete interface data items.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("failed to initialise interface console");
|
else SetErrorState("failed to initialise interface console");
|
||||||
@@ -124,7 +119,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Remove data item references.
|
// Remove data item references.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SbmDataItemMgr dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
SbmDataItemMgr dataItemMgr = internals.DataItemMgr;
|
||||||
if (dataItemMgr != null)
|
if (dataItemMgr != null)
|
||||||
{
|
{
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Affiliate, Id))
|
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Affiliate, Id))
|
||||||
|
|||||||
@@ -16,26 +16,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmProcessMgr processMgr;
|
|
||||||
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAssetCategory_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, Sbm.AssetType assetType, ushort flags) :
|
public SbmAssetCategory_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.AssetType assetType, ushort flags) :
|
||||||
base(userContext, id)
|
base(internals.UserContext, id)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Id = id;
|
|
||||||
AffIdOwner = affIdOwner;
|
|
||||||
AssetType = assetType;
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (processMgr != null) processMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -43,29 +39,19 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Internal Processing.
|
|
||||||
public bool InitProcMgr()
|
|
||||||
{
|
|
||||||
if (processMgr == null)
|
|
||||||
processMgr = SbmGlobals.System.CreateProcessMgr(userContext);
|
|
||||||
return (processMgr != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
public override bool HasProcesses()
|
public override bool HasProcesses()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||||
if (processMgr == null) return SetErrorState("process manager not available");
|
return internals.ProcessMgr.HasItemProcesses(Sbm.ItemType.Asset, Id);
|
||||||
return false;// processMgr.ItemHasProcesses(Sbm.ItemType.Asset, Id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool HasAssets()
|
public override bool HasAssets()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableAsset = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAsset);
|
String tableAsset = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAsset);
|
||||||
@@ -83,7 +69,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (this == null || !SysId.IsValid(Id)) return false;
|
if (this == null || !SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null && !HasErrorState())
|
if (db != null && !HasErrorState())
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -113,11 +99,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove interface data items:
|
// Remove interface data items:
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
SetErrorState(interfaceConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
@@ -135,15 +121,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (activeOnly)
|
if (activeOnly)
|
||||||
{
|
{
|
||||||
// Retrieve the list of 'active' processes for this item.
|
// Retrieve the list of 'active' processes for this item.
|
||||||
processMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, true);
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Full list required - check whether the internal list has been populated yet.
|
// Full list required - check whether the internal list has been populated yet.
|
||||||
if (itemProcesses == null && SysId.IsValid(Id) && processMgr != null)
|
if (itemProcesses == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Get the list of processes:
|
// Get the list of processes:
|
||||||
processMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, false);
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.AssetCategory, Id, false);
|
||||||
}
|
}
|
||||||
// Clone the list.
|
// Clone the list.
|
||||||
itemProcesesCopy = itemProcesses.Clone();
|
itemProcesesCopy = itemProcesses.Clone();
|
||||||
|
|||||||
@@ -9,23 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAssetProcess_Dbas(SbmUserContext userContext, SysId id, SysId assetId, SysId processId, ushort flags) :
|
public SbmAssetProcess_Dbas(SbmInternals internals, SysId id, SysId assetId, SysId processId, ushort flags) :
|
||||||
base(userContext, id, assetId, processId)
|
base(internals.UserContext, id, assetId, processId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Id = id;
|
|
||||||
AssetId = assetId;
|
|
||||||
ProcessId = processId;
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,19 +16,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmAssetMgr assetMgr;
|
|
||||||
private SbmDataItemMgr dataItemMgr;
|
|
||||||
private SbmProcessMgr processMgr;
|
|
||||||
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
||||||
private List<SbmItemPrice> itemPrices = new List<SbmItemPrice>();
|
private List<SbmItemPrice> itemPrices = new List<SbmItemPrice>();
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAsset_Dbas(SbmUserContext userContext, SysId id, SysId assetCatId, ushort flags) :
|
public SbmAsset_Dbas(SbmInternals internals, SysId id, SysId assetCatId, ushort flags) :
|
||||||
base(userContext, id, assetCatId)
|
base(internals.UserContext, id, assetCatId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Id = id;
|
Id = id;
|
||||||
AssetCategoryId = assetCatId;
|
AssetCategoryId = assetCatId;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
@@ -37,9 +34,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (assetMgr != null) assetMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
if (dataItemMgr != null) dataItemMgr.Dispose();
|
|
||||||
if (processMgr != null) processMgr.Dispose();
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -47,36 +42,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Internal Processing.
|
|
||||||
public bool InitAssetMgr()
|
|
||||||
{
|
|
||||||
if (assetMgr == null)
|
|
||||||
assetMgr = SbmGlobals.System.CreateAssetMgr(userContext);
|
|
||||||
return (assetMgr != null);
|
|
||||||
}
|
|
||||||
public bool InitDataItemMgr()
|
|
||||||
{
|
|
||||||
if (dataItemMgr == null)
|
|
||||||
dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
|
||||||
return (dataItemMgr != null);
|
|
||||||
}
|
|
||||||
public bool InitProcessMgr()
|
|
||||||
{
|
|
||||||
if (processMgr == null)
|
|
||||||
processMgr = SbmGlobals.System.CreateProcessMgr(userContext);
|
|
||||||
return (processMgr != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
public override bool HasProcesses()
|
public override bool HasProcesses()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (processMgr == null) return SetErrorState("process manager not available");
|
|
||||||
//processMgr.ItemHasProcesses(Sbm.ItemType.Asset, Id);ISacsDatabase db = SbmGlobals.Application.GetDatabase(SessionContext);
|
//processMgr.ItemHasProcesses(Sbm.ItemType.Asset, Id);ISacsDatabase db = SbmGlobals.Application.GetDatabase(SessionContext);
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableAssetProcess = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess);
|
String tableAssetProcess = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess);
|
||||||
@@ -93,19 +66,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssetId);
|
||||||
if (db != null)
|
return internals.BusMgrDatabase.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), filter + "=" + Id.ToString()) > 0;
|
||||||
{
|
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssetId);
|
|
||||||
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement), filter + "=" + Id.ToString()) > 0;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public override bool HasInterfaceDataItems()
|
public override bool HasInterfaceDataItems()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole == null) return false;
|
if (interfaceConsole == null) return false;
|
||||||
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Asset, Id));
|
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Asset, Id));
|
||||||
}
|
}
|
||||||
@@ -113,15 +81,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (dataItemMgr != null)
|
return internals.DataItemMgr.HasItemLinks(Sbm.ItemType.Asset, Id);
|
||||||
return dataItemMgr.HasItemLinks(Sbm.ItemType.Asset, Id);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
public override bool ClearDependentData()
|
public override bool ClearDependentData()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (this == null || !SysId.IsValid(Id)) return false;
|
if (this == null || !SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null && !HasErrorState())
|
if (db != null && !HasErrorState())
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -151,26 +117,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Remove items data.
|
// Remove items data.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SbmDataItemMgr dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
if (internals.DataItemMgr != null)
|
||||||
if (dataItemMgr != null)
|
|
||||||
{
|
{
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Asset, Id))
|
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Asset, Id))
|
||||||
SetErrorState(dataItemMgr.ErrorState.ToString());
|
SetErrorState(internals.DataItemMgr.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve Data Item manager");
|
else SetErrorState("Failed to retrieve Data Item manager");
|
||||||
}
|
}
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove interface data items.
|
// Remove interface data items.
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
if (internals.InterfaceConsole != null)
|
||||||
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
|
||||||
if (interfaceConsole != null)
|
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), userContext.DbUpdateInfo))
|
if (!internals.InterfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
SetErrorState(internals.InterfaceConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
interfaceConsole = null; // Do not delete this global object.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else SetErrorState("database is unavailable");
|
else SetErrorState("database is unavailable");
|
||||||
@@ -185,15 +147,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (activeOnly)
|
if (activeOnly)
|
||||||
{
|
{
|
||||||
// Retrieve the list of 'active' processes for this item.
|
// Retrieve the list of 'active' processes for this item.
|
||||||
processMgr.GetProcessesForItem(Sbm.ItemType.Asset, Id, true);
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.Asset, Id, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Full list required - check whether the internal list has been populated yet.
|
// Full list required - check whether the internal list has been populated yet.
|
||||||
if (itemProcesses == null && SysId.IsValid(Id) && processMgr != null)
|
if (itemProcesses == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Get the list of processes:
|
// Get the list of processes:
|
||||||
itemProcesses = processMgr.GetProcessesForItem(Sbm.ItemType.Asset, Id, false);
|
itemProcesses = internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.Asset, Id, false);
|
||||||
}
|
}
|
||||||
// Copy the list.
|
// Copy the list.
|
||||||
itemProcesesCopy = new List<SbmItemProcess>(itemProcesses);
|
itemProcesesCopy = new List<SbmItemProcess>(itemProcesses);
|
||||||
@@ -213,7 +175,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
SbmAsset asset = null;
|
SbmAsset asset = null;
|
||||||
if (!processMgr.StoreItemProcesses(Sbm.ItemType.Asset, Id, itemProcesses, userContext.DbUpdateInfo))
|
if (!internals.ProcessMgr.StoreItemProcesses(Sbm.ItemType.Asset, Id, itemProcesses, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
// Make a note of the 'Next' process.
|
// Make a note of the 'Next' process.
|
||||||
SbmItemProcess itemProcessNext = itemProcesses.GetNextProcessInSequence(SaStatus.Awaiting);
|
SbmItemProcess itemProcessNext = itemProcesses.GetNextProcessInSequence(SaStatus.Awaiting);
|
||||||
@@ -221,15 +183,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (ProcessIdNext != itemProcessIdNext)
|
if (ProcessIdNext != itemProcessIdNext)
|
||||||
{
|
{
|
||||||
ProcessIdNext = itemProcessIdNext;
|
ProcessIdNext = itemProcessIdNext;
|
||||||
if (assetMgr != null)
|
if (!internals.AssetMgr.UpdateAsset(asset, internals.DbUpdateInfo))
|
||||||
{
|
SetErrorState("Failed to update next process id - " + internals.AssetMgr.ErrorState);
|
||||||
if (!assetMgr.UpdateAsset(asset, userContext.DbUpdateInfo))
|
|
||||||
SetErrorState("Failed to update next process id - " + assetMgr.ErrorState);
|
|
||||||
}
|
|
||||||
else SetErrorState("Asset manager is unavailable");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SetErrorState(processMgr.ErrorState.ToString());
|
SetErrorState(internals.ProcessMgr.ErrorState.ToString());
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
}
|
}
|
||||||
public override bool PopulateDefaultProcesses()
|
public override bool PopulateDefaultProcesses()
|
||||||
@@ -267,7 +225,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
||||||
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
||||||
prm.ItemIdFrom = Id;
|
prm.ItemIdFrom = Id;
|
||||||
foreach (SbmItemLink itemLink in dataItemMgr.GetItemLinkList(prm))
|
foreach (SbmItemLink itemLink in internals.DataItemMgr.GetItemLinkList(prm))
|
||||||
if (itemLink != null) return true;
|
if (itemLink != null) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -275,13 +233,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override List<SbmItemPrice> GetPrices()
|
public override List<SbmItemPrice> GetPrices()
|
||||||
{
|
{
|
||||||
List<SbmItemPrice> itemPricesCopy = null;
|
List<SbmItemPrice> itemPricesCopy = null;
|
||||||
if (itemPrices == null && SysId.IsValid(Id) && dataItemMgr != null)
|
if (itemPrices == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
SbmItemLink.Params prm = new SbmItemLink.Params();
|
SbmItemLink.Params prm = new SbmItemLink.Params();
|
||||||
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
prm.ItemLinkType = Sbm.ItemLinkType.ItemPrice;
|
||||||
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
prm.ItemTypeFrom = Sbm.ItemType.Asset;
|
||||||
prm.ItemIdFrom = Id;
|
prm.ItemIdFrom = Id;
|
||||||
List<SbmItemLink> itemLinks = dataItemMgr.GetItemLinkList(prm);
|
List<SbmItemLink> itemLinks = internals.DataItemMgr.GetItemLinkList(prm);
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
{
|
{
|
||||||
foreach (SbmItemLink itemLink in itemLinks)
|
foreach (SbmItemLink itemLink in itemLinks)
|
||||||
@@ -314,14 +272,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
// Do not attempt any updates unless the list has been populated:
|
// Do not attempt any updates unless the list has been populated:
|
||||||
if (itemPrices != null && SysId.IsValid(Id) && dataItemMgr != null)
|
if (itemPrices != null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Build an item link list corresponding to the list of prices.
|
// Build an item link list corresponding to the list of prices.
|
||||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||||
foreach (SbmItemPrice itemPrice in itemPrices)
|
foreach (SbmItemPrice itemPrice in itemPrices)
|
||||||
{
|
{
|
||||||
if (itemPrice == null) continue;
|
if (itemPrice == null) continue;
|
||||||
SbmItemLink itemLink = dataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemPrice, Sbm.ItemType.Asset, Id, Sbm.ItemType.Unknown, new SysId(0));
|
SbmItemLink itemLink = internals.DataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemPrice, Sbm.ItemType.Asset, Id, Sbm.ItemType.Unknown, new SysId(0));
|
||||||
if (itemLink != null)
|
if (itemLink != null)
|
||||||
{
|
{
|
||||||
itemLink.Seq = (short)itemPrice.CodeSeq;
|
itemLink.Seq = (short)itemPrice.CodeSeq;
|
||||||
@@ -332,12 +290,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Store these details.
|
// Store these details.
|
||||||
if (dataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemPrice, Sbm.ItemType.Asset, Id, itemLinks, userContext.DbUpdateInfo))
|
if (internals.DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemPrice, Sbm.ItemType.Asset, Id, itemLinks, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetErrorState("Failed to save asset price item links - " + dataItemMgr.ErrorState);
|
SetErrorState("Failed to save asset price item links - " + internals.DataItemMgr.ErrorState);
|
||||||
}
|
}
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
itemLinks.Clear();
|
itemLinks.Clear();
|
||||||
|
|||||||
@@ -13,20 +13,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmAssociation_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.AssociationType associationType, SysId affiliateIdTarget, ushort flags) :
|
public SbmAssociation_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.AssociationType associationType, SysId affiliateIdTarget, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, associationType, affiliateIdTarget)
|
base(internals.UserContext, id, affiliateIdOwner, associationType, affiliateIdTarget)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasTransactions()
|
public override bool HasTransactions()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssocId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssocId) + "=" + Id.ToString();
|
||||||
@@ -53,7 +54,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasRequirements()
|
public override bool HasRequirements()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssocId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_AssocId) + "=" + Id.ToString();
|
||||||
@@ -64,7 +65,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasConstituents()
|
public override bool HasConstituents()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_AssocId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_AssocId) + "=" + Id.ToString();
|
||||||
@@ -76,7 +77,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
// Is associated with transaction for delivery.
|
// Is associated with transaction for delivery.
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssIdDeliver) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Transaction_AssIdDeliver) + "=" + Id.ToString();
|
||||||
@@ -89,16 +90,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
if (SbmGlobals.System == null) return SetErrorState("System is not available");
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null) return SetErrorState("Database is not available");
|
if (db != null) return SetErrorState("Database is not available");
|
||||||
|
|
||||||
// Delete interface data items.
|
// Delete interface data items.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Association, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("failed to initialise interface console");
|
else SetErrorState("failed to initialise interface console");
|
||||||
@@ -119,13 +120,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Remove data item references.
|
// Remove data item references.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
SbmDataItemMgr dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Association, Id))
|
||||||
if (dataItemMgr != null)
|
SetErrorState(internals.DataItemMgr.ErrorState.ToString());
|
||||||
{
|
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Association, Id))
|
|
||||||
SetErrorState(dataItemMgr.ErrorState.ToString());
|
|
||||||
}
|
|
||||||
else SetErrorState("Data item manager is not available");
|
|
||||||
}
|
}
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmCommodityCustomer_Dbas(SbmUserContext userContext, SysId commodityId, SysId assocIdCustomer, ushort flags) :
|
public SbmCommodityCustomer_Dbas(SbmInternals internals, SysId commodityId, SysId assocIdCustomer, ushort flags) :
|
||||||
base(userContext, commodityId, assocIdCustomer)
|
base(internals.UserContext, commodityId, assocIdCustomer)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmCommoditySupplier_Dbas(SbmUserContext userContext, SysId commodityId, SysId assocIdSupplier, ushort flags) :
|
public SbmCommoditySupplier_Dbas(SbmInternals internals, SysId commodityId, SysId assocIdSupplier, ushort flags) :
|
||||||
base(userContext, commodityId, assocIdSupplier)
|
base(internals.UserContext, commodityId, assocIdSupplier)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,28 +18,23 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmDataItemMgr dataItemMgr;
|
|
||||||
private SbmProcessMgr processMgr;
|
|
||||||
private SbmTransactionMgr transactionMgr;
|
|
||||||
private List<SbmCostEstimate> costEstimates = new List<SbmCostEstimate>();
|
private List<SbmCostEstimate> costEstimates = new List<SbmCostEstimate>();
|
||||||
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmCommodity_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.CommodityType commodityType, String code, ushort flags) :
|
public SbmCommodity_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.CommodityType commodityType, String code, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, commodityType, code)
|
base(internals.UserContext, id, affiliateIdOwner, commodityType, code)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (transactionMgr != null) transactionMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
if (processMgr != null) processMgr.Dispose();
|
|
||||||
if (dataItemMgr != null) dataItemMgr.Dispose();
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -47,27 +42,6 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Internal Processing.
|
|
||||||
public bool InitDataItemMgr()
|
|
||||||
{
|
|
||||||
if (dataItemMgr == null)
|
|
||||||
dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
|
||||||
return dataItemMgr != null;
|
|
||||||
}
|
|
||||||
public bool InitProcMgr()
|
|
||||||
{
|
|
||||||
if (processMgr == null)
|
|
||||||
processMgr = SbmGlobals.System.CreateProcessMgr(userContext);
|
|
||||||
return processMgr != null;
|
|
||||||
}
|
|
||||||
public bool InitTransactionMgr()
|
|
||||||
{
|
|
||||||
if (transactionMgr == null)
|
|
||||||
transactionMgr = SbmGlobals.System.CreateTransactionMgr(userContext);
|
|
||||||
return transactionMgr != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@@ -75,14 +49,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||||
if (processMgr != null) return SetErrorState("process manager not available");
|
return internals.ProcessMgr.HasItemProcesses(Sbm.ItemType.Commodity, Id);
|
||||||
return processMgr.HasItemProcesses(Sbm.ItemType.Commodity, Id);
|
|
||||||
}
|
}
|
||||||
public override bool HasRequirements()
|
public override bool HasRequirements()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableRequirement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement);
|
String tableRequirement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement);
|
||||||
@@ -95,7 +68,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableCommodity = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity);
|
String tableCommodity = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity);
|
||||||
@@ -113,7 +86,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||||
@@ -131,7 +104,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableContainer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Container);
|
String tableContainer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Container);
|
||||||
@@ -149,7 +122,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasCustomerDetails()
|
public override bool HasCustomerDetails()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableCommodityCustomer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer);
|
String tableCommodityCustomer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer);
|
||||||
@@ -165,7 +138,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasSupplierDetails()
|
public override bool HasSupplierDetails()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableCommoditySupplier = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommoditySupplier);
|
String tableCommoditySupplier = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommoditySupplier);
|
||||||
@@ -182,7 +155,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||||
@@ -201,7 +174,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
||||||
@@ -218,26 +191,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null && !HasErrorState())
|
if (db != null && !HasErrorState())
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove data item references.
|
// Remove data item references.
|
||||||
if (dataItemMgr != null)
|
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Commodity, Id))
|
||||||
{
|
SetErrorState(internals.DataItemMgr.ErrorState.ToString());
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Commodity, Id))
|
|
||||||
SetErrorState(dataItemMgr.ErrorState.ToString());
|
|
||||||
}
|
|
||||||
else SetErrorState("Data item manager is not available");
|
|
||||||
}
|
}
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// ToDo SaItemDocConsole for Remove document references.
|
// ToDo SaItemDocConsole for Remove document references.
|
||||||
SaItemDocConsole itemDocConsole = SbmGlobals.Application.GetItemDocConsole(userContext);
|
SaItemDocConsole itemDocConsole = internals.ItemDocConsole;
|
||||||
if (itemDocConsole != null)
|
if (itemDocConsole != null)
|
||||||
{
|
{
|
||||||
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.Commodity, Id), SaItemDocConsole.Category.Document, userContext.DbUpdateInfo))
|
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.Commodity, Id), SaItemDocConsole.Category.Document, internals.DbUpdateInfo))
|
||||||
SetErrorState(itemDocConsole.ErrorState.ToString());
|
SetErrorState(itemDocConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve item document console");
|
else SetErrorState("Failed to retrieve item document console");
|
||||||
@@ -246,10 +215,10 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove interface references.
|
// Remove interface references.
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Commodity, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Commodity, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
SetErrorState(interfaceConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
@@ -281,11 +250,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//ClearErrorState();
|
//ClearErrorState();
|
||||||
List<SbmCostEstimate> costEstimatesCopy = null;
|
List<SbmCostEstimate> costEstimatesCopy = null;
|
||||||
if (costEstimates == null && SysId.IsValid(Id) && dataItemMgr != null)
|
if (costEstimates == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
//***************************************************************
|
//***************************************************************
|
||||||
// 15-Dec MPE Fix - Commodity cost estimates were stored as requirement cost estimates. Here we convert the data for this commodity.
|
// 15-Dec MPE Fix - Commodity cost estimates were stored as requirement cost estimates. Here we convert the data for this commodity.
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null /*&& SbmGlobals.GetConsole().GetVersion().GetName() == "MPE" && Id.ToInt() < 6000*/)
|
if (db != null /*&& SbmGlobals.GetConsole().GetVersion().GetName() == "MPE" && Id.ToInt() < 6000*/)
|
||||||
{
|
{
|
||||||
String colItemLink_Type = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_Type);
|
String colItemLink_Type = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_Type);
|
||||||
@@ -315,7 +284,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
prmItemLink.ItemLinkType = Sbm.ItemLinkType.ItemCostEstimate;
|
prmItemLink.ItemLinkType = Sbm.ItemLinkType.ItemCostEstimate;
|
||||||
prmItemLink.ItemTypeFrom = Sbm.ItemType.Commodity;
|
prmItemLink.ItemTypeFrom = Sbm.ItemType.Commodity;
|
||||||
prmItemLink.ItemIdFrom = Id;
|
prmItemLink.ItemIdFrom = Id;
|
||||||
List<SbmItemLink> itemLinks = dataItemMgr.GetItemLinkList(prmItemLink);
|
List<SbmItemLink> itemLinks = internals.DataItemMgr.GetItemLinkList(prmItemLink);
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
{
|
{
|
||||||
foreach (SbmItemLink itemLink in itemLinks)
|
foreach (SbmItemLink itemLink in itemLinks)
|
||||||
@@ -346,14 +315,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool CommitCostEstimates()
|
public override bool CommitCostEstimates()
|
||||||
{
|
{
|
||||||
ClearErrorState();// Do not attempt any updates unless the list has been populated.
|
ClearErrorState();// Do not attempt any updates unless the list has been populated.
|
||||||
if (costEstimates != null && SysId.IsValid(Id) && dataItemMgr != null)
|
if (costEstimates != null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Build an item link list corresponding to the list of cost estimates.
|
// Build an item link list corresponding to the list of cost estimates.
|
||||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||||
foreach (SbmCostEstimate costEstimate in costEstimates)
|
foreach (SbmCostEstimate costEstimate in costEstimates)
|
||||||
{
|
{
|
||||||
if (costEstimate == null) continue;
|
if (costEstimate == null) continue;
|
||||||
SbmItemLink itemLink = dataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, Sbm.ItemType.Unknown, new SysId());
|
SbmItemLink itemLink = internals.DataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, Sbm.ItemType.Unknown, new SysId());
|
||||||
if (itemLink != null)
|
if (itemLink != null)
|
||||||
{
|
{
|
||||||
itemLink.Seq = (short)costEstimate.CodeSeq;
|
itemLink.Seq = (short)costEstimate.CodeSeq;
|
||||||
@@ -364,12 +333,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Store these details.
|
// Store these details.
|
||||||
if (dataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, itemLinks, userContext.DbUpdateInfo))
|
if (internals.DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, itemLinks, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetErrorState("Failed to save cost estimate item links - " + dataItemMgr.ErrorState);
|
SetErrorState("Failed to save cost estimate item links - " + internals.DataItemMgr.ErrorState);
|
||||||
}
|
}
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
itemLinks.Clear();
|
itemLinks.Clear();
|
||||||
@@ -386,15 +355,15 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (activeOnly)
|
if (activeOnly)
|
||||||
{
|
{
|
||||||
// Retrieve the list of 'active' processes for this item.
|
// Retrieve the list of 'active' processes for this item.
|
||||||
processMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, true);
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Full list required - check whether the internal list has been populated yet.
|
// Full list required - check whether the internal list has been populated yet.
|
||||||
if (itemProcesses == null && SysId.IsValid(Id) && processMgr != null)
|
if (itemProcesses == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Get the list of processes.
|
// Get the list of processes.
|
||||||
processMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, false);
|
internals.ProcessMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, false);
|
||||||
}
|
}
|
||||||
// Clone the list.
|
// Clone the list.
|
||||||
itemProcesesCopy = itemProcesses.Clone();
|
itemProcesesCopy = itemProcesses.Clone();
|
||||||
@@ -413,8 +382,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool CommitProcesses()
|
public override bool CommitProcesses()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!processMgr.StoreItemProcesses(Sbm.ItemType.Commodity, Id, itemProcesses, userContext.DbUpdateInfo))
|
if (!internals.ProcessMgr.StoreItemProcesses(Sbm.ItemType.Commodity, Id, itemProcesses, internals.DbUpdateInfo))
|
||||||
SetErrorState(processMgr.ErrorState.ToString());
|
SetErrorState(internals.ProcessMgr.ErrorState.ToString());
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,20 +11,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmConstituent_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, SysId assocId, Sbm.ConstituentType constituentType, ushort flags) :
|
public SbmConstituent_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, Sbm.ConstituentType constituentType, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, assocId, constituentType)
|
base(internals.UserContext, id, affIdOwner, assocId, constituentType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -37,7 +38,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasConstituents()
|
public override bool HasConstituents()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext);
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ConstId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ConstId) + "=" + Id.ToString();
|
||||||
|
|||||||
@@ -9,23 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmContainerItem_Dbas(SbmUserContext userContext, SysId containerId, Sbm.ItemType itemType, SysId itemId, ushort flags) :
|
public SbmContainerItem_Dbas(SbmInternals internals, SysId containerId, Sbm.ItemType itemType, SysId itemId, ushort flags) :
|
||||||
base(userContext, containerId, itemType, itemId)
|
base(internals.UserContext, containerId, itemType, itemId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
ContainerId = containerId;
|
|
||||||
ItemType = itemType;
|
|
||||||
ItemId = itemId;
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,24 +15,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmContainer_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.ContainerCategory containerCategory, Sbm.ContainerType containerType, ushort flags) :
|
public SbmContainer_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.ContainerCategory containerCategory, Sbm.ContainerType containerType, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, containerCategory, containerType)
|
base(internals.UserContext, id, affiliateIdOwner, containerCategory, containerType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Id = id;
|
|
||||||
AffiliateIdOwner = affiliateIdOwner;
|
|
||||||
ContainerCategory = containerCategory;
|
|
||||||
ContainerType = containerType;
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -46,7 +43,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableContainItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.ContainerItem);
|
String tableContainItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.ContainerItem);
|
||||||
@@ -63,7 +60,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||||
@@ -81,7 +78,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||||
|
|||||||
@@ -10,20 +10,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmItemBatch_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, Sbm.ItemBatchType itemBatchType, String reference, ushort flags) :
|
public SbmItemBatch_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.ItemBatchType itemBatchType, String reference, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, itemBatchType, reference)
|
base(internals.UserContext, id, affIdOwner, itemBatchType, reference)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmItemLink_Dbas(SbmUserContext userContext, SysId id, Sbm.ItemLinkType itemLinkType, Sbm.ItemType itemTypeFrom, SysId itemIdFrom, Sbm.ItemType itemTypeTo, SysId itemIdTo, ushort flags) :
|
public SbmItemLink_Dbas(SbmInternals internals, SysId id, Sbm.ItemLinkType itemLinkType, Sbm.ItemType itemTypeFrom, SysId itemIdFrom, Sbm.ItemType itemTypeTo, SysId itemIdTo, ushort flags) :
|
||||||
base(userContext, id, itemLinkType, itemTypeFrom, itemIdFrom, itemTypeTo, itemIdTo)
|
base(internals.UserContext, id, itemLinkType, itemTypeFrom, itemIdFrom, itemTypeTo, itemIdTo)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmItemProcess_Dbas(SbmUserContext userContext, Sbm.ItemType itemType, SysId itemId, SysId processId, ushort flags) :
|
public SbmItemProcess_Dbas(SbmInternals internals, Sbm.ItemType itemType, SysId itemId, SysId processId, ushort flags) :
|
||||||
base(userContext, itemType, itemId, processId)
|
base(internals.UserContext, itemType, itemId, processId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,20 +14,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmLocation_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.LocationCategory locationCategory, ushort flags) :
|
public SbmLocation_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.LocationCategory locationCategory, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, locationCategory)
|
base(internals.UserContext, id, affiliateIdOwner, locationCategory)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -41,7 +42,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||||
@@ -58,7 +59,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmMovement_Dbas(SbmUserContext userContext, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.MovementType movementType, ushort flags) :
|
public SbmMovement_Dbas(SbmInternals internals, SysId id, Sbm.ItemType itemType, SysId itemId, Sbm.MovementType movementType, ushort flags) :
|
||||||
base(userContext, id, itemType, itemId, movementType)
|
base(internals.UserContext, id, itemType, itemId, movementType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Id = id;
|
Id = id;
|
||||||
MovementType = movementType;
|
MovementType = movementType;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
@@ -25,6 +25,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmPortfolioItem_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.PortfolioItemType portfolioItemType, ushort flags) :
|
public SbmPortfolioItem_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, Sbm.PortfolioItemType portfolioItemType, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, portfolioItemType)
|
base(internals.UserContext, id, affiliateIdOwner, portfolioItemType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -47,7 +48,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return 0;
|
if (!SysId.IsValid(Id)) return 0;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||||
@@ -66,7 +67,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||||
@@ -109,7 +110,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.PortfolioItem, Id))
|
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.PortfolioItem, Id))
|
||||||
return SetErrorState(dataItemMgr.ErrorStateMessage);
|
return SetErrorState(dataItemMgr.ErrorStateMessage);
|
||||||
}
|
}
|
||||||
SaItemDocConsole itemDocConsole = SbmGlobals.GetItemDocConsole(UserContext);
|
SaItemDocConsole itemDocConsole = internals.ItemDocConsole;
|
||||||
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.PortfolioItem, Id), SaItemDocConsole.Category.Unknown, UserContext.DbUpdateInfo))
|
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.PortfolioItem, Id), SaItemDocConsole.Category.Unknown, UserContext.DbUpdateInfo))
|
||||||
return SetErrorState(itemDocConsole.ErrorStateMessage);
|
return SetErrorState(itemDocConsole.ErrorStateMessage);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -15,22 +15,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmPriceMgr priceMgr;
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmPriceSet_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType, ushort flags) :
|
public SbmPriceSet_Dbas(SbmInternals internals, SysId id, SysId affiliateIdOwner, String reference, Sbm.PriceType priceType, ushort flags) :
|
||||||
base(userContext, id, affiliateIdOwner, reference, priceType)
|
base(internals.UserContext, id, affiliateIdOwner, reference, priceType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (priceMgr != null) priceMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -38,23 +37,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Internal Processing.
|
|
||||||
public bool InitPriceMgr()
|
|
||||||
{
|
|
||||||
if (priceMgr == null)
|
|
||||||
priceMgr = SbmGlobals.System.CreatePriceMgr(userContext);
|
|
||||||
return (priceMgr != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
public override bool HasPrices()
|
public override bool HasPrices()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
InitPriceMgr();
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tablePrice = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaPrice);
|
String tablePrice = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaPrice);
|
||||||
|
|||||||
@@ -9,20 +9,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmPrice_Dbas(SbmUserContext userContext, SysId priceSetId, SysId commodityId, Sbm.PriceType priceType, ushort flags) :
|
public SbmPrice_Dbas(SbmInternals internals, SysId priceSetId, SysId commodityId, Sbm.PriceType priceType, ushort flags) :
|
||||||
base(userContext, priceSetId, commodityId, priceType)
|
base(internals.UserContext, priceSetId, commodityId, priceType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,42 +16,30 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SaItemDataConsole itemDataConsole;
|
|
||||||
private SbmDataItemMgr dataItemMgr;
|
|
||||||
private readonly List<TypeCodeDesc> itemDataTypes;
|
private readonly List<TypeCodeDesc> itemDataTypes;
|
||||||
private static readonly String codeDelim = ",";
|
private static readonly String codeDelim = ",";
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmProcess_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, Sbm.ProcessCategory processCategory, ushort flags) :
|
public SbmProcess_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.ProcessCategory processCategory, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, processCategory)
|
base(internals.UserContext, id, affIdOwner, processCategory)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
itemDataTypes = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.ItemDataType);
|
itemDataTypes = SbmSystem.GetCodesOfType(internals.UserContext, Sbm.SystemCode.ItemDataType);
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (dataItemMgr != null) dataItemMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
private SbmDataItemMgr DataItemMgr { get { if (dataItemMgr == null) dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext); return dataItemMgr; } }
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// I n i t i a l i s a t i o n
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
private void InitItemDataConsole()
|
|
||||||
{
|
|
||||||
if (itemDataConsole == null)
|
|
||||||
itemDataConsole = SbmGlobals.Application.GetItemDataConsole(userContext);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated codes.
|
// Associated codes.
|
||||||
@@ -69,8 +57,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasCostCodes()
|
public override bool HasCostCodes()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (itemDataConsole == null || !SysId.IsValid(Id)) return false;
|
|
||||||
|
|
||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
@@ -78,13 +65,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Fixed_Job));
|
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Fixed_Job));
|
||||||
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Unit));
|
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Unit));
|
||||||
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Job));
|
prmItemData.IncludedDataTypes.Add(GetCodeForCostCode(SbmProcessCostCode.Labour_Job));
|
||||||
return itemDataConsole.ItemDataExists(prmItemData);
|
return internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||||
}
|
}
|
||||||
public override bool HasCostCodes(SbmProcessCostCode processCostCode)
|
public override bool HasCostCodes(SbmProcessCostCode processCostCode)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (itemDataConsole == null || !SysId.IsValid(Id)) return false;
|
|
||||||
bool bHas = false;
|
bool bHas = false;
|
||||||
// Identify process code type code.
|
// Identify process code type code.
|
||||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||||
@@ -93,7 +79,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
||||||
bHas = itemDataConsole.ItemDataExists(prmItemData);
|
bHas = internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||||
}
|
}
|
||||||
return bHas;
|
return bHas;
|
||||||
}
|
}
|
||||||
@@ -103,13 +89,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
// Identify process code type code.
|
// Identify process code type code.
|
||||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||||
if (itemDataConsole != null || !SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
|
||||||
{
|
{
|
||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
||||||
List<SaItemData> itemDatas = itemDataConsole.GetItemDataList(prmItemData);
|
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||||
foreach (SaItemData itemData in itemDatas)
|
foreach (SaItemData itemData in itemDatas)
|
||||||
{
|
{
|
||||||
if (itemData == null) continue;
|
if (itemData == null) continue;
|
||||||
@@ -126,13 +111,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (StringUtil.IsEmpty(costCodes.Concat(codeDelim))) return ClearCostCodes(processCostCode);
|
if (StringUtil.IsEmpty(costCodes.Concat(codeDelim))) return ClearCostCodes(processCostCode);
|
||||||
// Identify process code type code.
|
// Identify process code type code.
|
||||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||||
if (itemDataConsole != null || !SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
|
||||||
{
|
{
|
||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
prmItemData.IncludedDataTypes.Add(itemDataTypeCode);
|
||||||
List<SaItemData> itemDatas = itemDataConsole.GetItemDataList(prmItemData);
|
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||||
// ToDo itemData condition.
|
// ToDo itemData condition.
|
||||||
//itemDatas.GotoStart();
|
//itemDatas.GotoStart();
|
||||||
SaItemData itemData = null;//itemDatas.Count == 1 ? itemDatas.Remove(1) : null;
|
SaItemData itemData = null;//itemDatas.Count == 1 ? itemDatas.Remove(1) : null;
|
||||||
@@ -140,16 +124,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (itemData == null)
|
if (itemData == null)
|
||||||
{
|
{
|
||||||
// Code type not found - create a new entry.
|
// Code type not found - create a new entry.
|
||||||
itemData = itemDataConsole.CreateItemData(new ItemId((short)Sbm.ItemType.Process, Id));
|
itemData = internals.ItemDataConsole.CreateItemData(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
itemData.DataType = itemDataTypeCode;
|
itemData.DataType = itemDataTypeCode;
|
||||||
}
|
}
|
||||||
if (itemData != null)
|
if (itemData != null)
|
||||||
{
|
{
|
||||||
// Populate item data for these codes.
|
// Populate item data for these codes.
|
||||||
itemData.ItemData = costCodes.Concat(codeDelim);
|
itemData.ItemData = costCodes.Concat(codeDelim);
|
||||||
if (!itemDataConsole.Store(itemData, userContext.DbUpdateInfo))
|
if (!internals.ItemDataConsole.Store(itemData, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
SetErrorState(itemDataConsole.ErrorStateMessage);
|
SetErrorState(internals.ItemDataConsole.ErrorStateMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,12 +144,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
// Identify process code type code.
|
// Identify process code type code.
|
||||||
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
String itemDataTypeCode = GetCodeForCostCode(processCostCode);
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
||||||
if (itemDataConsole != null || !SysId.IsValid(Id) && !StringUtil.IsEmpty(itemDataTypeCode))
|
|
||||||
{
|
{
|
||||||
if (!itemDataConsole.ClearItemData(new ItemId((short)Sbm.ItemType.Process, Id), itemDataTypeCode, userContext.DbUpdateInfo))
|
if (!internals.ItemDataConsole.ClearItemData(new ItemId((short)Sbm.ItemType.Process, Id), itemDataTypeCode, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
SetErrorState(itemDataConsole.ErrorStateMessage);
|
SetErrorState(internals.ItemDataConsole.ErrorStateMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
@@ -181,9 +164,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasReferences()
|
public override bool HasReferences()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (DataItemMgr.HasItemLinks(Sbm.ItemType.Process, Id)) return true;
|
if (internals.DataItemMgr.HasItemLinks(Sbm.ItemType.Process, Id)) return true;
|
||||||
// Is this process referenced by Constituents.
|
// Is this process referenced by Constituents.
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext); if (db != null) return true;
|
ISacsDatabase db = SbmGlobals.Application.GetBusMgrDatabase(internals.SessionContext); if (db != null) return true;
|
||||||
|
|
||||||
// Constituents.
|
// Constituents.
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ProcessId) + "=" + Id.ToString();
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_Id) + "=" + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Constituent_ProcessId) + "=" + Id.ToString();
|
||||||
@@ -192,29 +175,24 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasItemData()
|
public override bool HasItemData()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitItemDataConsole();
|
if (!SysId.IsValid(Id)) return false;
|
||||||
if (itemDataConsole == null || !SysId.IsValid(Id)) return false;
|
|
||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
return itemDataConsole.ItemDataExists(prmItemData);
|
return internals.ItemDataConsole.ItemDataExists(prmItemData);
|
||||||
}
|
}
|
||||||
public override bool ClearAssociatedData()
|
public override bool ClearAssociatedData()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return SetErrorState("item not specified");
|
if (!SysId.IsValid(Id)) return SetErrorState("item not specified");
|
||||||
// Clear Item data records.
|
// Clear Item data records.
|
||||||
InitItemDataConsole();
|
SaItemData.Params prmItemData = new SaItemData.Params();
|
||||||
if (itemDataConsole != null)
|
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
||||||
|
List<SaItemData> itemDatas = internals.ItemDataConsole.GetItemDataList(prmItemData);
|
||||||
|
foreach (SaItemData itemData in itemDatas)
|
||||||
{
|
{
|
||||||
SaItemData.Params prmItemData = new SaItemData.Params();
|
internals.ItemDataConsole.Remove(itemData, internals.DbUpdateInfo);
|
||||||
prmItemData.IncludedItemIds.Add(new ItemId((short)Sbm.ItemType.Process, Id));
|
|
||||||
List<SaItemData> itemDatas = itemDataConsole.GetItemDataList(prmItemData);
|
|
||||||
foreach (SaItemData itemData in itemDatas)
|
|
||||||
{
|
|
||||||
itemDataConsole.Remove(itemData, userContext.DbUpdateInfo);
|
|
||||||
}
|
|
||||||
itemDatas.Clear();
|
|
||||||
}
|
}
|
||||||
|
itemDatas.Clear();
|
||||||
return !HasErrorState();
|
return !HasErrorState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,75 +16,32 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private class Managers
|
|
||||||
{
|
|
||||||
public SbmDataItemMgr DataItemMgr { get; set; }
|
|
||||||
public SbmProcessMgr ProcessMgr { get; set; }
|
|
||||||
public SbmStockMgr StockMgr { get; set; }
|
|
||||||
public SbmTransactionMgr TransactionMgr { get; set; }
|
|
||||||
}
|
|
||||||
private readonly Managers mgrs = new Managers();
|
|
||||||
private readonly String statusCancelled = SacsSystem.GetStatusCode(SaStatus.Cancelled);
|
private readonly String statusCancelled = SacsSystem.GetStatusCode(SaStatus.Cancelled);
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmRequirement_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, SysId assocId, SysId transId, Sbm.RequirementType requirementType, ushort flags) :
|
public SbmRequirement_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, SysId transId, Sbm.RequirementType requirementType, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, assocId, transId, requirementType)
|
base(internals.UserContext, id, affIdOwner, assocId, transId, requirementType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (mgrs.StockMgr != null) mgrs.StockMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
if (mgrs.TransactionMgr != null) mgrs.TransactionMgr.Dispose();
|
|
||||||
if (mgrs.ProcessMgr != null) mgrs.ProcessMgr.Dispose();
|
|
||||||
if (mgrs.DataItemMgr != null) mgrs.DataItemMgr.Dispose();
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
private SbmTransactionMgr TransactionMgr
|
private SbmTransactionMgr TransactionMgr { get { return internals.TransactionMgr; } }
|
||||||
{
|
private SbmDataItemMgr DataItemMgr { get { return internals.DataItemMgr; } }
|
||||||
get
|
private SbmProcessMgr ProcessMgr { get { return internals.ProcessMgr; } }
|
||||||
{
|
private SbmStockMgr StockMgr { get { return internals.StockMgr; } }
|
||||||
if (mgrs.TransactionMgr == null)
|
|
||||||
mgrs.TransactionMgr = SbmGlobals.System.CreateTransactionMgr(userContext);
|
|
||||||
return mgrs.TransactionMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private SbmDataItemMgr DataItemMgr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (mgrs.DataItemMgr == null)
|
|
||||||
mgrs.DataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
|
||||||
return mgrs.DataItemMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private SbmProcessMgr ProcessMgr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (mgrs.ProcessMgr == null)
|
|
||||||
mgrs.ProcessMgr = SbmGlobals.System.CreateProcessMgr(userContext);
|
|
||||||
return mgrs.ProcessMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private SbmStockMgr StockMgr
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (mgrs.StockMgr == null)
|
|
||||||
mgrs.StockMgr = SbmGlobals.System.CreateStockMgr(userContext);
|
|
||||||
return mgrs.StockMgr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
@@ -148,7 +105,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
public override decimal GetQuantityDispatched(SysId transIdExclude)
|
public override decimal GetQuantityDispatched(SysId transIdExclude)
|
||||||
{
|
{
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (SysId.IsValid(Id))
|
if (SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Build query to sum associated dispatch item quantities.
|
// Build query to sum associated dispatch item quantities.
|
||||||
@@ -179,7 +136,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
public override decimal GetQuantityInvoiced(SysId transIdExclude)
|
public override decimal GetQuantityInvoiced(SysId transIdExclude)
|
||||||
{
|
{
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (SysId.IsValid(Id))
|
if (SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Build query to sum associated dispatch item quantities.
|
// Build query to sum associated dispatch item quantities.
|
||||||
@@ -263,7 +220,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Store these details.
|
// Store these details.
|
||||||
if (!DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Requirement_CostEstimate, Sbm.ItemType.Requirement, Id, itemLinks, userContext.DbUpdateInfo))
|
if (!DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Requirement_CostEstimate, Sbm.ItemType.Requirement, Id, itemLinks, internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to save cost estimate item links - " + DataItemMgr.ErrorState);
|
SetErrorState("Failed to save cost estimate item links - " + DataItemMgr.ErrorState);
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
itemLinks.Clear();
|
itemLinks.Clear();
|
||||||
@@ -319,7 +276,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
// Update the details.
|
// Update the details.
|
||||||
CopyFrom(itemProcessLocal, constituent);
|
CopyFrom(itemProcessLocal, constituent);
|
||||||
if (TransactionMgr.UpdateConstituent(constituent, userContext.DbUpdateInfo))
|
if (TransactionMgr.UpdateConstituent(constituent, internals.DbUpdateInfo))
|
||||||
itemProcessLocal.Changed = false;
|
itemProcessLocal.Changed = false;
|
||||||
else SetErrorState("failed to update process constituent");
|
else SetErrorState("failed to update process constituent");
|
||||||
}
|
}
|
||||||
@@ -330,7 +287,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
// Process no longer required.
|
// Process no longer required.
|
||||||
constituent.Status = SaStatus.Cancelled;
|
constituent.Status = SaStatus.Cancelled;
|
||||||
if (!TransactionMgr.DeleteConstituent(constituent, userContext.DbUpdateInfo))
|
if (!TransactionMgr.DeleteConstituent(constituent, internals.DbUpdateInfo))
|
||||||
SetErrorState("failed to delete process constituent");
|
SetErrorState("failed to delete process constituent");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +304,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
constituent.RequirementId = Id;
|
constituent.RequirementId = Id;
|
||||||
CopyFrom(itemprocess, constituent);
|
CopyFrom(itemprocess, constituent);
|
||||||
// Add it to the database:
|
// Add it to the database:
|
||||||
if (TransactionMgr.InsertConstituent(constituent, userContext.DbUpdateInfo))
|
if (TransactionMgr.InsertConstituent(constituent, internals.DbUpdateInfo))
|
||||||
itemprocess.Changed = false;
|
itemprocess.Changed = false;
|
||||||
else SetErrorState("failed to add constituent - " + TransactionMgr.ErrorState);
|
else SetErrorState("failed to add constituent - " + TransactionMgr.ErrorState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,20 +10,23 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmSysParam_Dbas(SbmUserContext userContext, SysId id, Sbm.SysParamCategory category, String name, ushort flags) :
|
public SbmSysParam_Dbas(SbmInternals internals, SysId id, Sbm.SysParamCategory category, String name, ushort flags) :
|
||||||
base(userContext, id, category, name)
|
base(internals.UserContext, id, category, name)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
|
if (this.internals != null) { }
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,23 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmSystemAccountUser_Dbas(SbmUserContext userContext, SysId accountId, SysId userId, ushort flags) :
|
public SbmSystemAccountUser_Dbas(SbmInternals internals, SysId accountId, SysId userId, ushort flags) :
|
||||||
base(userContext, accountId, userId)
|
base(internals.UserContext, accountId, userId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
|
if (this.internals != null) { }
|
||||||
|
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,20 +14,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmSystemAccount_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, Sbm.SystemAccountType systemAccountType, SysId interfaceId, SysId assocId, ushort flags) :
|
public SbmSystemAccount_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, Sbm.SystemAccountType systemAccountType, SysId interfaceId, SysId assocId, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, systemAccountType, interfaceId, assocId)
|
base(internals.UserContext, id, affIdOwner, systemAccountType, interfaceId, assocId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -40,7 +41,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasUsers()
|
public override bool HasUsers()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String table = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SystemAccountUser);
|
String table = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SystemAccountUser);
|
||||||
|
|||||||
@@ -9,20 +9,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmSystemUser_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, SysId interfaceId, SysId affiliateId, ushort flags) :
|
public SbmSystemUser_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId interfaceId, SysId affiliateId, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, interfaceId, affiliateId)
|
base(internals.UserContext, id, affIdOwner, interfaceId, affiliateId)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
|
if (this.internals != null) { }
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,12 +18,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
private SbmAccountMgr accountMgr;
|
|
||||||
private SbmDataItemMgr dataItemMgr;
|
|
||||||
private SbmStockMgr stockMgr;
|
|
||||||
private SbmTransactionMgr transactionMgr;
|
|
||||||
private SbmAccountsDfn accountDfn = null;
|
|
||||||
private List<SbmTransactionPayment> transactionPayments = new List<SbmTransactionPayment>();
|
private List<SbmTransactionPayment> transactionPayments = new List<SbmTransactionPayment>();
|
||||||
private readonly List<TypeCodeDesc> transactionTypes;
|
private readonly List<TypeCodeDesc> transactionTypes;
|
||||||
private readonly List<TypeCodeDesc> transactionStatusCats;
|
private readonly List<TypeCodeDesc> transactionStatusCats;
|
||||||
@@ -33,24 +28,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmTransaction_Dbas(SbmUserContext userContext, SysId id, SysId affIdOwner, SysId assocId, Sbm.TransactionType transactionType, ushort flags) :
|
public SbmTransaction_Dbas(SbmInternals internals, SysId id, SysId affIdOwner, SysId assocId, Sbm.TransactionType transactionType, ushort flags) :
|
||||||
base(userContext, id, affIdOwner, assocId, transactionType)
|
base(internals.UserContext, id, affIdOwner, assocId, transactionType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
transactionTypes = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.TransactionType);
|
transactionTypes = internals.GetCodesOfType(Sbm.SystemCode.TransactionType);
|
||||||
transactionStatusCats = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.TransactionStatusCat);
|
transactionStatusCats = internals.GetCodesOfType(Sbm.SystemCode.TransactionStatusCat);
|
||||||
requirementStatusCats = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.RequirementStatusCat);
|
requirementStatusCats = internals.GetCodesOfType(Sbm.SystemCode.RequirementStatusCat);
|
||||||
constituentStatusCats = SbmSystem.GetCodesOfType(userContext, Sbm.SystemCode.ConstituentStatusCat);
|
constituentStatusCats = internals.GetCodesOfType(Sbm.SystemCode.ConstituentStatusCat);
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
if (accountMgr != null) accountMgr.Dispose();
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
if (transactionMgr != null) transactionMgr.Dispose();
|
|
||||||
if (dataItemMgr != null) dataItemMgr.Dispose();
|
|
||||||
if (accountDfn != null) accountDfn.Dispose();
|
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -68,12 +60,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Transaction can't be updated after it has been exporetd to an accounts system.
|
// Transaction can't be updated after it has been exporetd to an accounts system.
|
||||||
if (!bReadOnly)
|
if (!bReadOnly)
|
||||||
{
|
{
|
||||||
if (accountDfn == null) accountDfn = new SbmAccountsDfn(userContext);
|
if (internals.AccountsDfn.IsTransactionTypeManagedByAccounts(TransactionType))
|
||||||
if (accountDfn != null)
|
bReadOnly = true;
|
||||||
{
|
|
||||||
if (accountDfn.IsTransactionTypeManagedByAccounts(TransactionType))
|
|
||||||
bReadOnly = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return bReadOnly;
|
return bReadOnly;
|
||||||
}
|
}
|
||||||
@@ -97,7 +85,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (TransactionStatusCat == SbmTransaction.StatusCat.Closed)
|
if (TransactionStatusCat == SbmTransaction.StatusCat.Closed)
|
||||||
{
|
{
|
||||||
// Once the 'grace' period has passed, only the status can be modified.
|
// Once the 'grace' period has passed, only the status can be modified.
|
||||||
int graceDaysUpdateClosedTrans = Math.Max(0, userContext.GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays.UpdateClosedTransaction, 0));
|
int graceDaysUpdateClosedTrans = Math.Max(0, internals.UserContext.GetOwnerOption_UpdateLimit(Sbm.OrgOption_PeriodDays.UpdateClosedTransaction, 0));
|
||||||
DateTime closed = Closed;
|
DateTime closed = Closed;
|
||||||
detailsAreReadOnly = (DateUtil.IsValid(closed) && closed <= DateTime.Today.AddDays(-graceDaysUpdateClosedTrans));
|
detailsAreReadOnly = (DateUtil.IsValid(closed) && closed <= DateTime.Today.AddDays(-graceDaysUpdateClosedTrans));
|
||||||
}
|
}
|
||||||
@@ -106,40 +94,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
return detailsAreReadOnly;
|
return detailsAreReadOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
|
||||||
// Internal Processing.
|
|
||||||
public bool InitAccountMgr()
|
|
||||||
{
|
|
||||||
if (accountMgr == null)
|
|
||||||
accountMgr = SbmGlobals.System.CreateAccountMgr(userContext);
|
|
||||||
return (accountMgr != null);
|
|
||||||
}
|
|
||||||
public bool InitDataItemMgr()
|
|
||||||
{
|
|
||||||
if (dataItemMgr == null)
|
|
||||||
dataItemMgr = SbmGlobals.System.CreateDataItemMgr(userContext);
|
|
||||||
return (dataItemMgr != null);
|
|
||||||
}
|
|
||||||
public bool InitStockMgr()
|
|
||||||
{
|
|
||||||
if (stockMgr == null)
|
|
||||||
stockMgr = SbmGlobals.System.CreateStockMgr(userContext);
|
|
||||||
return (stockMgr != null);
|
|
||||||
}
|
|
||||||
public bool InitTransactionMgr()
|
|
||||||
{
|
|
||||||
if (transactionMgr == null)
|
|
||||||
transactionMgr = SbmGlobals.System.CreateTransactionMgr(userContext);
|
|
||||||
return (transactionMgr != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Associated data.
|
// Associated data.
|
||||||
public override bool IsReferencedByOtherTransactions()
|
public override bool IsReferencedByOtherTransactions()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitTransactionMgr();
|
return internals.TransactionMgr.TransactionIsReferencedByOtherTransactions(Id);
|
||||||
return transactionMgr.TransactionIsReferencedByOtherTransactions(Id);
|
|
||||||
}
|
}
|
||||||
public override bool HasRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.NotDeleted)
|
public override bool HasRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.NotDeleted)
|
||||||
{
|
{
|
||||||
@@ -148,26 +108,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasConstituents(SbmConstituent.StatusCat constituentStatusCat = SbmConstituent.StatusCat.NotDeleted)
|
public override bool HasConstituents(SbmConstituent.StatusCat constituentStatusCat = SbmConstituent.StatusCat.NotDeleted)
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitTransactionMgr();
|
return internals.TransactionMgr.TransactionHasConstituents(Id, constituentStatusCat);
|
||||||
return transactionMgr.TransactionHasConstituents(Id, constituentStatusCat);
|
|
||||||
}
|
}
|
||||||
public override bool HasContainerItems()
|
public override bool HasContainerItems()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitTransactionMgr();
|
return internals.TransactionMgr.TransactionHasContainerItems(Id);
|
||||||
return transactionMgr.TransactionHasContainerItems(Id);
|
|
||||||
}
|
}
|
||||||
public override bool HasStockMovements()
|
public override bool HasStockMovements()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitTransactionMgr();
|
return internals.TransactionMgr.TransactionHasStockMovements(Id);
|
||||||
return transactionMgr.TransactionHasStockMovements(Id);
|
|
||||||
}
|
}
|
||||||
public override bool HasPendingStockMovements()
|
public override bool HasPendingStockMovements()
|
||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
InitTransactionMgr();
|
return internals.TransactionMgr.TransactionHasPendingStockMovements(Id);
|
||||||
return transactionMgr.TransactionHasPendingStockMovements(Id);
|
|
||||||
}
|
}
|
||||||
public override bool HasDiaryLinks()
|
public override bool HasDiaryLinks()
|
||||||
{
|
{
|
||||||
@@ -182,7 +138,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return 0;
|
if (!SysId.IsValid(Id)) return 0;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
List<String> filter = new List<String>();
|
List<String> filter = new List<String>();
|
||||||
@@ -198,21 +154,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
public override List<SbmRequirement> GetRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.Any)
|
public override List<SbmRequirement> GetRequirements(SbmRequirement.StatusCat requirementStatusCat = SbmRequirement.StatusCat.Any)
|
||||||
{
|
{
|
||||||
if (SysId.IsValid(Id) && InitTransactionMgr())
|
if (SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Retrieve the current set of requirements for this transaction.
|
// Retrieve the current set of requirements for this transaction.
|
||||||
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
||||||
//prmRequirement.RequirementStatusCat = requirementStatusCat;
|
//prmRequirement.RequirementStatusCat = requirementStatusCat;
|
||||||
prmRequirement.TransIncludedIds.Add(Id);
|
prmRequirement.TransIncludedIds.Add(Id);
|
||||||
return transactionMgr.GetRequirementList(prmRequirement);
|
return internals.TransactionMgr.GetRequirementList(prmRequirement);
|
||||||
}
|
}
|
||||||
return new List<SbmRequirement>();
|
return new List<SbmRequirement>();
|
||||||
}
|
}
|
||||||
public override bool ItemsRequireJobNumber()
|
public override bool ItemsRequireJobNumber()
|
||||||
{
|
{
|
||||||
// Check whether Job Number should be allocated:
|
// Check whether Job Number should be allocated:
|
||||||
SbmConfigConsole configConsole = SbmGlobals.GetConfigConsole(userContext.SessionContext);
|
SbmConfigConsole configConsole = internals.ConfigConsole;
|
||||||
if (configConsole != null && configConsole.AllowOption(UserContext, Sbm.ConfigOption.SalesOrderItemJobNumber) && SbmGlobals.Application.ColumnExists(userContext.SessionContext, SbmDbDfn.ColumnIdx.Requirement_JobNumber))
|
if (configConsole != null && configConsole.AllowOption(UserContext, Sbm.ConfigOption.SalesOrderItemJobNumber) && SbmGlobals.Application.BusMgrColumnExists(internals.SessionContext, SbmDbDfn.ColumnIdx.Requirement_JobNumber))
|
||||||
return TransactionType == Sbm.TransactionType.SalesOrder;
|
return TransactionType == Sbm.TransactionType.SalesOrder;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -220,10 +176,9 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
if (this == null) return false;
|
if (this == null) return false;
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
SacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext) as SacsDatabase;
|
SacsDatabase db = internals.BusMgrDatabase as SacsDatabase;
|
||||||
if (db == null) return SetErrorState("Database not available");
|
if (db == null) return SetErrorState("Database not available");
|
||||||
if (!SysId.IsValid(Id)) return SetErrorState("transaction does not exist");
|
if (!SysId.IsValid(Id)) return SetErrorState("transaction does not exist");
|
||||||
if (!InitTransactionMgr()) return SetErrorState("requirement manager is not available");
|
|
||||||
// Verify requirements list.
|
// Verify requirements list.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
@@ -253,7 +208,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
requirement.TransactionId = Id;
|
requirement.TransactionId = Id;
|
||||||
if (ItemsRequireJobNumber() && StringUtil.IsEmpty(requirement.JobNumber))
|
if (ItemsRequireJobNumber() && StringUtil.IsEmpty(requirement.JobNumber))
|
||||||
{
|
{
|
||||||
String jobNumberNextIdObject = "JobNumber:" + SysId.ToString(userContext.Organisation.AffiliateId);
|
String jobNumberNextIdObject = "JobNumber:" + SysId.ToString(internals.UserContext.Organisation.AffiliateId);
|
||||||
/*
|
/*
|
||||||
// Check for original Job Number 'NextId' key and convert to organisation specific.
|
// Check for original Job Number 'NextId' key and convert to organisation specific.
|
||||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.NextId_Object) + "='JobNumber'";
|
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.NextId_Object) + "='JobNumber'";
|
||||||
@@ -264,7 +219,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
db.ExecuteQuery(query);
|
db.ExecuteQuery(query);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
String jobNumber = SysId.ToString(db.GetNextId(jobNumberNextIdObject, userContext.DbUpdateInfo, false));
|
String jobNumber = SysId.ToString(db.GetNextId(jobNumberNextIdObject, internals.UserContext.DbUpdateInfo, false));
|
||||||
requirement.JobNumber = "";
|
requirement.JobNumber = "";
|
||||||
}
|
}
|
||||||
SetDefaults(requirement);
|
SetDefaults(requirement);
|
||||||
@@ -275,13 +230,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
List<SbmRequirement> requirementsNotUpdated = new List<SbmRequirement>(requirements);
|
List<SbmRequirement> requirementsNotUpdated = new List<SbmRequirement>(requirements);
|
||||||
// Retrieve each of the requirements currently specified for this transaction in turn.
|
// Retrieve each of the requirements currently specified for this transaction in turn.
|
||||||
List<SysId> requirementIdsUpdated = new List<SysId>();
|
List<SysId> requirementIdsUpdated = new List<SysId>();
|
||||||
if (!HasErrorState() && InitTransactionMgr())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
List<ColumnDfn> columnsQuery = new List<ColumnDfn>();
|
List<ColumnDfn> columnsQuery = new List<ColumnDfn>();
|
||||||
String colRequirement_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id);
|
String colRequirement_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id);
|
||||||
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
SbmRequirement.Params prmRequirement = new SbmRequirement.Params();
|
||||||
prmRequirement.TransIncludedIds.Add(Id);
|
prmRequirement.TransIncludedIds.Add(Id);
|
||||||
using (DbResultSet dbResultSet = transactionMgr.ExecuteRequirementQuery(columnsQuery, prmRequirement))
|
using (DbResultSet dbResultSet = internals.TransactionMgr.ExecuteRequirementQuery(columnsQuery, prmRequirement))
|
||||||
{
|
{
|
||||||
while (!HasErrorState() && dbResultSet != null && dbResultSet.NextRecord())
|
while (!HasErrorState() && dbResultSet != null && dbResultSet.NextRecord())
|
||||||
{
|
{
|
||||||
@@ -292,24 +247,24 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
// Requirement still in list - update the details.
|
// Requirement still in list - update the details.
|
||||||
SbmRequirement requirement = requirementsNotUpdated[0];
|
SbmRequirement requirement = requirementsNotUpdated[0];
|
||||||
if (transactionMgr.UpdateRequirement(requirement, userContext.DbUpdateInfo))
|
if (internals.TransactionMgr.UpdateRequirement(requirement, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
if (!requirement.CommitAssociatedData())
|
if (!requirement.CommitAssociatedData())
|
||||||
SetErrorState("Failed to update requirement's data: " + requirement.ErrorState);
|
SetErrorState("Failed to update requirement's data: " + requirement.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to update requirement: " + transactionMgr.ErrorState);
|
else SetErrorState("Failed to update requirement: " + internals.TransactionMgr.ErrorState);
|
||||||
requirementsNotUpdated.Remove(requirement);
|
requirementsNotUpdated.Remove(requirement);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Requirement not in list - remove it.
|
// Requirement not in list - remove it.
|
||||||
SbmRequirement requirement = transactionMgr.GetRequirement(prmRequirement);
|
SbmRequirement requirement = internals.TransactionMgr.GetRequirement(prmRequirement);
|
||||||
if (requirement != null)
|
if (requirement != null)
|
||||||
{
|
{
|
||||||
if (!transactionMgr.DeleteRequirement(requirement, TransactionType, userContext.DbUpdateInfo))
|
if (!internals.TransactionMgr.DeleteRequirement(requirement, TransactionType, internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to remove requirement: " + transactionMgr.ErrorState);
|
SetErrorState("Failed to remove requirement: " + internals.TransactionMgr.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve requirement for deletion: " + transactionMgr.ErrorState);
|
else SetErrorState("Failed to retrieve requirement for deletion: " + internals.TransactionMgr.ErrorState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,12 +278,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!SysId.IsValid(requirementNotUpdate.Id))
|
if (!SysId.IsValid(requirementNotUpdate.Id))
|
||||||
{
|
{
|
||||||
// Requirement does not yet exist - create it:
|
// Requirement does not yet exist - create it:
|
||||||
if (transactionMgr.InsertRequirement(requirementNotUpdate, userContext.DbUpdateInfo))
|
if (internals.TransactionMgr.InsertRequirement(requirementNotUpdate, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
if (!requirementNotUpdate.CommitAssociatedData())
|
if (!requirementNotUpdate.CommitAssociatedData())
|
||||||
SetErrorState("Failed to update requirement's data: " + requirementNotUpdate.ErrorState);
|
SetErrorState("Failed to update requirement's data: " + requirementNotUpdate.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to create requirement: " + transactionMgr.ErrorState);
|
else SetErrorState("Failed to create requirement: " + internals.TransactionMgr.ErrorState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else SetErrorState("null item in list");
|
else SetErrorState("null item in list");
|
||||||
@@ -349,16 +304,16 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Delete interface data items.
|
// Delete interface data items.
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Transaction, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Transaction, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
SetErrorState("Failed to clear interface data items - " + interfaceConsole.ErrorState);
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
@@ -379,12 +334,8 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
// Delete any associated items links.
|
// Delete any associated items links.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
if (InitDataItemMgr())
|
if (!internals.DataItemMgr.ClearDataItem(Sbm.ItemType.Transaction, Id))
|
||||||
{
|
SetErrorState("failed to clear transaction item links");
|
||||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Transaction, Id))
|
|
||||||
SetErrorState("failed to clear transaction item links");
|
|
||||||
}
|
|
||||||
else SetErrorState("failed to initialise data item manager");
|
|
||||||
}
|
}
|
||||||
// Delete any constituents that belong to this Transaction.
|
// Delete any constituents that belong to this Transaction.
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -394,25 +345,25 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
SetErrorState("failed to clear Transaction constituents");
|
SetErrorState("failed to clear Transaction constituents");
|
||||||
}
|
}
|
||||||
// Clear requirements.
|
// Clear requirements.
|
||||||
if (!HasErrorState() && InitTransactionMgr())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
List<SbmRequirement> requirements = GetRequirements();
|
List<SbmRequirement> requirements = GetRequirements();
|
||||||
if (requirements != null && requirements.Count > 0)
|
if (requirements != null && requirements.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (SbmRequirement requirement in requirements)
|
foreach (SbmRequirement requirement in requirements)
|
||||||
{
|
{
|
||||||
if (!transactionMgr.DeleteRequirement(requirement, TransactionType, userContext.DbUpdateInfo))
|
if (!internals.TransactionMgr.DeleteRequirement(requirement, TransactionType, internals.DbUpdateInfo))
|
||||||
SetErrorState(transactionMgr.ErrorState.ToString());
|
SetErrorState(internals.TransactionMgr.ErrorState.ToString());
|
||||||
requirements = null;
|
requirements = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (requirements != null) requirements.Clear();
|
if (requirements != null) requirements.Clear();
|
||||||
}
|
}
|
||||||
// Clear addresses.
|
// Clear addresses.
|
||||||
if (!HasErrorState() && InitAccountMgr())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
if (!accountMgr.ClearAddressesFor(Sbm.ItemType.Transaction, new ItemId()))
|
if (!internals.AccountMgr.ClearAddressesFor(Sbm.ItemType.Transaction, new ItemId()))
|
||||||
SetErrorState("failed to clear addresses - " + accountMgr.ErrorState);
|
SetErrorState("failed to clear addresses - " + internals.AccountMgr.ErrorState);
|
||||||
}
|
}
|
||||||
// Clear any references to this transaction from other transactions:
|
// Clear any references to this transaction from other transactions:
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -430,7 +381,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasPayments()
|
public override bool HasPayments()
|
||||||
{
|
{
|
||||||
if (transactionPayments != null) return true;
|
if (transactionPayments != null) return true;
|
||||||
else if (SysId.IsValid(Id) && InitDataItemMgr() && dataItemMgr != null)
|
else if (SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
SbmItemLink.Params prmItemLink = new SbmItemLink.Params
|
SbmItemLink.Params prmItemLink = new SbmItemLink.Params
|
||||||
{
|
{
|
||||||
@@ -438,7 +389,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
ItemTypeFrom = Sbm.ItemType.Transaction,
|
ItemTypeFrom = Sbm.ItemType.Transaction,
|
||||||
ItemIdFrom = Id
|
ItemIdFrom = Id
|
||||||
};
|
};
|
||||||
foreach (SbmItemLink itemLink in dataItemMgr.GetItemLinkList(prmItemLink))
|
foreach (SbmItemLink itemLink in internals.DataItemMgr.GetItemLinkList(prmItemLink))
|
||||||
if (itemLink != null) return true;
|
if (itemLink != null) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -446,13 +397,13 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override List<SbmTransactionPayment> GetPayments()
|
public override List<SbmTransactionPayment> GetPayments()
|
||||||
{
|
{
|
||||||
List<SbmTransactionPayment> transactionPaymentsCopy = new List<SbmTransactionPayment>();
|
List<SbmTransactionPayment> transactionPaymentsCopy = new List<SbmTransactionPayment>();
|
||||||
if (transactionPayments == null && SysId.IsValid(Id) && InitDataItemMgr() && dataItemMgr != null)
|
if (transactionPayments == null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
SbmItemLink.Params prm = new SbmItemLink.Params();
|
SbmItemLink.Params prm = new SbmItemLink.Params();
|
||||||
prm.ItemLinkType = Sbm.ItemLinkType.Transaction_Payment;
|
prm.ItemLinkType = Sbm.ItemLinkType.Transaction_Payment;
|
||||||
prm.ItemTypeFrom = Sbm.ItemType.Transaction;
|
prm.ItemTypeFrom = Sbm.ItemType.Transaction;
|
||||||
prm.ItemIdFrom = Id;
|
prm.ItemIdFrom = Id;
|
||||||
List<SbmItemLink> itemLinks = dataItemMgr.GetItemLinkList(prm);
|
List<SbmItemLink> itemLinks = internals.DataItemMgr.GetItemLinkList(prm);
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
{
|
{
|
||||||
foreach (SbmItemLink itemLink in itemLinks)
|
foreach (SbmItemLink itemLink in itemLinks)
|
||||||
@@ -486,7 +437,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
// Do not attempt any updates unless the list has been populated.
|
// Do not attempt any updates unless the list has been populated.
|
||||||
if (transactionPayments != null && SysId.IsValid(Id) && InitDataItemMgr() && dataItemMgr != null)
|
if (transactionPayments != null && SysId.IsValid(Id))
|
||||||
{
|
{
|
||||||
// Build an item link list corresponding to the list of payment:
|
// Build an item link list corresponding to the list of payment:
|
||||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||||
@@ -494,7 +445,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
foreach (SbmTransactionPayment transactionPayment in transactionPayments)
|
foreach (SbmTransactionPayment transactionPayment in transactionPayments)
|
||||||
{
|
{
|
||||||
if (transactionPayment == null) continue;
|
if (transactionPayment == null) continue;
|
||||||
SbmItemLink itemLink = dataItemMgr.CreateItemLink(Sbm.ItemLinkType.Transaction_Payment, Sbm.ItemType.Transaction, Id, Sbm.ItemType.Unknown, new SysId(0));
|
SbmItemLink itemLink = internals.DataItemMgr.CreateItemLink(Sbm.ItemLinkType.Transaction_Payment, Sbm.ItemType.Transaction, Id, Sbm.ItemType.Unknown, new SysId(0));
|
||||||
if (itemLink != null)
|
if (itemLink != null)
|
||||||
{
|
{
|
||||||
itemLink.Seq = (short)transactionPayment.CodeSeq;
|
itemLink.Seq = (short)transactionPayment.CodeSeq;
|
||||||
@@ -505,12 +456,12 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Store these details:
|
// Store these details:
|
||||||
if (dataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Transaction_Payment, Sbm.ItemType.Transaction, Id, itemLinks, userContext.DbUpdateInfo))
|
if (internals.DataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.Transaction_Payment, Sbm.ItemType.Transaction, Id, itemLinks, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SetErrorState("Failed to save transaction payment item links - " + dataItemMgr.ErrorState);
|
SetErrorState("Failed to save transaction payment item links - " + internals.DataItemMgr.ErrorState);
|
||||||
}
|
}
|
||||||
if (itemLinks != null)
|
if (itemLinks != null)
|
||||||
itemLinks.Clear();
|
itemLinks.Clear();
|
||||||
|
|||||||
@@ -17,20 +17,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmVehicleClass_Dbas(SbmUserContext userContext, SysId id, ushort flags) :
|
public SbmVehicleClass_Dbas(SbmInternals internals, SysId id, ushort flags) :
|
||||||
base(userContext, id)
|
base(internals.UserContext, id)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -45,7 +46,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
String make = "";
|
String make = "";
|
||||||
SbmSystem system = SbmGlobals.System;
|
SbmSystem system = SbmGlobals.System;
|
||||||
|
|
||||||
SaCodeTypeConsole codeTypeConsole = SbmGlobals.Application.GetCodeTypeConsole(userContext);
|
SaCodeTypeConsole codeTypeConsole = internals.CodeTypeConsole;
|
||||||
// Identify make:
|
// Identify make:
|
||||||
if (system == null && codeTypeConsole == null)
|
if (system == null && codeTypeConsole == null)
|
||||||
{
|
{
|
||||||
@@ -68,7 +69,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return 0;
|
if (!SysId.IsValid(Id)) return 0;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableVehicle = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicle);
|
String tableVehicle = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicle);
|
||||||
@@ -89,7 +90,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (this == null || !SysId.IsValid(Id)) return false;
|
if (this == null || !SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null && !HasErrorState())
|
if (db != null && !HasErrorState())
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -119,11 +120,11 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove interface data items:
|
// Remove interface data items:
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
//DbUpdateInfo dbUpdateInfo = userContext.DbUpdateInfo;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
SetErrorState(interfaceConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
|
|||||||
@@ -9,20 +9,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmVehicleEvent_Dbas(SbmUserContext userContext, SysId vehicleId, Sbm.VehicleEventType vehicleEventType, ushort flags) :
|
public SbmVehicleEvent_Dbas(SbmInternals internals, SysId vehicleId, Sbm.VehicleEventType vehicleEventType, ushort flags) :
|
||||||
base(userContext, vehicleId, vehicleEventType)
|
base(internals.UserContext, vehicleId, vehicleEventType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
|
if (this.internals != null) { }
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,22 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmVehicleFeature_Dbas(SbmUserContext userContext, SysId vehicleId, Sbm.VehicleFeatureSource vehicleFeatureSource, Sbm.VehicleFeatureType vehicleFeatureType, ushort flags) :
|
public SbmVehicleFeature_Dbas(SbmInternals internals, SysId vehicleId, Sbm.VehicleFeatureSource vehicleFeatureSource, Sbm.VehicleFeatureType vehicleFeatureType, ushort flags) :
|
||||||
base(userContext, vehicleId, vehicleFeatureSource, vehicleFeatureType)
|
base(internals.UserContext, vehicleId, vehicleFeatureSource, vehicleFeatureType)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
|
if (this.internals != null) { }
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,21 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmUserContext userContext;
|
private readonly SbmInternals internals;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
public SbmVehicle_Dbas(SbmUserContext userContext, SysId id, ushort flags) :
|
public SbmVehicle_Dbas(SbmInternals internals, SysId id, ushort flags) :
|
||||||
base(userContext, id)
|
base(internals.UserContext, id)
|
||||||
{
|
{
|
||||||
this.userContext = userContext;
|
this.internals = internals;
|
||||||
Flags = flags;
|
Flags = flags;
|
||||||
}
|
}
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
{
|
{
|
||||||
|
// NB Do not dispose the Internals - owned by manager.
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
@@ -44,65 +45,62 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
if (SysId.IsValid(Id) || odometer < 1) return false;
|
if (SysId.IsValid(Id) || odometer < 1) return false;
|
||||||
DateTime todayDate = DateTime.MinValue;
|
DateTime todayDate = DateTime.MinValue;
|
||||||
SbmAssetMgr assetMgr = SbmGlobals.System.CreateAssetMgr(userContext);
|
// Check whether there is already a reading for today.
|
||||||
if (assetMgr != null)
|
SbmVehicleEvent vehicleEventUpdated = null;
|
||||||
|
SbmVehicleEvent.Params prm = new SbmVehicleEvent.Params();
|
||||||
|
prm.VehicleId = Id;
|
||||||
|
prm.VehicleEventType = Sbm.VehicleEventType.Odometer;
|
||||||
|
foreach (SbmVehicleEvent vehicleEvent in internals.AssetMgr.GetVehicleEventList(prm))
|
||||||
{
|
{
|
||||||
// Check whether there is already a reading for today.
|
// Check whether this event should be used in preference to any previously found.
|
||||||
SbmVehicleEvent vehicleEventUpdated = null;
|
if (vehicleEvent.StartOn.Date == todayDate)
|
||||||
SbmVehicleEvent.Params prm = new SbmVehicleEvent.Params();
|
|
||||||
prm.VehicleId = Id;
|
|
||||||
prm.VehicleEventType = Sbm.VehicleEventType.Odometer;
|
|
||||||
foreach (SbmVehicleEvent vehicleEvent in assetMgr.GetVehicleEventList(prm))
|
|
||||||
{
|
{
|
||||||
// Check whether this event should be used in preference to any previously found.
|
// Always refresh any odometer reading recorded today.
|
||||||
if (vehicleEvent.StartOn.Date == todayDate)
|
vehicleEventUpdated = vehicleEvent;
|
||||||
{
|
break;
|
||||||
// Always refresh any odometer reading recorded today.
|
|
||||||
vehicleEventUpdated = vehicleEvent;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (vehicleEventUpdated == null && vehicleEvent.Odometer == odometer)
|
|
||||||
vehicleEventUpdated = vehicleEvent; // Events with the same reading can be updated (to refresh the date).
|
|
||||||
else if (vehicleEventUpdated == null && vehicleEvent.StartOn.Date > vehicleEventUpdated.StartOn.Date && vehicleEvent.Odometer == odometer)
|
|
||||||
vehicleEventUpdated = vehicleEvent; // Events with the same reading and more recent date can be refreshed.
|
|
||||||
}
|
}
|
||||||
if (vehicleEventUpdated != null)
|
else if (vehicleEventUpdated == null && vehicleEvent.Odometer == odometer)
|
||||||
|
vehicleEventUpdated = vehicleEvent; // Events with the same reading can be updated (to refresh the date).
|
||||||
|
else if (vehicleEventUpdated == null && vehicleEvent.StartOn.Date > vehicleEventUpdated.StartOn.Date && vehicleEvent.Odometer == odometer)
|
||||||
|
vehicleEventUpdated = vehicleEvent; // Events with the same reading and more recent date can be refreshed.
|
||||||
|
}
|
||||||
|
if (vehicleEventUpdated != null)
|
||||||
|
{
|
||||||
|
vehicleEventUpdated.StartOn = todayDate;
|
||||||
|
vehicleEventUpdated.FinishOn = todayDate;
|
||||||
|
vehicleEventUpdated.Odometer = odometer;
|
||||||
|
if (internals.AssetMgr.UpdateVehicleEvent(vehicleEventUpdated, internals.DbUpdateInfo))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#if _DEBUG
|
||||||
|
else TRACE("SapVehicle::SetOdometerReading: Failed to update vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Create a new reading.
|
||||||
|
SbmVehicleEvent vehicleEvent = internals.AssetMgr.CreateVehicleEvent(Id, Sbm.VehicleEventType.Odometer);
|
||||||
|
if (vehicleEvent != null)
|
||||||
{
|
{
|
||||||
vehicleEventUpdated.StartOn = todayDate;
|
vehicleEventUpdated.StartOn = todayDate;
|
||||||
vehicleEventUpdated.FinishOn = todayDate;
|
vehicleEventUpdated.FinishOn = todayDate;
|
||||||
vehicleEventUpdated.Odometer = odometer;
|
vehicleEventUpdated.Odometer = odometer;
|
||||||
if (assetMgr.UpdateVehicleEvent(vehicleEventUpdated, userContext.DbUpdateInfo))
|
if (internals.AssetMgr.InsertVehicleEvent(vehicleEvent, internals.DbUpdateInfo))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#if _DEBUG
|
|
||||||
else TRACE("SapVehicle::SetOdometerReading: Failed to update vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Create a new reading.
|
|
||||||
SbmVehicleEvent vehicleEvent = assetMgr.CreateVehicleEvent(Id, Sbm.VehicleEventType.Odometer);
|
|
||||||
if (vehicleEvent != null)
|
|
||||||
{
|
|
||||||
vehicleEventUpdated.StartOn = todayDate;
|
|
||||||
vehicleEventUpdated.FinishOn = todayDate;
|
|
||||||
vehicleEventUpdated.Odometer = odometer;
|
|
||||||
if (assetMgr.InsertVehicleEvent(vehicleEvent, userContext.DbUpdateInfo))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
else TRACE("SapVehicle::SetOdometerReading: Failed to add vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
else TRACE("SapVehicle::SetOdometerReading: Failed to add vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if _DEBUG
|
#if _DEBUG
|
||||||
else TRACE("SapVehicle::SetOdometerReading: Failed to create vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
else TRACE("SapVehicle::SetOdometerReading: Failed to create vehicle event - %s\n", assetMgr.ErrorState.Message.ToString());
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
// Update this vehicle itself.
|
|
||||||
LatestOdo = odometer;
|
|
||||||
LatestOdoOn = todayDate;
|
|
||||||
assetMgr.UpdateVehicle(this, userContext.DbUpdateInfo);
|
|
||||||
}
|
}
|
||||||
|
// Update this vehicle itself.
|
||||||
|
LatestOdo = odometer;
|
||||||
|
LatestOdoOn = todayDate;
|
||||||
|
internals.AssetMgr.UpdateVehicle(this, internals.DbUpdateInfo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +109,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
public override bool HasAssets()
|
public override bool HasAssets()
|
||||||
{
|
{
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableAsset = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAsset);
|
String tableAsset = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAsset);
|
||||||
@@ -130,7 +128,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableAssetProcess = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess);
|
String tableAssetProcess = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaAssetProcess);
|
||||||
@@ -147,7 +145,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableVehicleEvent = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicleEvent);
|
String tableVehicleEvent = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicleEvent);
|
||||||
@@ -164,7 +162,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return 0;
|
if (!SysId.IsValid(Id)) return 0;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null)
|
if (db != null)
|
||||||
{
|
{
|
||||||
String tableVehicleFeature = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicleFeature);
|
String tableVehicleFeature = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.SaVehicleFeature);
|
||||||
@@ -185,7 +183,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (!SysId.IsValid(Id)) return false;
|
if (!SysId.IsValid(Id)) return false;
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole == null) return false;
|
if (interfaceConsole == null) return false;
|
||||||
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Vehicle, Id));
|
return interfaceConsole.ItemHasDataItems(new ItemId((short)Sbm.ItemType.Vehicle, Id));
|
||||||
}
|
}
|
||||||
@@ -223,7 +221,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
{
|
{
|
||||||
ClearErrorState();
|
ClearErrorState();
|
||||||
if (this == null || !SysId.IsValid(Id)) return false;
|
if (this == null || !SysId.IsValid(Id)) return false;
|
||||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
ISacsDatabase db = internals.BusMgrDatabase;
|
||||||
if (db != null && !HasErrorState())
|
if (db != null && !HasErrorState())
|
||||||
{
|
{
|
||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
@@ -253,10 +251,10 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
|||||||
if (!HasErrorState())
|
if (!HasErrorState())
|
||||||
{
|
{
|
||||||
// Remove interface data items.
|
// Remove interface data items.
|
||||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
SaInterfaceConsole interfaceConsole = internals.InterfaceConsole;
|
||||||
if (interfaceConsole != null)
|
if (interfaceConsole != null)
|
||||||
{
|
{
|
||||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), userContext.DbUpdateInfo))
|
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.AssetCategory, Id), internals.DbUpdateInfo))
|
||||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
SetErrorState(interfaceConsole.ErrorState.ToString());
|
||||||
}
|
}
|
||||||
else SetErrorState("Failed to retrieve interface console");
|
else SetErrorState("Failed to retrieve interface console");
|
||||||
|
|||||||
@@ -17,25 +17,64 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
|
private SbmConfigConsole configConsole;
|
||||||
|
private SaItemOptionConsole itemOptionConsole;
|
||||||
|
private SaUpdateLogConsole updateLogConsole;
|
||||||
private readonly List<TypeCodeDesc> dataItemTypes;
|
private readonly List<TypeCodeDesc> dataItemTypes;
|
||||||
private readonly List<TypeCodeDesc> interfaceDataTypes;
|
private readonly List<TypeCodeDesc> interfaceDataTypes;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmInterfaceConsole_Dbas(SbmUserContext userContext) : base(SbmGlobals.Application.GetDatabase(userContext.SessionContext) as SacsDatabase)
|
protected SbmInterfaceConsole_Dbas(SbmUserContext userContext) : base(SbmGlobals.Application.GetBusMgrDatabase(userContext.SessionContext) as SacsDatabase)
|
||||||
{
|
{
|
||||||
UserContext = userContext;
|
UserContext = userContext;
|
||||||
dataItemTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.ItemType);
|
dataItemTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.ItemType);
|
||||||
interfaceDataTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceDataType);
|
interfaceDataTypes = SbmSystem.GetCodesOfType(UserContext, Sbm.SystemCode.InterfaceDataType);
|
||||||
}
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (configConsole != null) configConsole.Dispose(); configConsole = null;
|
||||||
|
if (itemOptionConsole != null) itemOptionConsole.Dispose(); itemOptionConsole = null;
|
||||||
|
if (updateLogConsole != null) updateLogConsole.Dispose(); updateLogConsole = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public SbmUserContext UserContext { get; }
|
public SbmUserContext UserContext { get; }
|
||||||
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
public override short InterfaceDataType { get { return (short)Sbm.ItemType.Interface; } }
|
public override short InterfaceDataType { get { return (short)Sbm.ItemType.Interface; } }
|
||||||
public override SaItemOptionConsole ItemOptionConsole { get { return SbmGlobals.Application.GetItemOptionConsole(UserContext); } }
|
// Consoles.
|
||||||
public override SaUpdateLogConsole UpdateLogConsole { get { return SbmGlobals.Application.GetUpdateLogConsole(UserContext); } }
|
private SbmConfigConsole ConfigConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (configConsole == null)
|
||||||
|
configConsole = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext);
|
||||||
|
return configConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override SaItemOptionConsole ItemOptionConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (itemOptionConsole == null)
|
||||||
|
itemOptionConsole = SbmGlobals.Application.CreateItemOptionConsole(UserContext);
|
||||||
|
return itemOptionConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override SaUpdateLogConsole UpdateLogConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (updateLogConsole == null)
|
||||||
|
updateLogConsole = SbmGlobals.Application.CreateUpdateLogConsole(UserContext);
|
||||||
|
return updateLogConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
// Utilities.
|
// Utilities.
|
||||||
@@ -88,7 +127,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
}
|
}
|
||||||
public bool InterfaceTypeValidForContextCategory(SaInterfaceCategory interfaceCategory, short interfaceType)
|
public bool InterfaceTypeValidForContextCategory(SaInterfaceCategory interfaceCategory, short interfaceType)
|
||||||
{
|
{
|
||||||
return SbmGlobals.GetConfigConsole(UserContext.SessionContext).AllowInterface(UserContext, interfaceCategory, interfaceType);
|
return ConfigConsole.AllowInterface(UserContext, interfaceCategory, interfaceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||||
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
using Sarand.BusinessMgr.Net.Standard.Base.Mgr;
|
||||||
using Sarand.Net.Standard.Base.Bus;
|
using Sarand.Net.Standard.Base.Bus;
|
||||||
|
using Sarand.Net.Standard.Base.Interfaces;
|
||||||
using Sarand.Net.Standard.Base.ItemOptions;
|
using Sarand.Net.Standard.Base.ItemOptions;
|
||||||
using Sarand.Net.Standard.Base.UpdateLog;
|
using Sarand.Net.Standard.Base.UpdateLog;
|
||||||
using Sarand.Net.Standard.Dbas.Base;
|
using Sarand.Net.Standard.Dbas.Base;
|
||||||
@@ -15,20 +16,49 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private SbmAccountMgr accountMgr = null;
|
private SbmAccountMgr accountMgr = null;
|
||||||
|
private SaInterfaceConsole interfaceConsole;
|
||||||
|
private SaUpdateLogConsole updateLogConsole;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmItemOptionConsole_Dbas(SacsDatabase database) : base(database)
|
protected SbmItemOptionConsole_Dbas(SacsDatabase database) : base(database)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (accountMgr != null) accountMgr.Dispose(); accountMgr = null;
|
||||||
|
if (updateLogConsole != null) updateLogConsole.Dispose(); updateLogConsole = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public SbmUserContext UserContext { get; set; }
|
public SbmUserContext UserContext { get; set; }
|
||||||
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
public override short ItemOptionDataType { get { return (short)Sbm.ItemType.ItemOption; } }
|
public override short ItemOptionDataType { get { return (short)Sbm.ItemType.ItemOption; } }
|
||||||
public override SaUpdateLogConsole UpdateLogConsole { get { return SbmGlobals.Application.GetUpdateLogConsole(UserContext); } }
|
|
||||||
private SbmAccountMgr AccountMgr { get { if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(UserContext); return accountMgr; } }
|
private SbmAccountMgr AccountMgr { get { if (accountMgr == null) accountMgr = SbmGlobals.System.CreateAccountMgr(UserContext); return accountMgr; } }
|
||||||
|
// Consoles.
|
||||||
|
public SaInterfaceConsole InterfaceConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (interfaceConsole == null)
|
||||||
|
interfaceConsole = SbmGlobals.Application.CreateInterfaceConsole(UserContext);
|
||||||
|
return interfaceConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override SaUpdateLogConsole UpdateLogConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (updateLogConsole == null)
|
||||||
|
updateLogConsole = SbmGlobals.Application.CreateUpdateLogConsole(UserContext);
|
||||||
|
return updateLogConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// I t e m O p t i o n D e f i n i t i o n s
|
// I t e m O p t i o n D e f i n i t i o n s
|
||||||
@@ -38,7 +68,7 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
if (itemId.Type == (int)Sbm.ItemType.Association)
|
if (itemId.Type == (int)Sbm.ItemType.Association)
|
||||||
return AccountMgr.GetOrganisationItemOptionDfns(itemId.Id);
|
return AccountMgr.GetOrganisationItemOptionDfns(itemId.Id);
|
||||||
if (itemId.Type == (int)Sbm.ItemType.Interface)
|
if (itemId.Type == (int)Sbm.ItemType.Interface)
|
||||||
return SbmGlobals.Application.GetInterfaceConsole(UserContext).GetInterfaceItemOptionDfns(itemId.Id);
|
return InterfaceConsole.GetInterfaceItemOptionDfns(itemId.Id);
|
||||||
return new List<SaItemOptionDfn>();
|
return new List<SaItemOptionDfn>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
public abstract class SbmReferenceDataConsole_Dbas : SaReferenceDataConsole_Dbas
|
public abstract class SbmReferenceDataConsole_Dbas : SaReferenceDataConsole_Dbas
|
||||||
{
|
{
|
||||||
|
//-------------------------------------------------------------------
|
||||||
|
// Data members.
|
||||||
|
private SaUpdateLogConsole updateLogConsole;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmReferenceDataConsole_Dbas(SbmUserContext userContext, SacsDatabase database) :
|
protected SbmReferenceDataConsole_Dbas(SbmUserContext userContext, SacsDatabase database) :
|
||||||
@@ -15,18 +19,35 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
{
|
{
|
||||||
UserContext = userContext;
|
UserContext = userContext;
|
||||||
}
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (updateLogConsole != null) updateLogConsole.Dispose(); updateLogConsole = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public SbmSessionContext SessionContext { get; }
|
public SbmSessionContext SessionContext { get; }
|
||||||
public SbmUserContext UserContext { get; }
|
public SbmUserContext UserContext { get; }
|
||||||
public override SaUpdateLogConsole UpdateLogConsole { get { return SbmGlobals.Application.GetUpdateLogConsole(UserContext); } }
|
|
||||||
// Item types.
|
// Item types.
|
||||||
public override short LanguageItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
public override short LanguageItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
||||||
public override short RegionItemType { get { return (short)Sbm.ItemDataType.Region; } }
|
public override short RegionItemType { get { return (short)Sbm.ItemDataType.Region; } }
|
||||||
public override short CurrencyItemType { get { return (short)Sbm.ItemDataType.Currency; } }
|
public override short CurrencyItemType { get { return (short)Sbm.ItemDataType.Currency; } }
|
||||||
public override short TaxCodeItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
public override short TaxCodeItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
||||||
public override short UnitMeasureItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
public override short UnitMeasureItemType { get { return (short)Sbm.ItemDataType.Unknown; } }
|
||||||
|
// Consoles.
|
||||||
|
public override SaUpdateLogConsole UpdateLogConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (updateLogConsole == null)
|
||||||
|
updateLogConsole = SbmGlobals.Application.CreateUpdateLogConsole(UserContext);
|
||||||
|
return updateLogConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,14 +17,24 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
private readonly SbmConfigConsole configConsole;
|
private SbmConfigConsole configConsole;
|
||||||
|
private SaUpdateLogConsole updateLogConsole;
|
||||||
private List<TypeCodeDesc> securityRights;
|
private List<TypeCodeDesc> securityRights;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmSecurityConsole_Dbas(SacsDatabase database, SbmConfigConsole configConsole) : base(database)
|
protected SbmSecurityConsole_Dbas(SbmUserContext userContext, SacsDatabase database) : base(database)
|
||||||
{
|
{
|
||||||
this.configConsole = configConsole;
|
UserContext = userContext;
|
||||||
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (configConsole != null) configConsole.Dispose(); configConsole = null;
|
||||||
|
if (updateLogConsole != null) updateLogConsole.Dispose(); updateLogConsole = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
@@ -33,7 +43,25 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
public override short SecurityItemDataType { get { return (short)Sbm.ItemType.SecurityItem; } }
|
public override short SecurityItemDataType { get { return (short)Sbm.ItemType.SecurityItem; } }
|
||||||
public override short SecurityLinkDataType { get { return (short)Sbm.ItemType.SecurityLink; } }
|
public override short SecurityLinkDataType { get { return (short)Sbm.ItemType.SecurityLink; } }
|
||||||
public override SaUpdateLogConsole UpdateLogConsole { get { return SbmGlobals.Application.GetUpdateLogConsole(UserContext); } }
|
// Consoles.
|
||||||
|
private SbmConfigConsole ConfigConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (configConsole == null)
|
||||||
|
configConsole = SbmGlobals.Application.CreateConfigConsole(UserContext.SessionContext);
|
||||||
|
return configConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public override SaUpdateLogConsole UpdateLogConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (updateLogConsole == null)
|
||||||
|
updateLogConsole = SbmGlobals.Application.CreateUpdateLogConsole(UserContext);
|
||||||
|
return updateLogConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Utilities.
|
// Utilities.
|
||||||
|
|||||||
@@ -13,27 +13,45 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
|||||||
{
|
{
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Data members.
|
// Data members.
|
||||||
|
private SaSecurityConsole securityConsole;
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Construction.
|
// Construction.
|
||||||
protected SbmUpdateLogConsole_Dbas(SacsDatabase database) : base(database)
|
protected SbmUpdateLogConsole_Dbas(SacsDatabase database) : base(database)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing)
|
||||||
|
{
|
||||||
|
if (securityConsole != null) securityConsole.Dispose(); securityConsole = null;
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Properties.
|
// Properties.
|
||||||
public SbmUserContext UserContext { get; set; }
|
public SbmUserContext UserContext { get; set; }
|
||||||
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
public SbmSessionContext SessionContext { get { return UserContext.SessionContext; } }
|
||||||
|
// Consoles.
|
||||||
|
public SaSecurityConsole SecurityConsole
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (securityConsole == null)
|
||||||
|
securityConsole = SbmGlobals.Application.CreateSecurityConsole(UserContext);
|
||||||
|
return securityConsole;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Get name for User Id.
|
// Get name for User Id.
|
||||||
public override Dictionary<SysId, String> GetNameForUserIds(List<SysId> userIds)
|
public override Dictionary<SysId, String> GetNameForUserIds(List<SysId> userIds)
|
||||||
{
|
{
|
||||||
Dictionary<SysId, String> userNames = new Dictionary<SysId, String>();
|
Dictionary<SysId, String> userNames = new Dictionary<SysId, String>();
|
||||||
SaSecurityConsole securityConsole = SbmGlobals.Application.GetSecurityConsole(UserContext);
|
if (SecurityConsole != null)
|
||||||
if (securityConsole != null)
|
|
||||||
{
|
{
|
||||||
userNames = securityConsole.GetSecurityItemDescriptions(userIds);
|
userNames = SecurityConsole.GetSecurityItemDescriptions(userIds);
|
||||||
}
|
}
|
||||||
return userNames;
|
return userNames;
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user