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
| Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Déclaration des variables de transfert
Dim NCONTRAT As String
Dim VERSION As String
Dim TRANSFERT1 As String
Dim TRANSFERT2 As String
Dim NBLIGNE As Integer
Dim METIER As String
Dim MISSION As String
Dim LIGNE As String
'ProgressBar1.Visible = True
'Comptage du nombre de ligne a creer dans le Gridview 2 ( identique à celui du premier )
Dim COMPT As Integer = Convert.ToInt16(DataGridView1.Rows.Count) ' récupèretion du nombre de Ligne
' la Boucle de récupération par fichier
For X As Integer = 0 To COMPT - 1
' Barre de progression
CALCUL = (X / (COMPT - 1)) * 100
ProgressBar1.Value = CALCUL
Dim CHEMIN As String = Convert.ToString(DataGridView1.Rows(X).Cells(6).Value)
' Connexion fichier excel sans ouverture et recuperation de la feuille saisie dans une table d'un Datatset1
Dim MYCONNECTION As System.Data.OleDb.OleDbConnection
Dim MYCOMMAND As System.Data.OleDb.OleDbDataAdapter
MYCONNECTION = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & CHEMIN & ";Extended Properties='Excel 8.0;HDR=No;IMEX=1'")
MYCOMMAND = New System.Data.OleDb.OleDbDataAdapter("select F31, F35 from [Saisie$]", MYCONNECTION)
MYCONNECTION.Open()
MYCOMMAND.Fill(DATASET1)
MYCONNECTION.Close()
BIBLIODataSet.RECEPTIONS.AcceptChanges()
RECEPTIONSTableAdapter.update(BIBLIODataSet)
'Detection si le fichier est de la nouvelle ou ancienne version
VERSION = Convert.ToString(DATASET1.Tables(0).Rows(17).Item("F35"))
If VERSION.Length > 7 And VERSION <> "" Then
VERSION = VERSION.Substring(0, 7)
NCONTRAT = "RIEN"
Else
NCONTRAT = Convert.ToString(DATASET1.Tables(0).Rows(0).Item("F31"))
End If
DATASET1.Clear()
' Chargement de la feuille de Mission
MYCONNECTION = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & CHEMIN & ";Extended Properties='Excel 8.0;HDR=yes'")
MYCOMMAND = New System.Data.OleDb.OleDbDataAdapter("select * from [Annexe1$DR:DU]", MYCONNECTION)
MYCONNECTION.Open()
MYCOMMAND.Fill(BIBLIODataSet.RECEPTIONS)
MYCONNECTION.Close()
NBLIGNE = Convert.ToInt64(BIBLIODataSet.RECEPTIONS.Rows.Count) - 1
For Y As Integer = 0 To NBLIGNE
METIER = Convert.ToString(BIBLIODataSet.RECEPTIONS.Rows(Y).Item("Metier"))
MISSION = Convert.ToString(BIBLIODataSet.RECEPTIONS.Rows(Y).Item("Mission"))
LIGNE = Convert.ToString(BIBLIODataSet.RECEPTIONS.Rows(Y).Item("Ligne"))
TRANSFERT2 = Convert.ToString(BIBLIODataSet.RECEPTIONS.Rows(Y).Item("Libellé"))
If Not METIER = "" Then
TRANSFERT1 = METIER & MISSION & LIGNE
BIBLIODataSet.MISSIONS.Rows.Add(NCONTRAT, TRANSFERT1, TRANSFERT2)
BIBLIODataSet.MISSIONS.AcceptChanges()
DataGridView2.DataSource = BIBLIODataSet.MISSIONS
End If
Next Y
Next X
Dim MYCONNECTION2 As System.Data.OleDb.OleDbConnection
Dim MYCOMMAND2 As System.Data.OleDb.OleDbDataAdapter
MYCONNECTION2 = New System.Data.OleDb.OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Eric\Documents\Visual Studio 2012\Projects\LiensBiblio\LiensBiblio\Bilio.mdb'")
MYCOMMAND2 = New System.Data.OleDb.OleDbDataAdapter("select * from MISSIONS ", MYCONNECTION2)
MYCONNECTION2.Open()
MYCOMMAND2.Update(BIBLIODataSet.MISSIONS)
MYCONNECTION2.Close()
End Sub |
Partager