Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Ultra File - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Public Class Form1
  2.     'Variabili globali
  3.     Public Settings As String = Application.StartupPath + "\Settings.dat"
  4.     Public Database, Field As String
  5.     'Questa hashtable contiene tutti i dati, indicizzati per nome
  6.     Public Shared DB As New Hashtable
  7.     Public Shared FieldTable As New ArrayList
  8.     Public Shared FieldNumber As UInt16 = 0
  9. #Region "Metodi"
  10.     Public Shared Sub AddObject(ByVal Key As String, ByVal Obj As String())
  11.         DB.Add(Key, Obj)
  12.         Form1.lstFile.Items.Add(New ListViewItem(Obj))
  13.     End Sub
  14.     Public Shared Sub DelObject(ByVal Key As String)
  15.         DB.Remove(Key)
  16.         For Each L As ListViewItem In Form1.lstFile.Items
  17.             If L.SubItems(0).Text.ToLower = Key.ToLower Then
  18.                 L.Remove()
  19.                 Exit For
  20.             End If
  21.             Application.DoEvents()
  22.             Form1.lblStatus.Text = "Scansione in corso..."
  23.         Next
  24.         Form1.lblStatus.Text = "Completato"
  25.     End Sub
  26.     Public Shared Sub ModObject(ByVal Key As String, ByVal NewValue As String())
  27.         DB.Item(Key) = NewValue
  28.         For Each L As ListViewItem In Form1.lstFile.Items
  29.             If L.SubItems(0).Text.ToLower = Key.ToLower Then
  30.                 For i As UInt16 = 0 To FieldNumber
  31.                     L.SubItems(i).Text = NewValue(i)
  32.                 Next
  33.                 Exit For
  34.             End If
  35.             Application.DoEvents()
  36.             Form1.lblStatus.Text = "Modifica in corso..."
  37.         Next
  38.         Form1.lblStatus.Text = "Completato"
  39.     End Sub
  40.     Public Shared Sub SaveDB(ByVal File As String)
  41.         Dim W As New IO.StreamWriter(File)
  42.         Dim S() As String
  43.         Dim Count As UInt16 = 1
  44.  
  45.         With Form1
  46.             .strPrg.Visible = True
  47.             For Each K As String In DB.Keys
  48.                 S = Form1.DB.Item(K)
  49.                 For i As UInt16 = 0 To FieldNumber
  50.                     W.WriteLine(S(i))
  51.                 Next
  52.                 Application.DoEvents()
  53.                 .lblStatus.Text = "Salvataggio in corso (" & Count & "/" & DB.Keys.Count & ")..."
  54.                 .strPrg.Value = Count * 100 / DB.Keys.Count
  55.                 Count += 1
  56.             Next
  57.  
  58.             .lblStatus.Text = "Completato"
  59.             W.Close()
  60.         End With
  61.     End Sub
  62.     Public Shared Sub LoadDB(ByVal File As String)
  63.         Try
  64.             Dim R As New IO.StreamReader(File)
  65.             Dim Obj(FieldNumber) As String
  66.             Dim Count As UInt16 = 1
  67.  
  68.             With Form1
  69.                 .lstFile.Items.Clear()
  70.                 DB.Clear()
  71.                 While Not R.EndOfStream
  72.                     For i As UInt16 = 0 To FieldNumber
  73.                         Obj(i) = R.ReadLine
  74.                     Next
  75.                     AddObject(Obj(0), Obj)
  76.                     Application.DoEvents()
  77.                     .lblStatus.Text = "Caricamento in corso..."
  78.                 End While
  79.  
  80.                 .lblStatus.Text = "Completato"
  81.                 R.Close()
  82.             End With
  83.         Catch Ex As Exception
  84.             MsgBox("Impossibile caricare il database!", MsgBoxStyle.Exclamation)
  85.         End Try
  86.     End Sub
  87.     Public Shared Sub LoadField(ByVal File As String)
  88.         Try
  89.             Dim R As New IO.StreamReader(File)
  90.             Dim S() As String
  91.  
  92.             Form1.lstFile.Columns.Clear()
  93.             FieldTable.Clear()
  94.             FieldNumber = 0
  95.             While Not R.EndOfStream
  96.                 S = R.ReadLine.Split("|")
  97.                 Form1.lstFile.Columns.Add(S(0))
  98.                 FieldTable.Add(S)
  99.                 FieldNumber += 1
  100.             End While
  101.             FieldNumber -= 1
  102.  
  103.             Form1.lblStatus.Text = "Completato"
  104.             R.Close()
  105.         Catch Ex As Exception
  106.             MsgBox("Impossibile caricare la tabella dei campi!", MsgBoxStyle.Exclamation)
  107.         End Try
  108.     End Sub
  109. #End Region
  110.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  111.         Try
  112.             Dim R As New IO.StreamReader(Settings)
  113.             Dim S As String = ""
  114.  
  115.             While Not R.EndOfStream
  116.                 S = R.ReadLine
  117.                 If S.StartsWith("Database=") Then
  118.                     S = S.Remove(0, "Database=".Length)
  119.                     Database = S
  120.                 End If
  121.                 If S.StartsWith("Field=") Then
  122.                     S = S.Remove(0, "Field=".Length)
  123.                     Field = S
  124.                 End If
  125.             End While
  126.  
  127.             If Field <> Nothing Then
  128.                 LoadField(Field)
  129.                 If Database <> Nothing Then
  130.                     LoadDB(Database)
  131.                 End If
  132.             End If
  133.  
  134.             R.Close()
  135.         Catch ex As Exception
  136.             MsgBox("Impossibili caricare i dati!", MsgBoxStyle.Exclamation)
  137.             Dim W As New IO.StreamWriter(Settings)
  138.             W.WriteLine()
  139.             W.Close()
  140.         End Try
  141.     End Sub
  142.     Private Sub strAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAdd.Click
  143.         Dim A As New frmAdd
  144.         A.ShowDialog()
  145.     End Sub
  146.     Private Sub strLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLoad.Click
  147.         Dim O As New OpenFileDialog
  148.         O.Filter = "Database|*.db"
  149.         If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  150.             LoadDB(O.FileName)
  151.         End If
  152.     End Sub
  153.     Private Sub strSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSave.Click
  154.         Dim S As New SaveFileDialog
  155.         S.Filter = "Database|*.db"
  156.         If S.ShowDialog = Windows.Forms.DialogResult.OK Then
  157.             SaveDB(S.FileName)
  158.         End If
  159.     End Sub
  160.     Private Sub DatabasePredefinitoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DatabasePredefinitoToolStripMenuItem.Click
  161.         Dim O As New OpenFileDialog
  162.         O.Title = "Questo database verrà caricato all'avvio del programma"
  163.         O.Filter = "Database|*.db"
  164.         If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  165.             Dim W As New IO.StreamWriter(Settings)
  166.             W.WriteLine("Database=" + O.FileName)
  167.             W.WriteLine("Field=" + Field)
  168.             W.Close()
  169.             MsgBox("Operazione completata!", MsgBoxStyle.Information)
  170.         End If
  171.     End Sub
  172.     Private Sub TabellaCampiPredefinitaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabellaCampiPredefinitaToolStripMenuItem.Click
  173.         Dim O As New OpenFileDialog
  174.         O.Title = "Questa tabella verrà caricata all'avvio del programma"
  175.         O.Filter = "File DAT|*.dat"
  176.         If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  177.             Dim W As New IO.StreamWriter(Settings)
  178.             W.WriteLine("Database=" + Database)
  179.             W.WriteLine("Field=" + O.FileName)
  180.             W.Close()
  181.             MsgBox("Operazione completata!", MsgBoxStyle.Information)
  182.         End If
  183.     End Sub
  184.     Private Sub strLoadField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strLoadField.Click
  185.         Dim O As New OpenFileDialog
  186.         O.Filter = "File DAT|*.dat"
  187.         If O.ShowDialog = Windows.Forms.DialogResult.OK Then
  188.             LoadField(O.FileName)
  189.         End If
  190.     End Sub
  191.     Private Sub strExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strExit.Click
  192.         Me.Close()
  193.     End Sub
  194.     Private Sub strSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strSearch.Click
  195.         Dim R As New frmSearch
  196.         R.Show()
  197.     End Sub
  198.     Private Sub strDelSel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelSel.Click
  199.         Dim Ar As New ArrayList
  200.         Dim Count As UInt16 = 1
  201.  
  202.         strPrg.Visible = True
  203.  
  204.         For Each I As UInt16 In lstFile.CheckedIndices
  205.             Ar.Add(I)
  206.         Next
  207.         For Each I As UInt16 In Ar
  208.             DB.Remove(lstFile.Items(I).SubItems(0).Text)
  209.             lstFile.Items.RemoveAt(I)
  210.             Application.DoEvents()
  211.             strPrg.Value = Count * 100 / Ar.Count
  212.             lblStatus.Text = "Rimozione in corso (" & Count & "/" & Ar.Count & ")..."
  213.             Count += 1
  214.         Next
  215.  
  216.         lblStatus.Text = "Completato"
  217.     End Sub
  218.     Private Sub strDelAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strDelAll.Click
  219.         If MsgBox("Rimuovere tutti gli elementi della lista?", 36) = MsgBoxResult.No Then
  220.             Exit Sub
  221.         End If
  222.         lstFile.Items.Clear()
  223.         DB.Clear()
  224.     End Sub
  225.     Private Sub strMod_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strMod.Click
  226.         If lstFile.SelectedItems.Count = 0 Then
  227.             Exit Sub
  228.         End If
  229.         Dim M As New frmAdd(DB(lstFile.SelectedItems(0).SubItems(0).Text))
  230.         M.ShowDialog()
  231.     End Sub
  232.     Private Sub strHelpField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strHelpField.Click
  233.         Try
  234.             Shell("C:\WINDOWS\system32\notepad.exe " + Chr(34) + Application.StartupPath + "\Field.txt" + Chr(34), AppWinStyle.NormalFocus)
  235.         Catch Ex As Exception
  236.             MsgBox("Impossibile trovare il file e/o il blocco note!", MsgBoxStyle.Exclamation)
  237.         End Try
  238.     End Sub
  239.     Private Sub StrBugRep_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StrBugRep.Click
  240.         MsgBox("Per problemi, contattare nicolo1990@yahoo.it.", MsgBoxStyle.Information)
  241.     End Sub
  242.     Private Sub strAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles strAbout.Click
  243.         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)
  244.     End Sub
  245.     Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
  246.         If MsgBox("Salvare prima di uscire?", 36) = MsgBoxResult.Yes Then
  247.             Dim S As New SaveFileDialog
  248.             S.Filter = "Database|*.db"
  249.             If S.ShowDialog = Windows.Forms.DialogResult.OK Then
  250.                 SaveDB(S.FileName)
  251.             End If
  252.         End If
  253.     End Sub
  254. End Class