Add project files.
This commit is contained in:
@@ -0,0 +1,422 @@
|
||||
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.Bus;
|
||||
using Sarand.Net.Standard.Base.Core;
|
||||
using Sarand.Net.Standard.Base.Dbas;
|
||||
using Sarand.Net.Standard.Base.Interfaces;
|
||||
using Sarand.Net.Standard.Base.ItemDocs;
|
||||
using Sarand.Net.Standard.Base.Utils;
|
||||
using Sarand.Net.Standard.Dbas.Base;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Bus
|
||||
{
|
||||
//=======================================================================
|
||||
class SbmCommodity_Dbas : SbmCommodity
|
||||
{
|
||||
//-------------------------------------------------------------------
|
||||
// Data members.
|
||||
private readonly SbmUserContext userContext;
|
||||
private SbmDataItemMgr dataItemMgr;
|
||||
private SbmProcessMgr processMgr;
|
||||
private SbmTransactionMgr transactionMgr;
|
||||
private List<SbmCostEstimate> costEstimates = new List<SbmCostEstimate>();
|
||||
private List<SbmItemProcess> itemProcesses = new List<SbmItemProcess>();
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Construction.
|
||||
public SbmCommodity_Dbas(SbmUserContext userContext, SysId id, SysId affiliateIdOwner, Sbm.CommodityType commodityType, String code, ushort flags) :
|
||||
base(userContext, id, affiliateIdOwner, commodityType, code)
|
||||
{
|
||||
this.userContext = userContext;
|
||||
Flags = flags;
|
||||
}
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (transactionMgr != null) transactionMgr.Dispose();
|
||||
if (processMgr != null) processMgr.Dispose();
|
||||
if (dataItemMgr != null) dataItemMgr.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// 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.
|
||||
//-------------------------------------------------------------------
|
||||
public override bool HasProcesses()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return SetErrorState("invalid item");
|
||||
if (processMgr != null) return SetErrorState("process manager not available");
|
||||
return processMgr.HasItemProcesses(Sbm.ItemType.Commodity, Id);
|
||||
}
|
||||
public override bool HasRequirements()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableRequirement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Requirement);
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_CommodityId) + "=" + Id.ToString();
|
||||
return db.GetRowCount(tableRequirement, /*SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Requirement_Id),*/ filter) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool IsSalesBudgetTemplate()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableCommodity = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity);
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Commodity_CommodityIdSalesProj) + "=" + Id.ToString();
|
||||
return db.GetRowCount(tableCommodity, /*SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Commodity_Id),*/ filter) > 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasComponents()
|
||||
{
|
||||
ClearErrorState();
|
||||
return false;
|
||||
}
|
||||
public override bool HasPortfolioItems()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tablePortfolioItem = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.PortfolioItem);
|
||||
if (db.TableExists(tablePortfolioItem))
|
||||
{
|
||||
String colPortfolioItem_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.PortfolioItem_Id);
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.PortfolioItem_CommodityId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tablePortfolioItem, /*colPortfolioItem_Id,*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasContainers()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableContainer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Container);
|
||||
if (db.TableExists(tableContainer))
|
||||
{
|
||||
String colContainerItem_ContainerId = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ContainerItem_ContainerId);
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ContainerItem_ItemType) + "=" + Sbm.ItemType.Commodity.ToString());
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ContainerItem_ItemId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableContainer, /*colContainerItem_ContainerId,*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasCustomerDetails()
|
||||
{
|
||||
ClearErrorState();
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableCommodityCustomer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer);
|
||||
if (db.TableExists(tableCommodityCustomer))
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableCommodityCustomer, /*"1",*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasSupplierDetails()
|
||||
{
|
||||
ClearErrorState();
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableCommoditySupplier = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommoditySupplier);
|
||||
if (db.TableExists(tableCommoditySupplier))
|
||||
{
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.CommoditySupplier_CommodityId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableCommoditySupplier, /*"1",*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasMovements()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableMovement = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Movement);
|
||||
if (db.TableExists(tableMovement))
|
||||
{
|
||||
String colMovement_Id = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_Id);
|
||||
List<String> filters = new List<String>();
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemType));
|
||||
filters.Add(SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Movement_ItemId) + "=" + Id.ToString());
|
||||
return db.GetRowCount(tableMovement, /*colMovement_Id,*/ filters.Concat(" AND ", "(", ")")) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool HasStockLevels()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null)
|
||||
{
|
||||
String tableStockLevel = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.StockLevel);
|
||||
if (db.TableExists(tableStockLevel))
|
||||
{
|
||||
String colStockLevel_CommodityId = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.StockLevel_CommodityId);
|
||||
String filter = colStockLevel_CommodityId + "=" + Id.ToString();
|
||||
return db.GetRowCount(tableStockLevel, filter) > 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public override bool ClearDependentData()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!SysId.IsValid(Id)) return false;
|
||||
ISacsDatabase db = SbmGlobals.Application.GetDatabase(userContext.SessionContext);
|
||||
if (db != null && !HasErrorState())
|
||||
{
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Remove data item references.
|
||||
if (dataItemMgr != null)
|
||||
{
|
||||
if (!dataItemMgr.ClearDataItem(Sbm.ItemType.Commodity, Id))
|
||||
SetErrorState(dataItemMgr.ErrorState.ToString());
|
||||
}
|
||||
else SetErrorState("Data item manager is not available");
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// ToDo SaItemDocConsole for Remove document references.
|
||||
SaItemDocConsole itemDocConsole = SbmGlobals.Application.GetItemDocConsole(userContext);
|
||||
if (itemDocConsole != null)
|
||||
{
|
||||
if (!itemDocConsole.ClearItemDocs(new ItemId((short)Sbm.ItemType.Commodity, Id), SaItemDocConsole.Category.Document, userContext.DbUpdateInfo))
|
||||
SetErrorState(itemDocConsole.ErrorState.ToString());
|
||||
}
|
||||
else SetErrorState("Failed to retrieve item document console");
|
||||
itemDocConsole = null;
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Remove interface references.
|
||||
SaInterfaceConsole interfaceConsole = SbmGlobals.Application.GetInterfaceConsole(userContext);
|
||||
if (interfaceConsole != null)
|
||||
{
|
||||
if (!interfaceConsole.ClearInterfaceDataItems(new ItemId((short)Sbm.ItemType.Commodity, Id), userContext.DbUpdateInfo))
|
||||
SetErrorState(interfaceConsole.ErrorState.ToString());
|
||||
}
|
||||
else SetErrorState("Failed to retrieve interface console");
|
||||
interfaceConsole = null;
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Remove customer commodity details.
|
||||
List<StringPair> columnNameValues = new List<StringPair>();
|
||||
String tableCommodityCustomer = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer);
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId) + "=" + Id.ToString();
|
||||
if (db != null && db.TableExists(tableCommodityCustomer) && db.ExecuteDelete(tableCommodityCustomer, filter) > 0)
|
||||
SetErrorState("Failed to clear customer commodity details");
|
||||
}
|
||||
if (!HasErrorState())
|
||||
{
|
||||
// Remove Supplier commodity details.
|
||||
String tableCommoditySupplier = SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommoditySupplier);
|
||||
String filter = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.CommoditySupplier_CommodityId) + "=" + Id.ToString();
|
||||
if (db != null && db.TableExists(tableCommoditySupplier) && db.ExecuteDelete(tableCommoditySupplier, filter) > 0)
|
||||
SetErrorState("Failed to clear Supplier commodity details");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
// Commodity Cost Estimates.
|
||||
public override List<SbmCostEstimate> GetCostEstimates()
|
||||
{
|
||||
//ClearErrorState();
|
||||
List<SbmCostEstimate> costEstimatesCopy = null;
|
||||
if (costEstimates == null && SysId.IsValid(Id) && dataItemMgr != null)
|
||||
{
|
||||
//***************************************************************
|
||||
// 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);
|
||||
if (db != null /*&& SbmGlobals.GetConsole().GetVersion().GetName() == "MPE" && Id.ToInt() < 6000*/)
|
||||
{
|
||||
String colItemLink_Type = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_Type);
|
||||
String colItemLink_ItemTypeFrom = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_ItemTypeFrom);
|
||||
String colItemLink_ItemIdFrom = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_ItemIdFrom);
|
||||
String colItemLink_CreateOn = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_CreateOn);
|
||||
String colItemLink_UpdateOn = SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.ItemLink_UpdateOn);
|
||||
List<String> filters = new List<String>();
|
||||
// Identify cost estimates for requirements with the same Id as this commodity which were created since the 1-Jan-2006
|
||||
// (to avoid updating cost estimates that are more likely to belong to requirements - cost estimates were introduced against commodities during 2006).
|
||||
filters.Add("(" + colItemLink_Type + "=" + Sbm.ItemLinkType.ItemCostEstimate.ToString() + " OR " + colItemLink_Type + "=" + Sbm.ItemLinkType.Requirement_CostEstimate.ToString() + ")");
|
||||
filters.Add(colItemLink_ItemTypeFrom + "=" + Sbm.ItemType.Requirement.ToString());
|
||||
filters.Add(colItemLink_ItemIdFrom + "=" + Id.ToString());
|
||||
filters.Add(colItemLink_CreateOn + ">=" + DbQuery.FormatForCondition(new DateTime(1, 1, 2006/*2006,1,1*/).ToString()));
|
||||
if (db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.ItemLink), /*colItemLink_Type, rowCount,*/ filters.Concat(" AND ", "(", ")")) > 0)
|
||||
{
|
||||
// The link type and 'From' item type are changed to reflect the commodity relationship.
|
||||
List<StringPair> values = new List<StringPair>();
|
||||
SacsDatabase.AddValuePair(values, colItemLink_Type, ((int)Sbm.ItemLinkType.ItemCostEstimate).ToString(), false);
|
||||
SacsDatabase.AddValuePair(values, colItemLink_ItemTypeFrom, ((int)Sbm.ItemType.Commodity).ToString(), false);
|
||||
SacsDatabase.AddValuePair(values, colItemLink_UpdateOn, DbQuery.FormatForCondition(new DateTime().ToString()), false);
|
||||
db.ExecuteUpdate(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.ItemLink), values, filters.Concat(" AND ", "(", ")"));
|
||||
}
|
||||
}
|
||||
//***************************************************************
|
||||
SbmItemLink.Params prmItemLink = new SbmItemLink.Params();
|
||||
prmItemLink.ItemLinkType = Sbm.ItemLinkType.ItemCostEstimate;
|
||||
prmItemLink.ItemTypeFrom = Sbm.ItemType.Commodity;
|
||||
prmItemLink.ItemIdFrom = Id;
|
||||
List<SbmItemLink> itemLinks = dataItemMgr.GetItemLinkList(prmItemLink);
|
||||
if (itemLinks != null)
|
||||
{
|
||||
foreach (SbmItemLink itemLink in itemLinks)
|
||||
{
|
||||
SbmCostEstimate costEstimate = new SbmCostEstimate(UserContext, itemLink.DataContent);
|
||||
costEstimate.Notes = itemLink.Notes;
|
||||
costEstimate.Changed = false;
|
||||
if (costEstimates == null) costEstimates = new List<SbmCostEstimate>();
|
||||
costEstimates.Add(costEstimate);
|
||||
}
|
||||
// Clean-up.
|
||||
itemLinks.Clear();
|
||||
}
|
||||
}
|
||||
// Clone the list.
|
||||
costEstimatesCopy = costEstimates.Clone();
|
||||
return costEstimatesCopy;
|
||||
}
|
||||
public override bool SetCostEstimates(List<SbmCostEstimate> costEstimatesNew)
|
||||
{
|
||||
ClearErrorState();
|
||||
// Clear the existing list.
|
||||
if (costEstimates != null) costEstimates.Clear();
|
||||
// Copy all items from the specified list.
|
||||
costEstimates = costEstimatesNew.Clone();
|
||||
return true;
|
||||
}
|
||||
public override bool CommitCostEstimates()
|
||||
{
|
||||
ClearErrorState();// Do not attempt any updates unless the list has been populated.
|
||||
if (costEstimates != null && SysId.IsValid(Id) && dataItemMgr != null)
|
||||
{
|
||||
// Build an item link list corresponding to the list of cost estimates.
|
||||
List<SbmItemLink> itemLinks = new List<SbmItemLink>();
|
||||
foreach (SbmCostEstimate costEstimate in costEstimates)
|
||||
{
|
||||
if (costEstimate == null) continue;
|
||||
SbmItemLink itemLink = dataItemMgr.CreateItemLink(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, Sbm.ItemType.Unknown, new SysId());
|
||||
if (itemLink != null)
|
||||
{
|
||||
itemLink.Seq = (short)costEstimate.CodeSeq;
|
||||
itemLink.DataContent = costEstimate.ToString();
|
||||
itemLink.Notes = costEstimate.Notes;
|
||||
itemLinks.Add(itemLink);
|
||||
itemLink = null; // Now owned by the list.
|
||||
}
|
||||
}
|
||||
// Store these details.
|
||||
if (dataItemMgr.StoreFromItemLinks(Sbm.ItemLinkType.ItemCostEstimate, Sbm.ItemType.Commodity, Id, itemLinks, userContext.DbUpdateInfo))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
SetErrorState("Failed to save cost estimate item links - " + dataItemMgr.ErrorState);
|
||||
}
|
||||
if (itemLinks != null)
|
||||
itemLinks.Clear();
|
||||
}
|
||||
return !HasErrorState();
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
// Commodity processes.
|
||||
public override List<SbmItemProcess> GetProcesses(bool activeOnly)
|
||||
{
|
||||
//ToDo need to creat SbmProcessMgr_Dbas-ItemProcess inorder to do processMgr.???
|
||||
ClearErrorState();
|
||||
List<SbmItemProcess> itemProcesesCopy = null;
|
||||
if (activeOnly)
|
||||
{
|
||||
// Retrieve the list of 'active' processes for this item.
|
||||
processMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Full list required - check whether the internal list has been populated yet.
|
||||
if (itemProcesses == null && SysId.IsValid(Id) && processMgr != null)
|
||||
{
|
||||
// Get the list of processes.
|
||||
processMgr.GetProcessesForItem(Sbm.ItemType.Commodity, Id, false);
|
||||
}
|
||||
// Clone the list.
|
||||
itemProcesesCopy = itemProcesses.Clone();
|
||||
}
|
||||
if (itemProcesesCopy != null) itemProcesesCopy.Sort();
|
||||
return itemProcesesCopy;
|
||||
}
|
||||
public override bool SetProcesses(List<SbmItemProcess> itemProcessesNew)
|
||||
{
|
||||
ClearErrorState();
|
||||
if (itemProcesses != null) itemProcesses.Clear();
|
||||
// Copy all items from the specified list.
|
||||
itemProcesses = itemProcessesNew.Clone();
|
||||
return !HasErrorState();
|
||||
}
|
||||
public override bool CommitProcesses()
|
||||
{
|
||||
ClearErrorState();
|
||||
if (!processMgr.StoreItemProcesses(Sbm.ItemType.Commodity, Id, itemProcesses, userContext.DbUpdateInfo))
|
||||
SetErrorState(processMgr.ErrorState.ToString());
|
||||
return !HasErrorState();
|
||||
}
|
||||
}
|
||||
//=======================================================================
|
||||
}
|
||||
Reference in New Issue
Block a user