Example #1
0
        public void atualizarTrans(CadastroTrans a)
        {
            if (conn.State == ConnectionState.Open)
            {
                SqlCommand cmd = new SqlCommand("UPDATE Transacao SET Valor=@1, DataTrans=@2, Origem=@3, TipoMoeda=@4, Destino=@5 where idTransacao=@0", conn);
                cmd.Parameters.AddWithValue("@1", a.getValor());
                cmd.Parameters.Add("@2", SqlDbType.Date, 90).Value = a.getdataTrans();
                cmd.Parameters.AddWithValue("@3", a.getidOrigem());
                cmd.Parameters.AddWithValue("@4", a.getidMoeda());
                cmd.Parameters.AddWithValue("@5", a.getidDestino());
                cmd.Parameters.AddWithValue("@0", a.getId());


                cmd.CommandType = CommandType.Text;
                //conn.Open();
                try
                {
                    int i = cmd.ExecuteNonQuery();

                    if (i > 0)
                    {
                        MessageBox.Show("Registro atualizado com sucesso!");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro: " + ex.ToString());
                }
                finally
                {
                    conn.Close();
                }
            }
        }
        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();
        }
Example #3
0
        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();
                }
            }
        }