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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
|
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.OleDb
Imports System
Imports Microsoft.VisualBasic
Public Class Form1
Public myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myConnexion.Open()
'met à jour notre base de données
MaJ_BDD()
'TODO: cette ligne de code charge les données dans la table 'Map_DataSet.RCs'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
Me.RCsTableAdapter.Fill(Me.Map_DataSet.RCs)
'TODO: cette ligne de code charge les données dans la table 'Map_DataSet.Realized_Intention'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
Me.Realized_IntentionTableAdapter.Fill(Me.Map_DataSet.Realized_Intention)
'TODO: cette ligne de code charge les données dans la table 'Map_DataSet.Sections'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
Me.SectionsTableAdapter.Fill(Me.Map_DataSet.Sections)
'TODO: cette ligne de code charge les données dans la table 'Map_DataSet.Executed_sections'. Vous pouvez la déplacer ou la supprimer selon vos besoins.
Me.Executed_sectionsTableAdapter.Fill(Me.Map_DataSet.Executed_sections)
MaJ_Candidate_section()
End Sub
Public Sub NewRealizedIntention_enreg()
Dim sql_LastRC_id As Integer
'Dim recup_LastRc_id As Integer
'Recupere_Last_RC_id(sql_LastRC_id)
sql_LastRC_id = Recupere_Last_RC_id()
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand2 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
'on creer une variable pour recuperer la donnée rechercher
Dim sql_I_id As Integer
Dim sql_I_id_string As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(3).Value)
myCommand1.CommandText = "Select I_id from Intentions where I_name='" & sql_I_id_string & "';"
myCommand1.Connection = myConnexion
'myconnexion.open()
sql_I_id = CInt(myCommand1.ExecuteScalar())
'on implement notre commande
myCommand.CommandText = "insert into Realized_Intention(I_id,RC_id) values ('" & sql_I_id & "', '" & sql_LastRC_id & "');"
myCommand.Connection = myConnexion
Try
'ouvre la connexion a la bdd
''myconnexion.open()
'execute notre commande
myCommand.ExecuteNonQuery()
'ensuite je recupere le RI_id que je viens d'inserer pour lui attribuer un Name
Dim sql_LastRI_id As Integer
Dim recup_LastRi_id As Integer
Dim sql_RI_name As String
sql_LastRI_id = Recuper_Last_RI_id(recup_LastRi_id)
sql_RI_name = "RI_" + sql_LastRI_id.ToString()
' et je refait une requete insert pour inserer le name
myCommand2.CommandText = "Update Realized_Intention set RI_name='" & sql_RI_name & "' where RI_id= " & sql_LastRI_id & ";"
myCommand2.Connection = myConnexion
myCommand2.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
'TODO: cette ligne de code (re)charge les données dans la table 'Map_DataSet.Realized_Intention'.
Me.Realized_IntentionTableAdapter.Fill(Me.Map_DataSet.Realized_Intention)
'on rafraichit le tableau pour afficher nos nouvelles données
DataGrid_RealizedIntention.Refresh()
End Sub
Private Sub NewExecutedSections_enreg()
' le boolean fin permet de savoir si on a executer la section qui met fin au processus ou non
' on l'initialise donc a false
' Dim fin As Boolean
'on ajout un enregistrment dans le trace
Dim sql_LastRI_id As String
Dim recup_LastRi_id As Integer
Dim int_LastRI_id As Integer
'Recupere_Last_RI_id(sql_LastRI_id)
int_LastRI_id = Recuper_Last_RI_id(recup_LastRi_id)
sql_LastRI_id = "RI_" + int_LastRI_id.ToString()
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand2 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand3 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand4 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand5 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
'on creer une variable pour recuperer la donnée rechercher
Dim sql_RI_source As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(0).Value)
myCommand5.CommandText = "Select RI_id from Realized_Intention where RI_name='" & sql_RI_source & "';"
myCommand5.Connection = myConnexion
'myconnexion.open()
Dim intRI_id As Integer = CInt(myCommand5.ExecuteScalar())
myCommand5.CommandText = "Select I_id from Realized_Intention where RI_name='" & sql_RI_source & "';"
Dim intI_id As Integer = CInt(myCommand5.ExecuteScalar())
Try
'je recupere le strat_id de la strategie candidate choisi
'plusieurs strategie pouvant avoir le meme nom il me faut alors recuperer aussi l'argument Intention source
'pour determiner de quel strategie il s'agit vraiment
Dim string_strat_name As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(2).Value)
myCommand.CommandText = " Select Strategies.Strat_id from Strategies,Sections where Strategies.Strat_id=Sections.Strat_id and Sections.[I_id-source]=" & intI_id & " and Strategies.Strat_name='" & string_strat_name & "';"
myCommand.Connection = myConnexion
Dim intStrat_id As Integer = CInt(myCommand.ExecuteScalar())
'on recupere le RC en entrer
Dim string_RC_id_in As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(4).Value)
myCommand1.CommandText = "Select RC_id from RCs where RC_name='" & string_RC_id_in & "';"
myCommand1.Connection = myConnexion
Dim int_RC_id_in As Integer = CInt(myCommand1.ExecuteScalar())
' on recuperer le RC qu'on a génere suite a l'éxecution d'une section
Dim int_LastRc_id As Integer
'Dim recup_last_Rc_id As Integer
int_LastRc_id = Recupere_Last_RC_id()
'on implement notre commande
myCommand2.CommandText = "insert into Executed_sections(RI_id_source,RI_id_target,Strat_id,[RC_id-in], [RC_id-out]) values ('" & intRI_id & "','" & int_LastRI_id & "', '" & intStrat_id & "', '" & int_RC_id_in & "', '" & int_LastRc_id & "');"
myCommand2.Connection = myConnexion
'execute notre commande
myCommand2.ExecuteNonQuery()
'on va verifie si la section qu'on viens d'executé est multiple ou non,
myCommand3.CommandText = "SELECT Strategies.Multiple FROM Strategies, Executed_sections where Strategies.Strat_id = Executed_sections.Strat_id AND Executed_sections.Strat_id=" & intStrat_id & ";"
myCommand3.Connection = myConnexion
Dim sql_multiple As Boolean = CBool(myCommand3.ExecuteScalar())
'si elle n'est pas multiple alors on met a oui le champs Executed de la tables Sections
'pour cela d'abord on va recuperer les valeurs de la section qu'on veut modififer
'pour LE I_id_Source
Dim I_id_Source As Integer
Dim myCom_I_id_Source As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCom_I_id_Source.Connection = myConnexion
myCom_I_id_Source.CommandText = "select Sections.[I_id-source] from Sections, Executed_sections, Realized_Intention, Intentions where Executed_Sections.RI_id_source=Realized_Intention.RI_id And Realized_Intention.I_id=Intentions.I_id And Intentions.I_id=Sections.[I_id-source] And Executed_Sections.RI_id_source=" & intRI_id & ";"
I_id_Source = CInt(myCom_I_id_Source.ExecuteScalar())
'pour le Strat_id
Dim I_Strat_id As Integer
Dim myCom_Strat_id As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCom_Strat_id.Connection = myConnexion
myCom_Strat_id.CommandText = "SELECT distinct Sections.Strat_id FROM Strategies, Sections,Executed_sections WHERE Sections.Strat_id=Strategies.Strat_id AND Strategies.Strat_id = Executed_sections.Strat_id AND Executed_sections.Strat_id=" & intStrat_id & ";"
I_Strat_id = CInt(myCom_Strat_id.ExecuteScalar())
'pour le I_id_target
Dim I_id_Target As Integer
Dim myCom_I_id_Target As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCom_I_id_Target.Connection = myConnexion
myCom_I_id_Target.CommandText = "select Distinct Sections.[I_id-target] from Sections, Executed_sections, Realized_Intention, Intentions where Executed_Sections.RI_id_target=Realized_Intention.RI_id And Realized_Intention.I_id=Intentions.I_id And Intentions.I_id=Sections.[I_id-target] And Executed_Sections.RI_id_target=" & int_LastRI_id & ";"
I_id_Target = CInt(myCom_I_id_Target.ExecuteScalar())
'on indique que la section a été exécuté
myCommand4.CommandText = "Update Sections set Executed=yes where [I_id-source]=" & I_id_Source & " And Strat_id= " & I_Strat_id & " and [I_id-target]=" & I_id_Target & ";"
myCommand4.Connection = myConnexion
'ouvre la connexion a la bdd
'execute notre commande
myCommand4.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
'TODO: cette ligne de code (re)charge les données dans la table 'Map_DataSet.Executed_sections'.
Me.Executed_sectionsTableAdapter.Fill(Me.Map_DataSet.Executed_sections)
'TODO: cette ligne de code (re)charge les données dans la table 'Map_DataSet.sections'.
Me.SectionsTableAdapter.Fill(Me.Map_DataSet.Sections)
'on rafraichit le tableau pour afficher nos nouvelles données
DataGrid_ExeSection.Refresh()
DataGrid_Sections.Refresh()
End Sub
Public Sub NewRCs_enreg(ByVal int_strat_id As Integer)
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand2 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand.Connection = myConnexion
Try
'on implement notre commande
' on insere une ligne vide afin de cree un nouvel id, ensuite on va recuperer ce nouveau ID pour une donner une Name
myCommand.CommandText = "insert into RCs(RC_name) values ( 'RC_' );"
'ouvre la connexion a la bdd
If myConnexion.State = ConnectionState.Closed Then
'myconnexion.open()
End If
'execute notre commande
myCommand.ExecuteNonQuery()
Dim sql_rcname As String
Dim sql_LastRC_id As Integer = 1
Dim recup_LastRc_id As Integer
recup_LastRc_id = Recupere_Last_RC_id()
sql_rcname = "RC_" + recup_LastRc_id.ToString()
Dim int_G_id As Integer
Dim recup_last_G_id As Integer
recup_last_G_id = Recuper_Last_G_id(int_G_id)
Select Case int_strat_id
Case 1, 3
'int_strat_id=1 OU 3 dc on creer un goal
myCommand2.CommandText = "Update RCs set RC_name='" & sql_rcname & "', G_id=" & recup_last_G_id & " where RC_id= " & recup_LastRc_id & ";"
Case 4, 5
'int_strat_id=1 OU 3 dc on creer un scenario
myCommand2.CommandText = "Update RCs set RC_name='" & sql_rcname & "' where RC_id= " & recup_LastRc_id & ";"
Case 2, 6, 7, 8, 9, 10
'int_strat_id=2,6,7,8,9,10 dc on creer RIEN
myCommand2.CommandText = "Update RCs set RC_name='" & sql_rcname & "' where RC_id= " & recup_LastRc_id & ";"
End Select
myCommand2.Connection = myConnexion
myCommand2.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
Me.RCsTableAdapter.Fill(Me.Map_DataSet.RCs)
End Sub
Public Function Recupere_Last_RC_id() As Integer
Dim Last_RC_id As Integer
'Dim myConnexion As OleDbConnection
Dim myCommand As OleDbCommand
Try
Console.WriteLine("recupere last rc id : debut")
'creer un objet connexion ainsi qu'un objet command
'myConnexion = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
myCommand = New System.Data.OleDb.OleDbCommand()
'on creer une variable pour recuperer la donnée rechercher
' Dim sql_RC_id_last As Integer
myCommand.CommandText = "select max(RC_id) from RCs;"
myCommand.Connection = myConnexion
'ouvre la connexion a la bdd
'myconnexion.open()
'execute notre commande
' sql_RC_id_last = myCommand.ExecuteNonQuery()
Last_RC_id = CInt(myCommand.ExecuteScalar())
Console.WriteLine(Last_RC_id.ToString)
'fermeture de la connexion
'myconnexion.close()
Console.WriteLine("recupere last rc id : fin")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
If Not myConnexion Is Nothing Then
If myConnexion.State = ConnectionState.Open Then
'myconnexion.close()
End If
End If
End Try
Return Last_RC_id
End Function
Public Function Recuper_Last_RI_id(ByVal Last_Ri_id As Integer) As Integer
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
'on creer une variable pour recuperer la donnée rechercher
' Dim sql_RC_id_last As Integer
myCommand.CommandText = "select max(RI_id) from Realized_Intention;"
myCommand.Connection = myConnexion
Try
'ouvre la connexion a la bdd
'myconnexion.open()
'execute notre commande
' sql_RC_id_last = myCommand.ExecuteNonQuery()
Last_Ri_id = CInt(myCommand.ExecuteScalar())
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
Return Last_Ri_id
Debug.Print(CStr(Last_Ri_id))
End Function
Public Function Recuper_Last_G_id(ByVal Last_G_id As Integer) As Integer
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
'on creer une variable pour recuperer la donnée rechercher
' Dim sql_RC_id_last As Integer
myCommand.CommandText = "select max(G_id) from Goals;"
myCommand.Connection = myConnexion
Try
'ouvre la connexion a la bdd
'myconnexion.open()
'execute notre commande
' sql_RC_id_last = myCommand.ExecuteNonQuery()
Last_G_id = CInt(myCommand.ExecuteScalar())
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
Return Last_G_id
End Function
Private Sub MaJ_Candidate_section()
''''''''''''''''''''''''''''Vide la table candidate_section de notre base de données''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
Dim myCommand7 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand7.Connection = myConnexion
myCommand.Connection = myConnexion
'on implement notre commande
myCommand.CommandText = "delete * from Candidate_sections;"
''''''''''''''''''''''''''''Vide la Datagrid candidate_section du Form''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
DataGrid_Candidates.Rows.Clear()
'''''''''''''''''''''''''''avant de calculer les candidates on verifie qu'on a pas executer la strategie qui met fin au process'''''''''''''
'''''''''''''' pour cela on verifie si la section en question a ete executer ou pas
'''''''''''''' si oui alors le processus est terminer et on indique à l'utilisateur que c'est terminé,
'''''''''''''' sinon on continue en calculant les candidates
Dim Section_exe As Boolean
Dim myCom_Section_exe As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCom_Section_exe.Connection = myConnexion
myCom_Section_exe.CommandText = "select Executed from Sections where [I_id-source]=4 And [I_id-target]=5 And Strat_id=10;"
'myconnexion.open()
Section_exe = CBool(myCom_Section_exe.ExecuteScalar())
'myconnexion.close()
If Section_exe = True Then
MsgBox("Vous avez terminé le processus.")
'enlever l'option double click
Else
Try
'ouvre la connexion a la bdd
'myconnexion.open()
'execute notre commande
myCommand.ExecuteNonQuery()
''''''''''''''''''On met à jour notre table Candidate_sections dans notre base de données''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''calcul des candidates''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' la variable x correspond a l'index de la ligne du tableau candidate_section actuel (currentRows)
Dim x As Integer = -1
Dim I_id_sourceDAtaReader As OleDbDataReader
Dim myCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand1.Connection = myConnexion
myCommand1.CommandText = "Select DISTINCT I_id From Realized_Intention;"
I_id_sourceDAtaReader = myCommand1.ExecuteReader()
' Dim sql_I_id_source As Integer
'sql_I_id_source = myCommand.ExecuteNonQuery()
'boucle sur tout les sql_i_id_source
Do While I_id_sourceDAtaReader.Read()
Dim RI_id_datareader As OleDbDataReader
Dim myCommand2 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand2.Connection = myConnexion
myCommand2.CommandText = "Select DISTINCT Realized_Intention.RI_id, Realized_Intention.RI_name From Realized_Intention, Intentions, Sections, Strategies WHERE Realized_Intention.I_id = Intentions.I_id And Intentions.I_id=Sections.[I_id-source] And Sections.Strat_id=Strategies.Strat_id AND Sections.[I_id-source]=" & CInt(I_id_sourceDAtaReader.GetValue(0)) & ";"
' myCommand3.CommandType = CommandType.Text
RI_id_datareader = myCommand2.ExecuteReader()
Do While RI_id_datareader.Read()
Dim I_id_source_C_Datareader As OleDbDataReader
Dim myCommand3 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand3.Connection = myConnexion
myCommand3.CommandText = "Select DISTINCT Realized_Intention.[I_id] , Intentions.[I_name] From Realized_Intention, Intentions WHERE Realized_Intention.[I_id]=Intentions.[I_id] and Realized_Intention.[RI_id]=" & CInt(RI_id_datareader.GetValue(0)) & ";"
I_id_source_C_Datareader = myCommand3.ExecuteReader()
Do While I_id_source_C_Datareader.Read()
Dim ID_strat_datareader As OleDbDataReader
Dim myCommand4 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand4.Connection = myConnexion
myCommand4.CommandText = "SELECT Strategies.Strat_id, Strategies.Strat_name FROM Sections, Strategies WHERE Sections.Strat_id = Strategies.Strat_id AND Sections.[I_id-source]=" & CInt(I_id_source_C_Datareader.GetValue(0)) & " AND Strategies.Multiple=Yes UNION SELECT Strategies.Strat_id , Strategies.Strat_name FROM Sections, Strategies WHERE Sections.Strat_id = Strategies.Strat_id AND Sections.[I_id-source]=" & CInt(I_id_source_C_Datareader.GetValue(0)) & " AND Strategies.Multiple=no AND Sections.Executed=no;"
ID_strat_datareader = myCommand4.ExecuteReader()
Do While ID_strat_datareader.Read()
Dim I_id_target_datareader As OleDbDataReader
Dim myCommand5 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand5.Connection = myConnexion
myCommand5.CommandText = "Select DISTINCT Sections.[I_id-target], Intentions.I_name From Sections , Intentions WHERE Sections.[I_id-target]=Intentions.[I_id] AND Sections.[I_id-source]=" & CInt(I_id_source_C_Datareader.GetValue(0)) & " AND Sections.Strat_id=" & CInt(ID_strat_datareader.GetValue(0)) & ";"
I_id_target_datareader = myCommand5.ExecuteReader()
Do While I_id_target_datareader.Read()
Dim RC_id_datareader As OleDbDataReader
Dim myCommand6 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand6.Connection = myConnexion
myCommand6.CommandText = "Select DISTINCT Realized_Intention.RC_id, RCs.RC_name From Realized_Intention , RCs Where Realized_Intention.RC_id=RCs.RC_id AND RI_id=" & CInt(RI_id_datareader.GetValue(0)) & ";"
RC_id_datareader = myCommand6.ExecuteReader()
RC_id_datareader.Read()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' à ce niveau la, on a recupéré les strategies, les intentions et les produits
' il faut alors verifié si ces strategies ne sont pas exclues suite a une constraints_exclusion
Dim strat_id_constraint As OleDbDataReader
Dim myCommandConstraint As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommandConstraint.Connection = myConnexion
myCommandConstraint.CommandText = "Select Strat_id1, Strat_id2 from Exclusion_constraints where( Strat_id1=" & CInt(ID_strat_datareader.GetValue(0)) & " or Strat_id2=" & CInt(ID_strat_datareader.GetValue(0)) & ");"
strat_id_constraint = myCommandConstraint.ExecuteReader()
Dim boolean_executed As Boolean = False
'on viens de remplir note datareader des resultats de la requete, 3 cas se presente a nous
'1) il n'y a aucune contrainte sur cette strategie donc la requete ne retourne rien et notre datareader est vide
'2) il existe une seule contrainte sur cette strategie ~\ boucle sur le datareader
'3) il exiser plusieurs contrainte sur cette strategie ~/ " "
Dim cas1 As Boolean = False
Dim cas2 As Boolean = False
Dim cas3 As Boolean = False
' If nb_de_ligne <> 0 Then
If strat_id_constraint.HasRows Then
'cas 2 et 3
Do While strat_id_constraint.Read()
'on verifie si les sections auquelle appartiennent ces strategies ont deja ete executé ou non
Dim myCommandExecuted As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommandExecuted.Connection = myConnexion
myCommandExecuted.CommandText = "select distinct executed from (select Executed from Sections where Strat_id=" & CInt(strat_id_constraint(0)) & " or Strat_id=" & CInt(strat_id_constraint(1)) & ") where executed=yes;"
boolean_executed = CBool(myCommandExecuted.ExecuteScalar())
'si elles ont dejà étè executé alors on ne peut pas proposer la strategie initial a l'utilisateur
'sinon on peut lui proposer n'étant pas retenue par la contrainte d'exclusion
If boolean_executed = False Then
'si on se trouve ds cette condition cela veut dire que aucune des 2 strategies n'a jamais été executé
'Dont on peut ajouter la requete dans candidates
cas3 = True
Else
'si on se trouve dans cette condition cela veut dire que l'une des 2 strategies du couple (constraint_exclusion) à deja été
'executé, il faut alors savoir sur quel produit, si le produit et different alors on lui propose ces strategies, sinon rien
Dim RC_id_constraint As OleDbDataReader
Dim myCommand8 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand8.Connection = myConnexion
myCommand8.CommandText = "select distinct [RC_id-in] from Executed_sections where (Strat_id=" & CInt(strat_id_constraint(0)) & " or Strat_id=" & CInt(strat_id_constraint(1)) & ") and [RC_id-in] Is Not Null;"
RC_id_constraint = myCommand8.ExecuteReader()
Do While RC_id_constraint.Read()
'si le produit sur lesquel il y a une contrainte est different du produit de notre précandidate alors on peut l'ajouter aux candidate
If CInt(RC_id_constraint.GetValue(0)) <> CInt(RC_id_datareader.GetValue(0)) Then
cas2 = True
End If
Loop
RC_id_constraint.Close()
End If
Loop
Else
'cas 1
cas1 = True
End If
If cas1 = True Or cas2 = True Or cas3 = True Then
'Dont on peut ajouter la requete dans candidates
myCommand7.CommandText = "insert into Candidate_sections (RI_id, I_id_source, Strat_id, [I_id_target], [RC_id-in]) values (" & CInt(RI_id_datareader.GetValue(0)) & ", " & CInt(I_id_source_C_Datareader.GetValue(0)) & ", " & CInt(ID_strat_datareader.GetValue(0)) & ", " & CInt(I_id_target_datareader.GetValue(0)) & ", " & CInt(RC_id_datareader.GetValue(0)) & ");"
myCommand7.ExecuteNonQuery()
''''''''''''''''''On met à jour notre Dataset Candidate_sections et notre base de données''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'configure le datagrid
'insere dans le datagrid
x = x + 1
DataGrid_Candidates.Rows.Add()
DataGrid_Candidates.Item(0, x).Value = RI_id_datareader.GetValue(1)
DataGrid_Candidates.Item(1, x).Value = I_id_source_C_Datareader.GetValue(1)
DataGrid_Candidates.Item(2, x).Value = ID_strat_datareader.GetValue(1)
DataGrid_Candidates.Item(3, x).Value = I_id_target_datareader.GetValue(1)
DataGrid_Candidates.Item(4, x).Value = RC_id_datareader.GetValue(1)
End If
strat_id_constraint.Close()
'ferme le datareader
RC_id_datareader.Close()
Loop
'ferme le datareader
I_id_target_datareader.Close()
Loop
'ferme le datareader
ID_strat_datareader.Close()
Loop
'ferme le datareader
I_id_source_C_Datareader.Close()
Loop
'ferme le datareader
RI_id_datareader.Close()
Loop
'ferme le datareader
I_id_sourceDAtaReader.Close()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
End If
'fermeture de la connexion
'myconnexion.close()
''''''''''''''''''On met à jour notre Dataset Candidate_sections depuis notre base de données''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Me.Candidate_sectionsTableAdapter.Fill(Me.Map_DataSet.Candidate_sections)
'DataGrid_Candidates.Refresh()
End Sub
Private Sub DataGrid_Candidates_CellDoubleClick1(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGrid_Candidates.CellDoubleClick
'connexion a notre BDD
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Try
'myconnexion.open()
'Selon la strategie executer, on affiche à l'utilisateur la fenêtre correspondante
Dim string_strat_name As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(2).Value)
Dim string_Int_target As String = CStr(DataGrid_Candidates.Rows(DataGrid_Candidates.CurrentCell.RowIndex).Cells(3).Value)
Dim myCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand1.Connection = myConnexion
myCommand1.CommandText = " SELECT Strategies.Strat_id FROM Strategies, Sections, Intentions WHERE Strategies.Strat_id = Sections.Strat_id AND Sections.[I_id-target]=Intentions.I_id AND Intentions.I_name='" & string_Int_target & "' AND Strategies.Strat_name='" & string_strat_name & "';"
Dim int_strat_id As Integer = CInt(myCommand1.ExecuteScalar())
Select Case int_strat_id
Case 1
'int_strat_id=1
Me.Hide()
Form_S1.ShowDialog()
Case 2
'........
End Select
'si la strategie executé est generatrice alors on crée un nouveau produit, sinon on ne crée rien
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand.Connection = myConnexion
myCommand.CommandText = "Select Prod_Generate from Strategies where Strat_name='" & string_strat_name & "';"
Dim Boolean_Strat_id As Boolean = CBool(myCommand.ExecuteScalar())
'donc si le boolean de la strategie= true, alors on genere un nouveau RC, sinon rien
If Boolean_Strat_id = True Then
'appel de la fonction nouvel RCs
NewRCs_enreg(int_strat_id)
End If
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'myconnexion.close()
'appel la fonction nouvel realisation d'intention
NewRealizedIntention_enreg()
'une intention viens d'etre realiser donc il faut l'ajouter dans le trace Sections_Executed
'appel la fonction nouvel execution de section
NewExecutedSections_enreg()
'appel de la fonction mise a jour de la table candidate
MaJ_Candidate_section()
End Sub
Private Sub MaJ_BDD()
''''''''''''''''''''''''''''Vide la table Realized_Intention de notre base de données''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'creer un objet connexion ainsi qu'un objet command
'Dim myConnexion As OleDbConnection = New System.Data.OleDb.OleDbConnection(My.Settings.Map_ConnectionString())
Dim myCommand As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand.Connection = myConnexion
Dim myCommand1 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand1.Connection = myConnexion
Dim myCommand2 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand2.Connection = myConnexion
Dim myCommand3 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand3.Connection = myConnexion
Dim myCommand4 As OleDbCommand = New System.Data.OleDb.OleDbCommand()
myCommand4.Connection = myConnexion
'on implement notre commande
myCommand.CommandText = "Delete * from Candidate_sections;"
myCommand1.CommandText = "Delete * from Realized_Intention where RI_id not in (select min(RI_id) from Realized_Intention);"
myCommand2.CommandText = "Delete * from Executed_sections where exe_sec_id not in (select min(exe_sec_id) from Executed_sections);"
myCommand3.CommandText = " Update Sections set Executed=no;"
myCommand4.CommandText = "Delete * from RCs where RC_id not in (select min(RC_id) from RCs);"
Try
'ouvre la connexion a la bdd
'myconnexion.open()
'execute notre commande
myCommand.ExecuteNonQuery()
myCommand1.ExecuteNonQuery()
myCommand2.ExecuteNonQuery()
myCommand3.ExecuteNonQuery()
myCommand4.ExecuteNonQuery()
Catch ex As OleDb.OleDbException
MessageBox.Show(ex.ToString)
End Try
'fermeture de la connexion
'myconnexion.close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnexion.Close()
Application.Exit()
End Sub
End Class |