コード例 #1
0
        public void listarTable()
        {
            for (int i = 0; i < grdUsu.RowCount; i++)
            {
                grdUsu.Rows[i].DataGridView.Rows.Clear();
            }
            // Pega os Id da tabela do banco de dados
            int count = TransacaoDAO.quantidade();
            int aa    = 0;

            for (int i = 0; i <= count; i++)
            {
                if (!(TransacaoDAO.listarUsu(i) == null))
                {
                    CadastroTrans a = TransacaoDAO.listarUsu(i);

                    grdUsu.Rows.Add();

                    grdUsu.Rows[aa].Cells[0].Value = a.getId();
                    grdUsu.Rows[aa].Cells[1].Value = a.getValor();
                    grdUsu.Rows[aa].Cells[2].Value = a.getdataTrans();
                    grdUsu.Rows[aa].Cells[3].Value = a.getOrigem();
                    grdUsu.Rows[aa].Cells[4].Value = a.getMoeda();
                    grdUsu.Rows[aa].Cells[5].Value = a.getDestino();

                    aa++;
                }
            }
            listarMoedas();
            listarOrigem();
            listarDestino();
        }
コード例 #2
0
ファイル: TransacaoDAO.cs プロジェクト: TCC-CryptoCurrency/C
        public CadastroTrans getIds(CadastroTrans a)
        {
            conn = classeConexão.obterConexao();
            if (conn.State == ConnectionState.Open)
            {
                string        aux = null;
                SqlCommand    cmd1;
                SqlDataReader reader;
                conn = classeConexão.obterConexao();
                if (a.getOrigem() != "")
                {
                    cmd1 = new SqlCommand("SELECT idCarteira FROM Usuario WHERE Nome=@1", conn);
                    cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = a.getOrigem();
                    reader = cmd1.ExecuteReader();
                    if (reader.Read())
                    {
                        aux = (reader[0].ToString());
                    }
                    cmd1.Dispose();
                    reader.Close();
                    a.setidOrigem(int.Parse(aux));
                }
                cmd1 = new SqlCommand("SELECT idMoeda FROM Moeda WHERE NomeMoeda=@1", conn);
                cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = a.getMoeda();
                reader = cmd1.ExecuteReader();
                if (reader.Read())
                {
                    aux = (reader[0].ToString());
                }
                cmd1.Dispose();
                reader.Close();
                a.setidMoeda(int.Parse(aux));

                cmd1 = new SqlCommand("SELECT idCarteira FROM Usuario WHERE Nome=@1", conn);
                cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = a.getDestino();
                reader = cmd1.ExecuteReader();
                if (reader.Read())
                {
                    aux = (reader[0].ToString());
                }
                cmd1.Dispose();
                reader.Close();
                a.setidDestino(int.Parse(aux));

                return(a);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: TransacaoDAO.cs プロジェクト: TCC-CryptoCurrency/C
        public void criarTrans(CadastroTrans cad)
        {
            //conn = new SqlConnection(connString);
            string        aux = null;
            SqlCommand    cmd1;
            SqlDataReader reader;

            if (conn.State == ConnectionState.Open)
            {
                try
                {
                    string     queryString = "INSERT INTO Transacao (Valor,DataTrans,Origem,TipoMoeda,Destino) VALUES (@1,@2,@3,@4,@5)";
                    SqlCommand cmd         = new SqlCommand(queryString, conn);
                    cmd.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = cad.getValor();
                    cmd.Parameters.Add("@2", SqlDbType.Date, 90).Value     = cad.getdataTrans();
                    if (cad.getOrigem() != "")
                    {
                        cmd1 = new SqlCommand("SELECT idCarteira FROM Usuario WHERE Nome=@1", conn1);
                        cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = cad.getOrigem();
                        reader = cmd1.ExecuteReader();
                        if (reader.Read())
                        {
                            aux = (reader[0].ToString());
                        }
                        cmd1.Dispose();
                        reader.Close();
                        cmd.Parameters.Add("@3", SqlDbType.NVarChar, 90).Value = int.Parse(aux);
                    }
                    else
                    {
                        cmd.Parameters.Add("@3", SqlDbType.NVarChar, 90).Value = null;
                    }
                    cmd1 = new SqlCommand("SELECT idMoeda FROM Moeda WHERE NomeMoeda=@1", conn1);
                    cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = cad.getMoeda();
                    reader = cmd1.ExecuteReader();
                    if (reader.Read())
                    {
                        aux = (reader[0].ToString());
                    }
                    cmd1.Dispose();
                    reader.Close();
                    cmd.Parameters.Add("@4", SqlDbType.NVarChar, 90).Value = int.Parse(aux);

                    cmd1 = new SqlCommand("SELECT idCarteira FROM Usuario WHERE Nome=@1", conn1);
                    cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = cad.getDestino();
                    reader = cmd1.ExecuteReader();
                    if (reader.Read())
                    {
                        aux = (reader[0].ToString());
                    }
                    cmd1.Dispose();
                    reader.Close();
                    cmd.Parameters.Add("@5", SqlDbType.NVarChar, 90).Value = int.Parse(aux);

                    cmd.ExecuteScalar();

                    MessageBox.Show("Registro inserido com sucesso!");
                }
                catch (Exception error)
                {
                    MessageBox.Show("Erro: " + error);
                }
                finally
                {
                    classeConexão.fecharConexao();
                }
            }
        }