Advertisement
nostradamos

tarik facturation form

Nov 7th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data.SqlClient;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Microsoft.Office.Interop.Word;
  12.  
  13. namespace gestion_transport
  14. {
  15.     public partial class facturation : Form
  16.     {
  17.         SqlConnection conn = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=data_transport;Integrated Security=True");
  18.         SqlCommand cmnd = new SqlCommand();
  19.         SqlDataReader dataReader;
  20.         double tarif;
  21.  
  22.         double montant;
  23.         double tva;
  24.         double ttc;
  25.         //int fac_num;
  26.         public facturation()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.  
  31.         private void facturation_Load(object sender, EventArgs e)
  32.         {
  33.             conn.Open();
  34.             cmnd.CommandText = "Select DISTINCT societe from personne ";
  35.             cmnd.Connection = conn;
  36.             dataReader = cmnd.ExecuteReader();
  37.             while (dataReader.Read())
  38.             {
  39.                 cbx_societe.Items.Add(dataReader[0]);
  40.             }
  41.             dataReader.Close();
  42.             conn.Close();
  43.            
  44.  
  45.         }
  46.  
  47.         private void cbx_societe_SelectedIndexChanged(object sender, EventArgs e)
  48.         {
  49.             //combobox
  50.             cbx_groupe.Items.Clear();
  51.             conn.Open();
  52.             cmnd.CommandText = "Select DISTINCT numgroupe from personne WHERE societe='" + cbx_societe.Text + "'";
  53.             cmnd.Connection = conn;
  54.             dataReader = cmnd.ExecuteReader();
  55.             while (dataReader.Read())
  56.             {
  57.                 if (dataReader[0] != null)
  58.                     cbx_groupe.Items.Add(dataReader[0]);
  59.             }
  60.             dataReader.Close();
  61.             conn.Close();
  62.  
  63.  
  64.            
  65.         }
  66.  
  67.         private void cbx_groupe_SelectedIndexChanged(object sender, EventArgs e)
  68.         {
  69.             //add grid
  70.             dataPersonne.Rows.Clear();
  71.             conn.Open();
  72.             cmnd.CommandText = "Select * from personne where societe='" + cbx_societe.Text + "'and numgroupe="+int.Parse(cbx_groupe.Text);
  73.             cmnd.Connection = conn;
  74.             dataReader = cmnd.ExecuteReader();
  75.             while (dataReader.Read())
  76.             {
  77.                 dataPersonne.Rows.Add(dataReader[0], dataReader[1], dataReader[2], dataReader[3]);
  78.             }
  79.             dataReader.Close();
  80.             conn.Close();
  81.  
  82.            
  83.             conn.Open();
  84.             cmnd.CommandText = "Select tarif from tbl_groupe WHERE ngroupe=" + int.Parse(cbx_groupe.Text)+"" ;
  85.             cmnd.Connection = conn;
  86.             dataReader = cmnd.ExecuteReader();
  87.             while (dataReader.Read())
  88.             {
  89.                 tarif = int.Parse(dataReader[0].ToString());
  90.             }
  91.             dataReader.Close();
  92.             conn.Close();
  93.  
  94.              montant = tarif * (dataPersonne.RowCount-1);
  95.              tva = montant / 5;
  96.              ttc= montant + tva;
  97.  
  98.             label4.Text = montant.ToString() + "DH";
  99.             label6.Text = tva.ToString() + "DH";
  100.             label8.Text=ttc.ToString() + "DH";
  101.  
  102.         }
  103.  
  104.         private void button1_Click(object sender, EventArgs e)
  105.         {
  106.             int num = new_fac_num();
  107.             conn.Open();
  108.             cmnd.CommandText = "insert into facturess values("+ num + ",'" + cbx_societe.Text+"',"+montant+ "," +tva+ "," +ttc+")";
  109.             cmnd.Connection = conn;
  110.             cmnd.ExecuteNonQuery();
  111.             conn.Close();
  112.         }
  113.  
  114.  
  115.         int new_fac_num()
  116.         {
  117.             List<int> num_fac = new List<int>();
  118.             conn.Open();
  119.             cmnd.CommandText = "Select num_fac from factures";
  120.             cmnd.Connection = conn;
  121.             dataReader = cmnd.ExecuteReader();
  122.             while (dataReader.Read())
  123.             {
  124.                 num_fac.Add(int.Parse(dataReader[0].ToString()));
  125.             }
  126.             dataReader.Close();
  127.             conn.Close();
  128.  
  129.             int x = 0;
  130.             Random rnd = new Random();
  131.             bool exist = false;
  132.             while (!exist)
  133.             {
  134.                 x = rnd.Next(1, 10000);
  135.                 MessageBox.Show(x.ToString());
  136.                 if (!num_fac.Contains(x))
  137.                 {
  138.                     exist = true;
  139.                 }
  140.             }
  141.  
  142.             return x;
  143.         }
  144.  
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement