wayne2017, re-bonjour,
Pour info, tu aurais dû ouvrir cette discussion dans le forum VB.Net
Exemple sur le même principe de ta précédente discussion (Accès BDD).
Public Class Personnel
Public Property Employe As String
Public Property Code As String
Public Property Ref_Projet As String
Public Property Date_demarrage_Projet As Date
Public Property Heures_debut As Date
Public Property Date_fin_Projet As Date
Public Property Heures_fin As Date
Public Property Total_Heures As String
End Class
Option Strict On
Option Explicit On
Imports System.Data.OleDb
Public Class FrmROUGRAPH
Private pathbase As String = Application.StartupPath & "\V_Techno_DB_be.mdb"
Private connStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & pathbase
Private ListePersonnel As List(Of Personnel)
Private da As OleDb.OleDbDataAdapter
Private ds As DataSet = New DataSet
Private dtPersonnel As DataTable = New DataTable("Personnel")
Private Sub FrmROUGRAPH_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Initialize()
End Sub
Sub Initialize()
Using conn As New OleDbConnection(connStr)
conn.Open()
Dim querypersonnel As String = " Select * From [requêteGENERALE] " & _
" Where [Date_demarrage_Projet] Is Not Null And " & _
" [Date_fin_Projet] Is Not Null "
da = New OleDb.OleDbDataAdapter(querypersonnel, conn)
da.Fill(ds, "Personnel")
End Using
dtPersonnel = ds.Tables("Personnel")
' Initialisation DataGridView1
With Me.DataGridView1
.ColumnCount = 6
.Columns(0).Name = "Personnel"
.Columns(1).Name = "Code"
.Columns(2).Name = "Projet"
.Columns(3).Name = "Début Projet"
.Columns(4).Name = "Fin Projet"
.Columns(5).Name = "Total Heures"
.Columns(0).Width = 140
.Columns(3).Width = 100
.Columns(4).Width = 100
.Columns(5).Width = 100
End With
ListePersonnel = (
From row In dtPersonnel.AsEnumerable()
Order By row.Field(Of String)("Nom"), row.Field(Of String)("Prenom"), row.Field(Of String)("Code") Ascending
Select New Personnel With {
.Employe = row.Field(Of String)("Nom") & New String(" "c, 1) & row.Field(Of String)("Prenom"),
.Code = row.Field(Of String)("Code"),
.Ref_Projet = row.Field(Of String)("Ref_Projet"),
.Date_demarrage_Projet = row.Field(Of Date)("Date_demarrage_Projet"),
.Heures_debut = row.Field(Of Date)("Heures_debut"),
.Date_fin_Projet = row.Field(Of Date)("Date_fin_Projet"),
.Heures_fin = row.Field(Of Date)("Heures_fin"),
.Total_Heures = returnTotalHeures(row.Field(Of Date)("Date_demarrage_Projet") & New String(" "c, 1) & _
row.Field(Of Date)("Heures_debut"), _
row.Field(Of Date)("Date_fin_Projet") & New String(" "c, 1) & _
row.Field(Of Date)("Heures_fin"))
}).ToList
For Each item In ListePersonnel
With Me.DataGridView1.Rows
.Add(item.Employe, _
item.Code, _
item.Ref_Projet, _
item.Date_demarrage_Projet.ToString("yyyy/MM/dd") & New String(" "c, 1) & item.Heures_debut.ToString("HH:mm"), _
item.Date_fin_Projet.ToString("yyyy/MM/dd") & New String(" "c, 1) & item.Heures_fin.ToString("HH:mm"), _
item.Total_Heures)
End With
Next
End Sub
Function returnTotalHeures(ByVal debut As String, ByVal fin As String) As String
Dim days As Long = DateDiff(DateInterval.Minute, CDate(debut), CDate(fin))
Dim iSpan As TimeSpan = TimeSpan.FromMinutes(days)
Dim iHour As String = CStr(((iSpan.Days * 24) + iSpan.Hours)).PadLeft(2, "0"c) & " h " & _
iSpan.Minutes.ToString.PadLeft(2, "0"c)
Return iHour
End Function
End Class
jean-marc