Public Class Form1
'Variabili globali
Public Settings As String = Application.StartupPath + "\Settings.dat"
Public Database, Field As String
'Questa hashtable contiene tutti i dati, indicizzati per nome
Public Shared DB As New Hashtable
Public Shared FieldTable As New ArrayList
Public Shared FieldNumber As UInt16 = 0
#Region "Metodi"
Public Shared Sub AddObject(ByVal Key As String, ByVal Obj As String())
DB.Add(Key, Obj)
Form1.lstFile.Items.Add(New ListViewItem(Obj))
End Sub
Public Shared Sub DelObject(ByVal Key As String)
DB.Remove(Key)
For Each L As ListViewItem In Form1.lstFile.Items
If L.SubItems(0).Text.ToLower = Key.ToLower Then
L.Remove()
Exit For
End If
Application.DoEvents()
Form1.lblStatus.Text = "Scansione in corso..."
Next
Form1.lblStatus.Text = "Completato"
End Sub
Public Shared Sub ModObject(ByVal Key As String, ByVal NewValue As String())
DB.Item(Key) = NewValue
For Each L As ListViewItem In Form1.lstFile.Items
If L.SubItems(0).Text.ToLower = Key.ToLower Then
For i As UInt16 = 0 To FieldNumber
L.SubItems(i).Text = NewValue(i)
Next
Exit For
End If
Application.DoEvents()
Form1.lblStatus.Text = "Modifica in corso..."
Next
Form1.lblStatus.Text = "Completato"
End Sub
Public Shared Sub SaveDB
(ByVal File As String)
Dim W
As New IO.
StreamWriter(File)
Dim S() As String
Dim Count As UInt16 = 1
With Form1
.strPrg.Visible = True
For Each K As String In DB.Keys
S = Form1.DB.Item(K)
For i As UInt16 = 0 To FieldNumber
W.WriteLine(S(i))
Next
Application.DoEvents()
.lblStatus.Text = "Salvataggio in corso (" & Count & "/" & DB.Keys.Count & ")..."
.strPrg.Value = Count * 100 / DB.Keys.Count
Count += 1
Next
.lblStatus.Text = "Completato"
W.Close()
End With
End Sub
Public Shared Sub LoadDB
(ByVal File As String)
Try
Dim R
As New IO.
StreamReader(File)
Dim Obj(FieldNumber) As String
Dim Count As UInt16 = 1
With Form1
.lstFile.Items.Clear()
DB.Clear()
While Not R.EndOfStream
For i As UInt16 = 0 To FieldNumber
Obj(i) = R.ReadLine
Next
AddObject(Obj(0), Obj)
Application.DoEvents()
.lblStatus.Text = "Caricamento in corso..."
End While
.lblStatus.Text = "Completato"
R.Close()
End With
Catch Ex As Exception
MsgBox("Impossibile caricare il database!", MsgBoxStyle.Exclamation)
End Try
End Sub
Public Shared Sub LoadField
(ByVal File As String)
Try
Dim R
As New IO.
StreamReader(File)
Dim S() As String
Form1.lstFile.Columns.Clear()
FieldTable.Clear()
FieldNumber = 0
While Not R.EndOfStream
S = R.ReadLine.Split("|")
Form1.lstFile.Columns.Add(S(0))
FieldTable.Add(S)
FieldNumber += 1
End While
FieldNumber -= 1
Form1.lblStatus.Text = "Completato"
R.Close()
Catch Ex As Exception
MsgBox("Impossibile caricare la tabella dei campi!", MsgBoxStyle.Exclamation)
End Try
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim R As New IO.StreamReader(Settings)
Dim S As String = ""
While Not R.EndOfStream
S = R.ReadLine
If S.StartsWith("Database=") Then
S = S.Remove(0, "Database=".Length)
Database = S
End If
If S.StartsWith("Field=") Then
S = S.Remove(0, "Field=".Length)
Field = S
End If
End While
If Field <> Nothing Then
LoadField(Field)
If Database <> Nothing Then
LoadDB(Database)
End If
End If
R.Close()
Catch ex As Exception
MsgBox("Impossibili caricare i dati!", MsgBoxStyle.Exclamation)
Dim W As New IO.StreamWriter(Settings)
W.WriteLine()
W.Close()
End Try
End Sub
Private Sub strAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAdd.Click
Dim A As New frmAdd
A.ShowDialog()
End Sub
Private Sub strLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLoad.Click
Dim O As New OpenFileDialog
O.Filter = "Database|*.db"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
LoadDB(O.FileName)
End If
End Sub
Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
Dim S As New SaveFileDialog
S.Filter = "Database|*.db"
If S.ShowDialog = Windows.Forms.DialogResult.OK Then
SaveDB(S.FileName)
End If
End Sub
Private Sub DatabasePredefinitoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DatabasePredefinitoToolStripMenuItem.Click
Dim O As New OpenFileDialog
O.Title = "Questo database verrà caricato all'avvio del programma"
O.Filter = "Database|*.db"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim W As New IO.StreamWriter(Settings)
W.WriteLine("Database=" + O.FileName)
W.WriteLine("Field=" + Field)
W.Close()
MsgBox("Operazione completata!", MsgBoxStyle.Information)
End If
End Sub
Private Sub TabellaCampiPredefinitaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabellaCampiPredefinitaToolStripMenuItem.Click
Dim O As New OpenFileDialog
O.Title = "Questa tabella verrà caricata all'avvio del programma"
O.Filter = "File DAT|*.dat"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
Dim W As New IO.StreamWriter(Settings)
W.WriteLine("Database=" + Database)
W.WriteLine("Field=" + O.FileName)
W.Close()
MsgBox("Operazione completata!", MsgBoxStyle.Information)
End If
End Sub
Private Sub strLoadField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLoadField.Click
Dim O As New OpenFileDialog
O.Filter = "File DAT|*.dat"
If O.ShowDialog = Windows.Forms.DialogResult.OK Then
LoadField(O.FileName)
End If
End Sub
Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
Me.Close()
End Sub
Private Sub strSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearch.Click
Dim R As New frmSearch
R.Show()
End Sub
Private Sub strDelSel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelSel.Click
Dim Ar As New ArrayList
Dim Count As UInt16 = 1
strPrg.Visible = True
For Each I As UInt16 In lstFile.CheckedIndices
Ar.Add(I)
Next
For Each I As UInt16 In Ar
DB.Remove(lstFile.Items(I).SubItems(0).Text)
lstFile.Items.RemoveAt(I)
Application.DoEvents()
strPrg.Value = Count * 100 / Ar.Count
lblStatus.Text = "Rimozione in corso (" & Count & "/" & Ar.Count & ")..."
Count += 1
Next
lblStatus.Text = "Completato"
End Sub
Private Sub strDelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelAll.Click
If MsgBox("Rimuovere tutti gli elementi della lista?", 36) = MsgBoxResult.No Then
Exit Sub
End If
lstFile.Items.Clear()
DB.Clear()
End Sub
Private Sub strMod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strMod.Click
If lstFile.SelectedItems.Count = 0 Then
Exit Sub
End If
Dim M As New frmAdd(DB(lstFile.SelectedItems(0).SubItems(0).Text))
M.ShowDialog()
End Sub
Private Sub strHelpField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strHelpField.Click
Try
Shell("C:\WINDOWS\system32\notepad.exe " + Chr(34) + Application.StartupPath + "\Field.txt" + Chr(34), AppWinStyle.NormalFocus)
Catch Ex As Exception
MsgBox("Impossibile trovare il file e/o il blocco note!", MsgBoxStyle.Exclamation)
End Try
End Sub
Private Sub StrBugRep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StrBugRep.Click
MsgBox("Per problemi, contattare nicolo1990@yahoo.it.", MsgBoxStyle.Information)
End Sub
Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
MsgBox("Ultra File" + vbCrLf + "Versione: 1.0.0.0" + vbCrLf + "Autore: Totem" + vbCrLf + "Società: Piero Tofy's Community (http://www.pierotofy.it)" + vbCrLf + "Descrizione: cataloga qualsiasi tipo di oggetto o contatto, permettendo all'utente di scegliere quali campi compilare.", MsgBoxStyle.Information)
End Sub
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
If MsgBox("Salvare prima di uscire?", 36) = MsgBoxResult.Yes Then
Dim S As New SaveFileDialog
S.Filter = "Database|*.db"
If S.ShowDialog = Windows.Forms.DialogResult.OK Then
SaveDB(S.FileName)
End If
End If
End Sub
End Class