using System.Collections.Generic; using System.Data; using System.Linq; using Kreta.BusinessLogic.HelperClasses; using Kreta.BusinessLogic.Utils; using Kreta.Core; using Kreta.Core.ConnectionType; using Kreta.Core.Exceptions; using Kreta.DataAccessManual; using Kreta.DataAccessManual.Interfaces; using Kreta.DataAccessManual.ParameterClasses; using Kreta.Enums; namespace Kreta.BusinessLogic.Helpers { public class TanmenetHelper : LogicBase { public TanmenetHelper(IConnectionType connectionType) : base(connectionType) { } public DataSet GetTanmenetek(TanmenetKereseseCO co) { return Dal.CustomConnection.Run(ConnectionType, (h) => { TanmenetKeresesePCO pco = Convert_CO_to_PCO(co); var dal = h.Tanmenet(GridParameters); return dal.GetTanmenetek(pco); }); } public void SaveTanmenet(TanmenetCO co) { Dal.CustomConnection.Run(ConnectionType, h => SaveTanmenet(h, co)); } private void SaveTanmenet(IDalHandler handler, TanmenetCO co) { if (!co.FoglalkozasID.HasValue) { throw new BlException(StringResourcesUtils.GetString(2494) /*Foglalkozás megadása kötelező*/); } var foglalkozasDal = handler.Foglalkozas(); var tanmenetDal = handler.Tanmenet(); var entity = foglalkozasDal.Get(co.FoglalkozasID.Value); foreach (var torlendoId in co.Orak.Where(x => x.ID.HasValue).Select(a => a.ID)) { if (torlendoId.HasValue) { DeleteTanmenet(handler, torlendoId.Value); } } foreach (var ujSor in co.Orak.Where(x => !string.IsNullOrWhiteSpace(x.Tema))) { var ujElem = tanmenetDal.Get(); ujElem.Oraszam = ujSor.Oraszam; ujElem.FeltoltoId = co.AlkalmazottID; ujElem.TantargyId = entity.TantargyId; ujElem.OsztalyCsoportId = entity.OsztalyCsoportId; ujElem.Tema = ujSor.Tema.ReplaceMultipleSpacesAndTrim(); ujElem.Nev = $"{ujSor.Oraszam}. {ujSor.Tema}"; tanmenetDal.Insert(ujElem); } } public void DeleteTanmenet(int id) { Dal.CustomConnection.Run(ConnectionType, (handler) => { handler.Tanmenet().Delete(id); }); } private void DeleteTanmenet(IDalHandler handler, int id) { handler.Tanmenet().Delete(id); } public DataSet GetTanmenetek(int tantargyId, int osztalyId, int felhasznaloId, bool uresSorokkal = true, int? foglalkozasId = null) { return Dal.CustomConnection.Run(ConnectionType, (h) => { var dal = h.Tanmenet(GridParameters); DataSet ds = dal.GetTanmenetek(tantargyId, osztalyId, felhasznaloId, foglalkozasId); if (uresSorokkal) { //Dataset másolása DataSet copyDataSet; copyDataSet = ds.Copy(); var tanmenetOrakList = copyDataSet.Tables[0].AsEnumerable().Select(dataRow => new TanmenetOrakCO { ID = dataRow.Field("ID"), Oraszam = dataRow.Field("Oraszam"), Tema = dataRow.Field("Tema") }).ToList(); var sorokszama = 720; if (tanmenetOrakList.Count > 0) { foreach (var item in tanmenetOrakList) { if (item.Oraszam > sorokszama) sorokszama = item.Oraszam; } } //Régi dataset sorainak törlése ds.Tables[0].Rows.Clear(); //2000-ig feltöltjük a sorokat for (int i = 1; i <= sorokszama; i++) { DataRow row = ds.Tables[0].NewRow(); var ora = tanmenetOrakList.FirstOrDefault(o => o.Oraszam == i); if (ora != null) { row["ID"] = ora.ID; row["Tema"] = ora.Tema; row["Oraszam"] = i; ds.Tables[0].Rows.Add(row); } else { row["Tema"] = " "; row["Oraszam"] = i; ds.Tables[0].Rows.Add(row); } } } return ds; }); } public string GetTanmenetModalHeader(int tanarId, int tantargyId, int osztalycsoportId, OktNevelesiKategoriaEnum? kategoria) { return Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.Foglalkozas(); var ds = dal.GetFoglalkozasNev(tanarId, tantargyId, osztalycsoportId, kategoria); var row = ds?.Tables[0]?.Rows; if (row?.Count > 0) { return $"{row[0].Field("Nev")}"; } return string.Empty; }); } private TanmenetKeresesePCO Convert_CO_to_PCO(TanmenetKereseseCO co) { var pco = new TanmenetKeresesePCO() { AlkalmazottID = co.AlkalmazottID, OsztalyID = co.OsztalyID, TantargyID = co.TantargyID, Megjegyzes = co.Megjegyzes, Nev = co.Nev, Oraszam = co.Oraszam, RovidNev = co.RovidNev, Tema = co.Tema }; return pco; } public DataSet GetTantargyTanmenetei(int tantargyId) { return Dal.CustomConnection.Run(ConnectionType, (h) => { var dal = h.Tanmenet(GridParameters); return dal.GetTantargyTanmenetei(tantargyId, TanevId); }); } public DataSet GetOsztalyCsoportTanmenetei(int id, OktNevelesiKategoriaEnum? kategoria) { return Dal.CustomConnection.Run(ConnectionType, (h) => { var dal = h.Tanmenet(GridParameters); return dal.GetOsztalyCsoportTanmenetei(id, TanevId, kategoria); }); } public List GetTanmenetCoList(int? alkalmazottId = null) { DataSet dataSet = Dal.CustomConnection.Run(ConnectionType, dalHandler => dalHandler.Tanmenet().GetTanmenetDataSet(TanevId, alkalmazottId)); var result = new List(); foreach (DataRow dataRow in dataSet.Tables[0].Rows) { var item = new TanmenetItemCo(dataRow); result.Add(item); } return result; } } }