Public Class myinfo
Public Shared ReadOnly Property NombreEnsambladoA() As String
Get
Return My.Application.Info.AssemblyName & "."
End Get
End Property
Public Shared ReadOnly Property NombreEnsambladoB() As String
Get
Return My.Application.Info.ProductName & "."
End Get
End Property
End Class
Public Class crdFHandler
Class Formularios
Private Structure AssUti
Dim MiEnsamblado As System.Reflection.Assembly
Dim TipoD As Type
Dim TipoL As Type
End Structure
Private _AU As AssUti
Private _FL As FList
Private _FD As FDetail
Public MustInherit Class MasterForm
Protected WithEvents _F As Form
Protected _MiTipo As Type
Public Overridable Sub Mostrar()
If _F Is Nothing Or _F.IsDisposed = True Then
_F = Me.NuevaInstanciaDeMiTipo
Else
_F.BringToFront()
End If
_F.Show()
End Sub
Private Function NuevaInstanciaDeMiTipo() As Form
Return Activator.CreateInstance(_MiTipo)
End Function
End Class
Public Class FDetail : Inherits MasterForm
Sub New(ByVal FormDetail As Object, ByVal MiTipo As Type)
Me._F = DirectCast(FormDetail, Form)
Me._MiTipo = MiTipo
End Sub
End Class
Public Class FList : Inherits MasterForm
Sub New(ByVal FormList As Object, ByVal MiTipo As Type)
Me._F = DirectCast(FormList, Form)
Me._MiTipo = MiTipo
End Sub
End Class
Private Sub Inicializar()
_AU.MiEnsamblado = System.Reflection.Assembly.GetExecutingAssembly
End Sub
Sub New(ByVal NombreClaseL As String, ByVal NombreClaseD As String)
Me.Inicializar()
_AU.TipoD = _AU.MiEnsamblado.GetType(NombreClaseD)
_AU.TipoL = _AU.MiEnsamblado.GetType(NombreClaseL)
_FL = New FList(Activator.CreateInstance(_AU.TipoL), _AU.TipoL)
_FD = New FDetail(Activator.CreateInstance(_AU.TipoD), _AU.TipoD)
End Sub
Public ReadOnly Property FormularioDetalle() As FDetail
Get
Return _FD
End Get
End Property
Public ReadOnly Property FormularioLista() As FList
Get
Return _FL
End Get
End Property
End Class
Private _MyAss As System.Reflection.Assembly
Private _FClasses() As Type
Private _htFormularios As Hashtable
Sub New()
Call Me.ListarClasesDelEnsamblado()
_htFormularios = New Hashtable
End Sub
Private Sub ListarClasesDelEnsamblado()
Dim Counter As Integer
_MyAss = System.Reflection.Assembly.GetExecutingAssembly
For Each T As Type In _MyAss.GetTypes
ReDim Preserve _FClasses(Counter)
_FClasses(Counter) = T
Counter += 1
Next
End Sub
Public Function AgregarFormularios(ByVal Clave As String, ByVal NombreFormList As String, ByVal NombreFormDetail As String) As Boolean
Try
If _htFormularios(Clave) Is Nothing Then
If EsFormulario(NombreFormDetail) And EsFormulario(NombreFormList) Then
_htFormularios.Add(Clave, New Formularios(NombreFormList, NombreFormDetail))
Else
Throw New Exception("Parametro Pasado No es un Formulario")
End If
Return True
Else
Throw New Exception("Ya existe la clave '" & Clave & "' en la lista")
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Function
Public ReadOnly Property GetFormularios(ByVal Clave As String) As Formularios
Get
Try
If _htFormularios(Clave) Is Nothing Then
Throw New Exception("Clave '" & Clave & "' no existe o no apunta a ningún valor")
Else
Return _htFormularios(Clave)
End If
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Get
End Property
Private Function EsFormulario(ByVal NombreClase As String) As Boolean
Try
Dim T As Type = _MyAss.GetType(NombreClase), oTest As Object
oTest = Activator.CreateInstance(T)
If TypeOf oTest Is Form Then
Return True
Else
Return False
End If
Catch ex As Exception
Debug.Print(ex.Message)
Return False
End Try
End Function
End Class