471 lines
18 KiB
C#
471 lines
18 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Kreta.Framework;
|
|
using Kreta.Framework.Collections;
|
|
using Kreta.Framework.Collections.Generic;
|
|
using Kreta.Framework.Entities;
|
|
using Kreta.Framework.Entities.Associations;
|
|
using Kreta.Framework.Entities.Generic;
|
|
|
|
namespace SDA.Kreta.Entities
|
|
{
|
|
internal sealed class TelepulesDBHelper : EntityDBHelper<Telepules>
|
|
{
|
|
private Dictionary<string, string> dynamicColumns = new Dictionary<string, string>()
|
|
{
|
|
{ "Iranyitoszam", "T_TELEPULES_OSSZES.C_IRANYITOSZAM" },
|
|
{ "Megye", "T_TELEPULES_OSSZES.C_MEGYE" },
|
|
{ "Orszag", "T_TELEPULES_OSSZES.C_ORSZAG" },
|
|
{ "TelepulesNev", "T_TELEPULES_OSSZES.C_TELEPULESNEV" },
|
|
{ "TelepulesNev_1", "T_TELEPULES_OSSZES.C_TELEPULESNEV_1" },
|
|
{ "TelepulesNev_2", "T_TELEPULES_OSSZES.C_TELEPULESNEV_2" },
|
|
};
|
|
|
|
private const string dynamicQueryCommandText =
|
|
"select " +
|
|
"T_TELEPULES_OSSZES.ID, " +
|
|
"{COLUMNS}" +
|
|
// Telepules betöltése
|
|
// Telepules kapcsoló mezői
|
|
"T_TELEPULES_OSSZES.TOROLT, " +
|
|
"T_TELEPULES_OSSZES.SERIAL, " +
|
|
"T_TELEPULES_OSSZES.CREATED, " +
|
|
"T_TELEPULES_OSSZES.CREATOR, " +
|
|
"T_TELEPULES_OSSZES.LASTCHANGED, " +
|
|
"T_TELEPULES_OSSZES.MODIFIER " +
|
|
"from " +
|
|
"T_TELEPULES_OSSZES " +
|
|
"where " +
|
|
"(1 = 1) ";
|
|
|
|
private const string emptyQueryCommandText =
|
|
"select " +
|
|
"T_TELEPULES_OSSZES.ID, " +
|
|
// Telepules betöltése
|
|
// Telepules mezői
|
|
"T_TELEPULES_OSSZES.C_IRANYITOSZAM, " +
|
|
"T_TELEPULES_OSSZES.C_MEGYE, " +
|
|
"T_TELEPULES_OSSZES.C_ORSZAG, " +
|
|
"T_TELEPULES_OSSZES.C_TELEPULESNEV, " +
|
|
"T_TELEPULES_OSSZES.C_TELEPULESNEV_1, " +
|
|
"T_TELEPULES_OSSZES.C_TELEPULESNEV_2, " +
|
|
// Telepules kapcsoló mezői
|
|
"T_TELEPULES_OSSZES.TOROLT, " +
|
|
"T_TELEPULES_OSSZES.SERIAL, " +
|
|
"T_TELEPULES_OSSZES.CREATED, " +
|
|
"T_TELEPULES_OSSZES.CREATOR, " +
|
|
"T_TELEPULES_OSSZES.LASTCHANGED, " +
|
|
"T_TELEPULES_OSSZES.MODIFIER " +
|
|
"from " +
|
|
"T_TELEPULES_OSSZES " +
|
|
"where " +
|
|
"(1 = 1) ";
|
|
|
|
public override string EmptyQueryCommandText
|
|
{
|
|
get
|
|
{
|
|
return emptyQueryCommandText;
|
|
}
|
|
}
|
|
|
|
public override string DynamicQueryCommandText
|
|
{
|
|
get
|
|
{
|
|
return dynamicQueryCommandText;
|
|
}
|
|
}
|
|
|
|
public override IDictionary<string, string> DynamicColumns
|
|
{
|
|
get
|
|
{
|
|
return dynamicColumns;
|
|
}
|
|
}
|
|
|
|
protected override Telepules CreateEntityInstance()
|
|
{
|
|
return Telepules.GiveAnInstance();
|
|
}
|
|
|
|
#region Lekérdezés
|
|
|
|
public override void LoadEntityFields(Telepules entity, SDA.DataProvider.SDADataReader reader)
|
|
{
|
|
// Telepules betöltése
|
|
// Telepules mezői
|
|
|
|
entity.m_Iranyitoszam = DAUtil.ReadStringAttribute(reader, 1, "");
|
|
|
|
|
|
entity.m_Megye = DAUtil.ReadStringAttribute(reader, 2);
|
|
|
|
|
|
entity.m_Orszag = DAUtil.ReadStringAttribute(reader, 3, "");
|
|
|
|
|
|
entity.m_TelepulesNev = DAUtil.ReadStringAttribute(reader, 4, "");
|
|
|
|
|
|
entity.m_TelepulesNev_1 = DAUtil.ReadStringAttribute(reader, 5);
|
|
|
|
|
|
entity.m_TelepulesNev_2 = DAUtil.ReadStringAttribute(reader, 6);
|
|
|
|
// Telepules kapcsoló mezői
|
|
}
|
|
|
|
public override void LoadEntityFields(Telepules entity, SDA.DataProvider.SDADataReader reader, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
|
{
|
|
int index = 1;
|
|
if (columns == null)
|
|
{
|
|
columns = new List<string>(index);
|
|
}
|
|
// Telepules betöltése
|
|
// Telepules mezői
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("Iranyitoszam"))))
|
|
{
|
|
entity.m_Iranyitoszam = DAUtil.ReadStringAttribute(reader, index++, "");
|
|
}
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("Megye"))))
|
|
{
|
|
entity.m_Megye = DAUtil.ReadStringAttribute(reader, index++);
|
|
}
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("Orszag"))))
|
|
{
|
|
entity.m_Orszag = DAUtil.ReadStringAttribute(reader, index++, "");
|
|
}
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("TelepulesNev"))))
|
|
{
|
|
entity.m_TelepulesNev = DAUtil.ReadStringAttribute(reader, index++, "");
|
|
}
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("TelepulesNev_1"))))
|
|
{
|
|
entity.m_TelepulesNev_1 = DAUtil.ReadStringAttribute(reader, index++);
|
|
}
|
|
if (((columnFilterMode == ColumnFilterMode.DEFAULT_ALLOWED) ^ (columns.Contains("TelepulesNev_2"))))
|
|
{
|
|
entity.m_TelepulesNev_2 = DAUtil.ReadStringAttribute(reader, index++);
|
|
}
|
|
// Telepules kapcsoló mezői
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Paraméter kötés
|
|
|
|
public override void BindAttributes(Telepules entity, SDA.DataProvider.SDACommand command)
|
|
{
|
|
DAUtil.BindParameter(command, "pIRANYITOSZAM", SDA.DataProvider.SDADBType.String, 20, entity.m_Iranyitoszam, false);
|
|
|
|
DAUtil.BindParameter(command, "pMEGYE", SDA.DataProvider.SDADBType.String, 100, entity.m_Megye, entity.m_Megye == null);
|
|
|
|
DAUtil.BindParameter(command, "pORSZAG", SDA.DataProvider.SDADBType.String, 255, entity.m_Orszag, false);
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev, false);
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV_1", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev_1, entity.m_TelepulesNev_1 == null);
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV_2", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev_2, entity.m_TelepulesNev_2 == null);
|
|
}
|
|
|
|
public override void DynamicBindAttributes(Telepules entity, SDA.DataProvider.SDACommand command)
|
|
{
|
|
System.Text.StringBuilder sb = new System.Text.StringBuilder();
|
|
if (entity.HasChanged("Iranyitoszam"))
|
|
{
|
|
sb.Append("C_IRANYITOSZAM = :pIRANYITOSZAM,");
|
|
|
|
DAUtil.BindParameter(command, "pIRANYITOSZAM", SDA.DataProvider.SDADBType.String, 20, entity.m_Iranyitoszam, false);
|
|
|
|
}
|
|
if (entity.HasChanged("Megye"))
|
|
{
|
|
sb.Append("C_MEGYE = :pMEGYE,");
|
|
|
|
DAUtil.BindParameter(command, "pMEGYE", SDA.DataProvider.SDADBType.String, 100, entity.m_Megye, entity.m_Megye == null);
|
|
|
|
}
|
|
if (entity.HasChanged("Orszag"))
|
|
{
|
|
sb.Append("C_ORSZAG = :pORSZAG,");
|
|
|
|
DAUtil.BindParameter(command, "pORSZAG", SDA.DataProvider.SDADBType.String, 255, entity.m_Orszag, false);
|
|
|
|
}
|
|
if (entity.HasChanged("TelepulesNev"))
|
|
{
|
|
sb.Append("C_TELEPULESNEV = :pTELEPULESNEV,");
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev, false);
|
|
|
|
}
|
|
if (entity.HasChanged("TelepulesNev_1"))
|
|
{
|
|
sb.Append("C_TELEPULESNEV_1 = :pTELEPULESNEV_1,");
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV_1", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev_1, entity.m_TelepulesNev_1 == null);
|
|
|
|
}
|
|
if (entity.HasChanged("TelepulesNev_2"))
|
|
{
|
|
sb.Append("C_TELEPULESNEV_2 = :pTELEPULESNEV_2,");
|
|
|
|
DAUtil.BindParameter(command, "pTELEPULESNEV_2", SDA.DataProvider.SDADBType.String, 255, entity.m_TelepulesNev_2, entity.m_TelepulesNev_2 == null);
|
|
|
|
}
|
|
command.CommandText = command.CommandText.Replace("{COLUMNS}", sb.ToString());
|
|
}
|
|
|
|
public override void BindAssociations(Telepules entity, SDA.DataProvider.SDACommand command)
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
internal class TelepulesDA : EntityDataAccessor<Telepules>
|
|
{
|
|
private static TelepulesDBHelper m_dbhelper = new TelepulesDBHelper();
|
|
|
|
protected override IEntityDBHelper<Telepules> dbhelper
|
|
{
|
|
get { return m_dbhelper; }
|
|
}
|
|
|
|
#region Load
|
|
|
|
public override bool LoadEntity(Telepules entity, int entityId)
|
|
{
|
|
return LoadById(entity, entityId);
|
|
}
|
|
|
|
public override bool FilteredLoadEntity(Telepules entity, int entityId, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
|
{
|
|
return LoadById(entity, entityId, columnFilterMode, columns);
|
|
}
|
|
|
|
public bool LoadById(Telepules entity, int entityId)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = dbhelper.CreateEmptyQueryCommand())
|
|
{
|
|
command.CommandText += " and (T_TELEPULES_OSSZES.ID = :pID) ";
|
|
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = entityId;
|
|
return dbhelper.LoadSingleEntity(entity, command);
|
|
}
|
|
}
|
|
|
|
public bool LoadById(Telepules entity, int entityId, ColumnFilterMode columnFilterMode, IEnumerable<string> columns)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = dbhelper.CreateDynamicQueryCommand(columnFilterMode, columns))
|
|
{
|
|
command.CommandText += " and (T_TELEPULES_OSSZES.ID = :pID) ";
|
|
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = entityId;
|
|
return dbhelper.LoadSingleEntity(entity, command, columnFilterMode, columns);
|
|
}
|
|
}
|
|
|
|
[Obsolete("Ezt ne használjátok, mert mindenhova bele kellene fogalmazni a tanév szűrést is! Meg fog majd szűnni!")]
|
|
public override void LoadWithFilter(IEntityCollection<Telepules> collection, string filter, Dictionary<string, object> commandParameters = null)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = dbhelper.CreateEmptyQueryCommand())
|
|
{
|
|
command.CommandText += filter;
|
|
dbhelper.CreateParameterBinding(command, commandParameters);
|
|
dbhelper.LoadEntityCollection(collection, command);
|
|
}
|
|
}
|
|
|
|
[Obsolete("Ezt ne használjátok, mert mindenhova bele kellene fogalmazni a tanév szűrést is! Meg fog majd szűnni!")]
|
|
public override void LoadWithFilter(IEntityCollection<Telepules> collection, string filter, ColumnFilterMode columnFilterMode, IEnumerable<string> columns, Dictionary<string, object> commandParameters = null)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = dbhelper.CreateDynamicQueryCommand(columnFilterMode, columns))
|
|
{
|
|
command.CommandText += filter;
|
|
dbhelper.CreateParameterBinding(command, commandParameters);
|
|
dbhelper.LoadEntityCollection(collection, command, columnFilterMode, columns);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region InsertEntity
|
|
|
|
private const string m_InsertCommandText = @"
|
|
insert into T_TELEPULES_OSSZES (
|
|
C_IRANYITOSZAM,
|
|
C_MEGYE,
|
|
C_ORSZAG,
|
|
C_TELEPULESNEV,
|
|
C_TELEPULESNEV_1,
|
|
C_TELEPULESNEV_2,
|
|
TOROLT,
|
|
SERIAL,
|
|
CREATED,
|
|
CREATOR)
|
|
values (
|
|
:pIRANYITOSZAM,
|
|
:pMEGYE,
|
|
:pORSZAG,
|
|
:pTELEPULESNEV,
|
|
:pTELEPULESNEV_1,
|
|
:pTELEPULESNEV_2,
|
|
:pTOROLT,
|
|
:pSERIAL,
|
|
:pCREATED,
|
|
:pCREATOR);
|
|
|
|
SELECT SCOPE_IDENTITY() as ID;
|
|
|
|
";
|
|
|
|
public override void InsertEntity(Telepules entity)
|
|
{
|
|
entity.Serial = 0;
|
|
SetEntityCreator(entity, DateTime.Now, UserContext.Instance.UniqueIdentifier);
|
|
|
|
using (SDA.DataProvider.SDACommand command = DAUtil.CreateCommand(m_InsertCommandText))
|
|
{
|
|
dbhelper.BindAttributes(entity, command);
|
|
dbhelper.BindAssociations(entity, command);
|
|
command.Parameters.Add("pTOROLT", SDA.DataProvider.SDADBType.Boolean /* Boolean */).Value = false;
|
|
command.Parameters.Add("pSERIAL", SDA.DataProvider.SDADBType.Int).Value = 0;
|
|
command.Parameters.Add("pCREATED", SDA.DataProvider.SDADBType.DateTime).Value = entity.EntityCreated;
|
|
command.Parameters.Add("pCREATOR", SDA.DataProvider.SDADBType.Int).Value = entity.EntityCreator;
|
|
entity.ID = Convert.ToInt32(command.ExecuteScalar());
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateEntity
|
|
|
|
private const string m_UpdateAttributesCommandText = @"
|
|
update T_TELEPULES_OSSZES
|
|
set
|
|
{COLUMNS}
|
|
SERIAL = ISNULL(SERIAL,0) + 1,
|
|
LASTCHANGED = :pLASTCHANGED,
|
|
MODIFIER = :pMODIFIER,
|
|
TOROLT = :pTOROLT
|
|
where
|
|
(ID = :pID) and (ISNULL(SERIAL,0) = :pSERIAL)
|
|
";
|
|
|
|
public override bool UpdateEntity(Telepules entity)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = DAUtil.CreateCommand(m_UpdateAttributesCommandText))
|
|
{
|
|
bool result = true;
|
|
dbhelper.DynamicBindAttributes(entity, command);
|
|
|
|
SetEntityModifier(entity, DateTime.Now, UserContext.Instance.UniqueIdentifier);
|
|
|
|
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = entity.ID;
|
|
command.Parameters.Add("pSERIAL", SDA.DataProvider.SDADBType.Int).Value = entity.Serial;
|
|
command.Parameters.Add("pLASTCHANGED", SDA.DataProvider.SDADBType.DateTime).Value = entity.EntityLastChanged;
|
|
command.Parameters.Add("pMODIFIER", SDA.DataProvider.SDADBType.Int).Value = entity.EntityModifier;
|
|
command.Parameters.Add("pTOROLT", SDA.DataProvider.SDADBType.Boolean /* Boolean */).Value = entity.Torolt;
|
|
|
|
result = (command.ExecuteNonQuery() == 1);
|
|
if (result == true)
|
|
entity.Serial++;
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DeleteEntity
|
|
|
|
private const string m_FizikaiDeleteCommandText = @"DELETE FROM T_TELEPULES_OSSZES WHERE (ID = :pID) ";
|
|
private const string m_LogikaiDeleteCommandText = @"
|
|
UPDATE T_TELEPULES_OSSZES
|
|
SET TOROLT = 'T' ,
|
|
SERIAL = SERIAL + 1,
|
|
LASTCHANGED = :pLASTCHANGED,
|
|
MODIFIER = :pMODIFIER
|
|
WHERE (ID = :pID) ";
|
|
|
|
public override void DeleteEntity(Telepules entity, bool logikai = true)
|
|
{
|
|
var _deleteCommandText = logikai ? m_LogikaiDeleteCommandText : m_FizikaiDeleteCommandText;
|
|
using (SDA.DataProvider.SDACommand command = DAUtil.CreateCommand(_deleteCommandText))
|
|
{
|
|
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = entity.ID;
|
|
|
|
if (logikai)
|
|
{
|
|
DateTime lastchanged = DateTime.Now;
|
|
var modifier = UserContext.Instance.UniqueIdentifier;
|
|
|
|
command.Parameters.Add("pLASTCHANGED", SDA.DataProvider.SDADBType.DateTime).Value = lastchanged;
|
|
command.Parameters.Add("pMODIFIER", SDA.DataProvider.SDADBType.Int).Value = modifier;
|
|
}
|
|
|
|
if (command.ExecuteNonQuery() != 1)
|
|
{
|
|
throw new EntityNotFoundException("Telepules", entity.ID);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateAssociations
|
|
|
|
private const string m_UpdateAssociationCommandText = @"
|
|
update T_TELEPULES_OSSZES
|
|
set
|
|
SERIAL = ISNULL(SERIAL,0) + 1,
|
|
LASTCHANGED = :pLASTCHANGED,
|
|
MODIFIER = :pMODIFIER
|
|
where
|
|
(ID = :pID) and (ISNULL(SERIAL,0) = :pSERIAL)
|
|
";
|
|
|
|
public override bool UpdateAssociations(Telepules entity)
|
|
{
|
|
using (SDA.DataProvider.SDACommand command = DAUtil.CreateCommand(m_UpdateAssociationCommandText))
|
|
{
|
|
dbhelper.BindAssociations(entity, command);
|
|
|
|
DateTime lastchanged = DateTime.Now;
|
|
var modifier = UserContext.Instance.UniqueIdentifier;
|
|
|
|
command.Parameters.Add("pID", SDA.DataProvider.SDADBType.Int).Value = entity.ID;
|
|
command.Parameters.Add("pSERIAL", SDA.DataProvider.SDADBType.Int).Value = entity.Serial;
|
|
command.Parameters.Add("pLASTCHANGED", SDA.DataProvider.SDADBType.DateTime).Value = lastchanged;
|
|
command.Parameters.Add("pMODIFIER", SDA.DataProvider.SDADBType.Int).Value = modifier;
|
|
|
|
bool result = (command.ExecuteNonQuery() == 1);
|
|
if (result == true)
|
|
{
|
|
entity.Serial++;
|
|
SetEntityModifier(entity, lastchanged, modifier);
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Asszociációkkal kapcsolatos adatbázisműveletek (entitásspecifikus)
|
|
|
|
#region Mint asszociációs osztály
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
}
|
|
|
|
}
|
|
|