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
| Public Class Absence1
Dim Durée(3), NbJours, Nb1, Date2, Jour, NbOuvré, DateEnCours, Fériés(10), NbFériés, Test
Dim JourValide(2), DuréeAbsence(2)
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Initialisation des champs du formulaire
Me.Label1.Text = NomAgent
Me.DateTimePicker1.Value = Today
Me.DateTimePicker2.Value = Today
Me.ListBox1.Items.Clear()
'Chargement en mémoire des durées par type d'absence
Conn.Open(ChaineConnexion)
Rst = New ADODB.Recordset
Rst.CursorLocation = 3
Rst.CursorType = 0
Rst.LockType = 1
Rst.Open("Select * from [Durées]", Conn)
If Rst.RecordCount = 0 Then
Rst.Close()
Conn.Close()
Exit Sub
End If
ReDim Durée(Rst.RecordCount)
For i = 1 To Rst.RecordCount
Durée(i) = Rst(1).Value
Me.ListBox1.Items.Add(Rst(0).Value)
Rst.MoveNext()
Next
Rst.Close()
'Chargement en mémoire des jours féries
Rst = New ADODB.Recordset
Rst.CursorLocation = 3
Rst.CursorType = 0
Rst.LockType = 1
Rst.Open("Select * from [Férié] ORDER BY Férié", Conn)
If Rst.RecordCount = 0 Then
Rst.Close()
Conn.Close()
Exit Sub
End If
NbFériés = Rst.RecordCount
ReDim Fériés(NbFériés)
For i = 1 To NbFériés
Fériés(i) = Rst(0).Value
Rst.MoveNext()
Next
Rst.Close()
Conn.Close()
CalculJours()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim ChaineRecherchée
Conn.Open(ChaineConnexion)
Rst = New ADODB.Recordset
Rst.CursorLocation = 3
Rst.CursorType = 0
Rst.LockType = 1
For i = 0 To Nb1
Date2 = DateAdd("d", i, DateTimePicker1.Value)
DateEnCours = Format(Date2, "dd/MM/yyyy")
Test = True
For j = 1 To NbFériés
If DateEnCours = Fériés(j) Then Test = False : Exit For
Next
Jour = Format(Date2, "dddd")
If Jour <> "samedi" And Jour <> "dimanche" And Test Then
ChaineRecherchée = Year(Date2) & "-" & Date2.DayOfYear & "-" & _
Format(NumAgent, "00") & "-%"
Rst.Open("Select * from [Base] WHERE Code LIKE'" & ChaineRecherchée & "'", Conn, ADODB.CursorTypeEnum.adOpenDynamic, _
ADODB.LockTypeEnum.adLockOptimistic)
Select Case Rst.RecordCount
Case 0
Rst.AddNew()
Rst(0).Value = Year(Date2) & "-" & Date2.DayOfYear & "-" & _
Format(NumAgent, "00") & "-01"
Rst(1).Value = Format(Date2, "ddd/MM/yyyy")
Rst(3).Value = ListBox1.Items(ListBox1.SelectedIndex)
Rst(4).Value = Durée(ListBox1.SelectedIndex + 1)
Rst.Update()
Case Else
Rst.Sort = "Code"
Rst.MoveLast()
If Rst(2).Value Is DBNull.Value Then
Rst(2).Value = Format(Now, "g")
Rst.Update()
Texte = "Fin du service : "
Son = "BeepOkFin"
Else
Numpointage = Rst.RecordCount + 1
Rst.AddNew()
Rst(0).Value = Year(Date2) & "-" & Date2.DayOfYear & "-" & _
Format(NumAgent, "00") & "-" & Format(CInt(Numpointage), "00")
Rst(1).Value = Format(Date2, "ddd/MM/yyyy")
Rst(3).Value = ListBox1.Items(ListBox1.SelectedIndex)
Rst(4).Value = Durée(ListBox1.SelectedIndex + 1)
Rst.Update()
End If
End Select
End If
Rst.Close()
Next
Conn.Close()
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Label3.Text = Durée(ListBox1.SelectedIndex + 1) & " heures/Jour"
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
CalculJours()
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
CalculJours()
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
CalculJours()
End Sub
Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
CalculJours()
End Sub
Private Sub CalculJours()
NbOuvré = 0
Nb1 = DateDiff(DateInterval.Day, DateTimePicker1.Value, DateTimePicker2.Value) + 1
ReDim JourValide(Nb1)
ReDim DuréeAbsence(Nb1)
For i = 0 To Nb1 - 1
Date2 = DateAdd("d", i, DateTimePicker1.Value)
DateEnCours = Format(Date2, "dd/MM/yyyy")
Test = True
For j = 1 To NbFériés
If DateEnCours = Fériés(j) Then Test = False : Exit For
Next
Jour = Format(Date2, "dddd")
If Jour <> "samedi" And Jour <> "dimanche" And Test Then
NbOuvré = NbOuvré + 1
JourValide(i) = DateEnCours
DuréeAbsence(i) = Durée(ListBox1.SelectedIndex + 1)
If RadioButton2.Checked = True And i = 0 Then NbOuvré = NbOuvré - 0.5
If RadioButton3.Checked = True And i = Nb1 Then NbOuvré = NbOuvré - 0.5
End If
Next
Label2.Text = NbOuvré & " jours"
End Sub
Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged
CalculJours()
End Sub
Private Sub DateTimePicker2_ValueChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
CalculJours()
End Sub
End Class |
Partager