Example #1
0
        /// <summary>
        /// Returns the list of all the articles
        /// </summary>
        /// <returns>list of all the articles</returns>
        public List <Models.Article> Get_Articles_List()
        {
            List <Models.Article> Articles = new List <Models.Article>();

            System.Data.SQLite.SQLiteCommand cmd = SQL_Connection.CreateCommand();
            cmd.CommandText = "SELECT RefArticle, Description, SousFamilles.Nom as SousFamille, m.Nom as Marque, PrixHT, Quantite FROM Articles natural join SousFamilles inner join Marques m on m.RefMarque = Articles.refMarque";

            System.Data.SQLite.SQLiteDataReader Articles_Reader = cmd.ExecuteReader();

            int Article_Index     = Articles_Reader.GetOrdinal("RefArticle");
            int Description_Index = Articles_Reader.GetOrdinal("Description");
            int Sub_Familly_Index = Articles_Reader.GetOrdinal("SousFamille");
            int Brand_Index       = Articles_Reader.GetOrdinal("Marque");
            int Price_Index       = Articles_Reader.GetOrdinal("PrixHT");
            int Quantity_Index    = Articles_Reader.GetOrdinal("Quantite");

            while (Articles_Reader.Read())
            {
                Models.Article A = new Models.Article();


                A.Ref_Article      = Articles_Reader.GetString(Article_Index);
                A.Description      = Articles_Reader.GetString(Description_Index);
                A.Sub_Familly_Name = Articles_Reader.GetString(Sub_Familly_Index);
                A.Brand_Name       = Articles_Reader.GetString(Brand_Index);
                A.Price_HT         = Articles_Reader.GetFloat(Price_Index);
                A.Quantity         = Articles_Reader.GetInt32(Quantity_Index);

                Articles.Add(A);
            }

            return(Articles);
        }
Example #2
0
        /// <summary>
        /// Returns the article from its reference
        /// </summary>
        /// <param name="refArticle"></param>
        /// <returns>the article</returns>
        public Models.Article Get_Article(string refArticle)
        {
            Models.Article Article = new Models.Article();
            System.Data.SQLite.SQLiteCommand cmd = SQL_Connection.CreateCommand();
            cmd.CommandText = "SELECT RefArticle, Description, SousFamilles.Nom as SousFamille, m.Nom as Marque, PrixHT, Quantite FROM Articles natural join SousFamilles inner join Marques m on m.RefMarque = Articles.refMarque WHERE RefArticle = ?";

            System.Data.SQLite.SQLiteParameter Id_Parameter = new System.Data.SQLite.SQLiteParameter();
            Id_Parameter.Value = refArticle;
            cmd.Parameters.Add(Id_Parameter);

            System.Data.SQLite.SQLiteDataReader Articles_Reader = cmd.ExecuteReader();

            int Article_Index     = Articles_Reader.GetOrdinal("RefArticle");
            int Description_Index = Articles_Reader.GetOrdinal("Description");
            int Sub_Familly_Index = Articles_Reader.GetOrdinal("SousFamille");
            int Brand_Index       = Articles_Reader.GetOrdinal("Marque");
            int Price_Index       = Articles_Reader.GetOrdinal("PrixHT");
            int Quantity_Index    = Articles_Reader.GetOrdinal("Quantite");

            if (Articles_Reader.Read())
            {
                Models.Article A = new Models.Article();


                Article.Ref_Article      = Articles_Reader.GetString(Article_Index);
                Article.Description      = Articles_Reader.GetString(Description_Index);
                Article.Sub_Familly_Name = Articles_Reader.GetString(Sub_Familly_Index);
                Article.Brand_Name       = Articles_Reader.GetString(Brand_Index);
                Article.Price_HT         = Articles_Reader.GetFloat(Price_Index);
                Article.Quantity         = Articles_Reader.GetInt32(Quantity_Index);
            }

            return(Article);
        }
Example #3
0
 /// <summary>
 /// Executed when we click on the delete article button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void On_Delete_Article_Event(object sender, EventArgs e)
 {
     Models.Article Article = getSelectedArticle();
     if (Article != null)
     {
         On_Delete_Article(getSelectedArticle());
     }
 }
Example #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="Article">null for a creation or the article to modify one</param>
        public AddArticleForm(Models.Article Article)
        {
            InitializeComponent();
            this.Article = Article;

            Load_Sub_Familly();
            Load_Brand();

            if (Article != null)
            {
                Auto_Fill();
            }
        }
Example #5
0
        /// <summary>
        /// Returns the selected item in the listView
        /// </summary>
        /// <returns>A model object of the selected article</returns>
        public Models.Article getSelectedArticle()
        {
            Models.Article Article = new Models.Article();

            if (Article_List_View.SelectedItems.Count == 0)
            {
                return(null);
            }

            ListViewItem Item = Article_List_View.SelectedItems[0];

            Models.Article A = Database.GetInstance().Get_Article(Item.SubItems[0].Text);
            return(A);
        }
Example #6
0
        /// <summary>
        /// Executed when we click on the create article button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void On_Create_Article_Event(object sender, EventArgs e)
        {
            AddArticleForm Aaf    = new AddArticleForm(null);
            DialogResult   Result = Aaf.ShowDialog();

            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database       DB = Database.GetInstance();
                Models.Article A  = DB.Get_Article(Aaf.Inserted_Id);

                String[]     Row  = { A.Ref_Article, A.Description, A.Sub_Familly_Name, A.Brand_Name, "" + A.Price_HT, "" + A.Quantity };
                ListViewItem Item = new ListViewItem(Row);
                this.Article_List_View.Items.Add(Item);
                this.Status_Label.Text = "Article : " + A.Ref_Article + " ajouté !";
            }
        }
Example #7
0
        /// <summary>
        /// Open the modify Article form
        /// </summary>
        /// <param name="Article"></param>
        public void Open_Modify_Article(Models.Article Article)
        {
            AddArticleForm Aaf    = new AddArticleForm(Article);
            DialogResult   Result = Aaf.ShowDialog();

            // Refresh the view.
            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database       DB = Database.GetInstance();
                Models.Article Modified_Article = DB.Get_Article(Article.Ref_Article);

                ListViewItem Lvi = Article_List_View.SelectedItems[0];
                Lvi.SubItems[0].Text = Modified_Article.Ref_Article;
                Lvi.SubItems[1].Text = Modified_Article.Description;
                Lvi.SubItems[2].Text = Modified_Article.Sub_Familly_Name;
                Lvi.SubItems[3].Text = Modified_Article.Brand_Name;
                Lvi.SubItems[4].Text = "" + Modified_Article.Price_HT;
                Lvi.SubItems[5].Text = "" + Modified_Article.Quantity;
            }
        }
Example #8
0
        /// <summary>
        /// Executes the article erasement
        /// </summary>
        /// <param name="Article"></param>
        private void On_Delete_Article(Models.Article Article)
        {
            DialogResult Res = MessageBox.Show(this, "Etes vous sûr de vouloir supprimer l'article : " + Article.Ref_Article + " ?", "Supprimer", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (Res == DialogResult.Yes)
            {
                bool success = Database.GetInstance().Delete_Article(Article.Ref_Article);
                if (success)
                {
                    Res = MessageBox.Show(this, "Suppression réussie !", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (Res == DialogResult.OK)
                    {
                        Article_List_View.Items.Remove(Article_List_View.SelectedItems[0]);
                    }
                    this.Status_Label.Text = "Suppréssion réussi !";
                }
                else
                {
                    Res = MessageBox.Show(this, "Erreur lors de la supression", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Status_Label.Text = "Echec de la suppréssion réussi !";
                }
            }
        }
Example #9
0
 /// <summary>
 /// Checks the key pressed and execute the corresponding action
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void On_Key_Pressed(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F5)
     {
         Load_Articles();
     }
     else if (e.KeyCode == Keys.Enter)
     {
         Models.Article Article = getSelectedArticle();
         if (Article != null)
         {
             Open_Modify_Article(getSelectedArticle());
         }
     }
     else if (e.KeyCode == Keys.Delete)
     {
         Models.Article Article = getSelectedArticle();
         if (Article != null)
         {
             On_Delete_Article(getSelectedArticle());
         }
     }
 }