示例#1
0
        /// <summary>
        /// Raised when the user double click on the ListView to edit the item.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LvItems_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (LvItems.Columns[0].Text == "RefArticle" && LvItems.SelectedItems.Count == 1)
            {
                FormEditArticle formEditArticle = new FormEditArticle(LvItems.SelectedItems[0].Text);
                formEditArticle.ShowDialog();

                RefreshListView();
            }
        }
示例#2
0
        /// <summary>
        /// Raised when the user presses a key.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LvItems_KeyUp(object sender, KeyEventArgs e)
        {
            // Edit the item
            if (e.KeyCode.Equals(Keys.Enter) && LvItems.Columns[0].Text == "RefArticle" && LvItems.SelectedItems.Count == 1)
            {
                FormEditArticle formEditArticle = new FormEditArticle(LvItems.SelectedItems[0].Text);
                formEditArticle.ShowDialog();

                RefreshListView();
            }
            // Refresh data
            else if (e.KeyCode.Equals(Keys.F5))
            {
                TreeView_Initialize();
                RefreshListView();
            }
            // Delete the item
            else if (e.KeyCode.Equals(Keys.Delete) && LvItems.Columns[0].Text == "RefArticle" && LvItems.SelectedItems.Count == 1)
            {
                try
                {
                    SQLiteConnection.Open();
                }
                catch (Exception) { }

                string StrRefArticle = LvItems.SelectedItems[0].Text;

                DialogResult DrDelete = MessageBox.Show("Voulez-vous vraiment supprimer l'article suivant : " + StrRefArticle + " ?", "Article Deletion", MessageBoxButtons.YesNo);
                if (DrDelete.Equals(DialogResult.Yes))
                {
                    using (SQLiteCommand SqlCommand = new SQLiteCommand("DELETE FROM Articles WHERE RefArticle = '" + StrRefArticle + "'", SQLiteConnection))
                        SqlCommand.ExecuteNonQuery();

                    RefreshListView();
                    ShowStatusStrip();
                }

                SQLiteConnection.Close();
            }
        }
示例#3
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;
            }
        }