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
|
Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ajd = System.DateTime.Now
'Dim configpath As String
'Dim mypath As String
configpath = Application.StartupPath & "\Path.txt"
Try
If File.Exists(configpath) = False Then
OpenFileDialog1.FileName = "Path.txt"
OpenFileDialog1.DefaultExt = ".txt"
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
OpenFileDialog1.RestoreDirectory = False
OpenFileDialog1.InitialDirectory = "..\"
configpath = OpenFileDialog1.FileName
Else : Exit Sub
End If
End If
mypath = File.ReadAllText(configpath)
If mypath = "" Then
OpenFileDialog1.FileName = "db1.mdb"
OpenFileDialog1.DefaultExt = ".mdb"
If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
OpenFileDialog1.RestoreDirectory = True
mypath = OpenFileDialog1.FileName
File.WriteAllText(configpath, mypath)
Else : Exit Sub
End If
End If
Catch ex As Exception
End Try
strConn = "Provider=Microsoft.jet.OLEDB.4.0;Data Source= " & mypath & ";"
objetConnection = New OleDbConnection()
objetConnection.ConnectionString = strConn
objetConnection.Open()
Requetes()
objetDataAdapter.Dispose()
objetConnection.Close()
Dim res = From elt In tablectrl
Where elt.Field(Of String)("Début CJ") < ajd And elt.Field(Of String)("Fin") > ajd
Select elt
For Each p In res
ListBox1.Items.Add(p("Nom").ToString & " " & p("Prénom").ToString)
Next
end sub
Public Sub nouvelle_fiche()
If IsDate(Contacts_Form.Deb_DateTimePicker.Text) = False Then
MsgBox("Saisissez une date de début de CJ valide")
Exit Sub
End If
If IsDate(Contacts_Form.Fin_DateTimePicker.Text) = False Then
MsgBox("Saisissez une date de fin de CJ valide")
Exit Sub
End If
If IsNumeric(Contacts_Form.Freq_TextBox.Text) = False Then
MsgBox("Saisissez une fréquence de côntrôle valide")
Exit Sub
End If
Dim maLigne As DataRow = monDataset.Tables("Fiche").NewRow
maLigne("Nom") = Contacts_Form.Nom_TextBox.Text
maLigne("Date_de_naissance") = CType(Contacts_Form.DateN_TextBox.Text, Date)
maLigne("Prénom") = Contacts_Form.Prenom_TextBox.Text
maLigne("Adresse") = Contacts_Form.Adresse_TextBox.Text
maLigne("Ville") = Contacts_Form.Ville_TextBox.Text
maLigne("Code postal") = Contacts_Form.CP_TextBox.Text
maLigne("Début CJ") = CType(Contacts_Form.Deb_DateTimePicker.Text, Date)
maLigne("Fin") = CType(Contacts_Form.Fin_DateTimePicker.Text, Date)
maLigne("Fréquence") = CType(Contacts_Form.Freq_TextBox.Text, Double)
maLigne("Motif suivi") = Contacts_Form.Motif_TextBox.Text
maLigne("Personne référente") = Contacts_Form.Ref_TextBox.Text
maLigne("Mail") = Contacts_Form.Mail_TextBox.Text
maLigne("Téléphone") = Contacts_Form.Tel_TextBox.Text
monDataset.Tables("Fiche").Rows.Add(maLigne)
'Try
objetCommand = New OleDbCommand(strSql)
objetCommand.Connection() = objetConnection
objetDataAdapter.SelectCommand = objetCommand
objetCommandBuilder = New OleDb.OleDbCommandBuilder(objetDataAdapter)
objetDataAdapter.InsertCommand = objetCommandBuilder.GetInsertCommand
objetDataAdapter.Update(monDataset, "Fiche")
monDataset.Clear()
objetDataAdapter.Fill(monDataset, "Fiche")
tableFiches = monDataset.Tables("Fiche")
'Catch ex As Exception
'End Try
End Sub
Public Sub Requetes()
strSql = "SELECT * FROM Fiche"
objetCommand = New OleDbCommand(strSql)
objetDataAdapter = New OleDbDataAdapter(objetCommand)
objetCommand.Connection() = objetConnection
objetDataAdapter.Fill(monDataset, "Fiche")
tableFiches = monDataset.Tables("Fiche")
strSql2 = "SELECT * FROM Suivi"
objetCommand = New OleDbCommand(strSql2)
objetDataAdapter = New OleDbDataAdapter(objetCommand)
objetCommand.Connection() = objetConnection
objetDataAdapter.Fill(monDataset, "Suivi")
tableFiches = monDataset.Tables("Suivi")
End Sub |