Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 WindowsFormsApp2
- {
- public partial class Form3 : Form
- {
- public static int ajouterouchoisir = 0;
- public static float prixsomme = 0; //utile pour fidelite windows
- public static int niveaufidelite = 0;//utile pour fidelite windows
- SqlConnection cnn;
- SqlCommand cmd;
- float[,] qteproduit;
- string a = @"data source=NIPPONWORLD\SQLEXPRESS;initial catalog=gererlemagasin;integrated security=true";
- DataTable dt = new DataTable();
- DataTable combo = new DataTable();
- int finwsslna=0;
- int[,] panier = new int[100,2];
- public Form3()
- {
- InitializeComponent();
- }
- private void Form3_Load(object sender, EventArgs e)
- {
- cnn = new SqlConnection(a);
- cnn.Open();
- cmd = new SqlCommand("select designation from produit", cnn);
- combo.Load(cmd.ExecuteReader());
- comboBox1.DataSource = combo;
- comboBox1.DisplayMember = "designation";
- fillarrayproduit();
- rendreenabled("n");
- }
- private void pictureBox1_Click(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- // DABA QTE PRODUIT FIHA TOUT LES QTE DE PRODUITS DIAL TABLE PRODUTI
- //
- if (qteproduit[comboBox1.SelectedIndex, 0] - int.Parse(textBox3.Text) >= 0)
- {
- label7.Text += "\n" + (comboBox1.SelectedIndex+1) ;
- label8.Text += "\n " + textBox3.Text;
- label9.Text += "\n " + (qteproduit[comboBox1.SelectedIndex, 1] * int.Parse(textBox3.Text)).ToString(); //PRIX
- prixsomme += qteproduit[comboBox1.SelectedIndex, 1] * int.Parse(textBox3.Text);
- qteproduit[comboBox1.SelectedIndex, 0] -= int.Parse(textBox3.Text); //QTE
- /* panier diali*/
- panier[finwsslna, 0] = comboBox1.SelectedIndex+1;
- panier[finwsslna, 1] = int.Parse(textBox3.Text);
- /*************/
- finwsslna++;
- label12.Text = "Total Commande:" + prixsomme;
- label12.Location = new Point(label12.Location.X, label12.Location.Y+ 12);
- }
- else
- {
- MessageBox.Show("Stock insufisant. ("+ qteproduit[comboBox1.SelectedIndex, 0]+")");
- }
- }
- private void groupBox2_Enter(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- }
- private void fillarrayproduit()
- {
- //cette fonction sert à remplir le array produit(qte,prix) avec les nouvaux données de
- //la base.
- cmd = new SqlCommand("select * from produit", cnn);
- dt.Load(cmd.ExecuteReader());
- qteproduit = new float[dt.Rows.Count, 2];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- qteproduit[i, 0] = float.Parse(dt.Rows[i][2].ToString()); //qte
- qteproduit[i, 1] = float.Parse(dt.Rows[i][3].ToString()); //prix
- }
- }
- private void rendreenabled(string a)
- {
- if(a=="n")
- {
- label11.Visible = false;
- textBox1.Enabled = false;
- textBox2.Enabled = false;
- textBox3.Enabled = false;
- button1.Enabled = false;
- button2.Enabled = false;
- button3.Enabled = false;
- dateTimePicker1.Enabled = false;
- radioButton1.Enabled = false;
- radioButton2.Enabled = false;
- }
- if(a=="y")
- {
- label11.Visible = true;
- textBox1.Enabled = true;
- textBox2.Enabled = true;
- textBox3.Enabled = true;
- button1.Enabled = true;
- button2.Enabled = true;
- button3.Enabled = true;
- dateTimePicker1.Enabled = true;
- radioButton1.Enabled = true;
- radioButton2.Enabled = true;
- }
- }
- private void button4_Click(object sender, EventArgs e)
- {
- Client client = new Client();
- client.Show();
- ajouterouchoisir = 1;
- }
- public void afficher()
- {
- label1.Text = "oo";
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (Client.codeclient !=-1998)//ya3ni safi rah client selectionné
- {
- DataTable tableclientinfo = new DataTable();
- cmd = new SqlCommand("select * from client where codeclient=" + Client.codeclient, cnn);
- tableclientinfo.Load(cmd.ExecuteReader());
- label11.Text = "Client N°:" + tableclientinfo.Rows[0][0] + "//Nom=" + tableclientinfo.Rows[0][1] + " Prenom:" + tableclientinfo.Rows[0][2];
- niveaufidelite = int.Parse(tableclientinfo.Rows[0][3].ToString());
- rendreenabled("y");
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if(radioButton1.Checked)
- {
- }
- //ajout cmd
- try
- {
- fidelite fidelite = new fidelite();
- cmd = new SqlCommand("insert into commande values(" + textBox1.Text + ",'" + dateTimePicker1.Value.ToString()+"'," + Client.codeclient + ",101,"+(prixsomme - (prixsomme *( niveaufidelite/100))) +",NULL,NULL,NULL)",cnn);
- //MessageBox.Show((prixsomme - prixsomme *niveaufidelite*0.01).ToString());
- cmd.ExecuteNonQuery();
- for (int cho=0;cho<finwsslna;cho++)
- {
- cmd = new SqlCommand("insert into detailcommandeproduit values(" + textBox1.Text + "," + panier[cho,0] + "," + panier[cho, 1] + ")", cnn);
- cmd.ExecuteNonQuery();
- cmd = new SqlCommand("update produit set qtestock=qtestock-" + panier[cho, 1] + " where codeproduit="+(panier[cho,0]) , cnn);
- cmd.ExecuteNonQuery();
- }
- fidelite.Show();
- }
- catch(Exception ex)
- {
- label10.Visible = true;
- MessageBox.Show(ex.Message.ToString());
- }
- finally { }
- }
- private void button5_Click(object sender, EventArgs e)
- {
- Client client = new Client();
- ajouterouchoisir = 2;
- client.Show();
- }
- private void button3_Click_1(object sender, EventArgs e)
- {
- }
- private void groupBox2_Enter_1(object sender, EventArgs e)
- {
- }
- private void radioButton1_CheckedChanged(object sender, EventArgs e)
- {
- }
- private void radioButton2_CheckedChanged(object sender, EventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement