Esempio n. 1
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            frm_Pesquisa.nomeFormulario = nomeFormulario;
            frm_Pesquisa fp = new frm_Pesquisa();

            fp.ShowDialog();
            if (fp.Codigo != null)
            {
                using (IConnection Conexion = new Connection())
                {
                    IDAO <Produto> dao  = new DAOProduto(Conexion);
                    Produto        prod = dao.FindOrDefault(fp.Codigo);
                    txtCodigo.Text = prod.Id.ToString();
                    txtNome.Text   = prod.Nome;
                    txtPreco.Text  = prod.preço.ToString();
                    dgvProduto.Rows.Clear();
                    int renglon = dgvProduto.Rows.Add();
                    dgvProduto.Rows[renglon].Cells["Id"].Value    = prod.Id.ToString();
                    dgvProduto.Rows[renglon].Cells["Nome"].Value  = cultureinfo.TextInfo.ToTitleCase(prod.Nome.ToString().ToLower().Trim());
                    dgvProduto.Rows[renglon].Cells["Preco"].Value = cultureinfo.TextInfo.ToTitleCase(prod.preço.ToString().ToLower().Trim());

                    btnAdd.Visible = false;
                    //btnBuscar.Visible = false;
                    btnSalvar.Visible   = true;
                    btnDelete.Visible   = true;
                    btnCancelar.Visible = true;
                }
            }
        }
Esempio n. 2
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     using (IConnection Conexion = new Connection())
     {
         IDAO <Produto> dao  = new DAOProduto(Conexion);
         Produto        prod = dao.FindOrDefault(txtCodigo.Text);
         dao.Delete(prod);
     }
     DefaultObjetos();
 }
        //Deleta o produto da Base de Dados pelo ID
        public static bool Delete(int id)
        {
            var ret = false;

            using (IConnection Conexion = new Connection())
            {
                IDAO <Produto> dao = new DAOProduto(Conexion);
                Produto        p   = dao.FindOrDefault(id);
                if (p != null)
                {
                    ret = dao.Delete(p);
                }
            }

            return(ret);
        }
 private void cboProduto_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cboProduto.SelectedValue != null)
     {
         using (IConnection Conexion = new Connection())
         {
             IDAO <Produto> dao    = new DAOProduto(Conexion);
             Produto        entity = dao.FindOrDefault(cboProduto.SelectedValue);//Objeto tipo Modulos(tabela)
             if (entity != null)
             {
                 txtDescricao.Text = entity.Nome;
                 txtPUnit.Text     = entity.preço.ToString();
             }
         }
     }
 }
Esempio n. 5
0
        private void dgvProduto_Click(object sender, EventArgs e)
        {
            btnAdd.Visible = false;
            //btnBuscar.Visible = false;
            btnSalvar.Visible   = true;
            btnDelete.Visible   = true;
            btnCancelar.Visible = true;
            string xcod = dgvProduto.CurrentRow.Cells["Id"].Value.ToString();

            using (IConnection conexion = new Connection())
            {
                IDAO <Produto> dao  = new DAOProduto(conexion);
                Produto        prod = dao.FindOrDefault(xcod);
                txtCodigo.Text = prod.Id.ToString();
                txtNome.Text   = prod.Nome;
                txtPreco.Text  = prod.preço.ToString();
            }
        }
        //Recupera o produto pelo ID da Base de dados
        public static ProdutoViewModel GetFindOrDefault(int id)
        {
            ProdutoViewModel ret = null;

            using (IConnection conexion = new Connection())
            {
                IDAO <Produto> dao = new DAOProduto(conexion);
                Produto        p   = dao.FindOrDefault(id);
                if (p != null)
                {
                    ret = new ProdutoViewModel
                    {
                        Id    = p.Id,
                        Nome  = p.Nome,
                        Preco = p.preço
                    };
                }
            }
            return(ret);
        }
Esempio n. 7
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text == "")
            {
                mensagemInfoExibir("Informe o código para pesquisar!", "Pesquisa");
                txtCodigo.Focus();
                return;
            }
            if (nomeFormulario == "frmCliente")
            {
                using (IConnection Conexion = new Connection())
                {
                    IDAO <Cliente> daoCli = new DAOCliente(Conexion);
                    Cliente        cli    = daoCli.FindOrDefault(txtCodigo.Text);
                    if (cli != null)
                    {
                        dgvSearch.Rows.Clear();
                        int renglon = dgvSearch.Rows.Add();
                        dgvSearch.Rows[renglon].Cells["Id"].Value   = cli.Id.ToString();
                        dgvSearch.Rows[renglon].Cells["Nome"].Value = cli.Nome.ToString();
                    }
                    else
                    {
                        mensagemInfoExibir("Codigo não existe!", "Pesquisa");
                        txtCodigo.Focus();
                    }
                }
            }

            if (nomeFormulario == "frmProduto")
            {
                using (IConnection Conexion = new Connection())
                {
                    IDAO <Produto> daoProd = new DAOProduto(Conexion);
                    Produto        prod    = daoProd.FindOrDefault(txtCodigo.Text);
                    if (prod != null)
                    {
                        dgvSearch.Rows.Clear();
                        int renglon = dgvSearch.Rows.Add();
                        dgvSearch.Rows[renglon].Cells["Id"].Value   = prod.Id.ToString();
                        dgvSearch.Rows[renglon].Cells["Nome"].Value = prod.Nome.ToString();
                    }
                    else
                    {
                        mensagemInfoExibir("Codigo não existe!", "Pesquisa");
                        txtCodigo.Focus();
                    }
                }
            }

            if (nomeFormulario == "frmOrcamento")
            {
                using (IConnection Conexion = new Connection())
                {
                    IDAO <OrcCab> dao = new DAOOrcCab(Conexion);
                    OrcCab        oc  = dao.FindOrDefault(txtCodigo.Text);
                    if (oc != null)
                    {
                        dgvSearch.Rows.Clear();
                        int renglon = dgvSearch.Rows.Add();
                        dgvSearch.Rows[renglon].Cells["Id"].Value   = oc.Nro.ToString();
                        dgvSearch.Rows[renglon].Cells["Data"].Value = oc.Data.ToString();
                    }
                    else
                    {
                        mensagemInfoExibir("Codigo não existe!", "Pesquisa");
                        txtCodigo.Focus();
                    }
                }
            }
        }