diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3aad0c7..6939d2c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,6 +3,8 @@ variables: NEXUS_PATH: 'MagMan' APP_NAME: 'MagMan.UI' SOL_NAME: 'MagMan.UI' + NUGET_PATH: 'C:\Tools\nuget.exe' + MSBUILD_PATH: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe' # helper x fix pacchetti nuget da repo locale nexus.steamware.net .nuget-fix: &nuget-fix @@ -54,15 +56,59 @@ variables: mCurl -v -u GitLab:$NEXUS_PASSWD --upload-file "Resources\manifest.xml" https://nexus.steamware.net/repository/SWS/$env:NEXUS_PATH/$version/LAST/manifest.xml mCurl -v -u GitLab:$NEXUS_PASSWD --upload-file "Resources\ChangeLog.html" https://nexus.steamware.net/repository/SWS/$env:NEXUS_PATH/$version/LAST/ChangeLog.html - # mCurl -v -u $env:NEXUS_USER:$env:NEXUS_PASSWD --upload-file bin/release/$env:APP_NAME.zip $env:NEXUS_SERVER/utility/$env:NEXUS_PATH/$version/$env:APP_NAME-$version.zip +# helper x fix version number +.version-fix: &version-fix + - | + $env:NEW_REL = $env:VERS_MAIN+"."+(get-date -format yyMM)+"."+(get-date -format ddHH) + $env:NUM_REL = $env:VERS_MAIN+"."+(get-date -format yyMM)+"."+(get-date -format dHH) + $env:NUM_DEB = $env:VERS_MAIN+"."+(get-date -format yyMM)+"-beta."+(get-date -format dHH) + $env:NEW_COPYRIGHT = "EgalWare @ 2021-" + (get-date -format yyyy) + $contenuto = Get-Content -path 'VersGen\VersGen.cs' -Raw + $newContenuto = $contenuto -replace '0.0.0.0', $env:NEW_REL + $newContenuto = $newContenuto -replace 'EgalWare © 2021', $env:NEW_COPYRIGHT + $newContenuto | Set-Content -Path 'VersGen\VersGen.cs' + # display versioni generate + $resoconto = "Effettuato fix file VersGen | release v: " + $env:NUM_REL + " | debug v: " + $env:NUM_DEB; + Write-Output $resoconto; + echo "Replace completati" + +# helper x fix nuspec file +.nuspec-fix: &nuspec-fix + - | + echo "Modifica dati file nuspec Release" + $currRelease = $env:NUM_REL + $currDebug = $env:NUM_DEB + $find = "(.|\n)*?"; + $fileNameRel = "$env:APP_NAME.Release.nuspec"; + $replRel = "" + $currRelease + ""; + $nuspDataRel = Get-Content $fileNameRel; + $nuspDataRelUpd = $nuspDataRel -replace $find, $replRel; + $nuspDataRelUpd = $nuspDataRelUpd -replace "#copyright#", $replCopy; + $nuspDataRelUpd = $nuspDataRelUpd -replace "#releaseNotes#", "Build $adesso"; + Set-Content -Path $fileNameRel -Value $nuspDataRelUpd; + echo "Modifica dati file nuspec Debug" + $fileNameDeb = "$env:APP_NAME.Debug.nuspec"; + $replDeb = "" + $currDebug + ""; + $nuspDataDeb = Get-Content $fileNameDeb; + $nuspDataDebUpd = $nuspDataDeb -replace $find, $replDeb; + $nuspDataDebUpd = $nuspDataDebUpd -replace "#copyright#", $replCopy; + $nuspDataDebUpd = $nuspDataDebUpd -replace "#releaseNotes#", "Build $adesso"; + Set-Content -Path $fileNameDeb -Value $nuspDataDebUpd; + echo "replace completati" + + stages: - build + - staging - installer - # - release + - release -build: +# -------------------------------- +# BUILD +# -------------------------------- +MagMan.UI:build: stage: build tags: - win @@ -72,6 +118,49 @@ build: script: - echo $CI_COMMIT_BRANCH - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + +EgwProxy.MagMan:build: + stage: build + tags: + - win + variables: + APP_NAME: EgwProxy.MagMan + SOL_NAME: EgwProxy.MagMan + before_script: + - *nuget-fix + - '& "$env:NUGET_PATH" restore "$env:APP_NAME.sln" -verbosity quiet' + script: + - echo $CI_COMMIT_BRANCH + - dotnet build $env:APP_NAME/$env:APP_NAME.csproj + +# -------------------------------- +# STAGING (nuget beta) +# -------------------------------- +EgwProxy.MagMan:staging: + stage: staging + needs: ["EgwProxy.MagMan:build"] + tags: + - win + variables: + CONFIG: Debug + APP_NAME: EgwProxy.MagMan + SOL_NAME: EgwProxy.MagMan + only: + refs: + - develop + before_script: + - *nuget-fix + - '& "$env:NUGET_PATH" restore "$env:SOL_NAME.sln" -verbosity quiet' + - *version-fix + - *nuspec-fix + script: +# - '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=$env:CONFIG /p:Platform="Any CPU" /p:OutputPath=bin/$env:CONFIG /verbosity:minimal /m' + - dotnet build "$env:APP_NAME\$env:APP_NAME.csproj" + - '& Remove-Item *.nupkg' + - '& $env:NUGET_PATH pack "$env:APP_NAME.Debug.nuspec"' + - '& "$env:NUGET_PATH" setapikey $NUGET_API_KEY -source http://nexus.steamware.net/repository/nuget-hosted' + - '& "$env:NUGET_PATH" push *$env:NUM_DEB.nupkg -Source http://nexus.steamware.net/repository/nuget-hosted' + installer: stage: installer @@ -83,7 +172,7 @@ installer: before_script: - *nuget-fix - dotnet restore "$env:SOL_NAME.sln" - needs: ["build"] + needs: ["MagMan.UI:build"] script: # - dotnet publish -p:PublishProfile=IISProfile.pubxml -p:RunCodeAnalysis=false -p:Configuration=Release MagMan.UI/MagMan.UI.csproj -o:publish # pubblico solo installer Linux x64: https://docs.microsoft.com/en-us/dotnet/core/deploying/ @@ -92,19 +181,31 @@ installer: - *hashBuild - *nexusUpload -# release: -# stage: release -# tags: -# - win -# only: -# #- feature/Deploy_CI_CD -# # - main -# - tags -# except: -# - branches -# needs: ["build"] -# artifacts: -# paths: -# - publish/ -# script: -# - dotnet publish -c Release -o ./publish MagMan.UI/MagMan.UI.csproj \ No newline at end of file +# -------------------------------- +# RELEASE +# -------------------------------- + +EgwProxy.MagMan:release: + stage: release + needs: ["EgwProxy.MagMan:build"] + tags: + - win + variables: + CONFIG: Release + APP_NAME: EgwProxy.MagMan + SOL_NAME: EgwProxy.MagMan + only: + refs: + - SDK + before_script: + - *nuget-fix + - '& "$env:NUGET_PATH" restore "$env:SOL_NAME.sln" -verbosity quiet' + - *version-fix + - *nuspec-fix + script: + - dotnet build "$env:APP_NAME\$env:APP_NAME.csproj" + #- '& "$env:MSBUILD_PATH" "$env:APP_NAME\$env:APP_NAME.csproj" -target:Build /p:Configuration=$env:CONFIG /p:Platform="Any CPU" /p:OutputPath=bin/$env:CONFIG /verbosity:minimal /m' + - '& Remove-Item *.nupkg' + - '& $env:NUGET_PATH pack "$env:APP_NAME.Debug.nuspec"' + - '& "$env:NUGET_PATH" setapikey $NUGET_API_KEY -source http://nexus.steamware.net/repository/nuget-hosted' + - '& "$env:NUGET_PATH" push *$env:NUM_DEB.nupkg -Source http://nexus.steamware.net/repository/nuget-hosted' \ No newline at end of file diff --git a/EgwProxy.MagMan.Debug.nuspec b/EgwProxy.MagMan.Debug.nuspec new file mode 100644 index 0000000..2013a5d --- /dev/null +++ b/EgwProxy.MagMan.Debug.nuspec @@ -0,0 +1,24 @@ + + + + EgwProxy.MagMan + #version# + EgwProxy.MagMan + Samuele E. Locatelli, EgalWare + false + MIT + Libreria per comunicazione REST con server MagMan online/onsite per EgtBW - beta/unstable + #releaseNotes# + #copyright# + EgwProxy.MagMan MagMan Rest + + + + + + + + + + + \ No newline at end of file diff --git a/EgwProxy.MagMan.Release.nuspec b/EgwProxy.MagMan.Release.nuspec new file mode 100644 index 0000000..ef038dc --- /dev/null +++ b/EgwProxy.MagMan.Release.nuspec @@ -0,0 +1,23 @@ + + + + EgwProxy.MagMan + #version# + EgwProxy.MagMan + Samuele E. Locatelli, EgalWare + false + MIT + Libreria per comunicazione REST con server MagMan online/onsite per EgtBW + #releaseNotes# + #copyright# + EgwProxy.MagMan MagMan Rest + + + + + + + + + + \ No newline at end of file diff --git a/EgwProxy.MagMan.sln b/EgwProxy.MagMan.sln new file mode 100644 index 0000000..96190d3 --- /dev/null +++ b/EgwProxy.MagMan.sln @@ -0,0 +1,37 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34408.163 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApp", "TestConsoleApp\TestConsoleApp.csproj", "{57626C9A-AAE0-4A43-A7E9-610320DD9D31}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EgwProxy.MagMan", "EgwProxy.MagMan\EgwProxy.MagMan.csproj", "{1696D7A5-765A-4D25-8D29-CA7345023479}" +EndProject +Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "TestWinFormVB", "TestWinFormVB\TestWinFormVB.vbproj", "{665C94F5-27A6-4CD0-9487-036D199CDC47}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {57626C9A-AAE0-4A43-A7E9-610320DD9D31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {57626C9A-AAE0-4A43-A7E9-610320DD9D31}.Debug|Any CPU.Build.0 = Debug|Any CPU + {57626C9A-AAE0-4A43-A7E9-610320DD9D31}.Release|Any CPU.ActiveCfg = Release|Any CPU + {57626C9A-AAE0-4A43-A7E9-610320DD9D31}.Release|Any CPU.Build.0 = Release|Any CPU + {1696D7A5-765A-4D25-8D29-CA7345023479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1696D7A5-765A-4D25-8D29-CA7345023479}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1696D7A5-765A-4D25-8D29-CA7345023479}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1696D7A5-765A-4D25-8D29-CA7345023479}.Release|Any CPU.Build.0 = Release|Any CPU + {665C94F5-27A6-4CD0-9487-036D199CDC47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {665C94F5-27A6-4CD0-9487-036D199CDC47}.Debug|Any CPU.Build.0 = Debug|Any CPU + {665C94F5-27A6-4CD0-9487-036D199CDC47}.Release|Any CPU.ActiveCfg = Release|Any CPU + {665C94F5-27A6-4CD0-9487-036D199CDC47}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1A62D7FE-522B-4154-9525-DD9C529BF49B} + EndGlobalSection +EndGlobal diff --git a/EgwProxy.MagMan/DTO/ItemDTO.cs b/EgwProxy.MagMan/DTO/ItemDTO.cs new file mode 100644 index 0000000..4018507 --- /dev/null +++ b/EgwProxy.MagMan/DTO/ItemDTO.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwProxy.MagMan.DTO +{ + public class ItemDTO + { + + /// + /// Codice Univoco (DB) + /// + public int ItemID { get; set; } = 0; + /// + /// Codice Materiale di provenienza + /// + public int MatID { get; set; } = 0; + + /// + /// Check if is a Remnant + /// + public bool IsRemn { get; set; } = false; + + /// + /// Location + /// + public string Location { get; set; } = ""; + /// + /// Qty available on wharehouse + /// + public int QtyAvail { get; set; } = 0; + + /// + /// DateTime last modification + /// + public DateTime DtMod { get; set; } = DateTime.Now.AddYears(10); + + /// + /// Item's Lenght + /// + public decimal LMm { get; set; } = 0; + + /// + /// Item's Width + /// + public decimal WMm { get; set; } = 0; + + /// + /// Item's Thikness + /// + public decimal TMm { get; set; } = 0; + /// + /// Note + /// + public string Note { get; set; } = ""; + + /// + /// Codice QR/Matrix Item + /// + public string ItemDtmx { get; set; } = ""; + } +} diff --git a/EgwProxy.MagMan/DTO/MaterialDTO.cs b/EgwProxy.MagMan/DTO/MaterialDTO.cs new file mode 100644 index 0000000..576b9ca --- /dev/null +++ b/EgwProxy.MagMan/DTO/MaterialDTO.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EgwProxy.MagMan.DTO +{ + public class MaterialDTO + { + /// + /// Codice Univoco (DB) + /// + public int MatID { get; set; } = 0; + /// + /// Codice materiale (esterno) + /// + public int MatExtCode { get; set; } = 0; + /// + /// Descrizione materiale + /// + public string MatDesc { get; set; } = ""; + + /// + /// Lenght/Lunghezza in mm + /// + public decimal LMm { get; set; } = 0; + /// + /// Width/Larghezza in mm + /// + public decimal WMm { get; set; } = 0; + /// + /// Thikness/Spessore in mm + /// + public decimal TMm { get; set; } = 0; + /// + /// Codice QR/Matrix materiale + /// + public string MatDtmx { get; set; } = ""; + + /// + /// Elenco item e giancenze + /// + public List ItemList { get; set; } = new List(); + } +} diff --git a/EgwProxy.MagMan/DataSyncro.cs b/EgwProxy.MagMan/DataSyncro.cs new file mode 100644 index 0000000..3da4e60 --- /dev/null +++ b/EgwProxy.MagMan/DataSyncro.cs @@ -0,0 +1,190 @@ +using EgwProxy.MagMan.DTO; +using Newtonsoft.Json; +using RestSharp; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.NetworkInformation; +using System.Net; +using System.Text; +using System.Text.Json.Serialization; +using RestSharp.Serializers.NewtonsoftJson; +using System.Threading.Tasks; +using System.Web; + +namespace EgwProxy.MagMan +{ + public class DataSyncro + { + #region Public Constructors + + /// + /// Inizializza la libreria di comunicazione con il token assegnato + /// + /// + public DataSyncro(string serverUrl, string UserToken) + { + RestToken = UserToken; + servAddr = serverUrl; + apiUrl = $"https://{servAddr}/api/"; + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// Test ping x indirizzo indicato + /// + /// + /// + public static IPStatus pingAddress(string tgtAddr) + { + IPStatus answ = IPStatus.Unknown; + IPAddress address; + PingReply reply; + using (Ping pingSender = new Ping()) + { + address = IPAddress.Loopback; + int pingMsTimeout = 500; + IPAddress.TryParse(tgtAddr, out address); + try + { + // se != null --> uso tgtAddr... + if (address != null) + { + reply = pingSender.Send(address, pingMsTimeout); + } + else + { + reply = pingSender.Send(tgtAddr, pingMsTimeout); + } + } + catch + { + reply = pingSender.Send(IPAddress.Loopback, pingMsTimeout); + } + answ = reply.Status; + } + return answ; + } + + /// + /// Effettua chiamata test sul server (ping) + /// + /// + public bool CheckRemote() + { + IPAddress address = IPAddress.Loopback; + string srvIp = servAddr.Substring(0, servAddr.IndexOf(":")); + return pingAddress(srvIp) == IPStatus.Success; + } + + /// + /// Elenco Materiali dato RestToken + /// + public async Task> MaterialsGet() + { + List answ = new List(); + // cerco online + RestClient client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var request = new RestRequest($"Materials/{MKeyEnc}", Method.Get); + var response = await client.GetAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = JsonConvert.DeserializeObject>(rawData); + } + return await Task.FromResult(answ); + } + /// + /// Invia un elenco (anche parziale) di Materiali, il server farà il merge + /// + public async Task MaterialsSend(List List2Merge) + { + bool answ = false; + // cerco online + var client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var jsonBody = JsonConvert.SerializeObject(List2Merge); + var request = new RestRequest($"Materials/upsert/{MKeyEnc}", Method.Post).AddJsonBody(jsonBody); + var response = await client.PostAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = rawData == "OK"; + } + return await Task.FromResult(answ); + } + + /// + /// Inventario per materiale + /// + /// Se 0 = tutto + /// + public async Task> InventoryGet(int MatID) + { + List answ = new List(); + // cerco online + RestClient client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var request = new RestRequest($"Inventory/{MKeyEnc}?MatId={MatID}", Method.Get); + var response = await client.GetAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = JsonConvert.DeserializeObject>(rawData); + } + return await Task.FromResult(answ); + } + /// + /// Invia un elenco di RawItems associati ad un singolo materiale, il server farà il merge + /// + public async Task InventorySend(MaterialDTO Mat2Merge) + { + bool answ = false; + // cerco online + var client = new RestClient(apiUrl); + string MKeyEnc = HttpUtility.UrlEncode(RestToken); + var jsonBody = JsonConvert.SerializeObject(Mat2Merge.ItemList); + var request = new RestRequest($"Inventory/upsert/{MKeyEnc}", Method.Post).AddJsonBody(jsonBody); + var response = await client.PostAsync(request); + // controllo risposta + if (response.StatusCode == HttpStatusCode.OK) + { + // contenuto serializzato + string rawData = $"{response.Content}"; + answ = rawData == "OK"; + } + return await Task.FromResult(answ); + } + + #endregion Public Methods + + #region Private Fields + + /// + /// URL dell'API x chiamate gestione licenze + /// + private string apiUrl = $""; + + /// + /// Token di chiamata per l'applicazione + /// + private string RestToken = ""; + + /// + /// Indirizzo server (URL con eventuale porta) + /// + private string servAddr = $""; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/EgwProxy.MagMan/EgwProxy.MagMan.csproj b/EgwProxy.MagMan/EgwProxy.MagMan.csproj new file mode 100644 index 0000000..25c7dfa --- /dev/null +++ b/EgwProxy.MagMan/EgwProxy.MagMan.csproj @@ -0,0 +1,89 @@ + + + + + Debug + AnyCPU + {1696D7A5-765A-4D25-8D29-CA7345023479} + Library + Properties + EgwProxy.MagMan + EgwProxy.MagMan + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.7.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll + + + ..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Text.Encodings.Web.7.0.0\lib\net462\System.Text.Encodings.Web.dll + + + ..\packages\System.Text.Json.7.0.3\lib\net462\System.Text.Json.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EgwProxy.MagMan/Properties/AssemblyInfo.cs b/EgwProxy.MagMan/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2d320c4 --- /dev/null +++ b/EgwProxy.MagMan/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("EgwProxy.MagMan")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("EgwProxy.MagMan")] +[assembly: AssemblyCopyright("Copyright © 2024")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("1696d7a5-765a-4d25-8d29-ca7345023479")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/EgwProxy.MagMan/app.config b/EgwProxy.MagMan/app.config new file mode 100644 index 0000000..8922cd8 --- /dev/null +++ b/EgwProxy.MagMan/app.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/EgwProxy.MagMan/packages.config b/EgwProxy.MagMan/packages.config new file mode 100644 index 0000000..c5ca275 --- /dev/null +++ b/EgwProxy.MagMan/packages.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MagMan.Core/DTO/ItemDTO.cs b/MagMan.Core/DTO/ItemDTO.cs new file mode 100644 index 0000000..ab807f2 --- /dev/null +++ b/MagMan.Core/DTO/ItemDTO.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagMan.Core.DTO +{ + public class ItemDTO + { + /// + /// Ext ref for Material + /// + public int MatId { get; set; } = 0; + + /// + /// Key del RawItem di riferimento (se zero da verificare con quote) + /// + public int RawItemId { get; set; } = 0; + + /// + /// Check if is a Remnant + /// + public bool IsRemn { get; set; } = false; + + /// + /// Location + /// + public string Location { get; set; } = ""; + + /// + /// Qty available on wharehouse + /// + public int QtyAvail { get; set; } = 0; + + /// + /// Item's Lenght + /// + public decimal LMm { get; set; } = 0; + + /// + /// Item's Width + /// + public decimal WMm { get; set; } = 0; + + /// + /// Item's Thikness + /// + public decimal HMm { get; set; } = 0; + + /// + /// Note (optional) + /// + public string Note { get; set; } = ""; + } +} diff --git a/MagMan.Core/DTO/MaterialDTO.cs b/MagMan.Core/DTO/MaterialDTO.cs index 1c98963..5ab8283 100644 --- a/MagMan.Core/DTO/MaterialDTO.cs +++ b/MagMan.Core/DTO/MaterialDTO.cs @@ -8,27 +8,21 @@ namespace MagMan.Core.DTO { public class MaterialDTO { + /// + /// Primary Key Materiale, 0 se proviente da EgtBeamWall + /// + public int MatId { get; set; } = 0; /// - /// Codice materiale (esterno) + /// Codice Materiale /// - public int MatExtCode { get; set; } = 0; + public string MatCode { get; set; } = ""; + /// /// Descrizione materiale /// public string MatDesc { get; set; } = ""; -#if false - /// - /// Data approvazione (se non approvato è nel futuro) - /// - public DateTime ApprovDate { get; set; } = DateTime.Now.AddYears(100); - /// - /// Utente approvazione amteriale - /// - public string ApprovUser { get; set; } = ""; -#endif - /// /// Lenght/Lunghezza in mm /// @@ -40,6 +34,6 @@ namespace MagMan.Core.DTO /// /// Thikness/Spessore in mm /// - public decimal TMm { get; set; } = 0; + public decimal HMm { get; set; } = 0; } } diff --git a/MagMan.Core/DTO/ProjectDTO.cs b/MagMan.Core/DTO/ProjectDTO.cs new file mode 100644 index 0000000..b8bb59c --- /dev/null +++ b/MagMan.Core/DTO/ProjectDTO.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MagMan.Core.Enums; + +namespace MagMan.Core.DTO +{ + public class ProjectDTO + { + /// + /// Id macchina (MagMan) + /// + public int MachineID { get; set; } = 0; + + /// + /// Key di riferimento per il progetto + /// + public int KeyNum { get; set; } = 0; + + /// + /// ID del DB EgtBW, univoco con KeyNum + /// + public int ProjExtDbId { get; set; } = 0; + + /// + /// ID esterno (da EgtBW) + /// + public int ProjExtId { get; set; } = 0; + + /// + /// Nome file BTL originale + /// + public string BTLFileName { get; set; } = ""; + + /// + /// Tipologia del progetto (Travi, Pareti, ...) + /// + public BWType PType { get; set; } = BWType.NULL; + + /// + /// Macchina (Costruttore/Modello) + /// + public string Machine { get; set; } = ""; + + /// + /// Descrizione progetto (copiata da BTLFileName inizialmente) + /// + public string ProjDescription { get; set; } = ""; + + /// + /// Data Creazione progetto + /// + public DateTime DtCreated { get; set; } = DateTime.Now; + + /// + /// Data di schedulazione (prevista) + /// + public DateTime DtSchedule { get; set; } = DateTime.Today.AddMonths(3); + + /// + /// Data Inizio Produzione + /// + public DateTime DtStartProd { get; set; } = DateTime.MinValue; + + /// + /// Data ora ultima operazione registrata + /// + public DateTime DtLastAction { get; set; } = DateTime.MinValue; + + /// + /// ListName del BTL + /// + public string ListName { get; set; } = ""; + + /// + /// Tempo lavorazione previsto (stima) in minuti + /// + public double ProcTimeEst { get; set; } = 0; + + /// + /// Tempo lavorazione reale in minuti (parziale o totale se chiuso/completato/archiviato) + /// + public double ProcTimeReal { get; set; } = 0; + + /// + /// Record attivo (se false == cancellazione logica) + /// + public bool IsActive { get; set; } = true; + + /// + /// Stato Archiviato = NON visualizzabile normalmente, già prodotto/chiuso + /// + public bool IsArchived { get; set; } = false; + + } +} diff --git a/MagMan.Core/DTO/ResourceDTO.cs b/MagMan.Core/DTO/ResourceDTO.cs new file mode 100644 index 0000000..510bf11 --- /dev/null +++ b/MagMan.Core/DTO/ResourceDTO.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagMan.Core.DTO +{ + public class ResourceDTO + { + /// + /// Ext ref for Material + /// + public int RawItemId { get; set; } = 0; + /// + /// Qty, se > 0 rappresenta un IMPEGNO di qualsiasi tipo, se < 0 è un CONSUMO + /// + public int Qty { get; set; } = 0; + + } +} diff --git a/MagMan.Core/Enums.cs b/MagMan.Core/Enums.cs index 573e11e..4df7c47 100644 --- a/MagMan.Core/Enums.cs +++ b/MagMan.Core/Enums.cs @@ -1,7 +1,18 @@ -namespace MagMan.Core +using StackExchange.Redis; + +namespace MagMan.Core { public class Enums { + #region Public Enums + + public enum BWType + { + NULL = 0, + BEAM = 1, + WALL = 2 + } + public enum ItemState { None, @@ -10,5 +21,39 @@ Request, } + + public enum ProjResState + { + /// + /// Registrazione consumo effettivo (update giacenza su tab RawItemList) + /// + Consumed = -1, + /// + /// Non definito + /// + ND = 0, + /// + /// Consumo stimato da nesting (solo simulazione) + /// + Estimated, + /// + /// Consumo confermato (da ordinare) + /// + Confirmed, + /// + /// Riservato (utile x calcolo quantità da ordinare) + /// + Reserved + } + + public enum ResultTypes + { + NULL = 0, + EXECUTED = 1, + RESULT = 2 + } + + + #endregion Public Enums } -} +} \ No newline at end of file diff --git a/MagMan.Core/MagMan.Core.csproj b/MagMan.Core/MagMan.Core.csproj index df2e60e..934f236 100644 --- a/MagMan.Core/MagMan.Core.csproj +++ b/MagMan.Core/MagMan.Core.csproj @@ -7,9 +7,12 @@ + + + diff --git a/MagMan.Core/RestPayload.cs b/MagMan.Core/RestPayload.cs index 6eeaf40..7566fc5 100644 --- a/MagMan.Core/RestPayload.cs +++ b/MagMan.Core/RestPayload.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using MagMan.Core.DTO; +using static MagMan.Core.Enums; namespace MagMan.Core { @@ -16,5 +17,28 @@ namespace MagMan.Core /// public List? MatList { get; set; } } + public class Items + { + /// + /// Elenco Items x invio POST + /// + public List? ItemList { get; set; } + } + + public class Resources + { + /// + /// ID progetto univoco esterno (da associare a KEY) + /// + public int ProjDbId { get; set; } = 0; + /// + /// Tipo di registrazione dato inviata (previsione consumo, consumo effettivo...) + /// + public ProjResState ReqState { get; set; } = ProjResState.ND; + /// + /// Elenco Risorse x invio POST + /// + public List? ResourceList { get; set; } + } } } diff --git a/MagMan.Core/Services/MessageService.cs b/MagMan.Core/Services/MessageService.cs new file mode 100644 index 0000000..a3dc8dc --- /dev/null +++ b/MagMan.Core/Services/MessageService.cs @@ -0,0 +1,627 @@ +using Blazored.LocalStorage; +using Blazored.SessionStorage; +using NLog; +using StackExchange.Redis; +using System.Diagnostics; + +namespace MagMan.Core.Services +{ + public class MessageService + { + #region Public Constructors + + public MessageService(ILocalStorageService genLocalStorage, ISessionStorageService sessStore, IConnectionMultiplexer RedConn) + { + // gestione sessioni in browser + localStore = genLocalStorage; + sessionStore = sessStore; + // setup componenti REDIS + redisConn = RedConn; + redisDb = redisConn.GetDatabase(); + } + + #endregion Public Constructors + + #region Public Events + + public event Action EA_FilterUpdated = null!; + + public event Action EA_HideSearch = null!; + + public event Action EA_PageUpdated = null!; + + public event Action EA_SearchUpdated = null!; + + public event Action EA_ShowSearch = null!; + + #endregion Public Events + +#if false + public SelectData DetailFilter + { + get => _detailFilter; + set + { + if (_detailFilter != value) + { + _detailFilter = value; + + if (EA_FilterUpdated != null) + { + EA_FilterUpdated?.Invoke(); + } + } + } + } + + public SelectOrderData Order_Filter { get; set; } = SelectOrderData.Init(5, 30); +#endif + + #region Public Properties + + public string PageIcon + { + get => _pageIcon; + set + { + if (_pageIcon != value) + { + _pageIcon = value; + ReportPageUpd(); + } + } + } + + public string PageName + { + get => _pageName; + set + { + if (_pageName != value) + { + _pageName = value; + ReportPageUpd(); + } + } + } + + public string SearchVal + { + get => _searchVal; + set + { + if (_searchVal != value) + { + _searchVal = value; + + if (EA_SearchUpdated != null) + { + EA_SearchUpdated?.Invoke(); + } + } + } + } + + public string SelOrderCode { get; set; } = ""; + public string SelPlantId { get; set; } = "0"; + + public bool ShowSearch + { + get => _showSearch; + set + { + if (_showSearch != value) + { + _showSearch = value; + if (_showSearch) + { + if (EA_ShowSearch != null) + { + EA_ShowSearch?.Invoke(); + } + } + else + { + if (EA_HideSearch != null) + { + EA_HideSearch?.Invoke(); + } + } + } + } + } + + /// + /// Cliente selezionato (da browser data cache) + /// + public async Task ClientIdGet() + { + var answ = await localStore.GetItemAsync("ClientID"); + return answ; + } + + /// + /// Imposta Cliente selezionato (browser data cache) + /// + public async Task ClientIdSet(int machSel) + { + await localStore.SetItemAsync("ClientID", machSel); + } + + #endregion Public Properties + + #region Public Methods + + /// + /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// + /// + /// + public async Task CustomerIdByToken(string RestToken) + { + string currKey = $"{Const.rKeyConfig}:Dict:Token2CustID"; + int answ = await RedisHashGetInt(currKey, RestToken); + return answ; + } + + /// + /// salvataggio in dizionario Redis associativo Token / Customer + /// + /// + /// + /// + public bool CustomerIdByTokenSet(string RestToken, int CustId) + { + string currKey = $"{Const.rKeyConfig}:Dict:Token2CustID"; + bool fatto = RedisHashSet(currKey, RestToken, $"{CustId}"); + return fatto; + } + + /// + /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// + /// + /// + public async Task MainKeyByCustomer(int CustID) + { + string currKey = $"{Const.rKeyConfig}:Dict:Cust2MKey"; + int answ = await RedisHashGetInt(currKey, $"{CustID}"); + return answ; + } + + /// + /// salvataggio in dizionario Redis associativo Token / Customer + /// + /// + /// + /// + public bool MainKeyByCustomerSet(int CustId, int MainKey) + { + string currKey = $"{Const.rKeyConfig}:Dict:Cust2MKey"; + bool fatto = RedisHashSet(currKey, $"{CustId}", $"{MainKey}"); + return fatto; + } + + /// + /// Recupera MainKey dal dizionario dei token noti o cercando sul DB + /// + /// + /// + public async Task MainKeyByToken(string RestToken) + { + string currKey = $"{Const.rKeyConfig}:Dict:Token2MKey"; + int answ = await RedisHashGetInt(currKey, RestToken); + return answ; + } + + /// + /// salvataggio in dizionario Redis associativo Token / Customer + /// + /// + /// + /// + public bool MainKeyByTokenSet(string RestToken, int CustId) + { + string currKey = $"{Const.rKeyConfig}:Dict:Token2MKey"; + bool fatto = RedisHashSet(currKey, RestToken, $"{CustId}"); + return fatto; + } + + /// + /// Get single hash record + /// + /// Redis Key for Hashlist + /// Requested key on list + /// Value as Int + public async Task RedisHashGetInt(RedisKey currKey, string chiave) + { + int result = 0; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + var hasVal = await redisDb.HashExistsAsync(currKey, chiave); + if (hasVal) + { + var rawRes = await redisDb.HashGetAsync(currKey, chiave); + if (rawRes.HasValue) + { + int.TryParse($"{rawRes}", out result); + } + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"RedisHashGetInt | {currKey} | in: {ts.TotalMilliseconds} ms"); + return result; + } + + /// + /// Get single hash record + /// + /// Redis Key for Hashlist + /// Requested key on list + /// Value as string + public async Task RedisHashGetString(RedisKey currKey, string chiave) + { + string result = ""; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + var hasVal = await redisDb.HashExistsAsync(currKey, chiave); + if (hasVal) + { + var rawRes = await redisDb.HashGetAsync(currKey, chiave); + if (rawRes.HasValue) + { + result = $"{rawRes}"; + } + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"RedisHashGetString | {currKey} | in: {ts.TotalMilliseconds} ms"); + return result; + } + + /// + /// Remove for single hash record + /// + /// Chiave redis della Hashlist + /// Chiave nella HashList + /// Esito rimozione + public async Task RedisHashRemove(RedisKey currKey, string chiave) + { + bool fatto = false; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + fatto = await redisDb.HashDeleteAsync(currKey, chiave); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"RedisHashRemove | {currKey} | in: {ts.TotalMilliseconds} ms"); + return fatto; + } + + /// + /// Resetta 1:1 i dizionari Hash in Redis + /// + /// + public bool ResetHashDict() + { + bool fatto = false; + string baseKey = $"{Const.rKeyConfig}:Dict"; + try + { + // salvo! + RedisHashDictSet($"{baseKey}:Token2CustID", new Dictionary()); + RedisHashDictSet($"{baseKey}:Token2MKey", new Dictionary()); + RedisHashDictSet($"{baseKey}:Cust2MKey", new Dictionary()); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in ResetHashDict{Environment.NewLine}{exc}"); + } + return fatto; + } + + /// + /// Svuota localstorage (clear) + /// + /// + public async Task StoreLocalClear() + { + bool answ = false; + try + { + await localStore.ClearAsync(); + answ = true; + } + catch (Exception ex) + { + Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); + } + return answ; + } + + /// + /// Restituisce il valore richiesto da localstorage + /// + /// Chiave + /// + public async Task StoreLocalGet(string sKey) + { + string answ = ""; + var result = await localStore.GetItemAsync(sKey); + if (result != null) + { + answ = result; + } + return answ; + } + + /// + /// Scrive il valore nel localstorage + /// + /// Chiave + /// Valore associato + /// + public async Task StoreLocalSet(string sKey, string sVal) + { + bool answ = false; + try + { + await localStore.SetItemAsStringAsync(sKey, sVal); + answ = true; + } + catch (Exception ex) + { + Log.Error($"Eccezione in StoreLocalSet{Environment.NewLine}{ex}"); + } + return answ; + } + + /// + /// Svuota sessionstorage (clear) + /// + /// + public async Task StoreSessClear() + { + bool answ = false; + try + { + await sessionStore.ClearAsync(); + answ = true; + } + catch (Exception ex) + { + Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); + } + return answ; + } + + /// + /// Restituisce il valore richiesto da sessionstorage + /// + /// Chiave + /// + public async Task StoreSessGet(string sKey) + { + string answ = ""; + var result = await sessionStore.GetItemAsync(sKey); + if (result != null) + { + answ = result; + } + return answ; + } + + /// + /// Scrive il valore nel sessionstorage (tab) + /// + /// Chiave + /// Valore associato + /// + public async Task StoreSessSet(string sKey, string sVal) + { + bool answ = false; + try + { + await sessionStore.SetItemAsStringAsync(sKey, sVal); + answ = true; + } + catch (Exception ex) + { + Log.Error($"Eccezione in StoreSessSet{Environment.NewLine}{ex}"); + } + return answ; + } + + #endregion Public Methods + + #region Protected Fields + + /// + /// Oggetto per connessione a REDIS + /// + protected IConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + protected IDatabase redisDb = null!; + + #endregion Protected Fields + + #region Protected Properties + + protected ILocalStorageService localStore { get; set; } = null!; + protected ISessionStorageService sessionStore { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + /// + /// Effettua upsert in HasList redis + /// + /// Chiave redis della Hashlist + /// Chiave nella HashList + /// Valore da salvare + /// Num record nella HashList + protected async Task RedisHashUpsert(RedisKey currKey, string chiave, string valore) + { + long numReq = 0; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + await redisDb.HashSetAsync(currKey, chiave, valore); + numReq = await redisDb.HashLengthAsync(currKey); + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Trace($"RedisHashUpsert | {currKey} | in: {ts.TotalMilliseconds} ms"); + return numReq; + } + + #endregion Protected Methods + +#if false + private SelectData _detailFilter = SelectData.Init(5, 15); +#endif + + #region Private Fields + + private string _pageIcon = ""; + private string _pageName = ""; + private string _searchVal = ""; + private bool _showSearch = false; + private Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + + #region Private Methods + + /// + /// Recupero HashSet redis come Dictionary + /// + /// + /// + private Dictionary RedisHashDictGet(RedisKey currKey) + { + Dictionary answ = new Dictionary(); + try + { + answ = redisDb + .HashGetAll(currKey) + .ToDictionary(x => $"{x.Name}", x => $"{x.Value}"); + } + catch (Exception exc) + { + Log.Info($"Errore RedisHashDictGet | currKey: {currKey}{Environment.NewLine}{exc}"); + } + return answ; + } + + /// + /// Salvataggio Dictionary come HashSet Redis + /// + /// + /// + private bool RedisHashDictSet(RedisKey currKey, Dictionary dict) + { + bool fatto = false; + try + { + HashEntry[] data2ins = new HashEntry[dict.Count]; + int i = 0; + foreach (KeyValuePair kvp in dict) + { + data2ins[i] = new HashEntry(kvp.Key, kvp.Value); + i++; + } + // salvo! + redisDb.HashSet(currKey, data2ins); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in RedisHashDictSet | currKey: {currKey}{Environment.NewLine}{exc}"); + } + return fatto; + } + + /// + /// Salvataggio Dictionary come HashSet Redis + /// + /// + /// + /// + private bool RedisHashDictSet(RedisKey currKey, Dictionary dict, TimeSpan ttl) + { + bool fatto = false; + try + { + HashEntry[] data2ins = new HashEntry[dict.Count]; + int i = 0; + foreach (KeyValuePair kvp in dict) + { + data2ins[i] = new HashEntry(kvp.Key, kvp.Value); + i++; + } + // salvo! + redisDb.HashSet(currKey, data2ins); + redisDb.KeyExpire(currKey, ttl); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in RedisHashDictSet(+TTL) | currKey: {currKey} | ttl: {ttl}{Environment.NewLine}{exc}"); + } + return fatto; + } + + /// + /// Aggiunta KVP in HashSet Redis + /// + /// + /// + private bool RedisHashSet(RedisKey currKey, string hashField, string value) + { + bool fatto = false; + try + { + // salvo! + redisDb.HashSet(currKey, hashField, value); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in RedisHashSet | currKey: {currKey}{Environment.NewLine}{exc}"); + } + return fatto; + } + + private void ReportPageUpd() + { + if (EA_PageUpdated != null) + { + EA_PageUpdated?.Invoke(); + } + } + + private void ReportSearch() + { + if (EA_SearchUpdated != null) + { + EA_SearchUpdated?.Invoke(); + } + } + + #endregion Private Methods + +#if false + /// + /// Dizionario totale preferenze utente + /// + public Dictionary UsersPrefDict + { + get => RedisHashDictGet((RedisKey)$"{redisBaseKey}:{MatrOpr}"); + set => RedisHashDictSet((RedisKey)$"{redisBaseKey}:{MatrOpr}", value); + } +#endif + } +} \ No newline at end of file diff --git a/MagMan.Data.Admin/MagMan.Data.Admin.csproj b/MagMan.Data.Admin/MagMan.Data.Admin.csproj index 2406b07..b222b78 100644 --- a/MagMan.Data.Admin/MagMan.Data.Admin.csproj +++ b/MagMan.Data.Admin/MagMan.Data.Admin.csproj @@ -15,7 +15,7 @@ - + diff --git a/MagMan.Data.Admin/Services/MTAdminService.cs b/MagMan.Data.Admin/Services/MTAdminService.cs index 808fa58..70eac3e 100644 --- a/MagMan.Data.Admin/Services/MTAdminService.cs +++ b/MagMan.Data.Admin/Services/MTAdminService.cs @@ -1,4 +1,5 @@ using MagMan.Core; +using MagMan.Core.Services; using MagMan.Data.Admin.Controllers; using MagMan.Data.Admin.DbModels; using Microsoft.AspNetCore.Identity.UI.Services; @@ -14,12 +15,6 @@ namespace MagMan.Data.Admin.Services { public class MTAdminService : BaseServ { - #region Public Fields - - public static MTAdminController dbController = null!; - - #endregion Public Fields - #region Public Constructors public MTAdminService(IConfiguration configuration, IConnectionMultiplexer redisConnMult, IEmailSender emailSender) @@ -238,6 +233,34 @@ namespace MagMan.Data.Admin.Services return dbResult; } + /// + /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// + /// + /// + public async Task CustomerIdByToken(string RestToken) + { + int answ = -1; + if (TokenCustList.ContainsKey(RestToken)) + { + answ = TokenCustList[RestToken]; + } + else + { + // cerco nel DB + var custList = await CustomerGetAll(); + var custRow = custList.FirstOrDefault(x => x.RestToken == RestToken); + // se trovato salvo + if (custRow != null) + { + answ = custRow.CustomerID; + TokenCustList.Add(RestToken, answ); + Log.Info($"TokenCustList: added {RestToken} --> {answ}"); + } + } + return answ; + } + /// /// Update record customer + refresh cache /// @@ -395,39 +418,36 @@ namespace MagMan.Data.Admin.Services return fatto; } - #endregion Public Methods - - #region Protected Methods - /// /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB /// - /// + /// /// - public async Task CustomerIdByToken(string RestToken) + public async Task MainKeyByCustomer(int CustID) { int answ = -1; - if (TokenCustList.ContainsKey(RestToken)) + if (CustMKeyList.ContainsKey(CustID)) { - answ = TokenCustList[RestToken]; + answ = CustMKeyList[CustID]; } else { // cerco nel DB var custList = await CustomerGetAll(); - var custRow = custList.FirstOrDefault(x => x.RestToken == RestToken); + var custRow = custList.FirstOrDefault(x => x.CustomerID == CustID); // se trovato salvo if (custRow != null) { - answ = custRow.CustomerID; - TokenCustList.Add(RestToken, answ); - Log.Info($"TokenCustList: added {RestToken} --> {answ}"); + answ = custRow.MainKey; + CustMKeyList.Add(CustID, answ); + Log.Info($"TokenMKeyList: added {CustID} --> {answ}"); } } return answ; } + /// - /// Recupera CustomerID dal dizionario dei token noti o cercando sul DB + /// Recupera MainKey dal dizionario dei token noti o cercando sul DB /// /// /// @@ -454,11 +474,16 @@ namespace MagMan.Data.Admin.Services return answ; } - #endregion Protected Methods + #endregion Public Methods + + #region Protected Fields + + protected static MTAdminController dbController = null!; + + #endregion Protected Fields #region Private Fields - private static JsonSerializerSettings? JSSettings; private static Logger Log = LogManager.GetCurrentClassLogger(); @@ -495,18 +520,22 @@ namespace MagMan.Data.Admin.Services #region Private Properties /// - /// Dizionario dei token 2 customer + /// Dizionario customer 2 MainKey (x calcolo DB) + /// + private Dictionary CustMKeyList { get; set; } = new Dictionary(); + + /// + /// Dizionario dei token 2 customer /// private Dictionary TokenCustList { get; set; } = new Dictionary(); + /// - /// Dizionario dei token 2 MainKey (x calcolo DB) + /// Dizionario dei token 2 MainKey (x calcolo DB) /// private Dictionary TokenMKeyList { get; set; } = new Dictionary(); #endregion Private Properties - - #region Private Methods /// diff --git a/MagMan.Data.Tenant/Controllers/TenantController.cs b/MagMan.Data.Tenant/Controllers/TenantController.cs index 436a8b4..44fe134 100644 --- a/MagMan.Data.Tenant/Controllers/TenantController.cs +++ b/MagMan.Data.Tenant/Controllers/TenantController.cs @@ -1,4 +1,5 @@ using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using NLog; @@ -45,7 +46,7 @@ namespace MagMan.Data.Tenant.Controllers /// Stringa connessione (variabile x cliente) /// Item da eliminare /// - public bool ItemDelete(string connString, ItemModel rec2del) + public bool ItemDelete(string connString, RawItemModel rec2del) { bool done = false; using (MagManContext dbCtx = new MagManContext(connString)) @@ -54,7 +55,7 @@ namespace MagMan.Data.Tenant.Controllers { var currData = dbCtx .DbSetItems - .Where(x => x.ItemID == rec2del.ItemID) + .Where(x => x.RawItemId == rec2del.RawItemId) .FirstOrDefault(); if (currData != null) { @@ -78,16 +79,16 @@ namespace MagMan.Data.Tenant.Controllers /// /// Stringa connessione (variabile x cliente) /// - public List ItemGetAll(string connString) + public List ItemGetAll(string connString) { - List dbResult = new List(); + List dbResult = new List(); using (MagManContext dbCtx = new MagManContext(connString)) { dbResult = dbCtx .DbSetItems //.Where(x => CustomerId == 0 || x.CustomerID == CustomerId) .Include(c => c.MaterialNav) - .OrderBy(x => x.MatID) + .OrderBy(x => x.MatId) .ToList(); } return dbResult; @@ -99,52 +100,95 @@ namespace MagMan.Data.Tenant.Controllers /// Stringa connessione (variabile x cliente) /// ID del materiale x cui filtrare, 0 = tutti /// - public List ItemGetByMat(string connString, int matID) + public List ItemGetByMat(string connString, int matID) { - List dbResult = new List(); + List dbResult = new List(); using (MagManContext dbCtx = new MagManContext(connString)) { dbResult = dbCtx .DbSetItems - .Where(x => matID == 0 || x.MatID == matID) + .Where(x => matID == 0 || x.MatId == matID) .Include(c => c.MaterialNav) - //.OrderBy(x => x.MatID) + //.OrderBy(x => x.MatId) .OrderBy(x => x.WMm) - .ThenBy(x => x.TMm) + .ThenBy(x => x.HMm) .ThenBy(x => x.LMm) .ToList(); } return dbResult; } + /// Aggiunge/Modifica un item in magazzino Stringa connessione (variabile x cliente) Record da aggiornare quantità da + /// aggiornare (se <0 è consumo) + public bool ItemModQty(string connString, RawItemModel rec2upd, int deltaQty) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + /* + * Verifica se esistesse: deve essere valido TUTTO + * - stesso materiale + * - stesse dimensioni + * */ + var currData = dbCtx + .DbSetItems + .Where(x => (x.RawItemId == rec2upd.RawItemId) || + (x.MatId == rec2upd.MatId && (x.WMm == rec2upd.WMm && x.HMm == rec2upd.HMm && x.LMm == rec2upd.LMm))) + .FirstOrDefault(); + if (currData != null) + { + currData.QtyAvail += deltaQty; + dbCtx.Entry(currData).State = EntityState.Modified; + } + dbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in ItemModQty{Environment.NewLine}{exc}"); + } + } + return done; + } + /// /// Aggiunge/Modifica un item in magazzino /// /// Stringa connessione (variabile x cliente) /// Record da aggiungere/aggiornare /// - public bool ItemUpdate(string connString, ItemModel rec2upd) + public bool ItemUpdate(string connString, RawItemModel rec2upd) { bool done = false; using (MagManContext dbCtx = new MagManContext(connString)) { try { + /* + * Verifica se esistesse: deve essere valido TUTTO + * - stesso materiale + * - stesse dimensioni + * */ var currData = dbCtx .DbSetItems - .Where(x => x.ItemID == rec2upd.ItemID) + .Where(x => (x.RawItemId == rec2upd.RawItemId) || + (x.MatId == rec2upd.MatId && (x.WMm == rec2upd.WMm && x.HMm == rec2upd.HMm && x.LMm == rec2upd.LMm))) .FirstOrDefault(); if (currData != null) { - currData.MatID = rec2upd.MatID; + currData.MatId = rec2upd.MatId; + currData.QtyAvail = rec2upd.QtyAvail; + currData.IsActive = rec2upd.IsActive; currData.IsRemn = rec2upd.IsRemn; currData.Location = rec2upd.Location; - currData.QtyAvail = rec2upd.QtyAvail; - currData.Note = rec2upd.Note; currData.LMm = rec2upd.LMm; - currData.TMm = rec2upd.TMm; + currData.HMm = rec2upd.HMm; currData.WMm = rec2upd.WMm; - currData.DtMod = rec2upd.DtMod; + currData.Note = rec2upd.Note; dbCtx.Entry(currData).State = EntityState.Modified; } else @@ -179,7 +223,7 @@ namespace MagMan.Data.Tenant.Controllers { var currData = dbCtx .DbSetMaterials - .Where(x => x.MatID == rec2del.MatID) + .Where(x => x.MatId == rec2del.MatId) .FirstOrDefault(); if (currData != null) { @@ -203,18 +247,68 @@ namespace MagMan.Data.Tenant.Controllers /// /// Stringa connessione (variabile x cliente) /// - public List MaterialGetAll(string connString) + public List MaterialGetAll(string connString, bool withChild) { List dbResult = new List(); using (MagManContext dbCtx = new MagManContext(connString)) { - dbResult = dbCtx - .DbSetMaterials - .OrderBy(x => x.MatDesc) - .ThenBy(x => x.WMm) - .ThenBy(x => x.TMm) - .ThenBy(x => x.LMm) - .ToList(); + if (withChild) + { + dbResult = dbCtx + .DbSetMaterials + .Include(x => x.RawItemList) + .OrderBy(x => x.MatDesc) + .ThenBy(x => x.WMm) + .ThenBy(x => x.HMm) + .ThenBy(x => x.LMm) + .ToList(); + } + else + { + dbResult = dbCtx + .DbSetMaterials + .OrderBy(x => x.MatDesc) + .ThenBy(x => x.WMm) + .ThenBy(x => x.HMm) + .ThenBy(x => x.LMm) + .ToList(); + } + } + return dbResult; + } /// + + /// Elenco Materiali gestiti a magazzino Stringa + /// connessione (variabile x cliente) Materiale richiesto, 0 + /// = tutti Se true allora include record child + /// (Items) + public List MaterialGetFilt(string connString, int matID, bool withChild) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + if (withChild) + { + dbResult = dbCtx + .DbSetMaterials + .Where(x => matID == 0 || x.MatId == matID) + .Include(x => x.RawItemList) + .OrderBy(x => x.MatDesc) + .ThenBy(x => x.WMm) + .ThenBy(x => x.HMm) + .ThenBy(x => x.LMm) + .ToList(); + } + else + { + dbResult = dbCtx + .DbSetMaterials + .Where(x => matID == 0 || x.MatId == matID) + .OrderBy(x => x.MatDesc) + .ThenBy(x => x.WMm) + .ThenBy(x => x.HMm) + .ThenBy(x => x.LMm) + .ToList(); + } } return dbResult; } @@ -232,18 +326,24 @@ namespace MagMan.Data.Tenant.Controllers { try { + /* + * Ricerca equal: corrisponde se + * - MatId identico + * - se Uguali + NonNulli [MatCode oppure MatDescript] + uguali [W/H/L]... + */ var currData = dbCtx .DbSetMaterials - .Where(x => x.MatID == rec2upd.MatID || x.MatExtCode==rec2upd.MatExtCode) + .Where(x => (rec2upd.MatId > 0 && x.MatId == rec2upd.MatId) || + ((x.WMm == rec2upd.WMm && x.HMm == rec2upd.HMm && x.LMm == rec2upd.LMm) && + ((!string.IsNullOrEmpty(rec2upd.MatCode) && x.MatCode == rec2upd.MatCode) || (!string.IsNullOrEmpty(rec2upd.MatDesc) && x.MatDesc == rec2upd.MatDesc)) + )) .FirstOrDefault(); if (currData != null) { - currData.MatExtCode = rec2upd.MatExtCode; + currData.MatCode = rec2upd.MatCode; currData.MatDesc = rec2upd.MatDesc; - currData.ApprovDate = rec2upd.ApprovDate; - currData.ApprovUser = rec2upd.ApprovUser; currData.LMm = rec2upd.LMm; - currData.TMm = rec2upd.TMm; + currData.HMm = rec2upd.HMm; currData.WMm = rec2upd.WMm; dbCtx.Entry(currData).State = EntityState.Modified; } @@ -264,6 +364,165 @@ namespace MagMan.Data.Tenant.Controllers return done; } + /// + /// Elimina record Project + /// + /// Stringa connessione (variabile x cliente) + /// Item da eliminare + /// + public bool ProjectDelete(string connString, ProjModel rec2del) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + var currData = dbCtx + .DbSetProjects + .Where(x => x.ProjDbId == rec2del.ProjDbId) + .FirstOrDefault(); + if (currData != null) + { + dbCtx + .DbSetProjects + .Remove(currData); + dbCtx.SaveChanges(); + done = true; + } + } + catch (Exception exc) + { + Log.Error($"Eccezione in ProjectDelete{Environment.NewLine}{exc}"); + } + } + return done; + } + + /// + /// Elenco Projects (all) + /// + /// Stringa connessione (variabile x cliente) + /// + public List ProjectGetAll(string connString) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco Items gestiti a magazzino dato Materiale + /// + /// Stringa connessione (variabile x cliente) + /// ID del materiale x cui filtrare, 0 = tutti + /// + public List ProjectGetByNumKey(string connString, int numKey) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .Where(x => numKey == 0 || x.KeyNum == numKey) + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco Items gestiti a magazzino dato Materiale + /// + /// Stringa connessione (variabile x cliente) + /// ID master key, 0 = tutti + /// periodo x filtraggio + /// + public List ProjectGetFilt(string connString, int numKey, SelectData period) + { + List dbResult = new List(); + using (MagManContext dbCtx = new MagManContext(connString)) + { + dbResult = dbCtx + .DbSetProjects + .Where(x => (numKey == 0 || x.KeyNum == numKey) && + ((x.DtCreated >= period.DateStart && x.DtCreated <= period.DateEnd) + || (x.DtSchedule >= period.DateStart && x.DtSchedule <= period.DateEnd) + || (x.DtLastAction >= period.DateStart && x.DtLastAction <= period.DateEnd) + )) + .OrderBy(x => x.DtCreated) + .ToList(); + } + return dbResult; + } + + /// + /// Aggiunge/Modifica un record Project + /// + /// Stringa connessione (variabile x cliente) + /// Record da aggiungere/aggiornare + /// + public bool ProjectUpdate(string connString, ProjModel rec2upd) + { + bool done = false; + using (MagManContext dbCtx = new MagManContext(connString)) + { + try + { + /* + * Ricerca: + * - DbId corrisponde + * - Key + Id remoti corrispondono + * */ + var currData = dbCtx + .DbSetProjects + .Where(x => (x.ProjDbId == rec2upd.ProjDbId) || + (x.ProjExtDbId == rec2upd.ProjExtDbId && x.KeyNum == rec2upd.KeyNum) || + (x.ProjExtId == rec2upd.ProjExtId && x.KeyNum == rec2upd.KeyNum)) + .FirstOrDefault(); + if (currData != null) + { + currData.MachineID = rec2upd.MachineID; + currData.KeyNum = rec2upd.KeyNum; + currData.ProjExtDbId = rec2upd.ProjExtDbId; + currData.ProjExtId = rec2upd.ProjExtId; + currData.BTLFileName = rec2upd.BTLFileName; + currData.PType = rec2upd.PType; + currData.Machine = rec2upd.Machine; + currData.ProjDescription = rec2upd.ProjDescription; + currData.DtCreated = rec2upd.DtCreated; + currData.DtLastAction = rec2upd.DtLastAction; + currData.DtSchedule = rec2upd.DtSchedule; + currData.DtStartProd = rec2upd.DtStartProd; + currData.ListName = rec2upd.ListName; + currData.ProcTimeEst = rec2upd.ProcTimeEst; + currData.ProcTimeReal = rec2upd.ProcTimeReal; + currData.IsActive = rec2upd.IsActive; + currData.IsArchived = rec2upd.IsArchived; + dbCtx.Entry(currData).State = EntityState.Modified; + } + else + { + dbCtx + .DbSetProjects + .Add(rec2upd); + } + dbCtx.SaveChanges(); + done = true; + } + catch (Exception exc) + { + Log.Error($"Eccezione in ItemUpdate{Environment.NewLine}{exc}"); + } + } + return done; + } + #endregion Public Methods #region Private Fields diff --git a/MagMan.Data.Tenant/DbModels/AliasModel.cs b/MagMan.Data.Tenant/DbModels/AliasModel.cs new file mode 100644 index 0000000..1d0b6fc --- /dev/null +++ b/MagMan.Data.Tenant/DbModels/AliasModel.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MagMan.Data.Tenant.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + [Table("AliasList")] + public class AliasModel + { + /// + /// Famiglia di sinonimi + /// + public string Family { get; set; } = ""; + + /// + /// Codice originale (da trasformare) + /// + public string ValueOriginal { get; set; } = ""; + + /// + /// Codice Alias in cui viene convertito + /// + public string ValueAlias { get; set; } = ""; + } +} diff --git a/MagMan.Data.Tenant/DbModels/LogMachineModel.cs b/MagMan.Data.Tenant/DbModels/LogMachineModel.cs new file mode 100644 index 0000000..15e65fc --- /dev/null +++ b/MagMan.Data.Tenant/DbModels/LogMachineModel.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using static MagMan.Core.Enums; + +namespace MagMan.Data.Tenant.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + /// + /// Tabella dei LOG Macchina (per macchina) + /// + [Table("LogMachine")] + [Index(nameof(MachineID))] + [Index(nameof(KeyNum))] + public class LogMachineModel + { + [Key, Column("DbId"), DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int LogDbId { get; set; } + + /// + /// Id macchina (diMagMan) + /// + public int MachineID { get; set; } = 0; + + /// + /// Key di riferimento per il progetto + /// + public int KeyNum { get; set; } = 0; + +#if false + /// + /// Codice Allarme + /// + [Column("AlarmCode")] + public string AlarmCode { get; set; } = ""; + + /// + /// Data Evento + /// + [Column("AlarmDtEvent")] + public DateTime AlarmDatetime { get; set; } = DateTime.Now; + + /// + /// Messaggio Allarme + /// + [Column("AlarmMessage")] + public string AlarmMessage { get; set; } = ""; + + /// + /// Alarm Operation + /// + [Column("AlarmOperation")] + public int AlarmOperation { get; set; } = 0; + + /// + /// Alarm Type + /// + [Column("AlarmType")] + public int AlarmType { get; set; } = 0; + + /// + /// Esaecuzione comando corretta + /// + [Column("CommExecuted")] + public bool CommandExecutedCorrectly { get; set; } = false; + + /// + /// Stato da enum Core + /// + [Column("CommandState")] + public Core.ConstMachComm.CommandStates CommandState { get; set; } = Core.ConstMachComm.CommandStates.NULL; + + /// + /// Tipo Comando da enum Core + /// + [Column("CommandType")] + public Core.ConstMachComm.LogCommandTypes CommandType { get; set; } = Core.ConstMachComm.LogCommandTypes.NULL; + + /// + /// Descrizione + /// + [Column("Description")] + public string Description { get; set; } = ""; + + + + /// + /// New OP State + /// + [Column("NewOpState")] + public int NewOpState { get; set; } = 0; +#endif + + /// + /// Stato da enum Core + /// + [Column("ResultType")] + public ResultTypes ResultType { get; set; } = ResultTypes.NULL; + + /// + /// Indirizzo VAR + /// + [Column("VarAddress")] + public string VarAddress { get; set; } = ""; + + /// + /// Valore VAR + /// + [Column("VarValue")] + public string VarValue { get; set; } = ""; + + + } +} diff --git a/MagMan.Data.Tenant/DbModels/MaterialModel.cs b/MagMan.Data.Tenant/DbModels/MaterialModel.cs index 8b1cf3d..4217ef9 100644 --- a/MagMan.Data.Tenant/DbModels/MaterialModel.cs +++ b/MagMan.Data.Tenant/DbModels/MaterialModel.cs @@ -11,30 +11,33 @@ namespace MagMan.Data.Tenant.DbModels // // This is here so CodeMaid doesn't reorganize this document // - [Table("Materials")] + [Table("MaterialsList")] public partial class MaterialModel { - [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int MatID { get; set; } + /// + /// Init classe + /// + public MaterialModel() + { + RawItemList = new HashSet(); + } /// - /// Codice materiale (esterno) + /// Primary Key AUTO /// - public int MatExtCode { get; set; } = 0; + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int MatId { get; set; } + + /// + /// Codice Materiale + /// + public string MatCode { get; set; } = ""; + /// /// Descrizione materiale /// public string MatDesc { get; set; } = ""; - /// - /// Data approvazione (se non approvato è nel futuro) - /// - public DateTime ApprovDate { get; set; } = DateTime.Now.AddYears(100); - /// - /// Utente approvazione amteriale - /// - public string ApprovUser { get; set; } = ""; - /// /// Lenght/Lunghezza in mm /// @@ -44,10 +47,11 @@ namespace MagMan.Data.Tenant.DbModels /// public decimal WMm { get; set; } = 0; /// - /// Thikness/Spessore in mm + /// Height (Thikness/Spessore) in mm /// - public decimal TMm { get; set; } = 0; + public decimal HMm { get; set; } = 0; +#if false /// /// Lenght/Lunghezza in inch /// @@ -68,10 +72,11 @@ namespace MagMan.Data.Tenant.DbModels /// Thikness/Spessore in inch /// [NotMapped] - public decimal TIn + public decimal HIn { - get => Math.Round(TMm / (decimal)25.4, 3); - } + get => Math.Round(HMm / (decimal)25.4, 3); + } +#endif /// /// Codice materiale x QR/Datamatrix @@ -79,10 +84,30 @@ namespace MagMan.Data.Tenant.DbModels [NotMapped] public string MatDtmx { - get => $"MT{MatExtCode:00000000}"; + get => $"MT{MatId:00000000}"; } + /// + /// Verifica che sia Beam, quando L == 0 + /// + [NotMapped] + public bool IsBeam + { + get => (LMm == 0 && (HMm > 0 && WMm > 0)); + } - public virtual ICollection? ItemNav { get; set; } + /// + /// Verifica che sia Wall, quando W/L == 0 + /// + [NotMapped] + public bool IsWall + { + get => (HMm > 0 && (LMm == 0 && WMm == 0)); + } + + /// + /// Navigazione ad oggetti child + /// + public virtual ICollection? RawItemList { get; set; } } } diff --git a/MagMan.Data.Tenant/DbModels/MovMagModel.cs b/MagMan.Data.Tenant/DbModels/MovMagModel.cs index 32aac01..6cdd62e 100644 --- a/MagMan.Data.Tenant/DbModels/MovMagModel.cs +++ b/MagMan.Data.Tenant/DbModels/MovMagModel.cs @@ -44,8 +44,8 @@ namespace MagMan.Data.Tenant.DbModels /// /// Navigation property to Items /// - [ForeignKey("ItemID")] - public virtual ItemModel? ITemNav { get; set; } + [ForeignKey("RawItemId")] + public virtual RawItemModel? ITemNav { get; set; } } } diff --git a/MagMan.Data.Tenant/DbModels/ProjModel.cs b/MagMan.Data.Tenant/DbModels/ProjModel.cs new file mode 100644 index 0000000..0a124b6 --- /dev/null +++ b/MagMan.Data.Tenant/DbModels/ProjModel.cs @@ -0,0 +1,123 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static MagMan.Core.Enums; + +namespace MagMan.Data.Tenant.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + /// + /// Tabella dei PROJ caricati da EgtBeamWall + /// + [Table("ProjList")] + [Index(nameof(MachineID))] + [Index(nameof(KeyNum))] + [Index(nameof(ProjExtDbId))] + [Index(nameof(IsActive))] + [Index(nameof(IsArchived))] + public class ProjModel + { + #region Public Properties + + /// + /// Chiave univoca su DB + /// + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ProjDbId { get; set; } + + /// + /// Id macchina (MagMan) + /// + public int MachineID { get; set; } = 0; + + /// + /// Key di riferimento per il progetto + /// + public int KeyNum { get; set; } = 0; + + /// + /// ID del DB EgtBW, univoco con KeyNum + /// + public int ProjExtDbId { get; set; } = 0; + + /// + /// ID esterno (da EgtBW) + /// + public int ProjExtId { get; set; } = 0; + + /// + /// Nome file BTL originale + /// + public string BTLFileName { get; set; } = ""; + + /// + /// Tipologia del progetto (Travi, Pareti, ...) + /// + public BWType PType { get; set; } = BWType.NULL; + + /// + /// Macchina (Costruttore/Modello) + /// + public string Machine { get; set; } = ""; + + /// + /// Descrizione progetto (copiata da BTLFileName inizialmente) + /// + public string ProjDescription { get; set; } = ""; + + /// + /// Data Creazione progetto + /// + public DateTime DtCreated { get; set; } = DateTime.Now; + + /// + /// Data di schedulazione (prevista) + /// + public DateTime DtSchedule { get; set; } = DateTime.Today.AddMonths(3); + + /// + /// Data Inizio Produzione + /// + public DateTime DtStartProd { get; set; } = DateTime.MinValue; + + /// + /// Data ora ultima operazione registrata + /// + public DateTime DtLastAction { get; set; } = DateTime.MinValue; + + /// + /// ListName del BTL + /// + public string ListName { get; set; } = ""; + + /// + /// Tempo lavorazione previsto (stima) in minuti + /// + public double ProcTimeEst { get; set; } = 0; + + /// + /// Tempo lavorazione reale in minuti (parziale o totale se chiuso/completato/archiviato) + /// + public double ProcTimeReal { get; set; } = 0; + + /// + /// Record attivo (se false == cancellazione logica) + /// + public bool IsActive { get; set; } = true; + + /// + /// Stato Archiviato = NON visualizzabile normalmente, già prodotto/chiuso + /// + public bool IsArchived { get; set; } = false; + + #endregion Public Properties + } +} diff --git a/MagMan.Data.Tenant/DbModels/ItemModel.cs b/MagMan.Data.Tenant/DbModels/RawItemModel.cs similarity index 76% rename from MagMan.Data.Tenant/DbModels/ItemModel.cs rename to MagMan.Data.Tenant/DbModels/RawItemModel.cs index e4a8eac..40644dd 100644 --- a/MagMan.Data.Tenant/DbModels/ItemModel.cs +++ b/MagMan.Data.Tenant/DbModels/RawItemModel.cs @@ -12,19 +12,29 @@ namespace MagMan.Data.Tenant.DbModels // This is here so CodeMaid doesn't reorganize this document // //[Index(nameof(Installazione), nameof(Active), nameof(DiskStatus))] - [Table("ItemsList")] - public partial class ItemModel + [Table("RawItemList")] + public partial class RawItemModel { /// /// Primary Key AUTO /// [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] - public int ItemID { get; set; } + public int RawItemId { get; set; } /// /// Ext ref for Material /// - public int MatID { get; set; } = 0; + public int MatId { get; set; } = 0; + + /// + /// Qty available on wharehouse + /// + public int QtyAvail { get; set; } = 0; + + /// + /// Check if is a Remnant + /// + public bool IsActive { get; set; } = false; /// /// Check if is a Remnant @@ -35,16 +45,6 @@ namespace MagMan.Data.Tenant.DbModels /// Location /// public string Location { get; set; } = ""; - /// - /// Qty available on wharehouse - /// - public int QtyAvail { get; set; } = 0; - - /// - /// DateTime last modification - /// - public DateTime DtMod { get; set; } = DateTime.Now.AddYears(10); - /// /// Item's Lenght /// @@ -56,10 +56,16 @@ namespace MagMan.Data.Tenant.DbModels public decimal WMm { get; set; } = 0; /// - /// Item's Thikness + /// Item's Height (Thikness/Spessore) in mm /// - public decimal TMm { get; set; } = 0; + public decimal HMm { get; set; } = 0; + /// + /// Note (optional) + /// + public string Note { get; set; } = ""; + +#if false [NotMapped] public decimal LIn { @@ -71,22 +77,18 @@ namespace MagMan.Data.Tenant.DbModels get => Math.Round(WMm / (decimal)25.4, 3); } [NotMapped] - public decimal TIn + public decimal HIn { - get => Math.Round(TMm / (decimal)25.4, 3); - } + get => Math.Round(HMm / (decimal)25.4, 3); + } - /// - /// Note (optional) - /// - public string Note { get; set; } = ""; - [NotMapped] public decimal Area { get => LMm * WMm; } +#endif [NotMapped] @@ -94,10 +96,10 @@ namespace MagMan.Data.Tenant.DbModels { get { - string answ = $"MT99999999-{LMm * 1000:00000000}"; + string answ = $"MT99999999W{WMm * 10:000000}H{HMm * 10:000000}L{LMm * 10:000000}"; if (MaterialNav != null) { - answ = $"MT{MaterialNav.MatExtCode:00000000}-{LMm * 1000:00000000}"; + answ = $"MT{MaterialNav.MatId:00000000}W{WMm * 10:000000}H{HMm * 10:000000}L{LMm * 10:000000}"; } return answ; } @@ -106,7 +108,7 @@ namespace MagMan.Data.Tenant.DbModels /// /// Navigation property to Material /// - [ForeignKey("MatID")] + [ForeignKey("MatId")] public virtual MaterialModel MaterialNav { get; set; } = null!; } diff --git a/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs b/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs new file mode 100644 index 0000000..cfa204a --- /dev/null +++ b/MagMan.Data.Tenant/DbModels/RequestPlanModel.cs @@ -0,0 +1,57 @@ +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; +using static MagMan.Core.Enums; + +namespace MagMan.Data.Tenant.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + /// + /// Tabella dei Piano Richieste associate a Proj + /// + [Table("RequestPlan")] + public class RequestPlanModel + { + /// + /// Init classe + /// + public RequestPlanModel() + { + ResourcesList = new HashSet(); + } + + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int RequestId { get; set; } + + /// + /// Progetto di riferimento + /// + public int ProjDbId { get; set; } + + /// + /// Data richiesta + /// + public DateTime DtRequest { get; set; } + + /// + /// Tipo richiesta + /// + public ProjResState ReqState { get; set; } = ProjResState.ND; + + /// + /// Record attivo (se false == NON è il piano scelto per i casi "previsionali" = ReqState >0 ) + /// + public bool IsActive { get; set; } = true; + + /// + /// Navigazione ad oggetti child + /// + public virtual ICollection? ResourcesList { get; set; } + } +} diff --git a/MagMan.Data.Tenant/DbModels/ResourceModel.cs b/MagMan.Data.Tenant/DbModels/ResourceModel.cs new file mode 100644 index 0000000..e8e2a45 --- /dev/null +++ b/MagMan.Data.Tenant/DbModels/ResourceModel.cs @@ -0,0 +1,45 @@ +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; +using static MagMan.Core.Enums; + +namespace MagMan.Data.Tenant.DbModels +{ + // + // This is here so CodeMaid doesn't reorganize this document + // + /// + /// Tabella esplosione risorse (richiesta + items) + /// + [Table("ResourceList")] + public class ResourceModel + { + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ResourceId { get; set; } + + /// + /// Riferimento richiesta parent + /// + public int RequestId { get; set; } = 0; + + /// + /// Riferimento RawItem specifico + /// + public int RawItemId { get; set; } = 0; + + /// + /// Qty, se > 0 rappresenta un IMPEGNO di qualsiasi tipo, se < 0 è un CONSUMO + /// + public int Qty { get; set; } = 0; + + /// + /// Navigation property to RequestPlan + /// + [ForeignKey("RequestId")] + public virtual RequestPlanModel RequestNav { get; set; } = null!; + } +} diff --git a/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj b/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj index 4be0bad..b27104d 100644 --- a/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj +++ b/MagMan.Data.Tenant/MagMan.Data.Tenant.csproj @@ -13,7 +13,11 @@ - + + + + + @@ -38,6 +42,7 @@ + diff --git a/MagMan.Data.Tenant/MagManContext.cs b/MagMan.Data.Tenant/MagManContext.cs index d4ed53c..0be9330 100644 --- a/MagMan.Data.Tenant/MagManContext.cs +++ b/MagMan.Data.Tenant/MagManContext.cs @@ -33,56 +33,27 @@ namespace MagMan.Data.Tenant connString = currConnString; } -#if false - public MagManContext(DbContextOptions options) : base(options) - { - try - { - // se non ci fosse... crea o migra! - Database.Migrate(); - } - catch (Exception exc) - { - Log.Error(exc, "Exception during context initialization 02"); - } - } -#endif - #endregion Public Constructors #region Public Properties public virtual DbSet DbSetConfig { get; set; } = null!; - public virtual DbSet DbSetItems { get; set; } = null!; + public virtual DbSet DbSetItems { get; set; } = null!; public virtual DbSet DbSetMaterials { get; set; } = null!; - public virtual DbSet DbSetMovMag { get; set; } = null!; - public virtual DbSet DbSetPrintJob { get; set; } = null!; + public virtual DbSet DbSetRawItem { get; set; } = null!; + public virtual DbSet DbSetAlias { get; set; } = null!; + public virtual DbSet DbSetProjects { get; set; } = null!; + public virtual DbSet DbSetReqPlan { get; set; } = null!; + public virtual DbSet DbSetResources { get; set; } = null!; + #if false - public virtual DbSet DbSetKeyVal { get; set; } - - public virtual DbSet DbSetListVal { get; set; } - - public virtual DbSet DbSetOrders { get; set; } - - public virtual DbSet DbSetParamSend { get; set; } - - public virtual DbSet DbSetParamSet { get; set; } - - public virtual DbSet DbSetPlant { get; set; } - - public virtual DbSet DbSetPlantLog { get; set; } - - public virtual DbSet DbSetPlantStatus { get; set; } - - public virtual DbSet DbSetPlantSupplWeekPlan { get; set; } - - public virtual DbSet DbSetSupplier { get; set; } - - public virtual DbSet DbSetTransporter { get; set; } + public virtual DbSet DbSetMovMag { get; set; } = null!; + public virtual DbSet DbSetPrintJob { get; set; } = null!; #endif + private string connString = ""; #endregion Public Properties @@ -99,6 +70,9 @@ namespace MagMan.Data.Tenant { if (!optionsBuilder.IsConfigured) { +#if DEBUG + connString = "Server=localhost;port=3306;database=MagMan_000470;uid=MagMan_DbUser;pwd=viad@nte16!;sslmode=None;"; +#endif var serverVersion = ServerVersion.AutoDetect(connString); optionsBuilder.UseMySql(connString, serverVersion); } @@ -117,13 +91,8 @@ namespace MagMan.Data.Tenant .HasComment("Valore di default/riferimento per la variabile"); }); -#if false - modelBuilder.Entity().HasKey(c => new { c.TabName, c.FieldName, c.Val }); - - modelBuilder.Entity().HasKey(c => new { c.PlantId, c.FluxType }); - - modelBuilder.Entity().HasKey(c => new { c.PlantId, c.ParamUid }); -#endif + modelBuilder.Entity() + .HasKey(c => new { c.Family, c.ValueOriginal}); modelBuilder.Seed(); diff --git a/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.Designer.cs b/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.Designer.cs deleted file mode 100644 index 9171131..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.Designer.cs +++ /dev/null @@ -1,56 +0,0 @@ -// -using MagMan.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - [DbContext(typeof(MagManContext))] - [Migration("20231222163946_InitDb")] - partial class InitDb - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.25") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("MagMan.Data.DbModels.ConfigModel", b => - { - b.Property("KeyName") - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(0); - - b.Property("Note") - .IsRequired() - .HasMaxLength(250) - .HasColumnType("varchar(250)") - .HasColumnOrder(3); - - b.Property("Val") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(1); - - b.Property("ValStd") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(2) - .HasComment("Valore di default/riferimento per la variabile"); - - b.HasKey("KeyName"); - - b.ToTable("Config"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.cs b/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.cs deleted file mode 100644 index 0a7e484..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222163946_InitDb.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - public partial class InitDb : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "Config", - columns: table => new - { - KeyName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Val = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ValStd = table.Column(type: "varchar(50)", maxLength: 50, nullable: false, comment: "Valore di default/riferimento per la variabile") - .Annotation("MySql:CharSet", "utf8mb4"), - Note = table.Column(type: "varchar(250)", maxLength: 250, nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_Config", x => x.KeyName); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Config"); - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.Designer.cs b/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.Designer.cs deleted file mode 100644 index f1aa296..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.Designer.cs +++ /dev/null @@ -1,149 +0,0 @@ -// -using System; -using MagMan.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - [DbContext(typeof(MagManContext))] - [Migration("20231222180319_AddMagBaseObj")] - partial class AddMagBaseObj - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.25") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("MagMan.Data.DbModels.ConfigModel", b => - { - b.Property("KeyName") - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(0); - - b.Property("Note") - .IsRequired() - .HasMaxLength(250) - .HasColumnType("varchar(250)") - .HasColumnOrder(3); - - b.Property("Val") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(1); - - b.Property("ValStd") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(2) - .HasComment("Valore di default/riferimento per la variabile"); - - b.HasKey("KeyName"); - - b.ToTable("Config"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => - { - b.Property("ItemID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("DtMod") - .HasColumnType("datetime(6)"); - - b.Property("IsRemn") - .HasColumnType("tinyint(1)"); - - b.Property("LMm") - .HasColumnType("decimal(65,30)"); - - b.Property("Location") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("MatID") - .HasColumnType("int"); - - b.Property("Note") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("QtyAvail") - .HasColumnType("int"); - - b.Property("TMm") - .HasColumnType("decimal(65,30)"); - - b.Property("WMm") - .HasColumnType("decimal(65,30)"); - - b.HasKey("ItemID"); - - b.HasIndex("MatID"); - - b.ToTable("ItemsList"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => - { - b.Property("MatID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ApprovDate") - .HasColumnType("datetime(6)"); - - b.Property("ApprovUser") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("LMm") - .HasColumnType("decimal(65,30)"); - - b.Property("MatDesc") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("MatExtCode") - .HasColumnType("int"); - - b.Property("TMm") - .HasColumnType("decimal(65,30)"); - - b.Property("WMm") - .HasColumnType("decimal(65,30)"); - - b.HasKey("MatID"); - - b.ToTable("Materials"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => - { - b.HasOne("MagMan.Data.DbModels.MaterialModel", "MaterialNav") - .WithMany("ItemNav") - .HasForeignKey("MatID") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("MaterialNav"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => - { - b.Navigation("ItemNav"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.cs b/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.cs deleted file mode 100644 index b141d32..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222180319_AddMagBaseObj.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - public partial class AddMagBaseObj : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Materials", - columns: table => new - { - MatID = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - MatExtCode = table.Column(type: "int", nullable: false), - MatDesc = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ApprovDate = table.Column(type: "datetime(6)", nullable: false), - ApprovUser = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - LMm = table.Column(type: "decimal(65,30)", nullable: false), - WMm = table.Column(type: "decimal(65,30)", nullable: false), - TMm = table.Column(type: "decimal(65,30)", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Materials", x => x.MatID); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "ItemsList", - columns: table => new - { - ItemID = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - MatID = table.Column(type: "int", nullable: false), - IsRemn = table.Column(type: "tinyint(1)", nullable: false), - Location = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - QtyAvail = table.Column(type: "int", nullable: false), - DtMod = table.Column(type: "datetime(6)", nullable: false), - LMm = table.Column(type: "decimal(65,30)", nullable: false), - WMm = table.Column(type: "decimal(65,30)", nullable: false), - TMm = table.Column(type: "decimal(65,30)", nullable: false), - Note = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_ItemsList", x => x.ItemID); - table.ForeignKey( - name: "FK_ItemsList_Materials_MatID", - column: x => x.MatID, - principalTable: "Materials", - principalColumn: "MatID", - onDelete: ReferentialAction.Restrict); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateIndex( - name: "IX_ItemsList_MatID", - table: "ItemsList", - column: "MatID"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "ItemsList"); - - migrationBuilder.DropTable( - name: "Materials"); - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.Designer.cs b/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.Designer.cs deleted file mode 100644 index bc5a906..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.Designer.cs +++ /dev/null @@ -1,221 +0,0 @@ -// -using System; -using MagMan.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - [DbContext(typeof(MagManContext))] - [Migration("20231222180523_AddMagBaseObj01")] - partial class AddMagBaseObj01 - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.25") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("MagMan.Data.DbModels.ConfigModel", b => - { - b.Property("KeyName") - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(0); - - b.Property("Note") - .IsRequired() - .HasMaxLength(250) - .HasColumnType("varchar(250)") - .HasColumnOrder(3); - - b.Property("Val") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(1); - - b.Property("ValStd") - .IsRequired() - .HasMaxLength(50) - .HasColumnType("varchar(50)") - .HasColumnOrder(2) - .HasComment("Valore di default/riferimento per la variabile"); - - b.HasKey("KeyName"); - - b.ToTable("Config"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => - { - b.Property("ItemID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("DtMod") - .HasColumnType("datetime(6)"); - - b.Property("IsRemn") - .HasColumnType("tinyint(1)"); - - b.Property("LMm") - .HasColumnType("decimal(65,30)"); - - b.Property("Location") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("MatID") - .HasColumnType("int"); - - b.Property("Note") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("QtyAvail") - .HasColumnType("int"); - - b.Property("TMm") - .HasColumnType("decimal(65,30)"); - - b.Property("WMm") - .HasColumnType("decimal(65,30)"); - - b.HasKey("ItemID"); - - b.HasIndex("MatID"); - - b.ToTable("ItemsList"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => - { - b.Property("MatID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ApprovDate") - .HasColumnType("datetime(6)"); - - b.Property("ApprovUser") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("LMm") - .HasColumnType("decimal(65,30)"); - - b.Property("MatDesc") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("MatExtCode") - .HasColumnType("int"); - - b.Property("TMm") - .HasColumnType("decimal(65,30)"); - - b.Property("WMm") - .HasColumnType("decimal(65,30)"); - - b.HasKey("MatID"); - - b.ToTable("Materials"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MovMagModel", b => - { - b.Property("MovID") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("DtRec") - .HasColumnType("datetime(6)"); - - b.Property("ItemID") - .HasColumnType("int"); - - b.Property("QtyRec") - .HasColumnType("int"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("MovID"); - - b.HasIndex("ItemID"); - - b.ToTable("MovMag"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.PrintJobQueueModel", b => - { - b.Property("IdxPrintJob") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("DtEnd") - .HasColumnType("datetime(6)"); - - b.Property("DtLastTry") - .HasColumnType("datetime(6)"); - - b.Property("DtStart") - .HasColumnType("datetime(6)"); - - b.Property("KeyParam") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PrtName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Stato") - .HasColumnType("int"); - - b.Property("TipoReport") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("IdxPrintJob"); - - b.ToTable("PrintJobQueue"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => - { - b.HasOne("MagMan.Data.DbModels.MaterialModel", "MaterialNav") - .WithMany("ItemNav") - .HasForeignKey("MatID") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("MaterialNav"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MovMagModel", b => - { - b.HasOne("MagMan.Data.DbModels.ItemModel", "ITemNav") - .WithMany() - .HasForeignKey("ItemID") - .OnDelete(DeleteBehavior.Restrict) - .IsRequired(); - - b.Navigation("ITemNav"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => - { - b.Navigation("ItemNav"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.cs b/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.cs deleted file mode 100644 index 2ce7017..0000000 --- a/MagMan.Data.Tenant/Migrations/20231222180523_AddMagBaseObj01.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace MagMan.Data.Tenant.Migrations -{ - public partial class AddMagBaseObj01 : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "MovMag", - columns: table => new - { - MovID = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - DtRec = table.Column(type: "datetime(6)", nullable: false), - ItemID = table.Column(type: "int", nullable: false), - QtyRec = table.Column(type: "int", nullable: false), - UserId = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_MovMag", x => x.MovID); - table.ForeignKey( - name: "FK_MovMag_ItemsList_ItemID", - column: x => x.ItemID, - principalTable: "ItemsList", - principalColumn: "ItemID", - onDelete: ReferentialAction.Restrict); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "PrintJobQueue", - columns: table => new - { - IdxPrintJob = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - TipoReport = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - KeyParam = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - PrtName = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - DtStart = table.Column(type: "datetime(6)", nullable: false), - DtEnd = table.Column(type: "datetime(6)", nullable: true), - Stato = table.Column(type: "int", nullable: false), - DtLastTry = table.Column(type: "datetime(6)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_PrintJobQueue", x => x.IdxPrintJob); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateIndex( - name: "IX_MovMag_ItemID", - table: "MovMag", - column: "ItemID"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "MovMag"); - - migrationBuilder.DropTable( - name: "PrintJobQueue"); - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs new file mode 100644 index 0000000..e10b66d --- /dev/null +++ b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.Designer.cs @@ -0,0 +1,297 @@ +// +using System; +using MagMan.Data.Tenant; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace MagMan.Data.Tenant.Migrations +{ + [DbContext(typeof(MagManContext))] + [Migration("20240122174314_InitDb")] + partial class InitDb + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "6.0.25") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.AliasModel", b => + { + b.Property("Family") + .HasColumnType("varchar(255)"); + + b.Property("ValueOriginal") + .HasColumnType("varchar(255)"); + + b.Property("ValueAlias") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Family", "ValueOriginal"); + + b.ToTable("AliasList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ConfigModel", b => + { + b.Property("KeyName") + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnOrder(0); + + b.Property("Note") + .IsRequired() + .HasMaxLength(250) + .HasColumnType("varchar(250)") + .HasColumnOrder(3); + + b.Property("Val") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnOrder(1); + + b.Property("ValStd") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("varchar(50)") + .HasColumnOrder(2) + .HasComment("Valore di default/riferimento per la variabile"); + + b.HasKey("KeyName"); + + b.ToTable("Config"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => + { + b.Property("MatId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("HMm") + .HasColumnType("decimal(65,30)"); + + b.Property("LMm") + .HasColumnType("decimal(65,30)"); + + b.Property("MatCode") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MatDesc") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("WMm") + .HasColumnType("decimal(65,30)"); + + b.HasKey("MatId"); + + b.ToTable("MaterialsList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ProjModel", b => + { + b.Property("ProjDbId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("BTLFileName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DtCreated") + .HasColumnType("datetime(6)"); + + b.Property("DtLastAction") + .HasColumnType("datetime(6)"); + + b.Property("DtSchedule") + .HasColumnType("datetime(6)"); + + b.Property("DtStartProd") + .HasColumnType("datetime(6)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsArchived") + .HasColumnType("tinyint(1)"); + + b.Property("KeyNum") + .HasColumnType("int"); + + b.Property("ListName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Machine") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MachineID") + .HasColumnType("int"); + + b.Property("PType") + .HasColumnType("int"); + + b.Property("ProcTimeEst") + .HasColumnType("double"); + + b.Property("ProcTimeReal") + .HasColumnType("double"); + + b.Property("ProjDescription") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProjExtDbId") + .HasColumnType("int"); + + b.Property("ProjExtId") + .HasColumnType("int"); + + b.HasKey("ProjDbId"); + + b.HasIndex("IsActive"); + + b.HasIndex("IsArchived"); + + b.HasIndex("KeyNum"); + + b.HasIndex("MachineID"); + + b.HasIndex("ProjExtDbId"); + + b.ToTable("ProjList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => + { + b.Property("RawItemId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("HMm") + .HasColumnType("decimal(65,30)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsRemn") + .HasColumnType("tinyint(1)"); + + b.Property("LMm") + .HasColumnType("decimal(65,30)"); + + b.Property("Location") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MatId") + .HasColumnType("int"); + + b.Property("Note") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("QtyAvail") + .HasColumnType("int"); + + b.Property("WMm") + .HasColumnType("decimal(65,30)"); + + b.HasKey("RawItemId"); + + b.HasIndex("MatId"); + + b.ToTable("RawItemList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => + { + b.Property("RequestId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("DtRequest") + .HasColumnType("datetime(6)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("ProjDbId") + .HasColumnType("int"); + + b.Property("ReqState") + .HasColumnType("int"); + + b.HasKey("RequestId"); + + b.ToTable("RequestPlan"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.Property("ResourceId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Qty") + .HasColumnType("int"); + + b.Property("RawItemId") + .HasColumnType("int"); + + b.Property("RequestId") + .HasColumnType("int"); + + b.HasKey("ResourceId"); + + b.HasIndex("RequestId"); + + b.ToTable("ResourceList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => + { + b.HasOne("MagMan.Data.Tenant.DbModels.MaterialModel", "MaterialNav") + .WithMany("RawItemList") + .HasForeignKey("MatId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("MaterialNav"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => + { + b.HasOne("MagMan.Data.Tenant.DbModels.RequestPlanModel", "RequestNav") + .WithMany("ResourcesList") + .HasForeignKey("RequestId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("RequestNav"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => + { + b.Navigation("RawItemList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => + { + b.Navigation("ResourcesList"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs new file mode 100644 index 0000000..57b8471 --- /dev/null +++ b/MagMan.Data.Tenant/Migrations/20240122174314_InitDb.cs @@ -0,0 +1,235 @@ +using System; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace MagMan.Data.Tenant.Migrations +{ + public partial class InitDb : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterDatabase() + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "AliasList", + columns: table => new + { + Family = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ValueOriginal = table.Column(type: "varchar(255)", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ValueAlias = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_AliasList", x => new { x.Family, x.ValueOriginal }); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "Config", + columns: table => new + { + KeyName = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + Val = table.Column(type: "varchar(50)", maxLength: 50, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ValStd = table.Column(type: "varchar(50)", maxLength: 50, nullable: false, comment: "Valore di default/riferimento per la variabile") + .Annotation("MySql:CharSet", "utf8mb4"), + Note = table.Column(type: "varchar(250)", maxLength: 250, nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_Config", x => x.KeyName); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "MaterialsList", + columns: table => new + { + MatId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + MatCode = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + MatDesc = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + LMm = table.Column(type: "decimal(65,30)", nullable: false), + WMm = table.Column(type: "decimal(65,30)", nullable: false), + HMm = table.Column(type: "decimal(65,30)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_MaterialsList", x => x.MatId); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "ProjList", + columns: table => new + { + ProjDbId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + MachineID = table.Column(type: "int", nullable: false), + KeyNum = table.Column(type: "int", nullable: false), + ProjExtDbId = table.Column(type: "int", nullable: false), + ProjExtId = table.Column(type: "int", nullable: false), + BTLFileName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + PType = table.Column(type: "int", nullable: false), + Machine = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ProjDescription = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + DtCreated = table.Column(type: "datetime(6)", nullable: false), + DtSchedule = table.Column(type: "datetime(6)", nullable: false), + DtStartProd = table.Column(type: "datetime(6)", nullable: false), + DtLastAction = table.Column(type: "datetime(6)", nullable: false), + ListName = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + ProcTimeEst = table.Column(type: "double", nullable: false), + ProcTimeReal = table.Column(type: "double", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsArchived = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProjList", x => x.ProjDbId); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "RequestPlan", + columns: table => new + { + RequestId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + ProjDbId = table.Column(type: "int", nullable: false), + DtRequest = table.Column(type: "datetime(6)", nullable: false), + ReqState = table.Column(type: "int", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RequestPlan", x => x.RequestId); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "RawItemList", + columns: table => new + { + RawItemId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + MatId = table.Column(type: "int", nullable: false), + QtyAvail = table.Column(type: "int", nullable: false), + IsActive = table.Column(type: "tinyint(1)", nullable: false), + IsRemn = table.Column(type: "tinyint(1)", nullable: false), + Location = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4"), + LMm = table.Column(type: "decimal(65,30)", nullable: false), + WMm = table.Column(type: "decimal(65,30)", nullable: false), + HMm = table.Column(type: "decimal(65,30)", nullable: false), + Note = table.Column(type: "longtext", nullable: false) + .Annotation("MySql:CharSet", "utf8mb4") + }, + constraints: table => + { + table.PrimaryKey("PK_RawItemList", x => x.RawItemId); + table.ForeignKey( + name: "FK_RawItemList_MaterialsList_MatId", + column: x => x.MatId, + principalTable: "MaterialsList", + principalColumn: "MatId", + onDelete: ReferentialAction.Restrict); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateTable( + name: "ResourceList", + columns: table => new + { + ResourceId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + RequestId = table.Column(type: "int", nullable: false), + RawItemId = table.Column(type: "int", nullable: false), + Qty = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ResourceList", x => x.ResourceId); + table.ForeignKey( + name: "FK_ResourceList_RequestPlan_RequestId", + column: x => x.RequestId, + principalTable: "RequestPlan", + principalColumn: "RequestId", + onDelete: ReferentialAction.Restrict); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_IsActive", + table: "ProjList", + column: "IsActive"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_IsArchived", + table: "ProjList", + column: "IsArchived"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_KeyNum", + table: "ProjList", + column: "KeyNum"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_MachineID", + table: "ProjList", + column: "MachineID"); + + migrationBuilder.CreateIndex( + name: "IX_ProjList_ProjExtDbId", + table: "ProjList", + column: "ProjExtDbId"); + + migrationBuilder.CreateIndex( + name: "IX_RawItemList_MatId", + table: "RawItemList", + column: "MatId"); + + migrationBuilder.CreateIndex( + name: "IX_ResourceList_RequestId", + table: "ResourceList", + column: "RequestId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AliasList"); + + migrationBuilder.DropTable( + name: "Config"); + + migrationBuilder.DropTable( + name: "ProjList"); + + migrationBuilder.DropTable( + name: "RawItemList"); + + migrationBuilder.DropTable( + name: "ResourceList"); + + migrationBuilder.DropTable( + name: "MaterialsList"); + + migrationBuilder.DropTable( + name: "RequestPlan"); + } + } +} diff --git a/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs b/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs index 9092b6a..37bfa7e 100644 --- a/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs +++ b/MagMan.Data.Tenant/Migrations/MagManContextModelSnapshot.cs @@ -1,6 +1,6 @@ // using System; -using MagMan.Data; +using MagMan.Data.Tenant; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; @@ -19,7 +19,24 @@ namespace MagMan.Data.Tenant.Migrations .HasAnnotation("ProductVersion", "6.0.25") .HasAnnotation("Relational:MaxIdentifierLength", 64); - modelBuilder.Entity("MagMan.Data.DbModels.ConfigModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.AliasModel", b => + { + b.Property("Family") + .HasColumnType("varchar(255)"); + + b.Property("ValueOriginal") + .HasColumnType("varchar(255)"); + + b.Property("ValueAlias") + .IsRequired() + .HasColumnType("longtext"); + + b.HasKey("Family", "ValueOriginal"); + + b.ToTable("AliasList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ConfigModel", b => { b.Property("KeyName") .HasMaxLength(50) @@ -50,15 +67,122 @@ namespace MagMan.Data.Tenant.Migrations b.ToTable("Config"); }); - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => { - b.Property("ItemID") + b.Property("MatId") .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("DtMod") + b.Property("HMm") + .HasColumnType("decimal(65,30)"); + + b.Property("LMm") + .HasColumnType("decimal(65,30)"); + + b.Property("MatCode") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MatDesc") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("WMm") + .HasColumnType("decimal(65,30)"); + + b.HasKey("MatId"); + + b.ToTable("MaterialsList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ProjModel", b => + { + b.Property("ProjDbId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("BTLFileName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("DtCreated") .HasColumnType("datetime(6)"); + b.Property("DtLastAction") + .HasColumnType("datetime(6)"); + + b.Property("DtSchedule") + .HasColumnType("datetime(6)"); + + b.Property("DtStartProd") + .HasColumnType("datetime(6)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + + b.Property("IsArchived") + .HasColumnType("tinyint(1)"); + + b.Property("KeyNum") + .HasColumnType("int"); + + b.Property("ListName") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("Machine") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("MachineID") + .HasColumnType("int"); + + b.Property("PType") + .HasColumnType("int"); + + b.Property("ProcTimeEst") + .HasColumnType("double"); + + b.Property("ProcTimeReal") + .HasColumnType("double"); + + b.Property("ProjDescription") + .IsRequired() + .HasColumnType("longtext"); + + b.Property("ProjExtDbId") + .HasColumnType("int"); + + b.Property("ProjExtId") + .HasColumnType("int"); + + b.HasKey("ProjDbId"); + + b.HasIndex("IsActive"); + + b.HasIndex("IsArchived"); + + b.HasIndex("KeyNum"); + + b.HasIndex("MachineID"); + + b.HasIndex("ProjExtDbId"); + + b.ToTable("ProjList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => + { + b.Property("RawItemId") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("HMm") + .HasColumnType("decimal(65,30)"); + + b.Property("IsActive") + .HasColumnType("tinyint(1)"); + b.Property("IsRemn") .HasColumnType("tinyint(1)"); @@ -69,7 +193,7 @@ namespace MagMan.Data.Tenant.Migrations .IsRequired() .HasColumnType("longtext"); - b.Property("MatID") + b.Property("MatId") .HasColumnType("int"); b.Property("Note") @@ -79,139 +203,91 @@ namespace MagMan.Data.Tenant.Migrations b.Property("QtyAvail") .HasColumnType("int"); - b.Property("TMm") - .HasColumnType("decimal(65,30)"); - b.Property("WMm") .HasColumnType("decimal(65,30)"); - b.HasKey("ItemID"); + b.HasKey("RawItemId"); - b.HasIndex("MatID"); + b.HasIndex("MatId"); - b.ToTable("ItemsList"); + b.ToTable("RawItemList"); }); - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => { - b.Property("MatID") + b.Property("RequestId") .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("ApprovDate") + b.Property("DtRequest") .HasColumnType("datetime(6)"); - b.Property("ApprovUser") - .IsRequired() - .HasColumnType("longtext"); + b.Property("IsActive") + .HasColumnType("tinyint(1)"); - b.Property("LMm") - .HasColumnType("decimal(65,30)"); - - b.Property("MatDesc") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("MatExtCode") + b.Property("ProjDbId") .HasColumnType("int"); - b.Property("TMm") - .HasColumnType("decimal(65,30)"); + b.Property("ReqState") + .HasColumnType("int"); - b.Property("WMm") - .HasColumnType("decimal(65,30)"); + b.HasKey("RequestId"); - b.HasKey("MatID"); - - b.ToTable("Materials"); + b.ToTable("RequestPlan"); }); - modelBuilder.Entity("MagMan.Data.DbModels.MovMagModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => { - b.Property("MovID") + b.Property("ResourceId") .ValueGeneratedOnAdd() .HasColumnType("int"); - b.Property("DtRec") - .HasColumnType("datetime(6)"); - - b.Property("ItemID") + b.Property("Qty") .HasColumnType("int"); - b.Property("QtyRec") + b.Property("RawItemId") .HasColumnType("int"); - b.Property("UserId") - .IsRequired() - .HasColumnType("longtext"); + b.Property("RequestId") + .HasColumnType("int"); - b.HasKey("MovID"); + b.HasKey("ResourceId"); - b.HasIndex("ItemID"); + b.HasIndex("RequestId"); - b.ToTable("MovMag"); + b.ToTable("ResourceList"); }); - modelBuilder.Entity("MagMan.Data.DbModels.PrintJobQueueModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RawItemModel", b => { - b.Property("IdxPrintJob") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("DtEnd") - .HasColumnType("datetime(6)"); - - b.Property("DtLastTry") - .HasColumnType("datetime(6)"); - - b.Property("DtStart") - .HasColumnType("datetime(6)"); - - b.Property("KeyParam") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("PrtName") - .IsRequired() - .HasColumnType("longtext"); - - b.Property("Stato") - .HasColumnType("int"); - - b.Property("TipoReport") - .IsRequired() - .HasColumnType("longtext"); - - b.HasKey("IdxPrintJob"); - - b.ToTable("PrintJobQueue"); - }); - - modelBuilder.Entity("MagMan.Data.DbModels.ItemModel", b => - { - b.HasOne("MagMan.Data.DbModels.MaterialModel", "MaterialNav") - .WithMany("ItemNav") - .HasForeignKey("MatID") + b.HasOne("MagMan.Data.Tenant.DbModels.MaterialModel", "MaterialNav") + .WithMany("RawItemList") + .HasForeignKey("MatId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); b.Navigation("MaterialNav"); }); - modelBuilder.Entity("MagMan.Data.DbModels.MovMagModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.ResourceModel", b => { - b.HasOne("MagMan.Data.DbModels.ItemModel", "ITemNav") - .WithMany() - .HasForeignKey("ItemID") + b.HasOne("MagMan.Data.Tenant.DbModels.RequestPlanModel", "RequestNav") + .WithMany("ResourcesList") + .HasForeignKey("RequestId") .OnDelete(DeleteBehavior.Restrict) .IsRequired(); - b.Navigation("ITemNav"); + b.Navigation("RequestNav"); }); - modelBuilder.Entity("MagMan.Data.DbModels.MaterialModel", b => + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.MaterialModel", b => { - b.Navigation("ItemNav"); + b.Navigation("RawItemList"); + }); + + modelBuilder.Entity("MagMan.Data.Tenant.DbModels.RequestPlanModel", b => + { + b.Navigation("ResourcesList"); }); #pragma warning restore 612, 618 } diff --git a/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.Designer.cs b/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.Designer.cs deleted file mode 100644 index 46864d8..0000000 --- a/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.Designer.cs +++ /dev/null @@ -1,311 +0,0 @@ -// -using System; -using MagMan.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace MagMan.Data.Migrations.UserIdentityDb -{ - [DbContext(typeof(UserIdentityDbContext))] - [Migration("20231222165912_CreateIdentitySchema")] - partial class CreateIdentitySchema - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.25") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("MagMan.Data.DbModels.TableCount", b => - { - b.Property("Count") - .HasColumnType("int"); - - b.Property("TableName") - .IsRequired() - .HasColumnType("longtext"); - - b.ToTable("DbSetCounts"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("varchar(255)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("longtext"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "eebed9c1-7433-4716-a62f-df9829dc0f09", - ConcurrencyStamp = "4a1affe9-543f-4165-816a-2ed6d3f06c77", - Name = "Undef", - NormalizedName = "UNDEF" - }, - new - { - Id = "ca44b425-5c7e-4812-a28a-047ec6aa2e68", - ConcurrencyStamp = "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", - Name = "User", - NormalizedName = "USER" - }, - new - { - Id = "86a8f484-ca14-4e4d-a786-3eba35da6e06", - ConcurrencyStamp = "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "f5bd74e5-df26-4c52-963e-2d87e858c4d6", - ConcurrencyStamp = "1d620875-05b0-490d-91d5-6f21a83844f1", - Name = "SuperAdmin", - NormalizedName = "SUPERADMIN" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ClaimType") - .HasColumnType("longtext"); - - b.Property("ClaimValue") - .HasColumnType("longtext"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => - { - b.Property("Id") - .HasColumnType("varchar(255)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("longtext"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("tinyint(1)"); - - b.Property("LockoutEnabled") - .HasColumnType("tinyint(1)"); - - b.Property("LockoutEnd") - .HasColumnType("datetime(6)"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("longtext"); - - b.Property("PhoneNumber") - .HasColumnType("longtext"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("tinyint(1)"); - - b.Property("SecurityStamp") - .HasColumnType("longtext"); - - b.Property("TwoFactorEnabled") - .HasColumnType("tinyint(1)"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ClaimType") - .HasColumnType("longtext"); - - b.Property("ClaimValue") - .HasColumnType("longtext"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("varchar(255)"); - - b.Property("ProviderKey") - .HasColumnType("varchar(255)"); - - b.Property("ProviderDisplayName") - .HasColumnType("longtext"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("varchar(255)"); - - b.Property("RoleId") - .HasColumnType("varchar(255)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("varchar(255)"); - - b.Property("LoginProvider") - .HasColumnType("varchar(255)"); - - b.Property("Name") - .HasColumnType("varchar(255)"); - - b.Property("Value") - .HasColumnType("longtext"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs b/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs deleted file mode 100644 index 1eb4f0a..0000000 --- a/MagMan.Data.Tenant/Migrations/UserIdentityDb/20231222165912_CreateIdentitySchema.cs +++ /dev/null @@ -1,286 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace MagMan.Data.Migrations.UserIdentityDb -{ - public partial class CreateIdentitySchema : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AlterDatabase() - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetRoles", - columns: table => new - { - Id = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Name = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - NormalizedName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - ConcurrencyStamp = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - columns: table => new - { - Id = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - UserName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - NormalizedUserName = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - Email = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - NormalizedEmail = table.Column(type: "varchar(256)", maxLength: 256, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - EmailConfirmed = table.Column(type: "tinyint(1)", nullable: false), - PasswordHash = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - SecurityStamp = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - ConcurrencyStamp = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - PhoneNumber = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - PhoneNumberConfirmed = table.Column(type: "tinyint(1)", nullable: false), - TwoFactorEnabled = table.Column(type: "tinyint(1)", nullable: false), - LockoutEnd = table.Column(type: "datetime(6)", nullable: true), - LockoutEnabled = table.Column(type: "tinyint(1)", nullable: false), - AccessFailedCount = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "DbSetCounts", - columns: table => new - { - Count = table.Column(type: "int", nullable: false), - TableName = table.Column(type: "longtext", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - RoleId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ClaimType = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - ClaimValue = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - UserId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ClaimType = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - ClaimValue = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - columns: table => new - { - LoginProvider = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ProviderKey = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - ProviderDisplayName = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - UserId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - columns: table => new - { - UserId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - RoleId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - columns: table => new - { - UserId = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - LoginProvider = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Name = table.Column(type: "varchar(255)", nullable: false) - .Annotation("MySql:CharSet", "utf8mb4"), - Value = table.Column(type: "longtext", nullable: true) - .Annotation("MySql:CharSet", "utf8mb4") - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }) - .Annotation("MySql:CharSet", "utf8mb4"); - - migrationBuilder.InsertData( - table: "AspNetRoles", - columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, - values: new object[,] - { - { "86a8f484-ca14-4e4d-a786-3eba35da6e06", "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", "Admin", "ADMIN" }, - { "ca44b425-5c7e-4812-a28a-047ec6aa2e68", "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", "User", "USER" }, - { "eebed9c1-7433-4716-a62f-df9829dc0f09", "4a1affe9-543f-4165-816a-2ed6d3f06c77", "Undef", "UNDEF" }, - { "f5bd74e5-df26-4c52-963e-2d87e858c4d6", "1d620875-05b0-490d-91d5-6f21a83844f1", "SuperAdmin", "SUPERADMIN" } - }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - table: "AspNetRoles", - column: "NormalizedName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens"); - - migrationBuilder.DropTable( - name: "DbSetCounts"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - } - } -} diff --git a/MagMan.Data.Tenant/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs b/MagMan.Data.Tenant/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs deleted file mode 100644 index cc6e811..0000000 --- a/MagMan.Data.Tenant/Migrations/UserIdentityDb/UserIdentityDbContextModelSnapshot.cs +++ /dev/null @@ -1,309 +0,0 @@ -// -using System; -using MagMan.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace MagMan.Data.Migrations.UserIdentityDb -{ - [DbContext(typeof(UserIdentityDbContext))] - partial class UserIdentityDbContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "6.0.25") - .HasAnnotation("Relational:MaxIdentifierLength", 64); - - modelBuilder.Entity("MagMan.Data.DbModels.TableCount", b => - { - b.Property("Count") - .HasColumnType("int"); - - b.Property("TableName") - .IsRequired() - .HasColumnType("longtext"); - - b.ToTable("DbSetCounts"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .HasColumnType("varchar(255)"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("longtext"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex"); - - b.ToTable("AspNetRoles", (string)null); - - b.HasData( - new - { - Id = "eebed9c1-7433-4716-a62f-df9829dc0f09", - ConcurrencyStamp = "4a1affe9-543f-4165-816a-2ed6d3f06c77", - Name = "Undef", - NormalizedName = "UNDEF" - }, - new - { - Id = "ca44b425-5c7e-4812-a28a-047ec6aa2e68", - ConcurrencyStamp = "a1357889-6a23-49cb-9d33-6bc5ef6eb4e6", - Name = "User", - NormalizedName = "USER" - }, - new - { - Id = "86a8f484-ca14-4e4d-a786-3eba35da6e06", - ConcurrencyStamp = "9dd579c3-bdfa-4c44-b6ca-6dd10d34debb", - Name = "Admin", - NormalizedName = "ADMIN" - }, - new - { - Id = "f5bd74e5-df26-4c52-963e-2d87e858c4d6", - ConcurrencyStamp = "1d620875-05b0-490d-91d5-6f21a83844f1", - Name = "SuperAdmin", - NormalizedName = "SUPERADMIN" - }); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ClaimType") - .HasColumnType("longtext"); - - b.Property("ClaimValue") - .HasColumnType("longtext"); - - b.Property("RoleId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => - { - b.Property("Id") - .HasColumnType("varchar(255)"); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("longtext"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("tinyint(1)"); - - b.Property("LockoutEnabled") - .HasColumnType("tinyint(1)"); - - b.Property("LockoutEnd") - .HasColumnType("datetime(6)"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.Property("PasswordHash") - .HasColumnType("longtext"); - - b.Property("PhoneNumber") - .HasColumnType("longtext"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("tinyint(1)"); - - b.Property("SecurityStamp") - .HasColumnType("longtext"); - - b.Property("TwoFactorEnabled") - .HasColumnType("tinyint(1)"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("varchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex"); - - b.ToTable("AspNetUsers", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - b.Property("ClaimType") - .HasColumnType("longtext"); - - b.Property("ClaimValue") - .HasColumnType("longtext"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("varchar(255)"); - - b.Property("ProviderKey") - .HasColumnType("varchar(255)"); - - b.Property("ProviderDisplayName") - .HasColumnType("longtext"); - - b.Property("UserId") - .IsRequired() - .HasColumnType("varchar(255)"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("varchar(255)"); - - b.Property("RoleId") - .HasColumnType("varchar(255)"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("varchar(255)"); - - b.Property("LoginProvider") - .HasColumnType("varchar(255)"); - - b.Property("Name") - .HasColumnType("varchar(255)"); - - b.Property("Value") - .HasColumnType("longtext"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", (string)null); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/MagMan.Data.Tenant/Services/MessageService.cs b/MagMan.Data.Tenant/Services/MessageService.cs deleted file mode 100644 index 1ddc1c5..0000000 --- a/MagMan.Data.Tenant/Services/MessageService.cs +++ /dev/null @@ -1,279 +0,0 @@ -using Blazored.LocalStorage; -using Blazored.SessionStorage; -using NLog; -using NLog.Fluent; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection.Metadata; -using System.Text; -using System.Threading.Tasks; - -namespace MagMan.Data.Tenant.Services -{ - public class MessageService - { - #region Public Events - - public event Action EA_FilterUpdated = null!; - - public event Action EA_HideSearch = null!; - - public event Action EA_PageUpdated = null!; - - public event Action EA_SearchUpdated = null!; - - public event Action EA_ShowSearch = null!; - - #endregion Public Events - - #region Public Properties - - public SelectData DetailFilter - { - get => _detailFilter; - set - { - if (_detailFilter != value) - { - _detailFilter = value; - - if (EA_FilterUpdated != null) - { - EA_FilterUpdated?.Invoke(); - } - } - } - } - - public SelectOrderData Order_Filter { get; set; } = SelectOrderData.Init(5, 30); - - public string PageIcon - { - get => _pageIcon; - set - { - if (_pageIcon != value) - { - _pageIcon = value; - ReportPageUpd(); - } - } - } - - public string PageName - { - get => _pageName; - set - { - if (_pageName != value) - { - _pageName = value; - ReportPageUpd(); - } - } - } - - public string SearchVal - { - get => _searchVal; - set - { - if (_searchVal != value) - { - _searchVal = value; - - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } - } - } - } - - public string SelOrderCode { get; set; } = ""; - public string SelPlantId { get; set; } = "0"; - - public bool ShowSearch - { - get => _showSearch; - set - { - if (_showSearch != value) - { - _showSearch = value; - if (_showSearch) - { - if (EA_ShowSearch != null) - { - EA_ShowSearch?.Invoke(); - } - } - else - { - if (EA_HideSearch != null) - { - EA_HideSearch?.Invoke(); - } - } - } - } - } - - #endregion Public Properties - - #region Public Methods - - /// - /// Svuota localstorage (clear) - /// - /// - public async Task StoreLocalClear() - { - bool answ = false; - try - { - await localStore.ClearAsync(); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Restituisce il valore richiesto da localstorage - /// - /// Chiave - /// - public async Task StoreLocalGet(string sKey) - { - string answ = ""; - var result = await localStore.GetItemAsync(sKey); - if (result != null) - { - answ = result; - } - return answ; - } - - /// - /// Scrive il valore nel localstorage - /// - /// Chiave - /// Valore associato - /// - public async Task StoreLocalSet(string sKey, string sVal) - { - bool answ = false; - try - { - await localStore.SetItemAsStringAsync(sKey, sVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalSet{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Svuota sessionstorage (clear) - /// - /// - public async Task StoreSessClear() - { - bool answ = false; - try - { - await sessionStore.ClearAsync(); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreLocalClear{Environment.NewLine}{ex}"); - } - return answ; - } - - /// - /// Restituisce il valore richiesto da sessionstorage - /// - /// Chiave - /// - public async Task StoreSessGet(string sKey) - { - string answ = ""; - var result = await sessionStore.GetItemAsync(sKey); - if (result != null) - { - answ = result; - } - return answ; - } - - /// - /// Scrive il valore nel sessionstorage (tab) - /// - /// Chiave - /// Valore associato - /// - public async Task StoreSessSet(string sKey, string sVal) - { - bool answ = false; - try - { - await sessionStore.SetItemAsStringAsync(sKey, sVal); - answ = true; - } - catch (Exception ex) - { - Log.Error($"Eccezione in StoreSessSet{Environment.NewLine}{ex}"); - } - return answ; - } - - #endregion Public Methods - - #region Protected Properties - - protected ILocalStorageService localStore { get; set; } = null!; - protected ISessionStorageService sessionStore { get; set; } = null!; - - #endregion Protected Properties - - #region Private Fields - - private SelectData _detailFilter = SelectData.Init(5, 15); - private string _pageIcon = ""; - private string _pageName = ""; - private string _searchVal = ""; - private bool _showSearch = false; - private Logger Log = LogManager.GetCurrentClassLogger(); - - #endregion Private Fields - - #region Private Methods - - private void ReportPageUpd() - { - if (EA_PageUpdated != null) - { - EA_PageUpdated?.Invoke(); - } - } - - private void ReportSearch() - { - if (EA_SearchUpdated != null) - { - EA_SearchUpdated?.Invoke(); - } - } - - #endregion Private Methods - } -} \ No newline at end of file diff --git a/MagMan.Data.Tenant/Services/TenantService.cs b/MagMan.Data.Tenant/Services/TenantService.cs index 6ddc4d2..177061e 100644 --- a/MagMan.Data.Tenant/Services/TenantService.cs +++ b/MagMan.Data.Tenant/Services/TenantService.cs @@ -60,7 +60,7 @@ namespace MagMan.Data.Tenant.Services /// Key di riferimento /// Item da eliminare /// - public async Task ItemDelete(int nKey, ItemModel rec2del) + public async Task ItemDelete(int nKey, RawItemModel rec2del) { bool fatto = false; string cString = ConnString(nKey); @@ -79,29 +79,53 @@ namespace MagMan.Data.Tenant.Services return fatto; } + /// + /// Converte il DTO in ItemModel + /// + /// DTO di partenza + /// Parametro active da impostare + /// + public RawItemModel ItemFromDto(ItemDTO origItem, bool isActive) + { + RawItemModel answ = new RawItemModel() + { + MatId = origItem.MatId, + Note = origItem.Note, + LMm = origItem.LMm, + WMm = origItem.WMm, + HMm = origItem.HMm, + IsRemn = origItem.IsRemn, + Location = origItem.Location, + QtyAvail = origItem.QtyAvail, + IsActive = isActive + }; + + return answ; + } + /// /// Lista Items gestiti a magazzino /// /// Key di riferimento /// - public async Task> ItemGetAll(int nKey) + public async Task> ItemGetAll(int nKey) { string source = "DB"; string cString = ConnString(nKey); - List? dbResult = new List(); + List? dbResult = new List(); try { - string currKey = $"{Const.rKeyConfig}:{nKey}:ItemList"; + string currKey = $"{Const.rKeyConfig}:ItemList:{nKey}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty(rawData)) { source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); + var tempResult = JsonConvert.DeserializeObject>(rawData); if (tempResult == null) { - dbResult = new List(); + dbResult = new List(); } else { @@ -116,7 +140,7 @@ namespace MagMan.Data.Tenant.Services } if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; @@ -135,24 +159,24 @@ namespace MagMan.Data.Tenant.Services /// Key di riferimento /// ID del materiale x cui filtrare, 0 = tutti /// - public async Task> ItemGetByMat(int nKey, int matID) + public async Task> ItemGetByMat(int nKey, int matID) { string source = "DB"; string cString = ConnString(nKey); - List? dbResult = new List(); + List? dbResult = new List(); try { - string currKey = $"{Const.rKeyConfig}:{nKey}:{matID}:ItemList"; + string currKey = $"{Const.rKeyConfig}:{nKey}:ItemList:{matID}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); if (!string.IsNullOrEmpty(rawData)) { source = "REDIS"; - var tempResult = JsonConvert.DeserializeObject>(rawData); + var tempResult = JsonConvert.DeserializeObject>(rawData); if (tempResult == null) { - dbResult = new List(); + dbResult = new List(); } else { @@ -167,7 +191,7 @@ namespace MagMan.Data.Tenant.Services } if (dbResult == null) { - dbResult = new List(); + dbResult = new List(); } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; @@ -180,13 +204,35 @@ namespace MagMan.Data.Tenant.Services return dbResult; } + /// Update record Item + refresh cache Key di + /// riferimento Item interesato quantità da aggiornare (se <0 è consumo) + public async Task ItemModQty(int nKey, RawItemModel currItem, int deltaQty) + { + bool fatto = false; + string cString = ConnString(nKey); + try + { + fatto = dbController.ItemModQty(cString, currItem, deltaQty); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ItemModQty:{Environment.NewLine}{exc}"); + } + return fatto; + } + /// /// Update record Item + refresh cache /// /// Key di riferimento - /// + /// Item interesato /// - public async Task ItemUpdate(int nKey, ItemModel currItem) + public async Task ItemUpdate(int nKey, RawItemModel currItem) { bool fatto = false; string cString = ConnString(nKey); @@ -230,19 +276,41 @@ namespace MagMan.Data.Tenant.Services return fatto; } + /// + /// Converte il DTO in MaterialModel + /// + /// + /// + public MaterialModel MaterialFromDto(MaterialDTO origItem) + { + MaterialModel answ = new MaterialModel() + { + MatId = origItem.MatId, + MatCode = origItem.MatCode, + MatDesc = origItem.MatDesc, + LMm = origItem.LMm, + WMm = origItem.WMm, + HMm = origItem.HMm + }; + + return answ; + } + /// /// Lista Materiali gestiti a magazzino /// /// Key di riferimento + /// Se true allora include record child (Items) /// - public async Task> MaterialGetAll(int nKey) + public async Task> MaterialGetAll(int nKey, bool withChild) { string source = "DB"; string cString = ConnString(nKey); List? dbResult = new List(); try { - string currKey = $"{Const.rKeyConfig}:{nKey}:Materials"; + string dType = withChild ? "MaterialsFull" : "Materials"; + string currKey = $"{Const.rKeyConfig}:{dType}:{nKey}"; Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); string? rawData = await redisDb.StringGetAsync(currKey); @@ -261,9 +329,15 @@ namespace MagMan.Data.Tenant.Services } else { - dbResult = dbController.MaterialGetAll(cString); + dbResult = dbController.MaterialGetAll(cString, withChild); rawData = JsonConvert.SerializeObject(dbResult, JSSettings); await redisDb.StringSetAsync(currKey, rawData, LongCache); + // per evitare loopback uso deserialize... + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult != null) + { + dbResult = tempResult; + } } if (dbResult == null) { @@ -280,6 +354,65 @@ namespace MagMan.Data.Tenant.Services return dbResult; } + /// + /// Lista Materiali gestiti a magazzino + /// + /// Key di riferimento + /// Materiale richiesto + /// Se true allora include record child (Items) + /// + public async Task> MaterialGetFilt(int nKey, int matID, bool withChild) + { + string source = "DB"; + string cString = ConnString(nKey); + List? dbResult = new List(); + try + { + string dType = withChild ? "MatInvFull" : "MatInv"; + string currKey = $"{Const.rKeyConfig}:{dType}:{nKey}:{matID}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData) && rawData.Length > 2) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.MaterialGetFilt(cString, matID, withChild); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + // per evitare loopback uso deserialize... + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult != null) + { + dbResult = tempResult; + } + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"MaterialGetFilt | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during MaterialGetFilt:{Environment.NewLine}{exc}"); + } + return dbResult; + } + /// /// Update record Materiale + refresh cache /// @@ -306,24 +439,186 @@ namespace MagMan.Data.Tenant.Services } /// - /// Converte il DTO in MaterialModel + /// Elimina record Project + refresh cache /// - /// + /// Key di riferimento + /// Item da eliminare /// - public MaterialModel MaterialFromDto(MaterialDTO origItem) + public async Task ProjectDelete(int nKey, ProjModel rec2del) { - MaterialModel answ = new MaterialModel() + bool fatto = false; + string cString = ConnString(nKey); + try { - MatExtCode = origItem.MatExtCode, - MatDesc = origItem.MatDesc, - LMm = origItem.LMm, - WMm = origItem.WMm, - TMm = origItem.TMm + fatto = dbController.ProjectDelete(cString, rec2del); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ProjectDelete:{Environment.NewLine}{exc}"); + } + return fatto; + } + + /// + /// Converte il DTO in ItemModel + /// + /// DTO di partenza + /// + public ProjModel ProjectFromDto(ProjectDTO origItem) + { + ProjModel answ = new ProjModel() + { + MachineID = origItem.MachineID, + KeyNum = origItem.KeyNum, + ProjExtDbId = origItem.ProjExtDbId, + ProjExtId = origItem.ProjExtId, + BTLFileName = origItem.BTLFileName, + PType = origItem.PType, + Machine = origItem.Machine, + ProjDescription = origItem.ProjDescription, + DtCreated = origItem.DtCreated, + DtLastAction = origItem.DtLastAction, + DtSchedule = origItem.DtSchedule, + DtStartProd = origItem.DtStartProd, + ListName = origItem.ListName, + ProcTimeEst = origItem.ProcTimeEst, + ProcTimeReal = origItem.ProcTimeReal, + IsActive = origItem.IsActive, + IsArchived = origItem.IsArchived }; return answ; } + /// + /// Lista Projects gestiti a magazzino + /// + /// Key di riferimento + /// + public async Task> ProjectGetAll(int nKey) + { + string source = "DB"; + string cString = ConnString(nKey); + List? dbResult = new List(); + try + { + string currKey = $"{Const.rKeyConfig}:ProjList:{nKey}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ProjectGetAll(cString); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ProjectGetAll | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ProjectGetAll:{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// + /// Lista Items gestiti a magazzino x materiale + /// + /// Key di riferimento + /// ID del materiale x cui filtrare, 0 = tutti + /// + public async Task> ProjectGetByNumKey(int nKey, int numKey) + { + string source = "DB"; + string cString = ConnString(nKey); + List? dbResult = new List(); + try + { + string currKey = $"{Const.rKeyConfig}:{nKey}:ProjList:{numKey}"; + Stopwatch stopWatch = new Stopwatch(); + stopWatch.Start(); + string? rawData = await redisDb.StringGetAsync(currKey); + if (!string.IsNullOrEmpty(rawData)) + { + source = "REDIS"; + var tempResult = JsonConvert.DeserializeObject>(rawData); + if (tempResult == null) + { + dbResult = new List(); + } + else + { + dbResult = tempResult; + } + } + else + { + dbResult = dbController.ProjectGetByNumKey(cString, numKey); + rawData = JsonConvert.SerializeObject(dbResult, JSSettings); + await redisDb.StringSetAsync(currKey, rawData, LongCache); + } + if (dbResult == null) + { + dbResult = new List(); + } + stopWatch.Stop(); + TimeSpan ts = stopWatch.Elapsed; + Log.Debug($"ProjectGetByNumKey | {source} in: {ts.TotalMilliseconds} ms"); + } + catch (Exception exc) + { + Log.Error($"Error during ProjectGetByNumKey:{Environment.NewLine}{exc}"); + } + return dbResult; + } + + /// + /// Update record Item + refresh cache + /// + /// Key di riferimento + /// Item interesato + /// + public async Task ProjectUpdate(int nKey, ProjModel currItem) + { + bool fatto = false; + string cString = ConnString(nKey); + try + { + fatto = dbController.ProjectUpdate(cString, currItem); + if (fatto) + { + await FlushRedisCache(); + } + } + catch (Exception exc) + { + Log.Error($"Error during ProjectUpdate:{Environment.NewLine}{exc}"); + } + return fatto; + } #endregion Public Methods @@ -370,42 +665,6 @@ namespace MagMan.Data.Tenant.Services return answ; } -#if false - /// - /// Dizionario dei token 2 connectionStrings - /// - private Dictionary TokenList { get; set; } = new Dictionary(); - - - /// - /// Recupera ConnectionString dal dizionario dei token noti o cercando sul DB - /// - /// - /// - public string ConnStringByToken(string RestToken) - { - string answ = ""; - if (TokenList.ContainsKey(RestToken)) - { - answ = TokenList[RestToken]; - } - else - { - // cerco nel DB - var custList = dbController.CustomerGetAll(); - var custRow = custList.FirstOrDefault(x => x.RestToken == RestToken); - // se trovato salvo - if (custRow != null) - { - answ = DbConfig.CustomerConnString(DbServerAddr, nKey); - TokenList.Add(RestToken, answ); - Log.Info($"TokenList: added {RestToken} --> {answ}"); - } - } - return answ; - } -#endif - #endregion Private Methods } } \ No newline at end of file diff --git a/MagMan.UI/Components/CmpSelCliente.razor b/MagMan.UI/Components/CmpSelCliente.razor new file mode 100644 index 0000000..c236799 --- /dev/null +++ b/MagMan.UI/Components/CmpSelCliente.razor @@ -0,0 +1,15 @@ +
+ + +
+ + diff --git a/MagMan.UI/Components/CmpSelCliente.razor.cs b/MagMan.UI/Components/CmpSelCliente.razor.cs new file mode 100644 index 0000000..75240e1 --- /dev/null +++ b/MagMan.UI/Components/CmpSelCliente.razor.cs @@ -0,0 +1,68 @@ +using MagMan.Core.Services; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Components +{ + public partial class CmpSelCliente + { + #region Public Properties + + [Parameter] + public EventCallback E_CustSelected { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + protected int CustomerID + { + get => customerID; + set + { + if (customerID != value) + { + customerID = value; + E_CustSelected.InvokeAsync(value); + InvokeAsync(() => AppMService.ClientIdSet(value)); + } + } + } + + [Inject] + protected MTAdminService MTService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + CustomerID = await AppMService.ClientIdGet(); + } + + protected override async Task OnInitializedAsync() + { + await ReloadData(); + } + + protected async Task ReloadData() + { + CustomersList = await MTService.CustomerGetAll(); + } + + #endregion Protected Methods + + #region Private Fields + + private int customerID = 0; + + private List? CustomersList = null; + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/CmpTop.razor b/MagMan.UI/Components/CmpTop.razor index 5714a62..850c2d8 100644 --- a/MagMan.UI/Components/CmpTop.razor +++ b/MagMan.UI/Components/CmpTop.razor @@ -1,10 +1,4 @@ -@using MagMan.UI.Components -@using System.Security.Claims -@using Microsoft.AspNetCore.Components.Authorization - -@inject MessageService AppMessages - -
+
diff --git a/MagMan.UI/Components/CmpTop.razor.cs b/MagMan.UI/Components/CmpTop.razor.cs index 7e309de..12f1112 100644 --- a/MagMan.UI/Components/CmpTop.razor.cs +++ b/MagMan.UI/Components/CmpTop.razor.cs @@ -1,22 +1,13 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. using Microsoft.AspNetCore.Components; +using MagMan.UI.Components; +using System.Security.Claims; +using Microsoft.AspNetCore.Components.Authorization; +using MagMan.Core.Services; namespace MagMan.UI.Components { public partial class CmpTop { - #region Private Properties - - private string PageIcon { get; set; } = ""; - - private string PageName { get; set; } = ""; - - [CascadingParameter(Name = "ShowSearch")] - private bool ShowSearch { get; set; } = false; - - #endregion Private Properties - #region Public Methods public void Dispose() @@ -36,6 +27,13 @@ namespace MagMan.UI.Components #endregion Public Methods + #region Protected Properties + + [Inject] + protected MessageService AppMessages { get; set; } = null!; + + #endregion Protected Properties + #region Protected Methods protected override void OnInitialized() @@ -49,5 +47,16 @@ namespace MagMan.UI.Components } #endregion Protected Methods + + #region Private Properties + + private string PageIcon { get; set; } = ""; + + private string PageName { get; set; } = ""; + + [CascadingParameter(Name = "ShowSearch")] + private bool ShowSearch { get; set; } = false; + + #endregion Private Properties } } \ No newline at end of file diff --git a/MagMan.UI/Components/CustomerEdit.razor b/MagMan.UI/Components/CustomerEdit.razor index 3f140c9..853870a 100644 --- a/MagMan.UI/Components/CustomerEdit.razor +++ b/MagMan.UI/Components/CustomerEdit.razor @@ -1,13 +1,19 @@ @if (CurrRecord != null) {
-
+
-
+
+
+ + +
+
+
@@ -29,7 +35,7 @@
-
+
diff --git a/MagMan.UI/Components/ItemEdit.razor b/MagMan.UI/Components/ItemEdit.razor new file mode 100644 index 0000000..abe3b1f --- /dev/null +++ b/MagMan.UI/Components/ItemEdit.razor @@ -0,0 +1,44 @@ +@if (CurrRecord != null) +{ +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+
+
+ @if (CurrRecord.MaterialNav.IsWall) + { +
+ + +
+ } + @*
+ + +
*@ +
+ + +
+ + @* *@ +
+
+
+
+} diff --git a/MagMan.UI/Components/ItemEdit.razor.cs b/MagMan.UI/Components/ItemEdit.razor.cs new file mode 100644 index 0000000..451b3ec --- /dev/null +++ b/MagMan.UI/Components/ItemEdit.razor.cs @@ -0,0 +1,50 @@ +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Components +{ + public partial class ItemEdit + { + #region Public Properties + + [Parameter] + public RawItemModel? CurrRecord { get; set; } = null; + + [Parameter] + public int KeyNum { get; set; } = 0; + [Parameter] + public EventCallback EC_update { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected async Task DoSave() + { + bool fatto = false; + await Task.Delay(1); + if (CurrRecord != null) + { + fatto = await TService.ItemUpdate(KeyNum, CurrRecord); + } + if (fatto) + { + await EC_update.InvokeAsync(true); + } + } + protected async Task DoCancel() + { + await EC_update.InvokeAsync(true); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/ItemMan.razor b/MagMan.UI/Components/ItemMan.razor index 0e1fac5..e2fa44f 100644 --- a/MagMan.UI/Components/ItemMan.razor +++ b/MagMan.UI/Components/ItemMan.razor @@ -1,5 +1,117 @@ -

ItemMan

+
+
+
+
+

Articoli

+
+
+
+
+ @if (CurrItem == null) + { + + } + else + { + + } +
+
+
+
+ @if (CurrItem != null) + { +
+ + } +
+
+ @if (ListRecords == null || isLoading) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { + + + + + + + + + @if (MaterialSel.IsWall) + { + + } + @* *@ + + @* *@ + + + + @foreach (var item in ListRecords) + { + + + + + + + @if (MaterialSel.IsWall) + { + + } + @* *@ + + @* *@ + + } + +
+ + Qty ID Note Posizione W (mm) H (mm) L (mm)
+ @* *@ + + + @item.QtyAvail + + @if (item.IsActive) + { + + + + } + else + { + + + + } +  @item.RawItemId + + @item.Note + + @item.Location + + @($"{item.WMm:N2}") + + @($"{item.HMm:N2}") + + @($"{item.LMm:N2}") + + +
+ } + +
+ +
-@code { -} diff --git a/MagMan.UI/Components/ItemMan.razor.cs b/MagMan.UI/Components/ItemMan.razor.cs new file mode 100644 index 0000000..5604f4f --- /dev/null +++ b/MagMan.UI/Components/ItemMan.razor.cs @@ -0,0 +1,346 @@ +using EgwCoreLib.Razor; +using MagMan.Core.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; + +namespace MagMan.UI.Components +{ + public partial class ItemMan + { + #region Public Properties + + [Parameter] + public int CustomerId { get; set; } = 0; + + [Parameter] + public EventCallback E_RawItemSel { get; set; } + + [Parameter] + public int KeyNum { get; set; } = 0; + + [Parameter] + public MaterialModel MaterialSel { get; set; } = null!; + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + [Inject] + protected IConfiguration Configuration { get; set; } = null!; + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + protected int totalCount { get; set; } = 0; + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected string CheckSel(RawItemModel curItem) + { + string answ = ""; + if (CurrItem != null) + { + answ = curItem.RawItemId == CurrItem.RawItemId ? "table-info" : ""; + } + else + { + answ = curItem.RawItemId == RawItemId ? "table-info" : ""; + } + return answ; + } + + + protected async Task CreateNew() + { + CurrItem = new RawItemModel() + { + MatId = MaterialSel.MatId, + Location = "nd", + Note = "...", + QtyAvail = 0, + IsActive = true, + IsRemn = false, + HMm = MaterialSel.HMm, + LMm = MaterialSel.LMm, + WMm = MaterialSel.WMm + }; + await InvokeAsync(StateHasChanged); + } + + protected async Task DeleteRecord(RawItemModel selItem) + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record?")) + return; + await TService.ItemDelete(KeyNum, selItem); + await ReloadData(); + } + + protected void DoEdit(RawItemModel? selItem) + { + CurrItem = selItem; + if (selItem == null) + { + DoSelect(null); + } + } + + protected void DoSelect(RawItemModel? selItem) + { + if (selItem != null) + { + RawItemId = selItem.MatId; + } + else + { + RawItemId = 0; + } + E_RawItemSel.InvokeAsync(RawItemId); + } + + protected async Task ForceReload(bool force) + { + CurrItem = null; + await ReloadData(); + } + + protected override void OnInitialized() + { + currSearch = ""; + AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; + } + + protected override async Task OnParametersSetAsync() + { + CurrItem = null; + await ReloadData(); + } + + protected void SetNumRec(int newNum) + { + numRecord = newNum; + currPage = 1; + InvokeAsync(ReloadData); + } + + protected void SetPage(int newNum) + { + currPage = newNum; + InvokeAsync(ReloadData); + } + + protected async Task SortRequested(Sorter.SortCallBack e) + { + sortField = e.ParamName; + sortAsc = e.IsAscending; + await ReloadData(); + } + + #endregion Protected Methods + + #region Private Fields + + private RawItemModel? CurrItem = null; + private string currSearch = ""; + private int filtType = 0; + private List? ListRecords = null; + private int RawItemId = 0; + private List? SearchRecords = null; + + private bool sortAsc = true; + + private string sortField = ""; + + #endregion Private Fields + + #region Private Properties + + private int currPage { get; set; } = 1; + + private int FiltType + { + get => filtType; + set + { + if (filtType != value) + { + filtType = value; + InvokeAsync(ReloadData); + InvokeAsync(StateHasChanged); + } + } + } + + private bool isLoading { get; set; } = false; + + private int numRecord { get; set; } = 10; + + #endregion Private Properties + + #region Private Methods + + private async void AppMService_EA_SearchUpdated() + { + currSearch = AppMService.SearchVal; + await ReloadData(); + } + + private async Task ReloadData() + { + isLoading = true; + await InvokeAsync(StateHasChanged); + ListRecords = null; + SearchRecords = await TService.ItemGetByMat(KeyNum, MaterialSel.MatId); + // verifico filtro per ricerca + if (!string.IsNullOrEmpty(currSearch)) + { + SearchRecords = SearchRecords.Where(x => x.Note.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); + } + totalCount = SearchRecords.Count; + SortTable(); + isLoading = false; + await InvokeAsync(StateHasChanged); + } + + private void SortTable() + { + if (SearchRecords != null) + { + // se ho ordinamento riordino... + if (!string.IsNullOrEmpty(sortField)) + { + switch (sortField) + { + case "RawItemId": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.RawItemId).ThenBy(x => x.Note).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.RawItemId).ThenByDescending(x => x.Note).ToList(); + } + break; + + case "Location": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.Location).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.Location).ToList(); + } + break; + + case "QtyAvail": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.QtyAvail).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.QtyAvail).ToList(); + } + break; + + case "Note": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.Note).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.Note).ToList(); + } + break; + + case "IsActive": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.IsActive).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.IsActive).ToList(); + } + break; + + case "IsRemn": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.IsRemn).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.IsRemn).ToList(); + } + break; + + case "W": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.WMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.WMm).ToList(); + } + break; + + case "H": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.HMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.HMm).ToList(); + } + break; + + case "L": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.LMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.LMm).ToList(); + } + break; + + default: + break; + } + } + + // filtro x display + ListRecords = SearchRecords + .Skip(numRecord * (currPage - 1)) + .Take(numRecord) + .ToList(); + } + else + { + ListRecords = new List(); + } + } + + private string textCss(bool isActive) + { + return isActive ? "text-dark" : "text-secondary text-decoration-line-through"; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/MachineMan.razor.cs b/MagMan.UI/Components/MachineMan.razor.cs index cec0547..fd84ba2 100644 --- a/MagMan.UI/Components/MachineMan.razor.cs +++ b/MagMan.UI/Components/MachineMan.razor.cs @@ -101,30 +101,6 @@ namespace MagMan.UI.Components #endregion Protected Methods -#if false - protected async Task CreateDb(MachineModel currRec) - { - await Task.Delay(1); - bool dbOk = Data.Admin.DbConfig.CheckCustDb(currRec.MainKey); - if (!dbOk) - { - dbOk = Data.Admin.DbConfig.CheckCustDb(currRec.MainKey); - } - // se ok --> migration... - if (dbOk || true) - { - string dbServerAddr = Configuration["DbConfig:Server"]; - Data.Tenant.DbConfig.InitDb(dbServerAddr, currRec.MainKey); - // verifico se serve applicazione migrazioni - Data.Tenant.DbConfig.ExecMigrationMain(); - } - // aggiorno comunque status DB... - currRec.HasDb = dbOk; - await MTService.MachineUpdate(currRec); - await ReloadData(); - } -#endif - #region Private Fields private MachineModel? CurrItem = null; diff --git a/MagMan.UI/Components/MaterialEdit.razor b/MagMan.UI/Components/MaterialEdit.razor new file mode 100644 index 0000000..2bcbad3 --- /dev/null +++ b/MagMan.UI/Components/MaterialEdit.razor @@ -0,0 +1,37 @@ +@if (CurrRecord != null) +{ +
+
+
+
+ + +
+
+ + +
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + +
+ + @* *@ +
+
+
+
+} diff --git a/MagMan.UI/Components/MaterialEdit.razor.cs b/MagMan.UI/Components/MaterialEdit.razor.cs new file mode 100644 index 0000000..4e2f325 --- /dev/null +++ b/MagMan.UI/Components/MaterialEdit.razor.cs @@ -0,0 +1,54 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Components +{ + public partial class MaterialEdit + { + #region Public Properties + + [Parameter] + public MaterialModel? CurrRecord { get; set; } = null; + + [Parameter] + public int KeyNum { get; set; } = 0; + [Parameter] + public EventCallback EC_update { get; set; } + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected async Task DoSave() + { + bool fatto = false; + await Task.Delay(1); + if (CurrRecord != null) + { + fatto = await TService.MaterialUpdate(KeyNum, CurrRecord); + } + if (fatto) + { + await EC_update.InvokeAsync(true); + } + } + protected async Task DoCancel() + { + await EC_update.InvokeAsync(true); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/MaterialMan.razor b/MagMan.UI/Components/MaterialMan.razor index 73aec93..4130b17 100644 --- a/MagMan.UI/Components/MaterialMan.razor +++ b/MagMan.UI/Components/MaterialMan.razor @@ -1,5 +1,124 @@ -

MaterialMan

+
+
+
+
+

Materiali

+
+
+
+
+ @if (CurrItem == null) + { + + } + else + { + + } +
+
+
+ Tipo Mat. + +
+
+
+
+
+ @if (CurrItem != null) + { +
+ + } +
+
+ @if (ListRecords == null || isLoading) + { + + } + else if (totalCount == 0) + { +
Nessun record trovato
+ } + else + { + + + + + + + + + + @* *@ + @* *@ + + + + @foreach (var item in ListRecords) + { + + + + + + + + @* *@ + @* *@ + + } + +
+ + ID Mat.Code Descr. W (mm) H (mm) L (mm)
+ + + + @if (item.IsBeam) + { + + + + } + else if (@item.IsWall) + { + + + + } +  @item.MatId + + @item.MatCode + + @item.MatDesc + + @if (item.IsBeam) + { + @($"{item.WMm:N2}") + } + else + { + - + } + + @($"{item.HMm:N2}") + + @($"{item.LMm:N2}") + + +
+ } + +
+ +
-@code { -} diff --git a/MagMan.UI/Components/MaterialMan.razor.cs b/MagMan.UI/Components/MaterialMan.razor.cs new file mode 100644 index 0000000..fbb97ec --- /dev/null +++ b/MagMan.UI/Components/MaterialMan.razor.cs @@ -0,0 +1,313 @@ +// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this +// file to you under the MIT license. +using EgwCoreLib.Razor; +using MagMan.Core.Services; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MimeKit.Text; + +namespace MagMan.UI.Components +{ + public partial class MaterialMan + { + #region Public Properties + + [Parameter] + public int CustomerId { get; set; } = 0; + + [Parameter] + public EventCallback E_MaterialSel { get; set; } + + [Parameter] + public int KeyNum { get; set; } = 0; + + #endregion Public Properties + + #region Protected Properties + + [Inject] + protected MessageService AppMService { get; set; } = null!; + + [Inject] + protected IConfiguration Configuration { get; set; } = null!; + + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + protected int totalCount { get; set; } = 0; + + [Inject] + protected TenantService TService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + + protected string CheckSel(MaterialModel curItem) + { + string answ = ""; + if (CurrItem != null) + { + answ = curItem.MatId == CurrItem.MatId ? "table-info" : ""; + } + else + { + answ = curItem.MatId == MaterialId ? "table-info" : ""; + } + return answ; + } + + protected async Task CreateNew() + { + CurrItem = new MaterialModel() + { + MatCode = "Mat_unique_code", + MatDesc = "Material Description" + }; + await InvokeAsync(StateHasChanged); + } + + protected async Task DeleteRecord(MaterialModel selItem) + { + if (!await JSRuntime.InvokeAsync("confirm", "Sicuro di voler eliminare il record?")) + return; + await TService.MaterialDelete(KeyNum, selItem); + await ReloadData(); + } + + protected void DoEdit(MaterialModel? selItem) + { + CurrItem = selItem; + if (selItem == null) + { + DoSelect(null); + } + } + protected void DoSelect(MaterialModel? selItem) + { + if (selItem != null) + { + MaterialId = selItem.MatId; + } + else + { + MaterialId = 0; + } + E_MaterialSel.InvokeAsync(selItem); + } + + protected async Task ForceReload(bool force) + { + CurrItem = null; + await ReloadData(); + } + + protected override void OnInitialized() + { + currSearch = ""; + AppMService.EA_SearchUpdated += AppMService_EA_SearchUpdated; + } + + protected override async Task OnParametersSetAsync() + { + await ReloadData(); + } + + protected void SetNumRec(int newNum) + { + numRecord = newNum; + currPage = 1; + InvokeAsync(ReloadData); + } + + protected void SetPage(int newNum) + { + currPage = newNum; + DoSelect(null); + InvokeAsync(ReloadData); + } + + protected async Task SortRequested(Sorter.SortCallBack e) + { + sortField = e.ParamName; + sortAsc = e.IsAscending; + await ReloadData(); + } + + #endregion Protected Methods + + #region Private Fields + + private MaterialModel? CurrItem = null; + private int MaterialId = 0; + + private string currSearch = ""; + private int filtType = 0; + private List? ListRecords = null; + + private List? SearchRecords = null; + + private bool sortAsc = true; + + private string sortField = ""; + + #endregion Private Fields + + #region Private Properties + + private int currPage { get; set; } = 1; + + private int FiltType + { + get => filtType; + set + { + if (filtType != value) + { + filtType = value; + InvokeAsync(ReloadData); + InvokeAsync(StateHasChanged); + } + } + } + + private bool isLoading { get; set; } = false; + + private int numRecord { get; set; } = 10; + + #endregion Private Properties + + #region Private Methods + + private async void AppMService_EA_SearchUpdated() + { + currSearch = AppMService.SearchVal; + await ReloadData(); + } + + private async Task ReloadData() + { + isLoading = true; + await InvokeAsync(StateHasChanged); + ListRecords = null; + SearchRecords = await TService.MaterialGetAll(KeyNum, false); + // verifico se filtrare x beam/wall + if (FiltType > 0) + { + SearchRecords = SearchRecords.Where(x => (x.IsBeam && FiltType == 1) || (x.IsWall && FiltType == 2)).ToList(); + } + // verifico filtro per ricerca + if (!string.IsNullOrEmpty(currSearch)) + { + SearchRecords = SearchRecords.Where(x => x.MatCode.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase) || x.MatDesc.Contains(currSearch, StringComparison.InvariantCultureIgnoreCase)).ToList(); + } + totalCount = SearchRecords.Count; + SortTable(); + isLoading = false; + await InvokeAsync(StateHasChanged); + } + + private void SortTable() + { + if (SearchRecords != null) + { + // se ho ordinamento riordino... + if (!string.IsNullOrEmpty(sortField)) + { + switch (sortField) + { + case "RawItemId": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.MatId).ThenBy(x => x.MatCode).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.MatId).ThenByDescending(x => x.MatCode).ToList(); + } + break; + + case "MatCode": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.MatCode).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.MatCode).ToList(); + } + break; + + case "MatDesc": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.MatDesc).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.MatDesc).ToList(); + } + break; + + case "W": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.WMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.WMm).ToList(); + } + break; + + case "H": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.HMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.HMm).ToList(); + } + break; + + case "L": + if (sortAsc) + { + SearchRecords = SearchRecords.OrderBy(x => x.LMm).ToList(); + } + else + { + SearchRecords = SearchRecords.OrderByDescending(x => x.LMm).ToList(); + } + break; + + default: + break; + } + } + + // filtro x display + ListRecords = SearchRecords + .Skip(numRecord * (currPage - 1)) + .Take(numRecord) + .ToList(); + } + else + { + ListRecords = new List(); + } + } + + private string textCss(bool isActive) + { + return isActive ? "text-dark" : "text-secondary text-decoration-line-through"; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MagMan.UI/Components/SearchMod.razor b/MagMan.UI/Components/SearchMod.razor index 05ade27..cc1a2b1 100644 --- a/MagMan.UI/Components/SearchMod.razor +++ b/MagMan.UI/Components/SearchMod.razor @@ -3,8 +3,6 @@
-
- -
+
diff --git a/MagMan.UI/Controllers/InventoryController.cs b/MagMan.UI/Controllers/InventoryController.cs new file mode 100644 index 0000000..f71323c --- /dev/null +++ b/MagMan.UI/Controllers/InventoryController.cs @@ -0,0 +1,123 @@ +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; +using MagMan.Core.Services; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using NLog; +using Org.BouncyCastle.Asn1.Pkcs; + +namespace MagMan.UI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class InventoryController : ControllerBase + { + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private MTAdminService MTAdmService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public InventoryController(MTAdminService MTDataService, TenantService TDataService) + { + MTAdmService = MTDataService; + TService = TDataService; + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + Log.Info("Avviata classe InventoryController"); + } + + /// + /// Controllo status Alive + /// GET: api/Inventory/alive + /// + /// + [HttpGet("alive")] + public string alive() + { + //Log.Debug("Chiamata alive"); + return $"OK"; + } + + // GET api/Inventory + [HttpGet] + public async Task> Get() + { + // se non ho chiave --> vuoto! + List ListRecords = new List(); + await Task.Delay(100); + return ListRecords; + } + + /// + /// Elenco Materiali dato RestToken + /// + /// Rest Token cliente + /// ID del materiale cercato + /// + // GET api/Inventory/00000000-0000-0000-0000-000000000000 + [HttpGet("{id}")] + public async Task> Get(string id, int MatId) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + // ora recupero direttametne i materiali + var ListRecords = await TService.MaterialGetFilt(nKey, MatId, true); + return ListRecords; + } + + /// + /// Processa una chiamata POST per l'invio di un array Json di oggetti MaterialModel da salvare + /// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Items rawList) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && rawList != null && rawList.ItemList != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) + { + // creo oggetti materiale da lista ricevuta + List matList = rawList.ItemList.Select(jpl => TService.ItemFromDto(jpl, true)).ToList(); + + foreach (var item in matList) + { + try + { + await TService.ItemUpdate(nKey, item); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"InventoryController.upsert | Errore in fase salvataggio ItemDto{Environment.NewLine}{exc}"); + fatto = false; + } + } + // resetto cache redis + await MTAdmService.FlushRedisCache(); + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } + + + } +} diff --git a/MagMan.UI/Controllers/MaterialsController.cs b/MagMan.UI/Controllers/MaterialsController.cs index 6599c8f..ef8aa5f 100644 --- a/MagMan.UI/Controllers/MaterialsController.cs +++ b/MagMan.UI/Controllers/MaterialsController.cs @@ -19,12 +19,12 @@ namespace MagMan.UI.Controllers /// Classe per logging ///
private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); - private MTAdminService MTAdminService { get; set; } = null!; + private MTAdminService MTAdmService { get; set; } = null!; private static JsonSerializerSettings? JSSettings; private TenantService TService { get; set; } = null!; public MaterialsController(MTAdminService MTDataService, TenantService TDataService) { - MTAdminService = MTDataService; + MTAdmService = MTDataService; TService = TDataService; // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ JSSettings = new JsonSerializerSettings() @@ -66,20 +66,20 @@ namespace MagMan.UI.Controllers public async Task> Get(string id) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); + int nKey = await MTAdmService.MainKeyByToken(id); // ora recupero direttametne i materiali - var ListRecords = await TService.MaterialGetAll(nKey); + var ListRecords = await TService.MaterialGetAll(nKey, false); return ListRecords; } /// /// Processa una chiamata POST per l'invio di un array Json di oggetti MaterialModel da salvare - /// PUT: api/Materials/upsertMat/00000000-0000-0000-0000-000000000000 + /// PUT: api/Materials/upsert/00000000-0000-0000-0000-000000000000 /// /// token comunicazione /// - [HttpPost("upsertMat/{id}")] - public async Task upsertMat(string id, [FromBody] RestPayload.Materials rawList) + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Materials rawList) { string answ = "ND"; bool fatto = false; @@ -87,22 +87,27 @@ namespace MagMan.UI.Controllers if (!string.IsNullOrEmpty(id) && rawList != null && rawList.MatList != null) { // in primis recupero codice chiave da token... - int nKey = await MTAdminService.MainKeyByToken(id); - // creo oggetti materiale da lista ricevuta - List matList = rawList.MatList.Select(jpl => TService.MaterialFromDto(jpl)).ToList(); - - foreach (var item in matList) + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) { - try + // creo oggetti materiale da lista ricevuta + List matList = rawList.MatList.Select(jpl => TService.MaterialFromDto(jpl)).ToList(); + + foreach (var item in matList) { - await TService.MaterialUpdate(nKey, item); - fatto = true; - } - catch (Exception exc) - { - Log.Error($"Errore in fase salvataggio MaterialDto{Environment.NewLine}{exc}"); - fatto = false; + try + { + await TService.MaterialUpdate(nKey, item); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"MaterialsController.upsert | Errore in fase salvataggio MaterialDto{Environment.NewLine}{exc}"); + fatto = false; + } } + // resetto cache redis + await MTAdmService.FlushRedisCache(); } } answ = fatto ? "OK" : "NO"; diff --git a/MagMan.UI/Controllers/ProjectsController.cs b/MagMan.UI/Controllers/ProjectsController.cs new file mode 100644 index 0000000..38b575a --- /dev/null +++ b/MagMan.UI/Controllers/ProjectsController.cs @@ -0,0 +1,113 @@ +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using NLog; +using System.Diagnostics; + +namespace MagMan.UI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ProjectsController : ControllerBase + { + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private MTAdminService MTAdmService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public ProjectsController(MTAdminService MTDataService, TenantService TDataService) + { + MTAdmService = MTDataService; + TService = TDataService; + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + Log.Info("Avviata classe ProjectsController"); + } + + /// + /// Controllo status Alive + /// GET: api/Machines/alive + /// + /// + [HttpGet("alive")] + public string alive() + { + //Log.Debug("Chiamata alive"); + return $"OK"; + } + + // GET api/Machines/5 + [HttpGet] + public async Task> Get() + { + // se non ho chaive --> vuoto! + List ListRecords = new List(); + await Task.Delay(100); + return ListRecords; + } + + /// + /// Elenco Macchine dato RestToken + /// + /// Rest Token cliente + /// + // GET api/Machines/2cba60c7-7be4-40b1-aa0d-52e7c71fc1a7 + [HttpGet("{id}")] + public async Task> Get(string id, int KeyNum) + { + var ListRecords = await MTAdmService.MachineGetByToken(id); + return ListRecords; + } + + /// + /// Processa una chiamata POST per l'invio di un oggetto di aggiornamento progetto + /// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] ProjectDTO projectData) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && projectData != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) + { + // converto ProjDto --> DB + var currRec = TService.ProjectFromDto(projectData); + try + { + await TService.ProjectUpdate(nKey, currRec); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"ProjectsController.upsert | Errore in fase salvataggio ProjectDTO{Environment.NewLine}{exc}"); + fatto = false; + } + // resetto cache redis + await MTAdmService.FlushRedisCache(); + + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } + } +} diff --git a/MagMan.UI/Controllers/ResourcesController.cs b/MagMan.UI/Controllers/ResourcesController.cs new file mode 100644 index 0000000..81edb1b --- /dev/null +++ b/MagMan.UI/Controllers/ResourcesController.cs @@ -0,0 +1,117 @@ +using k8s.Models; +using MagMan.Core; +using MagMan.Core.DTO; +using MagMan.Data.Admin.DbModels; +using MagMan.Data.Admin.Services; +using MagMan.Data.Tenant.DbModels; +using MagMan.Data.Tenant.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using NLog; + +namespace MagMan.UI.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class ResourcesController : ControllerBase + { + /// + /// Classe per logging + /// + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + private MTAdminService MTAdmService { get; set; } = null!; + private static JsonSerializerSettings? JSSettings; + private TenantService TService { get; set; } = null!; + public ResourcesController(MTAdminService MTDataService, TenantService TDataService) + { + MTAdmService = MTDataService; + TService = TDataService; + // json serializer... FIX errore loop circolare https://www.ryadel.com/en/jsonserializationexception-self-referencing-loop-detected-error-fix-entity-framework-asp-net-core/ + JSSettings = new JsonSerializerSettings() + { + ReferenceLoopHandling = ReferenceLoopHandling.Ignore + }; + Log.Info("Avviata classe ResourcesController"); + } + + /// + /// Controllo status Alive + /// GET: api/Machines/alive + /// + /// + [HttpGet("alive")] + public string alive() + { + //Log.Debug("Chiamata alive"); + return $"OK"; + } + + // GET api/Machines/5 + [HttpGet] + public async Task> Get() + { + // se non ho chaive --> vuoto! + List ListRecords = new List(); + await Task.Delay(100); + return ListRecords; + } + + /// + /// Elenco Macchine dato RestToken + /// + /// Rest Token cliente + /// + // GET api/Machines/2cba60c7-7be4-40b1-aa0d-52e7c71fc1a7 + [HttpGet("{id}")] + public async Task> Get(string id, int KeyNum) + { + var ListRecords = await MTAdmService.MachineGetByToken(id); + return ListRecords; + } + + /// + /// Processa una chiamata POST per l'invio di un oggetto di aggiornamento risorse progetto (RestPayload.Resources) + /// PUT: api/Inventory/upsert/00000000-0000-0000-0000-000000000000 + /// + /// token comunicazione + /// + [HttpPost("upsert/{id}")] + public async Task upsert(string id, [FromBody] RestPayload.Resources projectData) + { + string answ = "ND"; + bool fatto = false; + // verifico ci sia valore + if (!string.IsNullOrEmpty(id) && projectData != null) + { + // in primis recupero codice chiave da token... + int nKey = await MTAdmService.MainKeyByToken(id); + if (nKey > 0) + { +#if false + // creo oggetti materiale da lista ricevuta + List matList = item2Consume.ItemList.Select(jpl => TService.ItemFromDto(jpl, true)).ToList(); + + foreach (var item in matList) + { + try + { + await TService.ItemUpdate(nKey, item); + fatto = true; + } + catch (Exception exc) + { + Log.Error($"InventoryController.upsert | Errore in fase salvataggio ItemDto{Environment.NewLine}{exc}"); + fatto = false; + } + } +#endif + // resetto cache redis + await MTAdmService.FlushRedisCache(); + } + } + answ = fatto ? "OK" : "NO"; + return answ; + } + } +} diff --git a/MagMan.UI/MagMan.UI.csproj b/MagMan.UI/MagMan.UI.csproj index 26bccc8..1a68aab 100644 --- a/MagMan.UI/MagMan.UI.csproj +++ b/MagMan.UI/MagMan.UI.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.2401.1610 + 1.0.2401.2220 enable enable true @@ -36,8 +36,8 @@ - - + + diff --git a/MagMan.UI/Pages/AdminArea.razor b/MagMan.UI/Pages/AdminArea.razor index c15ffb1..d925cba 100644 --- a/MagMan.UI/Pages/AdminArea.razor +++ b/MagMan.UI/Pages/AdminArea.razor @@ -22,19 +22,7 @@
@if (currMode != CtMode.Company) { -
- - -
+ }
diff --git a/MagMan.UI/Pages/AdminArea.razor.cs b/MagMan.UI/Pages/AdminArea.razor.cs index cd24a4b..c035dc3 100644 --- a/MagMan.UI/Pages/AdminArea.razor.cs +++ b/MagMan.UI/Pages/AdminArea.razor.cs @@ -1,9 +1,6 @@ -// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this -// file to you under the MIT license. -using k8s.Models; +using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; -using MagMan.Data.Tenant.Services; using Microsoft.AspNetCore.Components; namespace MagMan.UI.Pages @@ -34,12 +31,16 @@ namespace MagMan.UI.Pages #region Protected Methods - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { AppMService.ShowSearch = false; AppMService.PageName = "Admin Area"; AppMService.PageIcon = "fa-solid fa-house pr-2"; - await ReloadData(); + } + + protected void SaveCust(int newCustId) + { + CustomerID = newCustId; } #endregion Protected Methods @@ -47,14 +48,12 @@ namespace MagMan.UI.Pages #region Private Fields private CtMode currMode = CtMode.Company; - private int CustomerID = 0; - private List? CustomersList = null; #endregion Private Fields #region Private Properties - private bool isLoading { get; set; } = false; + private int CustomerID { get; set; } = 0; [Inject] private NavigationManager NavMan { get; set; } = null!; @@ -69,13 +68,6 @@ namespace MagMan.UI.Pages return answ; } - private async Task ReloadData() - { - isLoading = true; - CustomersList = await MTService.CustomerGetAll(); - isLoading = false; - } - private void SetMode(CtMode newMode) { currMode = newMode; diff --git a/MagMan.UI/Pages/Index.razor b/MagMan.UI/Pages/Index.razor index ffb5bb5..d1470ea 100644 --- a/MagMan.UI/Pages/Index.razor +++ b/MagMan.UI/Pages/Index.razor @@ -46,8 +46,8 @@ - -
Admin Area
+ +

Admin Area

@@ -55,9 +55,9 @@
- - -
Macchine
+ + +

Dati Macchine

@@ -65,9 +65,9 @@
- - -
Magazzino
+ + +

Magazzino

diff --git a/MagMan.UI/Pages/Index.razor.cs b/MagMan.UI/Pages/Index.razor.cs index 98bd9f5..5c29f2f 100644 --- a/MagMan.UI/Pages/Index.razor.cs +++ b/MagMan.UI/Pages/Index.razor.cs @@ -1,6 +1,5 @@ -using MagMan.Data.Tenant.Services; +using MagMan.Core.Services; using Microsoft.AspNetCore.Components; -using System; namespace MagMan.UI.Pages { diff --git a/MagMan.UI/Pages/MachineStatus.razor b/MagMan.UI/Pages/MachineStatus.razor index b690dc2..2da7b02 100644 --- a/MagMan.UI/Pages/MachineStatus.razor +++ b/MagMan.UI/Pages/MachineStatus.razor @@ -3,3 +3,4 @@

MachineStatus

+Work In Progress \ No newline at end of file diff --git a/MagMan.UI/Pages/ResetCache.razor.cs b/MagMan.UI/Pages/ResetCache.razor.cs index 5b1fec6..4f66efc 100644 --- a/MagMan.UI/Pages/ResetCache.razor.cs +++ b/MagMan.UI/Pages/ResetCache.razor.cs @@ -1,11 +1,6 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -using k8s.KubeConfigModels; +using MagMan.Core.Services; using MagMan.Data.Admin.Services; -using MagMan.Data.Tenant.Services; -using MagMan.UI.Shared; using Microsoft.AspNetCore.Components; -using System; namespace MagMan.UI.Pages { diff --git a/MagMan.UI/Pages/WareHouse.razor b/MagMan.UI/Pages/WareHouse.razor index e1b6625..91abc55 100644 --- a/MagMan.UI/Pages/WareHouse.razor +++ b/MagMan.UI/Pages/WareHouse.razor @@ -4,59 +4,31 @@
-
-
- - - - -
+
-@if (KeyNum == 0) +@if (CustomerID == 0) {
- Key Undef + Customer Undef
- Prego selezionare Key valida per visualizzare dati Magazzino + Prego selezionare Cliente per visualizzare dati Magazzino
} else { - @if (currMode == CtMode.Materials) - { - - } - else if (currMode == CtMode.Items) - { - - } +
+
+ +
+ @if (MaterialSel != null) + { +
+ +
+ } +
} \ No newline at end of file diff --git a/MagMan.UI/Pages/WareHouse.razor.cs b/MagMan.UI/Pages/WareHouse.razor.cs index dfcf9d4..3a501b0 100644 --- a/MagMan.UI/Pages/WareHouse.razor.cs +++ b/MagMan.UI/Pages/WareHouse.razor.cs @@ -1,73 +1,83 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -using k8s.Models; +using MagMan.Core.Services; using MagMan.Data.Admin.DbModels; using MagMan.Data.Admin.Services; -using MagMan.Data.Tenant.Services; +using MagMan.Data.Tenant.DbModels; using Microsoft.AspNetCore.Components; +using YamlDotNet.Core.Tokens; namespace MagMan.UI.Pages { public partial class WareHouse { + #region Protected Fields + + protected int nKey = 0; + + #endregion Protected Fields + + #region Protected Properties + [Inject] protected MessageService AppMService { get; set; } = null!; + protected int CustomerID { get; set; } = 0; + + protected string mainCss + { + get => MaterialSel == null ? "col-12" : "col-6 small"; + } + [Inject] protected MTAdminService MTService { get; set; } = null!; + + #endregion Protected Properties + + #region Protected Methods + protected override async Task OnInitializedAsync() { - AppMService.ShowSearch = false; + AppMService.ShowSearch = true; AppMService.PageName = "Warehouse Area"; AppMService.PageIcon = "fa-solid fa-warehouse pr-2"; + // rileggo dati await ReloadData(); } + protected async Task SaveCust(int newCustId) + { + CustomerID = newCustId; + await ReloadData(); + } + + protected void SaveMat(MaterialModel? newMat) + { + MaterialSel = newMat; + } + + #endregion Protected Methods + + #region Private Fields + + private int KeyNum = 0; + private MaterialModel? MaterialSel = null; + + #endregion Private Fields + + #region Private Properties + + private bool isLoading { get; set; } = false; + + #endregion Private Properties + + #region Private Methods + private async Task ReloadData() { isLoading = true; - CustomersList = await MTService.CustomerGetAll(); - KeyList = await MTService.AuthKeyByCustId(CustomerID); + nKey = await MTService.MainKeyByCustomer(CustomerID); isLoading = false; } - private bool isLoading { get; set; } = false; - private CtMode currMode = CtMode.Materials; - protected int CustomerID - { - get => customerID; - set - { - if (customerID != value) - { - customerID = value; - // update keys - var pUpd = Task.Run(async () => await ReloadData()); - pUpd.Wait(); - } - } - } - private int customerID = 0; - private int KeyNum = 0; - private List? CustomersList = null; - private List? KeyList = null; - protected enum CtMode - { - Materials, - Items, - //Deposit, - //Pickup - } - - private string IsActive(CtMode modeReq) - { - string answ = currMode == modeReq ? "active" : ""; - return answ; - } - - private void SetMode(CtMode newMode) - { - currMode = newMode; - } + #endregion Private Methods } } \ No newline at end of file diff --git a/MagMan.UI/Shared/MainLayout.razor b/MagMan.UI/Shared/MainLayout.razor index 0e5211b..2131c01 100644 --- a/MagMan.UI/Shared/MainLayout.razor +++ b/MagMan.UI/Shared/MainLayout.razor @@ -1,10 +1,5 @@ @inherits LayoutComponentBase -@using MagMan.UI.Components -@inject MessageService MessageService -@implements IDisposable - - MagMan UI
@@ -27,46 +22,3 @@
- -@code { - bool ShowSearch { get; set; } = false; - - protected override void OnInitialized() - { - MessageService.EA_ShowSearch += OnShowSearch; - MessageService.EA_HideSearch += OnHideSearch; - } - public void OnShowSearch() - { - ShowSearch = true; - InvokeAsync(() => - { - StateHasChanged(); - }); - } - public void OnHideSearch() - { - ShowSearch = false; - InvokeAsync(() => - { - StateHasChanged(); - }); - } - - public void Dispose() - { - MessageService.EA_ShowSearch -= OnShowSearch; - MessageService.EA_ShowSearch -= OnHideSearch; - } - - protected bool navLarge { get; set; } = true; - - protected string sideClass { get; set; } = "sidebar"; - - protected void UpdateNavDisplay() - { - navLarge = !navLarge; - sideClass = navLarge ? "sidebar" : "sidebarSmall"; - } - -} diff --git a/MagMan.UI/Shared/MainLayout.razor.cs b/MagMan.UI/Shared/MainLayout.razor.cs new file mode 100644 index 0000000..a719d54 --- /dev/null +++ b/MagMan.UI/Shared/MainLayout.razor.cs @@ -0,0 +1,68 @@ +using MagMan.Core.Services; +using Microsoft.AspNetCore.Components; + +namespace MagMan.UI.Shared +{ + public partial class MainLayout : IDisposable + { + #region Public Methods + + public void Dispose() + { + MessageService.EA_ShowSearch -= OnShowSearch; + MessageService.EA_ShowSearch -= OnHideSearch; + } + + public void OnHideSearch() + { + ShowSearch = false; + InvokeAsync(() => + { + StateHasChanged(); + }); + } + + public void OnShowSearch() + { + ShowSearch = true; + InvokeAsync(() => + { + StateHasChanged(); + }); + } + + #endregion Public Methods + + #region Protected Properties + + [Inject] + protected MessageService MessageService { get; set; } = null!; + + protected bool navLarge { get; set; } = true; + protected string sideClass { get; set; } = "sidebar"; + + #endregion Protected Properties + + #region Protected Methods + + protected override void OnInitialized() + { + MessageService.EA_ShowSearch += OnShowSearch; + MessageService.EA_HideSearch += OnHideSearch; + } + + protected void UpdateNavDisplay() + { + navLarge = !navLarge; + sideClass = navLarge ? "sidebar" : "sidebarSmall"; + } + + #endregion Protected Methods + + #region Private Properties + + private bool ShowSearch { get; set; } = false; + + #endregion Private Properties + } +} \ No newline at end of file diff --git a/MagMan.UI/Shared/NavMenu.razor b/MagMan.UI/Shared/NavMenu.razor index 04ca961..8d63bc6 100644 --- a/MagMan.UI/Shared/NavMenu.razor +++ b/MagMan.UI/Shared/NavMenu.razor @@ -43,7 +43,12 @@ +