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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 | Imports System.Data.SqlClientPublic 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 SubEnd Class-------------------------------------------------------------------------------Imports System.Data.SqlClientImports System.Data.SqlClient.SqlDataAdapterImports System.DataModule 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 SubEnd Module |