sexta-feira, 31 de agosto de 2012

Compare files by Properties


Imports System.IO

Public Class CompareFiles

Dim filepath1 As String = "FilePath1"
Dim filepath2 As String = "FilePath2"

Private Function Ficheiro(ByVal file1 As String, ByVal file2 As String) As Boolean

  Dim ficheiro1 As New FileInfo(file1)
  Dim ficheiro2 As New FileInfo(file2)

'File 1 properties 
 Dim Size1 As Long = ficheiro1.Length
  Dim nome1 As String = ficheiro1.Name
  Dim dateFile1 As Date = ficheiro1.LastWriteTime

'File 2 properties 
 Dim Size2 As Long = ficheiro2.Length
  Dim nome2 As String = ficheiro1.Name
  Dim dateFile2 As Date = ficheiro2.LastWriteTime

'1 Use 
 If (Size1 = Size2) And (nome1 = nome2) Then 
   Ficheiro = True 
Else   
  Ficheiro = False 
 End If
''2 Another Use Compare by datediference'
'If DateDiff("s", dateFile1, dateFile2) = 0 Then
' Ficheiro = True
'Else
' Ficheiro = False
'End If
  Return Ficheiro

End Function
'Using ther function
Public Sub UseCompare()
'Check If files exists
  If File.Exists(filepath1) And File.Exists(filepath2) Then
      If Ficheiro(filepath1, filepath2) = True Then   
     'Something = Matches ...    
  Else       
 'Nothing  
    End If 
 Else   
  'One or another file missing
  End If
End Sub

End Class


segunda-feira, 6 de agosto de 2012

LINQ to DATASET (DataTable)


Use LINQ to conect to datatable rows

Dim srvcon as new sqlconnection("connection string")

Dim queryBOLETIN , estado As String
queryBOLETIN = "SELECT * FROM SMS_ENVIAR order by ID DESC"
estado = "ENVIADO"


Dim adaptBOLETIN As New SqlDataAdapter(queryBOLETIN, srvcon)<br />
Dim dsBOLETIN As New DataSetadaptBOLETIN.Fill(dsBOLETIN)<br />
<br /><br />
Dim dtBOLETIN As DataTable = dsBOLETIN.Tables(0)  <br />
Dim boletin = (From B In dtBOLETIN.AsEnumerable() _<br />
               Take (10) _<br />
        Where B.Field(Of String)("ESTADO").Equal(estado).ToString_<br />
               Select New With   <br />                
                         {<br />
                    .NºProcesso = B.Field(
Of Int64)("DOPID"),<br />
                                                .NºTubo = B.Field(Of String)("DOPNTUBO"),<br />
                                              .DataEnvio = B.Field(Of DateTime)("DATAENVIO"),      <br />
                                               .Estado = B.Field(Of String)("TIPOENVIO"),   <br />
                                              .Email = B.Field(Of String)("DESTINO")       <br />
             })<br />
 If boletin.Count > 0 Then   <br />
  Dim bs As New BindingSource() <br />
    bs.DataSource = boletin<br />
     grid_smsEnviadas.DataSource = bs<br />

Else   <br />
  grid_smsEnviadas.DataSource = Nothing <br />
    grid_smsEnviadas.Refresh()<br />
End If<br />