Torna al Thread
Imports System.IO
Imports As400Utils
Public Class FormMain
Public Shared sConnString As String = ""
Public imgList16x16 As ImageList
Public imgList64x64 As ImageList
Public sPathAcrobat As String
Public unitaMappata As String
Public iPrimoProgrLibero As Integer
Public hashFilePC As Hashtable
Public hashFileIomega As Hashtable
Public hashFileFiltro As Hashtable
Public arrCRC32Iomega As System.Collections.ObjectModel.Collection(Of String)
Public arrCRC32PC As System.Collections.ObjectModel.Collection(Of String)
Public listaTipoTrasf As List(Of TipoTrasferimento)
Public Shared dsParams As DataSet
Public Sub Init()
Me.WindowState = FormWindowState.Maximized
dsParams = New DataSet
dsParams.ReadXml(Application.StartupPath + "\Parametri.xml")
''File "civetta" la cui presenza indica che è stato affettuato l'Upgrade...
'If Not System.IO.File.Exists(Application.StartupPath & "Updated.civ") Then
' '...se invece manca...Aggiorna
' AutoUpdate()
'End If
labelTitoloPC.BackColor = Color.Blue
labelTitoloPC.ForeColor = Color.White
labelTitoloIomega.BackColor = Color.Green
labelTitoloIomega.ForeColor = Color.White
textFiltro.Visible = False
textFiltro.Font = New Font("Verdana", 14)
hashFilePC = New Hashtable
hashFileIomega = New Hashtable
arrCRC32Iomega = New System.Collections.ObjectModel.Collection(Of String)
arrCRC32PC = New System.Collections.ObjectModel.Collection(Of String)
gridPC_CurrentCellChanged(Nothing, Nothing)
End Sub
Public Sub AddFileToGrid(ByVal _file As FilePdf, ByVal _grid As DataGridView)
Dim sNome As String = Path.GetFileName(_file.PathFile & "\" & _file.NomeFile)
_grid.Rows.Add(New DataGridViewRow)
Dim i As Integer = _grid.Rows.Count - 1
_grid.Rows(i).Cells("colFile").Value = sNome
If _grid.Name = "gridIomega" Then
'Aggiungo riga a GridIomega
Dim cella As DataGridViewButtonCell = _grid.Rows(i).Cells("colPulsante")
cella.UseColumnTextForButtonValue = False
Dim sData As String = (Format(_file.DataCreazione, "dd/MM/yyyy HH.mm")).ToString
_grid.Rows(i).Cells("colData").Value = sData
Dim stile As New DataGridViewCellStyle
If _file.Commento = "" Then
stile.BackColor = Color.Red
_grid.Rows(i).Cells("colNota").Style = stile
cella.Value = ""
Else
stile.BackColor = Color.GreenYellow
_grid.Rows(i).Cells("colNota").Style = stile
cella.Value = "nota"
End If
If Not _file.TipoTrasferimento Is Nothing Then
Dim cellaTipoUpload As DataGridViewCell = _grid.Rows(i).Cells("coltipoTrasf")
cellaTipoUpload.Value = _file.TipoTrasferimento.Descrizione
End If
Else
'Aggiungo riga a GridPc
Try
Dim cella As DataGridViewComboBoxCell = _grid.Rows(i).Cells("colCombo")
cella.DataSource = listaTipoTrasf
cella.DisplayMember = "Descrizione"
cella.ValueMember = "Id"
Catch ex As Exception
MessageBox.Show(ex.Message, "ATTENZIONE...")
MessageBox.Show(ex.StackTrace, "ATTENZIONE...")
End Try
End If
End Sub
Public Function GetObjFilePdf(ByVal riga As DataRow) As FilePdf
Dim f As New FilePdf
f.Id = Integer.Parse(riga(0))
f.PartitaIva = riga(1)
f.PathFile = unitaMappata & ":\"
f.NomeFile = riga(2)
'commenti.commento
If riga(3) Is DBNull.Value Then
f.Commento = ""
Else
f.Commento = riga(3)
End If
f.CRC32 = GetCRC32(f.PathFile & f.NomeFile)
f.DataCreazione = riga(4)
f.DataModifica = riga(5)
'commenti.utente
If IsDBNull(riga(8)) Then
f.Utente = ""
Else
f.Utente = riga(8)
End If
'commenti.id_tipo_trasferimento
If Not IsDBNull(riga(9)) Then
'Ha oggetto figlio (tipo_trasferimento)
Dim tt As New TipoTrasferimento
tt.Id = riga(9)
tt.Codice = riga(11)
tt.Descrizione = riga(12)
f.IdTipoTrasferimento = tt.Id
f.TipoTrasferimento = tt
End If
Return f
End Function
Public Sub InitProgrBar(ByVal bShow As Boolean, Optional ByVal sTesto As String = "", Optional ByVal iMin As Integer = 0, Optional ByVal iMax As Integer = 0)
labelProgressBar.Visible = bShow
labelProgressBar.Text = sTesto
prbar.Visible = bShow
prbar.Minimum = iMin
prbar.Maximum = iMax
End Sub
Public Sub FillListaIomega(Optional ByVal _sqry As String = "")
Dim sQry As String = ""
If _sqry = "" Then
sQry = "SELECT * " & _
"FROM commenti as c LEFT JOIN tipo_trasferimento as tt ON (c.id_tipo_trasferimento = tt.id) " & _
"WHERE p_iva = '" & My.Application.CommandLineArgs(0) & "' ORDER BY nome_file"
Else
sQry = _sqry
End If
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & unitaMappata & ":\CommentiCGINFP.mdb"
Dim da As OleDb.OleDbDataAdapter = QueryUtils.QuerySelect(sQry, sConnString)
Dim dt As New DataTable("Commenti")
da.Fill(dt)
InitProgrBar(True, "Inizializzazione in corso...", 0, dt.Rows.Count)
iPrimoProgrLibero = 0
For Each riga As DataRow In dt.Rows
Dim f As FilePdf = GetObjFilePdf(riga)
'Popolo la lista Iomega
hashFileIomega.Add(gridIomega.Rows.Count, f)
AddFileToGrid(f, gridIomega)
arrCRC32Iomega.Add(f.CRC32)
Dim sFile As String = f.PathFile & f.NomeFile
Dim sProgr As String = sFile.Substring(20).Substring(0, sFile.Substring(20).LastIndexOf("."))
If Integer.Parse(sProgr) > iPrimoProgrLibero Then
iPrimoProgrLibero = Integer.Parse(sProgr)
End If
prbar.Increment(1)
Next
iPrimoProgrLibero += 1
InitProgrBar(False)
End Sub
Public Function GetObjTipoTrasferimento(ByVal riga As DataRow) As TipoTrasferimento
Dim tt As New TipoTrasferimento
tt.Id = riga(0)
tt.Codice = riga(1)
tt.Descrizione = riga(2)
tt.Predefinito = riga(3)
Return tt
End Function
Public Function GetCRC32(ByVal sFileName As String) As String
Try
Dim FS As FileStream = New FileStream(sFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
Dim CRC32Result As Integer = &HFFFFFFFF
Dim Buffer(4096) As Byte
Dim ReadSize As Integer = 4096
Dim Count As Integer = FS.Read(Buffer, 0, ReadSize)
Dim CRC32Table(256) As Integer
Dim DWPolynomial As Integer = &HEDB88320
Dim DWCRC As Integer
Dim i As Integer, j As Integer, n As Integer
'Create CRC32 Table
For i = 0 To 255
DWCRC = i
For j = 8 To 1 Step -1
If (DWCRC And 1) Then
DWCRC = ((DWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
DWCRC = DWCRC Xor DWPolynomial
Else
DWCRC = ((DWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
End If
Next j
CRC32Table(i) = DWCRC
Next i
'Calcualting CRC32 Hash
Do While (Count > 0)
For i = 0 To Count - 1
n = (CRC32Result And &HFF) Xor Buffer(i)
CRC32Result = ((CRC32Result And &HFFFFFF00) \ &H100) And &HFFFFFF
CRC32Result = CRC32Result Xor CRC32Table(n)
Next i
Count = FS.Read(Buffer, 0, ReadSize)
Loop
Return Hex(Not (CRC32Result))
Catch ex As Exception
MessageBox.Show(ex.Message, ex.StackTrace)
Return ""
End Try
End Function
End Class