730 lines
38 KiB
C#
730 lines
38 KiB
C#
using Sarand.BusinessMgr.Net.Standard.Base.App;
|
|
using Sarand.BusinessMgr.Net.Standard.Base.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.Bus;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.Internal;
|
|
using Sarand.BusinessMgr.Net.Standard.Dbas.UpdateLog;
|
|
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 Sarand.Net.Standard.Dbas.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
|
|
namespace Sarand.BusinessMgr.Net.Standard.Dbas.Mgr
|
|
{
|
|
//=======================================================================
|
|
partial class SbmCommodityMgr_Dbas
|
|
{
|
|
//*******************************************************************
|
|
// C o m m o d i t i e s C u s t o m e r
|
|
//*******************************************************************
|
|
//-------------------------------------------------------------------
|
|
// Data members.
|
|
private String msg_UnableToManageCommodityCustomers = "Unable to manage commodity customers";
|
|
|
|
//-------------------------------------------------------------------
|
|
// Utilities.
|
|
private List<StringPair> GetLogProperties(SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
return new List<StringPair>()
|
|
{
|
|
new StringPair("Id",SysId.ToString(commodityCustomer.Id)),
|
|
new StringPair("ProductCode",commodityCustomer.ProductCode),
|
|
new StringPair("Status",commodityCustomer.StatusCode)
|
|
};
|
|
}
|
|
public override bool CanManageCommodityCustomers()
|
|
{
|
|
if (ConfigConsole == null || !AllowConfigOption(Sbm.ConfigOption.CommodityCustomers)) return false;
|
|
return db != null && db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer));
|
|
}
|
|
public override bool StoreCommodityCustomers(List<SbmCommodityCustomer> commodityCustomers)
|
|
{
|
|
ClearErrorState();
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
foreach (SbmCommodityCustomer commodityCustomer in commodityCustomers)
|
|
{
|
|
for (int i = 1; i < commodityCustomers.Count; i++)
|
|
{
|
|
Store(commodityCustomers[i]);
|
|
}
|
|
}
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
public override bool StoreCommodityCustomersForCommodity(SysId commodityId, List<SbmCommodityCustomer> commodityCustomers)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(commodityId)) return SetErrorState("Commodity must be specified");
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
// Copy the list so that existing items can be removed once they are updated.
|
|
List<SbmCommodityCustomer> commodityCustomersCopy = commodityCustomers;
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
public override bool StoreCommodityCustomersForCustomer(SysId assocIdCustomer, List<SbmCommodityCustomer> commodityCustomers)
|
|
{
|
|
ClearErrorState();
|
|
if (!SysId.IsValid(assocIdCustomer)) return SetErrorState("Customer must be specified");
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
// Copy the list so that existing items can be removed once they are updated.
|
|
List<SbmCommodityCustomer> commodityCustomersCopy = commodityCustomers;
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
public override bool Store(SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
ClearErrorState();
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
DbUpdateInfo dbUpdateInfo = null;
|
|
if (IsValidCommodityCustomer(commodityCustomer))
|
|
{
|
|
SbmCommodityCustomer.Params prmCommodityCustomer = new SbmCommodityCustomer.Params();
|
|
prmCommodityCustomer.CommodityId = commodityCustomer.CommodityId;
|
|
prmCommodityCustomer.AssocIdCustomer = commodityCustomer.AssocIdCustomer;
|
|
prmCommodityCustomer.StatusCat = SbmCommodityCustomer.StatusCat.Any;
|
|
if (GetCommodityCustomerCount(prmCommodityCustomer) == 0)
|
|
{
|
|
InsertCommodityCustomer(commodityCustomer, dbUpdateInfo);
|
|
}
|
|
else
|
|
{
|
|
UpdateCommodityCustomer(commodityCustomer, dbUpdateInfo);
|
|
}
|
|
|
|
}
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
public override bool ClearCustomersForCommodity(SysId commodityId)
|
|
{
|
|
ClearErrorState();
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
if (!SysId.IsValid(commodityId)) SetErrorState("Commodity must be specified");
|
|
|
|
if (db != null && db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer)))
|
|
{
|
|
String filter = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, null, false) + "=" + commodityId.ToString();
|
|
if (db.ExecuteDelete(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer), filter) > 0)
|
|
SetErrorState("Delete failed - " + db.ErrorState);
|
|
}
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
public override bool ClearCommoditiesForCustomer(SysId assocCustomerId)
|
|
{
|
|
ClearErrorState();
|
|
if (CanManageCommodityCustomers())
|
|
{
|
|
if (!SysId.IsValid(assocCustomerId)) SetErrorState("Customer must be specified");
|
|
if (db != null && db.TableExists(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer)))
|
|
{
|
|
String filter = SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, null, false) + "=" + assocCustomerId.ToString();
|
|
if (db.ExecuteDelete(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer), filter) > 0)
|
|
SetErrorState("Delete failed - " + db.ErrorState);
|
|
}
|
|
}
|
|
else SetErrorState(msg_UnableToManageCommodityCustomers);
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get CommodityCustomer.
|
|
public override SbmCommodityCustomer GetCommodityCustomer(SbmCommodityCustomer.Params prm)
|
|
{
|
|
return GetCommodityCustomer(GetCommodityCustomerQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
private SbmCommodityCustomer GetCommodityCustomer(String filter)
|
|
{
|
|
ClearErrorState();
|
|
long count = GetCommodityCustomerCount(filter);
|
|
if (count == 0) return null;
|
|
if (count != 1)
|
|
{
|
|
SetErrorState("Multiple Commodity Customer found");
|
|
return null;
|
|
}
|
|
SbmCommodityCustomer prmCommodityCustomer = null;
|
|
// Query data.
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
CommodityCustomer_Db dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
dbCommodityCustomer.PopulateFrom(dbCommand, aliasCommodityCustomer, filter);
|
|
prmCommodityCustomer = CreateCommodityCustomer(dbCommodityCustomer);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SetErrorState("Database query exception");
|
|
SaLogger.Warn(GetType().Name + ".GetCommodityCustomer\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
|
}
|
|
}
|
|
return prmCommodityCustomer;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create CommodityCustomer.
|
|
public override SbmCommodityCustomer CreateCommodityCustomer(SysId commodityId, SysId assocIdCustomer)
|
|
{
|
|
return new SbmCommodityCustomer_Dbas(Internals, commodityId, assocIdCustomer, 0);
|
|
}
|
|
private SbmCommodityCustomer_Dbas CreateCommodityCustomer(CommodityCustomer_Db dbCommodityCustomer)
|
|
{
|
|
ClearErrorState();
|
|
SbmCommodityCustomer_Dbas commodityCustomer = new SbmCommodityCustomer_Dbas(Internals, new SysId(dbCommodityCustomer._CommodityId), new SysId(dbCommodityCustomer._AssocIdCustomer), (ushort)dbCommodityCustomer._Flags);
|
|
PopulateFrom(dbCommodityCustomer, commodityCustomer);
|
|
return commodityCustomer;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate CommodityCustomer.
|
|
public override bool IsValidCommodityCustomerData(SbmCommodityCustomer.Data data, SbmCommodityCustomer.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.IsValidCommodityCustomerData(data, errField)) return false;
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Insert CommodityCustomer.
|
|
public override bool InsertCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".InsertCommodityCustomer";
|
|
ClearErrorState();
|
|
if (!IsValidCommodityCustomer(commodityCustomer)) return false;
|
|
if (SysId.IsValid(commodityCustomer.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
CommodityCustomer_Db dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
PopulateTo(dbCommodityCustomer, commodityCustomer, dbUpdateInfo);
|
|
if (CommodityCustomer_Db.FieldsNonId.Contains("Id"))
|
|
{
|
|
// Generate next Id.
|
|
dbCommodityCustomer._CommodityId = SysId.ToInt(db.GetNextId("CommodityCustomer", dbUpdateInfo));
|
|
}
|
|
dbCommodityCustomer.ExecuteInsertCommand(dbCommand);
|
|
commodityCustomer.Id = new SysId(dbCommodityCustomer._CommodityId);
|
|
commodityCustomer.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(commodityCustomer).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update CommodityCustomer.
|
|
public override bool UpdateCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".UpdateCommodityCustomer";
|
|
ClearErrorState();
|
|
if (!IsValidCommodityCustomer(commodityCustomer)) return false;
|
|
if (!SysId.IsValid(commodityCustomer.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
|
if (!commodityCustomer.Changed)
|
|
{
|
|
if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(commodityCustomer).Concat(": ").Concat("", "\n\t"));
|
|
return true;
|
|
}
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve commodityCustomer.
|
|
dbConnection.Open();
|
|
CommodityCustomer_Db dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
dbCommodityCustomer.PopulateFrom(dbCommand, aliasCommodityCustomer, "Id=" + SysId.ToString(commodityCustomer.Id));
|
|
SbmUpdateLogItemMonitor_CommodityCustomer updateLogMonitor = new SbmUpdateLogItemMonitor_CommodityCustomer(Internals, CreateCommodityCustomer(dbCommodityCustomer));
|
|
|
|
// Update properties.
|
|
PopulateTo(dbCommodityCustomer, commodityCustomer, dbUpdateInfo);
|
|
dbCommodityCustomer.ExecuteUpdateCommand(dbCommand);
|
|
commodityCustomer.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(commodityCustomer).Concat(": ").Concat("", "\n\t"));
|
|
|
|
// Record updates.
|
|
updateLogMonitor.RecordUpdatedValues(commodityCustomer);
|
|
updateLogMonitor.LogUpdates();
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete CommodityCustomer.
|
|
public override bool CommodityCustomerCanBeDeleted(SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.CommodityCustomerCanBeDeleted(commodityCustomer)) return false;
|
|
return true;
|
|
}
|
|
public override bool DeleteCommodityCustomer(SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".DeleteCommodityCustomer";
|
|
ClearErrorState();
|
|
if (!CommodityCustomerCanBeDeleted(commodityCustomer)) return false;
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve prmCommodityCustomer.
|
|
dbConnection.Open();
|
|
CommodityCustomer_Db dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
dbCommodityCustomer.PopulateFrom(dbCommand, aliasCommodityCustomer, "Id=" + commodityCustomer.Id.ToString());
|
|
// Delete prmCommodityCustomer.
|
|
dbCommand.CommandType = System.Data.CommandType.Text;
|
|
dbCommand.CommandText = "DELETE FROM " + SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer) + " WHERE Id=" + SysId.ToString(commodityCustomer.Id) + ";";
|
|
dbCommand.ExecuteNonQuery();
|
|
commodityCustomer.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(commodityCustomer).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Copy data properties to and from database.
|
|
private void PopulateTo(CommodityCustomer_Db dbCommodityCustomer, SbmCommodityCustomer commodityCustomer, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
dbCommodityCustomer._CommodityId = commodityCustomer.Id.ToInt();
|
|
dbCommodityCustomer._CommodityId = commodityCustomer.CommodityId.ToInt();
|
|
dbCommodityCustomer._AssocIdCustomer = commodityCustomer.AssocIdCustomer.ToInt();
|
|
dbCommodityCustomer._ProductCode = commodityCustomer.ProductCode;
|
|
dbCommodityCustomer._AmountRetail = commodityCustomer.AmountRetail;
|
|
dbCommodityCustomer._CurrencyIdRetail = commodityCustomer.CurrencyIdRetail.ToInt();
|
|
dbCommodityCustomer._PromotionCode = commodityCustomer.PromotionCode;
|
|
// Common properties.
|
|
dbCommodityCustomer._Notes = commodityCustomer.Notes;
|
|
dbCommodityCustomer._Flags = (short)commodityCustomer.Flags;
|
|
dbCommodityCustomer._Status = SacsSystem.GetStatusCode(commodityCustomer.Status);
|
|
if (!SysId.IsValid(commodityCustomer.Id))
|
|
{
|
|
dbCommodityCustomer._CreateOn = DateTime.UtcNow;
|
|
dbCommodityCustomer._CreateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbCommodityCustomer._CreateHost = dbUpdateInfo.Host;
|
|
}
|
|
dbCommodityCustomer._UpdateOn = DateTime.UtcNow;
|
|
dbCommodityCustomer._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbCommodityCustomer._UpdateHost = dbUpdateInfo.Host;
|
|
}
|
|
private void PopulateFrom(CommodityCustomer_Db dbCommodityCustomer, SbmCommodityCustomer commodityCustomer)
|
|
{
|
|
commodityCustomer.Id = new SysId(dbCommodityCustomer._CommodityId);
|
|
commodityCustomer.CommodityId = new SysId(dbCommodityCustomer._CommodityId);
|
|
commodityCustomer.AssocIdCustomer = new SysId(dbCommodityCustomer._AssocIdCustomer);
|
|
commodityCustomer.ProductCode = dbCommodityCustomer._ProductCode;
|
|
commodityCustomer.AmountRetail = dbCommodityCustomer._AmountRetail;
|
|
commodityCustomer.CurrencyIdRetail = new SysId(dbCommodityCustomer._CurrencyIdRetail);
|
|
commodityCustomer.PromotionCode = dbCommodityCustomer._PromotionCode;
|
|
// Common properties.
|
|
commodityCustomer.Notes = dbCommodityCustomer._Notes;
|
|
commodityCustomer.Status = SacsSystem.GetStatusForCode(dbCommodityCustomer._Status);
|
|
commodityCustomer.SetCreateStamp(dbCommodityCustomer._CreateOn, new SysId(dbCommodityCustomer._CreateBy), dbCommodityCustomer._CreateHost);
|
|
commodityCustomer.SetUpdateStamp(dbCommodityCustomer._UpdateOn, new SysId(dbCommodityCustomer._UpdateBy), dbCommodityCustomer._UpdateHost);
|
|
commodityCustomer.AcceptChanges();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Table aliases & column prefixes.
|
|
private static readonly String aliasCommodityCustomer = "CmdCust";
|
|
private static String aliasCommodityCustomer_Commodity = "CmdCustCmd";
|
|
private static String prefixCommodityCustomer_Commodity = "_CmdCustCmd";
|
|
private static String aliasCommodityCustomer_Association = "CmdCustAss";
|
|
private static String prefixCommodityCustomer_Association = "CmdCustAss_";
|
|
private static String aliasCommodityCustomer_Affiliate = "CmdCustAff";
|
|
private static String prefixCommodityCustomer_Affiliate = "CmdCustAff_";
|
|
private static String aliasCommodityCustomer_CurrencyRetail = "CmdCustCurRet";
|
|
private static String prefixCommodityCustomer_CurrencyRetail = "CmdCustCurrRet_";
|
|
|
|
//-------------------------------------------------------------------
|
|
// Column definitions.
|
|
private void SetCommodityCustomerColDfn
|
|
(ColumnDfn col, String caption, int width, SbmDbDfn.ColumnIdx dbCol,
|
|
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
|
String alias = "", String prefix = "")
|
|
{
|
|
if (String.IsNullOrEmpty(alias) && SbmDbDfn.GetTableForColumn(dbCol) == SbmDbDfn.TableIdx.CommodityCustomer)
|
|
alias = aliasCommodityCustomer;
|
|
col.Set(caption, width, (int)dbCol, prefix + SbmDbDfn.GetColumnName(dbCol, false), SbmDbDfn.GetColumnNameQual(dbCol, alias), dataType, align);
|
|
if (dataType == DataValue.DataType.String && dbCol != SbmDbDfn.ColumnIdx.Unknown)
|
|
col.MaxLength = (int)SbmDbDfn.GetColTextLen(dbCol);
|
|
}
|
|
public override ColumnDfn GetCommodityCustomerColumnDfn(SbmCommodityCustomer.Column columnId, string caption = "", int width = 0)
|
|
{
|
|
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
|
switch (columnId)
|
|
{
|
|
case SbmCommodityCustomer.Column.Pos:
|
|
SetCommodityCustomerColDfn(columnDfn, "Pos", 45, SbmDbDfn.ColumnIdx.Unknown, ColumnAlignment.Right);
|
|
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
|
columnDfn.ReadOnly = true;
|
|
columnDfn.Resizable = false;
|
|
break;
|
|
|
|
// CommodityCustomer Properties.
|
|
case SbmCommodityCustomer.Column.Commodity_Id:
|
|
SetCommodityCustomerColDfn(columnDfn, "Cmd Id", 60, SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_Code:
|
|
SetCommodityCustomerColDfn(columnDfn, "Commodity", 80, SbmDbDfn.ColumnIdx.Commodity_Code, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_DescBrief:
|
|
SetCommodityCustomerColDfn(columnDfn, "Commodity desc", 100, SbmDbDfn.ColumnIdx.Commodity_DescBrief, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_CategoryCode:
|
|
SetCommodityCustomerColDfn(columnDfn, "Commodity Cat", 80, SbmDbDfn.ColumnIdx.Commodity_Category, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_CategoryDesc:
|
|
SetCommodityCustomerColDfn(columnDfn, "Commodity Category", 120, SbmDbDfn.ColumnIdx.Commodity_Category, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_Status:
|
|
SetCommodityCustomerColDfn(columnDfn, "Cmd status", 75, SbmDbDfn.ColumnIdx.Commodity_Status, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_StatusDesc:
|
|
SetCommodityCustomerColDfn(columnDfn, "Commodity status", 75, SbmDbDfn.ColumnIdx.Commodity_Status, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Commodity_StatusInd:
|
|
SetCommodityCustomerColDfn(columnDfn, "Cmd status", 75, SbmDbDfn.ColumnIdx.Commodity_Status, ColumnAlignment.Center, DataValue.DataType.TriState, aliasCommodityCustomer_Commodity, prefixCommodityCustomer_Commodity);
|
|
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
|
break;
|
|
case SbmCommodityCustomer.Column.AssocIdCustomer:
|
|
SetCommodityCustomerColDfn(columnDfn, "Cust Id", 60, SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, ColumnAlignment.Right);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Customer_Code:
|
|
SetCommodityCustomerColDfn(columnDfn, "Customer code", 80, SbmDbDfn.ColumnIdx.Association_Code, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Association, prefixCommodityCustomer_Association);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Customer_Name:
|
|
SetCommodityCustomerColDfn(columnDfn, "Customer name", 120, SbmDbDfn.ColumnIdx.Affiliate_Name, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_Affiliate, prefixCommodityCustomer_Affiliate);
|
|
break;
|
|
case SbmCommodityCustomer.Column.ProductCode:
|
|
SetCommodityCustomerColDfn(columnDfn, "Product", 100, SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode);
|
|
break;
|
|
case SbmCommodityCustomer.Column.AmountRetail:
|
|
SetCommodityCustomerColDfn(columnDfn, "Retail", 70, SbmDbDfn.ColumnIdx.CommodityCustomer_AmountRetail, ColumnAlignment.Right, DataValue.DataType.Double);
|
|
break;
|
|
case SbmCommodityCustomer.Column.AmountRetail_Fmt:
|
|
SetCommodityCustomerColDfn(columnDfn, "Retail", 70, SbmDbDfn.ColumnIdx.CommodityCustomer_AmountRetail, ColumnAlignment.Right, DataValue.DataType.String);
|
|
break;
|
|
case SbmCommodityCustomer.Column.CurrencyIdRetail:
|
|
SetCommodityCustomerColDfn(columnDfn, "Retail", 70, SbmDbDfn.ColumnIdx.CommodityCustomer_CurrencyIdRetail, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
break;
|
|
case SbmCommodityCustomer.Column.CurrencyIdRetail_Code:
|
|
SetCommodityCustomerColDfn(columnDfn, "Currency", 70, SbmDbDfn.ColumnIdx.Currency_Code, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_CurrencyRetail, prefixCommodityCustomer_CurrencyRetail);
|
|
break;
|
|
case SbmCommodityCustomer.Column.CurrencyIdRetail_Symbol:
|
|
SetCommodityCustomerColDfn(columnDfn, "Currency", 70, SbmDbDfn.ColumnIdx.Currency_Symbol, ColumnAlignment.Default, DataValue.DataType.String, aliasCommodityCustomer_CurrencyRetail, prefixCommodityCustomer_CurrencyRetail);
|
|
break;
|
|
case SbmCommodityCustomer.Column.PromotionCode:
|
|
SetCommodityCustomerColDfn(columnDfn, "Promotion", 100, SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode);
|
|
break;
|
|
case SbmCommodityCustomer.Column.PromotionDesc:
|
|
SetCommodityCustomerColDfn(columnDfn, "Promotion", 100, SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode);
|
|
break;
|
|
|
|
// Common properties.
|
|
case SbmCommodityCustomer.Column.Notes:
|
|
SetCommodityCustomerColDfn(columnDfn, "Notes", 200, SbmDbDfn.ColumnIdx.CommodityCustomer_Notes);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Status:
|
|
SetCommodityCustomerColDfn(columnDfn, "Status", 75, SbmDbDfn.ColumnIdx.CommodityCustomer_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Status_Desc:
|
|
SetCommodityCustomerColDfn(columnDfn, "Status", 75, SbmDbDfn.ColumnIdx.CommodityCustomer_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SbmCommodityCustomer.Column.Status_Ind:
|
|
SetCommodityCustomerColDfn(columnDfn, "Status", 75, SbmDbDfn.ColumnIdx.CommodityCustomer_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
|
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
|
break;
|
|
case SbmCommodityCustomer.Column.CreateOn_Date:
|
|
SetCommodityCustomerColDfn(columnDfn, "Created", 65, SbmDbDfn.ColumnIdx.CommodityCustomer_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SbmCommodityCustomer.Column.UpdateOn_Date:
|
|
SetCommodityCustomerColDfn(columnDfn, "Updated", 65, SbmDbDfn.ColumnIdx.CommodityCustomer_UpdateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
}
|
|
if (!String.IsNullOrEmpty(caption))
|
|
columnDfn.Caption = caption;
|
|
if (width > 0)
|
|
columnDfn.Width = width;
|
|
return columnDfn;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// CommodityCustomer query filter.
|
|
public override List<string> GetCommodityCustomerQueryFilter(SbmCommodityCustomer.Params prm)
|
|
{
|
|
List<String> filter = new List<String>();
|
|
|
|
//CommodityCustomer Id.
|
|
String includedIds = prm.IncludedIds.Concat(",");
|
|
if (!includedIds.IsEmpty())
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer) + " IN (" + includedIds + ")");
|
|
String excludedIds = prm.ExcludedIds.Concat(",");
|
|
if (!excludedIds.IsEmpty())
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer) + " NOT IN (" + excludedIds + ")");
|
|
|
|
//---------------------------------------------------------------
|
|
// Type.
|
|
|
|
if (SysId.IsValid(prm.CommodityId))
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer, false) + "=" + prm.CommodityId.ToString());
|
|
if (SysId.IsValid(prm.AssocIdCustomer))
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, aliasCommodityCustomer, false) + "=" + prm.AssocIdCustomer.ToString());
|
|
|
|
// CommodityPartial.
|
|
if (!StringUtil.IsEmpty(prm.CommodityPartial))
|
|
{
|
|
bool cmdTableInQuery = !aliasCommodityCustomer_Commodity.IsEmpty();
|
|
if (aliasCommodityCustomer_Commodity.IsEmpty()) aliasCommodityCustomer_Commodity = "cctaCmd";
|
|
List<String> filtersCommodity = new List<String>();
|
|
filtersCommodity.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Commodity_Id, aliasCommodityCustomer_Commodity, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer, false));
|
|
filtersCommodity.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Commodity_Code, aliasCommodityCustomer_Commodity, false) + " LIKE '" + DbQuery.FormatForLike(prm.CommodityPartial) + "%' OR " + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Commodity_DescBrief, aliasCommodityCustomer_Commodity, false) + " LIKE '" + DbQuery.FormatForLike(prm.CommodityPartial) + "%'");
|
|
if (cmdTableInQuery)
|
|
filter.AddRange(filtersCommodity);// Commodity table is included in the query so filter it directly.
|
|
else
|
|
{
|
|
DbQuery qry = new DbQuery(db.DbmsType);
|
|
qry.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity), aliasCommodityCustomer_Commodity);
|
|
qry.Columns.Add("1");
|
|
qry.Filters.AddRange(filtersCommodity);
|
|
filter.Add("EXISTS (" + qry.BuildQuery() + ")");
|
|
}
|
|
}
|
|
// CustomerPartial.
|
|
if (!StringUtil.IsEmpty(prm.CustomerPartial))
|
|
{
|
|
DbQuery qry = new DbQuery(db.DbmsType);
|
|
qry.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Association), aliasCommodityCustomer_Association);
|
|
qry.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate), aliasCommodityCustomer_Affiliate);
|
|
qry.Columns.Add("1");
|
|
qry.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Affiliate_Id, aliasCommodityCustomer_Affiliate, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_AffIdTarget, aliasCommodityCustomer_Association, false));
|
|
qry.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_Id, aliasCommodityCustomer_Association, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, aliasCommodityCustomer, false));
|
|
qry.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_Code, aliasCommodityCustomer_Association, false) + " LIKE '" + DbQuery.FormatForLike(prm.CustomerPartial) + "%' OR " + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Affiliate_Name, aliasCommodityCustomer_Association, false) + " LIKE '" + DbQuery.FormatForLike(prm.CustomerPartial) + "%'");
|
|
filter.Add("EXISTS (" + qry.BuildQuery() + ")");
|
|
}
|
|
|
|
// ProductCode.
|
|
if (!StringUtil.IsEmpty(prm.ProductCode))
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode, aliasCommodityCustomer, false) + "='" + DbQuery.FormatForCondition(prm.ProductCode) + "'");
|
|
else if (!StringUtil.IsEmpty(prm.ProductCodePartial))
|
|
filter.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode, aliasCommodityCustomer, false) + " LIKE '" + DbQuery.FormatForLike(prm.ProductCodePartial) + "%'");
|
|
|
|
if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1");
|
|
return filter;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Sort columns.
|
|
public List<String> GetCommodityCustomerSortColumns(SbmCommodityCustomer.Params prm)
|
|
{
|
|
// Sort sequence:
|
|
List<String> sortColumnNames = new List<String>();
|
|
foreach (var columnDfn in prm.SortColumns)
|
|
{
|
|
// Need to ensure correct alias used for CommodityCustomer columns in case of conflict.
|
|
String sortCol = String.Empty;
|
|
if (SbmDbDfn.GetTableForColumn((SbmDbDfn.ColumnIdx)columnDfn.DbColumn) == SbmDbDfn.TableIdx.CommodityCustomer)
|
|
{
|
|
sortCol = SbmDbDfn.GetColumnNameQual((SbmDbDfn.ColumnIdx)columnDfn.DbColumn, aliasCommodityCustomer);
|
|
}
|
|
else
|
|
{
|
|
sortCol = columnDfn.DataName;
|
|
if (!StringUtil.IsEmpty(columnDfn.SortDataName))
|
|
sortCol = columnDfn.SortDataName;
|
|
}
|
|
if (!sortCol.IsEmpty())
|
|
{
|
|
DbOrderByNullMode orderByNullMode = DbOrderByNullMode.Default; // eSaOrderByDemoteNulls, eSaOrderByPromoteNulls
|
|
sortColumnNames.Add(DbQuery.FormatForOrderBy(sortCol, columnDfn.SortAscending, orderByNullMode).Concat(", "));
|
|
}
|
|
}
|
|
sortColumnNames.RemoveBlanks();
|
|
if (sortColumnNames.IsEmpty())
|
|
{
|
|
// Default sort columns:
|
|
sortColumnNames.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode, aliasCommodityCustomer) + " ASC");
|
|
}
|
|
return sortColumnNames;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item count.
|
|
private long GetCommodityCustomerCount(String filter)
|
|
{
|
|
ClearErrorState();
|
|
return db.GetRowCount(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer) + " As " + aliasCommodityCustomer, filter);
|
|
}
|
|
public override long GetCommodityCustomerCount(SbmCommodityCustomer.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetCommodityCustomerCount(GetCommodityCustomerQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item list.
|
|
public override List<SbmCommodityCustomer> GetCommodityCustomerList(SbmCommodityCustomer.Params prm)
|
|
{
|
|
List<SbmCommodityCustomer> CommodityCustomeres = new List<SbmCommodityCustomer>();
|
|
DbQuery qry = new DbQuery(db.DbmsType);
|
|
qry.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer), aliasCommodityCustomer);
|
|
CommodityCustomer_Db dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
qry.Columns.AddRange(dbCommodityCustomer.ExistingColumnNames);
|
|
qry.Filters.AddRange(GetCommodityCustomerQueryFilter(prm));
|
|
qry.OrderBy.AddRange(GetCommodityCustomerSortColumns(prm));
|
|
// Query data.
|
|
using (var dbConnection = db.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging);
|
|
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
|
{
|
|
while (dbDataReader.Read())
|
|
{
|
|
dbCommodityCustomer = new CommodityCustomer_Db(DbInfo);
|
|
dbCommodityCustomer.PopulateFrom(dbDataReader);
|
|
CommodityCustomeres.Add(CreateCommodityCustomer(dbCommodityCustomer));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(GetType().Name + ".GetCommodityCustomerList\n\tQuery: " + dbCommand.CommandText + "\n\tException: " + exc.Message);
|
|
}
|
|
}
|
|
return CommodityCustomeres;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Execute query.
|
|
public override DbResultSet ExecuteCommodityCustomerQuery(List<ColumnDfn> columns, SbmCommodityCustomer.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
|
|
//---------------------------------------------------------------
|
|
// Construct query.
|
|
DbQuery query = new DbQuery(db.DbmsType);
|
|
query.Tables.Add(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.CommodityCustomer), aliasCommodityCustomer);
|
|
|
|
//---------------------------------------------------------------
|
|
// CommodityCustomer Properties - add columns as defined in query list.
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer, false));
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, aliasCommodityCustomer, false));
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_ProductCode, aliasCommodityCustomer, false));
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AmountRetail, aliasCommodityCustomer, false));
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CurrencyIdRetail, aliasCommodityCustomer, false));
|
|
if (ColumnExists(SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_PromotionCode, aliasCommodityCustomer, false));
|
|
|
|
//---------------------------------------------------------------
|
|
// Commodity.
|
|
bool hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_Code);
|
|
if (!hasCommodityCols) hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_DescBrief);
|
|
if (!hasCommodityCols) hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_Status);
|
|
if (!hasCommodityCols) hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_StatusDesc);
|
|
if (!hasCommodityCols) hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_CategoryCode);
|
|
if (!hasCommodityCols) hasCommodityCols = columns.HasId((int)SbmCommodityCustomer.Column.Commodity_CategoryDesc);
|
|
if (hasCommodityCols)
|
|
{
|
|
// Join to the commodity.
|
|
DbQueryJoin joinCmd = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinCmd.Table = new StringPair(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Commodity), aliasCommodityCustomer_Commodity);
|
|
joinCmd.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Commodity_Id, aliasCommodityCustomer_Commodity, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CommodityId, aliasCommodityCustomer, false));
|
|
query.Joins.Add(joinCmd);
|
|
// Data columns to return.
|
|
List<SbmDbDfn.ColumnIdx> commodityCols = new List<SbmDbDfn.ColumnIdx>()
|
|
{
|
|
SbmDbDfn.ColumnIdx.Commodity_Code,
|
|
SbmDbDfn.ColumnIdx.Commodity_DescBrief,
|
|
SbmDbDfn.ColumnIdx.Commodity_Category,
|
|
SbmDbDfn.ColumnIdx.Commodity_Status,
|
|
};
|
|
foreach (SbmDbDfn.ColumnIdx dbColumn in commodityCols)
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(dbColumn, aliasCommodityCustomer_Commodity), prefixCommodityCustomer_Commodity + SbmDbDfn.GetColumnName(dbColumn, false));
|
|
}
|
|
//---------------------------------------------------------------
|
|
// Customer with Association.
|
|
bool hasCustomerCols = columns.HasId((int)SbmCommodityCustomer.Column.Customer_Code);
|
|
if (!hasCustomerCols) hasCustomerCols = columns.HasId((int)SbmCommodityCustomer.Column.Customer_Name);
|
|
if (hasCustomerCols)
|
|
{
|
|
// Join to the Customer Association.
|
|
DbQueryJoin joinAssoc = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinAssoc.Table = new StringPair(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Association), aliasCommodityCustomer_Association);
|
|
joinAssoc.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_Id, aliasCommodityCustomer_Association, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_AssocIdCustomer, aliasCommodityCustomer, false));
|
|
query.Joins.Add(joinAssoc);
|
|
// Join to the Customer Affiliate.
|
|
DbQueryJoin joinAffil = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinAffil.Table = new StringPair(SbmDbDfn.GetTableName(SbmDbDfn.TableIdx.Affiliate), aliasCommodityCustomer_Affiliate);
|
|
joinAffil.Filters.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Affiliate_Id, aliasCommodityCustomer_Affiliate, false) + "=" + SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_AffIdTarget, aliasCommodityCustomer_Association, false));
|
|
query.Joins.Add(joinAffil);
|
|
// Data columns to return.
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Association_Code, aliasCommodityCustomer_Association, false), prefixCommodityCustomer_Association + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Association_Code, false));
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.Affiliate_Name, aliasCommodityCustomer_Affiliate, false), prefixCommodityCustomer_Affiliate + SbmDbDfn.GetColumnName(SbmDbDfn.ColumnIdx.Affiliate_Name, false));
|
|
}
|
|
|
|
// Common Properties
|
|
if (columns.HasId((int)SbmCommodityCustomer.Column.Notes))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_Notes, aliasCommodityCustomer));
|
|
if (columns.HasId((int)SbmCommodityCustomer.Column.Status) || columns.HasId((int)SbmCommodityCustomer.Column.Status_Desc) || columns.HasId((int)SbmCommodityCustomer.Column.Status_Ind))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_Status, aliasCommodityCustomer));
|
|
if (columns.HasId((int)SbmCommodityCustomer.Column.CreateOn_Date))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_CreateOn, aliasCommodityCustomer));
|
|
if (columns.HasId((int)SbmCommodityCustomer.Column.UpdateOn_Date))
|
|
query.Columns.Add(SbmDbDfn.GetColumnNameQual(SbmDbDfn.ColumnIdx.CommodityCustomer_UpdateOn, aliasCommodityCustomer));
|
|
|
|
//---------------------------------------------------------------
|
|
// Populate filter.
|
|
query.Filters.AddRange(GetCommodityCustomerQueryFilter(prm));
|
|
|
|
if (prm.IncludedIds.Count != 1)
|
|
{
|
|
// Configure sort sequence.
|
|
foreach (String sortColumn in GetCommodityCustomerSortColumns(prm))
|
|
query.OrderBy.Add(sortColumn);
|
|
}
|
|
|
|
//---------------------------------------------------------------
|
|
//return new DbResultSet_DataTableReader(db, query.BuildQuery());
|
|
return DbResultSet_DataReader.ExecuteQuery(db, query.BuildQuery(prm.ResultsPaging));
|
|
}
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|