239 lines
10 KiB
C#
239 lines
10 KiB
C#
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.Bus;
|
|
using Sarand.Net.Standard.Base.Core;
|
|
using Sarand.Net.Standard.Base.Dbas;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Base.Mgr
|
|
{
|
|
//=======================================================================
|
|
// Account manager - System Accounts.
|
|
//=======================================================================
|
|
partial class SbmAccountMgr
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
|
|
// Associated data.
|
|
public abstract bool SystemAccountHasUsers(SysId systemAccountId);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Retrieve individual systemAccounts.
|
|
//-------------------------------------------------------------------
|
|
// SsystemAccount exists.
|
|
public bool SystemAccountExistsById(SysId systemAccountId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(systemAccountId)) return false;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.IdsIncluded.Add(systemAccountId);
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccountCount(prmSystemAccount) == 1;
|
|
}
|
|
public bool AccountExistsByAssoc(SysId interfaceId, SysId assocId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(interfaceId) || !SysId.IsValid(assocId)) return false;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.InterfaceId = interfaceId;
|
|
prmSystemAccount.AssocId = assocId;
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccountCount(prmSystemAccount) == 1;
|
|
}
|
|
|
|
public bool AccountExistsByCode(SysId interfaceId, String code)
|
|
{
|
|
ClearErrorState();
|
|
if (StringUtil.IsEmpty(code)) return false;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.InterfaceId = interfaceId;
|
|
prmSystemAccount.CodePartial = code;
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccountCount(prmSystemAccount) == 1;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get systemAccount.
|
|
public abstract SbmSystemAccount GetSystemAccount(SbmSystemAccount.Params prm);
|
|
|
|
public SbmSystemAccount GetSystemAccountById(SysId systemAccountId)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(systemAccountId)) return null;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.IdsIncluded.Add(systemAccountId);
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccount(prmSystemAccount);
|
|
}
|
|
public SbmSystemAccount GetAccountByAssocId(SysId interfaceId, SysId assocId)
|
|
{
|
|
SbmSystemAccount systemAccount = null;
|
|
if (!SysId.IsValid(interfaceId) || !SysId.IsValid(assocId)) return systemAccount;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.InterfaceId = interfaceId;
|
|
prmSystemAccount.AssocId = assocId;
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccount(prmSystemAccount);
|
|
}
|
|
|
|
public SbmSystemAccount GetAccountByCode(SysId interfaceId, String code)
|
|
{
|
|
SbmSystemAccount systemAccount = null;
|
|
if (StringUtil.IsEmpty(code)) return systemAccount;
|
|
SbmSystemAccount.Params prmSystemAccount = new SbmSystemAccount.Params();
|
|
prmSystemAccount.InterfaceId = interfaceId;
|
|
prmSystemAccount.CodePartial = code;
|
|
prmSystemAccount.StatusCat = SbmSystemAccount.StatusCat.Any;
|
|
return GetSystemAccount(prmSystemAccount);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create systemAccount.
|
|
public abstract SbmSystemAccount CreateSystemAccount(Sbm.SystemAccountType systemAccountType, SysId interfaceId, SysId assocId);
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate systemAccount data.
|
|
public bool IsValidSystemAccount(SbmSystemAccount systemAccount)
|
|
{
|
|
ClearErrorState();
|
|
if (systemAccount == null) return SetErrorState(ErrorMessage.ItemNotSpecified);
|
|
return IsValidSystemAccountData(systemAccount.GetData(), new SbmSystemAccount.ErrField());
|
|
}
|
|
public virtual bool IsValidSystemAccountData(SbmSystemAccount.Data data, SbmSystemAccount.ErrField errField)
|
|
{
|
|
// SystemAccount properties.
|
|
ClearErrorState();
|
|
//Validate the identity.
|
|
if (!SysId.IsValid(data.AffiliateIdOwner)) return SetErrorState("invalid affiliate owner");
|
|
if ((int)data.SystemAccountType < 1) return SetErrorState("invalid type");
|
|
if (!SysId.IsValid(data.InterfaceId)) return SetErrorState("invalid system");
|
|
if (!SysId.IsValid(data.AssociationId)) return SetErrorState("invalid association");
|
|
// Validate the text attributes.
|
|
if (errField.Code != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Code, "code", (long)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.SystemAccount_Code), true))
|
|
{
|
|
errField.Code = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Name != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Name, "name", (long)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.SystemAccount_Name), true))
|
|
{
|
|
errField.Name = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.AuthCodeEnc != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.AuthCodeEnc, "authorisation code", (long)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.SystemAccount_AuthCodeEnc)))
|
|
{
|
|
errField.AuthCodeEnc = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
// Common properties.
|
|
if (!IsValidValue(data.Notes, "notes", (long)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.SystemAccount_Notes)))
|
|
{
|
|
errField.Notes = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (errField.Status != SacsHierarchyItem.ValidValue.Ignore)
|
|
{
|
|
if (!IsValidValue(data.StatusCode, "status", (long)SbmDbDfn.GetColTextLen(SbmDbDfn.ColumnIdx.SystemAccount_Status), true, true))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return false;
|
|
}
|
|
if (!SbmSystemAccount.SystemAccountStatuses.Contains(data.Status))
|
|
{
|
|
errField.Status = SacsHierarchyItem.ValidValue.Invalid;
|
|
return SetErrorState(ErrorMessage.InvalidStatus);
|
|
}
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// SystemAccount database interface.
|
|
public abstract bool InsertSystemAccount(SbmSystemAccount systemAccount, DbUpdateInfo dbUpdateInfo);
|
|
public abstract bool UpdateSystemAccount(SbmSystemAccount systemAccount, DbUpdateInfo dbUpdateInfo);
|
|
public virtual bool SystemAccountCanBeDeleted(SbmSystemAccount systemAccount)
|
|
{
|
|
ClearErrorState();
|
|
return true;
|
|
}
|
|
public abstract bool DeleteSystemAccount(SbmSystemAccount systemAccount, DbUpdateInfo dbUpdateInfo);
|
|
|
|
//-------------------------------------------------------------------
|
|
// SystemAccount list.
|
|
public abstract ColumnDfn GetSystemAccountColumnDfn(SbmSystemAccount.Column columnId, String caption = "", int width = 0);
|
|
public abstract List<String> GetSystemAccountQueryFilter(SbmSystemAccount.Params prm);
|
|
public abstract long GetSystemAccountCount(SbmSystemAccount.Params prm);
|
|
public abstract List<SbmSystemAccount> GetSystemAccountList(SbmSystemAccount.Params prm);
|
|
public abstract DbResultSet SystemAccountExecuteQuery(List<ColumnDfn> columns, SbmSystemAccount.Params prm);
|
|
|
|
//-------------------------------------------------------------------
|
|
// D a t a V a l u e s
|
|
//-------------------------------------------------------------------
|
|
/// <summary>
|
|
/// Extract and format result set data value where specific handling is required.
|
|
/// <para>Where response is an invalid data value, format value using column.FormatValue(values).</para>
|
|
/// </summary>
|
|
public DataValue GetSystemAccountDataValue(ColumnDfn column, NamedValue.Map values)
|
|
{
|
|
DataValue value = new DataValue();
|
|
switch ((SbmSystemAccount.Column)column.Id)
|
|
{
|
|
//-----------------------------------------------------------
|
|
// SystemAccount TypeDesc.
|
|
case SbmSystemAccount.Column.Type_Desc:
|
|
{
|
|
Sbm.SystemAccountType systemAccountType = (Sbm.SystemAccountType)values.GetValue(column.DataName).AsLong();
|
|
value = new DataValue(SystemAccountTypes.GetDescForType(systemAccountType, ((int)systemAccountType).ToString()));
|
|
break;
|
|
}
|
|
|
|
//-----------------------------------------------------------
|
|
// Notes.
|
|
case SbmSystemAccount.Column.Notes:
|
|
value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200));
|
|
break;
|
|
|
|
// Assoc Status.
|
|
case SbmSystemAccount.Column.Assoc_Status_Desc:
|
|
case SbmSystemAccount.Column.Assoc_Status_Ind:
|
|
{
|
|
String statusCode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
|
if (column.Id == (int)SbmSystemAccount.Column.Assoc_Status_Desc)
|
|
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
|
if (column.Id == (int)SbmSystemAccount.Column.Assoc_Status_Ind)
|
|
value = new DataValue(SbmAssociation.GetStatusTriState(status));
|
|
}
|
|
break;
|
|
|
|
// Status.
|
|
case SbmSystemAccount.Column.Status_Desc:
|
|
case SbmSystemAccount.Column.Status_Ind:
|
|
{
|
|
String statusCode = values.GetValue(column.DataName).ToString();
|
|
SaStatus status = SacsSystem.GetStatusForCode(statusCode);
|
|
if (column.Id == (int)SbmSystemAccount.Column.Status_Desc)
|
|
value = new DataValue(SacsSystem.GetStatusDescForCode(statusCode));
|
|
else if (column.Id == (int)SbmSystemAccount.Column.Status_Ind)
|
|
value = new DataValue(SbmSystemAccount.GetStatusTriState(status));
|
|
}
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
default:
|
|
value = values.GetValue(column.DataName);
|
|
break;
|
|
|
|
}
|
|
return value;
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|