721 lines
38 KiB
C#
721 lines
38 KiB
C#
using Sarand.Net.Standard.Dbas.Data;
|
|
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 Saxonite.Base.App;
|
|
using Saxonite.Net.Standard.Dbas.Bus;
|
|
using Saxonite.Net.Standard.Dbas.Internal;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Text;
|
|
using Sarand.Net.Standard.Base.Utils;
|
|
using System.Linq;
|
|
using Saxonite.Net.Standard.Dbas.Internal.Core;
|
|
|
|
namespace Saxonite.Net.Standard.Dbas.Mgr
|
|
{
|
|
//=======================================================================
|
|
partial class SaxActivityMgr_Dbas
|
|
{
|
|
//*******************************************************************
|
|
// Activity Mgr - Organisation Event
|
|
//*******************************************************************
|
|
// Utilities.
|
|
private List<StringPair> GetLogProperties(SaxOrganisationEvent organisationEvent)
|
|
{
|
|
return new List<StringPair>()
|
|
{
|
|
new StringPair("Id", SysId.ToString(organisationEvent.Id)),
|
|
new StringPair("OrganisationId", SysId.ToString(organisationEvent.OrganisationId)),
|
|
new StringPair("Event at", DateUtil.Format(organisationEvent.EventAt, "d-MMM-yyyy HH:mm")),
|
|
new StringPair("Event type", EventTypeCodes.GetDescForType(organisationEvent.EventType)),
|
|
new StringPair("Status", organisationEvent.StatusCode)
|
|
};
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override SaxOrganisationEvent CreateOrganisationEvent(SysId userAccountIdJournalist)
|
|
{
|
|
ClearErrorState();
|
|
return new SaxOrganisationEvent_Dbas(CoreDatabase, null, userAccountIdJournalist, 0);
|
|
}
|
|
private SaxOrganisationEvent_Dbas CreateOrganisationEvent(OrganisationEvent_Db dbOrganisationEvent)
|
|
{
|
|
ClearErrorState();
|
|
SaxOrganisationEvent_Dbas organisationEvent = new SaxOrganisationEvent_Dbas(CoreDatabase, new SysId(dbOrganisationEvent._Id), new SysId(dbOrganisationEvent._OrganisationId), (UInt16)dbOrganisationEvent._Flags);
|
|
PopulateFrom(dbOrganisationEvent, organisationEvent);
|
|
return organisationEvent;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get item.
|
|
public override SaxOrganisationEvent GetOrganisationEvent(SaxOrganisationEvent.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetOrganisationEvent(GetOrganisationEventQueryFilter(prm).Concat(" And ", "(", ")"));
|
|
}
|
|
private SaxOrganisationEvent GetOrganisationEvent(String filter)
|
|
{
|
|
ClearErrorState();
|
|
long count = GetOrganisationEventCount(filter);
|
|
if (count == 0) return null;
|
|
if (count != 1)
|
|
{
|
|
SetErrorState("Multiple items found");
|
|
return null;
|
|
}
|
|
SaxOrganisationEvent organisationEvent = null;
|
|
// Query data.
|
|
using (var dbConnection = CoreDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, filter);
|
|
organisationEvent = CreateOrganisationEvent(dbOrganisationEvent);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SetErrorState("Database query exception");
|
|
SaLogger.Warn(GetType().Name + ".GetOrganisationEvent\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
|
|
}
|
|
}
|
|
return organisationEvent;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate item.
|
|
public override bool IsValidOrganisationEventData(SaxOrganisationEvent.Data data, SaxOrganisationEvent.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.IsValidOrganisationEventData(data, errField)) return false;
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Insert item.
|
|
public override bool InsertOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".InsertOrganisationEvent";
|
|
ClearErrorState();
|
|
if (!IsValidOrganisationEvent(organisationEvent)) return false;
|
|
if (SysId.IsValid(organisationEvent.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
|
using (var dbConnection = CoreDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
PopulateTo(dbOrganisationEvent, organisationEvent, dbUpdateInfo);
|
|
if (OrganisationEvent_Db.FieldsNonId.Contains("Id"))
|
|
{
|
|
// Generate next Id.
|
|
// ToDo dbOrganisationEvent._Id = CoreDatabase.GetNextIdFromTable("OrganisationEvent");
|
|
}
|
|
dbOrganisationEvent.ExecuteInsertCommand(dbCommand);
|
|
organisationEvent.Id = new SysId(dbOrganisationEvent._Id);
|
|
organisationEvent.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update item.
|
|
public override bool UpdateOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".UpdateOrganisationEvent";
|
|
ClearErrorState();
|
|
if (!IsValidOrganisationEvent(organisationEvent)) return false;
|
|
if (!SysId.IsValid(organisationEvent.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
|
if (!organisationEvent.Changed)
|
|
{
|
|
if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t"));
|
|
return true;
|
|
}
|
|
using (var dbConnection = CoreDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve item.
|
|
dbConnection.Open();
|
|
OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, "Id=" + SysId.ToString(organisationEvent.Id));
|
|
// ToDo SaxUpdateLogItemMonitor_OrganisationEvent updateLogMonitor = new SaxUpdateLogItemMonitor_OrganisationEvent(SessionContext, CreateOrganisationEvent(dbOrganisationEvent), dbUpdateInfo);
|
|
// Update item.
|
|
PopulateTo(dbOrganisationEvent, organisationEvent, dbUpdateInfo);
|
|
dbOrganisationEvent.ExecuteUpdateCommand(dbCommand);
|
|
organisationEvent.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t"));
|
|
// Record updates.
|
|
// ToDo updateLogMonitor.RecordUpdatedValues(organisationEvent);
|
|
// ToDo updateLogMonitor.LogUpdates();
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool OrganisationEventCanBeDeleted(SaxOrganisationEvent organisationEvent)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.OrganisationEventCanBeDeleted(organisationEvent)) return false;
|
|
return true;
|
|
}
|
|
public override bool DeleteOrganisationEvent(SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".DeleteOrganisationEvent";
|
|
ClearErrorState();
|
|
if (!OrganisationEventCanBeDeleted(organisationEvent)) return false;
|
|
|
|
// Organisation Events are logically deleted by changing the status.
|
|
organisationEvent.Status = SaStatus.Deleted;
|
|
return UpdateOrganisationEvent(organisationEvent, dbUpdateInfo);
|
|
|
|
/*
|
|
* Physical deletion.
|
|
using (var dbConnection = CoreDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve item.
|
|
dbConnection.Open();
|
|
OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
dbOrganisationEvent.PopulateFrom(dbCommand, aliasOrganisationEvent, "Id=" + organisationEvent.Id.ToString());
|
|
// Delete item.
|
|
dbCommand.CommandType = System.Data.CommandType.Text;
|
|
dbCommand.CommandText = "DELETE FROM " + SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent) + " WHERE Id=" + SysId.ToString(organisationEvent.Id) + ";";
|
|
dbCommand.ExecuteNonQuery();
|
|
organisationEvent.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(organisationEvent).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
*/
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Copy data properties to and from database.
|
|
private void PopulateTo(OrganisationEvent_Db dbOrganisationEvent, SaxOrganisationEvent organisationEvent, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
dbOrganisationEvent._Id = SysId.ToInt(organisationEvent.Id);
|
|
dbOrganisationEvent._OrganisationId = SysId.ToInt(organisationEvent.OrganisationId);
|
|
dbOrganisationEvent._SportIdPrimary = SysId.ToInt(organisationEvent.SportIdPrimary);
|
|
dbOrganisationEvent._RegionIdCountry = SysId.ToInt(organisationEvent.RegionIdCountry);
|
|
dbOrganisationEvent._EventAt = organisationEvent.EventAt;
|
|
dbOrganisationEvent._EventTypeCode = EventTypeCodes.GetCodeForType(organisationEvent.EventType);
|
|
dbOrganisationEvent._Summary = organisationEvent.Summary;
|
|
dbOrganisationEvent._Details = organisationEvent.Details;
|
|
dbOrganisationEvent._EventData = organisationEvent.EventData;
|
|
dbOrganisationEvent._PublishedAt = organisationEvent.PublishedAt;
|
|
dbOrganisationEvent._ExpiresAt = organisationEvent.ExpiresAt;
|
|
dbOrganisationEvent._Notes = organisationEvent.Notes;
|
|
dbOrganisationEvent._Status = SacsSystem.GetStatusCode(organisationEvent.Status);
|
|
dbOrganisationEvent._Flags = (short)organisationEvent.Flags;
|
|
if (!SysId.IsValid(organisationEvent.Id))
|
|
{
|
|
dbOrganisationEvent._CreateOn = DateTime.Now;
|
|
dbOrganisationEvent._CreateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbOrganisationEvent._CreateHost = dbUpdateInfo.Host;
|
|
}
|
|
dbOrganisationEvent._UpdateOn = DateTime.Now;
|
|
dbOrganisationEvent._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbOrganisationEvent._UpdateHost = dbUpdateInfo.Host;
|
|
}
|
|
private void PopulateFrom(OrganisationEvent_Db dbOrganisationEvent, SaxOrganisationEvent organisationEvent)
|
|
{
|
|
//organisationEvent.Id = new SysId(dbOrganisationEvent._Id);
|
|
//organisationEvent.OrganisationId = new SysId(dbOrganisationEvent._OrganisationId);
|
|
organisationEvent.SportIdPrimary = new SysId(dbOrganisationEvent._SportIdPrimary);
|
|
organisationEvent.RegionIdCountry = new SysId(dbOrganisationEvent._RegionIdCountry);
|
|
organisationEvent.EventAt = dbOrganisationEvent._EventAt;
|
|
organisationEvent.EventType = (Sax.EventType)EventTypeCodes.GetTypeForCode(dbOrganisationEvent._EventTypeCode);
|
|
organisationEvent.Summary = dbOrganisationEvent._Summary;
|
|
organisationEvent.Details = dbOrganisationEvent._Details;
|
|
organisationEvent.EventData = dbOrganisationEvent._EventData;
|
|
organisationEvent.PublishedAt = dbOrganisationEvent._PublishedAt;
|
|
organisationEvent.ExpiresAt = dbOrganisationEvent._ExpiresAt;
|
|
organisationEvent.Notes = dbOrganisationEvent._Notes;
|
|
organisationEvent.Status = SacsSystem.GetStatusForCode(dbOrganisationEvent._Status);
|
|
organisationEvent.SetCreateStamp(dbOrganisationEvent._CreateOn, new SysId(dbOrganisationEvent._CreateBy), dbOrganisationEvent._CreateHost);
|
|
organisationEvent.SetUpdateStamp(dbOrganisationEvent._UpdateOn, new SysId(dbOrganisationEvent._UpdateBy), dbOrganisationEvent._UpdateHost);
|
|
organisationEvent.AcceptChanges();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item column definitions.
|
|
private static readonly String aliasOrganisationEvent = "OrgEvt";
|
|
private static readonly String aliasOrganisationEvent_Organisation = "OrgEvt_Org";
|
|
private static readonly String prefixOrganisationEvent_Organisation = aliasOrganisationEvent_Organisation + "_";
|
|
private static readonly String colOrganisationEvent_OrganisationOwner_LogoCount = "OrgEvt_Org_LogoCount";
|
|
private static readonly String aliasOrganisationEvent_Organisation_UserOrganisation = "OrgEvt_Org_UsrOrg";
|
|
private static readonly String aliasOrganisationEvent_Sport = "OrgEvt_Spt";
|
|
private static readonly String prefixOrganisationEvent_Sport = aliasOrganisationEvent_Sport + "_";
|
|
private static readonly String aliasOrganisationEvent_Region = "OrgEvt_Rgn";
|
|
private static readonly String prefixOrganisationEvent_Region = aliasOrganisationEvent_Region + "_";
|
|
private void SetOrganisationEventColDfn
|
|
(ColumnDfn col, String caption, int width, SaxDbDfn_Core.ColumnIdx dbCol,
|
|
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
|
String alias = "", String prefix = "")
|
|
{
|
|
if (String.IsNullOrEmpty(alias) && SaxDbDfn_Core.GetTableForColumn(dbCol) == SaxDbDfn_Core.TableIdx.OrganisationEvent)
|
|
alias = aliasOrganisationEvent;
|
|
col.Set(caption, width, (int)dbCol, prefix + SaxDbDfn_Core.GetColumnName(dbCol, false), SaxDbDfn_Core.GetColumnNameQual(dbCol, alias), dataType, align);
|
|
if (dataType == DataValue.DataType.String && dbCol != SaxDbDfn_Core.ColumnIdx.Unknown)
|
|
col.MaxLength = (int)SaxDbDfn_Core.GetColTextLen(dbCol);
|
|
}
|
|
public override ColumnDfn GetOrganisationEventColumnDfn(SaxOrganisationEvent.Column columnId, string caption = "", int width = 0)
|
|
{
|
|
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
|
switch (columnId)
|
|
{
|
|
//-----------------------------------------------------------
|
|
case SaxOrganisationEvent.Column.Pos:
|
|
SetOrganisationEventColDfn(columnDfn, "Pos", 60, SaxDbDfn_Core.ColumnIdx.Unknown, ColumnAlignment.Right);
|
|
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
|
columnDfn.ReadOnly = true;
|
|
columnDfn.Resizable = false;
|
|
break;
|
|
case SaxOrganisationEvent.Column.Id:
|
|
SetOrganisationEventColDfn(columnDfn, "Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Organisation.
|
|
case SaxOrganisationEvent.Column.OrganisationId:
|
|
SetOrganisationEventColDfn(columnDfn, "Organisation Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.Organisation_Name:
|
|
SetOrganisationEventColDfn(columnDfn, "Organisation", 160, SaxDbDfn_Core.ColumnIdx.Organisation_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Organisation, prefixOrganisationEvent_Organisation);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.Organisation_LogoCount:
|
|
SetActivityIndexColDfn(columnDfn, "Organisation Logos", 100, SaxDbDfn_Core.ColumnIdx.Unknown, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.DataName = colOrganisationEvent_OrganisationOwner_LogoCount;
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Sport.
|
|
case SaxOrganisationEvent.Column.SportIdPrimary:
|
|
SetOrganisationEventColDfn(columnDfn, "Sport Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.Sport_Name:
|
|
SetOrganisationEventColDfn(columnDfn, "Sport", 100, SaxDbDfn_Core.ColumnIdx.Sport_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Sport, prefixOrganisationEvent_Sport);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Region.
|
|
case SaxOrganisationEvent.Column.RegionIdCountry:
|
|
SetOrganisationEventColDfn(columnDfn, "Region Id", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.Region_Name:
|
|
SetOrganisationEventColDfn(columnDfn, "Region", 100, SaxDbDfn_Core.ColumnIdx.Region_Name, ColumnAlignment.Left, DataValue.DataType.String, aliasOrganisationEvent_Region, prefixOrganisationEvent_Region);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Event.
|
|
case SaxOrganisationEvent.Column.EventAt_Date:
|
|
SetOrganisationEventColDfn(columnDfn, "Event", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.EventAt_DateTime:
|
|
SetOrganisationEventColDfn(columnDfn, "Event", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, ColumnAlignment.Center, DataValue.DataType.DateTime);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.EventTypeCode:
|
|
SetOrganisationEventColDfn(columnDfn, "Type", 90, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, ColumnAlignment.Center);
|
|
break;
|
|
case SaxOrganisationEvent.Column.EventType_Desc:
|
|
SetOrganisationEventColDfn(columnDfn, "Type", 120, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, ColumnAlignment.Center);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Summary:
|
|
SetOrganisationEventColDfn(columnDfn, "Summary", 200, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Details:
|
|
SetOrganisationEventColDfn(columnDfn, "Details", 200, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Details);
|
|
break;
|
|
case SaxOrganisationEvent.Column.PublishedAt_Date:
|
|
SetOrganisationEventColDfn(columnDfn, "Published", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.PublishedAt_DateTime:
|
|
SetOrganisationEventColDfn(columnDfn, "Published", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, ColumnAlignment.Center, DataValue.DataType.DateTime);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.ExpiresAt_Date:
|
|
SetOrganisationEventColDfn(columnDfn, "Expires", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.ExpiresAt_DateTime:
|
|
SetOrganisationEventColDfn(columnDfn, "Expires", 100, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, ColumnAlignment.Center, DataValue.DataType.DateTime);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Derived properties.
|
|
|
|
//-----------------------------------------------------------
|
|
// Common properties.
|
|
case SaxOrganisationEvent.Column.Notes:
|
|
SetOrganisationEventColDfn(columnDfn, "Notes", 240, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Flags:
|
|
SetOrganisationEventColDfn(columnDfn, "Flags", 60, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Flags, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Status:
|
|
SetOrganisationEventColDfn(columnDfn, "Status", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Status_Desc:
|
|
SetOrganisationEventColDfn(columnDfn, "Status", 90, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SaxOrganisationEvent.Column.Status_Ind:
|
|
SetOrganisationEventColDfn(columnDfn, "Status", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
|
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
|
break;
|
|
case SaxOrganisationEvent.Column.CreateOn_Date:
|
|
SetOrganisationEventColDfn(columnDfn, "Created", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxOrganisationEvent.Column.UpdateOn_Date:
|
|
SetOrganisationEventColDfn(columnDfn, "Updated", 80, SaxDbDfn_Core.ColumnIdx.OrganisationEvent_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;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item query filter.
|
|
public override List<string> GetOrganisationEventQueryFilter(SaxOrganisationEvent.Params prm)
|
|
{
|
|
List<String> filter = new List<String>();
|
|
|
|
// Item Ids.
|
|
String idsIncluded = prm.IdsIncluded.Concat(",");
|
|
if (!idsIncluded.IsEmpty())
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " IN (" + idsIncluded + ")");
|
|
String idsExcluded = prm.IdsExcluded.Concat(",");
|
|
if (!idsExcluded.IsEmpty())
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " NOT IN (" + idsExcluded + ")");
|
|
|
|
// User Account Ids.
|
|
String userAccountIdsIncluded = prm.UserAccountIdsIncluded.Concat(",");
|
|
if (!userAccountIdsIncluded.IsEmpty())
|
|
{
|
|
// User Organisation.
|
|
if (!StringUtil.IsEmpty(prm.Alias_UserOrganisation))
|
|
{
|
|
// Filter directly on the joined User Organisation table.
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_UserAccountId, prm.Alias_UserOrganisation) + " IN (" + userAccountIdsIncluded + ")");
|
|
}
|
|
else
|
|
{
|
|
// User Organisation query.
|
|
String alias_UserOrganisation = aliasOrganisationEvent_Organisation_UserOrganisation;
|
|
DbQuery queryUserOrganisation = new DbQuery(CoreDatabase.DbmsType);
|
|
queryUserOrganisation.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.UserOrganisation), alias_UserOrganisation);
|
|
queryUserOrganisation.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_UserAccountId, alias_UserOrganisation) + " IN (" + userAccountIdsIncluded + ")");
|
|
|
|
// Filter Organisation directly against the Organisation Event.
|
|
queryUserOrganisation.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.UserOrganisation_OrganisationId, alias_UserOrganisation));
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent) + " IN (" + queryUserOrganisation.BuildQuery() + ")");
|
|
}
|
|
}
|
|
|
|
// Organisation Ids.
|
|
String organisationIdsIncluded = prm.OrganisationIdsIncluded.Concat(",");
|
|
if (!organisationIdsIncluded.IsEmpty())
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent) + " IN (" + organisationIdsIncluded + ")");
|
|
|
|
// Sport Ids.
|
|
String sportIdsIncluded = prm.SportIdsIncluded.Concat(",");
|
|
if (!sportIdsIncluded.IsEmpty())
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent) + " IN (" + sportIdsIncluded + ")");
|
|
|
|
// Region Ids.
|
|
String regionIdsIncluded = prm.RegionIdsIncluded.Concat(",");
|
|
if (!regionIdsIncluded.IsEmpty())
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent) + " IN (" + regionIdsIncluded + ")");
|
|
|
|
// Summary.
|
|
if (!StringUtil.IsEmpty(prm.SummaryPartial))
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary, aliasOrganisationEvent) + " Like '%" + DbQuery.FormatForLike(prm.SummaryPartial, true) + "%'");
|
|
|
|
// Event filter.
|
|
if (!StringUtil.IsEmpty(prm.EventFilter))
|
|
{
|
|
// Split filter into words.
|
|
List<String> filterWords = prm.EventFilter.Split((char[])null).ToList();
|
|
filterWords.RemoveDuplicatesCI();
|
|
filterWords.RemoveBlanks();
|
|
foreach (String filterWord in filterWords)
|
|
{
|
|
List<String> articleFilter = new List<String>();
|
|
articleFilter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary, aliasOrganisationEvent) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'");
|
|
articleFilter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Details, aliasOrganisationEvent) + " Like '%" + DbQuery.FormatForLike(filterWord, true) + "%'");
|
|
filter.Add(articleFilter.Concat(" OR ", "(", ")"));
|
|
}
|
|
}
|
|
|
|
// Notes.
|
|
if (!StringUtil.IsEmpty(prm.NotesPartial))
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes, aliasOrganisationEvent) + " LIKE '%" + DbQuery.FormatForLike(prm.NotesPartial) + "%'");
|
|
|
|
// Status.
|
|
if (prm.StatusCat != SaxOrganisationEvent.StatusCat.Any)
|
|
filter.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, aliasOrganisationEvent) + GetOrganisationEventStatusCatFilterCondition(prm.StatusCat));
|
|
|
|
if (filter.Count < 1) filter.Add("1=1");
|
|
return filter;
|
|
}
|
|
internal static String GetOrganisationEventStatusCatFilterCondition(SaxOrganisationEvent.StatusCat statusCat)
|
|
{
|
|
if (statusCat == SaxOrganisationEvent.StatusCat.ActiveOnly)
|
|
return "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'";
|
|
if (statusCat == SaxOrganisationEvent.StatusCat.InactiveOnly)
|
|
return "='" + SacsSystem.GetStatusCode(SaStatus.Inactive) + "'";
|
|
if (statusCat == SaxOrganisationEvent.StatusCat.NotDeleted)
|
|
return "!='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'";
|
|
if (statusCat == SaxOrganisationEvent.StatusCat.DeletedOnly)
|
|
return "='" + SacsSystem.GetStatusCode(SaStatus.Deleted) + "'";
|
|
return "";
|
|
}
|
|
// Item sort columns.
|
|
public List<String> GetOrganisationEventSortColumns(SaxOrganisationEvent.Params prm)
|
|
{
|
|
// Sort sequence:
|
|
List<String> sortColumnNames = new List<String>();
|
|
foreach (var columnDfn in prm.SortColumns)
|
|
{
|
|
// Need to ensure correct alias used for OrganisationEvent columns in case of conflict.
|
|
String sortCol = String.Empty;
|
|
if (SaxDbDfn_Core.GetTableForColumn((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn) == SaxDbDfn_Core.TableIdx.OrganisationEvent)
|
|
{
|
|
sortCol = SaxDbDfn_Core.GetColumnNameQual((SaxDbDfn_Core.ColumnIdx)columnDfn.DbColumn, aliasOrganisationEvent);
|
|
}
|
|
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(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent) + " ASC");
|
|
}
|
|
return sortColumnNames;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item count.
|
|
private long GetOrganisationEventCount(String filter)
|
|
{
|
|
ClearErrorState();
|
|
return CoreDatabase.GetRowCount(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent) + " As " + aliasOrganisationEvent, filter);
|
|
}
|
|
public override long GetOrganisationEventCount(SaxOrganisationEvent.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetOrganisationEventCount(GetOrganisationEventQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item list.
|
|
public override List<SaxOrganisationEvent> GetOrganisationEventList(SaxOrganisationEvent.Params prm)
|
|
{
|
|
List<SaxOrganisationEvent> userActivitys = new List<SaxOrganisationEvent>();
|
|
DbQuery qry = new DbQuery(CoreDatabase.DbmsType);
|
|
qry.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent), aliasOrganisationEvent);
|
|
OrganisationEvent_Db dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
qry.Columns.AddRange(dbOrganisationEvent.ExistingColumnNames);
|
|
qry.Filters.AddRange(GetOrganisationEventQueryFilter(prm));
|
|
qry.OrderBy.AddRange(GetOrganisationEventSortColumns(prm));
|
|
// Query data.
|
|
using (var dbConnection = CoreDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging);
|
|
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
|
{
|
|
while (dbDataReader.Read())
|
|
{
|
|
dbOrganisationEvent = new OrganisationEvent_Db(CoreDbInfo);
|
|
dbOrganisationEvent.PopulateFrom(dbDataReader);
|
|
userActivitys.Add(CreateOrganisationEvent(dbOrganisationEvent));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(GetType().Name + ".GetOrganisationEventList\n\tQuery: " + dbCommand.CommandText + "\n\t" + ExceptionUtil.GetLogMessage(exc));
|
|
}
|
|
}
|
|
return userActivitys;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item query execution.
|
|
public override DbResultSet ExecuteOrganisationEventQuery(List<ColumnDfn> columns, SaxOrganisationEvent.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
|
|
//---------------------------------------------------------------------
|
|
// Construct query.
|
|
DbQuery query = new DbQuery(CoreDatabase.DbmsType);
|
|
query.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.OrganisationEvent), aliasOrganisationEvent);
|
|
|
|
// Add columns as defined in query list.
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Id))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Id, aliasOrganisationEvent));
|
|
bool hasOrganisationCols = (columns.HasId(SaxOrganisationEvent.Column.Organisation_Name));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.OrganisationId) || hasOrganisationCols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent));
|
|
bool hasSportCols = (columns.HasId(SaxOrganisationEvent.Column.Sport_Name));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.SportIdPrimary) || hasSportCols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent));
|
|
bool hasRegionCols = (columns.HasId(SaxOrganisationEvent.Column.Region_Name));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.RegionIdCountry) || hasRegionCols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.EventAt_Date) || columns.HasId(SaxOrganisationEvent.Column.EventAt_DateTime))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventAt, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.EventTypeCode) || columns.HasId(SaxOrganisationEvent.Column.EventType_Desc))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_EventTypeCode, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Summary))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Summary, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Details))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Details, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.PublishedAt_Date) || columns.HasId(SaxOrganisationEvent.Column.PublishedAt_DateTime))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_PublishedAt, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.ExpiresAt_Date) || columns.HasId(SaxOrganisationEvent.Column.ExpiresAt_DateTime))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_ExpiresAt, aliasOrganisationEvent));
|
|
// Common properties.
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Notes))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Notes, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Flags))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Flags, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Status) || columns.HasId(SaxOrganisationEvent.Column.Status_Desc) || columns.HasId(SaxOrganisationEvent.Column.Status_Ind))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_Status, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.CreateOn_Date))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_CreateOn, aliasOrganisationEvent));
|
|
if (columns.HasId(SaxOrganisationEvent.Column.UpdateOn_Date))
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_UpdateOn, aliasOrganisationEvent));
|
|
|
|
//---------------------------------------------------------------------
|
|
// Organisation.
|
|
if (hasOrganisationCols)
|
|
{
|
|
DbQueryJoin joinOrganisation = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinOrganisation.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Organisation), aliasOrganisationEvent_Organisation);
|
|
joinOrganisation.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Organisation_Id, aliasOrganisationEvent_Organisation) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent));
|
|
query.Joins.Add(joinOrganisation);
|
|
List<SaxDbDfn_Core.ColumnIdx> cols = new List<SaxDbDfn_Core.ColumnIdx>();
|
|
cols.Add(SaxDbDfn_Core.ColumnIdx.Organisation_Name);
|
|
foreach (var col in cols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Organisation), prefixOrganisationEvent_Organisation + SaxDbDfn_Core.GetColumnName(col, false));
|
|
prm.Alias_Organisation = aliasOrganisationEvent_Organisation;
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
// Organisation Logo Image Count.
|
|
if (columns.HasId(SaxOrganisationEvent.Column.Organisation_LogoCount))
|
|
{
|
|
String aliasLogoCount = "aImg_Logo";
|
|
DbQuery queryLogoCount = new DbQuery(CoreDatabase.DbmsType);
|
|
queryLogoCount.Tables.Add(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.ItemImage), aliasLogoCount);
|
|
queryLogoCount.Columns.Add("Count(*)");
|
|
queryLogoCount.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.ItemImage_ItemType, aliasLogoCount) + "=" + (int)Sax.DataItemType.Organisation);
|
|
queryLogoCount.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.ItemImage_ItemId, aliasLogoCount) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_OrganisationId, aliasOrganisationEvent));
|
|
queryLogoCount.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.ItemImage_ImageType, aliasLogoCount) + "=" + (int)Sax.ImageType.OrganisationLogo);
|
|
queryLogoCount.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.ItemImage_Status, aliasLogoCount) + "='" + SacsSystem.GetStatusCode(SaStatus.Active) + "'");
|
|
// Construct sub-query.
|
|
query.Columns.Add("(" + queryLogoCount.BuildQuery() + ")", colOrganisationEvent_OrganisationOwner_LogoCount);
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
// Primary Sport.
|
|
if (hasSportCols)
|
|
{
|
|
DbQueryJoin joinSport = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinSport.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Sport), aliasOrganisationEvent_Sport);
|
|
joinSport.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Sport_Id, aliasOrganisationEvent_Sport) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_SportIdPrimary, aliasOrganisationEvent));
|
|
query.Joins.Add(joinSport);
|
|
List<SaxDbDfn_Core.ColumnIdx> cols = new List<SaxDbDfn_Core.ColumnIdx>();
|
|
cols.Add(SaxDbDfn_Core.ColumnIdx.Sport_Name);
|
|
foreach (var col in cols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Sport), prefixOrganisationEvent_Sport + SaxDbDfn_Core.GetColumnName(col, false));
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
// Primary Region.
|
|
if (hasRegionCols)
|
|
{
|
|
DbQueryJoin joinRegion = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinRegion.Table = new StringPair(SaxDbDfn_Core.GetTableName(SaxDbDfn_Core.TableIdx.Region), aliasOrganisationEvent_Region);
|
|
joinRegion.Filters.Add(SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.Region_Id, aliasOrganisationEvent_Region) + "=" + SaxDbDfn_Core.GetColumnNameQual(SaxDbDfn_Core.ColumnIdx.OrganisationEvent_RegionIdCountry, aliasOrganisationEvent));
|
|
query.Joins.Add(joinRegion);
|
|
List<SaxDbDfn_Core.ColumnIdx> cols = new List<SaxDbDfn_Core.ColumnIdx>();
|
|
cols.Add(SaxDbDfn_Core.ColumnIdx.Region_Name);
|
|
foreach (var col in cols)
|
|
query.Columns.Add(SaxDbDfn_Core.GetColumnNameQual(col, aliasOrganisationEvent_Region), prefixOrganisationEvent_Region + SaxDbDfn_Core.GetColumnName(col, false));
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
// Populate filter.
|
|
query.Filters.AddRange(GetOrganisationEventQueryFilter(prm));
|
|
|
|
if (prm.IdsIncluded.Count != 1)
|
|
{
|
|
// Configure sort sequence.
|
|
foreach (String sortColumn in GetOrganisationEventSortColumns(prm))
|
|
query.OrderBy.Add(sortColumn);
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
//return new DbResultSet_DataTableReader(db, query.BuildQuery(prm.ResultsPaging));
|
|
return DbResultSet_DataReader.ExecuteQuery(CoreDatabase, query.BuildQuery(prm.ResultsPaging));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|