Exercice Visual Basic : Gestion Commerciale

Ecrire le code VB qui permet de réaliser l'interface suivante:

Avant de commancer la programmation il faut créer une Base de Donnée avec les champs cités dans l'interface

ExerciceVB-id2136


 

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
Imports System.Data.SqlClient
 
Public Class Form1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            tecli()
            ds.Clear()
            cn.Open()
            da = New SqlDataAdapter("select * from Client", cn)
            da.TableMappings.Add("Client", "Client")
            da.Fill(ds, "Client")
            bind.DataSource = ds.Tables("Client")
            DataGridView1.DataSource = bind
            cn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
    End Sub
 
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If MsgBox("Voulez vous vraimment quitter l'application", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
            End
        End If
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            da.InsertCommand = New SqlCommand("insert into Client (NumCli, NomCli, AdrCli, VilCli, TelCli) values(@a, @b, @c, @d, @e)", cn)
            da.InsertCommand.Parameters.Add("@a", SqlDbType.Int, "NumCli")
            da.InsertCommand.Parameters.Add("@b", SqlDbType.Char, "NomCli")
            da.InsertCommand.Parameters.Add("@c", SqlDbType.VarChar, "AdrCli")
            da.InsertCommand.Parameters.Add("@d", SqlDbType.Char, "VilCli")
            da.InsertCommand.Parameters.Add("@e", SqlDbType.Text, "TelCli")
            dr = dt.NewRow
            dr("NumCli") = txtnum.Text
            dr("NomCli") = txtnom.Text
            dr("AdrCli") = txtad.Text
            dr("VilCli") = txtvil.Text
            dr("TelCli") = txttel.Text
            Try
                dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)}
                dt.Rows.Add(dr)
            Catch ex As Exception
                MsgBox("Ce client est déjà dans la liste")
                Exit Sub
            End Try
            da.Update(ds, "Client")
            MsgBox("Ajout avec succes")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
 
    End Sub
 
    Private Sub txtvil_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtvil.TextChanged
 
    End Sub
End Class
 
-------------------------------------------------------------------------------
 
 
Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlDataAdapter
Imports System.Data
Module esseyer
    Public pos As Integer
    Public cn As New SqlConnection("datasource=PC-DE-COMPAQ\SQLEXPRESS; initial catalog=GESTION_COMMERCIALE; integrated security=true")
    Public cmd As SqlCommand
    Public da As SqlDataAdapter
    Public ds As New DataSet
    Public dt As New DataTable
    Public dr As DataRow
    Public bind As New BindingSource
    Public dtr As SqlDataReader
    Sub tecli()
        da = New SqlDataAdapter("select * from Client", cn)
        da.Fill(ds, "Client")
        dt = ds.Tables("Client")
        dt.PrimaryKey = New DataColumn() {dt.Columns.Item(0)}
    End Sub
End Module

Lire aussi

  • Exercice Visual Basic : Adhérant
  • Exercice Visual Basic : Gestion Magasin
  • Exercice Visual Basic : Mode connecté
  • Exercice Visual Basic : EFF TSDI Juin 2008 Variante 1
  • Exercice Visual Basic : Voyage
  • Exercice Visual Basic : EFF TSDI Session Juin 2008 Variante 2
  • Exercice Visual Basic : ListBox
  • x