public void historicoMoeda(CadastroMoeda a) { conn1 = classeConexão.obterConexao(); if (conn1.State == ConnectionState.Open) { try { // Insere na tbl Cliente string queryString = "INSERT INTO HistoricoMoeda (DataRegistro,ValorData,idMoeda) VALUES (@1,@2,@3)"; SqlCommand cmd = new SqlCommand(queryString, conn1); DateTime b = DateTime.Now; string c = b.ToString("d"); cmd.Parameters.Add("@1", SqlDbType.Date, 90).Value = c; cmd.Parameters.Add("@2", SqlDbType.Money, 90).Value = a.getValor(); cmd.Parameters.Add("@3", SqlDbType.Int, 90).Value = a.getId(); cmd.ExecuteScalar(); } catch (Exception error) { MessageBox.Show("Erro: " + error); } finally { classeConexão.fecharConexao(); } } }
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 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++; } } }