Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Démonstration mode déconnecté

Schéma

Script bdd

USE [gestion_vente]
GO
/****** Object: Table [dbo].[vente] Script Date: 11/08/2021 08:45:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[vente](
[numVente] [int] NOT NULL,
[datevente] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[numVente] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[produit] Script Date: 11/08/2021 08:45:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[produit](
[numproduit] [int] NOT NULL,
[libelle] [varchar](25) NULL,
[prix] [money] NULL,
[qteStock] [int] NULL,
PRIMARY KEY CLUSTERED
(
[numproduit] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object: Table [dbo].[lignevente] Script Date: 11/08/2021 08:45:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[lignevente](
[numVente] [int] NOT NULL,
[numproduit] [int] NOT NULL,
[qteVendu] [int] NULL,
PRIMARY KEY CLUSTERED
(
[numVente] ASC,
[numproduit] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: ForeignKey [FK__lignevent__numpr__108B795B] Script Date:
11/08/2021 08:45:34 ******/
ALTER TABLE [dbo].[lignevente] WITH CHECK ADD FOREIGN KEY([numproduit])
REFERENCES [dbo].[produit] ([numproduit])
GO
/****** Object: ForeignKey [FK__lignevent__numVe__0F975522] Script Date:
11/08/2021 08:45:34 ******/
ALTER TABLE [dbo].[lignevente] WITH CHECK ADD FOREIGN KEY([numVente])
REFERENCES [dbo].[vente] ([numVente])
GO

Interface 1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace projet1_2021
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
SqlConnection cnx = new SqlConnection(Properties.Settings.Default.chaine2);
DataSet ds = new DataSet();
SqlDataAdapter da;
private void Form4_Load(object sender, EventArgs e)
{
da = new SqlDataAdapter("select * from produit", cnx);
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds, "prod");
dataGridView1.DataSource = ds.Tables["prod"];
}
//bouton ajouter
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables["prod"].NewRow();
// instancie une nouvelle ligne ayant la structure de la table produit
dr[0] = int.Parse(textBox1.Text);
dr[1] = textBox2.Text;
dr[2] = double.Parse(textBox3.Text);
dr[3] = int.Parse(textBox4.Text);
ds.Tables["prod"].Rows.Add(dr);
MessageBox.Show("bien ajouté");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox1.Focus();
}
// bouton enregistrer
private void button4_Click(object sender, EventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(ds.Tables["prod"]);
MessageBox.Show("bien enregistré");
}
//bouton modifier
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < ds.Tables["prod"].Rows.Count; i++)
{
if (textBox1.Text == ds.Tables["prod"].Rows[i][0].ToString())
{
ds.Tables["prod"].Rows[i][1] = textBox2.Text;
ds.Tables["prod"].Rows[i][2] = double.Parse(textBox3.Text);
ds.Tables["prod"].Rows[i][3] = int.Parse(textBox4.Text);
break;
}
}
MessageBox.Show("bien modifié");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox1.Focus();
}
// bouton supprimer
private void button3_Click(object sender, EventArgs e)
{
int p=-1;
for (int i = 0; i < ds.Tables["prod"].Rows.Count; i++)
{
if (textBox1.Text == ds.Tables["prod"].Rows[i][0].ToString())
{
p = i;
break;
}
}
if (p != -1)
ds.Tables["prod"].Rows[p].Delete();
else
MessageBox.Show("aucune ligne à supprimer!!");

}
}
}

Travail à faire

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace projet1_2021
{
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
SqlConnection cnx = new SqlConnection(Properties.Settings.Default.chaine2);
DataSet ds = new DataSet();
SqlDataAdapter da1, da2, da3;
private void Form5_Load(object sender, EventArgs e)
{
da1 = new SqlDataAdapter("select * from produit",cnx);
da2 = new SqlDataAdapter("select * from vente",cnx);
da3 = new SqlDataAdapter("select * from lignevente",cnx);
da3.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da1.Fill(ds, "prod");
da2.Fill(ds, "vente");
da3.Fill(ds, "lv");
dataGridView1.DataSource = ds.Tables["lv"];
comboBox1.DataSource = ds.Tables["prod"];
comboBox1.DisplayMember = "numproduit";
comboBox2.DataSource = ds.Tables["vente"];
comboBox2.DisplayMember = "numvente";
}
//ajouter
private void button1_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables["lv"].NewRow();
dr[0] = int.Parse(comboBox2.Text);
dr[1] = int.Parse(comboBox1.Text);
dr[2] = int.Parse(textBox1.Text);
ds.Tables["lv"].Rows.Add(dr);
MessageBox.Show("bien ajouté");
}
// bouton modifier
private void button2_Click(object sender, EventArgs e)
{
bool trouve = false;
for(int i=0; i<ds.Tables["lv"].Rows.Count; i++)
{
if (ds.Tables["lv"].Rows[i][0].ToString() == comboBox2.Text
&& ds.Tables["lv"].Rows[i][1].ToString() == comboBox1.Text)
{
ds.Tables["lv"].Rows[i][2] = int.Parse(textBox1.Text);
trouve = true;
break;
}
}
if (trouve)
MessageBox.Show("bien modifié");
else
MessageBox.Show("aucune ligne à modifier ");
}
// bouton supprimer
private void button3_Click(object sender, EventArgs e)
{

int p = -1;
for (int i = 0; i < ds.Tables["lv"].Rows.Count; i++)
{
if (ds.Tables["lv"].Rows[i][0].ToString() == comboBox2.Text
&& ds.Tables["lv"].Rows[i][1].ToString() == comboBox1.Text)
{
ds.Tables["lv"].Rows[i][2] = int.Parse(textBox1.Text);
p = i;
break;
}
}
if (p != -1)
{
ds.Tables["lv"].Rows[p].Delete();
MessageBox.Show("ligne bien supprimé");
}
else
MessageBox.Show("aucune ligne à supprimer");
}
// bouton enregitsrer
private void button4_Click(object sender, EventArgs e)
{
SqlCommandBuilder cb = new SqlCommandBuilder(da3);
da3.Update(ds.Tables["lv"]);
MessageBox.Show("bien enregistré");
}
}
}

You might also like