Exemplo n.º 1
0
        public List<Component> getComponentListByType(String type)
        {
            //Get components Type == type

            /*SqlCeEngine engine = new SqlCeEngine(StrCon);
            engine.Upgrade();*/

            List<Component> auxList = new List<Component>();
            Component aux = null;

            string query = "SELECT * FROM ComponentRepository WHERE Type='" + type + "'";
            OleDbConnection conn = new OleDbConnection(StrCon);
            OleDbCommand cmd = new OleDbCommand(query, conn);

            conn.Open();
            OleDbDataReader rdr = cmd.ExecuteReader();

            try
            {
                // Iterate through the results
                //
                while (rdr.Read())
                {
                    aux = new Component(DB_path);

                    aux.ID = rdr.GetInt32(0);
                    aux.Name = rdr.GetString(1);
                    aux.Description = rdr.GetString(2);
                    aux.Path = rdr.GetString(3);
                    aux.setType(rdr.GetString(4));
                    //aux.Date_added = rdr.GetString(4);
                    //aux.Download_counter = rdr.GetInt32(5);
                    /*if (!rdr.IsDBNull(6))
                    {
                        aux.Type = rdr.GetString(6);
                    }*/

                    auxList.Add(aux);
                    Console.WriteLine(aux.toString());
                }
            }
            finally
            {
                // Always call Close when done reading
                rdr.Close();

                // Always call Close when done reading
                conn.Close();
            }
            return auxList;
        }
Exemplo n.º 2
0
        // Class Methods
        public List<Component> getComponentList()
        {
            //Get all components

                List<Component> auxList = new List<Component>();
                Component aux = null;

                string query = "SELECT * FROM ComponentRepository";
                //OleDbConnection conn = new OleDbConnection(StrCon);

                // Read all the table
                OleDbConnection conexion;
                OleDbDataReader rdr;

                /*SqlEngine engine = new SqlEngine(StrCon);
                engine.Upgrade();*/

                try
                {

                    conexion = new OleDbConnection(StrCon);
                    OleDbCommand cmd = new OleDbCommand(query, conexion);
                    conexion.Open();
                    rdr = cmd.ExecuteReader();
                    // Iterate through the results
                    while (rdr.Read())
                    {
                        // Create the component
                        aux = new Component(DB_path);

                        string type = Convert.ToString(rdr.GetValue(0).GetType());

                        aux.ID = Convert.ToInt32(rdr.GetInt32(0));
                        aux.Name = rdr.GetString(1);
                        aux.Description = rdr.GetString(2);
                        aux.Path = rdr.GetString(3);
                        aux.setType(rdr.GetString(4));
                        //aux.Date_added = rdr.GetString(4);
                        aux.Download_counter = rdr.GetInt32(5);
                        /*if (!rdr.IsDBNull(6))
                        {
                            aux.Type = rdr.GetString(6);
                        }*/

                        // Add the component to the list
                        auxList.Add(aux);
                        Console.WriteLine(aux.toString());

                    }
                    rdr.Close();
                    conexion.Close();
                }
                catch (Exception ex)
                {
                    Component c = new Component(DB_path);
                    c.setDescription(ex.Message);
                    auxList.Add(c);
                    Console.WriteLine(ex.ToString());
                }
                /*finally
                {
                    // Always call Close when done reading
                    //rdr.Close();

                    // Always call Close when done reading
                    //conexion.Close();
                }*/

                return auxList;
        }