08237de2d8
- In UpdateLicencePage viene mostrato il nome del Prodotto della Licenza che si sta aggiornando - Ogni pulsante "Close" fa ritornare alla pagina precedente (Correzione simile per i vari pulsanti Update e New, mentre Delete rimane nella stessa pagina) - Correzione pulsanti del Main Menu (non hanno più la scritta "Cerca...") - I DataGrid non tagliano più l'ultima riga visibile ma si aggiustano in base al numero intero di righe visibili (implementato per tutte le pagine Search tranne che per Product per via di errori che non riesco a risolvere
390 lines
12 KiB
VB.net
390 lines
12 KiB
VB.net
Imports System.Collections.ObjectModel
|
|
Imports System.Windows.Forms
|
|
Imports EgtWPFLib5
|
|
Imports MySql.Data.MySqlClient
|
|
|
|
Public Class SearchProductPageVM
|
|
Inherits VMBase
|
|
|
|
#Region "FIELDS & PROPERTIES"
|
|
|
|
Private m_SelSearchResult As Product
|
|
Public Property SelSearchResult As Product
|
|
Get
|
|
Return m_SelSearchResult
|
|
End Get
|
|
Set(value As Product)
|
|
m_SelSearchResult = value
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProductNameList As List(Of String)
|
|
Public ReadOnly Property ProductNameList As List(Of String)
|
|
Get
|
|
Return m_ProductNameList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelProductName As String
|
|
Public Property SelProductName As String
|
|
Get
|
|
Return m_SelProductName
|
|
End Get
|
|
Set(value As String)
|
|
m_SelProductName = value
|
|
NotifyPropertyChanged("SelProductName")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProductNumberList As List(Of String)
|
|
Public ReadOnly Property ProductNumberList As List(Of String)
|
|
Get
|
|
Return m_ProductNumberList
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelProductNumber As String
|
|
Public Property SelProductNumber As String
|
|
Get
|
|
Return m_SelProductNumber
|
|
End Get
|
|
Set(value As String)
|
|
m_SelProductNumber = value
|
|
NotifyPropertyChanged("SelProductNumber")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProductOption1List As List(Of String)
|
|
Public ReadOnly Property ProductOption1List As List(Of String)
|
|
Get
|
|
Return m_ProductOption1List
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelProductOption1 As String
|
|
Public Property SelProductOption1 As String
|
|
Get
|
|
Return m_SelProductOption1
|
|
End Get
|
|
Set(value As String)
|
|
m_SelProductOption1 = value
|
|
NotifyPropertyChanged("SelProductOption1")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_ProductOption2List As List(Of String)
|
|
Public ReadOnly Property ProductOption2List As List(Of String)
|
|
Get
|
|
Return m_ProductOption2List
|
|
End Get
|
|
End Property
|
|
|
|
Private m_SelProductOption2 As String
|
|
Public Property SelProductOption2 As String
|
|
Get
|
|
Return m_SelProductOption2
|
|
End Get
|
|
Set(value As String)
|
|
m_SelProductOption2 = value
|
|
NotifyPropertyChanged("SelProductOption2")
|
|
End Set
|
|
End Property
|
|
|
|
Private m_SearchResult As ObservableCollection(Of Product)
|
|
Public ReadOnly Property SearchResult As ObservableCollection(Of Product)
|
|
Get
|
|
Return m_SearchResult
|
|
End Get
|
|
End Property
|
|
|
|
' Definizione comandi
|
|
Private m_cmdNewProduct As Command
|
|
Private m_cmdSearch As Command
|
|
Private m_cmdCancel As Command
|
|
Private m_cmdUpdate As Command
|
|
Private m_cmdDelete As Command
|
|
|
|
#Region "Messages"
|
|
|
|
Public ReadOnly Property SearchProductMsg As String
|
|
Get
|
|
Return "Search product"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property NewMsg As String
|
|
Get
|
|
Return "New"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProductNameMsg As String
|
|
Get
|
|
Return "Name"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProductNumberMsg As String
|
|
Get
|
|
Return "Number"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProductOption1Msg As String
|
|
Get
|
|
Return "Option 1"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property ProductOption2Msg As String
|
|
Get
|
|
Return "Option 2"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property SearchMsg As String
|
|
Get
|
|
Return "Search"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property CancelMsg As String
|
|
Get
|
|
Return "Close"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property UpdateMsg As String
|
|
Get
|
|
Return "Update"
|
|
End Get
|
|
End Property
|
|
|
|
Public ReadOnly Property DeleteMsg As String
|
|
Get
|
|
Return "Delete"
|
|
End Get
|
|
End Property
|
|
|
|
#End Region ' Messages
|
|
|
|
#End Region ' FIELDS & PROPERTIES
|
|
|
|
#Region "CONSTRUCTOR"
|
|
|
|
Sub New()
|
|
' Imposto riferimento nella mappa
|
|
Map.SetRefSearchProductPageVM(Me)
|
|
End Sub
|
|
|
|
#End Region ' CONSTRUCTOR
|
|
|
|
#Region "METHODS"
|
|
|
|
Friend Sub InitSearchProductPage()
|
|
' Svuoto campi
|
|
SelProductName = Nothing
|
|
NotifyPropertyChanged("SelProductName")
|
|
SelProductNumber = Nothing
|
|
NotifyPropertyChanged("SelProductNumber")
|
|
SelProductOption1 = Nothing
|
|
NotifyPropertyChanged("SelProductOption1")
|
|
SelProductOption2 = Nothing
|
|
NotifyPropertyChanged("SelProductOption2")
|
|
|
|
' Carico lista ProductName
|
|
Dim Query As String
|
|
Query = "SELECT " & DB_PRODUCTNAME & " FROM " & DB_PRODUCT
|
|
m_ProductNameList = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTNAME)
|
|
NotifyPropertyChanged("ProductNameList")
|
|
|
|
' Carico lista ProductNumber
|
|
Query = "SELECT " & DB_PRODUCTNUMBER & " FROM " & DB_PRODUCT & " GROUP BY " & DB_PRODUCTNUMBER
|
|
m_ProductNumberList = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTNUMBER)
|
|
m_ProductNumberList.Sort(Function(x, y) CInt(y).CompareTo(CInt(x)))
|
|
NotifyPropertyChanged("ProductNumberList")
|
|
|
|
' Carico lista ProductOption1
|
|
Query = "SELECT " & DB_PRODUCTOPTION1 & " FROM " & DB_PRODUCT & " GROUP BY " & DB_PRODUCTOPTION1
|
|
m_ProductOption1List = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTOPTION1)
|
|
m_ProductOption1List.Sort(Function(x, y) CInt(y).CompareTo(CInt(x)))
|
|
NotifyPropertyChanged("ProductOption1List")
|
|
|
|
' Carico lista ProductOption2
|
|
Query = "SELECT " & DB_PRODUCTOPTION2 & " FROM " & DB_PRODUCT & " GROUP BY " & DB_PRODUCTOPTION2
|
|
m_ProductOption2List = ManageDb.ExecuteStringQuery(Query, DB_PRODUCTOPTION2)
|
|
m_ProductOption2List.Sort(Function(x, y) CInt(y).CompareTo(CInt(x)))
|
|
NotifyPropertyChanged("ProductOption2List")
|
|
|
|
' m_SearchResult = New ObservableCollection(Of Product)()
|
|
Dim ProdQuery As String = "SELECT * FROM " & DB_PRODUCT & " "
|
|
m_SearchResult = New ObservableCollection(Of Product)(ManageDb.ExecuteSearchProductQuery(ProdQuery))
|
|
NotifyPropertyChanged("SearchResult")
|
|
End Sub
|
|
|
|
#End Region ' METHODS
|
|
|
|
#Region "COMMANDS"
|
|
|
|
#Region "NewProduct"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property NewProduct_Command As ICommand
|
|
Get
|
|
If m_cmdNewProduct Is Nothing Then
|
|
m_cmdNewProduct = New Command(AddressOf NewProduct)
|
|
End If
|
|
Return m_cmdNewProduct
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub NewProduct(ByVal param As Object)
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.NEWPRODUCT
|
|
|
|
End Sub
|
|
|
|
#End Region ' NewProduct
|
|
|
|
#Region "Search"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property SearchProduct_Command As ICommand
|
|
Get
|
|
If m_cmdSearch Is Nothing Then
|
|
m_cmdSearch = New Command(AddressOf Search)
|
|
End If
|
|
Return m_cmdSearch
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Search(ByVal param As Object)
|
|
' Cerco nella tabella Client
|
|
Dim Query As String = "SELECT * FROM " & DB_PRODUCT & " "
|
|
Dim bFirstWhere As Boolean = True
|
|
If Not String.IsNullOrWhiteSpace(SelProductName) OrElse
|
|
Not IsNothing(SelProductNumber) OrElse
|
|
Not IsNothing(SelProductOption1) OrElse
|
|
Not IsNothing(SelProductOption2) Then
|
|
Query &= "WHERE "
|
|
If Not String.IsNullOrWhiteSpace(SelProductName) Then
|
|
EvalWhere(bFirstWhere, Query)
|
|
Query &= DB_PRODUCTNAME & " LIKE '" & m_SelProductName & "' "
|
|
End If
|
|
If Not IsNothing(SelProductNumber) Then
|
|
EvalWhere(bFirstWhere, Query)
|
|
Query &= DB_PRODUCTNUMBER & " LIKE '" & m_SelProductNumber & "' "
|
|
End If
|
|
If Not IsNothing(SelProductOption1) Then
|
|
EvalWhere(bFirstWhere, Query)
|
|
Query &= DB_PRODUCTOPTION1 & " LIKE '" & m_SelProductOption1 & "' "
|
|
End If
|
|
If Not IsNothing(SelProductOption2) Then
|
|
EvalWhere(bFirstWhere, Query)
|
|
Query &= DB_PRODUCTOPTION2 & " LIKE '" & m_SelProductOption2 & "' "
|
|
End If
|
|
Query = Query.TrimEnd(","c, " "c)
|
|
End If
|
|
m_SearchResult = New ObservableCollection(Of Product)(ManageDb.ExecuteSearchProductQuery(Query))
|
|
If (m_SearchResult.Count = 0) Then
|
|
MessageBox.Show("Nessun risultato per i filtri impostati")
|
|
End If
|
|
NotifyPropertyChanged("SearchResult")
|
|
End Sub
|
|
|
|
Private Sub EvalWhere(ByRef bFirst As Boolean, ByRef Query As String)
|
|
If bFirst Then
|
|
bFirst = False
|
|
Else
|
|
Query &= " AND "
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' Search
|
|
|
|
#Region "Cancel"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property Cancel_Command As ICommand
|
|
Get
|
|
If m_cmdCancel Is Nothing Then
|
|
m_cmdCancel = New Command(AddressOf Cancel)
|
|
End If
|
|
Return m_cmdCancel
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Cancel(ByVal param As Object)
|
|
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.MAINMENU
|
|
|
|
End Sub
|
|
|
|
#End Region ' Cancel
|
|
|
|
#Region "Update"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property UpdateProduct_Command As ICommand
|
|
Get
|
|
If m_cmdUpdate Is Nothing Then
|
|
m_cmdUpdate = New Command(AddressOf Update)
|
|
End If
|
|
Return m_cmdUpdate
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Update(ByVal param As Object)
|
|
If Not IsNothing(m_SelSearchResult) Then
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
Map.refUpdateProductPageVM.Product = m_SelSearchResult
|
|
Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.UPDATEPRODUCT
|
|
Else
|
|
MessageBox.Show("Non è stato selezionato nessun prodotto")
|
|
End If
|
|
|
|
End Sub
|
|
|
|
#End Region ' Update
|
|
|
|
#Region "Delete"
|
|
|
|
' Returns a command that manage the MainWindow_Unloaded command
|
|
Public ReadOnly Property DeleteProduct_Command As ICommand
|
|
Get
|
|
If m_cmdDelete Is Nothing Then
|
|
m_cmdDelete = New Command(AddressOf Delete)
|
|
End If
|
|
Return m_cmdDelete
|
|
End Get
|
|
End Property
|
|
|
|
Public Sub Delete(ByVal param As Object)
|
|
If Not IsNothing(m_SelSearchResult) Then
|
|
' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded.
|
|
If MessageBox.Show("Do you really want to delete this Product?", "Delete", MessageBoxButtons.YesNo) = DialogResult.No Then
|
|
MsgBox("Operation cancelled")
|
|
Exit Sub
|
|
End If
|
|
' Cerco nella tabella Product
|
|
Dim Query As String = "DELETE FROM " & DB_PRODUCT & " WHERE " & DB_PRODUCTID & " = " & m_SelSearchResult.ProductID
|
|
Dim Result As Integer = ExecuteQuery(Query)
|
|
If Result <> 0 Then
|
|
MsgBox("Operation executed")
|
|
End If
|
|
' Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.MAINMENU
|
|
Search(param)
|
|
Else
|
|
MessageBox.Show("Non è stato selezionato nessun prodotto")
|
|
End If
|
|
End Sub
|
|
|
|
#End Region ' Delete
|
|
|
|
#End Region ' COMMANDS
|
|
|
|
End Class
|
|
|