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
Agenda Digitale - Copia di Form1.vb

Copia di Form1.vb

Caricato da:
Scarica il programma completo

  1. Imports System
  2. Imports System.IO
  3.  
  4. Public Class Form1
  5.  
  6.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  7.         If nome.Text = "" Then
  8.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  9.             Exit Sub
  10.         End If
  11.         If cognome.Text = "" Then
  12.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  13.             Exit Sub
  14.         End If
  15.         If indirizzo.Text = "" Then
  16.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  17.             Exit Sub
  18.         End If
  19.         If email.Text = "" Then
  20.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  21.             Exit Sub
  22.         End If
  23.         If tel.Text = "" Then
  24.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  25.             Exit Sub
  26.         End If
  27.         If cell.Text = "" Then
  28.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  29.             Exit Sub
  30.         End If
  31.         If lavoro.Text = "" Then
  32.             MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
  33.             Exit Sub
  34.         End If
  35.  
  36.         Dim items(8) As String
  37.         items(0) = nome.Text
  38.         items(1) = cognome.Text
  39.         items(2) = indirizzo.Text
  40.         items(3) = email.Text
  41.         items(4) = tel.Text
  42.         items(5) = cell.Text
  43.         items(6) = lavoro.Text
  44.         items(7) = commento.Text
  45.         items(8) = appunto.Text
  46.  
  47.         Dim lvi As ListViewItem
  48.         lvi = New ListViewItem(items)
  49.         listview.Items.Add(lvi)
  50.  
  51.         Dim sw As StreamWriter = New StreamWriter(Application.StartupPath & "\agenda.txt", True)
  52.         sw.WriteLine(nome.Text & "___" & cognome.Text & "___" & indirizzo.Text & "___" & email.Text & "___" & tel.Text & "___" & cell.Text & "___" & lavoro.Text & "___" & commento.Text & "___" & appunto.Text)
  53.         sw.Close()
  54.  
  55.         nome.Clear()
  56.         cognome.Clear()
  57.         indirizzo.Clear()
  58.         email.Clear()
  59.         tel.Clear()
  60.         cell.Clear()
  61.         lavoro.Clear()
  62.         commento.Clear()
  63.         appunto.Clear()
  64.     End Sub
  65.  
  66.  
  67.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  68.         File.Delete(Application.StartupPath & "\agenda.txt")
  69.         Dim a As Integer
  70.         Dim sw As StreamWriter = New StreamWriter(Application.StartupPath & "\agenda.txt")
  71.         For a = 0 To listview.Items.Count - 1
  72.             Dim lvi As ListViewItem
  73.             lvi = listview.Items(a)
  74.             sw.WriteLine(lvi.SubItems(0).Text & "___" & lvi.SubItems(1).Text & "___" & lvi.SubItems(2).Text & "___" & lvi.SubItems(3).Text & "___" & lvi.SubItems(4).Text & "___" & lvi.SubItems(5).Text & "___" & lvi.SubItems(6).Text & "___" & lvi.SubItems(7).Text & "___" & lvi.SubItems(8).Text)
  75.         Next
  76.         sw.Close()
  77.     End Sub
  78.  
  79.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  80.         If File.Exists(Application.StartupPath & "\agenda.txt") = True Then
  81.             Dim sr As StreamReader = New StreamReader(Application.StartupPath & "\agenda.txt")
  82.             Try
  83.                 Dim line As String
  84.                 line = ""
  85.  
  86.                 While Not line Is Nothing
  87.                     line = sr.ReadLine()
  88.                     If (Not line = "") Then
  89.                         Dim info() As String
  90.                         info = Split(line, "___")
  91.                         Dim a1 As Integer
  92.                         Dim items(8) As String
  93.  
  94.                         For a1 = 0 To info.Length - 1
  95.                             items(a1) = info(a1)
  96.                         Next
  97.  
  98.                         Dim lvi As ListViewItem
  99.                         lvi = New ListViewItem(items)
  100.                         listview.Items.Add(lvi)
  101.                     End If
  102.                 End While
  103.                 sr.Close()
  104.             Catch ex As Exception
  105.                 sr.Close()
  106.             End Try
  107.         End If
  108.     End Sub
  109.  
  110.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  111.         If (listview.SelectedItems.Count > 0) Then
  112.             listview.SelectedItems(0).Remove()
  113.         End If
  114.         nome.Clear()
  115.         cognome.Clear()
  116.         indirizzo.Clear()
  117.         email.Clear()
  118.         tel.Clear()
  119.         cell.Clear()
  120.         lavoro.Clear()
  121.         appunto.Clear()
  122.         commento.Clear()
  123.     End Sub
  124.  
  125.     Private Sub listview_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listview.SelectedIndexChanged
  126.         If (listview.SelectedItems.Count > 0) Then
  127.             nome.Text = listview.SelectedItems(0).SubItems(0).Text
  128.             cognome.Text = listview.SelectedItems(0).SubItems(1).Text
  129.             indirizzo.Text = listview.SelectedItems(0).SubItems(2).Text
  130.             email.Text = listview.SelectedItems(0).SubItems(3).Text
  131.             tel.Text = listview.SelectedItems(0).SubItems(4).Text
  132.             cell.Text = listview.SelectedItems(0).SubItems(5).Text
  133.             lavoro.Text = listview.SelectedItems(0).SubItems(6).Text
  134.             commento.Text = listview.SelectedItems(0).SubItems(7).Text
  135.             appunto.Text = listview.SelectedItems(0).SubItems(8).Text
  136.         End If
  137.     End Sub
  138. End Class