Example #1
0
        /// <summary>
        /// Modify a sousfamille of the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Modify_Click(object sender, EventArgs e)
        {
            var SousFamilleName = this.textBox_NewSousFamilleName.Text;

            if (SousFamilleName == "")
            {
                MessageBox.Show("Please enter the SousFamille Name!", "ERROR");
                return;
            }

            else if (SousFamilleName == this.label_Famille_Name.Text)
            {
                MessageBox.Show("SousFamilleName and FamilleName can't be the same!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (SousFamilleName == this.label_SousFamille_Name.Text)
            {
                MessageBox.Show("SousFamilleName can't be the same before and after modification!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (SousFamilleName == "Familles")
            {
                MessageBox.Show("SousFamilleName can't be Familles!");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (SousFamilleName == "Marques")
            {
                MessageBox.Show("SousFamilleName can't be Marques!");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (SousFamilleName == "Tous les articles")
            {
                MessageBox.Show("SousFamilleName can't be Tous les articles!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (MarqueController.FindMarqueByMarqueName(SousFamilleName))
            {
                MessageBox.Show("This name has already been used by a Marque!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (FamilleController.FindFamilleByFamilleName(SousFamilleName))
            {
                MessageBox.Show("This name has already been used by a Famille!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else if (SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
            {
                MessageBox.Show("SousFamille Already exsited!", "ERROR");
                this.textBox_NewSousFamilleName.Text = "";
                return;
            }

            else
            {
                SousFamilles SousFamille = SousFamilleController.FindSousFamillesBySousFamilleName(this.label_SousFamille_Name.Text);
                SousFamille.SousFamilleName = SousFamilleName;
                SousFamilleDao.ModifySousFamille(SousFamille);

                if (SousFamilleController.FindSousFamilleBySousFamilleName(SousFamille.SousFamilleName))
                {
                    MessageBox.Show("Modify succeed!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Modify Failed!");
                    this.Close();
                }
            }
        }
Example #2
0
        /// <summary>
        /// Add a famille to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Add_Click(object sender, EventArgs e)
        {
            var FamilleName = this.textBox_FamilleName.Text;

            if (FamilleName == "")
            {
                MessageBox.Show("Please enter the Famille Name!", "ERROR");
                return;
            }

            if (FamilleName == "Familles")
            {
                MessageBox.Show("FamilleName can't be Familles!");
                this.textBox_FamilleName.Text = "";
                return;
            }

            if (FamilleName == "Marques")
            {
                MessageBox.Show("FamilleName can't be Marques!");
                this.textBox_FamilleName.Text = "";
                return;
            }

            if (FamilleName == "Tous les articles")
            {
                MessageBox.Show("FamilleName can't be Tous les articles!");
                this.textBox_FamilleName.Text = "";
                return;
            }

            if (MarqueController.FindMarqueByMarqueName(FamilleName))
            {
                MessageBox.Show("FamilleName already used by a Marque!", "ERROR");
                this.textBox_FamilleName.Text = "";
                return;
            }

            if (SousFamilleController.FindSousFamilleBySousFamilleName(FamilleName))
            {
                MessageBox.Show("FamilleName already used by a SousFamille!", "ERROR");
                this.textBox_FamilleName.Text = "";
                return;
            }

            if (FamilleController.FindFamilleByFamilleName(FamilleName))
            {
                MessageBox.Show("Famille Already exsited!", "ERROR");
                this.textBox_FamilleName.Text = "";
                return;
            }
            else
            {
                Familles Famille = new Familles(FamilleName);
                Famille.RefFamille = FamilleDao.GetMaxRefFamille() + 1;
                FamilleDao.AddFamille(Famille);

                if (FamilleController.FindFamilleByFamilleName(FamilleName))
                {
                    MessageBox.Show("Add Famille succeed!");
                    this.Close();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Add an article to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Add_Click(object sender, EventArgs e)
        {
            var RefArticle      = this.textBox_RefArticle.Text;
            var Description     = this.textBoxDescription.Text;
            var MarqueName      = this.comboBox_Marque.Text;
            var FamilleName     = this.comboBox_Famille.Text;
            var SousFamilleName = this.comboBox_SousFamille.Text;
            var PrixHT          = this.textBox_PrixHT.Text;
            var Quantite        = this.textBox_Quantite.Text;

            if (RefArticle == "")
            {
                MessageBox.Show("Please enter the RefArticle!", "ERROR");
            }

            else if (Description == "")
            {
                MessageBox.Show("Please enter the Description!", "ERROR");
            }

            else if (PrixHT == "")
            {
                MessageBox.Show("Please enter the Price!", "ERROR");
            }

            else if (Quantite == "")
            {
                MessageBox.Show("Please enter the Quantite!", "ERROR");
            }

            else if (MarqueName == "")
            {
                MessageBox.Show("Please enter the Marque Name!", "ERROR");
            }

            else if (FamilleName == "")
            {
                MessageBox.Show("Please enter the Famille Name!", "ERROR");
            }

            else if (SousFamilleName == "")
            {
                MessageBox.Show("Please enter the SousFamille Name!", "ERROR");
            }

            else if (RefArticle.Length >= 15)
            {
                MessageBox.Show("RefArticle is too long! The maximum length of the RefArticle is 15!");
            }

            else if (!float.TryParse(PrixHT, out var Prix))
            {
                MessageBox.Show("Please enter the right price!");
            }

            else if (!int.TryParse(Quantite, out var Number))
            {
                MessageBox.Show("Please enter the right quantity!");
            }

            else if (ArticleController.FindArticleByRefArticle(RefArticle))
            {
                MessageBox.Show("Article Already exsited!", "ERROR");
            }

            else
            {
                if (!SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
                {
                    var Result = MessageBox.Show("SousFamille doesn't exsite! Do you want to add a new SousFamille?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (Result == DialogResult.OK)
                    {
                        AddSousFamille AddSousFamille = new AddSousFamille {
                            StartPosition = FormStartPosition.CenterParent
                        };
                        AddSousFamille.ShowDialog(this);
                    }
                    else
                    {
                        return;
                    }
                }
                if (!MarqueController.FindMarqueByMarqueName(MarqueName))
                {
                    var Result = MessageBox.Show("Marque doesn't exsite! Do you want to add a new Marque?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                    if (Result == DialogResult.OK)
                    {
                        Marques NewMarque = new Marques(MarqueName);
                        NewMarque.RefMarque = MarqueDao.GetMaxRefMarque() + 1;
                        MarqueDao.AddMarque(NewMarque);
                    }
                    else
                    {
                        return;
                    }
                }

                SousFamilles SousFamille = SousFamilleController.FindSousFamillesBySousFamilleName(SousFamilleName);
                Marques      Marque      = MarqueController.FindMarquesByMarqueName(MarqueName);
                string       Price       = float.Parse(PrixHT).ToString();
                Price = Price.Replace(".", ",");
                Articles Article = new Articles(RefArticle, Description, FamilleController.FindFamillesByRefSousFamille(SousFamille.RefSousFamille), SousFamille, Marque, float.Parse(Price), int.Parse(Quantite));
                ArticleDao.AddArticle(Article);

                if (ArticleController.FindArticleByRefArticle(RefArticle))
                {
                    MessageBox.Show("Add Article succeed!");
                    this.Close();
                }
            }
        }
Example #4
0
        /// <summary>
        /// Add a marque to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Add_Click(object sender, EventArgs e)
        {
            var MarqueName = this.textBox_MarqueName.Text;

            if (MarqueName == "")
            {
                MessageBox.Show("Please enter the Marque Name!", "ERROR");
                return;
            }

            if (MarqueName == "Familles")
            {
                MessageBox.Show("MarqueName can't be Familles!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (MarqueName == "Marques")
            {
                MessageBox.Show("MarqueName can't be Marques!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (MarqueName == "Familles")
            {
                MessageBox.Show("MarqueName can't be Familles!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (MarqueName == "Tous les articles")
            {
                MessageBox.Show("MarqueName can't be Tous les articles!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (FamilleController.FindFamilleByFamilleName(MarqueName))
            {
                MessageBox.Show("This name has already been used by a Famille!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (SousFamilleController.FindSousFamilleBySousFamilleName(MarqueName))
            {
                MessageBox.Show("This name has already been used by a SousFamille!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }

            if (MarqueController.FindMarqueByMarqueName(MarqueName))
            {
                MessageBox.Show("Marque Already exsited!", "ERROR");
                this.textBox_MarqueName.Text = "";
                return;
            }
            else
            {
                Marques Marque = new Marques(MarqueName);
                Marque.RefMarque = MarqueDao.GetMaxRefMarque() + 1;
                MarqueDao.AddMarque(Marque);
                if (MarqueController.FindMarqueByMarqueName(MarqueName))
                {
                    MessageBox.Show("Add Marque succeed!");
                    this.Close();
                }
            }
        }
Example #5
0
        /// <summary>
        /// Read the csv file in two modes, mode erasement et mode ajout.
        /// </summary>
        /// <param name="Flag"></param>
        /// <param name="FilePath"></param>
        /// <param name="FormImport"></param>
        public static void ReadFile(bool Flag, string FilePath, FormImport FormImport)
        {
            try
            {
                int AddedArticles    = 0;
                int ExistingArticles = 0;

                if (Flag == true)
                {
                    ModelList.Articles.Clear();
                    ModelList.Familles.Clear();
                    ModelList.Marques.Clear();
                    ModelList.SousFamilles.Clear();

                    ArticleDao.EmptyArticles();
                    SousFamilleDao.EmptySousFamilles();
                    MarqueDao.EmptyMarques();
                    FamilleDao.EmptyFamilles();
                }

                if (FilePath == "")
                {
                    if (MessageBox.Show("Please choose a file!", "ERROR") == DialogResult.OK)
                    {
                        using (OpenFileDialog openFileDialog = new OpenFileDialog())
                        {
                            openFileDialog.Filter           = "csv files (*.csv)|*.csv";
                            openFileDialog.RestoreDirectory = true;

                            if (openFileDialog.ShowDialog() == DialogResult.OK)
                            {
                                FilePath = openFileDialog.FileName;
                                FormImport.label_FichierImporte.Text = "FileName: " + System.IO.Path.GetFileName(FilePath);
                            }
                        }
                    }
                }

                using (var StreamReader = new StreamReader(FilePath, Encoding.Default))
                {
                    var NbLines = File.ReadAllLines(FilePath).Length;

                    FormImport.progressBar.Maximum = NbLines;
                    FormImport.progressBar.Value   = 1;

                    StreamReader.ReadLine();

                    string Line;
                    while ((Line = StreamReader.ReadLine()) != null)
                    {
                        var Values          = Line.Split(';');
                        var Description     = Values[0].Trim();
                        var RefArticle      = Values[1].Trim();
                        var MarqueName      = Values[2].Trim();
                        var FamilleName     = Values[3].Trim();
                        var SousFamilleName = Values[4].Trim();
                        //var Prix = Values[5].Trim();

                        /*
                         * if (Prix.IndexOf("\"") >= 0)
                         *  Prix = Prix.Replace("\"", "");
                         *
                         * if (Prix.EndsWith(","))
                         *  Prix = Prix.Remove(Prix.Length - 1, 1);
                         *
                         * if (Prix.IndexOf(",") != -1)
                         * {
                         *  int StartIndex = 0;
                         *  int Count = 0;
                         *  while (true)
                         *  {
                         *      int Index = Prix.IndexOf(",", StartIndex);
                         *      if (Index != -1)
                         *      {
                         *          Count++;
                         *          StartIndex = Index + 1;
                         *      }
                         *      else
                         *          break;
                         *  }
                         *
                         *  StartIndex = 0;
                         *  for (int i = 0; i < Count - 1; i++)
                         *  {
                         *      int Index = Prix.IndexOf(",", StartIndex);
                         *      StartIndex = Index + 1;
                         *      Prix = Prix.Remove(Index, Index);
                         *  }
                         *
                         *  Prix = Prix.Replace(",", ".");
                         * }
                         *
                         * var PrixHT = float.Parse(Prix, CultureInfo.InvariantCulture.NumberFormat);
                         */
                        var PrixHT = float.Parse(Values[5].Trim().Replace(",", "."), CultureInfo.InvariantCulture.NumberFormat);
                        if (ArticleController.FindArticleByRefArticle(RefArticle))
                        {
                            ExistingArticles += 1;
                            if (Flag == false)
                            {
                                Article = ArticleController.FindArticlesByRefArticle(RefArticle);
                                if (Article.Description != Description)
                                {
                                    Article.Description = Description;
                                }
                                if (Article.PrixHT != PrixHT)
                                {
                                    Article.PrixHT = PrixHT;
                                }
                                if (Article.Quantite != 1)
                                {
                                    Article.Quantite = 1;
                                }
                                if (!MarqueController.FindMarqueByMarqueName(MarqueName))
                                {
                                    Marque = new Marques(MarqueName);
                                    ModelList.Marques.Add(Marque);
                                    MarqueDao.AddMarque(Marque);
                                    Article.Marque = Marque;
                                }
                                if (!SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
                                {
                                    SousFamille = new SousFamilles(SousFamilleName);
                                    ModelList.SousFamilles.Add(SousFamille);
                                    SousFamilleDao.AddSousFamille(SousFamille, Famille);
                                    Article.SousFamille = SousFamille;
                                }
                            }
                            continue;
                        }
                        else
                        {
                            AddedArticles += 1;
                        }

                        if (!MarqueController.FindMarqueByMarqueName(MarqueName))
                        {
                            Marque = new Marques(MarqueName);
                            ModelList.Marques.Add(Marque);
                            MarqueDao.AddMarque(Marque);
                        }

                        if (!ArticleController.FindArticleByFamilleName(FamilleName))
                        {
                            Famille = new Familles(FamilleName);
                            ModelList.Familles.Add(Famille);
                            FamilleDao.AddFamille(Famille);
                        }

                        if (!SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
                        {
                            SousFamille = new SousFamilles(SousFamilleName);
                            ModelList.SousFamilles.Add(SousFamille);
                            SousFamilleDao.AddSousFamille(SousFamille, Famille);
                        }

                        Article = new Articles(RefArticle, Description, FamilleController.FindFamillesByRefSousFamille(SousFamille.RefSousFamille), SousFamille, Marque, PrixHT, 1);
                        ModelList.Articles.Add(Article);
                        ArticleDao.AddArticle(Article);

                        FormImport.progressBar.Value++;
                    }
                    StreamReader.Close();
                }

                string Message = "Nombre d'articles ajoutés " + AddedArticles + "\n" +
                                 "Nombre d'articles anomalies " + ExistingArticles;

                MessageBox.Show(" Import success!\n" + Message, System.IO.Path.GetFileName(FilePath));

                FileDirectory = Path.GetDirectoryName(FilePath);
                if (FileDirectory != null)
                {
                    FormMain_FileSystemWatcher();
                }
            }
            catch (System.IO.IOException)
            {
                MessageBox.Show("Please close the selected file!");
            }
        }
        /// <summary>
        /// Modify an article of the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Modify_Click(object sender, EventArgs e)
        {
            var Description     = this.textBox_Description.Text;
            var MarqueName      = this.comboBox_Marque.Text;
            var FamilleName     = this.comboBox_Famille.Text;
            var SousFamilleName = this.comboBox_SousFamille.Text;
            var PrixHT          = this.textBox_PrixHT.Text;
            var Quantite        = this.textBox_Quantite.Text;

            if (Description == "")
            {
                MessageBox.Show("Please enter the Description!", "ERROR");
            }

            else if (MarqueName == "")
            {
                MessageBox.Show("Please enter the Marque Name!", "ERROR");
            }

            else if (FamilleName == "")
            {
                MessageBox.Show("Please enter the Famille Name!", "ERROR");
            }

            else if (SousFamilleName == "")
            {
                MessageBox.Show("Please enter the SousFamille Name!", "ERROR");
            }

            else if (PrixHT == "")
            {
                MessageBox.Show("Please enter the Price!", "ERROR");
            }

            else if (Quantite == "")
            {
                MessageBox.Show("Please enter the Quantite!", "ERROR");
            }

            else if (!float.TryParse(PrixHT, out var Prix))
            {
                MessageBox.Show("Please enter the right price!");
            }

            else if (!int.TryParse(Quantite, out var Number))
            {
                MessageBox.Show("Please enter the right quantity!");
            }

            else
            {
                if (!SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
                {
                    if (MessageBox.Show("SousFamille doesn't exsite! Do you want to add a new SousFamille?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        AddSousFamille AddSousFamille = new AddSousFamille {
                            StartPosition = FormStartPosition.CenterParent
                        };
                        AddSousFamille.ShowDialog(this);
                    }
                    else
                    {
                        return;
                    }
                }
                if (!MarqueController.FindMarqueByMarqueName(MarqueName))
                {
                    if (MessageBox.Show("Marque doesn't exsite! Do you want to add a new Marque?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        AddMarque AddMarque = new AddMarque {
                            StartPosition = FormStartPosition.CenterParent
                        };
                        AddMarque.ShowDialog(this);
                    }
                    else
                    {
                        return;
                    }
                }

                SousFamilles SousFamille = SousFamilleController.FindSousFamillesBySousFamilleName(SousFamilleName);
                Marques      Marque      = MarqueController.FindMarquesByMarqueName(MarqueName);
                Articles     Article     = new Articles(this.label_ReferenceArticle.Text, Description, FamilleController.FindFamillesByRefSousFamille(SousFamille.RefSousFamille), SousFamille, Marque, float.Parse(PrixHT), int.Parse(Quantite));

                if (!ArticleController.CompareArticles(ArticleController.FindArticlesByRefArticle(Article.RefArticle), Article))
                {
                    ArticleDao.ModifyArticle(Article);
                    if (ArticleController.FindArticleByRefArticle(Article.RefArticle))
                    {
                        MessageBox.Show("Modify succeed!");
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("The article can't be the same before and after modification!");
                    return;
                }
            }
        }
        /// <summary>
        /// Add a sousfamille to the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_Add_Click(object sender, EventArgs e)
        {
            var SousFamilleName = this.textBox_SousFamilleName.Text;
            var FamilleName     = this.label_Famille_Name.Text;

            if (SousFamilleName == "")
            {
                MessageBox.Show("Please enter the SousFamille Name!", "ERROR");
                return;
            }

            if (SousFamilleName == FamilleName)
            {
                MessageBox.Show("SousFamilleName and FamilleName can't be the same!", "ERROR");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (SousFamilleName == "Familles")
            {
                MessageBox.Show("SousFamilleName can't be Familles!");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (SousFamilleName == "Marques")
            {
                MessageBox.Show("SousFamilleName can't be Marques!");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (SousFamilleName == "Tous les articles")
            {
                MessageBox.Show("SousFamilleName can't be Tous les articles!", "ERROR");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (MarqueController.FindMarqueByMarqueName(SousFamilleName))
            {
                MessageBox.Show("This name has already been used by a Marque!", "ERROR");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (FamilleController.FindFamilleByFamilleName(SousFamilleName))
            {
                MessageBox.Show("This name has already been used by a Famille!", "ERROR");
                this.textBox_SousFamilleName.Text = "";
                return;
            }

            if (SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
            {
                MessageBox.Show("SousFamille Already exsited!", "ERROR");
                this.textBox_SousFamilleName.Text = "";
                return;
            }
            else
            {
                if (!FamilleController.FindFamilleByFamilleName(FamilleName))
                {
                    if (MessageBox.Show("Famille doesn't exsite! Do you want to add a new Famille?", "Confirm Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        Familles NewFamille = new Familles(FamilleName);
                        NewFamille.RefFamille = FamilleDao.GetMaxRefFamille() + 1;
                        FamilleDao.AddFamille(NewFamille);
                        if (FamilleController.FindFamilleByFamilleName(FamilleName))
                        {
                            MessageBox.Show("Add Famille succeed!");
                        }
                    }
                }
                SousFamilles SousFamille = new SousFamilles(SousFamilleName);
                Familles     Famille     = FamilleController.FindFamillesByFamilleName(FamilleName);
                SousFamille.RefSousFamille = SousFamilleDao.GetMaxRefSousFamille() + 1;

                SousFamilleDao.AddSousFamille(SousFamille, Famille);

                if (SousFamilleController.FindSousFamilleBySousFamilleName(SousFamilleName))
                {
                    MessageBox.Show("Add SousFamille succeed!");
                    this.Close();
                }
            }
        }