コード例 #1
0
ファイル: IHM.cs プロジェクト: torkhan/.Net
        private void ActionVente()
        {
            int codeProduit;

            panier = new Panier();
            do
            {
                Console.Write("Code produit : ");
                codeProduit = Convert.ToInt32(Console.ReadLine());
                if (codeProduit != 0)
                {
                    Produit produit = data.GetProduitById(codeProduit);
                    if (produit != null)
                    {
                        panier.AddProduit(produit);
                        data.DescStock(produit.Id);
                        Console.WriteLine(produit);
                    }
                    else
                    {
                        Console.WriteLine("Aucun produit avec ce code");
                    }
                }
                else
                {
                    Console.WriteLine("=========Panier==========");
                    Console.WriteLine(panier);
                    data.SavePanier(panier);
                }
            } while (codeProduit != 0);
            clearConsole();
        }
コード例 #2
0
ファイル: DataBase.cs プロジェクト: torkhan/.Net
        public bool SavePanier(Panier panier)
        {
            string request = "INSERT INTO panier (total) OUTPUT INSERTED.ID values (@total)";

            command = new SqlCommand(request, connection);
            command.Parameters.Add(new SqlParameter("@total", panier.Total));
            connection.Open();
            panier.Id = (int)command.ExecuteScalar();
            command.Dispose();
            connection.Close();
            if (panier.Id > 0)
            {
                panier.Produits.ForEach(p => SavePanierProduit(panier.Id, p.Id));
                return(true);
            }
            return(false);
        }