Ejemplo n.º 1
0
        /// <summary>
        /// Deletes the brand if no article is linked to it
        /// </summary>
        /// <param name="Brand"></param>
        private void Delete_Brand(Models.Brand Brand)
        {
            DialogResult Res = MessageBox.Show(this, "Etes vous sûr de vouloir supprimer la sous famille : " + Brand.Name + " ?", "Supprimer", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (Res == DialogResult.Yes)
            {
                // Todo detect if connected to an article
                // Only load the affected row
                Database db = Database.GetInstance();
                if (db.Brand_Has_Articles_Associated(Brand.Id))
                {
                    Res = MessageBox.Show(this, "Erreur la marque est lié à un article", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                bool Sucess = db.Delete_Brand(Brand.Id);;
                if (Sucess)
                {
                    Res = MessageBox.Show(this, "Suppression réussie !", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Brand_List_View.Items.Remove(Brand_List_View.SelectedItems[0]);
                }
                else
                {
                    Res = MessageBox.Show(this, "Erreur lors de la suppression", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the currently selected item or null if none
        /// </summary>
        /// <returns>the currently selected item or null if none</returns>
        private Models.Brand Get_Selected_Item()
        {
            if (this.Brand_List_View.SelectedItems.Count != 0)
            {
                Models.Brand Brand = new Models.Brand();
                ListViewItem Item  = this.Brand_List_View.SelectedItems[0];
                Brand.Id   = int.Parse(Item.SubItems[0].Text);
                Brand.Name = Item.SubItems[1].Text;

                return(Brand);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Displays the add brand form
        /// </summary>
        private void Add_Brand()
        {
            AddBrandForm Form   = new AddBrandForm(null);
            DialogResult Result = Form.ShowDialog();

            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database     db             = Database.GetInstance();
                Models.Brand Modified_Brand = db.Get_Brand_With_Id(Form.Inserted_Id);

                String[]     row = { "" + Modified_Brand.Id, Modified_Brand.Name };
                ListViewItem lvi = new ListViewItem(row);
                Brand_List_View.Items.Add(lvi);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Displays the modify brand form
        /// </summary>
        /// <param name="Brand"></param>
        private void Modify_Brand(Models.Brand Brand)
        {
            AddBrandForm Form   = new AddBrandForm(Brand.Name);
            DialogResult Result = Form.ShowDialog();

            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database     db             = Database.GetInstance();
                Models.Brand Modified_Brand = db.Get_Brand_With_Id(Brand.Id);

                ListViewItem Lvi = Brand_List_View.SelectedItems[0];
                Lvi.SubItems[0].Text = Modified_Brand.Id.ToString();
                Lvi.SubItems[1].Text = Modified_Brand.Name;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Returns the list of all the brands
        /// </summary>
        /// <returns>list of all the brands</returns>
        public List <Models.Brand> Get_Brands()
        {
            List <Models.Brand> Brands = new List <Models.Brand>();

            System.Data.SQLite.SQLiteCommand cmd = SQL_Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM Marques";

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

            while (Brands_Reader.Read())
            {
                Models.Brand b = new Models.Brand();
                b.Id   = Brands_Reader.GetInt32(0);
                b.Name = Brands_Reader.GetString(1);
                Brands.Add(b);
            }

            return(Brands);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the brand from its id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns>the brand</returns>
        public Models.Brand Get_Brand_With_Id(int Id)
        {
            Models.Brand Brand = new Models.Brand();

            System.Data.SQLite.SQLiteCommand cmd = SQL_Connection.CreateCommand();
            cmd.CommandText = "SELECT * FROM Marques WHERE RefMarque = ?";

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

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

            if (Brand_Reader.Read())
            {
                Brand.Id   = Brand_Reader.GetInt32(0);
                Brand.Name = Brand_Reader.GetString(1);
            }

            return(Brand);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Event handler for the F5, Enter & delete keys.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void On_Key_Pressed(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.F5)
     {
         Load_Brands();
     }
     else if (e.KeyCode == Keys.Enter)
     {
         Models.Brand Brand = Get_Selected_Item();
         if (Brand != null)
         {
             Modify_Brand(Brand);
         }
     }
     else if (e.KeyCode == Keys.Delete)
     {
         Models.Brand Brand = Get_Selected_Item();
         if (Brand != null)
         {
             Delete_Brand(Brand);
         }
     }
 }