public List<string> GetComponents(string type)
        {
            List<string> components = new List<string>();

            component = new Component(DB_Path);
            //int nComp = component;

            List<Component> list;

            try
            {
                if (type != null)
                {
                    list = component.getComponentListByType(type);
                    foreach( Component comp in list)
                        components.Add(Convert.ToString(comp.getID()) + ";" + comp.getName() + ";" + comp.getPath() + ";" + comp.getDescription() + ";" + comp.getType() + ";" + comp.getDownload_counter() + ";");
                }
                else
                {
                    list = component.getComponentList();
                    foreach (Component comp in list)
                        components.Add(Convert.ToString(comp.getID()) + ";" + comp.getName() + ";" + comp.getPath() + ";" + comp.getDescription() + ";" + comp.getType() + ";" + comp.getDownload_counter() + ";");
                }
            }
            catch(Exception e)
            {
                return null;
            }

            return components;
        }
 public bool Delete(int Id)
 {
     try
     {
         component = new Component(DB_Path,Id);
         component.delete();
     }
     catch (Exception e)
     {
         return false;
     }
     return true;
 }
 public bool Add(string name, string path, string description, string type)
 {
     try
     {
         component = new Component(DB_Path,name,description,path,type);
         component.store();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return false;
     }
     return true;
 }
        public void updateDownload(int Id)
        {
            try
            {
                component = new Component(DB_Path, Id);
                component.updateDownload(Id);
            }
            catch (Exception e)
            {

            }
        }
 public bool ModifyInDB(int Id, string name, string path, string description, string type)
 {
     try
     {
         component = new Component(DB_Path);
         component.modify(Id, name, path, description, type);
     }
     catch (Exception e)
     {
         return false;
     }
     return true;
 }
Esempio n. 6
0
        // Not sure if it's useful
        private Component getComponent(int id)
        {
            Component aux = new Component(DB_path);

            string query = "SELECT * FROM component WHERE id LIKE " + id;
            OleDbConnection conn = new OleDbConnection(StrCon);
            OleDbCommand cmd = new OleDbCommand(query, conn);

            conn.Open();

            OleDbDataReader rdr = null;
            try
            {
                rdr = cmd.ExecuteReader();
                rdr.Read();

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

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                // Always call Close when done reading
                rdr.Close();

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

            return aux;
        }
Esempio n. 7
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;
        }
Esempio n. 8
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;
        }