Exemplo n.º 1
0
        private void valider_Click(object sender, RoutedEventArgs e)
        {
            succ = 0;
            SqlCommand    cmd;
            SqlConnection cn = new SqlConnection(@"Data source =.\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=true; ");

            try
            {
                cn.Open();
                if ((fournisseur.Text != "") && (code.Text != ""))
                {
                    list_info_fact = new List <info_fact>();
                    info_fact info = new info_fact(fournisseur.Text, Convert.ToInt32(code.Text), 0);
                    list_info_fact.Add(info);
                    if (date.Text != "")
                    {
                        cmd = new SqlCommand("Insert into Commande (fournisseur,Date,code) values('" + fournisseur.Text + "','" + date.Text + "'," + code.Text + ")", cn);
                    }
                    else
                    {
                        cmd = new SqlCommand("Insert into Commande (fournisseur,code) values('" + fournisseur.Text + "'," + code.Text + ")", cn);
                    }
                    succ = cmd.ExecuteNonQuery();
                    if (succ != 0)
                    {
                        MessageBox.Show("L'opération à finis avec succèe");
                        //Window_cmd.list_stock.Clear();
                        fournisseur.Text = "";
                        date.Text        = "";
                        code.Text        = "";
                    }
                }
                else
                {
                    MessageBox.Show("Veillez insérer tous les information du commande (Fournisseur, date et code) !!");
                }
            }
            catch
            {
                MessageBox.Show("ERREUR !! Verifiez vos saisies");
            }
            finally
            {
                cn.Close();
            }
        }
Exemplo n.º 2
0
        private void valider_Click(object sender, RoutedEventArgs e)
        {
            bool          succ = true;
            SqlCommand    cmd;
            SqlConnection cn = new SqlConnection(@"Data source =.\SQLEXPRESS; Initial Catalog=mydb; Integrated Security=true; ");

            try
            {
                cn.Open();
                DateTime?selected_date = date.SelectedDate;

                if ((selected_date.HasValue) && (code.Text != ""))
                {
                    string formated = selected_date.Value.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
                    if (Window1.list_inf.Count != 0)
                    {
                        list_info_fact = new List <info_fact>();
                        info_fact info = new info_fact(client.Text, Convert.ToInt32(code.Text), prix_tot());
                        list_info_fact.Add(info);
                        if (client.Text != "")
                        {
                            cmd = new SqlCommand("Insert into Facture (Client,Date,code) values('" + client.Text + "','" + formated + "'," + code.Text + ")", cn);
                        }
                        else
                        {
                            cmd = new SqlCommand("Insert into Facture (Date,code) values('" + formated + "'," + code.Text + ")", cn);
                        }

                        cmd.ExecuteNonQuery();
                        foreach (Listview_content produit in Window1.list_inf)
                        {
                            if (produit.Medicament)
                            {
                                if (produit.restitue)
                                {
                                    if (Window1.db.Dec_Stock_med("TabRestitue", produit.id, produit.Quant) == -1)
                                    {
                                        succ = false;
                                        MessageBox.Show("ERREUR");
                                        break;
                                    }
                                }
                                else
                                {
                                    if (Window1.db.Dec_Stock_med("Tab_NEW", produit.id, produit.Quant) == -1)
                                    {
                                        succ = false;
                                        MessageBox.Show("ERREUR");
                                        break;
                                    }
                                }
                            }
                            else //decrementer le stock de produit de bien etre
                            {
                                if (Window1.db.Dec_Stock_bien_etre("Bien_etre", produit.id, produit.Quant, produit.marque, produit.type, produit.comp) == -1)
                                {
                                    succ = false;
                                    MessageBox.Show("ERREUR");
                                    break;
                                }
                            }
                        }
                        if (succ)
                        {
                            MessageBox.Show("L'opération à finis avec succèe");
                            valide = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Vous devez insérer au moins un médicament !!");
                    }
                }
                else
                {
                    MessageBox.Show("Veillez insérer tous les information du commande (Nom, date et code) !!");
                }
            }
            finally
            {
                cn.Close();
            }
        }