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 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 CadastroMoeda listarHistoricoMoeda(int id, DateTime A) { conn1 = classeConexão.obterConexao(); if (conn1.State == ConnectionState.Open) { SqlCommand cmd = new SqlCommand("select * from HistoricoMoeda where idMoeda = @id and DataRegistro = @a", conn1); cmd.Parameters.AddWithValue("@id", id); cmd.Parameters.AddWithValue("@a", A); try { CadastroMoeda a = new CadastroMoeda(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { a.setId(id); a.setIdHistorico(int.Parse(reader[0].ToString())); a.setAttt(DateTime.Parse(reader[1].ToString())); a.setValor(Double.Parse(reader[2].ToString())); a.setId(int.Parse(reader[3].ToString())); return(a); } else { return(null); } } catch (Exception error) { MessageBox.Show("Erro: " + error); return(null); } finally { classeConexão.fecharConexao(); } } else { MessageBox.Show("Erro: " + conn1.State.ToString()); return(null); } }
private void btnEditar_Click(object sender, EventArgs e) { CadastroMoeda a = new CadastroMoeda(); a.setId(int.Parse(txtId.Text)); a.setNome(txtNome.Text); a.setValor(Double.Parse(txtValor.Text)); a.setAttt(DateTime.Parse(txtAtt.Text)); consultaDao.atualizarMoeda(a); listarTable(); txtId.Clear(); txtNome.Clear(); txtAtt.Clear(); txtValor.Clear(); }
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); } }