From eaf4646754ee435a1703d503a376d9290402a9af Mon Sep 17 00:00:00 2001 From: RenzoL Date: Tue, 15 Jun 2021 15:02:06 +0200 Subject: [PATCH] LicenceManager 2.3f2: - sistemato ritardo apertura UpdateLicencePage quando si fa Update (New) - aggiunto ExecuteStringDictionaryQuery per evitare chiamate doppie al DB con la stessa query che estrae lo stesso record --- LicenceBox/LicenceBoxVM.vb | 6 ++-- My Project/AssemblyInfo.vb | 4 +-- NewLicencePage/NewLicencePageVM.vb | 3 +- SearchLicencePage/SearchLicencePageVM.vb | 5 ++-- UpdateClientPage/UpdateClientPageVM.vb | 6 ++-- UpdateLicencePage/UpdateLicencePageVM.vb | 35 ++++++++++++++-------- UpdateResellerPage/UpdateResellerPageVM.vb | 5 ++-- Utility/ManageDb.vb | 25 ++++++++++++++++ 8 files changed, 65 insertions(+), 24 deletions(-) diff --git a/LicenceBox/LicenceBoxVM.vb b/LicenceBox/LicenceBoxVM.vb index 2ea81ea..ed9d1f5 100644 --- a/LicenceBox/LicenceBoxVM.vb +++ b/LicenceBox/LicenceBoxVM.vb @@ -151,7 +151,8 @@ Public Class LicenceBoxVM ' Cerco NestDeadline associato alla Licenza, se presente lo visualizzo Dim licId As String = CType(Map.refSearchLicencePageVM.Row.Item, Licence).LicenceID Dim Query As String = "SELECT " & DB_NESTDEADLINE & " FROM " & DB_LICENCE & " WHERE " & DB_LICENCEID & " = " & licId - Dim NestDl As String = ManageDb.ExecuteStringQuery(Query, DB_NESTDEADLINE)(0) + Dim m_NestKeyDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Dim NestDl As String = m_NestKeyDict(DB_NESTDEADLINE) If Not String.IsNullOrWhiteSpace(NestDl) Or Not String.IsNullOrEmpty(NestDl) Then m_NestDlTxBl_Visibility = Visibility.Visible m_NestDlTxBx_Visibility = Visibility.Visible @@ -171,7 +172,8 @@ Public Class LicenceBoxVM Dim SelectedLicence = CType(Map.refSearchLicencePageVM.Row.Item, Licence) 'Cerco ProductName associato a ProductID Dim Query As String = "SELECT " & DB_PRODUCTNAME & " FROM " & DB_PRODUCT & " WHERE " & DB_PRODUCTID & " = " & SelectedLicence.ProductID - Dim ProductName = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTNAME)(0) + Dim m_ProductNameDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Dim ProductName As String = m_ProductNameDict(DB_PRODUCTNAME) ' Cancello opzioni OptionList.Clear() ' Carico opzioni diff --git a/My Project/AssemblyInfo.vb b/My Project/AssemblyInfo.vb index 5423c73..e1d0e5d 100644 --- a/My Project/AssemblyInfo.vb +++ b/My Project/AssemblyInfo.vb @@ -59,5 +59,5 @@ Imports System.Windows ' usando l'asterisco '*' come illustrato di seguito: ' - - + + diff --git a/NewLicencePage/NewLicencePageVM.vb b/NewLicencePage/NewLicencePageVM.vb index 600a837..9aea2ad 100644 --- a/NewLicencePage/NewLicencePageVM.vb +++ b/NewLicencePage/NewLicencePageVM.vb @@ -528,7 +528,8 @@ Public Class NewLicencePageVM ' Cerco LockID associato alla chiave Dim Query As String = "SELECT " & DB_LOCKID & " FROM " & DB_KEY & " WHERE " & DB_NUMBER & " = " & SelNumber.Number & " AND " & DB_ISDONGLE & " = " & If(GetSelIsDongle(), 1, 0) - Dim LockID As String = ManageDb.ExecuteStringQuery(Query, DB_LOCKID)(0) + Dim m_LockIDDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Dim LockID As String = m_LockIDDict(DB_LOCKID) If String.IsNullOrWhiteSpace(LockID) Then MessageBox.Show("Errore") Return diff --git a/SearchLicencePage/SearchLicencePageVM.vb b/SearchLicencePage/SearchLicencePageVM.vb index 9073085..e70f39e 100644 --- a/SearchLicencePage/SearchLicencePageVM.vb +++ b/SearchLicencePage/SearchLicencePageVM.vb @@ -422,7 +422,7 @@ Public Class SearchLicencePageVM NotifyPropertyChanged("VersionList") ' Carico lista ProductLevel - Query = "SELECT " & DB_PRODUCTLEVEL & " FROM " & DB_LICENCE & " GROUP BY " & DB_PRODUCTLEVEL + Query = "SELECT DISTINCT " & DB_PRODUCTLEVEL & " FROM " & DB_LICENCE & " GROUP BY " & DB_PRODUCTLEVEL m_ProductLevelList = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTLEVEL) m_ProductLevelList.Sort(Function(x, y) CInt(y).CompareTo(CInt(x))) m_ProductLevelList.Add("---ANY---") @@ -771,7 +771,8 @@ Public Class SearchLicencePageVM " INNER JOIN " & DB_CLIENT & " ON " & DB_KEY & "." & DB_CLIENTID & " = " & DB_CLIENT & "." & DB_CLIENTID & " WHERE " & DB_LICENCEID & " = " & m_SelSearchResult.LicenceID - Dim sRecipentAddress As String = ExecuteStringQuery(Query, DB_EMAIL)(0) + Dim m_sRecipentAddressDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Dim sRecipentAddress As String = m_sRecipentAddressDict(DB_EMAIL) ' preparo la mail per il supporto Dim bEx As Boolean = False diff --git a/UpdateClientPage/UpdateClientPageVM.vb b/UpdateClientPage/UpdateClientPageVM.vb index 96cef16..3b7c8f5 100644 --- a/UpdateClientPage/UpdateClientPageVM.vb +++ b/UpdateClientPage/UpdateClientPageVM.vb @@ -76,13 +76,15 @@ Public Class UpdateClientPageVM ' Carico campo Name Dim Query As String = "SELECT " & DB_NAME & " FROM " & DB_CLIENT & " WHERE " & DB_CLIENTID & " LIKE " & IdToUpdate - Name = ManageDb.ExecuteStringQuery(Query, DB_NAME)(0) + Dim m_NameDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Dim Name As String = m_NameDict(DB_NAME) NotifyPropertyChanged("Name") ' Carico campo Email Dim eQuery As String = "SELECT " & DB_EMAIL & " FROM " & DB_CLIENT & " WHERE " & DB_CLIENTID & " LIKE " & IdToUpdate - Email = ManageDb.ExecuteStringQuery(eQuery, DB_EMAIL)(0) + Dim m_EmailDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(eQuery) + Dim Email As String = m_EmailDict(DB_EMAIL) NotifyPropertyChanged("Email") ' Carico lista Reseller diff --git a/UpdateLicencePage/UpdateLicencePageVM.vb b/UpdateLicencePage/UpdateLicencePageVM.vb index 7c777d6..7c06571 100644 --- a/UpdateLicencePage/UpdateLicencePageVM.vb +++ b/UpdateLicencePage/UpdateLicencePageVM.vb @@ -231,7 +231,8 @@ Public Class UpdateLicencePageVM ' Quando viene scelto un KeyNumber viene modificato automaticamente anche il FilePath sostituendo il KeyNumber e ' calcolando il nome che il file dovrà avere senza o con '_' e con quale numero dopo) Dim LicQuery As String = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_LICENCEID & " = " & Licence.LicenceID - Dim FilePath As String = ManageDb.ExecuteStringQuery(LicQuery, DB_FILE)(0) + Dim m_FilePathDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(LicQuery) + Dim FilePath As String = m_FilePathDict(DB_FILE) Dim KeyQuery As String = "SELECT * FROM " & DB_KEY & " WHERE " & DB_LOCKID & " = '" & Licence.Number & "' " FilePath = FilePath.Replace("-" & ManageDb.ExecuteKeyQuery(KeyQuery)(0).Number.ToString("D6") & "-", "-" & SelNumber.Number.ToString("D6") & "-") @@ -435,7 +436,8 @@ Public Class UpdateLicencePageVM NotifyPropertyChanged("VersionList") ' Carico elemento della lista ProductVersion selezionato precedentemente Dim selQuery As String = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_LICENCEID & " = " & Licence.LicenceID - Dim VersNumber As String = ManageDb.ExecuteStringQuery(selQuery, DB_PRODUCTVERSION)(0) + Dim m_VersNumberDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(selQuery) + Dim VersNumber As String = m_VersNumberDict(DB_PRODUCTVERSION) m_SelVersion = m_VersionList.FirstOrDefault(Function(vers) vers.VersionNumber.Equals(CInt(VersNumber.Substring(0, 2)))) NotifyPropertyChanged("SelVersion") ' Carico elemento della lista SubVersion selezionato precedentemente @@ -502,7 +504,8 @@ Public Class UpdateLicencePageVM Dim selKQuery As String = "SELECT * FROM " & DB_LICENCE & " INNER JOIN " & DB_KEY & " ON " & DB_LICENCE & "." & DB_LOCKID & " = " & DB_KEY & "." & DB_LOCKID & " WHERE " & DB_LICENCEID & " = " & Licence.LicenceID - SelNumber = m_NumberList.FirstOrDefault(Function(key) key.Number.Equals(ManageDb.ExecuteKeyQuery(selKQuery)(0).Number)) + Dim selNum As Integer = ManageDb.ExecuteKeyQuery(selKQuery)(0).Number + SelNumber = m_NumberList.FirstOrDefault(Function(key) key.Number.Equals(selNum)) NotifyPropertyChanged("SelNumber") End If @@ -517,10 +520,12 @@ Public Class UpdateLicencePageVM m_NestKey = String.Empty m_NestDeadline = Date.Now Dim NestQuery As String = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_LICENCEID & " = " & Licence.LicenceID - m_NestKey = ManageDb.ExecuteStringQuery(NestQuery, DB_NESTKEY)(0) - Dim sNestDl As String = ManageDb.ExecuteStringQuery(NestQuery, DB_NESTDEADLINE)(0) - If Not String.IsNullOrEmpty(sNestDl) Then - m_NestDeadline = Date.ParseExact(sNestDl, "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) + Dim m_NestKeyDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(NestQuery) + m_NestKey = m_NestKeyDict(DB_NESTKEY) + Dim sNestDl As String = m_NestKeyDict(DB_NESTDEADLINE) + Dim splittedNestDl() As String = Split(sNestDl) + If Not String.IsNullOrEmpty(splittedNestDl(0)) Then + m_NestDeadline = Date.ParseExact(splittedNestDl(0), "dd/MM/yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo) End If NotifyPropertyChanged("NestKey") NotifyPropertyChanged("NestDeadline") @@ -538,7 +543,8 @@ Public Class UpdateLicencePageVM Private Sub LoadOptions(nIndex As Integer, OptionList As ObservableCollection(Of KeyOption)) 'Cerco ProductName associat a ProductID Dim Query As String = "SELECT " & DB_PRODUCTNAME & " FROM " & DB_PRODUCT & " WHERE " & DB_PRODUCTID & " = " & Licence.ProductID - m_ProductName = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTNAME)(0) + Dim m_ProductNameDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + m_ProductName = m_ProductNameDict(DB_PRODUCTNAME) ' Cancello opzioni OptionList.Clear() ' Carico opzioni @@ -611,9 +617,10 @@ Public Class UpdateLicencePageVM If Overwrite Then Dim LicQuery As String = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_LICENCEID & " = " & Licence.LicenceID - Dim LockID As String = ManageDb.ExecuteStringQuery(LicQuery, DB_LOCKID)(0) - Dim ProductID As Integer = ManageDb.ExecuteIntegerQuery(LicQuery, DB_PRODUCTID)(0) - Dim FilePath As String = ManageDb.ExecuteStringQuery(LicQuery, DB_FILE)(0) + Dim m_UpdateLicDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(LicQuery) + Dim LockID As String = m_UpdateLicDict(DB_LOCKID) + Dim ProductID As Integer = CInt(m_UpdateLicDict(DB_PRODUCTID)) + Dim FilePath As String = m_UpdateLicDict(DB_FILE) Dim FileNameOnly As String = Path.GetFileNameWithoutExtension(FilePath) Dim ProdQuery As String = "SELECT * FROM " & DB_PRODUCT & " WHERE " & DB_PRODUCTID & " = " & ProductID @@ -967,14 +974,16 @@ Public Class UpdateLicencePageVM FilePath = Path.GetDirectoryName(FilePath) & "\" & FileNameOnly.Split("_")(0) & ".Kge" FilePath = FilePath.Replace("\", "\\") Dim sFileNameQuery = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_FILE & " = '" & FilePath & "' " - If Not String.IsNullOrEmpty(ExecuteStringQuery(sFileNameQuery, DB_FILE)(0)) Then + Dim m_UpdateLicDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(sFileNameQuery) + If m_UpdateLicDict.ContainsKey(DB_FILE) AndAlso Not String.IsNullOrEmpty(m_UpdateLicDict(DB_FILE)) Then ' Se il nome del file già esiste procedo col loop per il calcolo del numero dopo '_' FilePath = FilePath.Replace("\\", "\") Dim fileNumber As Integer = 0 Do FilePath = FilePath.Replace("\", "\\") sFileNameQuery = "SELECT * FROM " & DB_LICENCE & " WHERE " & DB_FILE & " = '" & FilePath & "' " - If Not String.IsNullOrEmpty(ExecuteStringQuery(sFileNameQuery, DB_FILE)(0)) Then + m_UpdateLicDict = ManageDb.ExecuteStringDictionaryQuery(sFileNameQuery) + If m_UpdateLicDict.ContainsKey(DB_FILE) AndAlso Not String.IsNullOrEmpty(m_UpdateLicDict(DB_FILE)) Then 'The file does exist, so increment and try the next one fileNumber = fileNumber + 1 FilePath = FilePath.Replace("\\", "\") diff --git a/UpdateResellerPage/UpdateResellerPageVM.vb b/UpdateResellerPage/UpdateResellerPageVM.vb index 0eae8bb..cd953bd 100644 --- a/UpdateResellerPage/UpdateResellerPageVM.vb +++ b/UpdateResellerPage/UpdateResellerPageVM.vb @@ -93,9 +93,10 @@ Public Class UpdateResellerPageVM ' Name = String.Empty Dim Query As String = "SELECT * FROM " & DB_RESELLER & " WHERE " & DB_RESELLERID & " LIKE " & IdToUpdate - Name = ManageDb.ExecuteStringQuery(Query, DB_RESELLERNAME)(0) + Dim m_UpdateResDict As Dictionary(Of String, String) = ManageDb.ExecuteStringDictionaryQuery(Query) + Name = m_UpdateResDict(DB_RESELLERNAME) NotifyPropertyChanged("Name") - Note = ManageDb.ExecuteStringQuery(Query, DB_NOTE)(0) + Note = m_UpdateResDict(DB_NOTE) NotifyPropertyChanged("Note") End Sub diff --git a/Utility/ManageDb.vb b/Utility/ManageDb.vb index 25f3464..c5f06b7 100644 --- a/Utility/ManageDb.vb +++ b/Utility/ManageDb.vb @@ -149,6 +149,31 @@ Module ManageDb Return StringList End Function + Friend Function ExecuteStringDictionaryQuery(MySqlQuery As String) As Dictionary(Of String, String) + Dim StringDict As New Dictionary(Of String, String) + Try + Using DbConnection As New MySqlConnection(m_DbPath) + DbConnection.Open() + Using Command As MySqlCommand = New MySqlCommand(MySqlQuery, DbConnection) + Using Reader As MySqlDataReader = Command.ExecuteReader() + While Reader.Read() + For index = 0 To Reader.FieldCount - 1 + StringDict.Add(Reader.GetName(index), Reader.GetValue(index).ToString()) + Next + End While + If IsNothing(StringDict) Or StringDict.Count = 0 Then + StringDict.Add(String.Empty, String.Empty) + End If + End Using + End Using + DbConnection.Close() + End Using + Catch ex As MySqlException + MessageBox.Show(ex.Message) + End Try + Return StringDict + End Function + Friend Function ExecuteIntegerQuery(MySqlQuery As String, ResColumnName As String) As List(Of Integer) Dim IntegerList As New List(Of Integer) Try