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.SqlClient;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Microsoft.Office.Interop.Word;
- namespace gestion_transport
- {
- public partial class facturation : Form
- {
- SqlConnection conn = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=data_transport;Integrated Security=True");
- SqlCommand cmnd = new SqlCommand();
- SqlDataReader dataReader;
- double tarif;
- double montant;
- double tva;
- double ttc;
- //int fac_num;
- public facturation()
- {
- InitializeComponent();
- }
- private void facturation_Load(object sender, EventArgs e)
- {
- conn.Open();
- cmnd.CommandText = "Select DISTINCT societe from personne ";
- cmnd.Connection = conn;
- dataReader = cmnd.ExecuteReader();
- while (dataReader.Read())
- {
- cbx_societe.Items.Add(dataReader[0]);
- }
- dataReader.Close();
- conn.Close();
- }
- private void cbx_societe_SelectedIndexChanged(object sender, EventArgs e)
- {
- //combobox
- cbx_groupe.Items.Clear();
- conn.Open();
- cmnd.CommandText = "Select DISTINCT numgroupe from personne WHERE societe='" + cbx_societe.Text + "'";
- cmnd.Connection = conn;
- dataReader = cmnd.ExecuteReader();
- while (dataReader.Read())
- {
- if (dataReader[0] != null)
- cbx_groupe.Items.Add(dataReader[0]);
- }
- dataReader.Close();
- conn.Close();
- }
- private void cbx_groupe_SelectedIndexChanged(object sender, EventArgs e)
- {
- //add grid
- dataPersonne.Rows.Clear();
- conn.Open();
- cmnd.CommandText = "Select * from personne where societe='" + cbx_societe.Text + "'and numgroupe="+int.Parse(cbx_groupe.Text);
- cmnd.Connection = conn;
- dataReader = cmnd.ExecuteReader();
- while (dataReader.Read())
- {
- dataPersonne.Rows.Add(dataReader[0], dataReader[1], dataReader[2], dataReader[3]);
- }
- dataReader.Close();
- conn.Close();
- conn.Open();
- cmnd.CommandText = "Select tarif from tbl_groupe WHERE ngroupe=" + int.Parse(cbx_groupe.Text)+"" ;
- cmnd.Connection = conn;
- dataReader = cmnd.ExecuteReader();
- while (dataReader.Read())
- {
- tarif = int.Parse(dataReader[0].ToString());
- }
- dataReader.Close();
- conn.Close();
- montant = tarif * (dataPersonne.RowCount-1);
- tva = montant / 5;
- ttc= montant + tva;
- label4.Text = montant.ToString() + "DH";
- label6.Text = tva.ToString() + "DH";
- label8.Text=ttc.ToString() + "DH";
- }
- private void button1_Click(object sender, EventArgs e)
- {
- int num = new_fac_num();
- conn.Open();
- cmnd.CommandText = "insert into facturess values("+ num + ",'" + cbx_societe.Text+"',"+montant+ "," +tva+ "," +ttc+")";
- cmnd.Connection = conn;
- cmnd.ExecuteNonQuery();
- conn.Close();
- }
- int new_fac_num()
- {
- List<int> num_fac = new List<int>();
- conn.Open();
- cmnd.CommandText = "Select num_fac from factures";
- cmnd.Connection = conn;
- dataReader = cmnd.ExecuteReader();
- while (dataReader.Read())
- {
- num_fac.Add(int.Parse(dataReader[0].ToString()));
- }
- dataReader.Close();
- conn.Close();
- int x = 0;
- Random rnd = new Random();
- bool exist = false;
- while (!exist)
- {
- x = rnd.Next(1, 10000);
- MessageBox.Show(x.ToString());
- if (!num_fac.Contains(x))
- {
- exist = true;
- }
- }
- return x;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement