Esempio n. 1
0
        static void Main(string[] args)
        {
            string choice = "y";

            do
            {
                Console.Clear();
                Console.WriteLine("----------------------------Create a product----------------------------");
                Console.Write("Enter reference\t:");
                string reference = Console.ReadLine();
                Console.Write("Enter name\t:");
                string name = Console.ReadLine();
                Console.Write("Enter unit price\t:");
                double price = double.Parse(Console.ReadLine());
                Console.Write("Enter tax\t:");
                float tax = float.Parse(Console.ReadLine());

                Product    product    = new Product(reference, name, price, tax, null);
                ProductBLO productBLO = new ProductBLO(ConfigurationManager.AppSettings["DbFolder"]);
                productBLO.CreateProduct(product);

                IEnumerable <Product> products = productBLO.GetAllProducts();
                foreach (Product p in products)
                {
                    Console.WriteLine($"{p.Reference}\t{p.Name}");
                }

                Console.Write("Create another product ?[y/n]:");
                choice = Console.ReadLine();
            }while (choice.ToLower() != "n");
            Console.WriteLine("Program end !");

            Console.ReadKey();
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                checkForm();
                Product newProduct = new Product
                                     (
                    txtReference.Text.ToUpper(),
                    txtName.Text,
                    double.Parse(txtPrice.Text),
                    float.Parse(txtTaxe.Text)
                                     );
                ProductBLO productBLO = new ProductBLO(ConfigurationManager.AppSettings["DbFolder"]);

                if (this.oldProduct == null)
                {
                    productBLO.CreateProduct(newProduct);
                }
                else
                {
                    productBLO.EditProduct(oldProduct, newProduct);
                }

                MessageBox.Show
                (
                    "Save done!",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                );

                if (callBack != null)
                {
                    callBack();
                }
                if (oldProduct != null)
                {
                    Close();
                }

                txtReference.Clear();
                txtName.Clear();
                txtPrice.Clear();
                txtTaxe.Clear();
                txtReference.Focus();
            }

            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    "Une erreur est survenue, veuillez reessayez plus tard SVP",
                    "Erreur de saisie",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }

            catch (DuplicateNameException ex)
            {
                //ex.WriteToFile();
                MessageBox.Show
                (
                    ex.Message,
                    "Erreur, déjà existant",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }

            catch (KeyNotFoundException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }

            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    ex.Message,
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
        }
Esempio n. 3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                checkForm();

                Product newProduct = new Product
                                     (
                    txtReference.Text.ToUpper(),
                    txtName.Text,
                    double.Parse(txtPrice.Text),
                    float.Parse(txtTax.Text),
                    !string.IsNullOrEmpty(pictureBox1.ImageLocation) ? File.ReadAllBytes(pictureBox1.ImageLocation) : this.oldProduct?.Picture
                                     );

                ProductBLO productBLO = new ProductBLO(ConfigurationManager.AppSettings["DbFolder"]);

                if (this.oldProduct == null)
                {
                    productBLO.CreateProduct(newProduct);
                }
                else
                {
                    productBLO.EditProduct(oldProduct, newProduct);
                }

                MessageBox.Show
                (
                    "Save done !",
                    "Confirmation",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                );

                if (callBack != null)
                {
                    callBack();
                }

                if (oldProduct != null)
                {
                    Close();
                }

                txtReference.Clear();
                txtName.Clear();
                txtPrice.Clear();
                txtTax.Clear();
                txtReference.Focus();
            }
            catch (TypingException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Typing error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (DuplicateNameException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Duplicate error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show
                (
                    ex.Message,
                    "Not found error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning
                );
            }
            catch (Exception ex)
            {
                ex.WriteToFile();
                MessageBox.Show
                (
                    "An error occurred! Please try again later.",
                    "Erreur",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                );
            }
        }