Esempio n. 1
0
        private void Confirma()
        {
            if (MessageBox.Show("Tem certeza que deseja mesclar as Pré-Vendas selecionadas?", "Mesclar Pre-Venda", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                FCaixa.LabelMensagens.Text = "Aguarde. Mesclando Pré-Venda!";
                List <PreVendaCabecalhoVO> ListaPreVendaCabecalhoMescla = new List <PreVendaCabecalhoVO>();
                List <PreVendaDetalheVO>   ListaPreVendaDetalheMescla   = new List <PreVendaDetalheVO>();
                PreVendaCabecalhoVO        PreVendaCabecalho;
                PreVendaDetalheVO          PreVendaDetalhe;

                for (int i = 0; i <= GridMestre.Rows.Count - 1; i++)
                {
                    if (ListaPreVendaCabecalho[i].Situacao == "X")
                    {
                        PreVendaCabecalho       = new PreVendaCabecalhoVO();
                        PreVendaCabecalho.Id    = ListaPreVendaCabecalho[i].Id;
                        PreVendaCabecalho.Valor = ListaPreVendaCabecalho[i].Valor;
                        ListaPreVendaCabecalhoMescla.Add(PreVendaCabecalho);

                        for (int j = 0; j <= GridDetalhe.Rows.Count - 1; j++)
                        {
                            //TODO:  Observe que não temos todos esses itens na lista. Implemente isso no Controller ao carregar a tabela de detalhe.
                            PreVendaDetalhe                = new PreVendaDetalheVO();
                            PreVendaDetalhe.IdPreVenda     = PreVendaCabecalho.Id;
                            PreVendaDetalhe.Id             = ListaPreVendaDetalhe[j].Id;
                            PreVendaDetalhe.IdProduto      = ListaPreVendaDetalhe[j].IdProduto;
                            PreVendaDetalhe.GtinProduto    = ListaPreVendaDetalhe[j].GtinProduto;
                            PreVendaDetalhe.NomeProduto    = ListaPreVendaDetalhe[j].NomeProduto;
                            PreVendaDetalhe.UnidadeProduto = ListaPreVendaDetalhe[j].UnidadeProduto;
                            PreVendaDetalhe.Cancelado      = ListaPreVendaDetalhe[j].Cancelado;
                            PreVendaDetalhe.Quantidade     = ListaPreVendaDetalhe[j].Quantidade;
                            PreVendaDetalhe.ValorUnitario  = ListaPreVendaDetalhe[j].ValorUnitario;
                            PreVendaDetalhe.ValorTotal     = ListaPreVendaDetalhe[j].ValorTotal;
                            ListaPreVendaDetalheMescla.Add(PreVendaDetalhe);
                        }
                    }
                }

                if (ListaPreVendaDetalheMescla.Count < 1)
                {
                    MessageBox.Show("Nenhum item selecionado!", "Informação do Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    PreVendaController.MesclaPreVenda(ListaPreVendaCabecalhoMescla, ListaPreVendaDetalheMescla);
                    FCaixa.LabelMensagens.Text = "Venda em andamento.";
                    this.Close();
                }
            }
        }
Esempio n. 2
0
        private void EditCodigoProduto_Leave(object sender, EventArgs e)
        {
            try
            {
                if (EditCodigoProduto.Text.Trim() != "")
                {
                    ProdutoVO Produto = ProdutoController.ConsultaId(Convert.ToInt32(EditCodigoProduto.Text.Trim()));
                    if (Produto != null)
                    {
                        editUnitario.Text  = Produto.ValorVenda.ToString();
                        editTotalItem.Text = (Produto.ValorVenda * Convert.ToDecimal(editQuantidade.Text)).ToString("0.00");

                        PreVendaDetalheVO PreVendaDetalhe = new PreVendaDetalheVO();
                        PreVendaDetalhe.IdProduto      = Produto.Id;
                        PreVendaDetalhe.Item           = Item++;
                        PreVendaDetalhe.Quantidade     = Convert.ToDecimal(editQuantidade.Text);
                        PreVendaDetalhe.ValorUnitario  = Convert.ToDecimal(editUnitario.Text);
                        PreVendaDetalhe.ValorTotal     = Convert.ToDecimal(editTotalItem.Text);
                        PreVendaDetalhe.GtinProduto    = Produto.GTIN;
                        PreVendaDetalhe.NomeProduto    = Produto.Nome;
                        PreVendaDetalhe.UnidadeProduto = Produto.UnidadeProduto;
                        PreVendaDetalhe.ECFICMS        = Produto.TotalizadorParcial;

                        ListaPreVendaDetalhe.Add(PreVendaDetalhe);
                        GridItens.DataSource = typeof(List <PreVendaDetalheVO>);
                        GridItens.DataSource = ListaPreVendaDetalhe;
                        GridItens.Refresh();

                        TotalGeral         = TotalGeral + PreVendaDetalhe.ValorTotal;
                        labelSubtotal.Text = TotalGeral.ToString("0.00");
                        labelTotal.Text    = TotalGeral.ToString("0.00");

                        EditCodigoProduto.Text = "";
                        EditCodigoProduto.Focus();
                    }
                    else
                    {
                        MessageBox.Show("Código não cadastrado.", "Informação do Sistema", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception eError)
            {
                Log.write(eError.ToString());
            }
        }
        public List <PreVendaDetalheVO> TabelaPreVendaDetalhe(string pIdCabecalho)
        {
            List <PreVendaDetalheVO> ListaPreVendaDetalhe = new List <PreVendaDetalheVO>();

            ConsultaSQL = " SELECT * FROM PRE_VENDA_DETALHE WHERE ID_PRE_VENDA_CABECALHO = " + pIdCabecalho;

            try
            {
                comando = new MySqlCommand(ConsultaSQL, conexao);
                leitor  = comando.ExecuteReader();
                while (leitor.Read())
                {
                    PreVendaDetalheVO PreVendaDetalhe = new PreVendaDetalheVO();

                    PreVendaDetalhe.Id            = Convert.ToInt32(leitor["ID"]);
                    PreVendaDetalhe.NomeProduto   = leitor["NOME_PRODUTO"].ToString();
                    PreVendaDetalhe.Quantidade    = Convert.ToDecimal(leitor["QUANTIDADE"]);
                    PreVendaDetalhe.ValorUnitario = Convert.ToDecimal(leitor["VALOR_UNITARIO"]);
                    PreVendaDetalhe.ValorTotal    = Convert.ToDecimal(leitor["VALOR_TOTAL"]);

                    ListaPreVendaDetalhe.Add(PreVendaDetalhe);
                }
                return(ListaPreVendaDetalhe);
            }

            catch (Exception eError)
            {
                Log.write(eError.ToString());
                return(null);
            }
            finally
            {
                if (leitor != null)
                {
                    leitor.Close();
                }
            }
        }
        public List <PreVendaDetalheVO> CarregaPreVenda(int pId)
        {
            // verifica se existe a pre-venda solicitada
            ConsultaSQL =
                "select * from PRE_VENDA_CABECALHO where " +
                "SITUACAO <> " + Biblioteca.QuotedStr("E") + " and SITUACAO <> " + Biblioteca.QuotedStr("M") + " and ID=" + Convert.ToString(pId);

            try
            {
                comando = new MySqlCommand(ConsultaSQL, conexao);
                leitor  = comando.ExecuteReader();

                // caso exista a pre-venda, procede com a importacao da mesma
                if (leitor.HasRows)
                {
                    leitor.Close();
                    // verifica se existem itens para a pre-venda
                    ConsultaSQL =
                        "select * from PRE_VENDA_DETALHE where ID_PRE_VENDA_CABECALHO=" + Convert.ToString(pId);
                    comando = new MySqlCommand(ConsultaSQL, conexao);
                    leitor  = comando.ExecuteReader();
                    // caso existam itens no detalhe
                    if (leitor.HasRows)
                    {
                        leitor.Close();

                        ConsultaSQL =
                            "select * from PRE_VENDA_CABECALHO where ID=" + Convert.ToString(pId);
                        comando = new MySqlCommand(ConsultaSQL, conexao);
                        leitor  = comando.ExecuteReader();
                        leitor.Read();

                        if (FCaixa.Cliente == null)
                        {
                            FCaixa.Cliente = new ClienteVO();
                        }

                        FCaixa.Cliente.Id        = Convert.ToInt32(leitor["ID_PESSOA"]);
                        FCaixa.Cliente.Nome      = Convert.ToString(leitor["NOME_DESTINATARIO"]);
                        FCaixa.Cliente.CpfOuCnpj = Convert.ToString(leitor["CPF_CNPJ_DESTINATARIO"]);
                        FCaixa.Desconto          = Convert.ToDecimal(leitor["DESCONTO"]);
                        FCaixa.Acrescimo         = Convert.ToDecimal(leitor["ACRESCIMO"]);

                        leitor.Close();
                        ConsultaSQL =
                            "select * from PRE_VENDA_DETALHE where ID_PRE_VENDA_CABECALHO=" + Convert.ToString(pId);
                        comando = new MySqlCommand(ConsultaSQL, conexao);
                        leitor  = comando.ExecuteReader();

                        List <PreVendaDetalheVO> ListaVenda = new List <PreVendaDetalheVO>();
                        while (leitor.Read())
                        {
                            PreVendaDetalheVO PreVendaDetalhe = new PreVendaDetalheVO();
                            PreVendaDetalhe.Id             = Convert.ToInt32(leitor["ID"]);
                            PreVendaDetalhe.IdPreVenda     = pId;
                            PreVendaDetalhe.IdProduto      = Convert.ToInt32(leitor["ID_PRODUTO"]);
                            PreVendaDetalhe.Item           = Convert.ToInt32(leitor["ITEM"]);
                            PreVendaDetalhe.Quantidade     = Convert.ToInt32(leitor["QUANTIDADE"]);
                            PreVendaDetalhe.ValorUnitario  = Convert.ToDecimal(leitor["VALOR_UNITARIO"]);
                            PreVendaDetalhe.ValorTotal     = Convert.ToDecimal(leitor["VALOR_TOTAL"]);
                            PreVendaDetalhe.Cancelado      = Convert.ToString(leitor["CANCELADO"]);
                            PreVendaDetalhe.GtinProduto    = Convert.ToString(leitor["GTIN_PRODUTO"]);
                            PreVendaDetalhe.NomeProduto    = Convert.ToString(leitor["NOME_PRODUTO"]);
                            PreVendaDetalhe.UnidadeProduto = Convert.ToString(leitor["UNIDADE_PRODUTO"]);
                            PreVendaDetalhe.ECFICMS        = Convert.ToString(leitor["ECF_ICMS_ST"]);
                            ListaVenda.Add(PreVendaDetalhe);
                        }
                        return(ListaVenda);
                    }
                    else
                    {
                        return(null);
                    }
                }
                // caso não exista a pre-venda, retorna um ponteiro nulo
                else
                {
                    return(null);
                }
            }

            catch (Exception eError)
            {
                Log.write(eError.ToString());
                return(null);
            }
            finally
            {
                if (leitor != null)
                {
                    leitor.Close();
                }
            }
        }
        public void CancelaPreVendasPendentes(int pId)
        {
            PreVendaCabecalhoVO PreVendaCabecalho = new PreVendaCabecalhoVO();

            try
            {
                List <PreVendaCabecalhoVO> ListaPreVendaCabecalho = new List <PreVendaCabecalhoVO>();
                List <PreVendaDetalheVO>   ListaPreVendaDetalhe   = new List <PreVendaDetalheVO>();
                //
                ConsultaSQL = "select * from PRE_VENDA_CABECALHO where ID=" + Convert.ToString(pId);
                comando     = new MySqlCommand(ConsultaSQL, conexao);
                leitor      = comando.ExecuteReader();
                leitor.Read();
                {
                    PreVendaCabecalho.Id    = Convert.ToInt32(leitor["ID"]);
                    PreVendaCabecalho.Valor = Convert.ToDecimal(leitor["VALOR"]);
                    ListaPreVendaCabecalho.Add(PreVendaCabecalho);
                    leitor.Close();

                    ConsultaSQL = "SELECT * FROM PRE_VENDA_DETALHE WHERE ID_PRE_VENDA_CABECALHO=" + Convert.ToString(PreVendaCabecalho.Id);
                    comando     = new MySqlCommand(ConsultaSQL, conexao);
                    leitor      = comando.ExecuteReader();

                    while (leitor.Read())
                    {
                        PreVendaDetalheVO PreVendaDetalhe = new PreVendaDetalheVO();
                        PreVendaDetalhe.IdProduto      = Convert.ToInt32(leitor["ID_PRODUTO"]);
                        PreVendaDetalhe.IdPreVenda     = Convert.ToInt32(leitor["ID_PRE_VENDA_CABECALHO"]);
                        PreVendaDetalhe.IdProduto      = Convert.ToInt32(leitor["ID_PRODUTO"]);
                        PreVendaDetalhe.Item           = Convert.ToInt32(leitor["ITEM"]);
                        PreVendaDetalhe.Quantidade     = Convert.ToDecimal(leitor["QUANTIDADE"]);
                        PreVendaDetalhe.ValorUnitario  = Convert.ToDecimal(leitor["VALOR_UNITARIO"]);
                        PreVendaDetalhe.ValorTotal     = Convert.ToDecimal(leitor["VALOR_TOTAL"]);
                        PreVendaDetalhe.Cancelado      = Convert.ToString(leitor["CANCELADO"]);
                        PreVendaDetalhe.GtinProduto    = Convert.ToString(leitor["GTIN_PRODUTO"]);
                        PreVendaDetalhe.NomeProduto    = Convert.ToString(leitor["NOME_PRODUTO"]);
                        PreVendaDetalhe.UnidadeProduto = Convert.ToString(leitor["UNIDADE_PRODUTO"]);
                        PreVendaDetalhe.ECFICMS        = Convert.ToString(leitor["ECF_ICMS_ST"]);
                        ListaPreVendaDetalhe.Add(PreVendaDetalhe);
                    }
                }

                if (leitor != null)
                {
                    leitor.Close();
                }

                // atualiza no banco de dados
                ConsultaSQL =
                    "update PRE_VENDA_CABECALHO set " +
                    "SITUACAO = " + Biblioteca.QuotedStr("C") +
                    " where ID=" + Convert.ToString(PreVendaCabecalho.Id);

                comando = new MySqlCommand(ConsultaSQL, conexao);
                comando.ExecuteNonQuery();

                CancelaPreVendasPendentes(ListaPreVendaCabecalho, ListaPreVendaDetalhe);
            }

            catch (Exception eError)
            {
                Log.write(eError.ToString());
            }
            finally
            {
                if (leitor != null)
                {
                    leitor.Close();
                }
            }
        }
        public void CancelaPreVendasPendentes(System.DateTime pDataMovimento)
        {
            MySqlDataReader leitorInterno;

            // verifica se existem PV pendentes
            ConsultaSQL =
                "select * from PRE_VENDA_CABECALHO where " +
                "SITUACAO = " + Biblioteca.QuotedStr("P") + " and DATA_PV < ?pData ";

            try
            {
                comando = new MySqlCommand(ConsultaSQL, conexao);
                comando.Parameters.AddWithValue("?pData", pDataMovimento);
                leitor = comando.ExecuteReader();

                // caso existam PV pendentes procede com o processo de cancelamento de pre-vendas
                if (leitor.HasRows)
                {
                    leitor.Close();
                    List <PreVendaCabecalhoVO> ListaPreVendaCabecalho = new List <PreVendaCabecalhoVO>();
                    List <PreVendaDetalheVO>   ListaPreVendaDetalhe   = new List <PreVendaDetalheVO>();
                    //
                    ConsultaSQL = "select * from PRE_VENDA_CABECALHO where " +
                                  "SITUACAO = " + Biblioteca.QuotedStr("P") + " and DATA_PV < ?pData";

                    comando = new MySqlCommand(ConsultaSQL, conexao);
                    comando.Parameters.AddWithValue("?pData", pDataMovimento);
                    leitor = comando.ExecuteReader();

                    while (leitor.Read())
                    {
                        PreVendaCabecalhoVO PreVendaCabecalho = new PreVendaCabecalhoVO();
                        PreVendaCabecalho.Id    = Convert.ToInt32(leitor["ID"]);
                        PreVendaCabecalho.Valor = Convert.ToDecimal(leitor["VALOR"]);
                        ListaPreVendaCabecalho.Add(PreVendaCabecalho);

                        comando       = new MySqlCommand("SELECT * FROM PRE_VENDA_DETALHE WHERE ID_PRE_VENDA_CABECALHO=" + Convert.ToString(PreVendaCabecalho.Id), conexao);
                        leitorInterno = comando.ExecuteReader();

                        while (leitorInterno.Read())
                        {
                            PreVendaDetalheVO PreVendaDetalhe = new PreVendaDetalheVO();
                            PreVendaDetalhe.IdProduto      = Convert.ToInt32(leitor["ID_PRODUTO"]);
                            PreVendaDetalhe.IdPreVenda     = Convert.ToInt32(leitor["ID_PRE_VENDA_CABECALHO"]);
                            PreVendaDetalhe.IdProduto      = Convert.ToInt32(leitor["ID_PRODUTO"]);
                            PreVendaDetalhe.Item           = Convert.ToInt32(leitor["ITEM"]);
                            PreVendaDetalhe.Quantidade     = Convert.ToDecimal(leitor["QUANTIDADE"]);
                            PreVendaDetalhe.ValorUnitario  = Convert.ToDecimal(leitor["VALOR_UNITARIO"]);
                            PreVendaDetalhe.ValorTotal     = Convert.ToDecimal(leitor["VALOR_TOTAL"]);
                            PreVendaDetalhe.Cancelado      = Convert.ToString(leitor["CANCELADO"]);
                            PreVendaDetalhe.GtinProduto    = Convert.ToString(leitor["GTIN_PRODUTO"]);
                            PreVendaDetalhe.NomeProduto    = Convert.ToString(leitor["NOME_PRODUTO"]);
                            PreVendaDetalhe.UnidadeProduto = Convert.ToString(leitor["UNIDADE_PRODUTO"]);
                            PreVendaDetalhe.ECFICMS        = Convert.ToString(leitor["ECF_ICMS_ST"]);
                            ListaPreVendaDetalhe.Add(PreVendaDetalhe);
                        }
                    }

                    // atualiza no banco de dados
                    ConsultaSQL =
                        "update PRE_VENDA_CABECALHO set " +
                        "SITUACAO = " + Biblioteca.QuotedStr("C") +
                        " where SITUACAO = " + Biblioteca.QuotedStr("P") + " and DATA_PV < ?pData";
                    comando.Parameters.AddWithValue("?pData", pDataMovimento);
                    comando.ExecuteNonQuery();

                    CancelaPreVendasPendentes(ListaPreVendaCabecalho, ListaPreVendaDetalhe);
                }
            }

            catch (Exception eError)
            {
                Log.write(eError.ToString());
            }
            finally
            {
                if (leitor != null)
                {
                    leitor.Close();
                }
            }
        }