-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrmUpdateAction.vb
More file actions
95 lines (82 loc) · 4.13 KB
/
Copy pathFrmUpdateAction.vb
File metadata and controls
95 lines (82 loc) · 4.13 KB
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
Imports MONIN_CONTACT.dbconnect
Imports MONIN_CONTACT.FrmContact
Imports System.Data.SqlClient
Public Class FrmUpdateAction
Dim IdT As Integer
Private Sub FrmUpdateAction_Load(sender As Object, e As EventArgs) Handles MyBase.Load
cnn = New SqlConnection(connectionString)
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT * FROM TYPE_ACTION"
reader = cmd.ExecuteReader()
While (reader.Read)
cbTypeAction.Items.Add(reader.GetValue(1))
End While
reader.Close()
cnn.Close()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdAction, Commentaire, ARelancer, DateRelance, LibTypeAction FROM ACTION A, TYPE_ACTION T WHERE A.IdTypeAction = T.IdTypeAction AND IdAction ='" & FrmContact.dgAction.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
reader.Read()
tbCom.Text = reader.GetValue(1)
cbTypeAction.Text = reader.GetValue(4)
cbARelancer.Text = reader.GetValue(2)
DateTimePicker1.Value = reader.GetValue(3)
reader.Close()
cnn.Close()
End Sub
Private Sub btnValidAction_Click(sender As Object, e As EventArgs) Handles btnValidAction.Click
If tbCom.Text = "" Or cbARelancer.Text = "" Or cbTypeAction.Text = "" Then
lblMsg.Text = "Erreur : Champs vides"
lblMsg.ForeColor = Color.Red
Else
tbCom.Text = tbCom.Text.Replace("'", "''")
cbARelancer.Text = cbARelancer.Text.Replace("'", "''")
cbTypeAction.Text = cbTypeAction.Text.Replace("'", "''")
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT A.IdTypeAction FROM ACTION A, TYPE_ACTION T WHERE T.IdTypeAction = A.IdTypeAction AND LibTypeAction = '" & cbTypeAction.Text & "'"
reader = cmd.ExecuteReader()
reader.Read()
IdT = reader.GetValue(0)
reader.Close()
cnn.Close()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "UPDATE ACTION SET dateAction = '" & DateTime.Today & "' , Commentaire = '" & tbCom.Text & "', ARelancer = '" & cbARelancer.Text & "', DateRelance = '" & DateTimePicker1.Value.Date & "', IdContact = '" & FrmContact.dgContact.CurrentRow.Cells(0).Value & "', IdTypeAction = '" & IdT & "' WHERE IdAction = '" & FrmContact.dgAction.CurrentRow.Cells(0).Value & "'"
cmd.ExecuteNonQuery()
cnn.Close()
MsgBox("Modification de l'action réussi", vbOKOnly & vbInformation, "Information")
FrmContact.dgAction.Rows.Clear()
FrmContact.dgAction.Refresh()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdAction, DateAction, Commentaire, ARelancer, DateRelance, LibTypeAction FROM ACTION A, TYPE_ACTION T WHERE A.IdTypeAction = T.IdTypeAction AND IdContact = '" & FrmContact.dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
FrmContact.dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
FrmContact.dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
tbCom.Clear()
cbTypeAction.Text = ""
cbARelancer.Text = ""
DateTimePicker1.ResetText()
Me.Close()
End If
End Sub
Private Sub DateTimePicker1_ValueChanged(sender As Object, e As EventArgs) Handles DateTimePicker1.ValueChanged
If DateTimePicker1.Value.Date < DateTime.Today Then
lblMsg.Text = "Erreur : La date ne peut pas être inférieur à la date d'aujourd'hui"
lblMsg.ForeColor = Color.Red
DateTimePicker1.Value = DateTime.Today
End If
End Sub
End Class