예제 #1
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
                );
            }
        }
예제 #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(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
                );
            }
        }