Ma nel codice load cosa ce che non va
questo è tutto il codice del form1
ublic Class form1
Friend bsnAgg As Integer
Private Sub ClientiBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles ClientiBindingNavigatorSaveItem.Click
Me.Validate()
Me.ClientiBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: questa riga di codice carica i dati nella tabella 'Database1DataSet.contabilita'. È possibile spostarla o rimuoverla se necessario.
Me.ContabilitaTableAdapter.Fill(Me.Database1DataSet.contabilita)
'TODO: questa riga di codice carica i dati nella tabella 'Database1DataSet.clienti'. È possibile spostarla o rimuoverla se necessario.
Me.ClientiTableAdapter.Fill(Me.Database1DataSet.clienti)
ContabilitaDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue
ContabilitaDataGridView.EnableHeadersVisualStyles = False
ContabilitaDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Beige
ContabilitaDataGridView.ColumnHeadersDefaultCellStyle.Font = New Font("Microsoft Sans Serif", 11, FontStyle.Bold)
ClientiDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
ClientiDataGridView.EnableHeadersVisualStyles = False
ClientiDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.AliceBlue
ClientiDataGridView.ColumnHeadersDefaultCellStyle.Font = New Font("Microsoft Sans Serif", 11, FontStyle.Bold)
LblData.Text = System.DateTime.Now.ToShortDateString
Try
ContabilitaDataGridView.FirstDisplayedScrollingRowIndex = ContabilitaDataGridView.RowCount - 2
Catch ex As Exception
End Try
Try
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim num1 As Double
num1 = TextBox1.Text
TextBox1.Text = CDec(TextBox1.Text).ToString("c2") 'nel datagridwiew usare la virgola e non il punto per i decimali
End Sub
Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
Dim num1 As Double
num1 = TextBox2.Text
TextBox2.Text = CDec(TextBox2.Text).ToString("c2") 'nel datagridwiew usare la virgola e non il punto per i decimali
End Sub
Private Sub TextBox3_TextChanged(sender As Object, e As EventArgs) Handles TextBox3.TextChanged
Dim num1 As Double
num1 = TextBox3.Text
TextBox3.Text = CDec(TextBox3.Text).ToString("c2") 'nel datagridwiew usare la virgola e non il punto per i decimali
End Sub
Private Sub ClientiDataGridView_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles ClientiDataGridView.CellClick
Try
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
ContabilitaDataGridView.FirstDisplayedScrollingRowIndex = ContabilitaDataGridView.RowCount - 2
Catch ex As Exception
End Try
End Sub
Private Sub NuovaOperazioneToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NuovaOperazioneToolStripMenuItem.Click
Form2.Show()
Form2.Id_clientiTextBox.Text = Me.Id_clientiTextBox.Text
End Sub
Private Sub SalvaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SalvaToolStripMenuItem.Click
Me.Validate()
Me.ClientiBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
MsgBox("Dati salvati con successo", MsgBoxStyle.Information, "Informazione")
End Sub
Private Sub NuovaCategoriaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NuovaCategoriaToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub EliminaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles EliminaToolStripMenuItem.Click
Dim index As Integer
Try
Dim result As DialogResult = MessageBox.Show("ATTENZIONE!" & vbCrLf & "Sei Sicuro di eliminare questa operazione", "Eliminazione", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If result = Windows.Forms.DialogResult.Yes Then
index = ContabilitaDataGridView.CurrentCell.RowIndex
ContabilitaDataGridView.Rows.RemoveAt(index)
ContabilitaTableAdapter.Update(Database1DataSet)
If result = Windows.Forms.DialogResult.No Then
End If
End If
Catch ex As Exception
MsgBox("Non ci sono operazioni da eliminare", MsgBoxStyle.Critical, "Informazione")
End Try
Try
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub ContabilitaDataGridView_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs)
Try
With ContabilitaBindingSource
bsnAgg = CType(.List(.Position), DataRowView).Item(0)
End With
Catch ex As Exception
MsgBox("Non ci sono dati", vbExclamation, "Errore")
Exit Sub
End Try
Form4.Show()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ContabilitaTableAdapter.FillByData(Database1DataSet.contabilita, DateTimePicker1.Value.ToString, DateTimePicker2.Value.ToString)
Try
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
ContabilitaDataGridView.Sort(ContabilitaDataGridView.Columns(1), System.ComponentModel.ListSortDirection.Ascending)
Catch ex As Exception
End Try
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ContabilitaTableAdapter.Fill(Database1DataSet.contabilita)
DateTimePicker1.Value = System.DateTime.Now.ToShortDateString
DateTimePicker2.Value = System.DateTime.Now.ToShortDateString
Try
ContabilitaDataGridView.FirstDisplayedScrollingRowIndex = ContabilitaDataGridView.RowCount - 2
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub TextBox4_TextChanged(sender As Object, e As EventArgs) Handles TextBox4.TextChanged
ContabilitaBindingSource.Filter = "descrizione LIKE '%" + TextBox4.Text + "%' or categoria like'%" + TextBox4.Text + "%'or assegno like'%" + TextBox4.Text + "%'or entrate like'%" + TextBox4.Text + "%' or uscite like'%" + TextBox4.Text + "%'"
Try
ContabilitaDataGridView.FirstDisplayedScrollingRowIndex = ContabilitaDataGridView.RowCount - 2
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox4.Text = ""
TextBox4.Focus()
Try
ContabilitaDataGridView.FirstDisplayedScrollingRowIndex = ContabilitaDataGridView.RowCount - 2
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Try
Dim somma As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(5, r).Value) Then
somma += CType(ContabilitaDataGridView.Rows(r).Cells(5).Value, Double)
End If
Next
TextBox1.Text = somma.ToString
Dim uscite As Double = 0
For r = 0 To ContabilitaDataGridView.Rows.Count - 1
If Not DBNull.Value.Equals(ContabilitaDataGridView(6, r).Value) Then
uscite += CType(ContabilitaDataGridView.Rows(r).Cells(6).Value, Double)
End If
Next
TextBox2.Text = uscite.ToString
TextBox3.Text = TextBox1.Text - TextBox2.Text
If TextBox3.Text < 0 Then
TextBox3.ForeColor = Color.Red
Else
TextBox3.ForeColor = Color.Green
End If
Catch ex As Exception
End Try
End Sub
Private Sub ContabilitaDataGridView_CellDoubleClick_1(sender As Object, e As DataGridViewCellEventArgs) Handles ContabilitaDataGridView.CellDoubleClick
Try
With ContabilitaBindingSource
bsnAgg = CType(.List(.Position), DataRowView).Item(0)
End With
Catch ex As Exception
MsgBox("Non ci sono dati", vbExclamation, "Errore")
Exit Sub
End Try
Form4.Show()
End Sub
Private Sub ContabilitaDataGridView_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles ContabilitaDataGridView.CellFormatting
Try
Dim data As DateTime = CType(e.Value, DateTime)
If e.ColumnIndex = 1 Then
If e.ColumnIndex = 1 Then
If data > DateTime.Today Then
' se data maggiore di oggi
e.CellStyle.BackColor = Color.Yellow
Else
' altrimenti ha il colore di default
e.CellStyle.BackColor = DirectCast(sender, DataGridView).DefaultCellStyle.BackColor
End If
End If
End If
Catch ex As Exception
End Try
End Sub
End Class