Ejemplo n.º 1
0
        /// <summary>
        /// Get a family in database.
        /// </summary>
        /// <param name="Id"><b>Id</b>The Id of the SubFamily to find.</param>
        public static List <SousFamillesModel> SelectByFamille(int RefFamille)
        {
            List <SousFamillesModel> SousFamilles = new List <SousFamillesModel>();

            SQLiteConnection Connection = DaoContext.Connection;

            Connection.Open();

            using (SQLiteCommand Cmd = Connection.CreateCommand())
            {
                Cmd.CommandText = @"SELECT * FROM SousFamilles WHERE RefFamille = @RefFamille;";
                Cmd.Parameters.AddWithValue("@RefFamille", RefFamille);
                using (SQLiteDataReader reader = Cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        SousFamilles.Add(new SousFamillesModel(int.Parse(reader["RefSousFamille"].ToString()),
                                                               FamillesDao.SelectByID(int.Parse(reader["RefFamille"].ToString())), reader["Nom"].ToString()));
                    }
                    reader.Close();
                }
            }

            Connection.Close();
            return(SousFamilles);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get a family in database.
        /// </summary>
        /// <param name="Id"><b>Id</b>The Id of the SubFamily to find.</param>
        public static SousFamillesModel SelectByID(int Id)
        {
            bool IsOpenHere = false;
            SousFamillesModel SousFamille = null;

            SQLiteConnection Connection = DaoContext.Connection;

            if (Connection.State == ConnectionState.Closed)
            {
                Connection.Open(); IsOpenHere = true;
            }

            using (SQLiteCommand Cmd = Connection.CreateCommand())
            {
                Cmd.CommandText = @"SELECT * FROM SousFamilles WHERE RefSousFamille = @RefSousFamille;";
                Cmd.Parameters.AddWithValue("@RefSousFamille", Id);
                SQLiteDataReader reader = Cmd.ExecuteReader();
                while (reader.Read())
                {
                    SousFamille = new SousFamillesModel(FamillesDao.SelectByID(int.Parse(reader["RefFamille"].ToString())), reader["Nom"].ToString());
                }
                reader.Close();
            }

            if (Connection.State == ConnectionState.Open && IsOpenHere)
            {
                Connection.Close();
            }
            return(SousFamille);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method used to select a list of subfamilies.
        /// </summary>
        public static List <SousFamillesModel> SelectAll()
        {
            bool IsOpenHere = false;
            List <SousFamillesModel> AllTable    = new List <SousFamillesModel>();
            SousFamillesModel        SousFamille = null;

            SQLiteConnection Connection = DaoContext.Connection;

            if (Connection.State == ConnectionState.Closed)
            {
                Connection.Open(); IsOpenHere = true;
            }

            using (SQLiteCommand Cmd = Connection.CreateCommand())
            {
                Cmd.CommandText = @"SELECT * FROM SousFamilles;";
                SQLiteDataReader reader = Cmd.ExecuteReader();
                while (reader.Read())
                {
                    SousFamille = new SousFamillesModel(int.Parse(reader["RefSousFamille"].ToString()), FamillesDao.SelectByID(int.Parse(reader["RefFamille"].ToString())), reader["Nom"].ToString());
                    AllTable.Add(SousFamille);
                }
                reader.Close();
            }
            if (Connection.State == ConnectionState.Open && IsOpenHere)
            {
                Connection.Close();
            }
            return(AllTable);
        }