296 lines
9.4 KiB
C#
296 lines
9.4 KiB
C#
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Kreta.DataAccess.Interfaces;
|
|
using Kreta.DataAccessManual.Interfaces;
|
|
using Kreta.DataAccessManual.ParameterClasses;
|
|
using Kreta.DataAccessManual.Util;
|
|
using Kreta.Framework;
|
|
using Kreta.Framework.Util;
|
|
using SDA.DataProvider;
|
|
using SDA.Kreta.Entities;
|
|
|
|
namespace Kreta.DataAccessManual
|
|
{
|
|
internal class EszkozDAL : DataAccessBase, IEszkozDal
|
|
{
|
|
public EszkozDAL(DalHandler handler, GridParameters parameters) : base(handler, parameters) { }
|
|
|
|
public EszkozDAL(DalHandler handler) : base(handler) { }
|
|
|
|
#region BaseCRUD
|
|
|
|
public IEszkoz Get()
|
|
{
|
|
return Eszkoz.GiveAnInstance();
|
|
}
|
|
|
|
public IEszkoz Get(int id)
|
|
{
|
|
var entity = Eszkoz.GiveAnInstance();
|
|
entity.LoadByID(id);
|
|
return entity;
|
|
}
|
|
|
|
public void Insert(IEszkoz dto)
|
|
{
|
|
var entity = dto as Eszkoz;
|
|
entity.Importalt = false;
|
|
entity.Insert();
|
|
dto.ID = entity.ID;
|
|
FollowUp(entity);
|
|
DalHelper.Commit();
|
|
}
|
|
|
|
public void Update(IEszkoz dto)
|
|
{
|
|
var entity = dto as Eszkoz;
|
|
entity.Importalt = false;
|
|
entity.Update();
|
|
FollowUp(entity);
|
|
DalHelper.Commit();
|
|
}
|
|
|
|
public void FullUpdate(IEszkoz entity)
|
|
{
|
|
entity.Importalt = false;
|
|
((Eszkoz)entity).FullUpdate();
|
|
FollowUp(entity);
|
|
DalHelper.Commit();
|
|
}
|
|
|
|
public void Delete(int id)
|
|
{
|
|
var oEszkoz = Eszkoz.GiveAnInstance();
|
|
oEszkoz.LoadByID(id);
|
|
|
|
oEszkoz.Importalt = false;
|
|
oEszkoz.Delete();
|
|
DalHelper.Commit();
|
|
}
|
|
|
|
public void Delete(IEszkoz dto)
|
|
{
|
|
var entity = dto as Eszkoz;
|
|
entity.Delete();
|
|
DalHelper.Commit();
|
|
}
|
|
|
|
#endregion
|
|
|
|
public bool GetEszkozByName(string eszkozName, int tanevId, int? id, int teremId, int jelleg)
|
|
{
|
|
int? eszkozId = id ?? -1;
|
|
using (SDACommand command = new SDACommand())
|
|
{
|
|
command.Connection = UserContext.Instance.SDAConnection;
|
|
command.Transaction = UserContext.Instance.SDATransaction;
|
|
command.CommandText = @"SELECT C_NEV, C_JELLEGE, C_TEREMID FROM T_ESZKOZ_OSSZES WHERE TOROLT = 'F'
|
|
AND
|
|
(
|
|
(@pJelleg <> 1076 AND C_NEV = @pEszkozName AND ID <> @pEszkozId AND C_TANEVID = @pTanevId)
|
|
or
|
|
(@pJelleg = 1076 AND
|
|
(
|
|
(C_NEV = @pEszkozName AND ID <> @pEszkozId AND C_TANEVID = @pTanevId AND C_JELLEGE <> 1076)
|
|
OR
|
|
(C_NEV = @pEszkozName AND ID <> @pEszkozId AND C_TANEVID = @pTanevId AND C_TEREMID = @pTeremId AND C_JELLEGE = 1076)
|
|
)
|
|
)
|
|
)";
|
|
command.Parameters.Add("pEszkozName", eszkozName);
|
|
command.Parameters.Add("pEszkozId", eszkozId);
|
|
command.Parameters.Add("pTanevId", tanevId);
|
|
command.Parameters.Add("pTeremId", teremId);
|
|
command.Parameters.Add("pJelleg", jelleg);
|
|
|
|
var result = command.ExecuteScalar();
|
|
if (result != null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool GetEszkozByIds(string eszkozIdString, int tanevId, int teremId)
|
|
{
|
|
using (SDACommand command = new SDACommand())
|
|
{
|
|
command.Connection = UserContext.Instance.SDAConnection;
|
|
command.Transaction = UserContext.Instance.SDATransaction;
|
|
command.CommandText = $@"
|
|
SELECT
|
|
C_NEV
|
|
,C_JELLEGE
|
|
,C_TEREMID
|
|
FROM T_ESZKOZ_OSSZES
|
|
WHERE
|
|
TOROLT = 'F'
|
|
AND
|
|
((ID in ({eszkozIdString}) AND C_TANEVID = @pTanevId AND C_TEREMID = @pTeremId AND C_JELLEGE = 1076))";
|
|
|
|
command.Parameters.Add("pTanevId", tanevId);
|
|
command.Parameters.Add("pTeremId", teremId);
|
|
|
|
var result = command.ExecuteScalar();
|
|
if (result != null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void FollowUpEszkoz(int intezmenyId, int aktTanevId, int kovetkezoTanevId, int eszkozId)
|
|
{
|
|
using (SDACommand command = new SDACommand())
|
|
{
|
|
command.Connection = UserContext.Instance.SDAConnection;
|
|
command.Transaction = UserContext.Instance.SDATransaction;
|
|
command.CommandText = "uspFollowUpEszkoz";
|
|
command.Parameters.Add("intezmenyId", intezmenyId);
|
|
command.Parameters.Add("aktTanevId", aktTanevId);
|
|
command.Parameters.Add("kovetkezoTanevId", kovetkezoTanevId);
|
|
command.Parameters.Add("eszkozId", eszkozId);
|
|
command.CommandType = CommandType.StoredProcedure;
|
|
command.ExecuteNonQuery();
|
|
DalHelper.Commit();
|
|
}
|
|
}
|
|
|
|
public DataSet EszkozKereses(EszkozokSearchPco pco)
|
|
{
|
|
var ds = GetEszkozokDataSet(pco, true);
|
|
return ds;
|
|
}
|
|
|
|
public DataSet EszkozKeresesExport(EszkozokSearchPco pco)
|
|
{
|
|
var ds = GetEszkozokDataSet(pco, false);
|
|
return ds;
|
|
}
|
|
|
|
public DataSet GetEszkozDataSet(int tanevId)
|
|
{
|
|
var pco = new EszkozokSearchPco
|
|
{
|
|
TanevId = tanevId
|
|
};
|
|
|
|
var ds = GetEszkozokDataSet(pco, false);
|
|
return ds;
|
|
}
|
|
|
|
public DataSet GetEszkozokWhereTeremID(int teremId, int tanevId)
|
|
{
|
|
var pco = new EszkozokSearchPco
|
|
{
|
|
TanevId = tanevId,
|
|
TeremId = teremId
|
|
};
|
|
|
|
var ds = GetEszkozokDataSet(pco, false, simpleResult: true);
|
|
|
|
return ds;
|
|
}
|
|
|
|
/// <summary>
|
|
/// A szűrőparaméterek alapján SP használatával lekérdezi az Eszközök DataSet-et!
|
|
/// </summary>
|
|
/// <param name="pco">Szűrő paraméterek</param>
|
|
/// <param name="needPaging">Szükség van-e lapozáásra az SP-ben</param>
|
|
/// <param name="isExcelExport">ExcelExport-hoz fut-e a lekérdezés</param>
|
|
/// <returns></returns>
|
|
private DataSet GetEszkozokDataSet(EszkozokSearchPco pco, bool needPaging, bool simpleResult = false, bool isExcelExport = false)
|
|
{
|
|
var parameters = SetParametersForEszkozSearch(pco);
|
|
var dnameColumns = "TipusId,KategoriaId,CeljaId,JellegeId,MennyisegiEgysegId";
|
|
|
|
using (var cmd = new SDACommand())
|
|
{
|
|
cmd.Connection = UserContext.Instance.SDAConnection;
|
|
cmd.Transaction = UserContext.Instance.SDATransaction;
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|
|
|
cmd.CommandText = "uspGetEszkoz";
|
|
|
|
foreach (var param in parameters)
|
|
{
|
|
cmd.Parameters.Add(param.Name, param.Value);
|
|
}
|
|
|
|
if (isExcelExport)
|
|
{
|
|
cmd.Parameters.Add("IsExport", true);
|
|
}
|
|
|
|
if (simpleResult)
|
|
{
|
|
cmd.Parameters.Add("SimpleResult", true);
|
|
dnameColumns = "TipusId";
|
|
}
|
|
|
|
var ds = new DataSet();
|
|
using (var adapter = new SDADataAdapter())
|
|
{
|
|
adapter.SelectCommand = cmd;
|
|
adapter.Fill(ds);
|
|
}
|
|
|
|
SetDNAME(ds.Tables[0], dnameColumns);
|
|
|
|
if (needPaging && GridParameters != null)
|
|
{
|
|
ds = SortingAndPaging(ds.Tables[0], GridParameters).AsDataSet();
|
|
}
|
|
|
|
return ds;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Keresési feltételek összeállítása az SP részére. A paraméternevek az SP-ben lévőkkel kell, hogy egyezzenek!
|
|
/// </summary>
|
|
private IList<CommandParameter> SetParametersForEszkozSearch(EszkozokSearchPco pco)
|
|
{
|
|
var parameters = new List<CommandParameter>
|
|
{
|
|
new CommandParameter("pTanevId", pco.TanevId)
|
|
};
|
|
|
|
if (pco.TeremId.HasValue)
|
|
{
|
|
parameters.Add(new CommandParameter("pTeremId", pco.TeremId.Value));
|
|
}
|
|
|
|
if (pco.FelelosId.HasValue)
|
|
{
|
|
parameters.Add(new CommandParameter("pFelelosId", pco.FelelosId.Value));
|
|
}
|
|
|
|
if (pco.KategoriaId.HasValue)
|
|
{
|
|
parameters.Add(new CommandParameter("pKategoriaId", pco.KategoriaId.Value));
|
|
}
|
|
|
|
if (pco.MinDarabszam.HasValue)
|
|
{
|
|
parameters.Add(new CommandParameter("pMinDarabszam", pco.MinDarabszam.Value));
|
|
}
|
|
|
|
if (pco.MaxDarabszam.HasValue)
|
|
{
|
|
parameters.Add(new CommandParameter("pMaxDarabszam", pco.MaxDarabszam.Value));
|
|
}
|
|
|
|
if (!string.IsNullOrWhiteSpace(pco.Nev))
|
|
{
|
|
parameters.Add(new CommandParameter("pNev", pco.Nev));
|
|
}
|
|
|
|
return parameters;
|
|
}
|
|
}
|
|
}
|