3.0.0.1 Demo repository registration
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.App;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
||||
{
|
||||
@@ -9,36 +14,549 @@ namespace Sarand.BusinessMgr.Net.Standard.Dbas.Consoles
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmSessionContext sessionContext;
|
||||
private class DataMembers
|
||||
{
|
||||
public DataMembers(SbmSessionContext sessionContext)
|
||||
{
|
||||
this.SessionContext = sessionContext;
|
||||
}
|
||||
public SbmSessionContext SessionContext { get; }
|
||||
public ISacsDatabase Database { get; set; }
|
||||
}
|
||||
private DataMembers mbr { get; }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmDatabaseConsole(SbmSessionContext sessionContext)
|
||||
{
|
||||
this.sessionContext = sessionContext;
|
||||
this.mbr = new DataMembers(sessionContext);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Properties.
|
||||
private SbmSessionContext SessionContext { get { return mbr.SessionContext; } }
|
||||
private ISacsDatabase Database { get { if (mbr.Database == null) { mbr.Database = SbmGlobals.Application.GetBusMgrDatabase(SessionContext); } return mbr.Database; } }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// D a t a b a s e I n d i c e s
|
||||
// Database Indices.
|
||||
//-------------------------------------------------------------------
|
||||
public bool CreateDbIndices(IndexStats indexStats)
|
||||
public bool InstallDbIndices(IndexStats indexStats)
|
||||
{
|
||||
ClearErrorState();
|
||||
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.
|
||||
bool displayDbExceptionsPrev = database.DisplayErrors;
|
||||
database.DisplayErrors = false;
|
||||
bool displayDbExceptionsPrev = Database.DisplayErrors;
|
||||
Database.DisplayErrors = false;
|
||||
|
||||
// ToDo SbmDatabaseConsole Create database indices.
|
||||
//---------------------------------------------------------------
|
||||
// Common tables.
|
||||
|
||||
// NextId table:
|
||||
CreatePrimaryDbIndex("NextId", "Object");
|
||||
|
||||
// Attribute Update table:
|
||||
CreatePrimaryDbIndex("SaAttrUpdate", "Logged,ItemType,ItemId,Attribute");
|
||||
CreateDbIndex("SaAttrUpdate", "IDX_SaAttrUpdate_Item", "ItemType,ItemId,Logged,Attribute");
|
||||
CreateDbIndex("SaAttrUpdate", "IDX_SaAttrUpdate_ItemAttr", "ItemType,ItemId,Attribute,Logged");
|
||||
|
||||
// Code table:
|
||||
CreatePrimaryDbIndex("SaCode", "Id");
|
||||
CreateDbIndex("SaCode", "IDX_SaCode_Status", "Status");
|
||||
CreateDbIndex("SaCode", "IDX_SaCode_Type", "CodeTypeId");
|
||||
CreateDbIndex("SaCode", "IDX_SaCode_TypeCode", "CodeTypeId,Code", "", true);
|
||||
CreateDbIndex("SaCode", "IDX_SaCode_TypeSeq", "CodeTypeId,Seq");
|
||||
|
||||
// Code Type table:
|
||||
CreatePrimaryDbIndex("SaCodeType", "Id");
|
||||
CreateDbIndex("SaCodeType", "IDX_SaCodeType_Code", "Code", "", true);
|
||||
|
||||
// Diary Entry table:
|
||||
CreatePrimaryDbIndex("SaDiaryEntry", "Id");
|
||||
CreateDbIndex("SaDiaryEntry", "IDX_SaDiaryEntry_Finish", "Finish");
|
||||
CreateDbIndex("SaDiaryEntry", "IDX_SaDiaryEntry_Start", "Start");
|
||||
|
||||
// Diary Link table:
|
||||
CreatePrimaryDbIndex("SaDiaryLink", "EntryId,ItemType,ItemId");
|
||||
|
||||
// Item Data table:
|
||||
CreatePrimaryDbIndex("SaItemData", "Id");
|
||||
CreateDbIndex("SaItemData", "IDX_SaItemData_DataTypeItem", "DataType,ItemType,ItemId");
|
||||
CreateDbIndex("SaItemData", "IDX_SaItemData_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("SaItemData", "IDX_SaItemData_ItemTypeDataType", "ItemType,DataType");
|
||||
|
||||
// Item Document table:
|
||||
CreatePrimaryDbIndex("SaItemDoc", "Id");
|
||||
CreateDbIndex("SaItemDoc", "IDX_SaItemDoc_Item", "ItemType,ItemId");
|
||||
|
||||
// Item Named Value table:
|
||||
CreatePrimaryDbIndex("SaItemNamedValue", "ItemType,ItemId,Name,Seq");
|
||||
CreateDbIndex("SaItemNamedValue", "IDX_SaItemNamedValue_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("SaItemNamedValue", "IDX_SaItemNamedValue_ItemName", "ItemType,ItemId,Name");
|
||||
CreateDbIndex("SaItemNamedValue", "IDX_SaItemNamedValue_Name", "Name");
|
||||
|
||||
// Item Option table:
|
||||
CreatePrimaryDbIndex("SaItemOption", "ItemType,ItemId,Name,Context");
|
||||
CreateDbIndex("SaItemOption", "IDX_SaItemOption_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("SaItemOption", "IDX_SaItemOption_ItemName", "ItemType,ItemId,Name");
|
||||
CreateDbIndex("SaItemOption", "IDX_SaItemOption_Name", "Name");
|
||||
|
||||
// Security Item table:
|
||||
CreatePrimaryDbIndex("SaSecItem", "Id");
|
||||
CreateDbIndex("SaSecItem", "IDX_SaSecItem_Code", "Code");
|
||||
CreateDbIndex("SaSecItem", "IDX_SaSecItem_Desc", "Description");
|
||||
CreateDbIndex("SaSecItem", "IDX_SaSecItem_TypeCode", "Type,Code", "", true);
|
||||
|
||||
// Security Link table:
|
||||
CreatePrimaryDbIndex("SaSecLink", "ItemOwner,ItemTarget,ItemContext");
|
||||
CreateDbIndex("SaSecLink", "IDX_SaSecLink_ItemContext", "ItemContext");
|
||||
CreateDbIndex("SaSecLink", "IDX_SaSecLink_ItemOwner", "ItemOwner");
|
||||
CreateDbIndex("SaSecLink", "IDX_SaSecLink_ItemTarget", "ItemTarget");
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// I n t e r f a c e s
|
||||
//---------------------------------------------------------------------
|
||||
// Interface table:
|
||||
CreatePrimaryDbIndex("Interface", "Id");
|
||||
CreateDbIndex("Interface", "IDX_Interface_ContextCategoryType", "Context,Category,Type");
|
||||
CreateDbIndex("Interface", "IDX_Interface_ContextCode", "Context,Code", "", true);
|
||||
|
||||
// Interface Data Item table:
|
||||
CreatePrimaryDbIndex("InterfaceDataItem", "Id");
|
||||
CreateDbIndex("InterfaceDataItem", "IDX_InterfaceDataItem_InterfaceDirectionItemRef", "InterfaceId,Direction,ItemType,ExternalRef");
|
||||
CreateDbIndex("InterfaceDataItem", "IDX_InterfaceDataItem_InterfaceItemRef", "InterfaceId,Direction,ItemType,ItemId,ExternalRef", "", true);
|
||||
CreateDbIndex("InterfaceDataItem", "IDX_InterfaceDataItem_InterfaceStatusItemRef", "InterfaceId,Direction,ProcessStatus,ItemType,ItemId,ExternalRef", "", true);
|
||||
CreateDbIndex("InterfaceDataItem", "IDX_InterfaceDataItem_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("InterfaceDataItem", "IDX_InterfaceDataItem_ItemExternal", "ItemType,ExternalRef");
|
||||
|
||||
// Interface Process table:
|
||||
CreatePrimaryDbIndex("InterfaceProcess", "Id");
|
||||
CreateDbIndex("InterfaceProcess", "IDX_InterfaceProcess_IntDirSeq", "InterfaceId,Direction,ProcSeq", "", true);
|
||||
CreateDbIndex("InterfaceProcess", "IDX_InterfaceProcess_IntProc", "InterfaceId,ProcRef");
|
||||
CreateDbIndex("InterfaceProcess", "IDX_InterfaceProcess_IntProcDate", "InterfaceId,ProcDate,ProcTime");
|
||||
|
||||
// Interface Process Data Item table:
|
||||
CreatePrimaryDbIndex("InterfaceProcessDataItem", "ProcessId,InterfaceDataItemId");
|
||||
CreateDbIndex("InterfaceProcessDataItem", "IDX_InterfaceProcessDataItem_Item", "InterfaceDataItemId");
|
||||
CreateDbIndex("InterfaceProcessDataItem", "IDX_InterfaceProcessDataItem_ProcItemData", "ProcessId,ItemData");
|
||||
|
||||
// InterfaceProcessMessage table:
|
||||
CreatePrimaryDbIndex("InterfaceProcessMessage", "Id");
|
||||
CreateDbIndex("InterfaceProcessMessage", "IDX_InterfaceProcessMessage_Process", "ProcessId");
|
||||
CreateDbIndex("InterfaceProcessMessage", "IDX_InterfaceProcessMessage_ProcMsgType", "ProcessId,MsgType");
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// B u s i n e s s M a n a g e r
|
||||
//---------------------------------------------------------------------
|
||||
// Address table:
|
||||
CreatePrimaryDbIndex("Address", "Id");
|
||||
CreateDbIndex("Address", "IDX_Address_CityRgn", "CityRgn");
|
||||
CreateDbIndex("Address", "IDX_Address_CountryRgn", "CountryRgn");
|
||||
CreateDbIndex("Address", "IDX_Address_Flags", "Flags");
|
||||
CreateDbIndex("Address", "IDX_Address_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("Address", "IDX_Address_Line1", "Line1");
|
||||
CreateDbIndex("Address", "IDX_Address_Owner", "AffIdOwner");
|
||||
CreateDbIndex("Address", "IDX_Address_Postcode", "Postcode");
|
||||
CreateDbIndex("Address", "IDX_Address_PostcodeFmt", "PostcodeFmt");
|
||||
CreateDbIndex("Address", "IDX_Address_ProvinceRgn", "ProvinceRgn");
|
||||
CreateDbIndex("Address", "IDX_Address_RefAddress", "AddIdRef");
|
||||
CreateDbIndex("Address", "IDX_Address_Status", "Status");
|
||||
CreateDbIndex("Address", "IDX_Address_Type", "Type");
|
||||
|
||||
// Affiliate table:
|
||||
CreatePrimaryDbIndex("Affiliate", "Id");
|
||||
CreateDbIndex("Affiliate", "IDX_Affiliate_Name", "Name");
|
||||
CreateDbIndex("Affiliate", "IDX_Affiliate_Status", "Status");
|
||||
CreateDbIndex("Affiliate", "IDX_Affiliate_Type", "Type");
|
||||
CreateDbIndex("Affiliate", "IDX_Affiliate_UserId", "UserId");
|
||||
|
||||
// Association table:
|
||||
CreatePrimaryDbIndex("Association", "Id");
|
||||
CreateDbIndex("Association", "IDX_Association_Code", "Code");
|
||||
CreateDbIndex("Association", "IDX_Association_ExtRef", "ExtRef");
|
||||
CreateDbIndex("Association", "IDX_Association_Owner", "AffIdOwner");
|
||||
CreateDbIndex("Association", "IDX_Association_OwnerTargetType", "AffIdOwner,AffIdTarget,Type", "", true);
|
||||
CreateDbIndex("Association", "IDX_Association_OwnerTypeCode", "AffIdOwner,Type,Code");
|
||||
CreateDbIndex("Association", "IDX_Association_PriceSet", "PriceSetId");
|
||||
CreateDbIndex("Association", "IDX_Association_Target", "AffIdTarget");
|
||||
CreateDbIndex("Association", "IDX_Association_TaxCode", "TaxCodeId");
|
||||
|
||||
// Commodity table:
|
||||
CreatePrimaryDbIndex("Commodity", "Id");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_AssetCat", "AssetCatId");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_CodeIssue", "Code,DrawingIssue");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Colour", "ColourCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Customer", "AssIdCustomer");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Delivery", "DeliveryCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Description", "DescBrief");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Finish", "FinishCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Handling", "HandlingCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Material", "MaterialCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Owner", "AffIdOwner");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Range", "RangeCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_SalesProjCommodity", "CommodityIdSalesProj");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Source", "SourceCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_Supplier", "AssIdSupplier");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_SupplyMethod", "SupplyMethodCode");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_TaxCode", "TaxCodeId");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomBox", "UomIdBox");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomDensity", "UomIdDensity");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomLength", "UomIdLength");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomSale", "UomIdSale");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomTimeProd", "UomIdTimeProd");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomVolume", "UomIdVolume");
|
||||
CreateDbIndex("Commodity", "IDX_Commodity_UomWeight", "UomIdWeight");
|
||||
|
||||
// Commodity Customer table:
|
||||
CreatePrimaryDbIndex("CommodityCustomer", "CommodityId,AssocIdCustomer");
|
||||
CreateDbIndex("CommodityCustomer", "IDX_CommodityCustomer_Currency", "CurrencyIdRetail");
|
||||
CreateDbIndex("CommodityCustomer", "IDX_CommodityCustomer_Customer", "AssocIdCustomer");
|
||||
|
||||
// Commodity Supplier table:
|
||||
CreatePrimaryDbIndex("CommoditySupplier", "CommodityId,AssocIdSupplier");
|
||||
CreateDbIndex("CommoditySupplier", "IDX_CommoditySupplier_Currency", "CurrencyIdCost");
|
||||
CreateDbIndex("CommoditySupplier", "IDX_CommoditySupplier_Supplier", "AssocIdSupplier");
|
||||
|
||||
// Constituent table:
|
||||
CreatePrimaryDbIndex("Constituent", "Id");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Asset", "AssetId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Assoc", "AssocId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Const", "ConstId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Contractor", "AssocIdContractor");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Effective", "Effective");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Owner", "AffIdOwner");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Process", "ProcessId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Reqnt", "ReqntId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Target", "AffIdTarget");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_TaxCode", "TaxCodeId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Trans", "TransId");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Type", "Type");
|
||||
CreateDbIndex("Constituent", "IDX_Constituent_Uom", "UomId");
|
||||
|
||||
// Container table:
|
||||
CreatePrimaryDbIndex("Container", "Id");
|
||||
CreateDbIndex("Container", "IDX_Container_Customer", "AssIdCustomer");
|
||||
CreateDbIndex("Container", "IDX_Container_OwnerRef", "AffIdOwner,Reference");
|
||||
CreateDbIndex("Container", "IDX_Container_OwnerType", "AffIdOwner,Type");
|
||||
CreateDbIndex("Container", "IDX_Container_Supplier", "AssIdSupplier");
|
||||
CreateDbIndex("Container", "IDX_Container_TagId", "TagId");
|
||||
|
||||
// Container Item table:
|
||||
CreatePrimaryDbIndex("ContainerItem", "ContainerId,ItemSeq,ItemType,ItemId");
|
||||
CreateDbIndex("ContainerItem", "IDX_ContainerItem_ContainerSeq", "ContainerId,ItemSeq");
|
||||
CreateDbIndex("ContainerItem", "IDX_ContainerItem_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("ContainerItem", "IDX_ContainerItem_SourceItem", "ItemTypeSource,ItemIdSource");
|
||||
|
||||
// Item Link table:
|
||||
//CreatePrimaryDbIndex ("ItemLink","Type,ItemTypeFrom,ItemIdFrom,ItemTypeTo,ItemIdTo,Seq");
|
||||
CreateDbIndex("ItemLink", "IDX_ItemLink_ItemFrom", "ItemTypeFrom,ItemIdFrom");
|
||||
CreateDbIndex("ItemLink", "IDX_ItemLink_ItemTo", "ItemTypeTo,ItemIdTo");
|
||||
CreateDbIndex("ItemLink", "IDX_ItemLink_TypeItemFromStatus", "Type,ItemTypeFrom,ItemIdFrom,Status");
|
||||
CreateDbIndex("ItemLink", "IDX_ItemLink_Type_ItemTypeFrom_ItemTypeTo", "Type,ItemTypeFrom,ItemTypeTo", "ItemIdFrom,ItemIdTo");
|
||||
|
||||
// Location table:
|
||||
CreatePrimaryDbIndex("Location", "Id");
|
||||
CreateDbIndex("Location", "IDX_Location_Owner", "AffIdOwner");
|
||||
CreateDbIndex("Location", "IDX_Location_OwnerCat", "AffIdOwner,Category");
|
||||
CreateDbIndex("Location", "IDX_Location_OwnerCode", "AffIdOwner,Code");
|
||||
|
||||
// Movement table:
|
||||
CreatePrimaryDbIndex("Movement", "Id");
|
||||
CreateDbIndex("Movement", "IDX_Movement_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("Movement", "IDX_Movement_ItemTypeMovement", "ItemType,ItemId,Type,Movement");
|
||||
CreateDbIndex("Movement", "IDX_Movement_LocationFrom", "LocationIdFrom");
|
||||
CreateDbIndex("Movement", "IDX_Movement_LocationTo", "LocationIdTo");
|
||||
CreateDbIndex("Movement", "IDX_Movement_Movement", "Movement");
|
||||
CreateDbIndex("Movement", "IDX_Movement_SourceItem", "ItemTypeSource,ItemIdSource");
|
||||
CreateDbIndex("Movement", "IDX_Movement_SourceMovement", "MovementIdSource");
|
||||
|
||||
// PortfolioItem table:
|
||||
CreatePrimaryDbIndex("PortfolioItem", "Id");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_Commodity", "CommodityId");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_Owner", "AffIdOwner");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_OwnerParentCode", "AffIdOwner,ItemIdParent,Code");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_OwnerParentType", "AffIdOwner,ItemIdParent,Type");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_ParentItem", "ItemIdParent");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_ParentSeq", "ItemIdParent,Seq");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_RefItem", "ItemIdRef");
|
||||
CreateDbIndex("PortfolioItem", "IDX_PortfolioItem_ShortCut", "ShortCut");
|
||||
|
||||
// Process table:
|
||||
CreatePrimaryDbIndex("Process", "Id");
|
||||
CreateDbIndex("Process", "IDX_Process_OwnerCategory", "AffIdOwner,Category");
|
||||
CreateDbIndex("Process", "IDX_Process_OwnerSeq", "AffIdOwner,Seq");
|
||||
CreateDbIndex("Process", "IDX_Process_OwnerType", "AffIdOwner,Type");
|
||||
|
||||
// Requirement table:
|
||||
CreatePrimaryDbIndex("Requirement", "Id");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Reqnt_Trans", "Id,TransId", "ReqntIdSource", true);
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Reqnt_Trans_ReqntSource", "Id,TransId,ReqntIdSource", "", true);
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_AffilOwner", "AffIdOwner");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Asset", "AssetId");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Assoc", "AssocId");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_AssocContract", "AssIdSubcontract");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Commodity", "CommodityId");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_MaterialSource", "MaterialSourceCode");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_ProductCode", "ProductCode");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_ReqntSource", "ReqntIdSource");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_StockLocation", "LocationIdStock");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_TaxCode", "TaxCodeId");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Trans", "TransId");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_TransCommodityStatus", "TransId,CommodityId,Status");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_TransSeq", "TransId,Seq");
|
||||
CreateDbIndex("Requirement", "IDX_Requirement_Uom", "UomId");
|
||||
|
||||
// Asset table:
|
||||
CreatePrimaryDbIndex("SaAsset", "Id");
|
||||
CreateDbIndex("SaAsset", "IDX_SaAsset_CategorySerial", "AssetCategoryId,SerialFmt", "", true);
|
||||
CreateDbIndex("SaAsset", "IDX_SaAsset_Customer", "AssocIdCustomer,Id", "", true);
|
||||
CreateDbIndex("SaAsset", "IDX_SaAsset_Item", "ItemType,ItemId");
|
||||
CreateDbIndex("SaAsset", "IDX_SaAsset_Supplier", "AssocIdSupplier,Id", "", true);
|
||||
|
||||
// Asset Category table:
|
||||
CreatePrimaryDbIndex("SaAssetCategory", "Id");
|
||||
CreateDbIndex("SaAssetCategory", "IDX_SaAssetCategory_Customer", "AssocIdCustomer,Id", "", true);
|
||||
CreateDbIndex("SaAssetCategory", "IDX_SaAssetCategory_OwnerType", "AffIdOwner,AssetType,Code", "", true);
|
||||
CreateDbIndex("SaAssetCategory", "IDX_SaAssetCategory_Supplier", "AssocIdSupplier,Id", "", true);
|
||||
|
||||
// Asset Process table:
|
||||
CreatePrimaryDbIndex("SaAssetProcess", "Id");
|
||||
|
||||
// Price table:
|
||||
CreatePrimaryDbIndex("SaPrice", "PriceSetId,CommodityId");
|
||||
CreateDbIndex("SaPrice", "IDX_SaPrice_Commodity", "CommodityId");
|
||||
CreateDbIndex("SaPrice", "IDX_SaPrice_PriceSet", "PriceSetId");
|
||||
|
||||
// Price Set table:
|
||||
CreatePrimaryDbIndex("SaPriceSet", "Id");
|
||||
CreateDbIndex("SaPriceSet", "IDX_SaPriceSet_AffOwner", "AffIdOwner");
|
||||
CreateDbIndex("SaPriceSet", "IDX_SaPriceSet_Currency", "CurrencyId");
|
||||
CreateDbIndex("SaPriceSet", "IDX_SaPriceSet_Name", "Name");
|
||||
CreateDbIndex("SaPriceSet", "IDX_SaPriceSet_OwnerRef", "AffIdOwner,Ref", "", true);
|
||||
|
||||
// Vehicle table:
|
||||
CreatePrimaryDbIndex("SaVehicle", "Id");
|
||||
CreateDbIndex("SaVehicle", "IDX_SaVehicle_CapCode", "CapCode,Id", "", true);
|
||||
CreateDbIndex("SaVehicle", "IDX_SaVehicle_KeyLocation", "KeyLocation,Id", "", true);
|
||||
CreateDbIndex("SaVehicle", "IDX_SaVehicle_RegNumber", "RegNumber", "", true);
|
||||
CreateDbIndex("SaVehicle", "IDX_SaVehicle_VehicleClass", "VehicleClassId,Id", "", true);
|
||||
|
||||
// Vehicle Class table:
|
||||
CreatePrimaryDbIndex("SaVehicleClass", "Id");
|
||||
CreateDbIndex("SaVehicleClass", "IDX_SaVehicleClass_Category", "VehicleCategoryCode");
|
||||
CreateDbIndex("SaVehicleClass", "IDX_SaVehicleClass_Make", "MakeCode,Id", "", true);
|
||||
|
||||
// Vehicle Event table:
|
||||
CreatePrimaryDbIndex("SaVehicleEvent", "Id");
|
||||
CreateDbIndex("SaVehicleEvent", "IDX_SaVehicleEvent_TaxCode", "TaxCodeId");
|
||||
CreateDbIndex("SaVehicleEvent", "IDX_SaVehicleEvent_VehicleStart", "VehicleId,StartOn", "", true);
|
||||
|
||||
// Vehicle Feature table:
|
||||
CreatePrimaryDbIndex("SaVehicleFeature", "VehicleId,Source,Type,CategoryCode,FeatureCode");
|
||||
|
||||
// Stock Level table:
|
||||
CreatePrimaryDbIndex("StockLevel", "Id");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_Commodity", "CommodityId");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_CommodityRecorded", "CommodityId,Recorded");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_CommodityType", "CommodityId,Type");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_Location", "LocationId");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_Recorded", "Recorded");
|
||||
CreateDbIndex("StockLevel", "IDX_StockLevel_Type", "Type");
|
||||
|
||||
// System Account table:
|
||||
CreatePrimaryDbIndex("SystemAccount", "Id");
|
||||
CreateDbIndex("SystemAccount", "IDX_SystemAccount_AffIdOwner", "AffIdOwner");
|
||||
CreateDbIndex("SystemAccount", "IDX_SystemAccount_Association", "AssocId");
|
||||
CreateDbIndex("SystemAccount", "IDX_SystemAccount_Interface", "InterfaceId");
|
||||
|
||||
// System Account User table:
|
||||
CreatePrimaryDbIndex("SystemAccountUser", "AccountId,UserId");
|
||||
CreateDbIndex("SystemAccountUser", "IDX_SystemAccountUser_User", "UserId");
|
||||
|
||||
// System User table:
|
||||
CreatePrimaryDbIndex("SystemUser", "Id");
|
||||
CreateDbIndex("SystemUser", "IDX_SystemUser_AffiliateId", "AffiliateId");
|
||||
CreateDbIndex("SystemUser", "IDX_SystemUser_Interface", "InterfaceId");
|
||||
CreateDbIndex("SystemUser", "IDX_SystemUser_OwnerCode", "AffIdOwner,Code", "", true);
|
||||
|
||||
// Transaction table:
|
||||
CreatePrimaryDbIndex("Transaction", "Id");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_AffilRaise", "AffIdRaise");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_AffilRefer", "AffIdRefer");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_Assoc", "AssocId");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_AssocContract", "AssocIdContract");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_AssocOffice", "AssocIdOffice");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_AssocType", "AssocId,Type");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_Currency", "CurrencyId");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_OwnerRef", "AffIdOwner,Ref");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_OwnerRefExt", "AffIdOwner,RefExt");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_OwnerTypeRaised", "AffIdOwner,Type,Raised");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_Postcode", "Postcode");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_StatusCat", "StatusCat");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_StockLocation", "LocationIdStock");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_TaxCode", "TaxCodeId");
|
||||
CreateDbIndex("Transaction", "IDX_Transaction_TransSource", "TransIdSource");
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// R e f e r e n c e D a t a
|
||||
//---------------------------------------------------------------------
|
||||
// Currency table:
|
||||
CreatePrimaryDbIndex("Currency", "Id");
|
||||
CreateDbIndex("Currency", "IDX_Currency_Code", "Code", "", true);
|
||||
CreateDbIndex("Currency", "IDX_Currency_Region", "Region");
|
||||
|
||||
// Language table:
|
||||
CreatePrimaryDbIndex("Language", "Id");
|
||||
CreateDbIndex("Language", "IDX_Language_Code", "Code", "", true);
|
||||
|
||||
// Region table:
|
||||
CreatePrimaryDbIndex("Region", "Id");
|
||||
CreateDbIndex("Region", "IDX_Region_ParentTypeName", "Parent,Type,Name");
|
||||
CreateDbIndex("Region", "IDX_Region_TypeName", "Type,Name", "", true);
|
||||
|
||||
// SysParam table:
|
||||
CreatePrimaryDbIndex("SysParam", "Id");
|
||||
CreateDbIndex("SysParam", "IDX_SysParam_CatAssName", "Cat,AssocId,Name");
|
||||
CreateDbIndex("SysParam", "IDX_SysParam_CatName", "Cat,Name");
|
||||
CreateDbIndex("SysParam", "IDX_SysParam_CatOrgName", "Cat,AffIdTarget,Name");
|
||||
CreateDbIndex("SysParam", "IDX_SysParam_CatPerName", "Cat,AffIdOwner,Name");
|
||||
|
||||
// TaxCode table:
|
||||
CreatePrimaryDbIndex("TaxCode", "Id");
|
||||
CreateDbIndex("TaxCode", "IdX_TaxCode_Code", "Code");
|
||||
CreateDbIndex("TaxCode", "IdX_TaxCode_CodeAlt1", "CodeAlt1");
|
||||
CreateDbIndex("TaxCode", "IdX_TaxCode_CodeAlt2", "CodeAlt2");
|
||||
|
||||
// Unit of Measure table:
|
||||
CreatePrimaryDbIndex("UnitMeasure", "Id");
|
||||
CreateDbIndex("UnitMeasure", "IDX_UnitMeasure_Code", "Code", "", true);
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Clean-up.
|
||||
database.DisplayErrors = displayDbExceptionsPrev;
|
||||
return !HasErrorState();
|
||||
Database.DisplayErrors = displayDbExceptionsPrev;
|
||||
return OK;
|
||||
}
|
||||
|
||||
private bool CreatePrimaryDbIndex(String tableName, String columns, bool dropIndicesIfNotExist = false)
|
||||
{
|
||||
if (HasErrorState()) return false;
|
||||
if (!Database.TableExists(tableName)) return true;
|
||||
List<String> columnNames = new List<String>(Regex.Split(columns, "[\\s,;\\-+]+"));
|
||||
DbDfnTable dfnTbl = Database.GetTableDfn(tableName);
|
||||
String indexName = "PK_" + tableName;
|
||||
if (!dfnTbl.HasIndexByName(indexName))
|
||||
{
|
||||
// Primary index does not exist on table.
|
||||
if (dropIndicesIfNotExist)
|
||||
{
|
||||
// All existing indices are dropped
|
||||
foreach (DbDfnIndex index in dfnTbl.Indices)
|
||||
DropDbIndex(tableName, index.Name);
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Examples:
|
||||
// MS Access: ALTER TABLE <table> ADD PRIMARY KEY (<ColumnList>)
|
||||
// 1. ALTER TABLE Customer ADD PRIMARY KEY (SID);
|
||||
// 2. ALTER TABLE [Sales].[Individual]
|
||||
// ADD CONSTRAINT [PK_Individual_CustomerID]
|
||||
// PRIMARY KEY CLUSTERED
|
||||
// ([CustomerID] ASC)
|
||||
String query = "ALTER TABLE [" + tableName + "] ADD CONSTRAINT [" + indexName + "] PRIMARY KEY (" + columnNames.Concat(",", "[", "]") + ")";
|
||||
if (Database.DbmsType == DbmsType.MsSql)
|
||||
query = "ALTER TABLE [" + tableName + "] ADD CONSTRAINT [" + indexName + "] PRIMARY KEY CLUSTERED (" + columnNames.Concat(",", "[", "]") + ")";
|
||||
SaLogger.Info($"{SysUtil.Fn} Query:\n\t" + query);
|
||||
if (!query.IsEmpty()) Database.ExecuteNonQuery(query);
|
||||
if (Database.HasErrorState())
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: {tableName}. Index: {indexName}. Exception: {Database.ErrorStateMessage.TrimEnd('.')}.");
|
||||
#endif
|
||||
SetErrorState($"Failed to create primary index {indexName} on {tableName} - {Database.ErrorStateMessage}");
|
||||
SaLogger.Error(ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
private bool CreateDbIndex(String tableName, String indexName, String columns, String includeColumns = "", bool unique = false)
|
||||
{
|
||||
if (HasErrorState()) return false;
|
||||
if (!Database.TableExists(tableName)) return true;
|
||||
List<String> columnNames = new List<String>(Regex.Split(columns, "[\\s,;\\-+]+"));
|
||||
List<String> includeColumnNames = new List<String>(Regex.Split(includeColumns, "[\\s,;\\-+]+"));
|
||||
DbDfnTable dfnTbl = Database.GetTableDfn(tableName);
|
||||
if (!dfnTbl.HasIndexByName(indexName)) // ToDo Should also check the columns and their sequence in the index.
|
||||
{
|
||||
String query = "CREATE " + (unique ? "UNIQUE " : "") + "INDEX ";
|
||||
query += "[" + indexName + "] ON [" + tableName + "] (" + columnNames.Concat(",", "[", "]") + ")";
|
||||
if (!includeColumnNames.IsEmpty())
|
||||
query += " INCLUDE (" + includeColumnNames.Concat(",", "[", "]") + ")";
|
||||
#if DEBUG
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: {tableName}. Index: {indexName}.");
|
||||
SaLogger.Debug("\tQuery: {query}");
|
||||
#endif
|
||||
SaLogger.Info($"{SysUtil.Fn} Query:\n\t" + query);
|
||||
if (!query.IsEmpty()) Database.ExecuteNonQuery(query);
|
||||
if (Database.HasErrorState())
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug($"\tException: {Database.ErrorStateMessage}");
|
||||
#endif
|
||||
SetErrorState($"Failed to create index {indexName} on {tableName} - {Database.ErrorStateMessage}");
|
||||
SaLogger.Error(ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
private bool DropDbIndex(String tableName, String indexName)
|
||||
{
|
||||
if (HasErrorState()) return false;
|
||||
if (!Database.TableExists(tableName)) return true;
|
||||
DbDfnTable dfnTbl = Database.GetTableDfn(tableName);
|
||||
if (!dfnTbl.HasIndexByName(indexName)) // ToDo Should also check the columns and their sequence in the index.
|
||||
{
|
||||
// Drop index:
|
||||
// MS Access: DROP INDEX index_name ON table_name
|
||||
// MS SQL Server: DROP INDEX table_name.index_name
|
||||
// DB2/Oracle: DROP INDEX index_name
|
||||
// MySQL: ALTER TABLE table_name DROP INDEX index_name
|
||||
String query = "DROP INDEX [" + indexName + "] ON [" + tableName + "]";
|
||||
SaLogger.Info("SapphireDbConsole_Odbc::DropDbIndex");
|
||||
SaLogger.Info("Query: " + query);
|
||||
if (Database.DbmsType == DbmsType.MsSql)
|
||||
query = "DROP INDEX [" + tableName + "].[" + indexName + "]";
|
||||
if (!query.IsEmpty()) Database.ExecuteNonQuery(query);
|
||||
if (Database.HasErrorState())
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: {tableName}. Index: {indexName}. Exception: {Database.ErrorStateMessage}");
|
||||
#endif
|
||||
SetErrorState($"Failed to drop index {indexName} on {tableName} - {Database.ErrorStateMessage}");
|
||||
SaLogger.Error(ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume this is the Primary Key:
|
||||
String query = "ALTER TABLE [" + tableName + "] DROP CONSTRAINT [" + indexName + "]";
|
||||
SaLogger.Info($"{SysUtil.Fn}");
|
||||
SaLogger.Info("Query: " + query);
|
||||
//if (Database.DbmsType == eSaDbmsMsSql)
|
||||
// sQry = (String)"DROP INDEX ["+sTable+"].["+sIndex+"]";
|
||||
if (!query.IsEmpty()) Database.ExecuteNonQuery(query);
|
||||
if (Database.HasErrorState())
|
||||
{
|
||||
#if DEBUG
|
||||
SaLogger.Debug($"{SysUtil.Fn} Table: {tableName}. Index: {indexName}. Exception: {Database.ErrorStateMessage}");
|
||||
#endif
|
||||
SetErrorState($"Failed to drop primary key {indexName} on {tableName} - {Database.ErrorStateMessage}");
|
||||
SaLogger.Error(ErrorStateMessage);
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user