986 lines
35 KiB
C#
986 lines
35 KiB
C#
using Microsoft.Data.SqlClient;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
using StockMan.Data.DbModels;
|
|
|
|
namespace StockMan.Data.Controllers
|
|
{
|
|
public class StoManController : IDisposable
|
|
{
|
|
#region Public Constructors
|
|
|
|
public StoManController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
Log.Info("Avviata classe StoManController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Conferma movimenti
|
|
/// </summary>
|
|
/// <param name="itemID"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> ConfermaMov(int itemID)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new StockManContext(_configuration))
|
|
{
|
|
var ItemID = new SqlParameter("@ItemID", itemID);
|
|
|
|
var callResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_ItemConsolidate @ItemID", ItemID);
|
|
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Contatori
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<CountersListModel> CountersGetAll()
|
|
{
|
|
List<CountersListModel> dbResult = new List<CountersListModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetCountersList
|
|
.OrderBy(x => x.Id)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Flux Delete
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> DeleteFlux(ItemFluxModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var dbResult = localDbCtx
|
|
.DbSetItemFlux
|
|
.Where(x => x.Id == currRec.Id)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFlux
|
|
.Remove(dbResult);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante DeleteFlux{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
GC.Collect();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elimina movimenti duplicati
|
|
/// </summary>
|
|
/// <param name="itemID"></param>
|
|
/// <returns></returns>
|
|
public async Task<bool> EliminaDup(int itemID)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new StockManContext(_configuration))
|
|
{
|
|
var ItemID = new SqlParameter("@ItemID", itemID);
|
|
|
|
var callResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_ItemShrinkHist @ItemID", ItemID);
|
|
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// aggiunta item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> FluxAdd(ItemFluxModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
List<ItemFluxModel> dbResult = new List<ItemFluxModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItemFlux
|
|
.Where(x => x.Id == newRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
fatto = false;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFlux
|
|
.Add(newRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante FluxAdd{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifica flux
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> FluxMod(ItemFluxModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
//List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItemFlux
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.ItemId = editRec.ItemId;
|
|
currRec.LocationId = editRec.LocationId;
|
|
currRec.MovTypeId = editRec.MovTypeId;
|
|
currRec.ExtLocationId = editRec.ExtLocationId;
|
|
currRec.DtMov = editRec.DtMov;
|
|
currRec.Qta = editRec.Qta;
|
|
currRec.TotValue = editRec.TotValue;
|
|
currRec.OperatorId = "ND";
|
|
currRec.Note = editRec.Note;
|
|
currRec.CodDoc = editRec.CodDoc;
|
|
currRec.ModOperatorId = "ND";
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFlux
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante FluxMod;{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// aggiunta item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemAdd(ItemModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => x.Id == newRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
fatto = false;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItem
|
|
.Add(newRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ItemAdd{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiunta famiglia di item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemFamilyAdd(ItemFamilyModel newRec)
|
|
{
|
|
bool fatto = false;
|
|
List<ItemFamilyModel> dbResult = new List<ItemFamilyModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItemFamily
|
|
.Where(x => x.Id == newRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
fatto = false;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFamily
|
|
.Add(newRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ItemFamilyAdd{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Items
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemFamilyDeleteByID(ItemFamilyModel currRec)
|
|
{
|
|
bool fatto = false;
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var dbResult = localDbCtx
|
|
.DbSetItemFamily
|
|
.Where(x => x.Id == currRec.Id)
|
|
.FirstOrDefault();
|
|
if (dbResult != null)
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFamily
|
|
.Remove(dbResult);
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ItemFamilyDeleteByID{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Famiglie Articoli
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemFamilyModel> ItemFamilyGetAll()
|
|
{
|
|
List<ItemFamilyModel> dbResult = new List<ItemFamilyModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemFamily
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Famiglie Articoli da ricerca
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemFamilyModel> ItemFamilyGetSearch(string searchVal)
|
|
{
|
|
List<ItemFamilyModel> dbResult = new List<ItemFamilyModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemFamily
|
|
.Where(x => x.Descr.Contains(searchVal))
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifica famiglia articoli
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemFamilyMod(ItemFamilyModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
List<ItemFamilyModel> dbResult = new List<ItemFamilyModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItemFamily
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Descr = editRec.Descr;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItemFamily
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ItemFamilyMod{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Flux x item
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemFluxModel> ItemFluxGetById(int id)
|
|
{
|
|
List<ItemFluxModel> dbResult = new List<ItemFluxModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemFlux
|
|
.Include(l => l.Location)
|
|
.Include(e => e.ExtLocation)
|
|
.Where(x => x.ItemId == id)
|
|
.OrderByDescending(x => x.Id)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifica item,
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> ItemMod(ItemModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
//List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Descr = editRec.Descr;
|
|
currRec.CodInt = editRec.CodInt;
|
|
currRec.ItemFamilyId = editRec.ItemFamilyId;
|
|
currRec.CodExt = editRec.CodExt;
|
|
currRec.DescrExt = editRec.DescrExt;
|
|
currRec.QtaMin = editRec.QtaMin;
|
|
currRec.QtaBatch = editRec.QtaBatch;
|
|
currRec.CurrValue = editRec.CurrValue;
|
|
currRec.QtaCurr = editRec.QtaCurr;
|
|
currRec.QtaPend = editRec.QtaPend;
|
|
currRec.Um = editRec.Um;
|
|
localDbCtx.Entry(currRec).State = EntityState.Modified;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetItem
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante ItemMod{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Items
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemModel> ItemsGetAll()
|
|
{
|
|
List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItem
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Items da ricerca
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemModel> ItemsGetByID(int id)
|
|
{
|
|
List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
var risultato = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => ((x.Id == id)))
|
|
.ToList();
|
|
|
|
if (risultato != null)
|
|
{
|
|
dbResult = risultato;
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Items da ricerca
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemStockModel> ItemsGetByLocation(string locationSel)
|
|
{
|
|
List<ItemStockModel> dbResult = new List<ItemStockModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemStock
|
|
.Where(x => x.LocationId == locationSel)
|
|
.Include(l => l.ItemNav)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
///// <summary>
|
|
///// Lista Items da ricerca
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//public List<ItemModel> ItemsGetSearch(string searchVal, string famID)
|
|
//{
|
|
// List<ItemModel> dbResult = new List<ItemModel>();
|
|
// using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
// {
|
|
// dbResult = localDbCtx
|
|
// .DbSetItem
|
|
// .Where(x => (x.ItemFamilyId == famID || string.IsNullOrEmpty(famID)) && (x.CodExt.Contains(searchVal) || x.Descr.Contains(searchVal) || x.DescrExt.Contains(searchVal) || string.IsNullOrEmpty(searchVal)))
|
|
// .OrderBy(x => x.Descr)
|
|
// .ToList();
|
|
// }
|
|
// return dbResult;
|
|
//}
|
|
/// <summary>
|
|
/// Lista Items da ricerca
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemModel> ItemsGetSearch(string searchVal, string itemFamId)
|
|
{
|
|
List<ItemModel> dbResult = new List<ItemModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
if (!string.IsNullOrEmpty(searchVal) && itemFamId == "*")
|
|
{
|
|
var risultato = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => ((x.Id.ToString() == searchVal)) || (x.CodInt.Contains(searchVal)) || (x.CodExt.Contains(searchVal)) || (x.Descr.Contains(searchVal) || (x.CurrValue.ToString().Contains(searchVal))))
|
|
.ToList();
|
|
|
|
if (risultato != null)
|
|
{
|
|
dbResult = risultato;
|
|
}
|
|
}
|
|
else if (itemFamId != "*" && string.IsNullOrEmpty(searchVal))
|
|
{
|
|
var risultato = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => ((x.ItemFamilyId == itemFamId)))
|
|
.ToList();
|
|
|
|
if (risultato != null)
|
|
{
|
|
dbResult = risultato;
|
|
}
|
|
}
|
|
else if (itemFamId != "*" && !string.IsNullOrEmpty(searchVal))
|
|
{
|
|
var risultato = localDbCtx
|
|
.DbSetItem
|
|
.Where(x => ((x.ItemFamilyId == itemFamId) && ((x.CodInt.Contains(searchVal)) || (x.CodExt.Contains(searchVal)) || (x.Descr.Contains(searchVal) || (x.CurrValue.ToString().Contains(searchVal))))))
|
|
.ToList();
|
|
|
|
if (risultato != null)
|
|
{
|
|
dbResult = risultato;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItem
|
|
.OrderBy(x => x.Id)
|
|
.ToList();
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Item Stock (ALL!)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<ItemStockModel> ItemsStockGetAll()
|
|
{
|
|
List<ItemStockModel> dbResult = new List<ItemStockModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemStock
|
|
.OrderBy(x => x.Id)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Item Stock (By ID)
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <returns></returns>
|
|
public List<ItemStockModel> ItemsStockGetById(int ItemID)
|
|
{
|
|
List<ItemStockModel> dbResult = new List<ItemStockModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetItemStock
|
|
.Where(x => x.ItemId == ItemID)
|
|
.OrderBy(x => x.Id)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiungi Locazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> LocationAddNew(LocationModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
List<LocationModel> dbResult = new List<LocationModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetLocation
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
fatto = false;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetLocation
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante LocationAddNew{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Locazioni
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<LocationModel> LocationGetAll()
|
|
{
|
|
List<LocationModel> dbResult = new List<LocationModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLocation
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Locazioni join con tabella location type
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<LocationModel> LocationGetLocType()
|
|
{
|
|
List<LocationModel> dbResult = new List<LocationModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLocation
|
|
.Include(l => l.LocTypeNav)
|
|
.Where(x => x.LocTypeNav.IsStock)
|
|
.OrderBy(x => x.Id)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Modifica Locazione
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> LocationMod(LocationModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
List<LocationModel> dbResult = new List<LocationModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetLocation
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.Descr = editRec.Descr;
|
|
currRec.LocTypeId = editRec.LocTypeId;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetLocation
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante LocationMod{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Tipi Locazioni
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<LocTypeModel> LocTypeGetAll()
|
|
{
|
|
List<LocTypeModel> dbResult = new List<LocTypeModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetLocType
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Muove gli items nei vari scaffali
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> MoveItems(int stockId, string locationIdFrom, string locationIdTo, string oprId)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new StockManContext(_configuration))
|
|
{
|
|
var StockId = new SqlParameter("@StockID", stockId);
|
|
var LocationIdFrom = new SqlParameter("@LocationID_FROM", locationIdFrom);
|
|
var LocationIdTo = new SqlParameter("@LocationID_TO", locationIdTo);
|
|
var OprId = new SqlParameter("@OperatorID", oprId);
|
|
|
|
var callResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec dbo.stp_ItemStockMove @StockID, @LocationID_FROM, @LocationID_TO, @OperatorID", StockId, LocationIdFrom, LocationIdTo, OprId);
|
|
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Muove gli items nei vari scaffali
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> MoveItems_New(int stockId, string locationIdFrom, string locationIdTo, string oprId, int qtyMov)
|
|
{
|
|
bool answ = false;
|
|
using (var dbCtx = new StockManContext(_configuration))
|
|
{
|
|
var StockId = new SqlParameter("@StockID", stockId);
|
|
var LocationIdFrom = new SqlParameter("@LocationID_FROM", locationIdFrom);
|
|
var LocationIdTo = new SqlParameter("@LocationID_TO", locationIdTo);
|
|
var OprId = new SqlParameter("@OperatorID", oprId);
|
|
var QtyMov = new SqlParameter("@QtyMov", qtyMov);
|
|
|
|
var callResult = await dbCtx
|
|
.Database
|
|
.ExecuteSqlRawAsync("exec stp_ItemStockMove_New @StockID, @LocationID_FROM, @LocationID_TO, @OperatorID, @QtyMov", StockId, LocationIdFrom, LocationIdTo, OprId, QtyMov);
|
|
|
|
answ = true;
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Tipi Movimenti
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<MovTypeModel> MovTypeGetAll()
|
|
{
|
|
List<MovTypeModel> dbResult = new List<MovTypeModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetMovType
|
|
.OrderBy(x => x.Descr)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
//}
|
|
/// <summary>
|
|
/// Aggiungi Operatore
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> OperatorAddNew(OperatorModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
List<OperatorModel> dbResult = new List<OperatorModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetOperator
|
|
.Where(x => x.CodExt == editRec.CodExt)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
fatto = false;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetOperator
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
///// <summary>
|
|
///// Modifica Famiglie Articoli
|
|
///// </summary>
|
|
///// <returns></returns>
|
|
//public List<ItemFamilyModel> ItemFamilyMod()
|
|
//{
|
|
// List<ItemFamilyModel> dbResult = new List<ItemFamilyModel>();
|
|
// using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
// {
|
|
// dbResult = localDbCtx
|
|
// .DbSetItemFamily
|
|
// .OrderBy(x => x.Descr)
|
|
// .ToList();
|
|
// }
|
|
// return dbResult;
|
|
/// <summary>
|
|
/// Modifica Operatore
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public async Task<bool> OperatorMod(OperatorModel editRec)
|
|
{
|
|
bool fatto = false;
|
|
List<OperatorModel> dbResult = new List<OperatorModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
try
|
|
{
|
|
var currRec = localDbCtx
|
|
.DbSetOperator
|
|
.Where(x => x.Id == editRec.Id)
|
|
.FirstOrDefault();
|
|
if (currRec != null)
|
|
{
|
|
currRec.CodExt = editRec.CodExt;
|
|
currRec.LastName = editRec.LastName;
|
|
currRec.FirstName = editRec.FirstName;
|
|
}
|
|
else
|
|
{
|
|
localDbCtx
|
|
.DbSetOperator
|
|
.Add(editRec);
|
|
}
|
|
await localDbCtx.SaveChangesAsync();
|
|
fatto = true;
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione durante OperatorMod{Environment.NewLine}{exc}");
|
|
}
|
|
}
|
|
return fatto;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Operatori
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<OperatorModel> OperatorsGetAll()
|
|
{
|
|
List<OperatorModel> dbResult = new List<OperatorModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetOperator
|
|
.OrderBy(x => x.LastName)
|
|
.ThenBy(x => x.FirstName)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Operatore cercato
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public OperatorModel OperatorsGetByCodExt(string codExt)
|
|
{
|
|
OperatorModel dbResult = new OperatorModel();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
var risultato = localDbCtx
|
|
.DbSetOperator
|
|
.Where(x => x.CodExt == codExt)
|
|
.OrderBy(x => x.LastName)
|
|
.ThenBy(x => x.FirstName)
|
|
.FirstOrDefault();
|
|
|
|
if (risultato != null)
|
|
{
|
|
dbResult = risultato;
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Permessi
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<PermessiModel> PermessiGetAll()
|
|
{
|
|
List<PermessiModel> dbResult = new List<PermessiModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetPermessi
|
|
.OrderBy(x => x.GRUPPO)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Lista Item Stock (raggruppati x location)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<VLocationValModel> StockStatus()
|
|
{
|
|
List<VLocationValModel> dbResult = new List<VLocationValModel>();
|
|
using (StockManContext localDbCtx = new StockManContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetVLocationVal
|
|
.Include(l => l.LocationNav)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration = null!;
|
|
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
}
|
|
} |