Public Class Form1
Public ValoreCellaClick As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
'Carica Nomi Colonne
CaricaDatiColonne()
'Popola la Tabella di Dati di tutti i file che contiene la cartella c:\test_ocr
CaricaTabellaFile("c:\test_ocr")
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
Private Sub CaricaTabellaFile(ByVal FolderPercorso As String)
Try
Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(FolderPercorso)
Dim file As System.IO.FileInfo
Dim i As Integer = 0
Dim data As String
Dim ora As String
For Each file In dir.GetFiles
Dim MyFile As String = file.FullName.ToString
Dim MyDSO As DSOFile.OleDocumentProperties
MyDSO = New DSOFile.OleDocumentProperties
MyDSO.Open(MyFile, True, DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess)
data = file.CreationTimeUtc.ToString("dd/MM/yyyy")
ora = file.CreationTimeUtc.ToString("T")
'ID, Nome File, Percorso, Estemzione, Data Creazione, Grandezza File, Titolo, Autore, Oggetto, Commenti
AggiungiRow(False, i, file.Name.ToString, file.FullName.ToString, _
file.Extension.ToString, _
data, _
ora, _
file.Length.ToString + " KB", _
MyDSO.SummaryProperties.Company, _
MyDSO.SummaryProperties.Title, _
MyDSO.SummaryProperties.Author, _
MyDSO.SummaryProperties.Subject, _
MyDSO.SummaryProperties.Comments)
MyDSO.Close()
i = i + 1
'Stampare nela Console tutti i dati che ci possono servire
'Console.WriteLine("Autore : " & MyDSO.SummaryProperties.Author)
'Console.WriteLine("Commento : " & MyDSO.SummaryProperties.Comments)
'Console.WriteLine("Titolo : " & MyDSO.SummaryProperties.Title)
'Console.WriteLine("Oggetto : " & MyDSO.SummaryProperties.Subject)
'Console.WriteLine("Documento Condiviso : " & MyDSO.SummaryProperties.SharedDocument)
'Console.WriteLine("Revisione File : " & MyDSO.SummaryProperties.RevisionNumber)
'Console.WriteLine("Applicazione Nome : " & MyDSO.SummaryProperties.ApplicationName)
'Console.WriteLine("Nome File : " & file.Name.ToString)
'Console.WriteLine("Creato il : " & file.CreationTime.ToString)
'Console.WriteLine("Grandezza File KB : " & file.Length.ToString)
Next
Catch ex As Exception
MsgBox(ex)
End Try
End Sub
Private Sub CaricaDatiColonne()
AddCheckBoxColumn("Seleziona")
AddCol("ID")
AddCol("Nome File")
AddCol("Percorso")
CreaImgCollon("Estenzione")
AddCol("Data")
AddCol("Ora")
AddCol("Grandezza File ")
AddCol("Società")
AddCol("Titolo")
AddCol("Autore")
AddCol("Oggetto")
AddCol("Commenti")
'Sparisce l'ultimo record vuoto per aggiungere i record nuovi
DataGridView1.AllowUserToAddRows = False
'Autoridimensiona le celle
DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
'Autoridimensiona le righe
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
'MultiSelect non possibile
DataGridView1.MultiSelect = False
'Aggiorna la griglia
DataGridView1.Refresh()
End Sub
Private Sub AggiungiRow(ByVal pVal As Boolean, ByVal pID As Object, ByVal pNameFile As Object, ByVal pPercorso As Object _
, ByVal pEstenzione As Object, ByVal pData As Object, ByVal pOra As Object _
, ByVal pGrandezzaFile As Object, ByVal pSocieta As Object, ByVal pTitolo As Object _
, ByVal pAutore As Object, ByVal pOggetto As Object, ByVal pCommenti As Object)
Dim iconColumn As New DataGridViewImageColumn()
iconColumn = CaricaImgFile(pEstenzione)
Dim dgv As New DataGridViewRow()
'Compilo la riga
dgv.CreateCells(DataGridView1, New Object() {pVal, pID, pNameFile, pPercorso, iconColumn.Image, pData, pOra, pGrandezzaFile, pSocieta, pTitolo, pAutore, pOggetto, pCommenti})
'Aggiunta riga
DataGridView1.Rows.Add(dgv)
End Sub
Private Function CaricaImgFile(ByVal Estenzione As String) As DataGridViewImageColumn
Dim treeIcon As Icon
CaricaImgFile = New DataGridViewImageColumn
Select Case Estenzione
Case ".tif"
treeIcon = New Icon(Application.StartupPath & "\icons\image.ico")
Case ".avi"
treeIcon = New Icon(Application.StartupPath & "\icons\video.ico")
Case ".mp3" ' Or ".wav" Or ".mdi"
treeIcon = New Icon(Application.StartupPath & "\icons\sound.ico")
Case ".txt"
treeIcon = New Icon(Application.StartupPath & "\icons\txt.ico")
Case ".xls"
treeIcon = New Icon(Application.StartupPath & "\icons\spreadsheet.ico")
Case ".pdf"
treeIcon = New Icon(Application.StartupPath & "\icons\pdf.icon")
Case Else
treeIcon = New Icon(Application.StartupPath & "\icons\filenew.icon")
End Select
CaricaImgFile.Image = treeIcon.ToBitmap()
Return CaricaImgFile
End Function
Private Sub AddCheckBoxColumn(ByVal NomeColonna As String)
Dim column As New DataGridViewCheckBoxColumn()
With column
.HeaderText = NomeColonna
.Name = NomeColonna
.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells
.FlatStyle = FlatStyle.Standard
.CellTemplate = New DataGridViewCheckBoxCell()
.CellTemplate.Style.BackColor = Color.Beige
End With
DataGridView1.Columns.Insert(DataGridView1.ColumnCount, column)
End Sub
Private Sub AddCol(ByVal pNameCol As Object)
Dim dgv As New DataGridView()
'Aggiungo Colonna Nome
DataGridView1.Columns.Add(pNameCol, pNameCol)
End Sub
Private Sub AggiornaFile(ByVal MyFile As String, ByVal NomeCella As String, ByVal ValoreNew As String)
Try
Dim myDSO As DSOFile.OleDocumentProperties = New DSOFile.OleDocumentProperties
myDSO.Open(MyFile, False, DSOFile.dsoFileOpenOptions.dsoOptionUseMBCStringsForNewSets)
Select Case NomeCella
Case "Autore"
myDSO.SummaryProperties.Author = ValoreNew
Case "Titolo"
myDSO.SummaryProperties.Title = ValoreNew
Case "Oggetto"
myDSO.SummaryProperties.Subject = ValoreNew
Case "Società"
myDSO.SummaryProperties.Company = ValoreNew
Case "Commenti"
myDSO.SummaryProperties.Comments = ValoreNew
End Select
myDSO.Save()
myDSO.Close()
Catch ex As Exception
MsgBox("Errore Agiornamento File : " + ex.ToString, vbCritical, "Errore")
End Try
End Sub
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Try
Dim NomeColonna As String
NomeColonna = DataGridView1.Columns(e.ColumnIndex).HeaderText
'Recupero il valore della cella corrispondente
ValoreCellaClick = Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index).Cells(NomeColonna).Value()
Catch ex As Exception
End Try
End Sub
Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
Try
Dim NomeColonna, NuovoValoreCella, PercorsoFile As String
NomeColonna = DataGridView1.Columns(e.ColumnIndex).HeaderText
'Recupero il valore della cella corrispondente
NuovoValoreCella = Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index).Cells(NomeColonna).Value()
If ValoreCellaClick <> NuovoValoreCella Then
PercorsoFile = Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index).Cells("Percorso").Value()
AggiornaFile(PercorsoFile, NomeColonna, NuovoValoreCella)
End If
Catch ex As Exception
MsgBox("Errore Agiornamento File : " + ex.ToString, vbCritical, "Errore")
End Try
End Sub
Public Sub CreaImgCollon(ByVal NomeColonna As String)
Dim treeIcon As New Icon(Application.StartupPath & "\icons\filenew.ico")
Dim iconColumn As New DataGridViewImageColumn()
With iconColumn
.Image = treeIcon.ToBitmap()
.Name = NomeColonna
.HeaderText = NomeColonna
End With
DataGridView1.Columns.Insert(DataGridView1.ColumnCount, iconColumn)
End Sub
End Class