Exemplo n.º 1
0
        public static List <Clube2> lerRegistos()
        {
            try
            {
                SQLiteConnection myConn = new SQLiteConnection("Data Source=OrniFile_v1.db; version=3");
                myConn.Open();

                string sql_select = "SELECT * FROM Clube";
                try
                {
                    SQLiteCommand    myCommand = new SQLiteCommand(sql_select, myConn);
                    SQLiteDataReader reader    = myCommand.ExecuteReader();
                    utilC.Clear();
                    while (reader.Read())
                    {
                        Clube2 newclube = new Clube2((long)reader["id_clube"],
                                                     (string)reader["nome"]);
                        utilC.Add(newclube);
                    }
                    reader.Dispose();
                    myConn.Close();
                    return(utilC);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Não consegui ler os registos. " + " " + ex.Message);
                    return(utilC);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não consegui conetar a base de dados." + " " + ex.Message);
                return(utilC);
            }
        }
Exemplo n.º 2
0
        public Utilizador()
        {
            InitializeComponent();
            try
            {
                List <Clube2> utilP = new List <Clube2>();
                utilP = Clube2.lerRegistos();
                if (utilP.Count != 0)
                {
                    foreach (var x in utilP)
                    {
                        string mostrar = x.id_clube + "-" + x.nome;

                        cb_clube.Items.Add(mostrar);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não consegui ler os clubes." + " " + ex.Message);
            }
            try {
                List <utilizador2> utilU = new List <utilizador2>();
                utilU = utilizador2.lerRegistos();
                if (utilU.Count != 0)
                {
                    foreach (var x in utilU)
                    {
                        tb_nome.Text         = x.nome;
                        tb_morada.Text       = x.morada;
                        tb_STAM.Text         = x.stam.ToString();
                        tb_telemovel.Text    = x.telemovel.ToString();
                        tb_codigopostal.Text = x.codigo_postal.ToString();
                        data_nascimento.Text = x.data_nascimento.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não consegui ler os dados do utilizador." + " " + ex.Message);
            }
        }