Exemple #1
0
 private void ajouterToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (ListView.Text.Equals("Articles"))
     {
         FormAddArticle FormAddArticle = new FormAddArticle
         {
             StartPosition = FormStartPosition.CenterParent,
             Owner         = this
         };
         FormAddArticle.ShowDialog(this);
     }
     else if (ListView.Text.Equals("Marques"))
     {
         FormAddMarque FormAddMarque = new FormAddMarque
         {
             StartPosition = FormStartPosition.CenterParent,
             Owner         = this,
         };
         FormAddMarque.ShowDialog(this);
     }
     else if (ListView.Text.Equals("Familles"))
     {
         FormAddFamille FormAddFamille = new FormAddFamille
         {
             StartPosition = FormStartPosition.CenterParent,
             Owner         = this
         };
         FormAddFamille.ShowDialog(this);
     }
     else if (ListView.Text.Equals("Sous-Familles"))
     {
         FormAddSousFamille FormAddSousFamille = new FormAddSousFamille
         {
             StartPosition = FormStartPosition.CenterParent,
             Owner         = this
         };
         FormAddSousFamille.ShowDialog(this);
     }
 }
Exemple #2
0
        /// <summary>
        /// Event raised when the user click on a CMS action. Perform the selected action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CmsModify_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Tag)
            {
            case "AddFamily":
                FormAddFamily NewFormFamily = new FormAddFamily();
                NewFormFamily.ShowDialog();

                TreeView_Initialize();
                ShowStatusStrip();

                break;

            case "EditFamily":
                FormEditFamily NewFormEditFamily = new FormEditFamily(GetObject(e.ClickedItem.Text));
                NewFormEditFamily.ShowDialog();

                TreeView_Initialize();
                RefreshListView();

                break;

            case "AddSubFamily":
                int RefFamily;
                try
                {
                    SQLiteConnection.Open();
                }
                catch (Exception) { }
                using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefFamille FROM Familles WHERE Nom = '" + GetObject(e.ClickedItem.Text) + "'", SQLiteConnection))
                {
                    using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                    {
                        SqlReader.Read();
                        RefFamily = Int32.Parse(SqlReader["RefFamille"].ToString());
                    }
                }
                FormAddSubFamily NewFormSubFamily = new FormAddSubFamily(RefFamily);
                NewFormSubFamily.ShowDialog();
                SQLiteConnection.Close();

                TreeView_Initialize();
                ShowStatusStrip();

                break;

            case "EditSubFamily":
                string Subfamily;
                try
                {
                    SQLiteConnection.Open();
                }
                catch (Exception) { }
                using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefSousFamille, Nom FROM SousFamilles WHERE Nom = '" + GetObject(e.ClickedItem.Text) + "'", SQLiteConnection))
                {
                    using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                    {
                        SqlReader.Read();
                        Subfamily = SqlReader["Nom"].ToString();
                    }
                }
                FormEditSubFamily NewFormEditSubFamily = new FormEditSubFamily(Subfamily);
                NewFormEditSubFamily.ShowDialog();
                SQLiteConnection.Close();

                TreeView_Initialize();
                RefreshListView();

                break;

            case "AddBrand":
                FormAddBrand NewFormBrand = new FormAddBrand();
                NewFormBrand.ShowDialog();

                TreeView_Initialize();
                ShowStatusStrip();

                break;

            case "EditBrand":
                FormEditBrand NewFormEditBrand = new FormEditBrand(GetObject(e.ClickedItem.Text));
                NewFormEditBrand.ShowDialog();

                TreeView_Initialize();
                RefreshListView();

                break;

            case "AddArticle":
                FormAddArticle NewFormArticle = new FormAddArticle();
                NewFormArticle.ShowDialog();

                RefreshListView();
                ShowStatusStrip();

                break;

            case "EditArticle":
                string          RefArticle         = GetObject(e.ClickedItem.Text);
                FormEditArticle NewFormEditArticle = new FormEditArticle(RefArticle);
                NewFormEditArticle.ShowDialog();

                RefreshListView();

                break;

            case "DeleteArticle":
                string       StrRefArticle = GetObject(e.ClickedItem.Text);
                DialogResult DrDelete      = MessageBox.Show("Voulez-vous vraiment supprimer l'article suivant : " + StrRefArticle + " ?", "Suppression de l'article", MessageBoxButtons.YesNo);
                if (DrDelete.Equals(DialogResult.Yes))
                {
                    try
                    {
                        SQLiteConnection.Open();
                    }
                    catch (Exception) { }

                    using (SQLiteCommand SqlCommand = new SQLiteCommand("DELETE FROM Articles WHERE RefArticle = '" + StrRefArticle + "'", SQLiteConnection))
                        SqlCommand.ExecuteNonQuery();

                    RefreshListView();
                    ShowStatusStrip();
                }

                break;

            case "DeleteBrand":
                string StrBrand = GetObject(e.ClickedItem.Text);
                DrDelete = MessageBox.Show("Voulez-vous vraiment supprimer la marque suivante : " + StrBrand + " ?", "Suppression de la marque", MessageBoxButtons.YesNo);
                if (DrDelete.Equals(DialogResult.Yes))
                {
                    try
                    {
                        SQLiteConnection.Open();
                    }
                    catch (Exception) { }

                    int RefBrand;
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefMarque FROM Marques WHERE Nom = '" + StrBrand + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            SqlReader.Read();
                            RefBrand = Int32.Parse(SqlReader["RefMarque"].ToString());
                        }
                    }

                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefArticle FROM Articles WHERE RefMarque = '" + RefBrand + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            if (SqlReader.HasRows)
                            {
                                MessageBox.Show("Vous ne pouvez pas supprimer cette marque car elle contient encore des articles.", "Erreur Suppression", MessageBoxButtons.OK);
                            }
                            else
                            {
                                using (SQLiteCommand SqlCommand2 = new SQLiteCommand("DELETE FROM Marques WHERE RefMarque = '" + RefBrand + "'", SQLiteConnection))
                                    SqlCommand2.ExecuteNonQuery();

                                TreeView_Initialize();
                                ShowStatusStrip();
                            }
                        }
                    }
                }

                break;

            case "DeleteFamily":
                string StrFamily = GetObject(e.ClickedItem.Text);
                DrDelete = MessageBox.Show("Voulez-vous vraiment supprimer la famille suivante : " + StrFamily + " ?", "Suppression de la famille", MessageBoxButtons.YesNo);
                if (DrDelete.Equals(DialogResult.Yes))
                {
                    try
                    {
                        SQLiteConnection.Open();
                    }
                    catch (Exception) { }

                    int RefFamily2;
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefFamille FROM Familles WHERE Nom = '" + StrFamily + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            SqlReader.Read();
                            RefFamily2 = Int32.Parse(SqlReader["RefFamille"].ToString());
                        }
                    }
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefSousFamille FROM SousFamilles WHERE RefFamille = '" + RefFamily2 + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            if (SqlReader.HasRows)
                            {
                                MessageBox.Show("Vous ne pouvez pas supprimer cette famille car elle contient encore des sous-familles.", "Erreur Suppression", MessageBoxButtons.OK);
                            }
                            else
                            {
                                using (SQLiteCommand SqlCommand2 = new SQLiteCommand("DELETE FROM Familles WHERE RefFamille = '" + RefFamily2 + "'", SQLiteConnection))
                                    SqlCommand2.ExecuteNonQuery();

                                TreeView_Initialize();
                                ShowStatusStrip();
                            }
                        }
                    }
                }

                break;

            case "DeleteSubFamily":
                string StrSubFamily = GetObject(e.ClickedItem.Text);
                DrDelete = MessageBox.Show("Voulez-vous vraiment supprimer la sous-famille suivante : " + StrSubFamily + " ?", "Suppression de la sous-famille", MessageBoxButtons.YesNo);
                if (DrDelete.Equals(DialogResult.Yes))
                {
                    try
                    {
                        SQLiteConnection.Open();
                    }
                    catch (Exception) { }

                    int RefSubFamily;
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefSousFamille FROM SousFamilles WHERE Nom = '" + StrSubFamily + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            SqlReader.Read();
                            RefSubFamily = Int32.Parse(SqlReader["RefSousFamille"].ToString());
                        }
                    }
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("SELECT RefArticle FROM Articles WHERE RefSousFamille = '" + RefSubFamily + "'", SQLiteConnection))
                    {
                        using (SQLiteDataReader SqlReader = SqlCommand.ExecuteReader())
                        {
                            if (SqlReader.HasRows)
                            {
                                MessageBox.Show("Vous ne pouvez pas supprimer cette sous-famille car elle contient encore des articles.", "Erreur Suppression", MessageBoxButtons.OK);
                            }
                            else
                            {
                                using (SQLiteCommand SqlCommand2 = new SQLiteCommand("DELETE FROM SousFamilles WHERE RefSousFamille = '" + RefSubFamily + "'", SQLiteConnection))
                                    SqlCommand2.ExecuteNonQuery();

                                TreeView_Initialize();
                                ShowStatusStrip();
                            }
                        }
                    }
                }

                break;
            }
        }