From 13c7bb688c3578f6a65eba3c95c739a62b902f0e Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 15:04:39 +0200 Subject: [PATCH 01/12] 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 /// From 44f148d41b3532c89152777c86b9bec08c43cab2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 15:04:56 +0200 Subject: [PATCH 02/12] Ancora update gestione editing file --- MP.Prog/Components/FileEditor.razor | 11 +++ MP.Prog/Components/FileEditor.razor.cs | 100 +++++++++++++++++++++++++ MP.Prog/Data/FileArchDataService.cs | 19 ++++- MP.Prog/Data/SelectData.cs | 4 +- MP.Prog/Pages/Archive.razor | 76 +++++++++++-------- MP.Prog/Pages/Archive.razor.cs | 29 ++++++- 6 files changed, 202 insertions(+), 37 deletions(-) create mode 100644 MP.Prog/Components/FileEditor.razor create mode 100644 MP.Prog/Components/FileEditor.razor.cs diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor new file mode 100644 index 00000000..3e7e8f23 --- /dev/null +++ b/MP.Prog/Components/FileEditor.razor @@ -0,0 +1,11 @@ +

FileEditor

+ +

mostrare dettaglio: diff? comando accetta/annulla?

+ +Funzionalità: +
    +
  • Mostra dettagli file
  • +
  • Mostra contenuto file (SE NON modificato)
  • +
  • Mostra preview file modalità diff (se modificato)
  • +
  • dettaglio file: accetta (legge + new rel) / rifiuta (DB --> file) modifica
  • +
\ No newline at end of file diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs new file mode 100644 index 00000000..18995c51 --- /dev/null +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -0,0 +1,100 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MP.FileData.DatabaseModels; +using MP.Prog.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Prog.Components +{ + public partial class FileEditor : ComponentBase + { + #region Public Fields + + public FileModel _currItem = new FileModel(); + + #endregion Public Fields + + #region Protected Properties + + [Inject] + protected FileArchDataService DataService { get; set; } + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public FileModel currItem + { + get + { + return _currItem = null; + } + set + { + _currItem = value; + } + } + + [Parameter] + public EventCallback DataReset { get; set; } + + [Parameter] + public EventCallback DataUpdated { get; set; } + + #endregion Public Properties + + #region Private Methods + + private async Task cancelUpdate() + { + await DataReset.InvokeAsync(0); + } + + private async Task deleteRecord() + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il file selezionato??")) + return; + + if (_currItem != null) + { + await DataService.FileDelete(_currItem); + await DataUpdated.InvokeAsync(1); + } + else + { + Console.WriteLine("File null!"); + } + } + + private async Task saveUpdate() + { + if (_currItem != null) + { + DataService.FileUpdate(_currItem); + await DataUpdated.InvokeAsync(1); + } + else + { + Console.WriteLine("File null!"); + } + } + + #endregion Private Methods + + //protected override async Task OnInitializedAsync() + //{ + // await ReloadAllData(); + //} + + //protected async Task ReloadAllData() + //{ + //} + } +} \ No newline at end of file diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index 6254e742..ef621dce 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -102,6 +102,16 @@ namespace MP.Prog.Data #region Internal Methods + internal Task FileDelete(FileData.DatabaseModels.FileModel currItem) + { + return Task.FromResult(dbController.FileDelete(currItem)); + } + + internal Task FileUpdate(FileData.DatabaseModels.FileModel updItem) + { + return Task.FromResult(dbController.FileUpdate(updItem)); + } + internal void ResetController() { dbController.ResetController(); @@ -196,9 +206,14 @@ namespace MP.Prog.Data dbController.Dispose(); } - public Task> FileGetFilt(string IdxMacchina, string CodArticolo, string SearchVal) + public Task FileGetByKey(int FileId) { - return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, SearchVal).ToList()); + return Task.FromResult(dbController.FileGetByKey(FileId)); + } + + public Task> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal) + { + return Task.FromResult(dbController.FileGetFilt(IdxMacchina, CodArticolo, OnlyMod, SearchVal).ToList()); } public Task> MacchineGetAll() diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 187318e8..0c6a9f65 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -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 OnlyMod { get; set; } = false; #endregion Public Properties @@ -41,7 +42,8 @@ namespace MP.Prog.Data { if (!(obj is SelectData item)) return false; - + if (OnlyMod != item.OnlyMod) + return false; if (CodArticolo != item.CodArticolo) return false; if (IdxMacchina != item.IdxMacchina) diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 4e567d7e..dc5618a8 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -15,6 +15,16 @@ +
+
+
+
+
+ + +
+
+
@@ -33,7 +43,7 @@
-
+
@@ -67,12 +77,12 @@
@if (currRecord != null) { -

mostrare dettaglio: diff? comando accetta/annulla?

- @**@ + } @if (ListRecords == null) { - + + RELOADING } else if (totalCount == 0) { @@ -86,18 +96,14 @@ - Macchina - Articolo File Rev Size - Modifica - Controllo - OK - @*Fornitore - Richiesta - Carico - Effettivo*@ + Ok + Macchina + Articolo + Modificato + @*Controllo*@ @@ -105,10 +111,9 @@ { - @if (currRecord == null) { - } @@ -118,15 +123,6 @@ } -
[@record.FileId]
- - -
@record.Macchina.CodMacchina
-
@record.Macchina.Descrizione
- - -
@record.Articolo.Disegno
-
@record.Articolo.DescArticolo
@record.Name
@@ -136,17 +132,37 @@
@record.Rev
-
@((double)record.Size)/1024
+
@((((double)record.Size)/1024).ToString("N2")) k
+ + + + + @if (@record.Changed) + { + + } + else + { + + } + +
@record.Macchina.CodMacchina
+
@record.Macchina.Descrizione
+ + +
@record.Articolo.Disegno
+
@record.Articolo.DescArticolo
+ +
@record.LastMod.ToString("yyyy.MM.dd")
@record.LastMod.ToString("ddd HH:mm.ss")
- -
@record.LastCheck.ToString("yyyy.MM.dd")
-
@record.LastCheck.ToString("ddd HH:mm.ss")
- - @record.Changed + @* +
@record.LastCheck.ToString("yyyy.MM.dd")
+
@record.LastCheck.ToString("ddd HH:mm.ss")
+ *@ } diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index d39ba288..0e843027 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.FileData.DatabaseModels; +using MP.Prog.Components; using MP.Prog.Data; using System; using System.Collections.Generic; @@ -63,6 +64,28 @@ namespace MP.Prog.Pages } } + private bool OnlyMod + { + get + { + bool answ = false; + if (AppMService.File_Filter != null) + { + answ = AppMService.File_Filter.OnlyMod; + } + return answ; + } + set + { + if (!AppMService.File_Filter.OnlyMod.Equals(value)) + { + AppMService.File_Filter.OnlyMod = value; + var pUpd = Task.Run(async () => await ReloadData()); + pUpd.Wait(); + } + } + } + private string SelCodArt { get @@ -170,7 +193,7 @@ namespace MP.Prog.Pages private async Task ReloadData() { isLoading = true; - SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.SearchVal); + SearchRecords = await DataService.FileGetFilt(AppMService.File_Filter.IdxMacchina, AppMService.File_Filter.CodArticolo, AppMService.File_Filter.OnlyMod, AppMService.SearchVal); ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); isLoading = false; } @@ -181,11 +204,9 @@ namespace MP.Prog.Pages protected void Edit(FileModel selRecord) { -#if false // rileggo dal DB il record corrente... - var pUpd = Task.Run(async () => currRecord = await DataService.OrderGetByCode(selRecord.OrderCode)); + var pUpd = Task.Run(async () => currRecord = await DataService.FileGetByKey(selRecord.FileId)); pUpd.Wait(); -#endif } protected async Task ForceCheck() From 81430d9b2722893ac6d6733630f1b7b7012480c1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 15:05:01 +0200 Subject: [PATCH 03/12] refresh --- MP.Prog/Shared/NavMenu.razor | 5 +++++ MP.Stats/MP.Stats.csproj | 2 +- Resources/ChangeLog.html | 2 +- Resources/VersNum.txt | 2 +- Resources/manifest.xml | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/MP.Prog/Shared/NavMenu.razor b/MP.Prog/Shared/NavMenu.razor index 344b1697..1ecf3fb7 100644 --- a/MP.Prog/Shared/NavMenu.razor +++ b/MP.Prog/Shared/NavMenu.razor @@ -17,6 +17,11 @@ Archivio File +
diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index bb53014e..6f622334 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,7 +4,7 @@ net5.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 1.0.2109.0316 + 1.0.2109.0318 diff --git a/Resources/ChangeLog.html b/Resources/ChangeLog.html index 0a6d6a70..7c25555c 100644 --- a/Resources/ChangeLog.html +++ b/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 1.0.2109.0316

+

Versione: 1.0.2109.0318


Note di rilascio:
    diff --git a/Resources/VersNum.txt b/Resources/VersNum.txt index 86913cfc..f39fda21 100644 --- a/Resources/VersNum.txt +++ b/Resources/VersNum.txt @@ -1 +1 @@ -1.0.2109.0316 +1.0.2109.0318 diff --git a/Resources/manifest.xml b/Resources/manifest.xml index ca4ca4df..cb5c5903 100644 --- a/Resources/manifest.xml +++ b/Resources/manifest.xml @@ -1,6 +1,6 @@ - 1.0.2109.0316 + 1.0.2109.0318 http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/MP.Stats.zip http://nexus.steamware.net/repository/SWS/MP-STATS/stable/0/ChangeLog.html false From c783a2d959f6ffd90a98d3cff803bb3f2ee962c5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 15:40:58 +0200 Subject: [PATCH 04/12] Aggiunta preliminare editor contenuto file --- MP.FileData/DatabaseModels/FileModel.cs | 14 ++++++++++++++ MP.Prog/Components/FileEditor.razor | 24 +++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/MP.FileData/DatabaseModels/FileModel.cs b/MP.FileData/DatabaseModels/FileModel.cs index 8ec845e6..ea53fc82 100644 --- a/MP.FileData/DatabaseModels/FileModel.cs +++ b/MP.FileData/DatabaseModels/FileModel.cs @@ -34,6 +34,20 @@ namespace MP.FileData.DatabaseModels public DateTime LastCheck { get; set; } = DateTime.Now.AddYears(-1); public byte[] FileContent { get; set; } + [NotMapped] + public string FileStringContent + { + get + { + return Encoding.UTF8.GetString(FileContent); + } + set + { + // serializzo a byte + FileContent = Encoding.ASCII.GetBytes(value); + } + } + [ForeignKey("CodArticolo")] public virtual ArticoloModel Articolo { get; set; } [ForeignKey("IdxMacchina")] diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor index 3e7e8f23..96c4e735 100644 --- a/MP.Prog/Components/FileEditor.razor +++ b/MP.Prog/Components/FileEditor.razor @@ -1,4 +1,26 @@ -

    FileEditor

    +
    +
    + Modifica +
    +
    + + +
    +
    + + + +
    +
    + + @**@ +
    +
    +
    +
    +
    + +

    FileEditor

    mostrare dettaglio: diff? comando accetta/annulla?

    From 68b9cd4d782cb189a5673e84e6cfc1072eee01fb Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 6 Sep 2021 18:34:38 +0200 Subject: [PATCH 05/12] Abbozzato controllo x filtraggio dati ricerca articoli --- MP.Prog/Components/CodArtSelector.razor | 110 ++++++++++++++++++++++++ MP.Prog/Components/FileEditor.razor | 37 +++++++- MP.Prog/Components/FileEditor.razor.cs | 8 +- MP.Prog/Components/SearchMod.razor | 4 +- MP.Prog/Data/FileArchDataService.cs | 3 +- MP.Prog/Pages/Archive.razor | 3 +- MP.Prog/Pages/Archive.razor.cs | 23 +++-- MP.Prog/Pages/Setup.razor | 23 +++++ 8 files changed, 198 insertions(+), 13 deletions(-) create mode 100644 MP.Prog/Components/CodArtSelector.razor create mode 100644 MP.Prog/Pages/Setup.razor diff --git a/MP.Prog/Components/CodArtSelector.razor b/MP.Prog/Components/CodArtSelector.razor new file mode 100644 index 00000000..f76926fc --- /dev/null +++ b/MP.Prog/Components/CodArtSelector.razor @@ -0,0 +1,110 @@ +@using MP.FileData.DatabaseModels +@using MP.Prog.Data + +@inject FileArchDataService DataService +@inject MessageService AppMService + +@if (ArtList == null) +{ + +} +else +{ +
    +
    + + + +
    + + +
    + +
    +
    +} + +@code { + + [Parameter] + public EventCallback searchUpdated { get; set; } + [Parameter] + public string SelCodArt + { + get + { + string answ = ""; + if (AppMService.File_Filter != null) + { + answ = AppMService.File_Filter.CodArticolo; + } + return answ; + } + set + { + if (!AppMService.File_Filter.CodArticolo.Equals(value)) + { + AppMService.File_Filter.CodArticolo = value; + } + reportChange(); + } + } + + private void reportChange() + { + searchUpdated.InvokeAsync(SelCodArt); + } + + protected string _SearchArt; + protected string defCodArt = ""; + protected List ArtList; + + protected string SearchArt + { + get + { + return _SearchArt; + } + set + { + _SearchArt = value; + // se son > 3 char... debounce... + if (string.IsNullOrEmpty(value)) + { + _SearchArt = defCodArt; + } + if (value.Length >= defCodArt.Length) + { + var pUpd = Task.Run(async () => + { + ArtList = await DataService.ArticoliGetFilt(SearchArt); + }); + pUpd.Wait(); + } + } + } + protected override async Task OnInitializedAsync() + { + await ReloadAllData(); + _SearchArt = defCodArt; + } + + protected async Task ReloadAllData() + { + SelCodArt = defCodArt; + ArtList = await DataService.ArticoliGetFilt(SearchArt); + } + + protected void ResetSearchArt() + { + SearchArt = defCodArt; + } +} \ No newline at end of file diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor index 96c4e735..1e805d32 100644 --- a/MP.Prog/Components/FileEditor.razor +++ b/MP.Prog/Components/FileEditor.razor @@ -7,12 +7,45 @@
    +
    +
    + + + +
    + +
    +
    +
    + + + +
    + +
    -
    - +
    + @*

    @((MarkupString )_currItem.FileStringContent)

    *@ + @**@
    diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs index 18995c51..0cae76b3 100644 --- a/MP.Prog/Components/FileEditor.razor.cs +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -29,6 +29,9 @@ namespace MP.Prog.Components #region Public Properties + [Parameter] + public List ArtList { get; set; } + [Parameter] public FileModel currItem { @@ -48,6 +51,9 @@ namespace MP.Prog.Components [Parameter] public EventCallback DataUpdated { get; set; } + [Parameter] + public List MacList { get; set; } + #endregion Public Properties #region Private Methods @@ -77,7 +83,7 @@ namespace MP.Prog.Components { if (_currItem != null) { - DataService.FileUpdate(_currItem); + await DataService.FileUpdate(_currItem); await DataUpdated.InvokeAsync(1); } else diff --git a/MP.Prog/Components/SearchMod.razor b/MP.Prog/Components/SearchMod.razor index 2d4f63ef..ba4df62a 100644 --- a/MP.Prog/Components/SearchMod.razor +++ b/MP.Prog/Components/SearchMod.razor @@ -28,9 +28,9 @@ } } - private void reportChange() + private async Task reportChange() { - searchUpdated.InvokeAsync(searchVal); + await searchUpdated.InvokeAsync(searchVal); } private void reset() diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index ef621dce..a29e5bb9 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -197,7 +197,8 @@ namespace MP.Prog.Data public Task> ArticoliGetFilt(string SearchVal) { - return Task.FromResult(dbController.ArtGetFilt(SearchVal, 20).ToList()); + return Task.FromResult(dbController.ArtGetFilt(SearchVal, 200).ToList()); + //return Task.FromResult(dbController.ArtGetFilt(SearchVal, 20).ToList()); } public void Dispose() diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index dc5618a8..37bf279d 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -64,6 +64,7 @@
+
@@ -77,7 +78,7 @@
@if (currRecord != null) { - + } @if (ListRecords == null) { diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 0e843027..13ef9388 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -15,6 +15,7 @@ namespace MP.Prog.Pages #region Private Fields private List ArtList; + private FileModel currRecord = null; private List ListRecords; private List MacList; @@ -24,7 +25,9 @@ namespace MP.Prog.Pages #region Protected Fields - protected string _SearchArt = "###"; + protected string _SearchArt; + + protected string defCodArt = ""; #endregion Protected Fields @@ -159,9 +162,9 @@ namespace MP.Prog.Pages // se son > 3 char... debounce... if (string.IsNullOrEmpty(value)) { - _SearchArt = "###"; + _SearchArt = defCodArt; } - if (value.Length >= 3) + if (value.Length >= defCodArt.Length) { var pUpd = Task.Run(async () => { @@ -234,6 +237,7 @@ namespace MP.Prog.Pages protected override async Task OnInitializedAsync() { DataService.ResetController(); + SearchArt = defCodArt; AppMService.ShowSearch = false; AppMService.PageName = "Archivio File Programmi"; AppMService.PageIcon = "fas fa-folder pr-2"; @@ -246,8 +250,10 @@ namespace MP.Prog.Pages isLoading = true; MacList = await DataService.MacchineGetAll(); SelIdxMacc = "0"; + SearchArt = defCodArt; + ArtList = await DataService.ArticoliGetFilt(SearchArt); - SelCodArt = "###"; + isLoading = false; await ReloadData(); } @@ -264,13 +270,18 @@ namespace MP.Prog.Pages SearchRecords = null; ListRecords = null; AppMService.File_Filter = SelectData.Init(5, 10); - SearchArt = "###"; + SearchArt = defCodArt; await ReloadAllData(); } protected void ResetSearchArt() { - SearchArt = "###"; + SearchArt = defCodArt; + } + + protected void searchArtUpd(string newCod) + { + SelCodArt = newCod; } protected void Select(FileModel selRecord) diff --git a/MP.Prog/Pages/Setup.razor b/MP.Prog/Pages/Setup.razor new file mode 100644 index 00000000..9c7b1836 --- /dev/null +++ b/MP.Prog/Pages/Setup.razor @@ -0,0 +1,23 @@ +@page "/Setup" + +@using MP.Prog.Components +@using MP.Prog.Data + +@inject MessageService AppMService + +

Setup

+ + + +

Selezionato @CurrCodArt

+ +@code { + + protected string CurrCodArt { get; set; } = ""; + + protected void searchUpd(string newCod) + { + CurrCodArt = newCod; + } + +} \ No newline at end of file From 607e096609ee66e52d30f24e595dd16c7b60a081 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 12:03:01 +0200 Subject: [PATCH 06/12] modifica (importante) modallo dati x tags + MD% check --- MP.FileData/Controllers/FileController.cs | 131 ++++++++++-------- MP.FileData/DatabaseModels/FileModel.cs | 5 +- MP.FileData/DatabaseModels/TagModel.cs | 23 +++ MP.FileData/Enum.cs | 20 +++ ...r.cs => 20210907100115_InitDb.Designer.cs} | 51 ++++++- ...915_InitDb.cs => 20210907100115_InitDb.cs} | 49 ++++++- .../MoonPro_ProgContextModelSnapshot.cs | 49 ++++++- 7 files changed, 264 insertions(+), 64 deletions(-) create mode 100644 MP.FileData/DatabaseModels/TagModel.cs create mode 100644 MP.FileData/Enum.cs rename MP.FileData/Migrations/{20210903153915_InitDb.Designer.cs => 20210907100115_InitDb.Designer.cs} (77%) rename MP.FileData/Migrations/{20210903153915_InitDb.cs => 20210907100115_InitDb.cs} (71%) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 76c8245d..9ff7ef26 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -101,7 +101,11 @@ namespace MP.FileData.Controllers } else { - fileMod.Add(file); + // verifico se data modifica e dimensione siano cambiati... + if (currRecord.LastMod != file.LastWriteTime || currRecord.Size != file.Length) + { + fileMod.Add(file); + } } } @@ -182,7 +186,7 @@ namespace MP.FileData.Controllers { dbResult = localDbCtx .DbSetProgFile - .Where(x => x.Path.StartsWith(path) && ((onlyActive && x.Active) || !onlyActive)) + .Where(x => x.Path.StartsWith(path) && ((onlyActive == x.Active) || !onlyActive)) .OrderBy(x => x.Name) .ToList(); } @@ -198,7 +202,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.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.Changed)) + .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.DiskState != FileState.Unchanged)) .OrderBy(x => x.Name) .ToList(); } @@ -215,33 +219,44 @@ namespace MP.FileData.Controllers { bool answ = false; DateTime adesso = DateTime.Now; - using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + // MD5 hash + using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) { - // converto - List newRec = newFiles.Select(o => new DatabaseModels.FileModel() + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) { - 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(); + // converto + List newRec = newFiles.Select(o => new DatabaseModels.FileModel() + { + Active = true, + CodArticolo = "ND", + DiskState = FileState.New, + 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); + // calcolo MD5 + foreach (var item in newRec) + { + var hash = md5.ComputeHash(item.FileContent); + item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } - // salvo - localDbCtx.SaveChanges(); - answ = true; + // aggiungo in blocco + localDbCtx + .DbSetProgFile + .AddRange(newRec); + + // salvo + localDbCtx.SaveChanges(); + answ = true; + } } return answ; } @@ -265,12 +280,7 @@ namespace MP.FileData.Controllers .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}"; - //} + updItem.DiskState = FileState.Changed; localDbCtx.Entry(updItem).State = EntityState.Modified; localDbCtx.SaveChanges(); } @@ -358,33 +368,44 @@ namespace MP.FileData.Controllers { bool answ = false; DateTime adesso = DateTime.Now; - using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) + // MD5 hash + using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) { - // converto - List newRec = updFiles.Select(o => new DatabaseModels.FileModel() + using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) { - 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(); + // converto + List newRec = updFiles.Select(o => new DatabaseModels.FileModel() + { + Active = true, + DiskState = 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(); - // aggiungo in blocco - localDbCtx - .DbSetProgFile - .UpdateRange(newRec); + // calcolo MD5 + foreach (var item in newRec) + { + var hash = md5.ComputeHash(item.FileContent); + item.MD5 = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); + } - // salvo - localDbCtx.SaveChanges(); - answ = true; + // aggiungo in blocco + localDbCtx + .DbSetProgFile + .UpdateRange(newRec); + + // salvo + localDbCtx.SaveChanges(); + answ = true; + } } return answ; } diff --git a/MP.FileData/DatabaseModels/FileModel.cs b/MP.FileData/DatabaseModels/FileModel.cs index ea53fc82..1ba32544 100644 --- a/MP.FileData/DatabaseModels/FileModel.cs +++ b/MP.FileData/DatabaseModels/FileModel.cs @@ -30,10 +30,13 @@ namespace MP.FileData.DatabaseModels public long Size { get; set; } = 0; public string Path { get; set; } = ""; public string MimeType { get; set; } = ""; - public bool Changed { get; set; } = false; + public string MD5 { get; set; } = ""; + public FileState DiskState { get; set; } = FileState.New; public DateTime LastCheck { get; set; } = DateTime.Now.AddYears(-1); public byte[] FileContent { get; set; } + public ICollection Tags { get; set; } + [NotMapped] public string FileStringContent { diff --git a/MP.FileData/DatabaseModels/TagModel.cs b/MP.FileData/DatabaseModels/TagModel.cs new file mode 100644 index 00000000..849cb577 --- /dev/null +++ b/MP.FileData/DatabaseModels/TagModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.FileData.DatabaseModels +{ + [Table("Tags")] + public partial class TagModel + { + + [Key] + public string TagId { get; set; } + + public ICollection Files { get; set; } + } +} diff --git a/MP.FileData/Enum.cs b/MP.FileData/Enum.cs new file mode 100644 index 00000000..a514cd02 --- /dev/null +++ b/MP.FileData/Enum.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.FileData +{ + /// + /// Stato File + /// + public enum FileState + { + ND = 0, + New, + Changed, + Deleted, + Unchanged + } +} \ No newline at end of file diff --git a/MP.FileData/Migrations/20210903153915_InitDb.Designer.cs b/MP.FileData/Migrations/20210907100115_InitDb.Designer.cs similarity index 77% rename from MP.FileData/Migrations/20210903153915_InitDb.Designer.cs rename to MP.FileData/Migrations/20210907100115_InitDb.Designer.cs index 9960c4e3..4886b82e 100644 --- a/MP.FileData/Migrations/20210903153915_InitDb.Designer.cs +++ b/MP.FileData/Migrations/20210907100115_InitDb.Designer.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MP.FileData.Migrations { [DbContext(typeof(MoonPro_ProgContext))] - [Migration("20210903153915_InitDb")] + [Migration("20210907100115_InitDb")] partial class InitDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -22,6 +22,21 @@ namespace MP.FileData.Migrations .HasAnnotation("ProductVersion", "5.0.9") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + modelBuilder.Entity("FileModelTagModel", b => + { + b.Property("FilesFileId") + .HasColumnType("int"); + + b.Property("TagsTagId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("FilesFileId", "TagsTagId"); + + b.HasIndex("TagsTagId"); + + b.ToTable("FileModelTagModel"); + }); + modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b => { b.Property("CodArticolo") @@ -60,12 +75,12 @@ namespace MP.FileData.Migrations b.Property("Active") .HasColumnType("bit"); - b.Property("Changed") - .HasColumnType("bit"); - b.Property("CodArticolo") .HasColumnType("nvarchar(450)"); + b.Property("DiskState") + .HasColumnType("int"); + b.Property("FileContent") .HasColumnType("varbinary(max)"); @@ -78,6 +93,9 @@ namespace MP.FileData.Migrations b.Property("LastMod") .HasColumnType("datetime2"); + b.Property("MD5") + .HasColumnType("nvarchar(max)"); + b.Property("MimeType") .HasColumnType("nvarchar(max)"); @@ -146,6 +164,31 @@ namespace MP.FileData.Migrations }); }); + modelBuilder.Entity("MP.FileData.DatabaseModels.TagModel", b => + { + b.Property("TagId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("TagId"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("FileModelTagModel", b => + { + b.HasOne("MP.FileData.DatabaseModels.FileModel", null) + .WithMany() + .HasForeignKey("FilesFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MP.FileData.DatabaseModels.TagModel", null) + .WithMany() + .HasForeignKey("TagsTagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo") diff --git a/MP.FileData/Migrations/20210903153915_InitDb.cs b/MP.FileData/Migrations/20210907100115_InitDb.cs similarity index 71% rename from MP.FileData/Migrations/20210903153915_InitDb.cs rename to MP.FileData/Migrations/20210907100115_InitDb.cs index 46126bf6..3c346aac 100644 --- a/MP.FileData/Migrations/20210903153915_InitDb.cs +++ b/MP.FileData/Migrations/20210907100115_InitDb.cs @@ -39,6 +39,17 @@ namespace MP.FileData.Migrations table.PrimaryKey("PK_Macchine", x => x.IdxMacchina); }); + migrationBuilder.CreateTable( + name: "Tags", + columns: table => new + { + TagId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tags", x => x.TagId); + }); + migrationBuilder.CreateTable( name: "Files", columns: table => new @@ -54,7 +65,8 @@ namespace MP.FileData.Migrations Size = table.Column(type: "bigint", nullable: false), Path = table.Column(type: "nvarchar(max)", nullable: true), MimeType = table.Column(type: "nvarchar(max)", nullable: true), - Changed = table.Column(type: "bit", nullable: false), + MD5 = table.Column(type: "nvarchar(max)", nullable: true), + DiskState = table.Column(type: "int", nullable: false), LastCheck = table.Column(type: "datetime2", nullable: false), FileContent = table.Column(type: "varbinary(max)", nullable: true) }, @@ -75,6 +87,30 @@ namespace MP.FileData.Migrations onDelete: ReferentialAction.Restrict); }); + migrationBuilder.CreateTable( + name: "FileModelTagModel", + columns: table => new + { + FilesFileId = table.Column(type: "int", nullable: false), + TagsTagId = table.Column(type: "nvarchar(450)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_FileModelTagModel", x => new { x.FilesFileId, x.TagsTagId }); + table.ForeignKey( + name: "FK_FileModelTagModel_Files_FilesFileId", + column: x => x.FilesFileId, + principalTable: "Files", + principalColumn: "FileId", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_FileModelTagModel_Tags_TagsTagId", + column: x => x.TagsTagId, + principalTable: "Tags", + principalColumn: "TagId", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.InsertData( table: "Articoli", columns: new[] { "CodArticolo", "DescArticolo", "Disegno", "Tipo" }, @@ -85,6 +121,11 @@ namespace MP.FileData.Migrations columns: new[] { "IdxMacchina", "BasePath", "CodMacchina", "Descrizione", "ImgUrl", "Nome", "Note", "ShowOrder" }, values: new object[] { "0", "", "0", "--- Tutte ---", "", "--- Tutte ---", "", 0 }); + migrationBuilder.CreateIndex( + name: "IX_FileModelTagModel_TagsTagId", + table: "FileModelTagModel", + column: "TagsTagId"); + migrationBuilder.CreateIndex( name: "IX_Files_CodArticolo", table: "Files", @@ -98,9 +139,15 @@ namespace MP.FileData.Migrations protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "FileModelTagModel"); + migrationBuilder.DropTable( name: "Files"); + migrationBuilder.DropTable( + name: "Tags"); + migrationBuilder.DropTable( name: "Articoli"); diff --git a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs index 7149d346..3ab6f202 100644 --- a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs +++ b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs @@ -20,6 +20,21 @@ namespace MP.FileData.Migrations .HasAnnotation("ProductVersion", "5.0.9") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + modelBuilder.Entity("FileModelTagModel", b => + { + b.Property("FilesFileId") + .HasColumnType("int"); + + b.Property("TagsTagId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("FilesFileId", "TagsTagId"); + + b.HasIndex("TagsTagId"); + + b.ToTable("FileModelTagModel"); + }); + modelBuilder.Entity("MP.FileData.DatabaseModels.ArticoloModel", b => { b.Property("CodArticolo") @@ -58,12 +73,12 @@ namespace MP.FileData.Migrations b.Property("Active") .HasColumnType("bit"); - b.Property("Changed") - .HasColumnType("bit"); - b.Property("CodArticolo") .HasColumnType("nvarchar(450)"); + b.Property("DiskState") + .HasColumnType("int"); + b.Property("FileContent") .HasColumnType("varbinary(max)"); @@ -76,6 +91,9 @@ namespace MP.FileData.Migrations b.Property("LastMod") .HasColumnType("datetime2"); + b.Property("MD5") + .HasColumnType("nvarchar(max)"); + b.Property("MimeType") .HasColumnType("nvarchar(max)"); @@ -144,6 +162,31 @@ namespace MP.FileData.Migrations }); }); + modelBuilder.Entity("MP.FileData.DatabaseModels.TagModel", b => + { + b.Property("TagId") + .HasColumnType("nvarchar(450)"); + + b.HasKey("TagId"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("FileModelTagModel", b => + { + b.HasOne("MP.FileData.DatabaseModels.FileModel", null) + .WithMany() + .HasForeignKey("FilesFileId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("MP.FileData.DatabaseModels.TagModel", null) + .WithMany() + .HasForeignKey("TagsTagId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + modelBuilder.Entity("MP.FileData.DatabaseModels.FileModel", b => { b.HasOne("MP.FileData.DatabaseModels.ArticoloModel", "Articolo") From e5d6f579f4fed1d27be565ab9883ad7cba2004b9 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 12:03:09 +0200 Subject: [PATCH 07/12] refresh archive page --- MP.Prog/Pages/Archive.razor | 2 +- MP.Prog/Pages/Archive.razor.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 37bf279d..89144f0e 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -138,7 +138,7 @@ - @if (@record.Changed) + @if (@record.DiskState != MP.FileData.FileState.Unchanged) { } diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index 13ef9388..a5593f95 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -1,7 +1,6 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; using MP.FileData.DatabaseModels; -using MP.Prog.Components; using MP.Prog.Data; using System; using System.Collections.Generic; From 98b9a834913fe9e49c9f28e8f56ba875f687349c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 13:28:06 +0200 Subject: [PATCH 08/12] Update datamodel --- MP.FileData/Controllers/FileController.cs | 125 ++++++++++++++---- MP.FileData/DatabaseModels/FileModel.cs | 2 +- MP.FileData/Enum.cs | 1 - ...r.cs => 20210907103215_InitDb.Designer.cs} | 4 +- ...115_InitDb.cs => 20210907103215_InitDb.cs} | 2 +- .../MoonPro_ProgContextModelSnapshot.cs | 2 +- 6 files changed, 104 insertions(+), 32 deletions(-) rename MP.FileData/Migrations/{20210907100115_InitDb.Designer.cs => 20210907103215_InitDb.Designer.cs} (98%) rename MP.FileData/Migrations/{20210907100115_InitDb.cs => 20210907103215_InitDb.cs} (98%) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index 9ff7ef26..f06561ae 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -86,25 +86,34 @@ namespace MP.FileData.Controllers // recupera elenco file nel DB var archivedFile = FileGetByPath(path, true); - - // verifica i file - foreach (var file in fileList) + using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) { - // cerca nel DB... - var currRecord = archivedFile - .Where(x => x.Path == file.FullName) - .FirstOrDefault(); - // se NON trova lo crea - if (currRecord == null) + // verifica i file + foreach (var file in fileList) { - fileNew.Add(file); - } - else - { - // verifico se data modifica e dimensione siano cambiati... - if (currRecord.LastMod != file.LastWriteTime || currRecord.Size != file.Length) + // cerca nel DB... + var currRecord = archivedFile + .Where(x => x.Path == file.FullName) + .FirstOrDefault(); + // se NON trova lo crea + if (currRecord == null) { - fileMod.Add(file); + 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(file); + } + } } } } @@ -112,7 +121,7 @@ namespace MP.FileData.Controllers // salvo i NUOVI file if (fileNew != null && fileNew.Count > 0) { - FileInsert(idxMacchina, fileNew); + FileInsert(idxMacchina, fileNew, 0); } // aggiorno i file modificati if (fileMod != null && fileMod.Count > 0) @@ -166,6 +175,22 @@ namespace MP.FileData.Controllers return done; } + public bool FileDiskStatusChange(List 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; @@ -193,7 +218,7 @@ namespace MP.FileData.Controllers return dbResult; } - public List FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal = "") + public List FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyActive, bool OnlyMod, string SearchVal = "") { List dbResult = new List(); using (MoonPro_ProgContext localDbCtx = new MoonPro_ProgContext(_configuration)) @@ -202,20 +227,21 @@ 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.StartsWith("##") || string.IsNullOrEmpty(CodArticolo))) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal)) && (!OnlyMod || x.DiskState != FileState.Unchanged)) - .OrderBy(x => x.Name) + .Where(x => (x.IdxMacchina == IdxMacchina || IdxMacchina == "0") && (x.Active == OnlyActive || !OnlyActive) && (!OnlyMod || x.DiskStatus != FileState.Unchanged) && (x.Name.Contains(SearchVal) || string.IsNullOrEmpty(SearchVal))) + .OrderByDescending(x => x.LastMod) .ToList(); } return dbResult; } /// - /// effettua inserimento di un record in archivio come NUOVO documento tracciato + /// Effettua inserimento di un elenco di record in archivio come NUOVO documento tracciato /// /// /// + /// /// - public bool FileInsert(string idxMacchina, List newFiles) + public bool FileInsert(string idxMacchina, List newFiles, int rev) { bool answ = false; DateTime adesso = DateTime.Now; @@ -229,14 +255,14 @@ namespace MP.FileData.Controllers { Active = true, CodArticolo = "ND", - DiskState = FileState.New, + DiskStatus = FileState.Unchanged, IdxMacchina = idxMacchina, LastCheck = adesso, LastMod = o.LastWriteTime, MimeType = o.Extension, Name = o.Name, Path = o.FullName, - Rev = 0, + Rev = rev, Size = o.Length, FileContent = File.ReadAllBytes(o.FullName) }).ToList(); @@ -261,6 +287,53 @@ namespace MP.FileData.Controllers return answ; } + public bool FileModApprove(FileModel currFile) + { + bool done = false; + List listUpdate = new List(); + 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.Unchanged; + 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.Unchanged; + currFile.LastMod = newFileInfo.LastWriteTime; + + // salvo DB + localDbCtx.SaveChanges(); + done = true; + } + return done; + } + /// /// Aggiorna un Ordine /// @@ -280,7 +353,7 @@ namespace MP.FileData.Controllers .FirstOrDefault(); if (currData != null) { - updItem.DiskState = FileState.Changed; + updItem.DiskStatus = FileState.Changed; localDbCtx.Entry(updItem).State = EntityState.Modified; localDbCtx.SaveChanges(); } @@ -377,7 +450,7 @@ namespace MP.FileData.Controllers List newRec = updFiles.Select(o => new DatabaseModels.FileModel() { Active = true, - DiskState = FileState.Changed, + DiskStatus = FileState.Changed, CodArticolo = "ND", FileContent = File.ReadAllBytes(o.FullName), IdxMacchina = idxMacchina, diff --git a/MP.FileData/DatabaseModels/FileModel.cs b/MP.FileData/DatabaseModels/FileModel.cs index 1ba32544..32f645ab 100644 --- a/MP.FileData/DatabaseModels/FileModel.cs +++ b/MP.FileData/DatabaseModels/FileModel.cs @@ -31,7 +31,7 @@ namespace MP.FileData.DatabaseModels public string Path { get; set; } = ""; public string MimeType { get; set; } = ""; public string MD5 { get; set; } = ""; - public FileState DiskState { get; set; } = FileState.New; + public FileState DiskStatus { get; set; } = FileState.Unchanged; public DateTime LastCheck { get; set; } = DateTime.Now.AddYears(-1); public byte[] FileContent { get; set; } diff --git a/MP.FileData/Enum.cs b/MP.FileData/Enum.cs index a514cd02..c4104772 100644 --- a/MP.FileData/Enum.cs +++ b/MP.FileData/Enum.cs @@ -12,7 +12,6 @@ namespace MP.FileData public enum FileState { ND = 0, - New, Changed, Deleted, Unchanged diff --git a/MP.FileData/Migrations/20210907100115_InitDb.Designer.cs b/MP.FileData/Migrations/20210907103215_InitDb.Designer.cs similarity index 98% rename from MP.FileData/Migrations/20210907100115_InitDb.Designer.cs rename to MP.FileData/Migrations/20210907103215_InitDb.Designer.cs index 4886b82e..eca66e12 100644 --- a/MP.FileData/Migrations/20210907100115_InitDb.Designer.cs +++ b/MP.FileData/Migrations/20210907103215_InitDb.Designer.cs @@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace MP.FileData.Migrations { [DbContext(typeof(MoonPro_ProgContext))] - [Migration("20210907100115_InitDb")] + [Migration("20210907103215_InitDb")] partial class InitDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -78,7 +78,7 @@ namespace MP.FileData.Migrations b.Property("CodArticolo") .HasColumnType("nvarchar(450)"); - b.Property("DiskState") + b.Property("DiskStatus") .HasColumnType("int"); b.Property("FileContent") diff --git a/MP.FileData/Migrations/20210907100115_InitDb.cs b/MP.FileData/Migrations/20210907103215_InitDb.cs similarity index 98% rename from MP.FileData/Migrations/20210907100115_InitDb.cs rename to MP.FileData/Migrations/20210907103215_InitDb.cs index 3c346aac..4ab48e1b 100644 --- a/MP.FileData/Migrations/20210907100115_InitDb.cs +++ b/MP.FileData/Migrations/20210907103215_InitDb.cs @@ -66,7 +66,7 @@ namespace MP.FileData.Migrations Path = table.Column(type: "nvarchar(max)", nullable: true), MimeType = table.Column(type: "nvarchar(max)", nullable: true), MD5 = table.Column(type: "nvarchar(max)", nullable: true), - DiskState = table.Column(type: "int", nullable: false), + DiskStatus = table.Column(type: "int", nullable: false), LastCheck = table.Column(type: "datetime2", nullable: false), FileContent = table.Column(type: "varbinary(max)", nullable: true) }, diff --git a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs index 3ab6f202..1be4c878 100644 --- a/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs +++ b/MP.FileData/Migrations/MoonPro_ProgContextModelSnapshot.cs @@ -76,7 +76,7 @@ namespace MP.FileData.Migrations b.Property("CodArticolo") .HasColumnType("nvarchar(450)"); - b.Property("DiskState") + b.Property("DiskStatus") .HasColumnType("int"); b.Property("FileContent") From 30172c3bfcd3d40adc8abeb17ab5438ef5cc07dd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 14:22:24 +0200 Subject: [PATCH 09/12] Fix comportamento selezione attributo status file --- MP.Prog/Components/FileEditor.razor | 7 ++++++ MP.Prog/Components/FileEditor.razor.cs | 32 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor index 1e805d32..5c60f582 100644 --- a/MP.Prog/Components/FileEditor.razor +++ b/MP.Prog/Components/FileEditor.razor @@ -7,6 +7,12 @@
+ @if (_currItem.DiskStatus != FileData.FileState.Unchanged) + { + + +
+ }
@@ -39,6 +45,7 @@ }
+
diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs index 0cae76b3..10b27abc 100644 --- a/MP.Prog/Components/FileEditor.razor.cs +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -58,6 +58,22 @@ namespace MP.Prog.Components #region Private Methods + private async Task ApproveChange() + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler asccettare la modifica del file selezionato generando una nuova revisione?")) + return; + + if (_currItem != null) + { + await DataService.FileApprove(_currItem); + await DataUpdated.InvokeAsync(1); + } + else + { + Console.WriteLine("File null!"); + } + } + private async Task cancelUpdate() { await DataReset.InvokeAsync(0); @@ -79,6 +95,22 @@ namespace MP.Prog.Components } } + private async Task RejectChange() + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare la modifica del file selezionato e sovrascrivere la versione in rete?")) + return; + + if (_currItem != null) + { + await DataService.FileReject(_currItem); + await DataUpdated.InvokeAsync(1); + } + else + { + Console.WriteLine("File null!"); + } + } + private async Task saveUpdate() { if (_currItem != null) From 0e2030ba9ee47f9672860c8fb58581a309f8574a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 14:22:30 +0200 Subject: [PATCH 10/12] Fix verifica modifica file --- MP.FileData/Controllers/FileController.cs | 133 ++++++++++++---------- MP.Prog/Data/FileArchDataService.cs | 14 ++- MP.Prog/Data/SelectData.cs | 3 + MP.Prog/Pages/Archive.razor | 63 +++++----- MP.Prog/Pages/Archive.razor.cs | 49 +++++++- 5 files changed, 164 insertions(+), 98 deletions(-) diff --git a/MP.FileData/Controllers/FileController.cs b/MP.FileData/Controllers/FileController.cs index f06561ae..0b992f02 100644 --- a/MP.FileData/Controllers/FileController.cs +++ b/MP.FileData/Controllers/FileController.cs @@ -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 fileNew = new List(); - List fileMod = new List(); + List fileChecked = new List(); + List fileMod = new List(); + 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; } + /// + /// Effettua update di un record in archivio da lista (SOLO STATUS) + /// + /// + /// + public bool FileSetChecked(List 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; + } + + /// + /// Effettua update di un record in archivio da lista (SOLO STATUS) + /// + /// + /// + public bool FileSetUpdated(List 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; + } + /// /// Aggiorna un Ordine /// @@ -431,58 +500,6 @@ namespace MP.FileData.Controllers } #endif - /// - /// effettua inserimento di un record in archivio come NUOVO documento tracciato - /// - /// - /// - /// - public bool FileUpdate(string idxMacchina, List 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 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; - } - /// /// Elenco tabella Macchine /// diff --git a/MP.Prog/Data/FileArchDataService.cs b/MP.Prog/Data/FileArchDataService.cs index a29e5bb9..0f1d2a5c 100644 --- a/MP.Prog/Data/FileArchDataService.cs +++ b/MP.Prog/Data/FileArchDataService.cs @@ -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> FileGetFilt(string IdxMacchina, string CodArticolo, bool OnlyMod, string SearchVal) + public Task> 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> MacchineGetAll() diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 0c6a9f65..5c2cb00c 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -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) diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index 89144f0e..efa91e4d 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -20,12 +20,22 @@
- - + +
-
+
+
+
+
+
+ + +
+
+
+
@@ -43,29 +53,6 @@
-
-
-
- - - -
- - -
- -
-
- -
@@ -100,7 +87,7 @@ File Rev Size - Ok + State Macchina Articolo Modificato @@ -136,16 +123,18 @@
@((((double)record.Size)/1024).ToString("N2")) k
- - - @if (@record.DiskState != MP.FileData.FileState.Unchanged) - { - - } - else - { - - } + + + @record.DiskStatus + + @*@if (record.DiskStatus == MP.FileData.FileState.Unchanged) + { + + } + else + { + + }*@ diff --git a/MP.Prog/Pages/Archive.razor.cs b/MP.Prog/Pages/Archive.razor.cs index a5593f95..da5610b6 100644 --- a/MP.Prog/Pages/Archive.razor.cs +++ b/MP.Prog/Pages/Archive.razor.cs @@ -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; } From a387d9cd77cac68e9e423eb6b8c782db067ae968 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 7 Sep 2021 18:03:35 +0200 Subject: [PATCH 11/12] Componente differ inserito ed aggiornato --- MP.Prog/Components/DiffView.razor | 122 ++++++++++++++++++++++ MP.Prog/Components/FileEditor.razor | 138 +++++++++++++------------ MP.Prog/Components/FileEditor.razor.cs | 17 +++ MP.Prog/MP.Prog.csproj | 1 + MP.Prog/Pages/Setup.razor | 43 ++++++-- 5 files changed, 249 insertions(+), 72 deletions(-) create mode 100644 MP.Prog/Components/DiffView.razor diff --git a/MP.Prog/Components/DiffView.razor b/MP.Prog/Components/DiffView.razor new file mode 100644 index 00000000..a3c2c59a --- /dev/null +++ b/MP.Prog/Components/DiffView.razor @@ -0,0 +1,122 @@ +@using MP.Prog.Data +@using System.Text +@using DiffMatchPatch + +
+
+

Archiviato

+
+ @((MarkupString)oldResult) +
+
+
+
+
+

Attuale

+
+
+ @numChanges modifiche +
+
+
+

@((MarkupString)newResult)">

+
+
+
+ +@code { + + string sepDest = "
"; + + protected string oldResult = ""; + protected string newResult = ""; + + protected string _oldText = ""; + protected string _newText = ""; + + protected int numChanges = 0; + + [Parameter] + public string oldText + { + get + { + return _oldText; + } + set + { + _oldText = value; + ReloadData(); + } + } + + protected string oldTextFix + { + get + { + return _oldText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest); + } + } + + protected string newTextFix + { + get + { + return _newText.Replace(Environment.NewLine, sepDest).Replace("\n", sepDest).Replace("\r", sepDest); + } + } + [Parameter] + public string newText + { + get + { + return _newText; + } + set + { + _newText = value; + ReloadData(); + } + } + protected void ReloadData() + { + numChanges = 0; + // calcolo diff + diff_match_patch dmp = new diff_match_patch(); + List diff = dmp.diff_main(oldTextFix, newTextFix); + dmp.diff_cleanupSemantic(diff); + + // predispongo la stringa secondo l'elenco dei diff.... + StringBuilder sbNew = new StringBuilder(); + StringBuilder sbOld = new StringBuilder(); + foreach (var item in diff) + { + switch (item.operation) + { + case Operation.DELETE: + sbOld.Append($"{item.text}"); + break; + case Operation.INSERT: + sbNew.Append($"{item.text}"); + numChanges++; + break; + case Operation.EQUAL: + sbNew.Append($"{item.text}"); + sbOld.Append($"{item.text}"); + break; + default: + break; + } + } + + newResult = sbNew.ToString().Trim(); + oldResult = sbOld.ToString().Trim(); + } + + protected override Task OnInitializedAsync() + { + ReloadData(); + return base.OnInitializedAsync(); + } + +} \ No newline at end of file diff --git a/MP.Prog/Components/FileEditor.razor b/MP.Prog/Components/FileEditor.razor index 5c60f582..bff5eda2 100644 --- a/MP.Prog/Components/FileEditor.razor +++ b/MP.Prog/Components/FileEditor.razor @@ -1,73 +1,81 @@ 
-
- Modifica +
+
+
+
Dettaglio modifiche
+
+
+ @if (_currItem.DiskStatus != FileData.FileState.Unchanged) + { +
+
+ +
+
+ +
+
+ } +
+
+
+
+ +
+
- - -
-
- @if (_currItem.DiskStatus != FileData.FileState.Unchanged) - { - - + @* + +
+
+
+
+ + + +
+ +
+
+
+ + + +
+ +

- } -
-
- - - -
- + +
-
-
- - - -
- +
+
-
- - -
-
- @*

@((MarkupString )_currItem.FileStringContent)

*@ - - @**@ -
-
- + *@ + +
+ +
-
- -

FileEditor

- -

mostrare dettaglio: diff? comando accetta/annulla?

- -Funzionalità: -
    -
  • Mostra dettagli file
  • -
  • Mostra contenuto file (SE NON modificato)
  • -
  • Mostra preview file modalità diff (se modificato)
  • -
  • dettaglio file: accetta (legge + new rel) / rifiuta (DB --> file) modifica
  • -
\ No newline at end of file + +
\ No newline at end of file diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs index 10b27abc..414afd65 100644 --- a/MP.Prog/Components/FileEditor.razor.cs +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -4,6 +4,7 @@ using MP.FileData.DatabaseModels; using MP.Prog.Data; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; @@ -15,6 +16,8 @@ namespace MP.Prog.Components public FileModel _currItem = new FileModel(); + public int pHeight = 20; + #endregion Public Fields #region Protected Properties @@ -126,6 +129,20 @@ namespace MP.Prog.Components #endregion Private Methods + #region Public Methods + + public string CurrFileContent(string fullPath) + { + string answ = ""; + if (File.Exists(fullPath)) + { + answ = File.ReadAllText(fullPath); + } + return answ; + } + + #endregion Public Methods + //protected override async Task OnInitializedAsync() //{ // await ReloadAllData(); diff --git a/MP.Prog/MP.Prog.csproj b/MP.Prog/MP.Prog.csproj index 74f23af8..8f98d113 100644 --- a/MP.Prog/MP.Prog.csproj +++ b/MP.Prog/MP.Prog.csproj @@ -13,6 +13,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/MP.Prog/Pages/Setup.razor b/MP.Prog/Pages/Setup.razor index 9c7b1836..d7f551ca 100644 --- a/MP.Prog/Pages/Setup.razor +++ b/MP.Prog/Pages/Setup.razor @@ -1,23 +1,52 @@ @page "/Setup" -@using MP.Prog.Components @using MP.Prog.Data +@using System.Text +@using DiffMatchPatch @inject MessageService AppMService

Setup

- - -

Selezionato @CurrCodArt

+
+
+ -
-
-
*@ - -
- -
-
- \ No newline at end of file diff --git a/MP.Prog/Components/FileEditor.razor.cs b/MP.Prog/Components/FileEditor.razor.cs index 414afd65..d600311a 100644 --- a/MP.Prog/Components/FileEditor.razor.cs +++ b/MP.Prog/Components/FileEditor.razor.cs @@ -12,12 +12,16 @@ namespace MP.Prog.Components { public partial class FileEditor : ComponentBase { + #region Protected Fields + + protected int numDiff = 0; + + #endregion Protected Fields + #region Public Fields public FileModel _currItem = new FileModel(); - public int pHeight = 20; - #endregion Public Fields #region Protected Properties @@ -129,6 +133,17 @@ namespace MP.Prog.Components #endregion Private Methods + #region Protected Methods + + protected void diffDoneHandler(int numChanges) + { +#if false + numDiff = numChanges; +#endif + } + + #endregion Protected Methods + #region Public Methods public string CurrFileContent(string fullPath) @@ -142,14 +157,5 @@ namespace MP.Prog.Components } #endregion Public Methods - - //protected override async Task OnInitializedAsync() - //{ - // await ReloadAllData(); - //} - - //protected async Task ReloadAllData() - //{ - //} } } \ No newline at end of file diff --git a/MP.Prog/Data/SelectData.cs b/MP.Prog/Data/SelectData.cs index 5c2cb00c..62f2a68b 100644 --- a/MP.Prog/Data/SelectData.cs +++ b/MP.Prog/Data/SelectData.cs @@ -13,7 +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 OnlyActive { get; set; } = true; public bool OnlyMod { get; set; } = false; #endregion Public Properties diff --git a/MP.Prog/Pages/Archive.razor b/MP.Prog/Pages/Archive.razor index efa91e4d..31c0b83f 100644 --- a/MP.Prog/Pages/Archive.razor +++ b/MP.Prog/Pages/Archive.razor @@ -99,7 +99,7 @@ { - @if (currRecord == null) + @if (currRecord == null && record.Active) {