Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace WindowsFormsApp2
  13. {
  14. public partial class Form3 : Form
  15. {
  16. public static int ajouterouchoisir = 0;
  17. public static float prixsomme = 0; //utile pour fidelite windows
  18. public static int niveaufidelite = 0;//utile pour fidelite windows
  19.  
  20.  
  21.  
  22. SqlConnection cnn;
  23. SqlCommand cmd;
  24. float[,] qteproduit;
  25. string a = @"data source=NIPPONWORLD\SQLEXPRESS;initial catalog=gererlemagasin;integrated security=true";
  26. DataTable dt = new DataTable();
  27. DataTable combo = new DataTable();
  28.  
  29. int finwsslna=0;
  30. int[,] panier = new int[100,2];
  31.  
  32.  
  33.  
  34. public Form3()
  35. {
  36. InitializeComponent();
  37. }
  38.  
  39. private void Form3_Load(object sender, EventArgs e)
  40. {
  41.  
  42. cnn = new SqlConnection(a);
  43. cnn.Open();
  44. cmd = new SqlCommand("select designation from produit", cnn);
  45.  
  46. combo.Load(cmd.ExecuteReader());
  47.  
  48. comboBox1.DataSource = combo;
  49. comboBox1.DisplayMember = "designation";
  50. fillarrayproduit();
  51. rendreenabled("n");
  52.  
  53. }
  54.  
  55. private void pictureBox1_Click(object sender, EventArgs e)
  56. {
  57.  
  58. }
  59.  
  60. private void textBox1_TextChanged(object sender, EventArgs e)
  61. {
  62.  
  63. }
  64.  
  65. private void button2_Click(object sender, EventArgs e)
  66. {
  67.  
  68.  
  69.  
  70.  
  71. // DABA QTE PRODUIT FIHA TOUT LES QTE DE PRODUITS DIAL TABLE PRODUTI
  72. //
  73.  
  74. if (qteproduit[comboBox1.SelectedIndex, 0] - int.Parse(textBox3.Text) >= 0)
  75. {
  76.  
  77. label7.Text += "\n" + (comboBox1.SelectedIndex+1) ;
  78. label8.Text += "\n " + textBox3.Text;
  79.  
  80.  
  81.  
  82.  
  83. label9.Text += "\n " + (qteproduit[comboBox1.SelectedIndex, 1] * int.Parse(textBox3.Text)).ToString(); //PRIX
  84. prixsomme += qteproduit[comboBox1.SelectedIndex, 1] * int.Parse(textBox3.Text);
  85. qteproduit[comboBox1.SelectedIndex, 0] -= int.Parse(textBox3.Text); //QTE
  86. /* panier diali*/
  87.  
  88. panier[finwsslna, 0] = comboBox1.SelectedIndex+1;
  89. panier[finwsslna, 1] = int.Parse(textBox3.Text);
  90. /*************/
  91. finwsslna++;
  92.  
  93. label12.Text = "Total Commande:" + prixsomme;
  94. label12.Location = new Point(label12.Location.X, label12.Location.Y+ 12);
  95. }
  96. else
  97. {
  98. MessageBox.Show("Stock insufisant. ("+ qteproduit[comboBox1.SelectedIndex, 0]+")");
  99. }
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. }
  108.  
  109. private void groupBox2_Enter(object sender, EventArgs e)
  110. {
  111.  
  112. }
  113.  
  114. private void button3_Click(object sender, EventArgs e)
  115. {
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. private void fillarrayproduit()
  126. {
  127. //cette fonction sert à remplir le array produit(qte,prix) avec les nouvaux données de
  128. //la base.
  129. cmd = new SqlCommand("select * from produit", cnn);
  130. dt.Load(cmd.ExecuteReader());
  131.  
  132.  
  133.  
  134.  
  135. qteproduit = new float[dt.Rows.Count, 2];
  136. for (int i = 0; i < dt.Rows.Count; i++)
  137. {
  138.  
  139.  
  140. qteproduit[i, 0] = float.Parse(dt.Rows[i][2].ToString()); //qte
  141.  
  142. qteproduit[i, 1] = float.Parse(dt.Rows[i][3].ToString()); //prix
  143.  
  144.  
  145.  
  146. }
  147. }
  148.  
  149. private void rendreenabled(string a)
  150. {
  151. if(a=="n")
  152. {
  153. label11.Visible = false;
  154.  
  155. textBox1.Enabled = false;
  156. textBox2.Enabled = false;
  157. textBox3.Enabled = false;
  158. button1.Enabled = false;
  159. button2.Enabled = false;
  160. button3.Enabled = false;
  161. dateTimePicker1.Enabled = false;
  162. radioButton1.Enabled = false;
  163. radioButton2.Enabled = false;
  164. }
  165. if(a=="y")
  166. {
  167. label11.Visible = true;
  168.  
  169. textBox1.Enabled = true;
  170. textBox2.Enabled = true;
  171. textBox3.Enabled = true;
  172. button1.Enabled = true;
  173. button2.Enabled = true;
  174. button3.Enabled = true;
  175. dateTimePicker1.Enabled = true;
  176. radioButton1.Enabled = true;
  177. radioButton2.Enabled = true;
  178. }
  179. }
  180.  
  181. private void button4_Click(object sender, EventArgs e)
  182. {
  183. Client client = new Client();
  184. client.Show();
  185. ajouterouchoisir = 1;
  186. }
  187.  
  188. public void afficher()
  189. {
  190. label1.Text = "oo";
  191. }
  192.  
  193. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  194. {
  195.  
  196. if (Client.codeclient !=-1998)//ya3ni safi rah client selectionné
  197. {
  198.  
  199. DataTable tableclientinfo = new DataTable();
  200. cmd = new SqlCommand("select * from client where codeclient=" + Client.codeclient, cnn);
  201.  
  202. tableclientinfo.Load(cmd.ExecuteReader());
  203.  
  204. label11.Text = "Client N°:" + tableclientinfo.Rows[0][0] + "//Nom=" + tableclientinfo.Rows[0][1] + " Prenom:" + tableclientinfo.Rows[0][2];
  205.  
  206. niveaufidelite = int.Parse(tableclientinfo.Rows[0][3].ToString());
  207.  
  208. rendreenabled("y");
  209.  
  210. }
  211. }
  212.  
  213. private void button1_Click(object sender, EventArgs e)
  214. {
  215. if(radioButton1.Checked)
  216. {
  217.  
  218.  
  219. }
  220.  
  221.  
  222. //ajout cmd
  223. try
  224. {
  225. fidelite fidelite = new fidelite();
  226.  
  227.  
  228. cmd = new SqlCommand("insert into commande values(" + textBox1.Text + ",'" + dateTimePicker1.Value.ToString()+"'," + Client.codeclient + ",101,"+(prixsomme - (prixsomme *( niveaufidelite/100))) +",NULL,NULL,NULL)",cnn);
  229. //MessageBox.Show((prixsomme - prixsomme *niveaufidelite*0.01).ToString());
  230. cmd.ExecuteNonQuery();
  231.  
  232.  
  233. for (int cho=0;cho<finwsslna;cho++)
  234. {
  235. cmd = new SqlCommand("insert into detailcommandeproduit values(" + textBox1.Text + "," + panier[cho,0] + "," + panier[cho, 1] + ")", cnn);
  236. cmd.ExecuteNonQuery();
  237. cmd = new SqlCommand("update produit set qtestock=qtestock-" + panier[cho, 1] + " where codeproduit="+(panier[cho,0]) , cnn);
  238. cmd.ExecuteNonQuery();
  239.  
  240. }
  241.  
  242. fidelite.Show();
  243.  
  244.  
  245.  
  246.  
  247. }
  248. catch(Exception ex)
  249. {
  250. label10.Visible = true;
  251.  
  252. MessageBox.Show(ex.Message.ToString());
  253. }
  254. finally { }
  255. }
  256.  
  257. private void button5_Click(object sender, EventArgs e)
  258. {
  259. Client client = new Client();
  260. ajouterouchoisir = 2;
  261. client.Show();
  262.  
  263. }
  264.  
  265. private void button3_Click_1(object sender, EventArgs e)
  266. {
  267.  
  268. }
  269.  
  270. private void groupBox2_Enter_1(object sender, EventArgs e)
  271. {
  272.  
  273. }
  274.  
  275. private void radioButton1_CheckedChanged(object sender, EventArgs e)
  276. {
  277.  
  278. }
  279.  
  280. private void radioButton2_CheckedChanged(object sender, EventArgs e)
  281. {
  282.  
  283. }
  284. }
  285. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement