Ejemplo n.º 1
0
        /// <summary>
        /// Return the subfamily created (or edited) by the window
        /// </summary>
        /// <returns>The new subfamily</returns>
        public SubFamily GetSubFamily()
        {
            ComboBoxItem FamilyItem = (ComboBoxItem)ComboBoxFamily.SelectedItem;
            SubFamily    SubFamily  = new SubFamily(_Id, FamilyItem.Value, TextBoxName.Text);

            return(SubFamily);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Open a window to edit the given subfamily and update database if there are modifications
        /// </summary>
        /// <param name="SubFamily">The subfamily to update</param>
        private void UpdateSubFamily(SubFamily SubFamily)
        {
            AddSubFamily AddSubFamily = new AddSubFamily(SubFamily);

            if (AddSubFamily.ShowDialog() == DialogResult.OK)
            {
                LoadDatabase();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Validate the creation (or editing)
        /// </summary>
        /// <param name="Sender">The object sending the event</param>
        /// <param name="Event">The event</param>
        private void ButtonOK_Click(object Sender, EventArgs Event)
        {
            DialogResult = DialogResult.OK;
            SubFamily SubFamily = GetSubFamily();

            if (SubFamily != null)
            {
                DbConnect.GetInstance().UpdateOrCreateSubFamily(SubFamily);
            }
            Close();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Edit the given subfamily with the new data
 /// </summary>
 /// <param name="SubFamily">The subfamily to edit</param>
 public void SetSubFamily(SubFamily SubFamily)
 {
     for (int BrandIndex = 0; BrandIndex < ComboBoxFamily.Items.Count; BrandIndex++)
     {
         if (((ComboBoxItem)(ComboBoxFamily.Items[BrandIndex])).Value == SubFamily.FamilyReference)
         {
             ComboBoxFamily.SelectedIndex = BrandIndex;
             break;
         }
     }
     TextBoxName.Text = SubFamily.Name;
     _Id = SubFamily.Reference;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Put the attributes of the given subfamily in the corresponding fields
        /// </summary>
        /// <param name="SubFamily">The subfamily (or null for empty window)</param>
        private void Construct(SubFamily SubFamily)
        {
            //Do not allow resizing
            StartPosition   = FormStartPosition.CenterParent;
            DialogResult    = DialogResult.Cancel;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            MaximizeBox     = false;
            MinimizeBox     = false;

            // Filling the combobox
            SQLiteConnection Connection          = DbConnect.GetInstance().GetConnection();
            SQLiteCommand    CommandSelectBrands = new SQLiteCommand("SELECT * FROM Familles", Connection);
            SQLiteDataReader ResultFamilies      = CommandSelectBrands.ExecuteReader();

            if (ResultFamilies != null)
            {
                while (ResultFamilies.Read())
                {
                    object ObjId   = ResultFamilies["RefFamille"];
                    long   BrandId = 0;
                    if (ObjId != DBNull.Value)
                    {
                        BrandId = Convert.ToInt64(ObjId);
                    }
                    object ObjName   = ResultFamilies["Nom"];
                    string BrandName = "";
                    if (ObjName != DBNull.Value)
                    {
                        BrandName = Convert.ToString(ObjName);
                    }
                    ComboBoxFamily.Items.Add(new ComboBoxItem {
                        Name = BrandName, Value = BrandId
                    });
                }
                ResultFamilies.Close();
            }
            else
            {
                throw new FieldAccessException("Getting families failed");
            }

            if (SubFamily != null)
            {
                SetSubFamily(SubFamily);
            }
            else
            {
                _Id = -1;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Update (or insert if it doesn't exist) a subfamily in the database
        /// </summary>
        /// <param name="SubFamily">The subfamily</param>
        public void UpdateOrCreateSubFamily(SubFamily SubFamily)
        {
            long Id = -1;

            if (SubFamily.Reference == -1)//If no ID, get the next one
            {
                SQLiteCommand    CommandId = new SQLiteCommand("SELECT MAX(RefSousFamille) AS ID FROM SousFamilles", _Connection);
                SQLiteDataReader ResultId  = CommandId.ExecuteReader();
                if (ResultId != null)
                {
                    if (ResultId.Read())
                    {
                        object Obj = ResultId["ID"];
                        if (Obj != DBNull.Value)
                        {
                            Id = Convert.ToInt64(Obj);
                        }
                    }
                    ResultId.Close();
                    Id++;
                }
                else
                {
                    throw new Exception("Getting subfamily ID failed");
                }
            }
            else
            {
                Id = SubFamily.Reference;
            }

            //Insert sub family
            SQLiteCommand CommandInsert = new SQLiteCommand("INSERT OR REPLACE INTO SousFamilles (RefSousFamille, RefFamille, Nom) VALUES (@ID, @IDFamille, @Name)", _Connection);

            CommandInsert.Parameters.AddWithValue("@ID", Id);
            CommandInsert.Parameters.AddWithValue("@IDFamille", SubFamily.FamilyReference);
            CommandInsert.Parameters.AddWithValue("@Name", SubFamily.Name);

            if (CommandInsert.ExecuteNonQuery() != 1)
            {
                throw new Exception("Inserting SF failed");
            }
        }
Ejemplo n.º 7
0
 /// <inheritdoc />
 /// <summary>
 /// Initialize a window to modify the given subfamily
 /// </summary>
 /// <param name="SubFamily">The subfamily to edit</param>
 public AddSubFamily(SubFamily SubFamily)
 {
     InitializeComponent();
     Construct(SubFamily);
 }