From 13c7bb688c3578f6a65eba3c95c739a62b902f0e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 15:04:39 +0200 Subject: [PATCH] Inizio aggiunta controller editing file --- MP.FileData/Controllers/FileController.cs | 214 ++++++++++++++++------ 1 file changed, 155 insertions(+), 59 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index bf5619a3..76c8245d 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore; using System.Linq; using System.Text; using System.Threading.Tasks; +using MP.FileData.DatabaseModels; namespace MP.FileData.Controllers { @@ -31,63 +32,6 @@ namespace MP.FileData.Controllers #endregion Public Constructors -#if false - /// - /// Elenco Azioni (decodifica) - /// - /// - public List ActionsGetAll() - { - List dbResult = new List(); - - dbResult = dbCtx - .DbSetAzioniUL - .ToList(); - - return dbResult; - } - - /// - /// Elenco tabella Articoli da filtro - /// - /// - /// - /// - public List ArticoliGetSearch(int numRecord, string searchVal = "") - { - List dbResult = new List(); - - dbResult = dbCtx - .DbSetArticoli - .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) - .OrderBy(x => x.CodArticolo) - .Take(numRecord) - .ToList(); - - return dbResult; - } - - /// - /// Elenco tabella Articoli da filtro - /// - /// - /// - /// - public List CommesseGetSearch(int numRecord, string searchVal = "") - { - List dbResult = new List(); - - dbResult = dbCtx - .DbSetODL - .Where(x => x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) - .OrderBy(x => x.KeyRichiesta) - .Take(numRecord) - .ToList(); - - return dbResult; - } -#endif - #region Public Methods /// @@ -181,6 +125,56 @@ namespace MP.FileData.Controllers dbCtx.Dispose(); } + /// + /// ELiminazione file da tabella + /// + /// + /// + public bool FileDelete(FileModel currItem) + { + bool done = false; + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + // eliminazione di uno specifico file + rev da tabella + var file2del = localDbCtx + .DbSetProgFile + .Where(x => x.FileId == currItem.FileId) + .FirstOrDefault(); + localDbCtx + .DbSetProgFile + .Remove(file2del); + + // se ce ne fosse un altro precedente --> lo (ri)attiva + var file2open = localDbCtx + .DbSetProgFile + .Where(x => x.Articolo == currItem.Articolo && x.IdxMacchina == currItem.IdxMacchina) + .OrderByDescending(y => y.Rev) + .FirstOrDefault(); + if (file2open != null) + { + file2open.Active = true; + } + + // salvo! + localDbCtx.SaveChanges(); + done = true; + } + return done; + } + + public FileModel FileGetByKey(int FileId) + { + FileModel thisFile = null; + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + thisFile = localDbCtx + .DbSetProgFile + .Where(x => x.FileId == FileId) + .FirstOrDefault(); + } + return thisFile; + } + public List FileGetByPath(string path, bool onlyActive) { List dbResult = new List(); @@ -195,7 +189,7 @@ namespace MP.FileData.Controllers return dbResult; } - public List FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal = "") + public List FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal = "") { List dbResult = new List(); using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) @@ -204,7 +198,7 @@ namespace MP.FileData.Controllers .DbSetProgFile .Include(m => m.Macchina) .Include(a => a.Articolo) - .Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo == "")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal))) + .Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.CodArticolo == CodArticolo || CodArticolo == "ND" || CodArticolo.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.Changed)) .OrderBy(x => x.Name) .ToList(); } @@ -252,6 +246,108 @@ namespace MP.FileData.Controllers return answ; } + /// + /// Aggiorna un Ordine + /// + /// + /// + public bool FileUpdate(FileModel updItem) + { + bool done = false; + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + { + try + { + FileModel currData = null; + currData = dbCtx + .DbSetProgFile + .Where(x => x.FileId == updItem.FileId) + .FirstOrDefault(); + if (currData != null) + { + //// se ho modificato data --> cambio codice ordine! + //if (!localDbCtx.Entry(updItem).OriginalValues["DtOrder"].Equals(localDbCtx.Entry(updItem).CurrentValues["DtOrder"])) + //{ + // updItem.OrderCode = $"O{updItem.Plant.PlantCode}{updItem.DtOrder:yyMMddHHmm}"; + // updItem.OrderDesc = $"Ordine {updItem.Plant.PlantDesc} - {updItem.DtOrder}"; + //} + localDbCtx.Entry(updItem).State = EntityState.Modified; + localDbCtx.SaveChanges(); + } + else + { + dbCtx + .DbSetProgFile + .Add(updItem); + dbCtx.SaveChanges(); + } + done = true; + } + catch (Exception exc) + { + Log.Error(exc, "Eccezione durante FileUpdate"); + } + } + return done; + } + +#if false + /// + /// Elenco Azioni (decodifica) + /// + /// + public List ActionsGetAll() + { + List dbResult = new List(); + + dbResult = dbCtx + .DbSetAzioniUL + .ToList(); + + return dbResult; + } + + /// + /// Elenco tabella Articoli da filtro + /// + /// + /// + /// + public List ArticoliGetSearch(int numRecord, string searchVal = "") + { + List dbResult = new List(); + + dbResult = dbCtx + .DbSetArticoli + .Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) + .OrderBy(x => x.CodArticolo) + .Take(numRecord) + .ToList(); + + return dbResult; + } + + /// + /// Elenco tabella Articoli da filtro + /// + /// + /// + /// + public List CommesseGetSearch(int numRecord, string searchVal = "") + { + List dbResult = new List(); + + dbResult = dbCtx + .DbSetODL + .Where(x => x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) + .OrderBy(x => x.KeyRichiesta) + .Take(numRecord) + .ToList(); + + return dbResult; + } +#endif + /// /// effettua inserimento di un record in archivio come NUOVO documento tracciato ///