using System; using System.Collections.Generic; using System.Data; using System.Linq; using Kreta.Core.FeatureToggle; using Kreta.Core.Logic; using Kreta.DataAccess.Interfaces; using Kreta.DataAccessManual.Interfaces; using Kreta.DataAccessManual.ParameterClasses; using Kreta.DataAccessManual.Util; using Kreta.Enums; using Kreta.Framework; using Kreta.Framework.Util; using SDA.DataProvider; using SDA.Kreta.Entities; using static SDA.Kreta.Entities.SzamonkeresElorejelzes; namespace Kreta.DataAccessManual { internal class SzamonkeresElorejelzesDal : DataAccessBase, ISzamonkeresElorejelzesDal { public SzamonkeresElorejelzesDal(DalHandler handler) : base(handler) { } public SzamonkeresElorejelzesDal(DalHandler handler, GridParameters parameters) : base(handler, parameters) { } public ISzamonkeresElorejelzes Get() { return GiveAnInstance(); } public ISzamonkeresElorejelzes Get(int id) { var entity = GiveAnInstance(); entity.LoadByID(id); return entity; } public void Insert(ISzamonkeresElorejelzes dto) { var entity = dto as SzamonkeresElorejelzes; entity.IsErtesitesElkuldve = !FeatureContext.Instance.IsEnabled(Core.Constants.FeatureName.SendBejelentettSzamonkeresNotification); entity.Insert(); DalHelper.Commit(); } public void Update(ISzamonkeresElorejelzes dto) { var entity = dto as SzamonkeresElorejelzes; entity.Update(); DalHelper.Commit(); } public void FullUpdate(ISzamonkeresElorejelzes dto) { var entity = dto as SzamonkeresElorejelzes; entity.FullUpdate(); DalHelper.Commit(); } public void Delete(int id) { var entity = SzamonkeresElorejelzes.GiveAnInstance(); entity.LoadByID(id); entity.Delete(); DalHelper.Commit(); } public DataSet GetSzamonkeresElorejelzesDetailDataSet(int intezmenyId, int tanevId, SzamonkeresElorejelzesSearchPco pco, bool isKellKapcsolodoOsztalyok) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "uspGetSzamonkeresElorejelzesDetailDataSet"; command.Parameters.Add("IntezmenyId", intezmenyId); command.Parameters.Add("TanevId", tanevId); command.Parameters.Add("pOraGroupId", pco.OraGroupId); command.Parameters.Add("pDatum", pco.Datum); command.Parameters.Add("pOraszamSrc", pco.OraszamSrc); command.Parameters.Add("pOsztalyCsoportId", pco.OsztalyCsoportId); command.Parameters.Add("pIsKellKapcsolodoOsztalyok", isKellKapcsolodoOsztalyok); command.Parameters.Add("pErtekelesModTypeId", (int)GeneratedAdatszotarTipusEnum.ErtekelesMod); var dts = new DataSet(); using (var adapter = new SDADataAdapter()) { adapter.SelectCommand = command; adapter.Fill(dts); } SetBoolFields(dts.Tables[0], "Torolheto"); return dts; } } public DataSet GetTanulokSzamonkeresElorejelzesei(int intezmenyId, int tanevId, SzamonkeresElorejelzesSearchPco pco) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "uspGetTanulokSzamonkeresElorejelzesei"; command.Parameters.Add("IntezmenyId", intezmenyId); command.Parameters.Add("TanevId", tanevId); command.Parameters.Add("pOraGroupId", pco.OraGroupId); command.Parameters.Add("pDatum", pco.Datum); command.Parameters.Add("pOsztalyCsoportId", pco.OsztalyCsoportId); command.Parameters.Add("pNapiSzamonkeresLimit", pco.NapiSzamonkeresLimit); command.Parameters.Add("pErtekelesModokLimithez", string.Join(",", pco.ErtekelesModokLimithez)); var dts = new DataSet(); using (var adapter = new SDADataAdapter()) { adapter.SelectCommand = command; adapter.Fill(dts); } return dts; } } /// INFO @DevKornel: Mobil használja public DataSet GetBejelentettSzamonkeresekGrid(int intezmenyId, int tanevId, SzamonkeresElorejelzesSearchPco pco, OktNevelesiKategoriaEnum? feladatKategoria) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "uspGetSzamonkeresElorejelzesGrid"; command.Parameters.Add("pIntezmenyId", intezmenyId); command.Parameters.Add("pTanevId", tanevId); command.Parameters.Add("pSzamonkeresIdsString", SqlLogic.ParseListToParameter(pco.SzamonkeresIds)); command.Parameters.Add("pTanuloId", pco.TanuloId); command.Parameters.Add("pDatumTol", pco.DatumTol); command.Parameters.Add("pDatumIg", pco.DatumIg); command.Parameters.Add("pHetNapjaSrc", pco.HetNapjaSrc); command.Parameters.Add("pOraszamSrc", pco.OraszamSrc); command.Parameters.Add("pSzamonkeresModSrc", pco.SzamonkeresModSrc); command.Parameters.Add("pSzamonkeresMegnevezesSrc", pco.SzamonkeresMegnevezesSrc); command.Parameters.Add("pBejelentesDatumaTol", pco.BejelentesDatumaTol); command.Parameters.Add("pBejelentesDatumaIg", pco.BejelentesDatumaIg); command.Parameters.Add("pTantargySrc", pco.TantargySrc); command.Parameters.Add("pTanarSrc", pco.TanarSrc); command.Parameters.Add("pRegiekElrejtese", pco.RegiSzamonkeresekElrejtese); command.Parameters.Add("pCsakLegutobbi6", pco.CsakLegutobbi6); command.Parameters.Add("pOraGroupId", pco.OraGroupId); command.Parameters.Add("pErtekelesModTypeId", (int)GeneratedAdatszotarTipusEnum.ErtekelesMod); command.Parameters.Add("pMindegyikHetTipusId", (int)HetiRendTipusEnum.MindegyikHet); if (feladatKategoria.HasValue) { command.Parameters.Add("pFeladatKategoriaId", feladatKategoria); } else { command.Parameters.Add("pFeladatKategoriaId", DBNull.Value); } if (pco.OsztalyCsoportIdsKapcsolodoCsoportokkal?.Any() ?? false) { command.Parameters.Add("pOsztalyCsoportIdsKapcsolodoCsoportokkal", SqlLogic.ParseListToParameter(pco.OsztalyCsoportIdsKapcsolodoCsoportokkal)); } else { command.Parameters.Add("pOsztalyCsoportId", pco.OsztalyCsoportId); } var dts = new DataSet(); using (var adapter = new SDADataAdapter()) { adapter.SelectCommand = command; adapter.Fill(dts); } SetDNAME(dts.Tables[0], "HetNapja"); SetBoolFields(dts.Tables[0], "Torolheto"); DataTable dt = SortingAndPaging(dts.Tables[0], GridParameters); return dt.AsDataSet(); } } /// INFO @DevKornel: Mobil használja public DataSet GetBejelentettSzamonkeresekByDateRange(int intezmenyId, int tanevId, DateTime start, DateTime end) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "uspGetSzamonkeresElorejelzesekByDateRange"; command.Parameters.Add("pIntezmenyId", intezmenyId); command.Parameters.Add("pTanevId", tanevId); command.Parameters.Add("pDatumTol", start); command.Parameters.Add("pDatumIg", end); var dts = new DataSet(); using (var adapter = new SDADataAdapter()) { adapter.SelectCommand = command; adapter.Fill(dts); } return dts; } } public void DeleteAllByOrarendiOraGroupId(int tanevId, int orarendiOraGroupId) { var ds = GetSzamonkeresForOrarendiOraGroupId(tanevId, orarendiOraGroupId); foreach (DataRow row in ds.Tables[0].Rows) { if (row["ID"] != null && row["ID"] != DBNull.Value) { Delete(Convert.ToInt32(row["ID"])); } } } public DataSet GetSzamonkeresForOrarendiOraGroupId(int tanevId, int? orarendiOraGroupId) { var commandParameterList = new List { new CommandParameter("pTanevId", tanevId), new CommandParameter("pOrarendiOraGroupId", orarendiOraGroupId), }; string commandText = @" SELECT sz.ID ,sz.C_ORARENDIORAGROUPID as OrarendiOraGroupId ,sz.C_SZAMONKERESDATUMA FROM T_SZAMONKERESELOREJELZES_OSSZES sz WHERE sz.TOROLT = 'F' AND sz.C_TANEVID = :pTanevId AND sz.C_ORARENDIORAGROUPID = :pOrarendiOraGroupId "; var ds = GetData(commandText, commandParameterList); return ds; } public void DeleteAllByOraGroupIdAndIdoszak(int tanevId, int orarendiOraGroupId, DateTime? oraErvenyessegKezdete, DateTime? oraErvenyessegVege, bool idoszakonKivul = false) { var ids = GetSzamonkeresIDsForOrarendiOraGroupIdByIdoszak(tanevId, orarendiOraGroupId, oraErvenyessegKezdete, oraErvenyessegVege, idoszakonKivul); foreach (var id in ids) { Delete(id); } } private List GetSzamonkeresIDsForOrarendiOraGroupIdByIdoszak(int tanevId, int orarendiOraGroupId, DateTime? oraErvenyessegKezdete, DateTime? oraErvenyessegVege, bool idoszakonKivul) { List ret = new List(); var commandParameterList = new List { new CommandParameter("pTanevId", tanevId), new CommandParameter("pOrarendiOraGroupId", orarendiOraGroupId), }; if (oraErvenyessegKezdete.HasValue) { commandParameterList.Add(new CommandParameter("pOraErvenyessegKezdete", oraErvenyessegKezdete.Value)); } else { commandParameterList.Add(new CommandParameter("pOraErvenyessegKezdete", DBNull.Value)); } if (oraErvenyessegVege.HasValue) { commandParameterList.Add(new CommandParameter("pOraErvenyessegVege", oraErvenyessegVege.Value)); } else { commandParameterList.Add(new CommandParameter("pOraErvenyessegVege", DBNull.Value)); } string commandText = @" SELECT sz.ID FROM T_SZAMONKERESELOREJELZES_OSSZES sz WHERE sz.TOROLT = 'F' AND sz.C_TANEVID = :pTanevId AND sz.C_ORARENDIORAGROUPID = :pOrarendiOraGroupId "; commandText += idoszakonKivul ? @" AND (sz.C_SZAMONKERESDATUMA < :pOraErvenyessegKezdete OR (:pOraErvenyessegVege IS NOT NULL AND sz.C_SZAMONKERESDATUMA > :pOraErvenyessegVege)) " : @" AND (sz.C_SZAMONKERESDATUMA >= :pOraErvenyessegKezdete AND (:pOraErvenyessegVege IS NULL OR sz.C_SZAMONKERESDATUMA <= :pOraErvenyessegVege)) "; var ds = GetData(commandText, commandParameterList); foreach (DataRow row in ds.Tables[0].Rows) { if (row["ID"] != null && row["ID"] != DBNull.Value) { ret.Add(Convert.ToInt32(row["ID"])); } } return ret; } public bool HasSzamonkeresForOrarendiOraGroupId(int tanevId, int orarendiOraGroupId) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.Parameters.Add("pTanevId", tanevId); command.Parameters.Add("pOrarendiOraGroupId", orarendiOraGroupId); command.CommandText = @" IF EXISTS ( SELECT 1 FROM T_SZAMONKERESELOREJELZES_OSSZES sz WHERE sz.TOROLT = 'F' AND sz.C_TANEVID = :pTanevId AND sz.C_ORARENDIORAGROUPID = :pOrarendiOraGroupId ) SELECT 1 ELSE SELECT 0 "; return Convert.ToBoolean(command.ExecuteScalar()); } } public bool HasSzamonkeresByIdoszak(int tanevId, int orarendiOraGroupId, DateTime oraErvenyessegKezdete, DateTime oraErvenyessegVege, bool idoszakonKivul = true) { using (var command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.Parameters.Add("pTanevId", tanevId); command.Parameters.Add("pOrarendiOraGroupId", orarendiOraGroupId); command.Parameters.Add("pOraErvenyessegKezdete", oraErvenyessegKezdete); command.Parameters.Add("pOraErvenyessegVege", oraErvenyessegVege); command.CommandText = @" IF EXISTS ( SELECT 1 FROM T_SZAMONKERESELOREJELZES_OSSZES sz WHERE sz.TOROLT = 'F' AND sz.C_TANEVID = :pTanevId AND sz.C_ORARENDIORAGROUPID = :pOrarendiOraGroupId " + (idoszakonKivul ? @" AND (sz.C_SZAMONKERESDATUMA < :pOraErvenyessegKezdete OR sz.C_SZAMONKERESDATUMA > :pOraErvenyessegVege)" : @" AND (sz.C_SZAMONKERESDATUMA >= :pOraErvenyessegKezdete AND sz.C_SZAMONKERESDATUMA < :pOraErvenyessegVege)") + @" ) SELECT 1 ELSE SELECT 0 "; return Convert.ToBoolean(command.ExecuteScalar()); } } /// INFO @DevKornel: Mobil használja public List<(int TanuloId, Guid IdpUniqueId, int SzamonkeresId, int TanevId, int SzamonkeresModId, string TanuloNeve, string TantargyNeve, string IntezmenyAzonosito)> GetAllSchemaBejelentettSzamonkeresNotification() { var result = new List<(int TanuloId, Guid IdpUniqueId, int SzamonkeresId, int TanevId, int SzamonkeresModId, string TanuloNeve, string TantargyNeve, string IntezmenyAzonosito)>(); var ds = new DataSet(); using (var sdaCommand = new SDACommand()) { sdaCommand.Connection = UserContext.Instance.SDAConnection; sdaCommand.Transaction = UserContext.Instance.SDATransaction; sdaCommand.CommandType = CommandType.StoredProcedure; sdaCommand.CommandText = "uspGetAllSchemaBejelentettSzamonkeresNotification"; using (var adapter = new SDADataAdapter()) { adapter.SelectCommand = sdaCommand; adapter.Fill(ds); } } foreach (DataRow row in ds.Tables[0].Rows) { result.Add((row.Field("TanuloId"), row.Field("IdpUniqueId"), row.Field("SzamonkeresId"), row.Field("TanevId"), row.Field("SzamonkeresModId"), row.Field("TanuloNev"), row.Field("TantargyNev"), row.Field("IntezmenyAzonosito"))); } return result; } /// INFO @DevKornel: Mobil használja public void SetBejelentettSzamonkeresAsKikuldott(IEnumerable idList) { if (!idList.Any()) { return; } using (SDACommand command = new SDACommand()) { command.Connection = UserContext.Instance.SDAConnection; command.Transaction = UserContext.Instance.SDATransaction; command.CommandType = CommandType.StoredProcedure; command.CommandText = "uspSetSzamonkeresElorejelzesAsKikuldott"; command.Parameters.Add("item_list", SqlLogic.ParseListToParameter(idList.ToList())); command.ExecuteNonQuery(); DalHelper.Commit(); } } } }