Exemple #1
0
        private void btnConsultar_Click(object sender, EventArgs e)
        {
            int id = int.Parse(txtCod.Text);

            bool s = false;

            Depto x = new Depto();

            List <Depto> p = x.Listar();

            foreach (var Z in p)
            {
                if (Z.ID == id)
                {
                    txtCod.Text    = Z.ID.ToString();
                    txtNome.Text   = Z.Nome;
                    txtEvento.Text = Z.Evento;
                    txtFreq.Text   = Z.Freq.ToString();

                    s = true;

                    break;
                }
            }

            if (s == false)
            {
                txtCod.Clear();
                txtNome.Clear();
                txtEvento.Clear();
                txtFreq.Clear();
                MessageBox.Show("Registro não encontrado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #2
0
        private void btnExibir_Click(object sender, EventArgs e)
        {
            DGVdepto.Rows.Clear();

            Depto        x = new Depto();
            List <Depto> p = x.Listar();

            for (int i = 0; i < p.Count; i++)
            {
                string[] nova_linha = { p[i].ID.ToString(), p[i].Nome, p[i].Evento, p[i].Freq.ToString() };
                DGVdepto.Rows.Add(nova_linha);
            }
        }
Exemple #3
0
        private void btnAtualizar_Click(object sender, EventArgs e)
        {
            int id = int.Parse(txtCod.Text);

            Depto x = new Depto();

            x.ID     = id;
            x.Nome   = txtNome.Text;
            x.Evento = txtEvento.Text;
            x.Freq   = int.Parse(txtFreq.Text);

            x.alterar();
            MessageBox.Show("Registro alterado", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Exemple #4
0
        private void btnExcluir_Click(object sender, EventArgs e)
        {
            DialogResult resposta = MessageBox.Show("Confirma exclusão do registro?", "Alerta", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            Depto x = new Depto();

            if (resposta == DialogResult.Yes)
            {
                int id = int.Parse(DGVdepto.CurrentRow.Cells["ID"].Value.ToString());
                x.ID = id;
                x.excluir();

                MessageBox.Show("Registro excluido", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #5
0
        private void btnCadastrar_Click(object sender, EventArgs e)
        {
            string nome       = txtNome.Text;
            int    id         = int.Parse(txtCod.Text);
            string evento     = txtEvento.Text;
            int    frequencia = int.Parse(txtFreq.Text);

            Depto x = new Depto();

            x.ID     = id;
            x.Nome   = nome;
            x.Evento = evento;
            x.Freq   = frequencia;

            x.Cadastrar();

            MessageBox.Show("Produto cadastrado", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
        }
Exemple #6
0
        public List <Depto> Listar()
        {
            NpgsqlConnection conexao = null;

            try
            {
                conexao = new ConectaDB().getConexao();
                string sql = "SELECT * FROM departamentos";

                NpgsqlCommand cmd = new NpgsqlCommand(sql, conexao);

                NpgsqlDataReader dr = cmd.ExecuteReader();

                List <Depto> listaDepto = new List <Depto>();
                while (dr.Read())
                {
                    Depto novoDepto = new Depto();
                    novoDepto.ID     = Convert.ToInt16(dr["id_depto"]);
                    novoDepto.Nome   = dr["Nome"].ToString();
                    novoDepto.Evento = dr["Evento"].ToString();
                    novoDepto.Freq   = Convert.ToInt16(dr["Frequencia"]);

                    listaDepto.Add(novoDepto);
                }
                return(listaDepto);
            }
            catch (Exception e)
            {
                throw new Exception("   Erro!   " + e.Message);
            }
            finally
            {
                if (conexao != null)
                {
                    conexao.Close();
                }
            }
        }