Beispiel #1
0
        /// <summary>
        /// Deletes the sub-family if no article is linked to it
        /// </summary>
        /// <param name="SubFamily"></param>
        private void Delete_SubFamily(Models.SubFamily SubFamily)
        {
            DialogResult Res = MessageBox.Show(this, "Etes vous sûr de vouloir supprimer la sous famille : " + SubFamily.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.SubFamily_Has_Articles_Associated(SubFamily.Id))
                {
                    Res = MessageBox.Show(this, "Erreur la Sous famille est lié à un article", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                bool Sucess = db.Delete_Sub_Familly(SubFamily.Id);
                if (Sucess)
                {
                    Res = MessageBox.Show(this, "Suppression réussie !", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    SubFamily_List_View.Items.Remove(SubFamily_List_View.SelectedItems[0]);
                }
                else
                {
                    Res = MessageBox.Show(this, "Erreur lors de la suppression", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Displays the add sub-family form
        /// </summary>
        private void Add_SubFamily()
        {
            AddSubFamilyForm Form   = new AddSubFamilyForm(null);
            DialogResult     Result = Form.ShowDialog();

            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database         db = Database.GetInstance();
                Models.SubFamily Modified_SubFamily = db.Get_Sub_Family_With_Id(Form.Inserted_Id);

                String[]     row = { "" + Modified_SubFamily.Id, "" + Modified_SubFamily.Family_Id, Modified_SubFamily.Name };
                ListViewItem lvi = new ListViewItem(row);
                SubFamily_List_View.Items.Add(lvi);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Displays the modify sub-family form
        /// </summary>
        /// <param name="SubFamily"></param>
        private void Modify_SubFamily(Models.SubFamily SubFamily)
        {
            AddSubFamilyForm Form   = new AddSubFamilyForm(SubFamily.Name);
            DialogResult     Result = Form.ShowDialog();

            if (Result == DialogResult.OK)
            {
                // Get the new value.
                Database         db = Database.GetInstance();
                Models.SubFamily Modified_SubFamily = db.Get_Sub_Family_With_Id(SubFamily.Id);

                ListViewItem Lvi = SubFamily_List_View.SelectedItems[0];
                Lvi.SubItems[0].Text = Modified_SubFamily.Id.ToString();
                Lvi.SubItems[1].Text = Modified_SubFamily.Family_Id.ToString();
                Lvi.SubItems[2].Text = Modified_SubFamily.Name;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Returns the currently selected item or null if none
        /// </summary>
        /// <returns>the currently selected item or null if none</returns>
        private Models.SubFamily Get_Selected_Item()
        {
            if (this.SubFamily_List_View.SelectedItems.Count != 0)
            {
                Models.SubFamily SubFamily = new Models.SubFamily();
                ListViewItem     Item      = this.SubFamily_List_View.SelectedItems[0];

                SubFamily.Id        = int.Parse(Item.SubItems[0].Text);
                SubFamily.Family_Id = int.Parse(Item.SubItems[1].Text);
                SubFamily.Name      = Item.SubItems[2].Text;

                return(SubFamily);
            }
            else
            {
                return(null);
            }
        }
Beispiel #5
0
        /// <summary>
        /// Returns the list of all the sub-families
        /// </summary>
        /// <returns>list of all the sub-families</returns>
        public List <Models.SubFamily> Get_Sub_Families()
        {
            List <Models.SubFamily> SubFamillies = new List <Models.SubFamily>();

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

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

            while (SubFamillies_Reader.Read())
            {
                Models.SubFamily sf = new Models.SubFamily();
                sf.Id        = SubFamillies_Reader.GetInt32(0);
                sf.Family_Id = SubFamillies_Reader.GetInt32(1);
                sf.Name      = SubFamillies_Reader.GetString(2);
                SubFamillies.Add(sf);
            }

            return(SubFamillies);
        }
Beispiel #6
0
        /// <summary>
        /// Returns the subfamily from its id
        /// </summary>
        /// <param name="Id"></param>
        /// <returns>the subfamily</returns>
        public Models.SubFamily Get_Sub_Family_With_Id(int Id)
        {
            Models.SubFamily SubFamilly = new Models.SubFamily();

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

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

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

            if (SubFamilly_Reader.Read())
            {
                SubFamilly.Id        = SubFamilly_Reader.GetInt32(0);
                SubFamilly.Family_Id = SubFamilly_Reader.GetInt32(1);
                SubFamilly.Name      = SubFamilly_Reader.GetString(2);
            }

            return(SubFamilly);
        }
Beispiel #7
0
        /// <summary>
        /// Returns a sub-family from its name
        /// </summary>
        /// <param name="SubFamilly"></param>
        /// <returns>the sub-family</returns>
        public Models.SubFamily Get_Sub_Family(string SubFamilly)
        {
            Models.SubFamily SubFamily = new Models.SubFamily();

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

            System.Data.SQLite.SQLiteParameter Name_Parameter = new System.Data.SQLite.SQLiteParameter();
            Name_Parameter.Value = SubFamilly;
            cmd.Parameters.Add(Name_Parameter);

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

            if (Familly_Reader.Read())
            {
                SubFamily.Id        = Familly_Reader.GetInt32(0);
                SubFamily.Family_Id = Familly_Reader.GetInt32(1);
                SubFamily.Name      = Familly_Reader.GetString(2);
            }

            return(SubFamily);
        }
Beispiel #8
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_SubFamilies();
     }
     else if (e.KeyCode == Keys.Enter)
     {
         Models.SubFamily SubFamily = Get_Selected_Item();
         if (SubFamily != null)
         {
             Modify_SubFamily(SubFamily);
         }
     }
     else if (e.KeyCode == Keys.Delete)
     {
         Models.SubFamily SubFamily = Get_Selected_Item();
         if (SubFamily != null)
         {
             Delete_SubFamily(SubFamily);
         }
     }
 }