-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrmContact.vb
More file actions
326 lines (286 loc) · 13.6 KB
/
FrmContact.vb
File metadata and controls
326 lines (286 loc) · 13.6 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
Imports System.Data.SqlClient
Imports MONIN_CONTACT.dbconnect
Public Class FrmContact
Dim IdEnt As Integer
Dim RS As String
Dim dgActionIndex As DataGridViewRow
Private Sub FrmContact_Load(sender As Object, e As EventArgs) Handles Me.Load
''' DataGridView Contact '''
dgContact.ColumnCount = 8
dgContact.ColumnHeadersVisible = True
dgContact.Columns(0).Visible = False
dgContact.Columns(1).Name = "Titre"
dgContact.Columns(2).Name = "Nom"
dgContact.Columns(3).Name = "Prénom"
dgContact.Columns(4).Name = "Mail"
dgContact.Columns(5).Name = "Tel interne"
dgContact.Columns(6).Name = "Tel portable"
dgContact.Columns(7).Name = "Entreprise"
'''End DataGridView Contact '''
''' DataGridView Action '''
dgAction.ColumnCount = 6
dgAction.ColumnHeadersVisible = True
dgAction.Columns(0).Visible = False
dgAction.Columns(1).Name = "Date Action"
dgAction.Columns(2).Name = "Commentaire"
dgAction.Columns(3).Name = "A Relancer"
dgAction.Columns(4).Name = "Date de Relance"
dgAction.Columns(5).Name = "Type D'action"
'''End DataGridView Action '''
RefreshContact()
cboEntreprise.Text = "Tous les contacts"
''' CbEntreprise load content '''
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT RaisonSociale FROM ENTREPRISE"
reader = cmd.ExecuteReader()
While (reader.Read)
cboEntreprise.Items.Add(reader.GetValue(0))
End While
reader.Close()
cnn.Close()
'''END CbEntreprise load content '''
'''LoadAction '''
If (cnn.State = ConnectionState.Closed) Then
dgAction.Rows.Clear()
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 = '" & dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
'''END LoadAction '''
End Sub
''' Filtre combobox entreprise '''
Private Sub cboEntreprise_SelectedIndexChanged(sender As Object, e As EventArgs)
End Sub
'''End Filtre combobox entreprise '''
''' Sub refresh datagridview '''
Public Sub RefreshContact()
cnn = New SqlConnection(connectionString)
dgContact.Rows.Clear()
dgContact.Refresh()
dgAction.Rows.Clear()
cnn.Close()
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdContact, Titre, NomContact, PrenomContact, MailContact, TelInterneContact, TelPortable, RaisonSociale FROM CONTACT C, ENTREPRISE E WHERE C.IdEntreprise = E.IdEntreprise"
reader = cmd.ExecuteReader()
While reader.Read
dgContact.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6), reader.GetValue(7))
End While
reader.Close()
cnn.Close()
End Sub
''' End Sub refresh datagridview '''
''' Search txtBox contact '''
Private Sub tbClient_TextChanged(sender As Object, e As EventArgs) Handles tbClient.TextChanged
cboEntreprise.Text = "Tous les contacts"
dgContact.Rows.Clear()
dgContact.Refresh()
dgAction.Rows.Clear()
dgAction.Refresh()
If (cnn.State = ConnectionState.Closed) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdContact, Titre, NomContact, PrenomContact, MailContact, TelInterneContact, TelPortable, RaisonSociale FROM CONTACT C, ENTREPRISE E WHERE C.IdEntreprise = E.IdEntreprise AND NomContact like '" & tbClient.Text & "%'"
reader = cmd.ExecuteReader()
While reader.Read
dgContact.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6), reader.GetValue(7))
End While
reader.Close()
cnn.Close()
End If
If (cnn.State = ConnectionState.Closed And dgContact.RowCount > 0) Then
dgAction.Rows.Clear()
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 = '" & dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
End Sub
''' End Search txtBox contact '''
''' Remove Filtre Entreprise '''
Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs)
cboEntreprise.Text = ""
RefreshContact()
End Sub
'''End Remove Filtre Entreprise '''
''' On select row on datagridview contact '''
Private Sub dgContact_SelectionChanged(sender As Object, e As EventArgs) Handles dgContact.SelectionChanged
If (cnn.State = ConnectionState.Closed) Then
dgAction.Rows.Clear()
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 = '" & dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
End Sub
''' End On select row on datagridview contact '''
''' Btn Add Contact '''
Private Sub btnAddContact_Click(sender As Object, e As EventArgs) Handles btnAddContact.Click
FrmAddContact.Show()
End Sub
''' End Btn Add Contact '''
''' Btn Update Contact '''
Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
If dgContact.RowCount > 0 Then
FrmUpdateContact.Show()
Else
MsgBox("Veuillez sélectionné un contact", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Update Contact '''
''' Btn Del Contact '''
Private Sub btnDelContact_Click(sender As Object, e As EventArgs) Handles btnDelContact.Click
If dgContact.RowCount > 0 Then
Dim response = MsgBox("Voulez-vous vraiment supprimer le contact ?", vbCritical + vbYesNo, "Attention /!\")
If (response = vbYes) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM CONTACT WHERE IdContact = '" & dgContact.CurrentRow.Cells(0).Value & "'"
cmd.ExecuteNonQuery()
cnn.Close()
RefreshContact()
End If
Else
MsgBox("Veuillez sélectionné un contact", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Del Contact '''
'''Btn Add Action '''
Private Sub btnAddAction_Click(sender As Object, e As EventArgs) Handles btnAddAction.Click
FrmAddAction.Show()
End Sub
''' End Btn Add Action '''
''' Btn Del Action '''
Private Sub BtnDelAction_Click(sender As Object, e As EventArgs) Handles BtnDelAction.Click
If dgAction.RowCount > 0 Then
Dim response = MsgBox("Voulez-vous vraiment supprimer l'action sélectionné ?", vbCritical + vbYesNo, "Attention /!\")
If (response = vbYes) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "DELETE FROM ACTION WHERE IdAction = '" & dgAction.CurrentRow.Cells(0).Value & "'"
cmd.ExecuteNonQuery()
cnn.Close()
dgActionIndex = dgAction.CurrentRow
dgAction.Rows.Remove(dgActionIndex)
End If
Else
MsgBox("Veuillez sélectionné une action", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
''' End Btn Del Action '''
Private Sub dgContact_Click(sender As Object, e As EventArgs) Handles dgContact.Click
If (cnn.State = ConnectionState.Closed) Then
dgAction.Rows.Clear()
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 = '" & dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
End If
End Sub
''' Btn Update Contact '''
Private Sub btnEditAction_Click(sender As Object, e As EventArgs) Handles btnEditAction.Click
If dgAction.RowCount > 0 Then
FrmUpdateAction.Show()
Else
MsgBox("Veuillez sélectionné une action", vbOKOnly & vbCritical, "Impossible")
End If
End Sub
Private Sub cboEntreprise_SelectedIndexChanged_1(sender As Object, e As EventArgs) Handles cboEntreprise.SelectedIndexChanged
dgContact.Rows.Clear()
dgContact.Refresh()
dgAction.Rows.Clear()
dgAction.Refresh()
If cboEntreprise.Text = "Tous les contacts" Then
RefreshContact()
Else
'''SELECT IdEnt '''
Try
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdEntreprise FROM ENTREPRISE WHERE RaisonSociale = '" & cboEntreprise.Text & "'"
reader = cmd.ExecuteReader()
reader.Read()
IdEnt = reader.GetValue(0)
reader.Close()
cnn.Close()
Catch ex As Exception
End Try
'''END SELECT IdEnt '''
'''Content datagridview contact '''
If (cnn.State = ConnectionState.Closed) Then
cnn.Open()
cmd = New SqlCommand()
cmd.Connection = cnn
cmd.CommandText = "SELECT IdContact, Titre, NomContact, PrenomContact, MailContact, TelInterneContact, TelPortable, RaisonSociale FROM CONTACT C, ENTREPRISE E WHERE C.IdEntreprise = E.IdEntreprise AND C.IdEntreprise = '" & IdEnt & "'"
reader = cmd.ExecuteReader()
While (reader.Read)
dgContact.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5), reader.GetValue(6), reader.GetValue(7))
End While
reader.Close()
cnn.Close()
End If
'''END Content datagridview contact '''
'''Content datagridview action '''
If (cnn.State = ConnectionState.Closed) Then
Try
dgAction.Rows.Clear()
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 = '" & dgContact.CurrentRow.Cells(0).Value & "'"
reader = cmd.ExecuteReader()
While reader.Read
dgAction.Rows.Add(reader.GetValue(0), reader.GetValue(1), reader.GetValue(2), reader.GetValue(3), reader.GetValue(4), reader.GetValue(5))
End While
dgAction.AutoResizeColumns()
reader.Close()
cnn.Close()
Catch ex As Exception
End Try
End If
'''END Content datagridview action '''
End If
End Sub
''' End Btn Update Contact '''
End Class