public ArrayList Listar() { NpgsqlConnection con = new NpgsqlConnection(); con.ConnectionString = Dados.StringConexao; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = con; cmd.CommandText = "SELECT * FROM Cadastro ORDER BY Codigo"; con.Open(); NpgsqlDataReader dr = cmd.ExecuteReader(); ArrayList lista = new ArrayList(); while (dr.Read()) { CheckModelo check = new CheckModelo(); check.IdCodigo = Convert.ToInt32(dr[0]); check.RazaoSocial = dr[1].ToString(); check.Endereco = dr[2].ToString(); lista.Add(check); } dr.Close(); con.Close(); return(lista); }
public ArrayList lista2(string razao) { NpgsqlConnection con = new NpgsqlConnection(); con.ConnectionString = Dados.StringConexao; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = con; cmd.CommandText = "SELECT Codigo, RazaoSocial, Endereco FROM Cadastro WHERE RazaoSocial Like '%" + razao + "%' " + "ORDER BY Codigo"; con.Open(); NpgsqlDataReader dr = cmd.ExecuteReader(); ArrayList lista2 = new ArrayList(); while (dr.Read()) { CheckModelo check = new CheckModelo(); check.IdCodigo = Convert.ToInt32(dr["Codigo"]); check.RazaoSocial = dr["RazaoSocial"].ToString(); check.Endereco = dr["Endereco"].ToString(); lista2.Add(check); } dr.Close(); con.Close(); return(lista2); }
public void incluir(CheckModelo check, char verifica) { if (check.RazaoSocial.Trim().Length == 0) { throw new Exception("Preencher o campo 'Razao Social' Corretamente!"); } if (check.Endereco.Trim().Length == 0) { throw new Exception("Preencher o campo 'Endereço' Corretamente!"); } CheckDAL obj = new CheckDAL(); obj.incluir(check, verifica); }
private void bntExcluir_Click(object sender, EventArgs e) { CheckModelo cli = new CheckModelo(); cli.IdCodigo = Convert.ToInt32(txtCodigo.Text); cli.RazaoSocial = txtRazaoSocial.Text; cli.Endereco = txtEndereco.Text; if (MessageBox.Show("Deseja realmente excluir esse cadastro?", "Confirmação", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes) { CheckBLL obj = new CheckBLL(); obj.excluir(cli); MessageBox.Show("As observações do fornecedor excluída com sucesso!"); } txtCodigo.Focus(); bloquear(); }
public void excluir(CheckModelo cli) { NpgsqlConnection con = new NpgsqlConnection(); try { con.ConnectionString = Dados.StringConexao; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = con; cmd.CommandText = "DELETE FROM CADASTRO WHERE CODIGO = " + cli.IdCodigo; con.Open(); cmd.ExecuteNonQuery(); } catch (NpgsqlException ex) { throw new Exception("Erro: " + ex.Message); } finally { con.Close(); } }
private void txtCodigo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { bntCadastrar.Enabled = true; try { if ((txtCodigo.Text.Equals("0") && (txtCodigo.Text.Trim().Length == 0))) { MessageBox.Show("Favor Informar o Codigo do Cliente"); } else { CheckModelo cli = new CheckModelo(); cli.IdCodigo = Convert.ToInt32(txtCodigo.Text); CheckBLL obj = new CheckBLL(); obj.listar3(cli); txtRazaoSocial.Enabled = true; txtEndereco.Enabled = true; if (!(ReferenceEquals(cli.RazaoSocial, null))) { txtRazaoSocial.Text = cli.RazaoSocial; txtEndereco.Text = cli.Endereco; verifica = 'S'; bntExcluir.Enabled = true; } txtRazaoSocial.Focus(); } } catch (Exception ex) { MessageBox.Show("Informe o código corretamente!\n" + ex.Message); } } }
private void bntCadastrar_Click(object sender, EventArgs e) { try { CheckModelo check = new CheckModelo(); check.IdCodigo = Convert.ToInt32(txtCodigo.Text); if (check.IdCodigo <= 0) { MessageBox.Show("Numeros negativos sao invalidos", "Aviso"); return; } check.RazaoSocial = txtRazaoSocial.Text; check.Endereco = txtEndereco.Text; CheckBLL obj = new CheckBLL(); obj.incluir(check, verifica); if (verifica == 'S') { MessageBox.Show("Cliente Alterado com Sucesso"); } else { MessageBox.Show("Cliente Efetuado com Sucesso"); } } catch (Exception ex) { MessageBox.Show("Erro", ex.Message); } limpar(); txtCodigo.Focus(); txtRazaoSocial.Enabled = false; txtEndereco.Enabled = false; }
public void incluir(CheckModelo check, char verifica) { NpgsqlConnection con = new NpgsqlConnection(); try { con.ConnectionString = Dados.StringConexao; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = con; cmd.CommandText = "INSERT INTO Cadastro " + "(Codigo, RazaoSocial, Endereco)" + "VALUES " + "(@Codigo, @RazaoSocial, @Endereco);"; if (verifica == 'S') { cmd.CommandText = "UPDATE Cadastro SET RazaoSocial = @RazaoSocial, Endereco = @Endereco WHERE Codigo = @Codigo"; } cmd.Parameters.AddWithValue("@Codigo", check.IdCodigo); cmd.Parameters.AddWithValue("@RazaoSocial", check.RazaoSocial); cmd.Parameters.AddWithValue("@endereco", check.Endereco); con.Open(); cmd.ExecuteNonQuery(); } catch (NpgsqlException ex) { throw new Exception("erro" + ex.Message); } catch (Exception ex) { throw new Exception(ex.Message); } finally { con.Close(); } }
public CheckModelo lista3(CheckModelo cli) { NpgsqlConnection con = new NpgsqlConnection(); try { con.ConnectionString = Dados.StringConexao; NpgsqlCommand cmd = new NpgsqlCommand(); cmd.Connection = con; cmd.CommandText = "SELECT * FROM Cadastro WHERE Codigo = " + cli.IdCodigo; con.Open(); NpgsqlDataReader dr = cmd.ExecuteReader(); cli.RazaoSocial = null; cli.Endereco = null; if (dr.Read()) { cli.IdCodigo = Convert.ToInt32(dr[0]); cli.RazaoSocial = dr[1].ToString(); cli.Endereco = dr[2].ToString(); } return(cli); } catch (NpgsqlException ex) { throw new Exception("Erro: " + ex.Message); } catch (Exception ex) { throw new Exception("erro: " + ex.Message); } finally { con.Close(); } }
public List <CheckModelo> Listar4(List <CheckModelo> lista) { NpgsqlConnection con = null; try { con = new NpgsqlConnection(Dados.StringConexao); string strCmd = "SELECT * FROM Cadastro ORDER BY Codigo"; NpgsqlCommand cmd = new NpgsqlCommand(strCmd, con); con.Open(); NpgsqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { CheckModelo list = new CheckModelo(); list.IdCodigo = Convert.ToInt32(dr[0]); list.razaoSocial = dr[1].ToString(); list.endereco = dr[2].ToString(); lista.Add(list); } return(lista); } catch (NpgsqlException ex) { throw new NpgsqlException("Erro: " + ex.Message); } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } finally { con.Close(); } }
public void excluir(CheckModelo cli) { CheckDAL obj = new CheckDAL(); obj.excluir(cli); }
public void listar3(CheckModelo codigo) { CheckDAL obj = new CheckDAL(); obj.lista3(codigo); }