Torna al Thread
Dim result() As DataRow = home.WinmenuDataSet.Tables("menu").Select(" data = '" & Me.DateTimePicker1.Text & "' ")
Dim nuovariga As DataRow
'controllo se il menu esiste già
If result.Length > 0 Then
'se esiste già un menu con questa data chiedo cosa si vuole fare
risultato = MsgBox("Esiste già un menu inserito con questa data! Sovrascriverlo?", MsgBoxStyle.YesNoCancel)
If risultato = MsgBoxResult.Cancel Then
Exit Sub
ElseIf risultato = MsgBoxResult.No Then
MsgBox("Menu non salvato, Selezionare un'altra data.")
Exit Sub
ElseIf risultato = MsgBoxResult.Yes Then
If MsgBox("Vuoi veramente sovrascrivere il menu precendente?", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
Exit Sub
End If
End If
' se si è scelto di sovrascrivere
nuovariga = result(0)
Else
'non ci sono menu con questa data
nuovariga = home.WinmenuDataSet.Tables("menu").NewRow
nuovariga("data") = Me.DateTimePicker1.Text
End If
' compilo i campi pranzo
For n As Integer = 1 To 24
If (menu_pranzo(n) IsNot Nothing) Then
nuovariga("pranzo" & n & "id") = menu_pranzo(n).getId
nuovariga("pranzo" & n & "tipo") = menu_pranzo(n).getCategoria
End If
Next n
' compilo i campi cena
For n As Integer = 1 To 24
If (menu_cena(n) IsNot Nothing) Then
nuovariga("cena" & n & "id") = menu_cena(n).getId
nuovariga("cena" & n & "tipo") = menu_cena(n).getCategoria
End If
Next n
' se si tratta di una nuova riga
If result.Length <= 0 Then
home.WinmenuDataSet.Tables("menu").Rows.Add(nuovariga)
End If
'aggiorno il database
home.MenuTableAdapter.Update(nuovariga)
salvato = True
Me.Close()