using System; using System.Data; using Kreta.BusinessLogic.Classes; using Kreta.BusinessLogic.HelperClasses; using Kreta.Core; using Kreta.Core.ConnectionType; using Kreta.DataAccess.Interfaces; using Kreta.DataAccessManual; using Kreta.Resources; namespace Kreta.BusinessLogic.Helpers { public class KerdoivHelper : LogicBase { public KerdoivHelper(IConnectionType connectionType) : base(connectionType) { } public NatKerdoivCo GetNatKerdoivCo() { NatKerdoivCo co = new NatKerdoivCo(); var dataSet = Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NatKerdoivDal(); return dal.GetNatKerdoivDataSetByAlkalmazott(IntezmenyId, TanevId, FelhasznaloId); }); DataRowCollection dataRowCollection = dataSet.Tables[0].Rows; if (dataRowCollection.Count > 1) { throw new OverflowException(ErrorResource.NemLehetEgynelTobbNatKerdoiveAzAlkalmazottnak); } if (dataRowCollection.Count == 0) { dataRowCollection.Add(); } DataRow dataRow = dataRowCollection[0]; co.Id = SDAConvert.ToNullableInt32(dataRow["Id"]); co.Kerdes01 = SDAConvert.ToNullableInt32(dataRow["Kerdes01"]); co.Kerdes02 = SDAConvert.ToNullableInt32(dataRow["Kerdes02"]); co.Kerdes03 = SDAConvert.ToNullableInt32(dataRow["Kerdes03"]); co.Kerdes04 = SDAConvert.ToNullableInt32(dataRow["Kerdes04"]); co.Kerdes05 = SDAConvert.ToNullableInt32(dataRow["Kerdes05"]); co.Kerdes06 = SDAConvert.ToNullableInt32(dataRow["Kerdes06"]); co.Kerdes07 = SDAConvert.ToNullableInt32(dataRow["Kerdes07"]); co.Kerdes08 = SDAConvert.ToNullableInt32(dataRow["Kerdes08"]); co.Kerdes09 = SDAConvert.ToNullableInt32(dataRow["Kerdes09"]); co.Kerdes10 = SDAConvert.ToNullableInt32(dataRow["Kerdes10"]); co.Kerdes11 = SDAConvert.ToString(dataRow["Kerdes11"]); co.Kerdes12 = SDAConvert.ToString(dataRow["Kerdes12"]); return co; } public void Save(NatKerdoivCo co) { Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NatKerdoivDal(); bool isNew = !co.Id.IsEntityId(); //NOTE: Az IsEntityId vizsgálat miatt nem lehet null az co.Id! INATKerdoiv entity = isNew ? dal.Get() : dal.Get(co.Id.Value); entity.IsLatta = true; entity.Kerdes01 = co.Kerdes01; entity.Kerdes02 = co.Kerdes02; entity.Kerdes03 = co.Kerdes03; entity.Kerdes04 = co.Kerdes04; entity.Kerdes05 = co.Kerdes05; entity.Kerdes06 = co.Kerdes06; entity.Kerdes07 = co.Kerdes07; entity.Kerdes08 = co.Kerdes08; entity.Kerdes09 = co.Kerdes09; entity.Kerdes10 = co.Kerdes10; entity.Kerdes11 = co.Kerdes11; entity.Kerdes12 = co.Kerdes12; if (isNew) { entity.TanevId = TanevId; entity.IntezmenyId = IntezmenyId; entity.AlkalmazottId = FelhasznaloId; dal.Insert(entity); } else { dal.FullUpdate(entity); } }); } public void SetNatKerdoivIsLattamTrue() { var co = GetNatKerdoivCo(); Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NatKerdoivDal(); bool isNew = !co.Id.IsEntityId(); //NOTE: Az IsEntityId vizsgálat miatt nem lehet null az co.Id! INATKerdoiv entity = isNew ? dal.Get() : dal.Get(co.Id.Value); entity.IsLatta = true; if (isNew) { entity.TanevId = TanevId; entity.IntezmenyId = IntezmenyId; entity.AlkalmazottId = FelhasznaloId; dal.Insert(entity); } else { dal.FullUpdate(entity); } }); } public bool GetShowKerdoivPopup(bool IsAlkalmazottPedagogus) { if (!IsAlkalmazottPedagogus) { return false; } return Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NatKerdoivDal(); return dal.GetShowNatKerdoivPopup(IntezmenyId, TanevId, FelhasznaloId); }); } } }