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
Rubrica - sorgenteRubrica.txt

sorgenteRubrica.txt

Caricato da: Bonny
Scarica il programma completo

  1. Imports System.Data.OleDb
  2. Public Class form1
  3.     Dim PercorsoDB As String = Application.StartupPath & "\dbrubrica.mdb"
  4.     Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & PercorsoDB
  5.     Dim CN As New OleDbConnection(ConnString)
  6.     Dim DA As New OleDbDataAdapter(Sql, CN)
  7.     Dim Ds As New DataSet
  8.     Dim Sql As String = ""
  9. #Region "Focus textbox"
  10.     Private Sub Focus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtindirizzo.GotFocus, txtmail.GotFocus, txttelefono.GotFocus, txtnome.GotFocus, txtcognome.GotFocus
  11.         If sender Is txtcognome Then
  12.             txtcognome.BackColor = Color.Yellow
  13.             txtindirizzo.BackColor = Color.White
  14.             txttelefono.BackColor = Color.White
  15.             txtnome.BackColor = Color.White
  16.             txtmail.BackColor = Color.White
  17.         ElseIf sender Is txtnome Then
  18.             txtcognome.BackColor = Color.White
  19.             txtindirizzo.BackColor = Color.White
  20.             txttelefono.BackColor = Color.White
  21.             txtnome.BackColor = Color.Yellow
  22.             txtmail.BackColor = Color.White
  23.         ElseIf sender Is txtindirizzo Then
  24.             txtcognome.BackColor = Color.White
  25.             txtindirizzo.BackColor = Color.Yellow
  26.             txttelefono.BackColor = Color.White
  27.             txtnome.BackColor = Color.White
  28.             txtmail.BackColor = Color.White
  29.         ElseIf sender Is txtmail Then
  30.             txtcognome.BackColor = Color.White
  31.             txtindirizzo.BackColor = Color.White
  32.             txttelefono.BackColor = Color.White
  33.             txtnome.BackColor = Color.White
  34.             txtmail.BackColor = Color.Yellow
  35.         ElseIf sender Is txttelefono Then
  36.             txtcognome.BackColor = Color.White
  37.             txtindirizzo.BackColor = Color.White
  38.             txttelefono.BackColor = Color.Yellow
  39.             txtnome.BackColor = Color.White
  40.             txtmail.BackColor = Color.White
  41.         End If
  42.     End Sub
  43. #End Region
  44. #Region "insert"
  45.     Private Sub cmdsalva_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdsalva.Click
  46.         If txtnome.Text = "" Or txttelefono.Text = "" Then
  47.             MsgBox("devi riempire tutti i campi", MsgBoxStyle.Information, "Errore")
  48.             Exit Sub
  49.         End If
  50.         Try
  51.             Sql = "Insert into amici (Nome,Cognome,Indirizzo,Email,Cell) Values ("
  52.             Sql = Sql & "'" & txtnome.Text.Trim & "','" & txtcognome.Text.Trim & "','" & txtindirizzo.Text.Trim & "','"
  53.             Sql = Sql & txtmail.Text.Trim & "','" & txttelefono.Text.Trim & "')"
  54.             If CN.State = ConnectionState.Closed Then
  55.                 CN.Open()
  56.             End If
  57.             Dim CM As New OleDbCommand(Sql, CN) 'oggetto che permette l'esecuzione della query
  58.             CM.ExecuteNonQuery()
  59.         Catch ex As Exception
  60.             MsgBox(ex.Message, MsgBoxStyle.Critical, "Errore")
  61.             Exit Sub
  62.         End Try
  63.         MsgBox("Contatto salvato correttamente", MsgBoxStyle.Information, "Salvato")
  64.         CN.Close()
  65.     End Sub
  66. #End Region
  67.  
  68.     Private Sub CmdVisualiza_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdVisualiza.Click
  69.         With Form2
  70.             Sql = "Select * From amici order by Nome"
  71.             Dim DA As New OleDbDataAdapter(Sql, CN)
  72.             Dim CM As New OleDbCommand(Sql, CN)
  73.             DA.SelectCommand = CM
  74.             DA.Fill(Ds, "amici")
  75.             .Dg.DataSource = Ds
  76.             .Dg.DataMember = "amici"
  77.             .Text = "Lista amici"
  78.             .Show()
  79.         End With
  80.  
  81.     End Sub
  82. End Class