Пример #1
0
        public static int AddRegistos(utilizador2 util)
        {
            try
            {
                SQLiteConnection myConn = new SQLiteConnection("Data Source=OrniFile_v1.db; version=3");
                myConn.Open();
                string sql_add = "UPDATE `utilizador` SET `nome`= '" + util.nome + "',`morada`= '" + util.morada + "',`cod_postal`= '" + util.codigo_postal + "',`telemovel`= " + util.telemovel + ",`STAM`= '" + util.stam + "',`id_clube`= " + util.clube + ",`data_nascimento`= '" + util.data_nascimento + "' WHERE `id_utilizador` = 1";

                //"VALUES ('" + util.nome + "','" + util.telemovel + "','" + util.stam + "', '" + util.data_nascimento + "','" + util.morada + "')" + "','" + util.codigo_postal + "')" + "','" + util.clube + "')";
                SQLiteCommand newCommand = new SQLiteCommand(sql_add, myConn);
                newCommand.ExecuteNonQuery();

                string           sql_id     = "SELECT MAX(id_Utilizador) as idAtual FROM Utilizador ";
                SQLiteCommand    idCommando = new SQLiteCommand(sql_id, myConn);
                SQLiteDataReader reader     = idCommando.ExecuteReader();
                int idUltimoRegisto         = 0;
                reader.Read(); // Ler na Base de Dados
                idUltimoRegisto = Convert.ToInt32(reader["idAtual"]);
                reader.Dispose();
                myConn.Close();
                MessageBox.Show("Foi Registado com sucesso");
                return(idUltimoRegisto);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Nao consegui adicionar com sucesso" + " " + ex.Message);
                return(0);
            }
        }
Пример #2
0
 private void bt_salvar_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         int         clube   = cb_clube.SelectedIndex;
         utilizador2 registo = new utilizador2(tb_nome.Text, System.Convert.ToInt32(tb_telemovel.Text), tb_STAM.Text, data_nascimento.Text, tb_morada.Text, tb_codigopostal.Text, clube);
         utilizador2.AddRegistos(registo);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Nao consegui adicionar o ultilizador. " + " " + ex.Message);
     }
 }
Пример #3
0
        public static List <utilizador2> lerRegistos()
        {
            SQLiteConnection myConn = new SQLiteConnection("Data Source=OrniFile_v1.db; version=3");

            myConn.Open();
            string           sql_select = "SELECT * FROM Utilizador";
            SQLiteCommand    myCommand  = new SQLiteCommand(sql_select, myConn);
            SQLiteDataReader reader     = myCommand.ExecuteReader();

            while (reader.Read())
            {
                utilizador2 newUtilizador = new utilizador2((string)reader["nome"], (long)reader["telemovel"],
                                                            (string)reader["STAM"], (string)reader["data_nascimento"],
                                                            (string)reader["Morada"], (string)reader["cod_postal"],
                                                            (long)reader["id_clube"]);
                util.Add(newUtilizador);
            }
            reader.Dispose();
            myConn.Close();
            return(util);
        }