using System; using System.Collections.Generic; using System.Data; using System.Text; using Kreta.DataAccess.Interfaces; using Kreta.DataAccessManual.Interfaces; using Kreta.DataAccessManual.Util; using Kreta.Framework; using Kreta.Framework.Entities; using Kreta.Framework.Util; using SDA.DataProvider; using SDA.Kreta.Entities; namespace Kreta.DataAccessManual { internal class LepEloadasDal : DataAccessBase, ILepEloadasDal { public LepEloadasDal(DalHandler handler, GridParameters gridParameters) : base(handler, gridParameters) { } public LepEloadasDal(DalHandler handler) : base(handler) { } #region BaseCRUD public ILepEloadas Get() { return LepEloadas.GiveAnInstance(); } public ILepEloadas Get(int id) { var entity = LepEloadas.GiveAnInstance(); entity.LoadByID(id); return entity; } public void Insert(ILepEloadas dto) { var entity = dto as LepEloadas; entity.Insert(); dto.ID = entity.ID; DalHelper.Commit(); } public void FullUpdate(ILepEloadas dto) { var entity = dto as LepEloadas; entity.FullUpdate(true); DalHelper.Commit(); } public void Update(ILepEloadas dto) { var entity = dto as LepEloadas; entity.Update(); DalHelper.Commit(); } public void Delete(ILepEloadas dto) { var entity = dto as LepEloadas; entity.Delete(); DalHelper.Commit(); } #endregion public void LepEloadasUpdateKiseroSzam(int intezmenyId, int tanevId, int eloadasId, int kiseroSzam) { string commandText = @" update T_LEPELOADAS set C_KISEROLETSZAM = :pKiseroSzam where C_ELOADASID = :pEloadasId and C_INTEZMENYID = :pIntezmenyId and C_TANEVID = :pTanevId "; using (SDACommand command = DAUtil.CreateCommand(commandText)) { command.Parameters.Add("pIntezmenyId", SDADBType.Int).Value = intezmenyId; command.Parameters.Add("pTanevId", SDADBType.Int).Value = tanevId; command.Parameters.Add("pEloadasId", SDADBType.Int).Value = eloadasId; command.Parameters.Add("pKiseroSzam", SDADBType.Int).Value = kiseroSzam; command.ExecuteNonQuery(); DalHelper.Commit(); } } public DataSet LepGetEloadasSzamok(int intezmenyId, int tanevId, int eloadasId) { var paramsList = new List() { new CommandParameter(nameof(intezmenyId), intezmenyId), new CommandParameter(nameof(tanevId), tanevId), new CommandParameter(nameof(eloadasId), eloadasId) }; var command = new StringBuilder($@" select ISNULL((select e.C_KISEROLETSZAM from T_LEPELOADAS e where e.C_ELOADASID = @{nameof(eloadasId)} and e.C_INTEZMENYID = @{nameof(intezmenyId)} and e.C_TANEVID = @{nameof(tanevId)} and e.TOROLT = 'F'), 0) as KiseroSzam ,ISNULL((select e.ID from T_LEPELOADAS e where e.C_ELOADASID = @{nameof(eloadasId)} and e.C_INTEZMENYID = @{nameof(intezmenyId)} and e.C_TANEVID = @{nameof(tanevId)} and e.TOROLT = 'F'), 0) as EloadasDBId ,ISNULL((select count(1) from T_LEPELOADASJEGYZEK ej where ej.C_ELOADASID = @{nameof(eloadasId)} and ej.C_INTEZMENYID = @{nameof(intezmenyId)} and ej.C_TANEVID = @{nameof(tanevId)} and ej.TOROLT = 'F'), 0) as TanuloSzam "); return GetData(command.ToString(), paramsList); } public bool HasLEPAccess(int felhasznaloId) { using (var command = UserContext.Instance.SDAConnection.CreateCommand()) { command.Transaction = UserContext.Instance.SDATransaction; command.Parameters.Add("pFelhasznaloId", felhasznaloId); command.CommandText = @" select SUM(Cnt) from ( select count(1) as Cnt from T_ALKALMAZOTT_OSSZES a where a.C_LEPKEZELO = 'T' and a.TOROLT = 'F' and a.ID = :pFelhasznaloId union select count(1) as Cnt from T_OSZTALY o where o.TOROLT = 'F' and o.C_OSZTALYFONOKID = :pFelhasznaloId or o.C_OFOHELYETTESID = :pFelhasznaloId ) as x "; var result = command.ExecuteScalar(); if (result != DBNull.Value && result != null) { if ((int)result > 0) { return true; } } return false; } } } }