예제 #1
0
        private void txtCodigo_Leave(object sender, EventArgs e)
        {
            try
            {
                if (txtCodigo.Text != "")
                {
                    rtbPedGerados.Clear();
                    DALConexao          cx         = new DALConexao(DadosDaConexao.StringDeConexao);
                    BLLPCVENDACONSUM    bllpcvc    = new BLLPCVENDACONSUM(cx);
                    ModeloPCVENDACONSUM modelopcvc = bllpcvc.CarregaPCVENDACONSUM(Convert.ToInt64(txtCodigo.Text));
                    BLLPCPEDC           bllpcpc    = new BLLPCPEDC(cx);
                    ModeloPCPEDC        modelopcpc = bllpcpc.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));
                    BLLPCPEDI           bllpcpi    = new BLLPCPEDI(cx);
                    ModeloPCPEDI        modelopcpi = bllpcpi.CarregaPCPEDI(Convert.ToInt64(txtCodigo.Text));

                    dgvItens.DataSource = bllpcpi.Localizar(Convert.ToInt64(txtCodigo.Text));


                    txtNome.Text     = modelopcvc.cliente.ToString();
                    txtCpf.Text      = modelopcvc.cgcent.ToString();
                    txtVlrTotal.Text = modelopcpc.vlatend.ToString();
                    txtQtdItens.Text = modelopcpc.numitens.ToString();
                    txtNumcar.Text   = modelopcpc.numcar.ToString();
                    reverterPedidoToolStripMenuItem.Enabled = true;
                    btnBuscar.Focus();
                }
            }

            catch (NullReferenceException ex)
            {
                MessageBox.Show("Erro: " + ex.Message + " \n " + "Verificar o Pedido de Digitado.");
            }
            catch (OracleException ex)
            {
                MessageBox.Show("Erro: " + ex.Message);
            }
            catch (Exception erros)
            {
                MessageBox.Show(erros.Message);
            }
        }
예제 #2
0
        public void ClassificaPed(int tpDiv)
        {
            try
            {
                if (txtNome.Text != null && tpDiv == 1)
                {
                    DALConexao   cx            = new DALConexao(DadosDaConexao.StringDeConexao);
                    BLLPCPEDC    bllpcpcold    = new BLLPCPEDC(cx);
                    ModeloPCPEDC modelopcpcold = bllpcpcold.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));
                    if (modelopcpcold.numcar == 0)
                    {
                        BLLCARREG      bllcar   = new BLLCARREG(cx);
                        ModeloPCCARREG modelcar = bllcar.CarregaNewNumCar();
                        modelcar.vltotal    = Convert.ToDouble(modelopcpcold.vltotal);
                        modelcar.codfuncmon = modelopcpcold.codemitente;
                        bllcar.Incluir(modelcar);
                        modelopcpcold.numcar = modelcar.numcar;
                        bllcar.MontaCarreg(modelopcpcold);
                        bllcar.MontaCarregI(modelopcpcold);
                        numcar = modelcar.numcar;
                    }

                    numcar = Convert.ToInt32(modelopcpcold.numcar);


                    ModeloPCPEDC modelopcpcnew = bllpcpcold.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));

                    decimal?vltotalrest = Convert.ToDecimal(modelopcpcnew.vlatend);
                    modelopcpcold.numpedold = Convert.ToInt64(txtCodigo.Text);

                    int     qualificado   = 0;
                    int     ped           = 0;
                    int     paraped       = 0;
                    decimal?totalgeralped = 0;
                    string  qtit          = txtQtdItens.Text;
                    qualificado = (vltotalrest < 500) ? 0 : 1;
                    if (qualificado == 1)
                    {
                        if (dgvItens.RowCount > 0)
                        {
                            ModeloPCPEDI mitens = new ModeloPCPEDI();
                            BLLPCPEDI    bitens = new BLLPCPEDI(cx);

                            for (int i = 0; i < dgvItens.RowCount; i++)
                            {
                                mitens.numped      = Convert.ToInt64(txtCodigo.Text);
                                mitens.codprod     = Convert.ToInt32(dgvItens.Rows[i].Cells[0].Value);
                                mitens.codauxiliar = Convert.ToInt64((dgvItens.Rows[i].Cells[1].Value.ToString()));
                                mitens.qt          = Convert.ToDecimal(dgvItens.Rows[i].Cells[2].Value);
                                mitens.qtunitemb   = Convert.ToDecimal(dgvItens.Rows[i].Cells[3].Value);
                                mitens.pvenda      = Convert.ToDecimal(dgvItens.Rows[i].Cells[4].Value);
                                bitens.IncluirDUP(mitens);
                            }
                        }

                        do
                        {
                            ped = ped + 1;

                            BLLPCVENDACONSUM    bllpcvc    = new BLLPCVENDACONSUM(cx);
                            ModeloPCVENDACONSUM modelopcvc = bllpcvc.CarregaPCVENDACONSUM(Convert.ToInt64(txtCodigo.Text));

                            BLLPCPEDC    bllpcpc    = new BLLPCPEDC(cx);
                            ModeloPCPEDC modelopcpc = bllpcpc.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));

                            modelopcpc.numpedold = Convert.ToInt64(txtCodigo.Text);

                            BLLVAR    bllvar    = new BLLVAR(cx);
                            ModeloVAR modelovar = bllvar.CarregaNewNumPed(Convert.ToInt64(modelopcpc.codusur));
                            bllvar.AlterarNW(modelovar);

                            modelopcpc.numped    = modelovar.newnumped;
                            modelopcvc.numped    = modelovar.newnumped;
                            modelopcpc.condvenda = 1;
                            //modelopcpc.codcli = 1;
                            modelopcpc.origemped = "T";

                            if (ped == 1)
                            {
                                pedidos[0] = modelopcpc.numped;
                            }
                            pedidos[1] = modelopcpc.numped;

                            int     it           = 0;
                            decimal vltotal      = 0;
                            decimal vltabela     = 0;
                            decimal vlcustoreal  = 0;
                            decimal vlcustofin   = 0;
                            decimal vlatend      = 0;
                            decimal?vlcustorep   = 0;
                            decimal?vlcustocont  = 0;
                            decimal?qtrest       = 0;
                            decimal VlrTotalVend = 0;

                            int contped = 0;
                            int itens   = 0;

                            do
                            {
                                BLLPCPEDI    bllpcpi    = new BLLPCPEDI(cx);
                                ModeloPCPEDI modelopcpi = bllpcpi.CarregaPCPEDI(Convert.ToInt64(txtCodigo.Text));
                                dgvItens.DataSource  = bllpcpi.Localizar(Convert.ToInt64(txtCodigo.Text));
                                modelopcpi.oldnumped = Convert.ToInt64(txtCodigo.Text);
                                modelopcpi.numped    = modelovar.newnumped;
                                //modelopcpi.codcli = 1;
                                modelopcpi.qtunitemb = 1;
                                modelopcpi.numseqori = modelopcpi.numseq;


                                if (modelopcpi.codprod != 0)
                                {
                                    bllpcpi.IncluirQT(modelopcpi);
                                }

                                modelopcpi.codauxiliar = modelopcpi.codauxiliarunit;
                                modelopcpi.qtunitcx    = modelopcpi.qtunitcxunit;
                                modelopcpi.qtunitemb   = Convert.ToDecimal(modelopcpi.qtunitcxunit);

                                decimal QtRestprod   = 0;
                                decimal QtAnt        = 0;
                                decimal VlrProd      = 0;
                                decimal QtProd       = 0;
                                decimal pvltabela    = 0;
                                decimal pvlcustoreal = 0;
                                decimal pvlcustofin  = 0;
                                decimal pvlatend     = 0;
                                decimal?pvlcustorep  = 0;
                                decimal?pvlcustocont = 0;

                                QtAnt = modelopcpi.qt;
                                modelopcpc.numitens = Convert.ToInt16(itens + 1);

                                for (decimal ii = 0; ii < QtAnt; ii++)
                                {
                                    if (modelopcpi.fracao == "N")
                                    {
                                        QtProd     = QtProd + 1;
                                        QtRestprod = QtAnt - QtProd;

                                        pvlcustoreal = pvlcustoreal + (modelopcpi.vlcustoreal);
                                        pvlcustofin  = pvlcustofin + (modelopcpi.vlcustofin);
                                        pvlcustorep  = (pvlcustorep + (modelopcpi.vlcustorep));
                                        pvlcustocont = pvlcustocont + (modelopcpi.vlcustocont);

                                        // Tratamento para politica de preços conforme tributação
                                        if (modelopcpi.sittribut == "90")
                                        {
                                            VlrProd      = VlrProd + Convert.ToDecimal(modelopcpi.pvenda);
                                            pvltabela    = pvlatend + Convert.ToDecimal(modelopcpi.pvenda);
                                            pvlatend     = pvlatend + Convert.ToDecimal(modelopcpi.pvenda);
                                            VlrTotalVend = VlrTotalVend + Convert.ToDecimal(modelopcpi.pvenda);
                                        }
                                        else
                                        {
                                            VlrProd      = VlrProd + Convert.ToDecimal(modelopcpi.pvenda);
                                            pvltabela    = pvlatend + Convert.ToDecimal(modelopcpi.pvenda);
                                            pvlatend     = pvlatend + Convert.ToDecimal(modelopcpi.pvenda);
                                            VlrTotalVend = VlrTotalVend + Convert.ToDecimal(modelopcpi.pvenda);
                                        }


                                        if (VlrTotalVend > 499)
                                        {
                                            QtProd     = QtProd - 1;
                                            QtRestprod = QtRestprod + 1;

                                            pvlcustoreal = pvlcustoreal - (modelopcpi.vlcustoreal);
                                            pvlcustofin  = pvlcustofin - (modelopcpi.vlcustofin);
                                            pvlcustorep  = pvlcustorep - (modelopcpi.vlcustorep);
                                            pvlcustocont = pvlcustocont - (modelopcpi.vlcustocont);


                                            // Tratamento para politica de preços conforme tributação
                                            if (modelopcpi.sittribut == "90")
                                            {
                                                VlrProd      = VlrProd - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvlatend     = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvltabela    = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                VlrTotalVend = VlrTotalVend - Convert.ToDecimal(modelopcpi.pvenda);
                                            }
                                            if (modelopcpi.sittribut == "60")
                                            {
                                                VlrProd      = VlrProd - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvlatend     = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvltabela    = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                VlrTotalVend = VlrTotalVend - Convert.ToDecimal(modelopcpi.pvenda);
                                            }
                                            else
                                            {
                                                VlrProd      = VlrProd - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvlatend     = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                pvltabela    = pvlatend - Convert.ToDecimal(modelopcpi.pvenda);
                                                VlrTotalVend = VlrTotalVend - Convert.ToDecimal(modelopcpi.pvenda);
                                            }


                                            contped = 1;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        QtProd     = QtProd + 0.10m;
                                        QtRestprod = QtAnt - QtProd;

                                        pvlcustoreal = pvlcustoreal + (modelopcpi.vlcustoreal / 10);
                                        pvlcustofin  = pvlcustofin + (modelopcpi.vlcustofin / 10);
                                        pvlcustorep  = pvlcustorep + (modelopcpi.vlcustorep / 10);
                                        pvlcustocont = pvlcustocont + (modelopcpi.vlcustocont / 10);



                                        // Tratamento para politica de preços conforme tributação
                                        VlrProd      = VlrProd + Convert.ToDecimal(modelopcpi.pvenda / 10);
                                        VlrTotalVend = VlrTotalVend + Convert.ToDecimal(modelopcpi.pvenda / 10);
                                        pvltabela    = pvlatend + Convert.ToDecimal(modelopcpi.pvenda / 10);
                                        pvlatend     = pvlatend + Convert.ToDecimal(modelopcpi.pvenda / 10);

                                        if (VlrTotalVend > 490)
                                        {
                                            contped = 1;
                                            break;
                                        }
                                        ii = ii - 0.90m;
                                    }
                                }

                                modelopcpi.numseq = it + 1;
                                modelopcpi.qt     = QtProd;

                                if (modelopcpi.codprod != 0 && modelopcpi.qt > 0)
                                {
                                    bllpcpi.Incluir(modelopcpi);
                                }

                                if (modelopcpi.qt == 0)
                                {
                                    bllpcpi.AlterarQTDEL(modelopcpi);
                                }

                                it++;
                                itens++;


                                vlcustoreal = vlcustoreal + pvlcustoreal;
                                vlcustofin  = vlcustofin + pvlcustofin;
                                vlcustorep  = vlcustorep + pvlcustorep;
                                vlcustocont = vlcustocont + pvlcustocont;


                                vltotal  = vltotal + VlrProd;
                                vltabela = vlatend + pvlatend; //vltabela + pvltabela;
                                vlatend  = vlatend + pvlatend;

                                //
                                modelopcpi.qtrest = QtAnt - QtProd;
                                qtrest            = modelopcpi.qtrest;

                                if (modelopcpi.codprod != 0)
                                {
                                    bllpcpi.AlterarQT(modelopcpi);
                                }
                                dgvItens.DataSource = bllpcpi.Localizar(Convert.ToInt64(txtCodigo.Text));
                                if (dgvItens.RowCount == 0)
                                {
                                    contped = 1;
                                    paraped = 1;
                                }
                            } while (vltotal < 500 && dgvItens.RowCount > 0 && contped == 0);

                            vltotalrest = vltotalrest - vltotal;

                            modelopcpc.vltotal     = Math.Round(vltotal, 2);
                            modelopcpc.vltabela    = Math.Round(vlatend, 2); // Math.Round(vltabela, 2);
                            modelopcpc.vlatend     = Math.Round(vlatend, 2);
                            modelopcpc.vlcustocont = Convert.ToDouble(vlcustocont);
                            modelopcpc.vlcustorep  = Convert.ToDouble(vlcustorep);
                            modelopcpc.vlcustofin  = Convert.ToDouble(vlcustofin);
                            modelopcpc.vlcustoreal = Convert.ToDouble(vlcustoreal);
                            modelopcpc.numpedtv1   = modelopcpcold.numpedold;
                            if (modelopcpc.vltotal != 0)
                            {
                                bllpcpc.Incluir(modelopcpc);

                                bllpcvc.Incluir(modelopcvc);

                                totalgeralped = totalgeralped + modelopcpc.vltotal;
                                string texto = "Pedido Cód: " + modelopcpc.numped.ToString() + " - Valor R$: " + Math.Round(Convert.ToDecimal(modelopcpc.vltotal), 2).ToString() + ";" + "\n";
                                rtbPedGerados.Text = rtbPedGerados.Text + "\n" + texto;
                            }
                        } while (vltotalrest > 1 && paraped == 0);

                        rtbPedGerados.Text = rtbPedGerados.Text + "\n" + "\n" + " Num. Carregamento:" + modelopcpcold.numcar + "\n" + " Pedidos/Itens: " + ped.ToString() + "/" + qtit + " Valor Total R$ " + Math.Round(Convert.ToDecimal(totalgeralped), 2).ToString();
                        clsArquivo LCLS_ArquivoTxt = new clsArquivo();
                        LCLS_ArquivoTxt.FU_Gravar(rtbPedGerados.Text);

                        //if (rtbPedGerados.Text != null)
                        //{
                        //    spoolrec("PEDIDOS.TXT");
                        //}



                        BLLPCPEDC    bllpcpold    = new BLLPCPEDC(cx);
                        ModeloPCPEDC modelopcpold = bllpcpold.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));
                        modelopcpold.vltotal = 0;
                        modelopcpold.numped  = Convert.ToInt64(txtCodigo.Text);
                        //bllpcpcold.AlterarCarSEL(modelopcpcold);
                        bllpcpold.AlterarVT(modelopcpold);
                        bllpcpold.AlterarVTI(modelopcpold);
                        txtVlrTotal.Text = "0";
                        btnGerar.Visible = false;
                        //btnImprimir.Visible = false;
                        txtTotalGer.Focus();
                        AtualizaDGVPED(Convert.ToInt32(modelopcpcold.numcar));
                        //LimpaTela();
                    }
                    if (qualificado == 0)
                    {
                        DALConexao   cx1       = new DALConexao(DadosDaConexao.StringDeConexao);
                        BLLPCPEDC    bllTab    = new BLLPCPEDC(cx1);
                        ModeloPCPEDC modeloTab = bllTab.CarregaPCPEDC(Convert.ToInt64(txtCodigo.Text));

                        bllpcpcold.AlterarPedPtabelaC(modeloTab);
                        bllpcpcold.AlterarPedPtabelaIT(modeloTab);

                        pedidos[0] = Convert.ToInt64(txtCodigo.Text);
                        pedidos[1] = Convert.ToInt64(txtCodigo.Text);
                        if (modelopcpcold.origemped != "B")
                        {
                        }
                        rtbPedGerados.Text = rtbPedGerados.Text + "\n" + "\n" + " Num. Carregamento:" + modelopcpcold.numcar + "\n" + " Pedidos/Itens: 1 /" + modelopcpcold.numitens + " Valor Total R$ " + Math.Round(Convert.ToDecimal(modelopcpcold.vlcustocont), 2).ToString();
                        AtualizaDGVPED(Convert.ToInt32(modelopcpcold.numcar));
                        txtTotalGer.Focus();
                        btnGerar.Visible = false;
                    }
                }
                if (txtNome.Text == null)
                {
                    MessageBox.Show("Pedido não pode ser dividio.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }