25/04/20 10:07
alip1
Ho costruito la seguente classe:
che provvede a cancellarmi i record nel db di riferimento che passo in una lista in quanto soddisfano certe condizioni.
Nel form in cui viene istanziata l'oggetto FD corrispondente ed agganciate i relativi eventi ha tra le altre queste routine principali:
Il tutto funziona correttamente e i record di fatto vengono cancellati e non ho alcun errore.
La sola cosa che non funziona sono gli eventi dell'oggetto:
Come mai? In una classe molto simile direi identica in quanto esattamente uguale funziona perfettamente e le uniche differenze nelle varie routine sono le chiamate del tipo:
in quanto gli serve solo l'iD per cancellare il record,
mentre nell'altra classe sono del tipo:
in quanto usa tutto il record.
Come mai il RaiseEvent non viene eseguito?. Dov'è il problema?
Grazie in anticipo a tutti per l'aiuto.
Imports System.Data.SqlClient Imports System.Data.OleDb Public Class FunDeletedLocalData Public Event ProgressDeleted(ByVal value As Integer) Public Event MaxProgressDeleted(value As Integer) Shared DataStartAppList As List(Of DataStartAppCS) Shared DataEndAppList As List(Of DataEndAppCS) Public Sub DeleteAllDataApp() Dim i As Integer = 0 '**** Preparo lista Record StartApp 'DataStartAppList = New List(Of DataStartAppCS) ReadDataStartAppFromDBLocaleForDelete() RaiseEvent MaxProgressDeleted(DataStartAppList.Count) For Each item As DataStartAppCS In DataStartAppList Try DataStartAppDB.DeleteDataStart(item.IdStartApp) Catch ex As Exception MessageBox.Show("error transfer data to Server: " & ex.ToString, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try i += 1 RaiseEvent ProgressDeleted(i) Next '**** Preparo lista Record EndApp DataEndAppList = New List(Of DataEndAppCS) ReadDataEndAppFromDBLocaleForDelete() RaiseEvent MaxProgressDeleted(i + DataEndAppList.Count) For Each item As DataEndAppCS In DataEndAppList Try DataEndAppDB.DeleteDataEnd(item.IdEndApp) Catch ex As Exception MessageBox.Show("error transfer data to Server: " & ex.ToString, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try i += 1 RaiseEvent ProgressDeleted(i) Next End Sub Public Sub DeleteOnlyDataStartApp() DataStartAppList = New List(Of DataStartAppCS) ReadDataStartAppFromDBLocaleForDelete() RaiseEvent MaxProgressDeleted(DataStartAppList.Count) Dim i As Integer = 0 For Each item As DataStartAppCS In DataStartAppList Try DataStartAppDB.DeleteDataStart(item.IdStartApp) Catch ex As Exception MessageBox.Show("error transfer data to Server: " & ex.ToString, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try i += 1 RaiseEvent ProgressDeleted(i) Next End Sub Sub DeleteOnlyDataEndApp() DataEndAppList = New List(Of DataEndAppCS) ReadDataEndAppFromDBLocaleForDelete() RaiseEvent MaxProgressDeleted(DataEndAppList.Count) Dim i As Integer = 0 For Each item As DataEndAppCS In DataEndAppList Try DataEndAppDB.DeleteDataEnd(item.IdEndApp) Catch ex As Exception MessageBox.Show("error transfer data to Server: " & ex.ToString, "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End Try i += 1 RaiseEvent ProgressDeleted(i) Next End Sub #Region "ReadDataFromDBLocaleForDelete" Public Shared Function ReadDataStartAppFromDBLocaleForDelete() As Boolean Dim stReturn As Boolean = True Try DataStartAppList = DataStartAppDB.GetDataStartListForDelete Catch ex As SqlException stReturn = False Throw ex End Try Return stReturn End Function Public Shared Function ReadDataEndAppFromDBLocaleForDelete() As Boolean Dim stReturn As Boolean = True Try DataEndAppList = DataEndAppDB.GetDataEndListForDelete Catch ex As SqlException stReturn = False Throw ex End Try Return stReturn End Function #End Region Sub New() End Sub End Class
che provvede a cancellarmi i record nel db di riferimento che passo in una lista in quanto soddisfano certe condizioni.
Nel form in cui viene istanziata l'oggetto FD corrispondente ed agganciate i relativi eventi ha tra le altre queste routine principali:
Public Class frmDeleteDatiLocali Private WithEvents FD As FunDeletedLocalData Private Sub btnAccept_Click(sender As Object, e As EventArgs) Handles btnAccept.Click btnClose.Enabled = False btnAccept.Enabled = False Me.lblRecDeleted.Visible = True Me.prgBar.Visible = True Me.Refresh() Dim FD = New FunDeletedLocalData If rdTDAll.Checked Then FD.DeleteAllDataApp() ElseIf rdStartApp.Checked Then FD.DeleteOnlyDataStartApp() ElseIf rdEndApp.Checked Then FD.DeleteOnlyDataEndApp() End If FD = Nothing btnAccept.Enabled = True btnClose.Enabled = True Me.prgBar.Visible = False End Sub Private Sub FD_ProgressDeleted(value As Integer) Handles FD.ProgressDeleted Me.prgBar.Maximum = value End Sub Private Sub FD_MaxProgressDeleted(value As Integer) Handles FD.MaxProgressDeleted Me.lblRecDeleted.Text = "Record Cancellati: " & value.ToString Me.prgBar.PerformStep() Me.Refresh() End Sub
Il tutto funziona correttamente e i record di fatto vengono cancellati e non ho alcun errore.
La sola cosa che non funziona sono gli eventi dell'oggetto:
RaiseEvent MaxProgressDeleted(DataEndAppList.Count) RaiseEvent ProgressDeleted(i)
Come mai? In una classe molto simile direi identica in quanto esattamente uguale funziona perfettamente e le uniche differenze nelle varie routine sono le chiamate del tipo:
DataEndAppDB.DeleteDataEnd(item.IdEndApp)
in quanto gli serve solo l'iD per cancellare il record,
mentre nell'altra classe sono del tipo:
DataEndAppSQLDB.AddEndApp(item)
in quanto usa tutto il record.
Come mai il RaiseEvent non viene eseguito?. Dov'è il problema?
Grazie in anticipo a tutti per l'aiuto.
Ultima modifica effettuata da alip1 25/04/20 10:11
aaa