public void atualizarMoeda(CadastroMoeda a) { conn = classeConexão.obterConexao(); if (conn.State == ConnectionState.Open) { historicoMoeda(a); SqlCommand cmd = new SqlCommand("UPDATE Moeda SET NomeMoeda=@1, ValorMoeda=@2, DataAtualizacao=@3 where idMoeda=@0", conn); cmd.Parameters.AddWithValue("@1", a.getNome()); cmd.Parameters.AddWithValue("@2", a.getValor()); cmd.Parameters.AddWithValue("@3", DateTime.Now); cmd.Parameters.AddWithValue("@0", a.getId()); cmd.CommandType = CommandType.Text; //conn.Open(); try { historicoMoeda(a); int i = cmd.ExecuteNonQuery(); if (i > 0) { MessageBox.Show("Registro atualizado com sucesso!"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.ToString()); } finally { classeConexão.fecharConexao(); } } }
public void criarMoeda(CadastroMoeda cad) { //conn = new SqlConnection(connString); conn = classeConexão.obterConexao(); if (conn.State == ConnectionState.Open) { try { // Insere na tbl Cliente string queryString = "INSERT INTO Moeda (NomeMoeda,ValorMoeda,DataAtualizacao) VALUES (@1,@2,@3)"; SqlCommand cmd = new SqlCommand(queryString, conn); cmd.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = cad.getNome(); cmd.Parameters.Add("@2", SqlDbType.Money, 90).Value = cad.getValor(); cmd.Parameters.Add("@3", SqlDbType.Date, 90).Value = DateTime.Now; cmd.ExecuteScalar(); MessageBox.Show("Registro inserido com sucesso!"); } catch (Exception error) { MessageBox.Show("Erro: " + error); } finally { classeConexão.fecharConexao(); } } }
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 = consultaDao.quantidade(); int aa = 0; for (int i = 0; i <= count; i++) { if (!(consultaDao.listarMoeda(i) == null)) { CadastroMoeda a = consultaDao.listarMoeda(i); grdUsu.Rows.Add(); grdUsu.Rows[aa].Cells[0].Value = a.getId(); grdUsu.Rows[aa].Cells[1].Value = a.getNome(); grdUsu.Rows[aa].Cells[2].Value = a.getValor(); grdUsu.Rows[aa].Cells[3].Value = a.getAtt(); aa++; } } }
private void checkbox() { int count = b.quantidade(); for (int i = 0; i <= count; i++) { if (b.listarMoeda(i) != null) { CadastroMoeda A = b.listarMoeda(i); cbMoeda.Items.Add(A.getNome()); } } }
public void listarMoedas() { // Pega os Id da tabela do banco de dados int count = moedas.quantidade(); for (int i = 0; i <= count; i++) { if (moedas.listarMoeda(i) != null) { CadastroMoeda A = moedas.listarMoeda(i); cbTipo.Items.Add(A.getNome()); } } }
public int getIds(CadastroMoeda a) { conn = classeConexão.obterConexao(); if (conn.State == ConnectionState.Open) { SqlCommand cmd1; SqlDataReader reader; cmd1 = new SqlCommand("SELECT idMoeda FROM Moeda WHERE NomeMoeda=@1", conn); cmd1.Parameters.Add("@1", SqlDbType.NVarChar, 90).Value = a.getNome(); reader = cmd1.ExecuteReader(); if (reader.Read()) { return(int.Parse(reader[0].ToString())); } cmd1.Dispose(); reader.Close(); return(0); } else { return(0); } }