Imports System
Imports System.IO
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If nome.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If cognome.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If indirizzo.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If email.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If tel.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If cell.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
If lavoro.Text = "" Then
MessageBox.Show("Riempire tutti i campi", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Dim items(8) As String
items(0) = nome.Text
items(1) = cognome.Text
items(2) = indirizzo.Text
items(3) = email.Text
items(4) = tel.Text
items(5) = cell.Text
items(6) = lavoro.Text
items(7) = commento.Text
items(8) = appunto.Text
Dim lvi As ListViewItem
lvi = New ListViewItem(items)
listview.Items.Add(lvi)
Dim sw As StreamWriter = New StreamWriter(Application.StartupPath & "\agenda.txt", True)
sw.WriteLine(nome.Text & "___" & cognome.Text & "___" & indirizzo.Text & "___" & email.Text & "___" & tel.Text & "___" & cell.Text & "___" & lavoro.Text & "___" & commento.Text & "___" & appunto.Text)
sw.Close()
nome.Clear()
cognome.Clear()
indirizzo.Clear()
email.Clear()
tel.Clear()
cell.Clear()
lavoro.Clear()
commento.Clear()
appunto.Clear()
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
File.
Delete(Application.
StartupPath & "\agenda.txt")
Dim a As Integer
Dim sw As StreamWriter = New StreamWriter(Application.StartupPath & "\agenda.txt")
For a = 0 To listview.Items.Count - 1
Dim lvi As ListViewItem
lvi = listview.Items(a)
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)
Next
sw.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If File.
Exists(Application.
StartupPath & "\agenda.txt") = True Then
Dim sr As StreamReader = New StreamReader(Application.StartupPath & "\agenda.txt")
Try
Dim line As String
line = ""
While Not line Is Nothing
line = sr.ReadLine()
If (Not line = "") Then
Dim info() As String
info = Split(line, "___")
Dim a1 As Integer
Dim items(8) As String
For a1 = 0 To info.Length - 1
items(a1) = info(a1)
Next
Dim lvi As ListViewItem
lvi = New ListViewItem(items)
listview.Items.Add(lvi)
End If
End While
sr.Close()
Catch ex As Exception
sr.Close()
End Try
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (listview.SelectedItems.Count > 0) Then
listview.SelectedItems(0).Remove()
End If
nome.Clear()
cognome.Clear()
indirizzo.Clear()
email.Clear()
tel.Clear()
cell.Clear()
lavoro.Clear()
appunto.Clear()
commento.Clear()
End Sub
Private Sub listview_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles listview.SelectedIndexChanged
If (listview.SelectedItems.Count > 0) Then
nome.Text = listview.SelectedItems(0).SubItems(0).Text
cognome.Text = listview.SelectedItems(0).SubItems(1).Text
indirizzo.Text = listview.SelectedItems(0).SubItems(2).Text
email.Text = listview.SelectedItems(0).SubItems(3).Text
tel.Text = listview.SelectedItems(0).SubItems(4).Text
cell.Text = listview.SelectedItems(0).SubItems(5).Text
lavoro.Text = listview.SelectedItems(0).SubItems(6).Text
commento.Text = listview.SelectedItems(0).SubItems(7).Text
appunto.Text = listview.SelectedItems(0).SubItems(8).Text
End If
End Sub
End Class