Merge branch 'feature/ArchivioFilePage' into develop
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -98,31 +100,79 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
maxNum = maxNum <= 0 ? 100 : maxNum;
|
||||
List<DatabaseModels.ArticoloModel> dbResult = new List<DatabaseModels.ArticoloModel>();
|
||||
|
||||
int totRecord = dbCtx
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
int totRecord = localDbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.Count();
|
||||
if (totRecord > maxNum)
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.OrderBy(x => x.DescArticolo)
|
||||
.Take(maxNum)
|
||||
.ToList();
|
||||
dbResult.Add(new DatabaseModels.ArticoloModel() { CodArticolo = "#####", DescArticolo = $"... +{totRecord - maxNum} rec ..." });
|
||||
if (totRecord > maxNum)
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.OrderBy(x => x.DescArticolo)
|
||||
.Take(maxNum)
|
||||
.ToList();
|
||||
dbResult.Add(new DatabaseModels.ArticoloModel() { CodArticolo = "#####", DescArticolo = $"... +{totRecord - maxNum} rec ..." });
|
||||
}
|
||||
else
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.OrderBy(x => x.DescArticolo)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
else
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <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("*.*");
|
||||
List<FileInfo> fileNew = new List<FileInfo>();
|
||||
List<FileInfo> fileMod = new List<FileInfo>();
|
||||
|
||||
// recupera elenco file nel DB
|
||||
var archivedFile = FileGetByPath(path, true);
|
||||
|
||||
// verifica i file
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
dbResult = dbCtx
|
||||
.DbSetArticoli
|
||||
.Where(x => x.CodArticolo.Contains(searchVal) || x.DescArticolo.Contains(searchVal) || x.Disegno.Contains(searchVal))
|
||||
.OrderBy(x => x.DescArticolo)
|
||||
.ToList();
|
||||
// cerca nel DB...
|
||||
var currRecord = archivedFile
|
||||
.Where(x => x.Path == file.FullName)
|
||||
.FirstOrDefault();
|
||||
// se NON trova lo crea
|
||||
if (currRecord == null)
|
||||
{
|
||||
fileNew.Add(file);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileMod.Add(file);
|
||||
}
|
||||
}
|
||||
|
||||
return dbResult;
|
||||
// salvo i NUOVI file
|
||||
if (fileNew != null && fileNew.Count > 0)
|
||||
{
|
||||
FileInsert(idxMacchina, fileNew);
|
||||
}
|
||||
// aggiorno i file modificati
|
||||
if (fileMod != null && fileMod.Count > 0)
|
||||
{
|
||||
FileUpdate(idxMacchina, fileMod);
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
@@ -131,19 +181,118 @@ namespace MP.FileData.Controllers
|
||||
dbCtx.Dispose();
|
||||
}
|
||||
|
||||
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, string SearchVal = "")
|
||||
{
|
||||
List<DatabaseModels.FileModel> dbResult = new List<DatabaseModels.FileModel>();
|
||||
|
||||
dbResult = dbCtx
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetProgFile
|
||||
.Where(x => ((x.IdxMacchina == IdxMacchina || IdxMacchina == "0") || (x.CodArticolo == CodArticolo || CodArticolo == "ND")) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)))
|
||||
.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)))
|
||||
.OrderBy(x => x.Name)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// effettua inserimento di un record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="newFiles"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileInsert(string idxMacchina, List<FileInfo> newFiles)
|
||||
{
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// converto
|
||||
List<DatabaseModels.FileModel> newRec = newFiles.Select(o => new DatabaseModels.FileModel()
|
||||
{
|
||||
Active = true,
|
||||
CodArticolo = "ND",
|
||||
Changed = false,
|
||||
IdxMacchina = idxMacchina,
|
||||
LastCheck = adesso,
|
||||
LastMod = o.LastWriteTime,
|
||||
MimeType = o.Extension,
|
||||
Name = o.Name,
|
||||
Path = o.FullName,
|
||||
Rev = 0,
|
||||
Size = o.Length,
|
||||
FileContent = File.ReadAllBytes(o.FullName)
|
||||
}).ToList();
|
||||
|
||||
// aggiungo in blocco
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.AddRange(newRec);
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// effettua inserimento di un record in archivio come NUOVO documento tracciato
|
||||
/// </summary>
|
||||
/// <param name="idxMacchina"></param>
|
||||
/// <param name="updFiles"></param>
|
||||
/// <returns></returns>
|
||||
public bool FileUpdate(string idxMacchina, List<FileInfo> updFiles)
|
||||
{
|
||||
bool answ = false;
|
||||
DateTime adesso = DateTime.Now;
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
// converto
|
||||
List<DatabaseModels.FileModel> newRec = updFiles.Select(o => new DatabaseModels.FileModel()
|
||||
{
|
||||
Active = true,
|
||||
CodArticolo = "ND",
|
||||
Changed = false,
|
||||
IdxMacchina = idxMacchina,
|
||||
LastCheck = adesso,
|
||||
LastMod = o.LastWriteTime,
|
||||
MimeType = o.Extension,
|
||||
Name = o.Name,
|
||||
Path = o.FullName,
|
||||
Rev = 0,
|
||||
Size = o.Length,
|
||||
FileContent = File.ReadAllBytes(o.FullName)
|
||||
}).ToList();
|
||||
|
||||
// aggiungo in blocco
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.UpdateRange(newRec);
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Macchine
|
||||
/// </summary>
|
||||
@@ -151,12 +300,13 @@ namespace MP.FileData.Controllers
|
||||
public List<DatabaseModels.MacchinaModel> MacchineGetAll()
|
||||
{
|
||||
List<DatabaseModels.MacchinaModel> dbResult = new List<DatabaseModels.MacchinaModel>();
|
||||
|
||||
dbResult = dbCtx
|
||||
using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration))
|
||||
{
|
||||
dbResult = localDbCtx
|
||||
.DbSetMacchine
|
||||
.OrderBy(x => x.IdxMacchina)
|
||||
.ToList();
|
||||
|
||||
}
|
||||
return dbResult;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace MP.FileData.DatabaseModels
|
||||
public string Name { get; set; } = "";
|
||||
public int Rev { get; set; } = 0;
|
||||
public DateTime LastMod { get; set; }
|
||||
public int Size { get; set; } = 0;
|
||||
public long Size { get; set; } = 0;
|
||||
public string Path { get; set; } = "";
|
||||
public string MimeType { get; set; } = "";
|
||||
public bool Changed { get; set; } = false;
|
||||
|
||||
@@ -8,8 +8,25 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MP.FileData
|
||||
{
|
||||
public class FileUtils
|
||||
public class FileUtils
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Elenco dei file data la directory da controllare
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="searchPattern"></param>
|
||||
/// <returns></returns>
|
||||
public static FileInfo[] GetFileList(string path, string searchPattern)
|
||||
{
|
||||
//string[] answ = Directory.GetFiles(path, searchPattern);
|
||||
DriveInfo di = new DriveInfo(path);
|
||||
DirectoryInfo dirInfo = di.RootDirectory;
|
||||
FileInfo[] answ = dirInfo.GetFiles("*.*");
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
public static async Task SaveToCsv<T>(List<T> reportData, string path)
|
||||
{
|
||||
@@ -21,5 +38,7 @@ namespace MP.FileData
|
||||
lines.AddRange(valueLines);
|
||||
await Task.Run(() => File.WriteAllLines(path, lines.ToArray()));
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace MP.FileData.Migrations
|
||||
{
|
||||
[DbContext(typeof(MoonPro_ProgContext))]
|
||||
[Migration("20210903125648_InitDb")]
|
||||
[Migration("20210903153915_InitDb")]
|
||||
partial class InitDb
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@@ -90,8 +90,8 @@ namespace MP.FileData.Migrations
|
||||
b.Property<int>("Rev")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Size")
|
||||
.HasColumnType("int");
|
||||
b.Property<long>("Size")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("FileId");
|
||||
|
||||
+1
-1
@@ -51,7 +51,7 @@ namespace MP.FileData.Migrations
|
||||
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Rev = table.Column<int>(type: "int", nullable: false),
|
||||
LastMod = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
Size = table.Column<int>(type: "int", nullable: false),
|
||||
Size = table.Column<long>(type: "bigint", nullable: false),
|
||||
Path = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
MimeType = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||
Changed = table.Column<bool>(type: "bit", nullable: false),
|
||||
@@ -88,8 +88,8 @@ namespace MP.FileData.Migrations
|
||||
b.Property<int>("Rev")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Size")
|
||||
.HasColumnType("int");
|
||||
b.Property<long>("Size")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.HasKey("FileId");
|
||||
|
||||
|
||||
@@ -219,6 +219,24 @@ namespace MP.Prog.Data
|
||||
dbController.RollBackEntity(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aggiorna intero archivio scansionando dati x tutte le macchine che hanno un path valido
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task updateAllArchive()
|
||||
{
|
||||
try
|
||||
{
|
||||
var listaMacchine = await MacchineGetAll();
|
||||
foreach (var item in listaMacchine.Where(x => !string.IsNullOrEmpty(x.BasePath)).ToList())
|
||||
{
|
||||
dbController.CheckFileArchived(item.IdxMacchina, item.BasePath, "*.*");
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
|
||||
#endregion Public Methods
|
||||
|
||||
#if false
|
||||
|
||||
+58
-57
@@ -40,7 +40,7 @@
|
||||
<span class="fas fa-search" aria-hidden="true"></span>
|
||||
</span>
|
||||
</div>
|
||||
<input type="text" class="form-control form-control-sm" placeholder="Ricerca Articolo" @bind-value="@SearchArt" />
|
||||
<input type="text" class="form-control form-control-sm" placeholder="Ricerca Articolo" @bind-value="@SearchArt" width="4em" />
|
||||
<select @bind="@SelCodArt" class="form-control form-control-sm">
|
||||
@if (ArtList != null)
|
||||
{
|
||||
@@ -86,67 +86,68 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th>Impianto</th>
|
||||
<th>Data Ordine</th>
|
||||
<th>Ordine</th>
|
||||
<th class="text-right">Fornitore</th>
|
||||
<th class="text-right">Richiesta</th>
|
||||
<th class="text-right">Carico</th>
|
||||
<th class="text-right">Effettivo</th>
|
||||
<th>Macchina</th>
|
||||
<th>Articolo</th>
|
||||
<th>File</th>
|
||||
<th>Rev</th>
|
||||
<th>Size</th>
|
||||
<th>Modifica</th>
|
||||
<th>Controllo</th>
|
||||
<th>OK</th>
|
||||
@*<th class="text-right">Fornitore</th>
|
||||
<th class="text-right">Richiesta</th>
|
||||
<th class="text-right">Carico</th>
|
||||
<th class="text-right">Effettivo</th>*@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var record in ListRecords)
|
||||
{
|
||||
@*<tr class="@checkSelect(@record.OrderId)">
|
||||
<td class="text-nowrap">
|
||||
@if (currRecord == null)
|
||||
{
|
||||
<button class="btn btn-sm btn-info" @onclick="() => Edit(record)">
|
||||
<span class="oi oi-pencil"></span>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-secondary disabled">
|
||||
<i class="oi oi-pencil"></i>
|
||||
</button>
|
||||
}
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Plant.PlantCode</div>
|
||||
<div class="small">@record.Plant.PlantDesc</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.DtOrder.ToString("yyyy.MM.dd")</div>
|
||||
<div class="small">@record.DtOrder.ToString("ddd HH:mm.ss")</div>
|
||||
</td>
|
||||
<td>@record.OrderCode | @record.OrderDesc</td>
|
||||
<td class="text-right">
|
||||
<div class="text-uppercase">
|
||||
@record.Supplier.SupplierDesc
|
||||
</div>
|
||||
<div class="small">@record.Transporter.TransporterDesc</div>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
@record.OrderQty.ToString("N0")
|
||||
</td>
|
||||
<td class="text-right">
|
||||
@if (!record.DtExecStart.Equals(@record.DtExecEnd))
|
||||
{
|
||||
<div>
|
||||
@record.DtExecStart.Date.ToString("ddd dd/MM/yyyyy")
|
||||
</div>
|
||||
<div class="small">@record.DtExecStart.ToString("HH:mm:ss") --> @record.DtExecEnd.ToString("HH:mm:ss")</div>
|
||||
}
|
||||
</td>
|
||||
<td class="text-right">
|
||||
@if (record.ExecutionQty > 0)
|
||||
{
|
||||
@record.ExecutionQty.ToString("N0")
|
||||
}
|
||||
</td>
|
||||
</tr>*@
|
||||
<tr class="@checkSelect(record.FileId)">
|
||||
<td class="text-nowrap">
|
||||
|
||||
@if (currRecord == null)
|
||||
{
|
||||
<button class="btn btn-sm btn-info" @onclick="() => Edit(record)">
|
||||
<i class="oi oi-pencil"></i>
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<button class="btn btn-sm btn-secondary disabled">
|
||||
<i class="oi oi-pencil"></i>
|
||||
</button>
|
||||
}
|
||||
<div class="small">[@record.FileId]</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Macchina.CodMacchina</div>
|
||||
<div class="small">@record.Macchina.Descrizione</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Articolo.Disegno</div>
|
||||
<div class="small">@record.Articolo.DescArticolo</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Name</div>
|
||||
<div class="small">@record.Path</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.Rev</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@((double)record.Size)/1024</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.LastMod.ToString("yyyy.MM.dd")</div>
|
||||
<div class="small">@record.LastMod.ToString("ddd HH:mm.ss")</div>
|
||||
</td>
|
||||
<td>
|
||||
<div>@record.LastCheck.ToString("yyyy.MM.dd")</div>
|
||||
<div class="small">@record.LastCheck.ToString("ddd HH:mm.ss")</div>
|
||||
</td>
|
||||
<td>@record.Changed</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@@ -190,11 +190,13 @@ namespace MP.Prog.Pages
|
||||
|
||||
protected async Task ForceCheck()
|
||||
{
|
||||
// !!!FARE
|
||||
isLoading = true;
|
||||
await DataService.updateAllArchive();
|
||||
currRecord = null;
|
||||
SearchRecords = null;
|
||||
ListRecords = null;
|
||||
AppMService.File_Filter = SelectData.Init(5, 10);
|
||||
isLoading = false;
|
||||
await ReloadAllData();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<TargetFramework>net5.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>1.0.2109.0312</Version>
|
||||
<Version>1.0.2109.0316</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 1.0.2109.0312</h4>
|
||||
<h4>Versione: 1.0.2109.0316</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.0.2109.0312
|
||||
1.0.2109.0316
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>1.0.2109.0312</version>
|
||||
<version>1.0.2109.0316</version>
|
||||
<url>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip</url>
|
||||
<changelog>http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
Reference in New Issue
Block a user