758 lines
29 KiB
C#
758 lines
29 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using NLog;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using MP.FileData.DatabaseModels;
|
|
|
|
namespace MP.FileData.Controllers
|
|
{
|
|
public class FileController : IDisposable
|
|
{
|
|
#region Private Fields
|
|
|
|
private static IConfiguration _configuration;
|
|
private static MoonPro_ProgContext dbCtx;
|
|
private static NLog.Logger Log = LogManager.GetCurrentClassLogger();
|
|
|
|
#endregion Private Fields
|
|
|
|
#region Public Constructors
|
|
|
|
public FileController(IConfiguration configuration)
|
|
{
|
|
_configuration = configuration;
|
|
dbCtx = new MoonPro_ProgContext(configuration);
|
|
Log.Info("Avviata classe FileController");
|
|
}
|
|
|
|
#endregion Public Constructors
|
|
|
|
#region Public Methods
|
|
|
|
/// <summary>
|
|
/// Effettua la comparazione tra i file in archivio ed i file attuali e segna info LastCheck e Changed (se cambiati)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool CheckFileArchived(string idxMacchina, string path, string searchPattern)
|
|
{
|
|
bool answ = false;
|
|
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
|
FileInfo[] fileList = dirInfo.GetFiles(searchPattern);
|
|
List<FileInfo> fileNew = new List<FileInfo>();
|
|
List<FileModel> fileChecked = new List<FileModel>();
|
|
List<FileModel> fileMod = new List<FileModel>();
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
// recupera elenco file nel DB
|
|
var archivedFile = FileGetByPath(path, true);
|
|
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
|
{
|
|
// verifica i file
|
|
foreach (var file in fileList)
|
|
{
|
|
// cerca nel DB...
|
|
FileModel currRecord = archivedFile
|
|
.Where(x => x.Active && x.Path == file.FullName)
|
|
.OrderByDescending(y => y.Rev)
|
|
.FirstOrDefault();
|
|
// se NON trova lo crea
|
|
if (currRecord == null)
|
|
{
|
|
fileNew.Add(file);
|
|
}
|
|
else
|
|
{
|
|
// verifico se data modifica sia cambiata...
|
|
if (currRecord.LastMod != file.LastWriteTime)
|
|
{
|
|
// calcolo e verifico MD5
|
|
var fileContent = File.ReadAllBytes(file.FullName);
|
|
var hash = md5.ComputeHash(fileContent);
|
|
var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
|
if (newMD5 != currRecord.MD5)
|
|
{
|
|
fileMod.Add(currRecord);
|
|
}
|
|
else
|
|
{
|
|
fileChecked.Add(currRecord);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
fileChecked.Add(currRecord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// salvo i NUOVI file
|
|
if (fileNew != null && fileNew.Count > 0)
|
|
{
|
|
FileInsert(idxMacchina, fileNew, 0);
|
|
}
|
|
// aggiorno i file modificati
|
|
if (fileMod != null && fileMod.Count > 0)
|
|
{
|
|
FileSetUpdated(fileMod);
|
|
}
|
|
// segno data-ora ultimo controllo x file invariati
|
|
if (fileChecked != null && fileChecked.Count > 0)
|
|
{
|
|
FileSetChecked(fileChecked);
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
// Clear database context
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
/// <summary>
|
|
/// ELiminazione file da tabella
|
|
/// </summary>
|
|
/// <param name="currItem"></param>
|
|
/// <returns></returns>
|
|
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.Name == currItem.Name && x.IdxMacchina == currItem.IdxMacchina)
|
|
.OrderByDescending(y => y.Rev)
|
|
.FirstOrDefault();
|
|
if (file2open != null)
|
|
{
|
|
file2open.Active = true;
|
|
}
|
|
|
|
// salvo!
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool FileDiskStatusChange(List<FileModel> updFiles, FileState newStatus)
|
|
{
|
|
bool done = false;
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
foreach (var item in updFiles)
|
|
{
|
|
item.DiskStatus = newStatus;
|
|
localDbCtx.Entry(item).State = EntityState.Modified;
|
|
}
|
|
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<DatabaseModels.FileModel> FileGetByPath(string path, bool onlyActive)
|
|
{
|
|
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetProgFile
|
|
.Where(x => x.Path.StartsWith(path) && ((onlyActive == x.Active) || !onlyActive))
|
|
.OrderBy(x => x.Name)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public List<DatabaseModels.FileModel> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal = "")
|
|
{
|
|
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetProgFile
|
|
.Include(m => m.Macchina)
|
|
.Include(t => t.Tags)
|
|
.Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (!OnlyMod || x.DiskStatus != FileState.Ok) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)))
|
|
.OrderByDescending(x => x.LastMod)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua inserimento di un elenco di record in archivio come NUOVO documento tracciato
|
|
/// </summary>
|
|
/// <param name="idxMacchina"></param>
|
|
/// <param name="newFiles"></param>
|
|
/// <param name="rev"></param>
|
|
/// <returns></returns>
|
|
public bool FileInsert(string idxMacchina, List<FileInfo> newFiles, int rev)
|
|
{
|
|
bool answ = false;
|
|
DateTime adesso = DateTime.Now;
|
|
// MD5 hash
|
|
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
|
|
{
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
// converto
|
|
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
|
|
{
|
|
Active = true,
|
|
DiskStatus = FileState.Ok,
|
|
IdxMacchina = idxMacchina,
|
|
LastCheck = adesso,
|
|
LastMod = o.LastWriteTime,
|
|
MimeType = o.Extension,
|
|
Name = o.Name,
|
|
Path = o.FullName,
|
|
Rev = rev,
|
|
Size = o.Length,
|
|
FileContent = File.ReadAllBytes(o.FullName)
|
|
}).ToList();
|
|
|
|
List<string> excludeTags = new List<string>() { "M4", "M5", "M4+A", "M4+B", "M5+A", "M5+B" };
|
|
|
|
// calcolo MD5 e tags
|
|
foreach (var item in newRec)
|
|
{
|
|
var hash = md5.ComputeHash(item.FileContent);
|
|
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
|
|
|
List<string> Tags = new List<string>();
|
|
// cerco codice tag come nome file(TAG) nei primi 500 char
|
|
string code2search = "";
|
|
if (item.FileStringContent.Length > 200)
|
|
{
|
|
code2search = item.FileStringContent.Substring(0, 200);
|
|
}
|
|
else
|
|
{
|
|
code2search = item.FileStringContent;
|
|
}
|
|
Tags = TagsUtils.searchProgComment(item.Name, code2search, excludeTags);
|
|
|
|
//// aggiungo i tags SE non ci fossero
|
|
//item.Tags = Tags;
|
|
}
|
|
|
|
// aggiungo in blocco
|
|
localDbCtx
|
|
.DbSetProgFile
|
|
.AddRange(newRec);
|
|
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
public bool FileModApprove(FileModel currFile)
|
|
{
|
|
bool done = false;
|
|
List<FileInfo> listUpdate = new List<FileInfo>();
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
// rileggo dati file...
|
|
var newFileInfo = new FileInfo(currFile.Path);
|
|
listUpdate.Add(newFileInfo);
|
|
|
|
// inserisco come REVISIONE
|
|
FileInsert(currFile.IdxMacchina, listUpdate, currFile.Rev + 1);
|
|
|
|
// archivio vecchio file
|
|
currFile.Active = false;
|
|
currFile.DiskStatus = FileState.Ok;
|
|
localDbCtx.Entry(currFile).State = EntityState.Modified;
|
|
// salvo DB
|
|
localDbCtx.SaveChanges();
|
|
|
|
done = true;
|
|
}
|
|
return done;
|
|
}
|
|
|
|
public bool FileModReject(FileModel currFile)
|
|
{
|
|
bool done = false;
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
// sovrascrivo il file su disco
|
|
File.WriteAllBytes(currFile.Path, currFile.FileContent);
|
|
|
|
// rileggo file...
|
|
var newFileInfo = new FileInfo(currFile.Path);
|
|
|
|
// aggiorno stato del file a unchanged e data mod ad ora...
|
|
currFile.DiskStatus = FileState.Ok;
|
|
currFile.LastMod = newFileInfo.LastWriteTime;
|
|
localDbCtx.Entry(currFile).State = EntityState.Modified;
|
|
|
|
// salvo DB
|
|
localDbCtx.SaveChanges();
|
|
done = true;
|
|
}
|
|
return done;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update di un record in archivio da lista (SOLO STATUS)
|
|
/// </summary>
|
|
/// <param name="updFiles"></param>
|
|
/// <returns></returns>
|
|
public bool FileSetChecked(List<FileModel> updFiles)
|
|
{
|
|
bool answ = false;
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
foreach (var item in updFiles)
|
|
{
|
|
item.LastCheck = adesso;
|
|
localDbCtx.Entry(item).State = EntityState.Modified;
|
|
}
|
|
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Effettua update di un record in archivio da lista (SOLO STATUS)
|
|
/// </summary>
|
|
/// <param name="updFiles"></param>
|
|
/// <returns></returns>
|
|
public bool FileSetUpdated(List<FileModel> updFiles)
|
|
{
|
|
bool answ = false;
|
|
DateTime adesso = DateTime.Now;
|
|
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
foreach (var item in updFiles)
|
|
{
|
|
item.DiskStatus = FileState.Changed;
|
|
item.LastCheck = adesso;
|
|
localDbCtx.Entry(item).State = EntityState.Modified;
|
|
}
|
|
|
|
// salvo
|
|
localDbCtx.SaveChanges();
|
|
answ = true;
|
|
}
|
|
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Aggiorna un Ordine
|
|
/// </summary>
|
|
/// <param name="updItem"></param>
|
|
/// <returns></returns>
|
|
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)
|
|
{
|
|
updItem.DiskStatus = FileState.Changed;
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Macchine
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.MacchinaModel> MacchineGetAll()
|
|
{
|
|
List<DatabaseModels.MacchinaModel> dbResult = new List<DatabaseModels.MacchinaModel>();
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetMacchine
|
|
.OrderBy(x => x.IdxMacchina)
|
|
.ToList();
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
public void ResetController()
|
|
{
|
|
dbCtx = new MoonPro_ProgContext(_configuration);
|
|
Log.Info("Effettuato reset FileController");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Annulla modifiche su una specifica entity (cancel update)
|
|
/// </summary>
|
|
/// <param name="item"></param>
|
|
/// <returns></returns>
|
|
public bool RollBackEntity(object item)
|
|
{
|
|
bool answ = false;
|
|
try
|
|
{
|
|
if (dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Deleted || dbCtx.Entry(item).State == Microsoft.EntityFrameworkCore.EntityState.Modified)
|
|
{
|
|
dbCtx.Entry(item).Reload();
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
Log.Error($"Eccezione in rollBackEntity{Environment.NewLine}{exc}");
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco TAGS (FILTRATO!!!)
|
|
/// </summary>
|
|
/// <param name="searchVal"></param>
|
|
/// <param name="maxNum"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.TagModel> TagGetFilt(string searchVal, int maxNum = 100)
|
|
{
|
|
maxNum = maxNum <= 0 ? 100 : maxNum;
|
|
List<DatabaseModels.TagModel> dbResult = new List<DatabaseModels.TagModel>();
|
|
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
|
{
|
|
int totRecord = localDbCtx
|
|
.DbSetTags
|
|
.Where(x => x.TagId.Contains(searchVal))
|
|
.Count();
|
|
if (totRecord > maxNum)
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetTags
|
|
.Where(x => x.TagId.Contains(searchVal))
|
|
.OrderBy(x => x.TagId)
|
|
.Take(maxNum)
|
|
.ToList();
|
|
dbResult.Add(new DatabaseModels.TagModel() { TagId = $"... +{totRecord - maxNum} rec ..." });
|
|
}
|
|
else
|
|
{
|
|
dbResult = localDbCtx
|
|
.DbSetTags
|
|
.Where(x => x.TagId.Contains(searchVal))
|
|
.OrderBy(x => x.TagId)
|
|
.ToList();
|
|
}
|
|
}
|
|
return dbResult;
|
|
}
|
|
|
|
#endregion Public Methods
|
|
|
|
#if false
|
|
/// <summary>
|
|
/// Elenco Azioni (decodifica)
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.AzioniUL> ActionsGetAll()
|
|
{
|
|
List<DatabaseModels.AzioniUL> dbResult = new List<DatabaseModels.AzioniUL>();
|
|
|
|
dbResult = dbCtx
|
|
.DbSetAzioniUL
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Articoli da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.AnagArticoli> ArticoliGetSearch(int numRecord, string searchVal = "")
|
|
{
|
|
List<DatabaseModels.AnagArticoli> dbResult = new List<DatabaseModels.AnagArticoli>();
|
|
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella Articoli da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.ODL> CommesseGetSearch(int numRecord, string searchVal = "")
|
|
{
|
|
List<DatabaseModels.ODL> dbResult = new List<DatabaseModels.ODL>();
|
|
|
|
dbResult = dbCtx
|
|
.DbSetODL
|
|
.Where(x => x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
|
.OrderBy(x => x.KeyRichiesta)
|
|
.Take(numRecord)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
#endif
|
|
#if false
|
|
/// <summary>
|
|
/// Elenco tabella controlli da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.ResControlli> StatControlliGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
List<DatabaseModels.ResControlli> dbResult = new List<DatabaseModels.ResControlli>();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetControlli
|
|
.FromSqlRaw("EXEC stp_UI_RC_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella DDB da filtro
|
|
/// </summary>
|
|
/// <param name="DataStart"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="IdxODL"></param>
|
|
/// <param name="KeyRichiesta"></param>
|
|
/// <param name="CodArticolo"></param>
|
|
/// <param name="FirstRecord"></param>
|
|
/// <param name="NumRecord"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.DdbTurni> StatDdbGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, int FirstRecord, int NumRecord)
|
|
{
|
|
List<DatabaseModels.DdbTurni> dbResult = new List<DatabaseModels.DdbTurni>();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
var firstRecord = new SqlParameter("@FirstRecord", FirstRecord);
|
|
var numRecord = new SqlParameter("@NumRecord", NumRecord);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetDdbTurni
|
|
.FromSqlRaw("EXEC stp_UI_DDBTurni_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo,@FirstRecord,@NumRecord", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo, firstRecord, numRecord)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella DDB da filtro
|
|
/// </summary>
|
|
/// <param name="DataStart"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="IdxODL"></param>
|
|
/// <param name="KeyRichiesta"></param>
|
|
/// <param name="CodArticolo"></param>
|
|
/// <returns></returns>
|
|
public int StatDdbGetCount(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
var dbResult = dbCtx
|
|
.DbSetDdbTurni
|
|
.Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "*") && (x.IdxOdl == IdxODL || IdxODL == -999) && (x.KeyRichiesta == KeyRichiesta || KeyRichiesta == "*") && (x.CodArticolo == CodArticolo || CodArticolo == "*") && (x.InizioPeriodo >= DataStart && x.InizioPeriodo <= DataEnd))
|
|
.Count();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella ODL da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.ODL> StatOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
List<DatabaseModels.ODL> dbResult = new List<DatabaseModels.ODL>();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetODL
|
|
.FromSqlRaw("EXEC stp_UI_Odl_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella scarti da filtro
|
|
/// </summary>
|
|
/// <param name="DataStart"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.ResScarti> StatScartiGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
List<DatabaseModels.ResScarti> dbResult = new List<DatabaseModels.ResScarti>();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetScarti
|
|
.FromSqlRaw("EXEC stp_UI_RS_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella TurniOee da filtro
|
|
/// </summary>
|
|
/// <param name="DataStart"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <param name="IdxMacchina"></param>
|
|
/// <param name="DataEnd"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.TurniOee> StatTurniOeeGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
List<DatabaseModels.TurniOee> dbResult = new List<DatabaseModels.TurniOee>();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetTurniOee
|
|
.FromSqlRaw("EXEC stp_UI_TurniOee_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco tabella UserLog da filtro
|
|
/// </summary>
|
|
/// <param name="numRecord"></param>
|
|
/// <param name="searchVal"></param>
|
|
/// <returns></returns>
|
|
public List<DatabaseModels.UserActionLog> StatUserLogGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo)
|
|
{
|
|
List<DatabaseModels.UserActionLog> dbResult = new List<DatabaseModels.UserActionLog>();
|
|
|
|
//dbResult = dbCtx
|
|
// .DbSetUserLog
|
|
// .Where(x => x.Valore.Contains(searchVal) || x.Cognome.Contains(searchVal) || x.CodArticolo.Contains(searchVal) || string.IsNullOrEmpty(searchVal))
|
|
// .OrderByDescending(x => x.DataOraRif)
|
|
// .Take(numRecord)
|
|
// .ToList();
|
|
|
|
var dataFrom = new SqlParameter("@dataFrom", DataStart);
|
|
var dataTo = new SqlParameter("@dataTo", DataEnd);
|
|
var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina);
|
|
var idxODL = new SqlParameter("@IdxODL", IdxODL);
|
|
var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta);
|
|
var codArticolo = new SqlParameter("@CodArticolo", CodArticolo);
|
|
|
|
dbResult = dbCtx
|
|
.DbSetUserLog
|
|
.FromSqlRaw("EXEC stp_UI_UL_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo)
|
|
.ToList();
|
|
|
|
return dbResult;
|
|
}
|
|
#endif
|
|
}
|
|
} |