1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
'************************** VALIDATION LIGNE ************************
Private Sub DataGridView1_RowValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.RowValidating
DataGridView1.EndEdit()
Dim row As DataGridViewRow = DataGridView1.CurrentRow 'DataGridView1.Rows(e.RowIndex)
' Test de la ligne.
' IsCurrentRowDirty : Dans ces cas (ex : le DataGridView est lié à une source de données),
' il évalue cette propriété au niveau de la ligne.
If DataGridView1.IsCurrentRowDirty AndAlso Not row Is Nothing AndAlso Not row.IsNewRow Then
Dim numCell As DataGridViewCell = row.Cells(DataGridView1.Columns("Num").Index)
Dim quantCell As DataGridViewCell = row.Cells(DataGridView1.Columns("Quant").Index)
Dim pUnitCell As DataGridViewCell = row.Cells(DataGridView1.Columns("PrixUnit").Index)
Dim listBilan As New List(Of String)
' Test si référence.
If numCell.Value IsNot Nothing Then
listBilan.Add(IsNumGood(numCell, ds, "Ligne"))
End If
If quantCell.Value IsNot Nothing Then
listBilan.Add(IsQuantGood(quantCell, pUnitCell))
End If
If pUnitCell.Value IsNot Nothing Then
listBilan.Add(IspUnitGood(pUnitCell, quantCell))
End If
' Analyse du résultat.
Dim resultList As Boolean = True
Select Case resultList
Case listBilan.Contains("NN")
MessageBox.Show("A corriger ? : Valorisation obligatoire", "", MessageBoxButtons.YesNo)
Case listBilan.Contains("L")
MessageBox.Show("A corriger ? : Valorisation de cette valeur liée", "", MessageBoxButtons.YesNo)
Case listBilan.Contains("N")
MessageBox.Show("A corriger ? : Cette valeur ne peut être négative", "", MessageBoxButtons.YesNo)
Case listBilan.Contains("VD")
MessageBox.Show("Garder les valeurs par défaut ?", "", MessageBoxButtons.YesNoCancel)
End Select
End If
End Sub
Private Function IsNumGood(ByRef cell As DataGridViewCell, ByVal Dset As DataSet, ByVal table As String) As String ' As Boolean
If String.IsNullOrEmpty(cell.Value.ToString) Then
cell.ErrorText = "Valorisation obligatoire !"
Return "NN" 'Not Nillable
End If
If cell.Value Is ds.Tables(table).Columns(cell.ColumnIndex).DefaultValue Then 'Valeur par défaut
Return "VD" 'Valeur par défaut non changée
End If
cell.ErrorText = ""
Return "OK" ' True
End Function
Private Function IsQuantGood(ByRef cell As DataGridViewCell, ByRef cellLiee As DataGridViewCell) As String 'Boolean
' Toujours tester du plus au moins contraignant.
If Not String.IsNullOrEmpty(cell.Value.ToString) And String.IsNullOrEmpty(cellLiee.Value.ToString) Then
cellLiee.ErrorText = "Cellule liée à renseigner !"
Return "L" 'Valeur liée non renseignée
End If
If String.IsNullOrEmpty(cell.Value.ToString) Then
cell.ErrorText = ""
Return "O" 'Valeur Vide acceptable possible
End If
cell.ErrorText = ""
Return "OK" 'True
End Function
Private Function IspUnitGood(ByRef cell As DataGridViewCell, ByRef cellLiee As DataGridViewCell) As String 'Boolean
' Toujours tester du plus au moins contraignant.
MessageBox.Show(cell.Value.ToString)
If Not String.IsNullOrEmpty(cell.Value.ToString) AndAlso Convert.ToDouble(cell.Value) < 0 Then 'TryCast(cell.Value, Double) < 0 Then '
cell.ErrorText = "La valeur ne peut être négative !"
Return "N" 'False
End If
If Not String.IsNullOrEmpty(cell.Value.ToString) And String.IsNullOrEmpty(cellLiee.Value.ToString) Then
cellLiee.ErrorText = "Cellule liée à renseigner !"
Return "L" 'Valeur liée non renseignée
End If
If String.IsNullOrEmpty(cell.Value.ToString) Then
cell.ErrorText = ""
Return "O" 'Valeur Vide acceptable
End If
cell.ErrorText = ""
Return "OK" 'True
End Function |