730 lines
37 KiB
C#
730 lines
37 KiB
C#
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 Saxonite.Base.App;
|
|
using Saxonite.Net.Standard.Base.App;
|
|
using Saxonite.Net.Standard.Base.Bus;
|
|
using Saxonite.Net.Standard.Base.Bus.Reference;
|
|
using Saxonite.Net.Standard.Dbas.Bus.Reference;
|
|
using Saxonite.Net.Standard.Dbas.Internal.Reference;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
|
|
namespace Saxonite.Net.Standard.Dbas.Mgr.Reference
|
|
{
|
|
//=======================================================================
|
|
partial class SaxReferenceGolfMgr_Dbas
|
|
{
|
|
//*******************************************************************
|
|
// Support Mgr - User Report
|
|
//*******************************************************************
|
|
// Utilities.
|
|
private List<StringPair> GetLogProperties(SaxGolfUsgaMarker usgaMarker)
|
|
{
|
|
return new List<StringPair>()
|
|
{
|
|
new StringPair("Id",SysId.ToString(usgaMarker.Id)),
|
|
new StringPair("CourseId",SysId.ToString(usgaMarker.CourseId)),
|
|
new StringPair("UsgaMarkerId",SysId.ToString(usgaMarker.UsgaMarkerId)),
|
|
new StringPair("Caption",usgaMarker.Caption),
|
|
new StringPair("Status",usgaMarker.StatusCode)
|
|
};
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Create item.
|
|
public override SaxGolfUsgaMarker CreateUsgaMarker(SysId courseId)
|
|
{
|
|
ClearErrorState();
|
|
return new SaxGolfUsgaMarker_Dbas(ReferenceDatabase, null, courseId, 0);
|
|
}
|
|
private SaxGolfUsgaMarker_Dbas CreateUsgaMarker(Golf_UsgaMarker_Db dbUsgaMarker)
|
|
{
|
|
ClearErrorState();
|
|
SaxGolfUsgaMarker_Dbas usgaMarker = new SaxGolfUsgaMarker_Dbas(ReferenceDatabase, new SysId(dbUsgaMarker._Id), new SysId(dbUsgaMarker._CourseId), (ushort)dbUsgaMarker._Flags);
|
|
PopulateFrom(dbUsgaMarker, usgaMarker);
|
|
return usgaMarker;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Get item.
|
|
public override SaxGolfUsgaMarker GetUsgaMarker(SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetUsgaMarker(GetUsgaMarkerQueryFilter(prm).Concat(" And ", "(", ")"));
|
|
}
|
|
private SaxGolfUsgaMarker GetUsgaMarker(String filter)
|
|
{
|
|
ClearErrorState();
|
|
long count = GetUsgaMarkerCount(filter);
|
|
if (count == 0) return null;
|
|
if (count != 1)
|
|
{
|
|
SetErrorState("Multiple items found");
|
|
return null;
|
|
}
|
|
SaxGolfUsgaMarker usgaMarker = null;
|
|
// Query data.
|
|
using (var dbConnection = ReferenceDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
Golf_UsgaMarker_Db dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
dbUsgaMarker.PopulateFrom(dbCommand, aliasUsgaMarker, filter);
|
|
usgaMarker = CreateUsgaMarker(dbUsgaMarker);
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SetErrorState("Database query exception");
|
|
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
|
|
}
|
|
}
|
|
return usgaMarker;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Validate item.
|
|
public override bool IsValidUsgaMarkerData(SaxGolfUsgaMarker.Data data, SaxGolfUsgaMarker.ErrField errField)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.IsValidUsgaMarkerData(data, errField)) return false;
|
|
return true;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Insert item.
|
|
public override bool InsertUsgaMarker(SaxGolfUsgaMarker usgaMarker, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".InsertUsgaMarker";
|
|
ClearErrorState();
|
|
if (!IsValidUsgaMarker(usgaMarker)) return false;
|
|
if (SysId.IsValid(usgaMarker.Id)) return SetErrorState(ErrorMessage.ValiditemId);
|
|
using (var dbConnection = ReferenceDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
Golf_UsgaMarker_Db dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
PopulateTo(dbUsgaMarker, usgaMarker, dbUpdateInfo);
|
|
if (Golf_UsgaMarker_Db.FieldsNonId.Contains("Id"))
|
|
{
|
|
// Generate next Id.
|
|
dbUsgaMarker._Id = ReferenceDatabase.GetNextIdFromTable("UsgaMarker");
|
|
}
|
|
dbUsgaMarker.ExecuteInsertCommand(dbCommand);
|
|
usgaMarker.Id = new SysId(dbUsgaMarker._Id);
|
|
usgaMarker.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Inserted. " + GetLogProperties(usgaMarker).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Update item.
|
|
public override bool UpdateUsgaMarker(SaxGolfUsgaMarker usgaMarker, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".UpdateUsgaMarker";
|
|
ClearErrorState();
|
|
if (!IsValidUsgaMarker(usgaMarker)) return false;
|
|
if (!SysId.IsValid(usgaMarker.Id)) return SetErrorState(ErrorMessage.InvalidItemId);
|
|
if (!usgaMarker.Changed)
|
|
{
|
|
if (DebugMode) SaLogger.Debug(fn + " Data not changed. " + GetLogProperties(usgaMarker).Concat(": ").Concat("", "\n\t"));
|
|
return true;
|
|
}
|
|
using (var dbConnection = ReferenceDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve item.
|
|
dbConnection.Open();
|
|
Golf_UsgaMarker_Db dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
dbUsgaMarker.PopulateFrom(dbCommand, aliasUsgaMarker, "Id=" + SysId.ToString(usgaMarker.Id));
|
|
// ToDo SaxUpdateLogItemMonitor_UsgaMarker updateLogMonitor = new SaxUpdateLogItemMonitor_UsgaMarker(SessionContext, CreateUsgaMarker(dbUsgaMarker), dbUpdateInfo);
|
|
// Update item.
|
|
PopulateTo(dbUsgaMarker, usgaMarker, dbUpdateInfo);
|
|
dbUsgaMarker.ExecuteUpdateCommand(dbCommand);
|
|
usgaMarker.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Updated. " + GetLogProperties(usgaMarker).Concat(": ").Concat("", "\n\t"));
|
|
// Record updates.
|
|
// ToDo updateLogMonitor.RecordUpdatedValues(usgaMarker);
|
|
// ToDo updateLogMonitor.LogUpdates();
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Delete item.
|
|
public override bool UsgaMarkerCanBeDeleted(SaxGolfUsgaMarker usgaMarker)
|
|
{
|
|
ClearErrorState();
|
|
if (!base.UsgaMarkerCanBeDeleted(usgaMarker)) return false;
|
|
return true;
|
|
}
|
|
public override bool DeleteUsgaMarker(SaxGolfUsgaMarker usgaMarker, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
String fn = GetType().Name + ".DeleteUsgaMarker";
|
|
ClearErrorState();
|
|
if (!UsgaMarkerCanBeDeleted(usgaMarker)) return false;
|
|
|
|
// User Roles are logically deleted by changing the status.
|
|
usgaMarker.Status = SaStatus.Deleted;
|
|
return UpdateUsgaMarker(usgaMarker, dbUpdateInfo);
|
|
|
|
/*
|
|
* Physical deletion.
|
|
using (var dbConnection = ReferenceDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
// Retrieve item.
|
|
dbConnection.Open();
|
|
Golf_UsgaMarker_Db dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
dbUsgaMarker.PopulateFrom(dbCommand, aliasUsgaMarker, "Id=" + usgaMarker.Id.ToString());
|
|
// Delete item.
|
|
dbCommand.CommandType = System.Data.CommandType.Text;
|
|
dbCommand.CommandText = "DELETE FROM " + SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker) + " WHERE Id=" + SysId.ToString(usgaMarker.Id) + ";";
|
|
dbCommand.ExecuteNonQuery();
|
|
usgaMarker.Changed = false;
|
|
if (DebugMode) SaLogger.Debug(fn + " Deleted. " + GetLogProperties(usgaMarker).Concat(": ").Concat("", "\n\t"));
|
|
}
|
|
catch (Exception exc) { SetErrorState(exc.Message); }
|
|
}
|
|
return !HasErrorState();
|
|
*/
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Copy data properties to and from database.
|
|
private void PopulateTo(Golf_UsgaMarker_Db dbUsgaMarker, SaxGolfUsgaMarker usgaMarker, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
dbUsgaMarker._Id = SysId.ToLong(usgaMarker.Id);
|
|
dbUsgaMarker._CourseId = SysId.ToInt(usgaMarker.CourseId);
|
|
dbUsgaMarker._UsgaMarkerId = SysId.ToInt(usgaMarker.UsgaMarkerId);
|
|
dbUsgaMarker._Caption = usgaMarker.Caption;
|
|
dbUsgaMarker._Holes = usgaMarker.Holes;
|
|
dbUsgaMarker._HolesCaption = usgaMarker.HolesCaption;
|
|
dbUsgaMarker._Tee = usgaMarker.Tee;
|
|
dbUsgaMarker._Gender = usgaMarker.Gender;
|
|
dbUsgaMarker._SlopeRating = usgaMarker.SlopeRating;
|
|
dbUsgaMarker._Par = usgaMarker.Par;
|
|
dbUsgaMarker._CourseRating = usgaMarker.CourseRating;
|
|
dbUsgaMarker._BogeyRating = usgaMarker.BogeyRating;
|
|
dbUsgaMarker._Length = usgaMarker.Length;
|
|
// Common.
|
|
dbUsgaMarker._Notes = usgaMarker.Notes;
|
|
dbUsgaMarker._Status = SacsSystem.GetStatusCode(usgaMarker.Status);
|
|
dbUsgaMarker._Flags = (short)usgaMarker.Flags;
|
|
if (!SysId.IsValid(usgaMarker.Id))
|
|
{
|
|
dbUsgaMarker._CreateOn = DateTime.Now;
|
|
dbUsgaMarker._CreateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbUsgaMarker._CreateHost = dbUpdateInfo.Host;
|
|
}
|
|
dbUsgaMarker._UpdateOn = DateTime.Now;
|
|
dbUsgaMarker._UpdateBy = dbUpdateInfo.UserId.ToInt();
|
|
dbUsgaMarker._UpdateHost = dbUpdateInfo.Host;
|
|
}
|
|
private void PopulateFrom(Golf_UsgaMarker_Db dbUsgaMarker, SaxGolfUsgaMarker usgaMarker)
|
|
{
|
|
//usgaMarker.Id = new SysId(dbUsgaMarker._Id);
|
|
usgaMarker.CourseId = new SysId(dbUsgaMarker._CourseId);
|
|
usgaMarker.UsgaMarkerId = new SysId(dbUsgaMarker._UsgaMarkerId);
|
|
usgaMarker.Caption = dbUsgaMarker._Caption;
|
|
usgaMarker.Holes = dbUsgaMarker._Holes;
|
|
usgaMarker.HolesCaption = dbUsgaMarker._HolesCaption;
|
|
usgaMarker.Tee = dbUsgaMarker._Tee;
|
|
usgaMarker.Gender = dbUsgaMarker._Gender;
|
|
usgaMarker.SlopeRating = dbUsgaMarker._SlopeRating;
|
|
usgaMarker.Par = dbUsgaMarker._Par;
|
|
usgaMarker.CourseRating = dbUsgaMarker._CourseRating;
|
|
usgaMarker.BogeyRating = dbUsgaMarker._BogeyRating;
|
|
usgaMarker.Length = dbUsgaMarker._Length;
|
|
// Common.
|
|
usgaMarker.Notes = dbUsgaMarker._Notes;
|
|
usgaMarker.Status = SacsSystem.GetStatusForCode(dbUsgaMarker._Status);
|
|
usgaMarker.SetCreateStamp(dbUsgaMarker._CreateOn, new SysId(dbUsgaMarker._CreateBy), dbUsgaMarker._CreateHost);
|
|
usgaMarker.SetUpdateStamp(dbUsgaMarker._UpdateOn, new SysId(dbUsgaMarker._UpdateBy), dbUsgaMarker._UpdateHost);
|
|
usgaMarker.AcceptChanges();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Bulk updates.
|
|
/// <summary>
|
|
/// Bulk update USGA Markers.
|
|
/// <para>- Course Id must be supplied to identify parent.</para>
|
|
/// <para>- Marker Id must be supplied to act as identifier.</para>
|
|
/// <para>- Other properties are validated as per marker rules - check error state.</para>
|
|
/// <para>- Other properties are left as is if null.</para>
|
|
/// </summary>
|
|
public override bool BulkUpdateUsgaMarkers(List<UsgaMarkerData> markers, DbUpdateInfo dbUpdateInfo)
|
|
{
|
|
ClearErrorState();
|
|
List<UsgaMarkerData> markersToUpdate = new List<UsgaMarkerData>();
|
|
|
|
// Validate supplied data.
|
|
foreach (UsgaMarkerData marker in markers)
|
|
{
|
|
// Validate marker properties.
|
|
// Course and Marker Codes are mandatory, other values only validated if non-null.
|
|
if (!SysId.IsValid(marker.UsgaCourseId)) return SetErrorState("USGA Course Id must be supplied");
|
|
// 9 hole markers missing Id: if (!SysId.IsValid(marker.UsgaMarkerId)) return SetErrorState("USGA Marker Id must be supplied");
|
|
if (marker.Caption != null && !IsValidValue(marker.HolesCaption, "caption", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption))) return false;
|
|
if (marker.Holes < 1) return SetErrorState("Holes must be supplied");
|
|
if (marker.HolesCaption != null && !IsValidValue(marker.HolesCaption, "holes caption", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption), true)) return false;
|
|
if (marker.Tee != null && !IsValidValue(marker.Tee, "tee", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee), true)) return false;
|
|
if (marker.Gender != null && !IsValidValue(marker.Gender, "gender", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender))) return false;
|
|
if (marker.SlopeRating < 1) return SetErrorState("Slope rating must be supplied");
|
|
if (marker.Par < 1) return SetErrorState("Par must be supplied");
|
|
if (marker.CourseRating < 1) return SetErrorState("Course rating must be supplied");
|
|
markersToUpdate.Add(marker);
|
|
}
|
|
int MaxBulkUpdateBatchSize = 64;
|
|
int batchSize = markersToUpdate.Any() ? (int)Math.Ceiling(markersToUpdate.Count() / Math.Ceiling((double)markersToUpdate.Count() / MaxBulkUpdateBatchSize)) : MaxBulkUpdateBatchSize;
|
|
while (markersToUpdate.Any())
|
|
{
|
|
List<String> query = new List<string>();
|
|
query.Add($"Declare @statusActive VarChar(3) = '{SacsSystem.GetStatusCode(SaxGolfUsgaMarker.DefaultStatus)}';");
|
|
query.Add($"Declare @updateOn DateTime = GetDate();");
|
|
query.Add($"Declare @updateBy Int = {SysId.ToLong(dbUpdateInfo.UserId)};");
|
|
query.Add($"Declare @updateHost VarChar(100) = '{DbQuery.FormatForCondition(dbUpdateInfo.Host)}';");
|
|
query.Add("Merge");
|
|
query.Add($"Into {SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker)} uMkr");
|
|
query.Add("Using");
|
|
query.Add("(");
|
|
query.Add("Select uCrs.Id CourseId, dMkr.UsgaCourseId, dMkr.UsgaMarkerId, dMkr.Caption, dMkr.Holes, dMkr.HolesCaption, dMkr.Tee, dMkr.Gender, dMkr.SlopeRating, dMkr.Par, dMkr.CourseRating, dMkr.BogeyRating, dMkr.Length");
|
|
query.Add("From");
|
|
query.Add("(");
|
|
query.Add("Select 0 UsgaCourseId, 0 UsgaMarkerId, '' Caption, 0 Holes, '' HolesCaption, '' Tee, '' Gender, 0 SlopeRating, 0 Par, 0 CourseRating, 0 BogeyRating, 0 Length");
|
|
foreach (UsgaMarkerData marker in markersToUpdate.ExtractRange(0, batchSize))
|
|
query.Add($"Union Select {marker.UsgaCourseId},{StringUtil.OnBlank(SysId.ToString(marker.UsgaMarkerId), "0")}," +
|
|
(marker.Caption != null ? $"'{DbQuery.FormatForCondition(marker.Caption)}'" : "Null") + "," +
|
|
$"{marker.Holes}," +
|
|
(marker.HolesCaption != null ? $"'{DbQuery.FormatForCondition(marker.HolesCaption)}'" : "Null") + "," +
|
|
(marker.Tee != null ? $"'{DbQuery.FormatForCondition(marker.Tee)}'" : "Null") + "," +
|
|
(marker.Gender != null ? $"'{DbQuery.FormatForCondition(marker.Gender)}'" : "Null") + "," +
|
|
$"{marker.SlopeRating}," +
|
|
$"{marker.Par}," +
|
|
$"{marker.CourseRating}," +
|
|
(marker.BogeyRating > 0 ? $"{marker.BogeyRating}" : "Null") + "," +
|
|
(marker.Length > 0 ? $"{marker.Length}" : "Null"));
|
|
query.Add(") dMkr");
|
|
query.Add($"Inner Join {SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaCourse)} uCrs On uCrs.UsgaCourseId=dMkr.UsgaCourseId");
|
|
query.Add(") dMkr");
|
|
// Want to use UsgaMarkerId to identify the Marker alongside the CourseId, but only 18 hole markers have an Id value.
|
|
// Use alternative identifiers for now: Holes Caption, Tee and Gender.
|
|
// Was: query.Add("On uMkr.CourseId=dMkr.CourseId And uMkr.UsgaMarkerId=dMkr.UsgaMarkerId");
|
|
query.Add("On uMkr.CourseId=dMkr.CourseId And uMkr.HolesCaption=dMkr.HolesCaption And uMkr.Tee=dMkr.Tee And uMkr.Gender=Coalesce(dMkr.Gender,'')");
|
|
query.Add("When Matched And ((dMkr.Caption Is Not Null And uMkr.Caption!=dMkr.Caption) Or (uMkr.Holes!=dMkr.Holes) Or (dMkr.HolesCaption Is Not Null And uMkr.HolesCaption!=dMkr.HolesCaption) Or (dMkr.Tee Is Not Null And uMkr.Tee!=dMkr.Tee) Or (dMkr.Gender Is Not Null And uMkr.Gender!=dMkr.Gender) Or (uMkr.SlopeRating!=dMkr.SlopeRating) Or (uMkr.Par!=dMkr.Par) Or (uMkr.CourseRating!=dMkr.CourseRating) Or (dMkr.BogeyRating Is Not Null And uMkr.BogeyRating!=dMkr.BogeyRating) Or (dMkr.Length Is Not Null And uMkr.Length!=dMkr.Length) Or uMkr.Status!=@statusActive)");
|
|
query.Add("Then Update Set");
|
|
query.Add(" Caption=Coalesce(dMkr.Caption,uMkr.Caption),");
|
|
query.Add(" Holes=Coalesce(dMkr.Holes,uMkr.Holes),");
|
|
query.Add(" HolesCaption=Coalesce(dMkr.HolesCaption,uMkr.HolesCaption),");
|
|
query.Add(" Tee=Coalesce(dMkr.Tee,uMkr.Tee),");
|
|
query.Add(" Gender=Coalesce(dMkr.Gender,uMkr.Gender),");
|
|
query.Add(" SlopeRating=Coalesce(dMkr.SlopeRating,uMkr.SlopeRating),");
|
|
query.Add(" Par=Coalesce(dMkr.Par,uMkr.Par),");
|
|
query.Add(" CourseRating=Coalesce(dMkr.CourseRating,uMkr.CourseRating),");
|
|
query.Add(" BogeyRating=Coalesce(dMkr.BogeyRating,uMkr.BogeyRating),");
|
|
query.Add(" Length=Coalesce(dMkr.Length,uMkr.Length),");
|
|
query.Add(" Status=@statusActive,");
|
|
query.Add(" UpdateOn=@updateOn,");
|
|
query.Add(" UpdateBy=@updateBy,");
|
|
query.Add(" UpdateHost=@updateHost");
|
|
query.Add("When Not Matched And Len(Coalesce(dMkr.Caption,''))>0 And dMkr.Holes>0 And dMkr.SlopeRating>0 And dMkr.Par>0 And dMkr.CourseRating>0");
|
|
query.Add("Then Insert (CourseId,UsgaMarkerId,Caption,Holes,HolesCaption,Tee,Gender,SlopeRating,Par,CourseRating,BogeyRating,Length,Notes,Flags,Status,CreateOn,CreateBy,CreateHost,UpdateOn,UpdateBy,UpdateHost)");
|
|
query.Add($"Values (dMkr.CourseId,dMkr.UsgaMarkerId,Coalesce(dMkr.Caption,''),dMkr.Holes,Coalesce(dMkr.HolesCaption,''),Coalesce(dMkr.Tee,''),Coalesce(dMkr.Gender,''),Coalesce(dMkr.SlopeRating,''),Coalesce(dMkr.Par,''),Coalesce(dMkr.CourseRating,''),Coalesce(dMkr.BogeyRating,''),Coalesce(dMkr.Length,''),'',0,@statusActive,@updateOn,@updateBy,@updateHost,@updateOn,@updateBy,@updateHost)");
|
|
query.Add(";");
|
|
//SaLogger.Info($"{SysUtil.Fn} Bulk USGA Marker update query:\n\t{query.Concat("\n\t")}");
|
|
|
|
try
|
|
{
|
|
int result = ReferenceDatabase.ExecuteNonQuery(query.Concat("\n"));
|
|
if (ReferenceDatabase.HasErrorState())
|
|
SaLogger.Warn($"{SysUtil.Fn} Error executing bulk USGA Marker update - {ReferenceDatabase.ErrorStateMessage}");
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SaLogger.Warn(SysUtil.Fn + " " + ExceptionUtil.GetLogMessage(exc, " executing bulk USGA Marker update"));
|
|
}
|
|
}
|
|
return HasErrorState();
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item column definitions.
|
|
private static readonly String aliasUsgaMarker = "UsgMkr";
|
|
private static readonly String aliasUsgaMarker_Course = "UsgMkr_Cty";
|
|
private static readonly String prefixUsgaMarker_Course = aliasUsgaMarker_Course + "_";
|
|
private void SetUsgaMarkerColDfn
|
|
(ColumnDfn col, String caption, int width, SaxDbDfn_Reference.ColumnIdx dbCol,
|
|
ColumnAlignment align = ColumnAlignment.Default, DataValue.DataType dataType = DataValue.DataType.String,
|
|
String alias = "", String prefix = "")
|
|
{
|
|
if (String.IsNullOrEmpty(alias) && SaxDbDfn_Reference.GetTableForColumn(dbCol) == SaxDbDfn_Reference.TableIdx.UsgaMarker)
|
|
alias = aliasUsgaMarker;
|
|
col.Set(caption, width, (int)dbCol, prefix + SaxDbDfn_Reference.GetColumnName(dbCol, false), SaxDbDfn_Reference.GetColumnNameQual(dbCol, alias), dataType, align);
|
|
if (dataType == DataValue.DataType.String && dbCol != SaxDbDfn_Reference.ColumnIdx.Unknown)
|
|
col.MaxLength = (int)SaxDbDfn_Reference.GetColTextLen(dbCol);
|
|
}
|
|
public override ColumnDfn GetUsgaMarkerColumnDfn(SaxGolfUsgaMarker.Column columnId, string caption = "", int width = 0)
|
|
{
|
|
ColumnDfn columnDfn = new ColumnDfn((int)columnId, caption, width);
|
|
switch (columnId)
|
|
{
|
|
//-----------------------------------------------------------
|
|
case SaxGolfUsgaMarker.Column.Pos:
|
|
SetUsgaMarkerColDfn(columnDfn, "Pos", 60, SaxDbDfn_Reference.ColumnIdx.Unknown, ColumnAlignment.Right);
|
|
columnDfn.SortMode = ColumnDfn.ColumnSortMode.Off;
|
|
columnDfn.ReadOnly = true;
|
|
columnDfn.Resizable = false;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Id:
|
|
SetUsgaMarkerColDfn(columnDfn, "Id", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, ColumnAlignment.Right, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-------------------------------------------------------
|
|
case SaxGolfUsgaMarker.Column.CourseId:
|
|
SetUsgaMarkerColDfn(columnDfn, "Course #", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Course_Name:
|
|
SetUsgaMarkerColDfn(columnDfn, "Course", 120, SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName, ColumnAlignment.Center, DataValue.DataType.String, aliasUsgaMarker_Course, prefixUsgaMarker_Course);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-------------------------------------------------------
|
|
case SaxGolfUsgaMarker.Column.UsgaMarkerId:
|
|
SetUsgaMarkerColDfn(columnDfn, "Id", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_UsgaMarkerId, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Caption:
|
|
SetUsgaMarkerColDfn(columnDfn, "Caption", 160, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Caption);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Holes:
|
|
SetUsgaMarkerColDfn(columnDfn, "Holes", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Holes, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.HolesCaption:
|
|
SetUsgaMarkerColDfn(columnDfn, "Holes", 100, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption, ColumnAlignment.Center);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Tee:
|
|
SetUsgaMarkerColDfn(columnDfn, "Tee", 100, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee, ColumnAlignment.Center);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Gender:
|
|
SetUsgaMarkerColDfn(columnDfn, "Gender", 100, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, ColumnAlignment.Center);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.SlopeRating:
|
|
SetUsgaMarkerColDfn(columnDfn, "Slope Rating", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_SlopeRating, ColumnAlignment.Center, DataValue.DataType.Decimal);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Par:
|
|
SetUsgaMarkerColDfn(columnDfn, "Par", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Par, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.CourseRating:
|
|
SetUsgaMarkerColDfn(columnDfn, "Course Rating", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseRating, ColumnAlignment.Center, DataValue.DataType.Decimal);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.BogeyRating:
|
|
SetUsgaMarkerColDfn(columnDfn, "Bogey Rating", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_BogeyRating, ColumnAlignment.Center, DataValue.DataType.Decimal);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Length:
|
|
SetUsgaMarkerColDfn(columnDfn, "Length", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Length, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
|
|
//-----------------------------------------------------------
|
|
// Derived properties.
|
|
|
|
//-----------------------------------------------------------
|
|
// Common properties.
|
|
case SaxGolfUsgaMarker.Column.Notes:
|
|
SetUsgaMarkerColDfn(columnDfn, "Notes", 240, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Notes);
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Flags:
|
|
SetUsgaMarkerColDfn(columnDfn, "Flags", 60, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Flags, ColumnAlignment.Center, DataValue.DataType.Long);
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Status:
|
|
SetUsgaMarkerColDfn(columnDfn, "Status", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Status_Desc:
|
|
SetUsgaMarkerColDfn(columnDfn, "Status", 90, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, ColumnAlignment.Center);
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.Status_Ind:
|
|
SetUsgaMarkerColDfn(columnDfn, "Status", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, ColumnAlignment.Center, DataValue.DataType.TriState);
|
|
columnDfn.TriStateFormat = ColumnTriStateFormat.Lights;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.CreateOn_Date:
|
|
SetUsgaMarkerColDfn(columnDfn, "Created", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CreateOn, ColumnAlignment.Center, DataValue.DataType.Date);
|
|
columnDfn.ReadOnly = true;
|
|
break;
|
|
case SaxGolfUsgaMarker.Column.UpdateOn_Date:
|
|
SetUsgaMarkerColDfn(columnDfn, "Updated", 80, SaxDbDfn_Reference.ColumnIdx.UsgaMarker_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> GetUsgaMarkerQueryFilter(SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
List<String> filter = new List<String>();
|
|
String col_Id = SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker);
|
|
|
|
// Item Ids.
|
|
if (prm.IdsIncluded.HasValidIds())
|
|
filter.Add($"{col_Id} IN ({prm.IdsIncluded.Concat(",")})");
|
|
if (prm.IdsExcluded.HasValidIds())
|
|
filter.Add($"{col_Id} NOT IN ({prm.IdsExcluded.Concat(",")})");
|
|
|
|
// Courses.
|
|
if (prm.CourseIdsIncluded.HasValidIds())
|
|
filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, aliasUsgaMarker)} IN ({prm.CourseIdsIncluded.Concat(",")})");
|
|
|
|
if (!StringUtil.IsBlank(prm.MarkerFilter))
|
|
{
|
|
// Split filter into words.
|
|
List<String> filterWords = prm.MarkerFilter.Split((char[])null).ToList();
|
|
filterWords.RemoveDuplicatesCI();
|
|
filterWords.RemoveBlanks();
|
|
foreach (String filterWord in filterWords)
|
|
{
|
|
List<String> markerFilter = new List<String>();
|
|
markerFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Caption, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'");
|
|
markerFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'");
|
|
markerFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'");
|
|
markerFilter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, aliasUsgaMarker)} Like '%{DbQuery.FormatForLike(filterWord, true)}%'");
|
|
filter.Add(markerFilter.Concat(" OR ", "(", ")"));
|
|
}
|
|
}
|
|
|
|
// Marker properties.
|
|
if (prm.Holes > 0)
|
|
filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Holes, aliasUsgaMarker)}={prm.Holes}");
|
|
if (!StringUtil.IsEmpty(prm.Gender))
|
|
filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, aliasUsgaMarker)}='{DbQuery.FormatForLike(prm.Gender)}'");
|
|
|
|
// Notes.
|
|
if (!StringUtil.IsEmpty(prm.NotesPartial))
|
|
filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Notes, aliasUsgaMarker)} LIKE '%{DbQuery.FormatForLike(prm.NotesPartial)}%'");
|
|
|
|
// Status.
|
|
if (prm.StatusCat != SaxGolfUsgaMarker.StatusCat.Any)
|
|
filter.Add($"{SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, aliasUsgaMarker)} {GetUsgaMarkerStatusCatFilterCondition(prm.StatusCat)}");
|
|
|
|
if (filter.Count < 1 && prm.IncludeDefaultFilter) filter.Add("1=1");
|
|
return filter;
|
|
}
|
|
internal static String GetUsgaMarkerStatusCatFilterCondition(SaxGolfUsgaMarker.StatusCat statusCat)
|
|
{
|
|
if (statusCat == SaxGolfUsgaMarker.StatusCat.ActiveOnly)
|
|
return $"='{SacsSystem.GetStatusCode(SaStatus.Active)}'";
|
|
if (statusCat == SaxGolfUsgaMarker.StatusCat.InactiveOnly)
|
|
return $"='{SacsSystem.GetStatusCode(SaStatus.Inactive)}'";
|
|
if (statusCat == SaxGolfUsgaMarker.StatusCat.NotDeleted)
|
|
return $"!='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'";
|
|
if (statusCat == SaxGolfUsgaMarker.StatusCat.DeletedOnly)
|
|
return $"='{SacsSystem.GetStatusCode(SaStatus.Deleted)}'";
|
|
return "";
|
|
}
|
|
// Item sort columns.
|
|
public List<String> GetUsgaMarkerSortColumns(SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
// Sort sequence:
|
|
List<String> sortColumnNames = new List<String>();
|
|
foreach (var columnDfn in prm.SortColumns)
|
|
{
|
|
// Need to ensure correct alias used for UsgaMarker columns in case of conflict.
|
|
String sortCol = String.Empty;
|
|
if (SaxDbDfn_Reference.GetTableForColumn((SaxDbDfn_Reference.ColumnIdx)columnDfn.DbColumn) == SaxDbDfn_Reference.TableIdx.UsgaMarker)
|
|
{
|
|
sortCol = SaxDbDfn_Reference.GetColumnNameQual((SaxDbDfn_Reference.ColumnIdx)columnDfn.DbColumn, aliasUsgaMarker);
|
|
}
|
|
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_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker) + " ASC");
|
|
}
|
|
return sortColumnNames;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item count.
|
|
private long GetUsgaMarkerCount(String filter)
|
|
{
|
|
ClearErrorState();
|
|
return ReferenceDatabase.GetRowCount(SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker) + " As " + aliasUsgaMarker, filter);
|
|
}
|
|
public override long GetUsgaMarkerCount(SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
return GetUsgaMarkerCount(GetUsgaMarkerQueryFilter(prm).Concat(" AND ", "(", ")"));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item list.
|
|
public override List<SaxGolfUsgaMarker> GetUsgaMarkerList(SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
List<SaxGolfUsgaMarker> userRoles = new List<SaxGolfUsgaMarker>();
|
|
DbQuery qry = new DbQuery(ReferenceDatabase.DbmsType);
|
|
qry.Tables.Add(SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker), aliasUsgaMarker);
|
|
Golf_UsgaMarker_Db dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
qry.Columns.AddRange(dbUsgaMarker.ExistingColumnNames);
|
|
qry.Filters.AddRange(GetUsgaMarkerQueryFilter(prm));
|
|
qry.OrderBy.AddRange(GetUsgaMarkerSortColumns(prm));
|
|
// Query data.
|
|
using (var dbConnection = ReferenceDatabase.CreateConnection())
|
|
using (var dbCommand = dbConnection.CreateCommand())
|
|
{
|
|
try
|
|
{
|
|
dbConnection.Open();
|
|
dbCommand.CommandText = qry.BuildQuery(prm.ResultsPaging);
|
|
using (DbDataReader dbDataReader = dbCommand.ExecuteReader())
|
|
{
|
|
while (dbDataReader.Read())
|
|
{
|
|
dbUsgaMarker = new Golf_UsgaMarker_Db(ReferenceDbInfo);
|
|
dbUsgaMarker.PopulateFrom(dbDataReader);
|
|
userRoles.Add(CreateUsgaMarker(dbUsgaMarker));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
SetErrorState("Database query exception");
|
|
SaLogger.Warn($"{SysUtil.Fn}\n\tQuery: {dbCommand.CommandText}\n\t{ExceptionUtil.GetErrorStateMessage(exc)}");
|
|
}
|
|
}
|
|
return userRoles;
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Item query execution.
|
|
public override DbResultSet ExecuteUsgaMarkerQuery(List<ColumnDfn> columns, SaxGolfUsgaMarker.Params prm)
|
|
{
|
|
ClearErrorState();
|
|
|
|
//---------------------------------------------------------------------
|
|
// Construct query.
|
|
DbQuery query = new DbQuery(ReferenceDatabase.DbmsType);
|
|
query.Tables.Add(SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaMarker), aliasUsgaMarker);
|
|
|
|
// Add columns as defined in query list.
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Id))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Id, aliasUsgaMarker));
|
|
bool hasCourseCols = (columns.HasId(SaxGolfUsgaMarker.Column.Course_Name));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.CourseId) || hasCourseCols)
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.UsgaMarkerId))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_UsgaMarkerId, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Caption))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Caption, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Holes))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Holes, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.HolesCaption))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_HolesCaption, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Tee))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Tee, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Gender))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Gender, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.SlopeRating))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_SlopeRating, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Par))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Par, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.CourseRating))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseRating, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.BogeyRating))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_BogeyRating, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Length))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Length, aliasUsgaMarker));
|
|
// Common properties.
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Notes))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Notes, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Flags))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Flags, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.Status) || columns.HasId(SaxGolfUsgaMarker.Column.Status_Desc) || columns.HasId(SaxGolfUsgaMarker.Column.Status_Ind))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_Status, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.CreateOn_Date))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CreateOn, aliasUsgaMarker));
|
|
if (columns.HasId(SaxGolfUsgaMarker.Column.UpdateOn_Date))
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_UpdateOn, aliasUsgaMarker));
|
|
|
|
//---------------------------------------------------------------------
|
|
// Course.
|
|
if (hasCourseCols)
|
|
{
|
|
DbQueryJoin joinCourse = new DbQueryJoin(DbJoinType.LeftOuter);
|
|
joinCourse.Table = new StringPair(SaxDbDfn_Reference.GetTableNameQual(SaxDbDfn_Reference.TableIdx.UsgaCourse), aliasUsgaMarker_Course);
|
|
joinCourse.Filters.Add(SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_Id, aliasUsgaMarker_Course) + "=" + SaxDbDfn_Reference.GetColumnNameQual(SaxDbDfn_Reference.ColumnIdx.UsgaMarker_CourseId, aliasUsgaMarker));
|
|
query.Joins.Add(joinCourse);
|
|
List<SaxDbDfn_Reference.ColumnIdx> cols = new List<SaxDbDfn_Reference.ColumnIdx>();
|
|
cols.Add(SaxDbDfn_Reference.ColumnIdx.UsgaCourse_CourseName);
|
|
foreach (var col in cols)
|
|
query.Columns.Add(SaxDbDfn_Reference.GetColumnNameQual(col, aliasUsgaMarker_Course), prefixUsgaMarker_Course + SaxDbDfn_Reference.GetColumnName(col, false));
|
|
prm.Alias_Course = aliasUsgaMarker_Course;
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
// Populate filter.
|
|
query.Filters.AddRange(GetUsgaMarkerQueryFilter(prm));
|
|
|
|
if (prm.IdsIncluded.Count != 1)
|
|
{
|
|
// Configure sort sequence.
|
|
foreach (String sortColumn in GetUsgaMarkerSortColumns(prm))
|
|
query.OrderBy.Add(sortColumn);
|
|
}
|
|
|
|
//---------------------------------------------------------------------
|
|
//return new DbResultSet_DataTableReader(db, query.BuildQuery(prm.ResultsPaging));
|
|
return DbResultSet_DataReader.ExecuteQuery(ReferenceDatabase, query.BuildQuery(prm.ResultsPaging));
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|