
Descargar


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each c As Control In Me.Controls
If TypeOf c Is NumericUpDown Then
AddHandler c.TextChanged, AddressOf NumericUpDownControls_TextChanged
End If
Next
End Sub
Private Sub NumericUpDownControls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If CType(sender, Control).Text = String.Empty Then
CType(sender, Control).Text = CType(sender, NumericUpDown).Value.ToString()
End If
End Sub
Public Function ListToDataTable(Of T)(List As System.Collections.Generic.List(Of T)) As System.Data.DataTable
Public Class MiClase
Private mId As Integer
Private mNombre As String
Private mCantidad As Integer
<System.ComponentModel.Browsable(False)> _
Public Property Id() As Integer
Get
Return mId
End Get
Set(ByVal value As Integer)
mId = value
End Set
End Property
Public Property Nombre() As String
Get
Return mNombre
End Get
Set(ByVal value As String)
mNombre = value
End Set
End Property
Public Property Cantidad() As Integer
Get
Return mCantidad
End Get
Set(ByVal value As Integer)
mCantidad = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(ByVal Id As Integer, ByVal Nombre As String, ByVal Cantidad As Integer)
mId = Id
mNombre = Nombre
mCantidad = Cantidad
End Sub
End Class

Imports System.Reflection
Imports System.ComponentModel
Imports System.Runtime.CompilerServices
Namespace System.Collections.Generic
Module ListExtension
''' <summary>
''' Gets a Datatable with all Browsable properties of T as columns containing all Items in the List.
''' </summary>
''' <typeparam name="T"></typeparam>
''' <param name="List">System.Collections.Generic.List(Of T)</param>
''' <returns>System.Data.DataTable</returns>
''' <remarks>http://aprendiendonet.blogspot.com</remarks>
<Extension()> _
Public Function ToDataTable(Of T)(ByVal List As List(Of T)) As DataTable
Dim dt As New DataTable()
Dim tipo As Type = GetType(T)
Dim members As MemberInfo() = tipo.GetMembers() ' Obtenemos todos los Miembros de la clase correspondiente al tipo T
For Each m As MemberInfo In members
If m.MemberType = MemberTypes.Property Then ' Sólo nos interesan las propiedades
Dim skip As Boolean = False
Dim atts As Object() = m.GetCustomAttributes(GetType(BrowsableAttribute), False) ' Chequeamos si tiene BrowsableAttribute
If atts.Length > 0 Then
If CType(atts(0), BrowsableAttribute).Browsable = False Then
skip = True ' Seteamos un flag para no agregar la columna
End If
End If
If Not skip Then
Dim c As DataColumn = Nothing
Try
c = New DataColumn(m.Name, CType(m, PropertyInfo).PropertyType) ' Nueva columna con el nombre de la propiedad y el tipo de la misma
Catch ex As Exception
c = New DataColumn(m.Name, GetType(String)) ' En caso de error intento crearla como String
End Try
dt.Columns.Add(c)
End If
End If
Next
For Each itm As T In List ' Recorro la lista y agrego una fila por cada item de la misma
Dim r As DataRow = dt.NewRow()
For Each c As DataColumn In r.Table.Columns
Dim aux As MemberInfo() = tipo.GetMember(c.ColumnName)
If aux.Length > 0 Then
r(c.ColumnName) = CType(aux(0), PropertyInfo).GetValue(itm, Nothing)
End If
Next
dt.Rows.Add(r)
Next
Return dt
End Function
End Module
End Namespace
Dim auxDT as DataTable = miLista.ToDataTable()

Public Sub EscribirEventLog(ByVal Origen As String, ByVal Mensaje As String, ByVal Equipo As String, ByVal TipoDeEntrada As EventTipoDeEntrada)
If Not EventLog.SourceExists(Origen, Equipo) Then ' Si el origen no existe lo creamos
EventLog.CreateEventSource(Origen, "GNSys", Equipo)
End If
Dim eLog As New EventLog("GNSys", Equipo, Origen) ' Instanciamos la clase EventLog
eLog.WriteEntry(Mensaje, TipoDeEntrada, GetSafeShort(111), GetSafeShort(1)) ' Escribimos la entrada
End Sub
eLog.WriteEntry([Event], LogEntryType, GetSafeShort(111), GetSafeShort(1))WriteEntry es la siguiente:Public Shared Sub WriteEntry(ByVal source As String, ByVal message As String, ByVal type As System.Diagnostics.EventLogEntryType, ByVal eventID As Integer, ByVal category As Short)