Ejemplo n.º 1
0
 private void Tick(DateTime curTick, DateTime lTick)
 {
     try {
         OnSecondPassed?.Invoke(curTick, lTick);
         if (MinutePassed(curTick, lTick))
         {
             OnMinutePassed?.Invoke(curTick, lTick);
         }
         if (HourPassed(curTick, lTick))
         {
             OnHourPassed?.Invoke(curTick, lTick);
         }
         if (DayPassed(curTick, lTick))
         {
             OnDayPassed?.Invoke(curTick, lTick);
         }
         if (MonthPassed(curTick, lTick))
         {
             OnMonthPassed?.Invoke(curTick, lTick);
         }
         if (YearPassed(curTick, lTick))
         {
             OnYearPassed?.Invoke(curTick, lTick);
         }
     } catch (Exception exc) {
         ExceptionCaught?.Invoke(exc);
     }
 }
Ejemplo n.º 2
0
 private void ForwardException(Exception ex)
 {
     if (ex is AggregateException ae)
     {
         foreach (Exception ie in ae.InnerExceptions)
         {
             ExceptionCaught?.Invoke(this, ie);
         }
     }
     else
     {
         ExceptionCaught?.Invoke(this, ex);
     }
 }
Ejemplo n.º 3
0
        private void SendCallback(IAsyncResult ar)
        {
            Object[]        args   = (Object[])ar.AsyncState;
            Socket          socket = (Socket)args[0];
            ExceptionCaught caught = (ExceptionCaught)args[1];

            try
            {
                socket.EndSend(ar);
                logReport.OnLogReport("socket send msg to tcp stream ok");
            }
            catch (Exception e)
            {
                caught(e);
            }
            finally
            {
                writing = false;
            }
        }
Ejemplo n.º 4
0
        internal void Write(IoBuffer ioBuffer, ExceptionCaught exceptionCaught)
        {
            if (!IsConnected())
            {
                throw new Exception("can't send data,socket connect is closed.");
            }
            if (ioBuffer.Length == 0)
            {
                logReport.OnDebugReport("skip write to sockt,iobuffer is empty");
                return;
            }
            if (writing)
            {
                logReport.OnDebugReport("skip write to sockt in this loop");
                return;
            }
            lock (wrlock)
            {
                if (writing)
                {
                    logReport.OnDebugReport("skip write to sockt in this loop");
                    return;
                }
                writing = true;
            }
            Socket socket = mTcp.Client;

            byte[] data = new byte[ioBuffer.Length];
            ioBuffer.Read(data, 0, data.Length);
            try
            {
                Object[] args = new Object[2];
                args[0] = socket;
                args[1] = exceptionCaught;
                socket.BeginSend(data, 0, data.Length, SocketFlags.None, new AsyncCallback(SendCallback), args);
            }
            finally
            {
                writing = false;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Retourne le nombre de sous familles de la base de donnée
        /// </summary>
        /// <returns></returns>
        public static int NbSubFamilies()
        {
            int Result = -1;

            var DataTableToReturn = new DataTable();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT COUNT(*) FROM SousFamilles;"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution
                        SQLiteDataAdapter Adapter = new SQLiteDataAdapter(Command);

                        // Récupération
                        Adapter.Fill(DataTableToReturn);
                        Result = Convert.ToInt32(DataTableToReturn.Rows[0][0].ToString());

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        MessageBox.Show("Echec" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Retourne l'article correspondant à la référence passée en paramètre
        /// </summary>
        /// <param name="ArticleRef"></param>
        /// <returns></returns>
        public static Article GetArticleById(String ArticleRef)
        {
            Article ArticleToReturn = null;

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Articles WHERE RefArticle = '" + ArticleRef + "';"))
                {
                    try
                    {
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            // Lecture de la ligne
                            Reader.Read();

                            // Creation de l'article à retourner
                            ArticleToReturn = new Article();

                            // Ajout des paramètres
                            ArticleToReturn.RefArticle   = Reader[0].ToString();
                            ArticleToReturn.Description  = Reader[1].ToString();
                            ArticleToReturn.RefSubFamily = SubFamilyDAO.GetSubFamilyById((int)Reader[2]);
                            ArticleToReturn.RefBrand     = BrandDAO.GetBrandById((int)Reader[3]);
                            ArticleToReturn.PriceHT      = float.Parse(Reader[4].ToString());
                            ArticleToReturn.Quantity     = (int)Reader[5];
                        }

                        Connection.Close();
                    }
                    // Dans le cas où l'article n'existe pas
                    catch (InvalidOperationException)
                    {
                        ArticleToReturn = null;

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        ArticleToReturn = null;

                        MessageBox.Show("Echec de la récupération de l'article " + ArticleRef + " \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(ArticleToReturn);
        }
Ejemplo n.º 7
0
 private Task OnExceptionCaught(Exception exception)
 {
     FirstClient.SetGameAsync(exception.Message + " from " + exception.Source + " in " + exception.TargetSite);
     return(ExceptionCaught?.Invoke(exception));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Compte le nombre de marques dans la base de données
        /// </summary>
        /// <returns></returns>
        public static int NbBrands()
        {
            // Initialisation du résultat à retourner
            int Result = -1;

            // DataTable récupèrant les résultats de la requete
            var DataTableToFill = new DataTable();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT COUNT(*) FROM Marques;"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution de la commande
                        SQLiteDataAdapter adp = new SQLiteDataAdapter(Command);

                        // Récupération des données
                        adp.Fill(DataTableToFill);
                        Result = Convert.ToInt32(DataTableToFill.Rows[0][0].ToString());

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        MessageBox.Show("Echec dans le comptage des marques \n " + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Retourne la marque correspondante au nom en paramètre
        /// </summary>
        /// <param name="BrandName"> Le nom de la marque à retourner </param>
        /// <returns></returns>
        public static Brand GetBrandByName(String BrandName)
        {
            Brand BrandToReturn = new Brand();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Marques WHERE Nom = '" + BrandName + "';"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            // Lecture de la ligne
                            Reader.Read();

                            // Ajout des paramètres
                            BrandToReturn.RefBrand  = (int)Reader[0];
                            BrandToReturn.NameBrand = Reader[1].ToString();
                        }

                        Connection.Close();
                    }
                    // Dans le cas où la marque n'existe pas
                    catch (InvalidOperationException)
                    {
                        BrandToReturn = null;

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Retourne null en cas d'erreur
                        BrandToReturn = null;

                        MessageBox.Show("Echec de la récupération de la marque " + BrandName + "  \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(BrandToReturn);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Ajoute la marque en entrée à la base de donnée
        /// </summary>
        /// <param name="BrandToAdd"></param>
        public static void AddBrand(Brand BrandToAdd)
        {
            // Vérifications
            if (BrandToAdd.NameBrand.Equals("") || BrandToAdd.NameBrand == null)
            {
                throw new ArgumentNullException("Brand Name");
            }
            if (BrandToAdd.RefBrand == -1)
            {
                throw new ArgumentException("La référence de la Marque ne doit pas être égale à -1");
            }

            // Ajout à la base de donnée
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("INSERT INTO Marques VALUES (" + BrandToAdd.RefBrand + ", '" + BrandToAdd.NameBrand + "');"))
                    {
                        // Execution de la requete
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Marque " + BrandToAdd.NameBrand + " non créée\n" + ExceptionCaught.Message.ToString(), ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Modifie l'article passé en référence
        /// </summary>
        /// <param name="RefArticle"> La Référence de l'article à modifier </param>
        /// <param name="NewDescription"> La nouvelle description de l'article </param>
        /// <param name="NewRefSubFamily"> La nouvelle sous famille de l'article </param>
        /// <param name="NewRefBrand"> La nouvelle marque de l'article </param>
        /// <param name="NewPrice"> Le nouveau prix de l'article </param>
        /// <param name="NewQuantity"> La nouvelle quantité </param>
        public static void EditArticle(String RefArticle, String NewDescription, SubFamily NewRefSubFamily, Brand NewRefBrand, float NewPrice, int NewQuantity)
        {
            // Vérification
            if (VerifArticleRef(RefArticle) == false)
            {
                throw new ArgumentException("La référence de l'article est invalide");
            }
            if (NewDescription.Equals("") || NewDescription == null)
            {
                throw new ArgumentNullException("Description");
            }

            // Modification de la base de données
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("UPDATE Familles SET Description = '" + NewDescription + "', RefSousFamille = " + NewRefSubFamily.RefSubFamily + ", RefMarque = " + NewRefBrand.RefBrand + ", PrisHT = " + NewPrice + ", Quantité = " + NewQuantity + " WHERE RefArticle = " + RefArticle + "; "))
                    {
                        // Execution de la requete
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Article " + RefArticle + " non modifièe : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Lance l'exportation des données vers le path choisit, à l'appuie sur le bouton "Exporter"
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="Event"></param>
        private void ExportButton_Click(object Sender, EventArgs Event)
        {
            // met le maximun de la progress bar au nombre de ligne
            ExportProgressBar.Maximum = ArticleDAO.NbArticles();


            try
            {
                // écrit les titres des colonnes en première ligne
                var csv = new StringBuilder();
                var TitleQuantityAndDescriptionRow = "Description";
                var TitleRefRow       = "Ref";
                var TitleBrandRow     = "Marque";
                var TitleFamilyRow    = "Famille";
                var TitleSubFamilyRow = "Sous-Famille";
                var TitlePriceRow     = "Prix H.T.";

                ExportProgressBar.PerformStep();

                // formate cette ligne puis l'ajoute au csv
                var TitleLine = string.Format("{0};{1};{2};{3};{4};{5}", TitleQuantityAndDescriptionRow, TitleRefRow, TitleBrandRow, TitleFamilyRow, TitleSubFamilyRow, TitlePriceRow);
                csv.AppendLine(TitleLine);
                // fait la meme chose pour tout les articles de la bd
                Article[] AllArticle = ArticleDAO.GetAllArticles();
                foreach (Article A in AllArticle)
                {
                    // une ligne est crée, on avance donc d'une étape dans la progress bar
                    ExportProgressBar.PerformStep();
                    var QuantityAndDescriptionRow = A.Quantity + " " + A.Description;
                    var RefRow       = A.RefArticle;
                    var BrandRow     = A.RefBrand.ToString();
                    var FamilyRow    = A.RefSubFamily.RefFamily.ToString();
                    var SubFamilyRow = A.RefSubFamily.ToString();
                    var PriceRow     = A.PriceHT.ToString();
                    var NewLine      = string.Format("{0};{1};{2};{3};{4};{5}", QuantityAndDescriptionRow, RefRow, BrandRow, FamilyRow, SubFamilyRow, PriceRow);
                    csv.AppendLine(NewLine);
                }

                // ecrit les données dans le fichier au path choisit
                File.WriteAllText(CSVNameTextBox.Text, csv.ToString());
            }
            catch (Exception ExceptionCaught)
            {
                MessageBox.Show("L'export à échoué \n" + ExceptionCaught.Message.ToString(), ExceptionCaught.GetType().ToString());
            }
            this.Close();
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Récupère la sous-famille portant le nom en entrèe et appratenant à la famille en entrée
        /// </summary>
        /// <param name="SubFamilyName"> Le nom de la sous-famille à retourner</param>
        /// <param name="RefFamily"> La famille à laquelle appartient la sous-famille </param>
        /// <returns></returns>
        public static SubFamily GetSubFamilyByName(String SubFamilyName, Family RefFamily)
        {
            SubFamily SubFamilyToReturn = new SubFamily();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM SousFamilles WHERE Nom = '" + SubFamilyName + "' AND RefFamille = " + RefFamily.RefFamily + ";"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution de la commande
                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            // Lecture de la ligne
                            Reader.Read();

                            // Ajout des paramètres
                            SubFamilyToReturn.RefSubFamily  = (int)Reader[0];
                            SubFamilyToReturn.RefFamily     = FamilyDAO.GetFamilyById((int)Reader[1]);
                            SubFamilyToReturn.NameSubFamily = Reader[2].ToString();
                        }

                        Connection.Close();
                    }
                    // dans le cas où il n'existe pas de sous familles avec cet id
                    catch (InvalidOperationException)
                    {
                        SubFamilyToReturn = null;

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Retourne null en cas d'échec
                        SubFamilyToReturn = null;

                        MessageBox.Show("Echec de la récupération de la SousFamille " + SubFamilyName + " \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(SubFamilyToReturn);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Retourne toutes les sous-familles de la base de donnée
        /// </summary>
        /// <returns></returns>
        public static SubFamily[] GetAllSubFamilies()
        {
            //The number of subFamily
            int nbSubFamily = SubFamilyDAO.NbSubFamilies();

            //The table to return
            SubFamily[] listToReturn = new SubFamily[nbSubFamily];

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM SousFamilles;"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            for (int currentSubFamilyIndex = 0; currentSubFamilyIndex < nbSubFamily; currentSubFamilyIndex++)
                            {
                                // Lecture de la ligne
                                Reader.Read();

                                // Creation de la famille
                                SubFamily SubFamilyToAdd = new SubFamily();

                                // Ajout des paramètres
                                SubFamilyToAdd.RefSubFamily  = (int)Reader[0];
                                SubFamilyToAdd.RefFamily     = FamilyDAO.GetFamilyById((int)Reader[1]);
                                SubFamilyToAdd.NameSubFamily = Reader[2].ToString();

                                // Ajout de la sous-famille à la liste à retourner
                                listToReturn.SetValue(SubFamilyToAdd, currentSubFamilyIndex);
                            }
                        }

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Rtourne null en cas d'erreur
                        listToReturn = null;

                        MessageBox.Show("Echec de la récupération des données de la table SousFamille  \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(listToReturn);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Compte le nombre d'articles dans la base de donéee
        /// </summary>
        /// <returns></returns>
        public static int NbArticles()
        {
            int Result = -1;

            var DataTableToReturn = new DataTable();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT COUNT(*) FROM Articles;"))
                {
                    try
                    {
                        //execute query
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        SQLiteDataAdapter adp = new SQLiteDataAdapter(Command);
                        adp.Fill(DataTableToReturn);
                        Result = Convert.ToInt32(DataTableToReturn.Rows[0][0].ToString());
                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        Connection.Close();
                        MessageBox.Show("Echec dans de décompte du nombre d'articles : \n " + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());
                    }
                }
            }

            return(Result);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Supprime l'article correspondant à la ref en entrée
        /// </summary>
        /// <param name="RefArticleToDelete"></param>
        public static void DeleteArticle(String RefArticleToDelete)
        {
            // Supression de l'article dans la base de donnée
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("DELETE FROM Articles WHERE RefArticle = '" + RefArticleToDelete + "'; "))
                    {
                        // Execution de la requête
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Article " + RefArticleToDelete + " non supprimée : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Change le nom de la famille
        /// </summary>
        /// <param name="RefFamily"></param>
        /// <param name="NewFamilyName"></param>
        public static void EditFamily(int RefFamily, String NewFamilyName)
        {
            // Verifications
            if (NewFamilyName.Equals("") || NewFamilyName == null)
            {
                throw new ArgumentNullException("Famille Ref");
            }

            // Modification de la base de données
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("UPDATE Familles SET Nom = '" + NewFamilyName + "' WHERE RefFamille = " + RefFamily + "; "))
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution de la requete
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Famille " + RefFamily + " non modifièe : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Change le nom de la marque en paramètre
        /// </summary>
        /// <param name="BrandRef"> La marque à modifier </param>
        /// <param name="NewBrandName"> Le nouveau nom </param>
        public static void EditBrand(int BrandRef, String NewBrandName)
        {
            // Vérifications
            if (NewBrandName.Equals("") || NewBrandName == null)
            {
                throw new ArgumentNullException("Brand Ref");
            }

            // Ajout à la base de données
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("UPDATE Marques SET Nom = '" + NewBrandName + "' WHERE RefMarque = " + BrandRef + "; "))
                    {
                        // Execution de la requete
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Echec de la modification de la marque " + BrandRef + " : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Retourne toutes les familles de la base de données
        /// </summary>
        /// <returns></returns>
        public static Family[] GetAllFamilies()
        {
            // Nombre de familles dans la base de données
            int NbFamilies = FamilyDAO.NbFamilies();

            // Tableau de familles à retourner
            Family[] listToReturn = new Family[NbFamilies];

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Familles;"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            for (int CurrentFamilyIndex = 0; CurrentFamilyIndex < NbFamilies; CurrentFamilyIndex++)
                            {
                                // Lecture de la ligne
                                Reader.Read();

                                // Création d'une nouvelle famille
                                Family FamilyToAdd = new Family();

                                // Ajout des paramètres
                                FamilyToAdd.RefFamily  = (int)Reader[0];
                                FamilyToAdd.NameFamily = Reader[1].ToString();

                                // Ajout de la famille au tableau
                                listToReturn.SetValue(FamilyToAdd, CurrentFamilyIndex);
                            }
                        }

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Retourne null en cas d'erreur
                        listToReturn = null;

                        MessageBox.Show("Echec de la récupération des données de la table Familles  \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(listToReturn);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Retourne toutes les marques de la base de données
        /// </summary>
        /// <returns></returns>
        public static Brand[] GetAllBrands()
        {
            //The number of brands to get
            int NbBrands = BrandDAO.NbBrands();

            //The table to return
            Brand[] listToReturn = new Brand[NbBrands];

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Marques;"))
                {
                    try
                    {
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            for (int currentBrandIndex = 0; currentBrandIndex < NbBrands; currentBrandIndex++)
                            {
                                Reader.Read();

                                Brand BrandToAdd = new Brand();

                                BrandToAdd.RefBrand  = (int)Reader[0];
                                BrandToAdd.NameBrand = Reader[1].ToString();

                                listToReturn.SetValue(BrandToAdd, currentBrandIndex);
                            }
                        }

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Retourne null en cas d'erreur
                        listToReturn = null;

                        MessageBox.Show("Echec de la récupération des données de la table Marques  \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(listToReturn);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Retourne la famille correspondant à la ref en entrée
        /// </summary>
        /// <param name="FamilyRef"></param>
        /// <returns></returns>
        public static Family GetFamilyById(int FamilyRef)
        {
            Family FamilyToReturn = new Family();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Familles WHERE RefFamille = '" + FamilyRef + "';"))
                {
                    try
                    {
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            // Lecture de la ligne
                            Reader.Read();

                            // Création d'une famille
                            FamilyToReturn = new Family();

                            // Ajout des paramètres
                            FamilyToReturn.RefFamily  = (int)Reader[0];
                            FamilyToReturn.NameFamily = Reader[1].ToString();
                        }

                        Connection.Close();
                    }
                    // Dans le cas où il n'y a pas de famille avec cet id
                    catch (InvalidOperationException)
                    {
                        FamilyToReturn = null;

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        // Retourne null en cas d'erreur
                        FamilyToReturn = null;

                        MessageBox.Show("Echec de la récupération de la Familles " + FamilyRef + "  \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(FamilyToReturn);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get the Brand corresponding to the Ref BrandRef
        /// </summary>
        /// <param name="BrandRef"></param>
        /// <returns></returns>
        public static Brand GetBrandById(int BrandRef)
        {
            Brand BrandToReturn = new Brand();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Marques WHERE RefMarque = " + BrandRef + ";"))
                {
                    try
                    {
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            Reader.Read();

                            BrandToReturn.RefBrand  = (int)Reader[0];
                            BrandToReturn.NameBrand = Reader[1].ToString();
                        }
                    }
                    // Dans le cas où la marque n'existe pas
                    catch (InvalidOperationException)
                    {
                        BrandToReturn = null;

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        MessageBox.Show("Echec de la récupération de la marque " + BrandRef + " \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        BrandToReturn = null;

                        Connection.Close();
                    }
                }
            }

            return(BrandToReturn);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Supprime la famille correspondant à la ref en entrée
        /// </summary>
        /// <param name="RefFamily"></param>
        public static void DeleteFamily(int RefFamily)
        {
            //vérifications (la famille ne doit pas avoir de sous famille)
            DataTable SQLRequestDataTable = new DataTable();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT COUNT(*) FROM SousFamilles WHERE RefFamille = " + RefFamily + ";"))
                {
                    try
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution de la requête
                        SQLiteDataAdapter Adapter = new SQLiteDataAdapter(Command);

                        // Récupération des données
                        Adapter.Fill(SQLRequestDataTable);
                        if (Convert.ToInt32(SQLRequestDataTable.Rows[0][0]) != 0)
                        {
                            MessageBox.Show("Il existe des sous familles utilisant cette famille. Il n'est pas possible de la supprimer");
                            return;
                        }
                        Connection.Close();
                    }
                    catch (Exception)
                    {
                        Connection.Close();
                    }
                }
            }

            // Supression de la famille dans la base de donnée
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("DELETE FROM Familles WHERE RefFamille = " + RefFamily + "; "))
                    {
                        // Connection
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        // Execution de la requête
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Famille " + RefFamily + " non supprimée : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Supprime la marque correspodant à la ref passée en paramètre
        /// </summary>
        /// <param name="BrandRef"></param>
        public static void DeleteBrand(int BrandRef)
        {
            //vérifications (la marque ne doit pas avoir d'article)
            DataTable SQLRequestDataTable = new DataTable();

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT COUNT(*) FROM Articles WHERE RefMarque = " + BrandRef + ";"))
                {
                    try
                    {
                        //Execution de la requête
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        SQLiteDataAdapter adp = new SQLiteDataAdapter(Command);
                        adp.Fill(SQLRequestDataTable);
                        if (Convert.ToInt32(SQLRequestDataTable.Rows[0][0]) != 0)
                        {
                            MessageBox.Show("Il existe des articles utilisant cette marque. Il n'est pas possible de la supprimer");
                            return;
                        }

                        Connection.Close();
                    }
                    catch
                    {
                        Connection.Close();
                    }
                }
            }

            // Suppression de la base de donnée
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("DELETE FROM Marques WHERE RefMarque = " + BrandRef + "; "))
                    {
                        //Execution de la requête
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();
                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("La suppression de la marque " + BrandRef + " à échoué\n" + ExceptionCaught.Message.ToString(), ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Retourne tous les articles de la base de données
        /// </summary>
        /// <returns></returns>
        public static Article[] GetAllArticles()
        {
            //Nombre d'articles dans la base de donnée
            int nbArticle = ArticleDAO.NbArticles();

            //Tableau d'artiles à retourner
            Article[] listToReturn = new Article[nbArticle];

            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                using (var Command = new SQLiteCommand("SELECT * FROM Articles;"))
                {
                    try
                    {
                        Command.Connection = Connection;
                        Command.Connection.Open();

                        using (SQLiteDataReader Reader = Command.ExecuteReader())
                        {
                            for (int currentArticleIndex = 0; currentArticleIndex < nbArticle; currentArticleIndex++)
                            {
                                // Lecture de la ligne
                                Reader.Read();

                                // Création d'un article
                                Article ArticleToAdd = new Article();

                                // Ajout des paramètres
                                ArticleToAdd.RefArticle   = Reader[0].ToString();
                                ArticleToAdd.Description  = Reader[1].ToString();
                                ArticleToAdd.RefSubFamily = SubFamilyDAO.GetSubFamilyById((int)Reader[2]);
                                ArticleToAdd.RefBrand     = BrandDAO.GetBrandById((int)Reader[3]);
                                ArticleToAdd.PriceHT      = float.Parse(Reader[4].ToString());
                                ArticleToAdd.Quantity     = (int)Reader[5];

                                // Ajout de l'article à la liste à retourner
                                listToReturn.SetValue(ArticleToAdd, currentArticleIndex);
                            }
                        }

                        Connection.Close();
                    }
                    catch (Exception ExceptionCaught)
                    {
                        //En cas d'erreur, retourne null
                        listToReturn = null;

                        MessageBox.Show("Echec de la récupération des données de la table Article \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                        Connection.Close();
                    }
                }
            }

            return(listToReturn);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Ajoute l'article à la base de données
        /// </summary>
        /// <param name="ArticleToAdd"></param>
        public static void AddArticle(Article ArticleToAdd)
        {
            // Vérification
            if (VerifArticleRef(ArticleToAdd.RefArticle) == false)
            {
                throw new ArgumentException("La référence de l'article est invalide");
            }
            if (ArticleToAdd.Description.Equals("") || ArticleToAdd.Description == null)
            {
                throw new ArgumentNullException("Description");
            }

            // Ajout à la base de données
            using (var Connection = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
            {
                try
                {
                    using (var Command = new SQLiteCommand("INSERT INTO Articles VALUES ('" + ArticleToAdd.RefArticle + "', '" + ArticleToAdd.Description + "', " + ArticleToAdd.RefSubFamily.RefSubFamily + " , " + ArticleToAdd.RefBrand.RefBrand + " , '" + ArticleToAdd.GetPriceToString() + "' , " + ArticleToAdd.Quantity + ") ;"))
                    {
                        // Execution de la requete
                        Command.Connection = Connection;
                        Command.Connection.Open();
                        Command.ExecuteNonQuery();

                        Connection.Close();
                    }
                }
                catch (Exception ExceptionCaught)
                {
                    MessageBox.Show("Article " + ArticleToAdd.RefArticle + " non créé : \n" + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());

                    Connection.Close();
                }
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        /// Lance l'import au clic sur "importer et Ecraser"
        /// </summary>
        /// <param name="Sender"></param>
        /// <param name="Event"></param>
        private void OverwriteButton_Click(object Sender, EventArgs Event)
        {
            //Nombre de ligne du fichier (-1 pour éviter la colonne titre)
            int NbLine = -1;

            // test les erreurs avec le fichier CSV
            try
            {
                // compte le nombre de ligne du fichier
                using (var reader = new StreamReader(@CSVNameTextBox.Text))
                {
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(';');
                        NbLine++;
                    }
                }

                // met le maximun de la progress bar au nombre de ligne
                ImportProgressBar.Maximum = NbLine;

                using (var reader = new StreamReader(@CSVNameTextBox.Text))
                {
                    // nettoie la bd
                    try
                    {
                        using (var con = new SQLiteConnection("Data Source = Bacchus.SQLite ;Version=3;New=False;Compress=True;"))
                        {
                            // supprime le contenu de la table articles
                            using (var Command = new SQLiteCommand("DELETE FROM Articles;"))
                            {
                                //execute query
                                Command.Connection = con;
                                Command.Connection.Open();
                                Command.ExecuteNonQuery();
                                con.Close();
                            }

                            // supprime le contenu de la table marques
                            using (var Command = new SQLiteCommand("DELETE FROM Marques;"))
                            {
                                //execute query
                                Command.Connection = con;
                                Command.Connection.Open();
                                Command.ExecuteNonQuery();
                                con.Close();
                            }

                            // supprime le contenu de la table sousfamilles
                            using (var Command = new SQLiteCommand("DELETE FROM SousFamilles;"))
                            {
                                //execute query
                                Command.Connection = con;
                                Command.Connection.Open();
                                Command.ExecuteNonQuery();
                                con.Close();
                            }

                            // supprime le contenu de la table familles
                            using (var Command = new SQLiteCommand("DELETE FROM Familles;"))
                            {
                                //execute query
                                Command.Connection = con;
                                Command.Connection.Open();
                                Command.ExecuteNonQuery();
                                con.Close();
                            }
                        }
                    }
                    catch (Exception ExceptionCaught)
                    {
                        MessageBox.Show("Error while clearing db : " + ExceptionCaught.Message, ExceptionCaught.GetType().ToString());
                    }


                    bool TitleLine = true;
                    while (!reader.EndOfStream)
                    {
                        var line   = reader.ReadLine();
                        var values = line.Split(';');

                        // verification qui permet d'éviter la ligne titre
                        if (TitleLine == false)
                        {
                            // verifie si la reference est valide
                            if (ArticleDAO.VerifArticleRef(values[1]) == true)
                            {
                                // cherche la quantité, si elle existe, dans la premiere colonne
                                var firstSpaceIndex = values[0].IndexOf(" ");
                                var Quantity        = values[0].Substring(0, firstSpaceIndex);  // la quantite si elle existe
                                var Description     = values[0].Substring(firstSpaceIndex + 1); // la description si il y a un quantite
                                int IntQuantity;
                                if (int.TryParse(Quantity, out IntQuantity) == false)
                                {
                                    Description = values[0];
                                    IntQuantity = 1;
                                }


                                // si la famille existe la trouve sinon la creer
                                Family FamilyToAdd = FamilyDAO.GetFamilyByName(values[3]);
                                if (FamilyToAdd == null)
                                {
                                    FamilyToAdd = new Family(values[3]);
                                    FamilyDAO.AddFamily(FamilyToAdd);
                                }

                                // si la sous famille existe la trouve sinon la creer
                                SubFamily SubFamilyToAdd = SubFamilyDAO.GetSubFamilyByName(values[4], FamilyToAdd);
                                if (SubFamilyToAdd == null)
                                {
                                    SubFamilyToAdd = new SubFamily(values[4], FamilyToAdd);
                                    SubFamilyDAO.AddSubFamily(SubFamilyToAdd);
                                }

                                // si la marque existe la trouve sinon la creer
                                Brand BrandToAdd = BrandDAO.GetBrandByName(values[2]);
                                if (BrandToAdd == null)
                                {
                                    BrandToAdd = new Brand(values[2]);
                                    BrandDAO.AddBrand(BrandToAdd);
                                }

                                // vérifie si le prix est bien un double
                                float FloatPrice;
                                if (float.TryParse(values[5], out FloatPrice))
                                {
                                    // si la reference de l'article existe la trouve sinon creer l'article
                                    Article ArticleToAdd = ArticleDAO.GetArticleById(values[1]);
                                    if (ArticleToAdd == null)
                                    {
                                        //créer l'article et le rajoute à la bd
                                        ArticleToAdd = new Article(values[1], Description, SubFamilyToAdd, BrandToAdd, FloatPrice, IntQuantity);
                                        ArticleDAO.AddArticle(ArticleToAdd);

                                        // une ligne rajoutée, on avance donc d'une étape dans la progress bar
                                        ImportProgressBar.PerformStep();
                                    }
                                }
                            }
                        }
                        else
                        {
                            TitleLine = false;
                        }
                    }
                    this.Close();
                }
            }
            catch (Exception ExceptionCaught)
            {
                MessageBox.Show(ExceptionCaught.Message, "Erreur : " + ExceptionCaught.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }