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.Base.App; using Saxonite.Net.Standard.Base.Bus.Reference; using System; using System.Collections.Generic; namespace Saxonite.Net.Standard.Base.Mgr.Reference { //======================================================================= partial class SaxReferenceGolfMgr { //******************************************************************* // Reference Mgr - Golf - USGA Country //******************************************************************* // Utilities. //------------------------------------------------------------------- // Create item. public abstract SaxGolfUsgaCountry CreateUsgaCountry(); //------------------------------------------------------------------- // Item exists. public bool UsgaCountryExistsById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return false; SaxGolfUsgaCountry.Params prmUsgaCountry = new SaxGolfUsgaCountry.Params(); prmUsgaCountry.IdsIncluded.Add(id); prmUsgaCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.Any; return GetUsgaCountryCount(prmUsgaCountry) == 1; } //------------------------------------------------------------------- // Retrieve individual items. public abstract SaxGolfUsgaCountry GetUsgaCountry(SaxGolfUsgaCountry.Params prmUsgaCountry); public SaxGolfUsgaCountry GetUsgaCountryById(SysId id) { ClearErrorState(); if (!SysId.IsValid(id)) return null; SaxGolfUsgaCountry.Params prmUsgaCountry = new SaxGolfUsgaCountry.Params(); prmUsgaCountry.IdsIncluded.Add(id); prmUsgaCountry.StatusCat = SaxGolfUsgaCountry.StatusCat.Any; return GetUsgaCountry(prmUsgaCountry); } //------------------------------------------------------------------- // Validate item data. public bool IsValidUsgaCountry(SaxGolfUsgaCountry usgaCountry) { ClearErrorState(); if (usgaCountry == null) return SetErrorState(ErrorMessage.ItemNotSpecified); return IsValidUsgaCountryData(usgaCountry.GetData(), new SaxGolfUsgaCountry.ErrField()); } public virtual bool IsValidUsgaCountryData(SaxGolfUsgaCountry.Data data, SaxGolfUsgaCountry.ErrField errField) { ClearErrorState(); //--------------------------------------------------------------- // Country code. if (errField.CountryCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CountryCode, "code", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_CountryCode), true)) { errField.CountryCode = SacsHierarchyItem.ValidValue.Invalid; return false; } // ENT Country code. if (errField.EntCountryCode != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.EntCountryCode, "ent code", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_EntCountryCode))) { errField.EntCountryCode = SacsHierarchyItem.ValidValue.Invalid; return false; } // Country name. if (errField.CountryName != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.CountryName, "name", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_CountryName), true)) { errField.CountryName = SacsHierarchyItem.ValidValue.Invalid; return false; } //--------------------------------------------------------------- // Common properties. if (errField.Notes != SacsHierarchyItem.ValidValue.Ignore && !IsValidValue(data.Notes, "notes", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Notes))) { errField.Notes = SacsHierarchyItem.ValidValue.Invalid; return false; } if (errField.Status != SacsHierarchyItem.ValidValue.Ignore) { if (!IsValidValue(data.StatusCode, "status", (long)SaxDbDfn_Reference.GetColTextLen(SaxDbDfn_Reference.ColumnIdx.UsgaCountry_Status), true, true)) { errField.Status = SacsHierarchyItem.ValidValue.Invalid; return false; } if (!SaxGolfUsgaCountry.ValidStatuses.Contains(data.Status)) { errField.Status = SacsHierarchyItem.ValidValue.Invalid; return SetErrorState(ErrorMessage.InvalidStatus); } } //--------------------------------------------------------------- return true; } //------------------------------------------------------------------- // Item database interface. public abstract bool InsertUsgaCountry(SaxGolfUsgaCountry usgaCountry, DbUpdateInfo dbUpdateInfo); public abstract bool UpdateUsgaCountry(SaxGolfUsgaCountry usgaCountry, DbUpdateInfo dbUpdateInfo); public virtual bool UsgaCountryCanBeDeleted(SaxGolfUsgaCountry usgaCountry) { ClearErrorState(); return true; } public abstract bool DeleteUsgaCountry(SaxGolfUsgaCountry usgaCountry, DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- // Bulk updates. public class UsgaCountryData { public String CountryCode { get; set; } public String EntCountryCode { get; set; } = null; public String CountryName { get; set; } = null; } /// /// Bulk update USGA Countries. /// - Country code must be supplied to act as identifier. /// - Other properties are validated as per country rules - check error state. /// - Other properties are left as is if null. /// public abstract bool BulkUpdateUsgaCountries(List countries, DbUpdateInfo dbUpdateInfo); //------------------------------------------------------------------- // Item list. public abstract ColumnDfn GetUsgaCountryColumnDfn(SaxGolfUsgaCountry.Column columnId, String caption = "", int width = 0); public abstract List GetUsgaCountryQueryFilter(SaxGolfUsgaCountry.Params prmUsgaCountry); public abstract long GetUsgaCountryCount(SaxGolfUsgaCountry.Params prmUsgaCountry); public long GetActiveUsgaCountryCount() { return GetUsgaCountryCount(new SaxGolfUsgaCountry.Params()); } public abstract List GetUsgaCountryList(SaxGolfUsgaCountry.Params prmUsgaCountry); public abstract DbResultSet ExecuteUsgaCountryQuery(List columns, SaxGolfUsgaCountry.Params prmUsgaCountry); //------------------------------------------------------------------- /// /// Extract and format result set data value where specific handling is required. /// Where response is an invalid data value, format value using column.FormatValue(values). /// public virtual DataValue GetUsgaCountryDataValue(ColumnDfn column, NamedValue.Map values) { DataValue value = new DataValue(); switch ((SaxGolfUsgaCountry.Column)column.Id) { //----------------------------------------------------------- // Notes. case SaxGolfUsgaCountry.Column.Notes: { value = new DataValue(SacsHierarchyItem.FormatForDisplay(values.GetValue(column.DataName).ToString(), 200)); } break; //----------------------------------------------------------- // Status. case SaxGolfUsgaCountry.Column.Status_Desc: case SaxGolfUsgaCountry.Column.Status_Ind: { String statusCode = values.GetValue(column.DataName).ToString(); SaStatus status = SacsSystem.GetStatusForCode(statusCode); if (column.Id == (int)SaxGolfUsgaCountry.Column.Status_Desc) value = new DataValue(SacsSystem.GetStatusDesc(status)); else if (column.Id == (int)SaxGolfUsgaCountry.Column.Status_Ind) value = new DataValue(SaxGolfUsgaCountry.GetStatusTriState(status)); } break; //----------------------------------------------------------- default: value = values.GetValue(column.DataName); break; } return value; } //------------------------------------------------------------------- } //======================================================================= }