80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Sarand.Core.Base;
|
|
using Sarand.Core.Dbas.Base;
|
|
using Sarand.PatientMgr.Core.App;
|
|
using Sarand.Win.Dbas.Data;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static Sarand.Win.Dbas.Data.DbDataItem;
|
|
|
|
namespace Sarand.PatientMgr.Win.Dbas.Data
|
|
{
|
|
//=======================================================================
|
|
public abstract class SpmDbDataItem : DbDataItem
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Definitions.
|
|
/// <summary>
|
|
/// Database information - object supplied by main application.
|
|
/// <para>NB Application may have multiple databases with schema differences.</para>
|
|
/// <para>Each instance of a DbDataItem must be database specific.</para>
|
|
/// </summary>
|
|
public class SlmDatabaseInfo : IDatabaseInfo
|
|
{
|
|
// Data members.
|
|
private readonly List<DbDfnTable> tables;
|
|
private static readonly String defaultSchemaName = "dbo";
|
|
// Construction.
|
|
public SlmDatabaseInfo (Spm.Site site, String databaseName, List<DbDfnTable> tables)
|
|
{
|
|
this.Site = site;
|
|
this.DatabaseName = databaseName;
|
|
this.tables = tables;
|
|
}
|
|
// Properties.
|
|
public Spm.Site Site { get; }
|
|
public String DatabaseName { get; }
|
|
public String Context { get { return StringUtil.OnEmpty(SpmSystem.GetSiteCode(Site), "UnknownSite") + "." + StringUtil.OnEmpty(DatabaseName, "UnknownDb"); } }
|
|
// Database schema.
|
|
public DbDfnTable GetTableDefinition (String schemaName, String tableName)
|
|
{
|
|
foreach (DbDfnTable table in tables.FindAll(item => item.Name.EqualsCI(tableName)))
|
|
{
|
|
if (StringUtil.OnEmpty(table.Schema, defaultSchemaName).EqualsCI(StringUtil.OnEmpty(schemaName, defaultSchemaName)))
|
|
return table;
|
|
}
|
|
return null;
|
|
}
|
|
public bool TableExists (String schemaName, String tableName)
|
|
{
|
|
return GetTableDefinition(schemaName, tableName) != null;
|
|
}
|
|
public bool ColumnExists (String schemaName, String tableName, String columnName)
|
|
{
|
|
DbDfnTable table = GetTableDefinition(schemaName, tableName);
|
|
if (table == null) return false;
|
|
return table.HasColumnByName(columnName);
|
|
}
|
|
public List<DbDfnColumn> GetColumnsForTable (String schemaName, String tableName)
|
|
{
|
|
DbDfnTable table = GetTableDefinition(schemaName, tableName);
|
|
if (table != null) return table.Columns;
|
|
return new List<DbDfnColumn>();
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
protected SpmDbDataItem (IDatabaseInfo dbInfo) : base(dbInfo)
|
|
{
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
}
|