Beispiel #1
0
        private void gerenciarClientesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmCadastrados frmCadastrados = new FrmCadastrados(modelCaixa = null);

            frmCadastrados.Show();
        }
Beispiel #2
0
 private void txtCodigoBarras_KeyDown(object sender, KeyEventArgs e)
 {
     //Adiciona o item na lista
     if (e.KeyCode == Keys.Enter && !VendaFinalizada)
     {
         try
         {
             for (int i = 1; i <= txtQuantidade.Value; i++)
             {
                 QuantidadeAdicionada = 1;
                 foreach (DataGridViewRow row in dgvCaixa.Rows)
                 {
                     if (row.Cells["CodigoBarras"].Value != null && (string)row.Cells["CodigoBarras"].Value == txtCodigoBarras.Text)
                     {
                         QuantidadeAdicionada++;
                     }
                 }
                 modelCaixa = controllerCaixa.VerificarProduto(txtCodigoBarras.Text);
                 if (controllerCaixa.VerificarProduto(txtCodigoBarras.Text) == null || QuantidadeAdicionada > controllerCaixa.VerificarQuantidade(txtCodigoBarras.Text))
                 {
                     txtCodigoBarras.ForeColor = Color.Red;
                     MessageBox.Show("Produto não existe no estoque!");
                     txtCodigoBarras.Text      = null;
                     txtCodigoBarras.ForeColor = Color.Black;
                     txtCodigoBarras.Focus();
                     txtQuantidade.Value = 1;
                 }
                 else
                 {
                     dgvCaixa.Rows.Insert(0, modelCaixa.Codigo, modelCaixa.NomeProduto, modelCaixa.Categoria, modelCaixa.Fabricante, modelCaixa.CodigoBarras, modelCaixa.Plataforma, modelCaixa.Garantia, modelCaixa.ValorProduto);
                     valorTotal         = valorTotal + Convert.ToInt32(modelCaixa.ValorProduto);
                     txtValorTotal.Text = valorTotal.ToString("C");
                     int valorUnitario;
                     valorUnitario             = Convert.ToInt32(modelCaixa.ValorProduto);
                     txtValorUnitario.Text     = valorUnitario.ToString("C");
                     txtNomeProduto.Text       = modelCaixa.NomeProduto;
                     dgvCaixa.Rows[0].Selected = true;
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     //Deleta o item da lista
     else if (e.KeyCode == Keys.Delete && !VendaFinalizada)
     {
         if (dgvCaixa.Rows.Count > 0)
         {
             try
             {
                 valorTotal = valorTotal - Convert.ToInt32(dgvCaixa.CurrentRow.Cells["ValorProduto"].Value.ToString());
                 dgvCaixa.Rows.RemoveAt(dgvCaixa.CurrentRow.Index);
                 txtValorTotal.Text = valorTotal.ToString("C");
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     //Finalizar venda
     if (dgvCaixa.Rows.Count > 0 && e.KeyCode == Keys.F1)
     {
         FrmCaixaOpcaoPagamento frmCaixaOpcaoPagamento = new FrmCaixaOpcaoPagamento();
         frmCaixaOpcaoPagamento.ShowDialog();
         if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "DINHEIRO")
         {
             if (dgvCaixa.Rows.Count > 0)
             {
                 try
                 {
                     FrmCaixaDinheiro frmCaixaDinheiro = new FrmCaixaDinheiro(txtValorTotal.Text);
                     frmCaixaDinheiro.ShowDialog();
                     if (frmCaixaDinheiro.Retorno != "")
                     {
                         VendaFinalizada = true;
                         if (valorVenda == 0)
                         {
                             valorVenda            = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", ""));
                             modelCaixa.ValorVenda = valorVenda.ToString("C");
                         }
                         dinheiroPago               = dinheiroPago + Convert.ToDecimal(frmCaixaDinheiro.Dinheiro);
                         valortotalPago             = valortotalPago + Convert.ToDecimal(frmCaixaDinheiro.Dinheiro);
                         modelCaixa.NomeCliente     = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento;
                         modelCaixa.StatusPagamento = "Recebido";
                         modelCaixa.DataRecebimento = DateTime.Now.ToString();
                         modelCaixa.RecebidoPor     = Properties.SettingsLogado.Default.Nome;
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "CARTAO")
         {
             if (dgvCaixa.Rows.Count > 0)
             {
                 try
                 {
                     FrmCaixaCartaoDebito frmCaixaCartaoDebito = new FrmCaixaCartaoDebito();
                     frmCaixaCartaoDebito.ShowDialog();
                     if (frmCaixaCartaoDebito.Retorno != "")
                     {
                         VendaFinalizada = true;
                         if (valorVenda == 0)
                         {
                             valorVenda            = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", ""));
                             modelCaixa.ValorVenda = valorVenda.ToString("C");
                         }
                         cartaoPago                 = cartaoPago + Convert.ToDecimal(frmCaixaCartaoDebito.Retorno);
                         valortotalPago             = valortotalPago + Convert.ToDecimal(frmCaixaCartaoDebito.Retorno);
                         modelCaixa.NomeCliente     = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento;
                         modelCaixa.StatusPagamento = "Recebido";
                         modelCaixa.DataRecebimento = DateTime.Now.ToString();
                         modelCaixa.RecebidoPor     = Properties.SettingsLogado.Default.Nome;
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "TICKET")
         {
             if (dgvCaixa.Rows.Count > 0)
             {
                 try
                 {
                     FrmCaixaTicket frmCaixaTicket = new FrmCaixaTicket(Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", "")));
                     frmCaixaTicket.ShowDialog();
                     if (frmCaixaTicket.Retorno != "")
                     {
                         VendaFinalizada = true;
                         if (valorVenda == 0)
                         {
                             valorVenda            = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", ""));
                             modelCaixa.ValorVenda = valorVenda.ToString("C");
                         }
                         ticketPago                 = ticketPago + frmCaixaTicket.RetornoTicket;
                         valortotalPago             = valortotalPago + frmCaixaTicket.RetornoTicket;
                         modelCaixa.NomeCliente     = "CAIXA-" + frmCaixaOpcaoPagamento.RetornoOpcaoPagamento;
                         modelCaixa.StatusPagamento = "Recebido";
                         modelCaixa.DataRecebimento = DateTime.Now.ToString();
                         modelCaixa.RecebidoPor     = Properties.SettingsLogado.Default.Nome;
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         if (frmCaixaOpcaoPagamento.RetornoOpcaoPagamento == "CONVENIADO" && !VendaFinalizada)
         {
             if (dgvCaixa.Rows.Count > 0)
             {
                 try
                 {
                     modelCaixa.Conveniado = "?";
                     FrmCadastrados frmCadastrados = new FrmCadastrados(modelCaixa);
                     frmCadastrados.ShowDialog();
                     if (frmCadastrados.Retorno != null)
                     {
                         VendaFinalizada = true;
                         if (valorVenda == 0)
                         {
                             valorVenda            = Convert.ToDecimal(txtValorTotal.Text.Replace("R$ ", ""));
                             modelCaixa.ValorVenda = valorVenda.ToString("C");
                         }
                         modelCaixa.NomeCliente     = frmCadastrados.Retorno;
                         conveniadoValor            = valorVenda;
                         valortotalPago             = valorVenda;
                         modelCaixa.StatusPagamento = "Em Aberto";
                         modelCaixa.DataRecebimento = "";
                         modelCaixa.RecebidoPor     = "";
                     }
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 }
             }
         }
         if (VendaFinalizada)
         {
             try
             {
                 if (valortotalPago >= valorVenda)
                 {
                     modelCaixa.OpcaoPagamento = frmCaixaOpcaoPagamento.RetornoOpcaoPagamento;
                     modelCaixa.Dinheiro       = dinheiroPago.ToString("C");
                     modelCaixa.Cartao         = cartaoPago.ToString("C");
                     modelCaixa.Ticket         = ticketPago.ToString("C");
                     modelCaixa.Conveniado     = conveniadoValor.ToString("C");
                     modelCaixa.Cheque         = "R$ 0,00";
                     modelCaixa.ChequeDias     = "----------";
                     modelCaixa.StatusVenda    = "Finalizada";
                     modelCaixa.DataVenda      = DateTime.Now.ToString();
                     modelCaixa.Vendedor       = Properties.SettingsLogado.Default.Nome;
                     int CodigoPedido = controllerCaixa.InserirPedido(modelCaixa);
                     foreach (DataGridViewRow row in dgvCaixa.Rows)
                     {
                         modelCaixa.CodigoPedido = CodigoPedido;
                         modelCaixa.CodigoBarras = row.Cells["CodigoBarras"].Value.ToString();
                         modelCaixa.NomeProduto  = row.Cells["NomeProduto"].Value.ToString();
                         modelCaixa.Categoria    = row.Cells["Categoria"].Value.ToString();
                         modelCaixa.Fabricante   = row.Cells["Fabricante"].Value.ToString();
                         modelCaixa.ValorProduto = row.Cells["ValorProduto"].Value.ToString();
                         modelCaixa.Plataforma   = row.Cells["Plataforma"].Value.ToString();
                         modelCaixa.Garantia     = row.Cells["Garantia"].Value.ToString();
                         controllerCaixa.MenosQuantidadeEstoque(modelCaixa);
                         controllerCaixa.InserirPedidoItens(modelCaixa);
                     }
                     ZerarCaixa();
                 }
                 else
                 {
                     decimal resto = valorVenda - valortotalPago;
                     txtValorTotal.Text = resto.ToString("C");
                 }
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     //Gera um orçamento dos itens listados
     if (dgvCaixa.Rows.Count > 0 && e.KeyCode == Keys.F12)
     {
         try
         {
             printFont = new Font("Arial", 9);
             PrintDocument pd = new PrintDocument();
             printDialog1.Document = pd;
             var result = printDialog1.ShowDialog();
             if (result == DialogResult.OK)
             {
                 pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                 pd.Print();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }