Imports EgtWPFLib5 Public Class NewClientPageVM Inherits ClientPageVM #Region "FIELDS & PROPERTIES" Private Shadows m_Name As String Public Overloads Property Name As String Get Return m_Name End Get Set(value As String) If Not String.IsNullOrWhiteSpace(value) Then ' Verifico se valore inserito già esistente Dim Query As String = "SELECT COUNT(" & DB_NAME & ") AS " & DB_MAXNUMBER & " FROM " & DB_CLIENT & " WHERE " & DB_NAME & " = '" & value & "'" ' COLLATE NOCASE" If ExecuteNumberQuery(Query) = 0 Then m_Name = value Else MessageBox.Show("Il cliente inserito esiste già!!") End If End If NotifyPropertyChanged("Name") End Set End Property Private m_ResellerList As List(Of Reseller) Public Overloads ReadOnly Property ResellerList As List(Of Reseller) Get Return m_ResellerList End Get End Property Private m_SelReseller As Reseller Public Overloads Property SelReseller As Reseller Get Return m_SelReseller End Get Set(value As Reseller) m_SelReseller = value NotifyPropertyChanged("SelReseller") End Set End Property Private m_Email As String Public Overloads Property Email As String Get Return m_Email End Get Set(value As String) m_Email = value NotifyPropertyChanged("Email") End Set End Property ' Definizione comandi Private m_cmdAddClient As Command Private m_cmdCancel As Command #Region "Messages" Public ReadOnly Property NewClientMsg As String Get Return "New client" End Get End Property Public ReadOnly Property AddMsg As String Get Return "Add" End Get End Property Public ReadOnly Property CancelMsg As String Get Return "Close" End Get End Property #End Region ' Messages #End Region ' FIELDS & PROPERTIES #Region "METHODS" Friend Sub InitNewClientPage() ' Svuoto campi m_Name = String.Empty NotifyPropertyChanged("Name") m_Email = String.Empty NotifyPropertyChanged("Email") ' Carico lista Reseller Dim Query As String = "SELECT * FROM " & DB_RESELLER m_ResellerList = ManageDb.ExecuteResellerQuery(Query) NotifyPropertyChanged("ResellerList") End Sub #End Region ' METHODS #Region "CONSTRUCTOR" Sub New() ' Imposto riferimento nella mappa Map.SetRefNewClientPageVM(Me) End Sub #End Region ' CONSTRUCTOR #Region "COMMANDS" #Region "AddClient" ' Returns a command that manage the MainWindow_Unloaded command Public ReadOnly Property AddClient_Command As ICommand Get If m_cmdAddClient Is Nothing Then m_cmdAddClient = New Command(AddressOf AddClient) End If Return m_cmdAddClient End Get End Property Public Sub AddClient(ByVal param As Object) If Not String.IsNullOrWhiteSpace(Name) And Not String.IsNullOrWhiteSpace(Email) And Not IsNothing(SelReseller) Then ' Aggiungo un rivenditore al Db Dim Query As String = "INSERT INTO " & DB_CLIENT & " (" & DB_NAME & ", " & DB_RESELLERID & ", " & DB_EMAIL & ")" & " VALUES ('" & Trim(m_Name) & "', " & "'" & SelReseller.ResellerID & "', " & "'" & m_Email & "')" ManageDb.ExecuteQuery(Query) ' Manage the MainWindow_Unloaded event. This method is invoked by the cmdMainWindow_Unloaded. Map.refMainWindowVM.SelProjectMode = MainWindowVM.ProjectModeOpt.SEARCHCLIENT Else MessageBox.Show("Completare tutti i campi presenti") End If End Sub #End Region ' AddClient #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.SEARCHCLIENT End Sub #End Region ' Cancel #End Region ' COMMANDS End Class