Fix verifica modifica file
This commit is contained in:
@@ -80,9 +80,11 @@ namespace MP.FileData.Controllers
|
||||
{
|
||||
bool answ = false;
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
FileInfo[] fileList = dirInfo.GetFiles("*.*");
|
||||
FileInfo[] fileList = dirInfo.GetFiles(searchPattern);
|
||||
List<FileInfo> fileNew = new List<FileInfo>();
|
||||
List<FileInfo> fileMod = 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);
|
||||
@@ -92,8 +94,9 @@ namespace MP.FileData.Controllers
|
||||
foreach (var file in fileList)
|
||||
{
|
||||
// cerca nel DB...
|
||||
var currRecord = archivedFile
|
||||
.Where(x => x.Path == file.FullName)
|
||||
FileModel currRecord = archivedFile
|
||||
.Where(x => x.Active && x.Path == file.FullName)
|
||||
.OrderByDescending(y => y.Rev)
|
||||
.FirstOrDefault();
|
||||
// se NON trova lo crea
|
||||
if (currRecord == null)
|
||||
@@ -111,8 +114,16 @@ namespace MP.FileData.Controllers
|
||||
var newMD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
if (newMD5 != currRecord.MD5)
|
||||
{
|
||||
fileMod.Add(file);
|
||||
fileMod.Add(currRecord);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileChecked.Add(currRecord);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fileChecked.Add(currRecord);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,7 +137,12 @@ namespace MP.FileData.Controllers
|
||||
// aggiorno i file modificati
|
||||
if (fileMod != null && fileMod.Count > 0)
|
||||
{
|
||||
FileUpdate(idxMacchina, fileMod);
|
||||
FileSetUpdated(fileMod);
|
||||
}
|
||||
// segno data-ora ultimo controllo x file invariati
|
||||
if (fileChecked != null && fileChecked.Count > 0)
|
||||
{
|
||||
FileSetChecked(fileChecked);
|
||||
}
|
||||
|
||||
return answ;
|
||||
@@ -334,6 +350,59 @@ namespace MP.FileData.Controllers
|
||||
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>
|
||||
@@ -431,58 +500,6 @@ namespace MP.FileData.Controllers
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <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;
|
||||
// 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 = updFiles.Select(o => new DatabaseModels.FileModel()
|
||||
{
|
||||
Active = true,
|
||||
DiskStatus = FileState.Changed,
|
||||
CodArticolo = "ND",
|
||||
FileContent = File.ReadAllBytes(o.FullName),
|
||||
IdxMacchina = idxMacchina,
|
||||
LastCheck = adesso,
|
||||
LastMod = o.LastWriteTime,
|
||||
MimeType = o.Extension,
|
||||
Name = o.Name,
|
||||
Path = o.FullName,
|
||||
Rev = 0,
|
||||
Size = o.Length
|
||||
}).ToList();
|
||||
|
||||
// calcolo MD5
|
||||
foreach (var item in newRec)
|
||||
{
|
||||
var hash = md5.ComputeHash(item.FileContent);
|
||||
item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
|
||||
// aggiungo in blocco
|
||||
localDbCtx
|
||||
.DbSetProgFile
|
||||
.UpdateRange(newRec);
|
||||
|
||||
// salvo
|
||||
localDbCtx.SaveChanges();
|
||||
answ = true;
|
||||
}
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Elenco tabella Macchine
|
||||
/// </summary>
|
||||
|
||||
@@ -102,11 +102,21 @@ namespace MP.Prog.Data
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal Task FileApprove(FileData.DatabaseModels.FileModel currItem)
|
||||
{
|
||||
return Task.FromResult(dbController.FileModApprove(currItem));
|
||||
}
|
||||
|
||||
internal Task FileDelete(FileData.DatabaseModels.FileModel currItem)
|
||||
{
|
||||
return Task.FromResult(dbController.FileDelete(currItem));
|
||||
}
|
||||
|
||||
internal Task FileReject(FileData.DatabaseModels.FileModel currItem)
|
||||
{
|
||||
return Task.FromResult(dbController.FileModReject(currItem));
|
||||
}
|
||||
|
||||
internal Task FileUpdate(FileData.DatabaseModels.FileModel updItem)
|
||||
{
|
||||
return Task.FromResult(dbController.FileUpdate(updItem));
|
||||
@@ -212,9 +222,9 @@ namespace MP.Prog.Data
|
||||
return Task.FromResult(dbController.FileGetByKey(FileId));
|
||||
}
|
||||
|
||||
public Task<List<MP.FileData.DatabaseModels.FileModel>> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal)
|
||||
public Task<List<MP.FileData.DatabaseModels.FileModel>> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal)
|
||||
{
|
||||
return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyMod, SearchVal).ToList());
|
||||
return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyActive, OnlyMod, SearchVal).ToList());
|
||||
}
|
||||
|
||||
public Task<List<MP.FileData.DatabaseModels.MacchinaModel>> MacchineGetAll()
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace MP.Prog.Data
|
||||
public DateTime DateEnd { get; set; } = DateTime.Now.AddMinutes(1);
|
||||
public DateTime DateStart { get; set; } = DateTime.Now.AddDays(-7);
|
||||
public string IdxMacchina { get; set; } = "";
|
||||
public bool OnlyActive { get; set; } = false;
|
||||
public bool OnlyMod { get; set; } = false;
|
||||
|
||||
#endregion Public Properties
|
||||
@@ -42,6 +43,8 @@ namespace MP.Prog.Data
|
||||
{
|
||||
if (!(obj is SelectData item))
|
||||
return false;
|
||||
if (OnlyActive != item.OnlyActive)
|
||||
return false;
|
||||
if (OnlyMod != item.OnlyMod)
|
||||
return false;
|
||||
if (CodArticolo != item.CodArticolo)
|
||||
|
||||
+26
-37
@@ -20,12 +20,22 @@
|
||||
<div class="input-group-prepend">
|
||||
</div>
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input" id="togAttivi" title="Solo Aperti / Mostra tutti" @bind-value="@OnlyMod" checked="@OnlyMod" />
|
||||
<label class="custom-control-label small" for="togAttivi"><sub>solo mod</sub></label>
|
||||
<input type="checkbox" class="custom-control-input" id="togAttivi" title="Solo Attivi / Mostra tutti" @bind-value="@OnlyActive" checked="@OnlyActive" />
|
||||
<label class="custom-control-label small" for="togAttivi"><sub>Attivi</sub></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="col-2">
|
||||
<div class="input-group input-group-sm">
|
||||
<div class="input-group-prepend">
|
||||
</div>
|
||||
<div class="custom-control custom-switch">
|
||||
<input type="checkbox" class="custom-control-input" id="togModificati" title="Solo Aperti / Mostra tutti" @bind-value="@OnlyMod" checked="@OnlyMod" />
|
||||
<label class="custom-control-label small" for="togModificati"><sub>Modifiche</sub></label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
@@ -43,29 +53,6 @@
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="input-group">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">
|
||||
<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" width="4em" />
|
||||
<select @bind="@SelCodArt" class="form-control form-control-sm">
|
||||
@if (ArtList != null)
|
||||
{
|
||||
foreach (var item in ArtList)
|
||||
{
|
||||
<option value="@item.CodArticolo">@item.Disegno | @item.DescArticolo</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
<div class="input-group-append">
|
||||
<button id="searchReset" class="btn btn-sm btn-secondary" @onclick="() => ResetSearchArt()" title="Reset ricerca articolo"><i class="fas fa-ban"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<MP.Prog.Components.CodArtSelector searchUpdated="searchArtUpd"></MP.Prog.Components.CodArtSelector>
|
||||
</div>
|
||||
<div class="col-1">
|
||||
<div class="form-group mb-0">
|
||||
<button id="btnReset" class="btn btn-info btn-sm btn-block" @onclick="() => ResetFilter()" title="Reset Filter"><span class="oi oi-loop-circular"></span></button>
|
||||
@@ -100,7 +87,7 @@
|
||||
<th>File</th>
|
||||
<th>Rev</th>
|
||||
<th>Size</th>
|
||||
<th class="text-center">Ok</th>
|
||||
<th class="text-center">State</th>
|
||||
<th>Macchina</th>
|
||||
<th>Articolo</th>
|
||||
<th class="text-right">Modificato</th>
|
||||
@@ -136,16 +123,18 @@
|
||||
<div>@((((double)record.Size)/1024).ToString("N2")) k</div>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<span title="Ultimo controllo: @record.LastCheck.ToString("yyyy.MM.dd HH:mm:ss")">
|
||||
|
||||
@if (@record.DiskState != MP.FileData.FileState.Unchanged)
|
||||
{
|
||||
<i class="fas fa-circle text-danger"></i>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="fas fa-check-circle text-success"></i>
|
||||
}
|
||||
<span title="@record.DiskStatus | Ultimo controllo: @record.LastCheck.ToString("yyyy.MM.dd HH:mm:ss")">
|
||||
<span class="@(cssStatusByCod(record.DiskStatus))">
|
||||
@record.DiskStatus
|
||||
</span>
|
||||
@*@if (record.DiskStatus == MP.FileData.FileState.Unchanged)
|
||||
{
|
||||
<i class="fas fa-check-circle text-success"></i>
|
||||
}
|
||||
else
|
||||
{
|
||||
<i class="fas fa-circle text-danger"></i>
|
||||
}*@
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -66,6 +66,28 @@ namespace MP.Prog.Pages
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnlyActive
|
||||
{
|
||||
get
|
||||
{
|
||||
bool answ = false;
|
||||
if (AppMService.File_Filter != null)
|
||||
{
|
||||
answ = AppMService.File_Filter.OnlyActive;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!AppMService.File_Filter.OnlyActive.Equals(value))
|
||||
{
|
||||
AppMService.File_Filter.OnlyActive = value;
|
||||
var pUpd = Task.Run(async () => await ReloadData());
|
||||
pUpd.Wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool OnlyMod
|
||||
{
|
||||
get
|
||||
@@ -192,10 +214,35 @@ namespace MP.Prog.Pages
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private string cssStatusByCod(MP.FileData.FileState currStatus)
|
||||
{
|
||||
string answ = "badge";
|
||||
switch (currStatus)
|
||||
{
|
||||
case FileData.FileState.Changed:
|
||||
answ += " badge-warning";
|
||||
break;
|
||||
|
||||
case FileData.FileState.Deleted:
|
||||
answ += " badge-danger";
|
||||
break;
|
||||
|
||||
case FileData.FileState.Unchanged:
|
||||
answ += " badge-success";
|
||||
break;
|
||||
|
||||
case FileData.FileState.ND:
|
||||
default:
|
||||
answ += " badge-light";
|
||||
break;
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
private async Task ReloadData()
|
||||
{
|
||||
isLoading = true;
|
||||
SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.File_Filter.OnlyMod, AppMService.SearchVal);
|
||||
SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.File_Filter.OnlyActive, AppMService.File_Filter.OnlyMod, AppMService.SearchVal);
|
||||
ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList();
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user