private void CarregaGVProdutos(int IdPedido)
        {
            PedidoCompra    objPedidoCompra = new PedidoCompra();
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();

            DataTable dt = dbPedidoCompra.CarregaListaProdutos(IdPedido, ref erro);

            gvProdutos.DataSource = dt;
            gvProdutos.AutoGenerateSelectButton = true;
            gvProdutos.DataBind();
        }
Exemplo n.º 2
0
        private void carregaGvPedido()
        {
            PedidoCompra    objPedidoCompra = new PedidoCompra();
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();

            DataTable dt = dbPedidoCompra.CarregaListaPedidos(ref erro);

            gvPedidos.DataSource = dt;
            gvPedidos.AutoGenerateSelectButton = true;
            gvPedidos.DataBind();
        }
Exemplo n.º 3
0
        protected void txtBusca_TextChanged(object sender, EventArgs e)
        {
            PedidoCompra    objPedidoCompra = new PedidoCompra();
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();

            DataTable dt = dbPedidoCompra.PesquisaListaPedidos(txtBusca.Text, ref erro);

            gvPedidos.DataSource = dt;
            gvPedidos.AutoGenerateSelectButton = true;
            gvPedidos.DataBind();
            ClientScript.RegisterStartupScript(this.GetType(), "alert", "openModal();", true);
        }
        protected void btnAdicionar_Click(object sender, EventArgs e)
        {
            PedidoCompra    objPedidoCompra = new PedidoCompra();
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();

            HttpCookie cookie = Request.Cookies["IdUsuario"];


            objPedidoCompra.DataPedido    = DateTime.Now;
            objPedidoCompra.IdProduto     = Convert.ToInt32(ddlProduto.SelectedValue);
            objPedidoCompra.Observacao    = txtObservacao.Text;
            objPedidoCompra.Status        = 1;
            objPedidoCompra.Quantidade    = Convert.ToDecimal(txtQuantidade.Text);
            objPedidoCompra.ValorPrevisto = Convert.ToDouble(txtValorPrevisto.Text);
            objPedidoCompra.IdFornecedor  = (ddlFornecedor.SelectedValue == "Selecione") ? 0 : Convert.ToInt32(ddlFornecedor.SelectedValue);
            objPedidoCompra.IdUsuario     = Convert.ToInt32(cookie.Value);

            int IdPedido = 0;

            if (string.IsNullOrEmpty(txtCodigo.Text))
            {
                IdPedido = dbPedidoCompra.CriarPedidoCompra(objPedidoCompra, ref erro);
                if (erro != "")
                {
                    Session.Add("danger", "Não foi possível criar o Pedido de Compras " + erro);
                    return;
                }
                HttpCookie cookiePedido = new HttpCookie("idPedidoCompra");
                cookiePedido.Value = IdPedido.ToString();
                Response.Cookies.Add(cookiePedido);
                txtCodigo.Text = IdPedido.ToString();
            }

            if (string.IsNullOrEmpty(hfIdPedido.Value))
            {
                if (!dbPedidoCompra.AdicionarProdutos(objPedidoCompra, ref erro, Convert.ToInt32(txtCodigo.Text)))
                {
                    Session.Add("danger", "Não foi possível Adicionar o produto ao pedido de compra numero " + IdPedido + "! " + erro);
                    return;
                }
            }
            else
            {
                objPedidoCompra.IdProdutoPedido = Convert.ToInt32(hfIdPedido.Value);
                if (!dbPedidoCompra.AtualizaProduto(objPedidoCompra, ref erro, Convert.ToInt32(txtCodigo.Text)))
                {
                    Session.Add("danger", "Não foi possível atualizar o produto! " + erro);
                    return;
                }
            }
            CarregaGVProdutos(Convert.ToInt32(txtCodigo.Text));
            carregaGvPedido();
        }
        protected void btnRemover_Click(object sender, EventArgs e)
        {
            PedidoCompraDAL dbPedido = new PedidoCompraDAL();

            if (!dbPedido.ExcluirProdutoPorIdPedido(Convert.ToInt32(hfIdPedido.Value), ref erro))
            {
                Session.Add("danger", "Não foi possível Excluir o produto " + erro);
            }
            else
            {
                Session.Add("success", "Produto Removido ");
            }
        }
Exemplo n.º 6
0
        protected void gvPedidos_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtCodigo.Text = gvPedidos.SelectedDataKey.Value.ToString();

            PedidoCompra    objPedidoCompra = new PedidoCompra();
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();

            objPedidoCompra = dbPedidoCompra.ObterPedidoPorID(Convert.ToInt32(txtCodigo.Text), ref erro);

            if (objPedidoCompra != null)
            {
                binPedidoCompra(objPedidoCompra);
            }
        }
Exemplo n.º 7
0
        protected void btnImprimir_Click(object sender, EventArgs e)
        {
            PedidoCompraDAL dbPedidoCompra = new PedidoCompraDAL();

            LSN006_PEDIDOCOMPRA_ crystalReport = new LSN006_PEDIDOCOMPRA_();
            DataSet1             dsPedido      = dbPedidoCompra.GetData(Convert.ToInt32(txtCodigo.Text), ref erro);

            if (dsPedido != null)
            {
                crystalReport.SetDataSource(dsPedido);
                CrystalReportViewer1.ReportSource = crystalReport;
                crystalReport.PrintToPrinter(1, false, 0, 0);
            }

            if (erro != "")
            {
                Session.Add("danger", "Não foi possível imprimir " + erro);
            }
        }
        protected void gvProdutos_SelectedIndexChanged(object sender, EventArgs e)
        {
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();
            Produto_Pedido  objPedidoCompra = dbPedidoCompra.CarregaProdutoporId(Convert.ToInt32(gvProdutos.SelectedDataKey.Value), ref erro);

            if (objPedidoCompra != null)
            {
                ddlProduto.SelectedValue    = objPedidoCompra.IdProduto.ToString();
                ddlFornecedor.SelectedValue = (objPedidoCompra.IdFornecedor == 0) ? "Selecione" : objPedidoCompra.IdFornecedor.ToString();
                txtQuantidade.Text          = objPedidoCompra.Quantidade.ToString();
                txtValorPrevisto.Text       = objPedidoCompra.ValorPrevisto.ToString();
                txtObservacao.Text          = objPedidoCompra.Observacao;
                hfIdPedido.Value            = objPedidoCompra.IdProdutoPedido.ToString();
            }

            if (erro != "")
            {
                Session.Add("danger", "Erro. " + erro);
            }
        }
        protected void btnExcluir_Click(object sender, EventArgs e)
        {
            PedidoCompraDAL dbPedidoCompra  = new PedidoCompraDAL();
            PedidoCompra    objPedidoCompra = new PedidoCompra();

            if (dbPedidoCompra.ExcluirProdutoPorIdPedido(Convert.ToInt32(txtCodigo.Text), ref erro) || erro == "")
            {
                if (dbPedidoCompra.ExcluirPedidoCompra(Convert.ToInt32(txtCodigo.Text), ref erro) || erro == "")
                {
                    Session.Add("success", "Pedido de Compra excluído com sucesso! ");
                    limpa();
                }
                else
                {
                    Session.Add("danger", "Não foi possível deletar o produto! " + erro);
                }
            }
            else
            {
                Session.Add("danger", "Não foi possível excluir o Pedido de Compra! " + erro);
            }
        }
Exemplo n.º 10
0
        protected void btnVisualizar_Click(object sender, EventArgs e)
        {
            if (!validacoes())
            {
                Session.Add("danger", "Selecione uma Pedido de Compra");
            }
            else
            {
                PedidoCompraDAL dbPedidoCompra = new PedidoCompraDAL();

                LSN006_PEDIDOCOMPRA_ crystalReport = new LSN006_PEDIDOCOMPRA_();
                DataSet1             dsPedido      = dbPedidoCompra.GetData(Convert.ToInt32(txtCodigo.Text), ref erro);
                if (dsPedido != null)
                {
                    crystalReport.SetDataSource(dsPedido);
                    CrystalReportViewer1.ReportSource = crystalReport;
                }
                if (erro != "")
                {
                    Session.Add("danger", "Não foi possível imprimir " + erro);
                }
            }
        }