Esempio n. 1
0
        /// <summary>
        /// Put the attributes of the given article in the corresponding fields
        /// </summary>
        /// <param name="Article">The article (or null for empty window)</param>
        private void Construct(Article Article)
        {
            //Do not allow resizing
            StartPosition   = FormStartPosition.CenterParent;
            DialogResult    = DialogResult.Cancel;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            MaximizeBox     = false;
            MinimizeBox     = false;

            //Filling the comboboxes
            SQLiteConnection Connection          = DbConnect.GetInstance().GetConnection();
            SQLiteCommand    CommandSelectBrands = new SQLiteCommand("SELECT * FROM Marques", Connection);
            SQLiteDataReader ResultBrands        = CommandSelectBrands.ExecuteReader();

            if (ResultBrands != null)
            {
                while (ResultBrands.Read())
                {
                    object ObjId   = ResultBrands["RefMarque"];
                    long   BrandId = 0;
                    if (ObjId != DBNull.Value)
                    {
                        BrandId = Convert.ToInt64(ObjId);
                    }
                    object ObjName   = ResultBrands["Nom"];
                    string BrandName = "";
                    if (ObjName != DBNull.Value)
                    {
                        BrandName = Convert.ToString(ObjName);
                    }
                    ComboBoxBrand.Items.Add(new ComboBoxItem {
                        Name = BrandName, Value = BrandId
                    });
                }
                ResultBrands.Close();
            }
            else
            {
                throw new FieldAccessException("Getting brands failed");
            }
            SQLiteCommand    CommandSelectSf = new SQLiteCommand("SELECT * FROM SousFamilles ORDER BY RefFamille", Connection);
            SQLiteDataReader ResultSf        = CommandSelectSf.ExecuteReader();

            if (ResultSf != null)
            {
                while (ResultSf.Read())
                {
                    object ObjId = ResultSf["RefSousFamille"];
                    long   SfId  = 0;
                    if (ObjId != DBNull.Value)
                    {
                        SfId = Convert.ToInt64(ObjId);
                    }
                    object ObjName = ResultSf["Nom"];
                    string SfName  = "";
                    if (ObjName != DBNull.Value)
                    {
                        SfName = Convert.ToString(ObjName);
                    }
                    ComboBoxSubFamily.Items.Add(new ComboBoxItem {
                        Name = SfName, Value = SfId
                    });
                }
                ResultSf.Close();
            }
            else
            {
                throw new FieldAccessException("Getting subfamily failed");
            }

            if (Article != null)
            {
                SetArticle(Article);
            }
        }