Example #1
0
        private void btnRemover_Click(object sender, EventArgs e)
        {
            if (!txtCodRemove.Text.Equals(""))
            {
                var P = new Produto();
                P.Codigo = txtCodRemove.Text;
                if ((ItemVendaDAO.RemoveItens(P)) == true)
                {
                    txtCodRemove.Clear();
                }
                else
                {
                    MessageBox.Show("Não há um produto com o código selecionado no carrinho!", "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Preencha o campo!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            ltvProdutos.Items.Clear();
            foreach (ItemVenda item in ItemVendaDAO.GetListItens())
            {
                ListViewItem item2 = new ListViewItem(item.Produto.Codigo.ToString());
                item2.SubItems.Add(item.Produto.Nome);
                item2.SubItems.Add(item.Produto.Preco.ToString());
                item2.SubItems.Add(item.Quant.ToString());
                item2.SubItems.Add(ItemVendaBO.CalcularSub(item.Produto.Preco, item.Quant).ToString("C2"));
                ltvProdutos.Items.Add(item2);
            }
            txtTotal.Text = ItemVendaBO.CalcularTotal().ToString();
        }
Example #2
0
 private void btnBuscar_Click(object sender, EventArgs e)
 {
     if (!txtIdVenda.Equals(""))
     {
         var Venda = new Venda();
         Venda.Id = int.Parse(txtIdVenda.Text);
         if ((Venda = VendaDAO.Find(Venda)) != null)
         {
             if ((Venda.Cliente) != null)
             {
                 //var C = new Cliente();
                 //C.Cpf = Venda.Cliente.Cpf;
                 //Venda.Cliente = C;
                 mskCpfC.Text  = Venda.Cliente.Cpf;
                 txtNomeC.Text = Venda.Cliente.Nome;
                 txtEndC.Text  = Venda.Cliente.Endereco;
                 mskTelC.Text  = Venda.Cliente.Telefone;
                 if (Venda.Cliente.Sexo.Equals("F"))
                 {
                     rdoFemC.Checked = true;
                 }
                 else
                 {
                     rdoMascC.Checked = true;
                 }
                 mskCpfV.Text  = Venda.Vendedor.Cpf;
                 txtTotal.Text = Venda.Total.ToString("C2");
                 txtForma.Text = Venda.FormaPag;
                 txtData.Text  = Venda.Data.ToString();
                 ltvProdutos.Items.Clear();
                 var VI = new VendaEItem();
                 VI.Venda = VendaDAO.Find(Venda);
                 foreach (VendaEItem item in VendaEItemDAO.FindVI(VI))
                 {
                     ListViewItem item2 = new ListViewItem(item.ItemVenda.Produto.Codigo.ToString());
                     item2.SubItems.Add(item.ItemVenda.Produto.Nome);
                     item2.SubItems.Add(item.ItemVenda.Produto.Preco.ToString("C2"));
                     item2.SubItems.Add(item.ItemVenda.Quant.ToString());
                     item2.SubItems.Add(ItemVendaBO.CalcularSub(item.ItemVenda.Produto.Preco, item.ItemVenda.Quant).ToString("C2"));
                     ltvProdutos.Items.Add(item2);
                 }
                 MessageBox.Show("Encontrada!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             else
             {
                 MessageBox.Show("Ocorreu um erro ao buscar a venda desejada!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("Venda não encontrada!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("Preencha o campo!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #3
0
 private void btnAdd_Click(object sender, EventArgs e)//-1 no index significa não ter
 {
     if (!txtIdP.Text.Equals("") && !txtQuantP.Text.Equals(""))
     {
         var P = new Produto();
         P.Codigo = txtIdP.Text;
         if ((P = ProdutoDAO.FindCodigo(P)) != null)
         {
             if (ItemVendaDAO.FindIndex(P) == -1)
             {
                 if (P.Estoque >= int.Parse(txtQuantP.Text) && int.Parse(txtQuantP.Text) > 0)
                 {
                     var i = new ItemVenda();
                     i.Quant   = int.Parse(txtQuantP.Text);
                     i.Produto = P;
                     ItemVendaDAO.AddItens(i);
                     txtIdP.Clear();
                     txtQuantP.Clear();
                 }
                 else
                 {
                     MessageBox.Show("Não tem estoque para a quantidade selecionada! Ou a quantidade selecionada é menor ou igual a zero.", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 }
             }
             else
             {
                 int index = ItemVendaDAO.FindIndex(P);
                 var iv    = new ItemVenda();
                 iv = ItemVendaDAO.FindIndexObj(index);
                 int quanttemp = iv.Quant + int.Parse(txtQuantP.Text);
                 iv.Produto = P;
                 if (quanttemp <= P.Estoque)
                 {
                     iv.Quant += int.Parse(txtQuantP.Text);
                     ItemVendaDAO.AddIndexObj(iv, index);
                     txtQuantP.Clear();
                     txtIdP.Clear();
                 }
                 else
                 {
                     MessageBox.Show("Não há estoque!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 }
             }
         }
         else
         {
             MessageBox.Show("Produto não cadastrado!", "Atenção!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     else
     {
         MessageBox.Show("Preencha os campos!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     ltvProdutos.Items.Clear();
     foreach (ItemVenda item in ItemVendaDAO.GetListItens())
     {
         ListViewItem item2 = new ListViewItem(item.Produto.Codigo.ToString());
         item2.SubItems.Add(item.Produto.Nome);
         item2.SubItems.Add(item.Produto.Preco.ToString("C2"));
         item2.SubItems.Add(item.Quant.ToString());
         item2.SubItems.Add(ItemVendaBO.CalcularSub(item.Produto.Preco, item.Quant).ToString("C2"));
         ltvProdutos.Items.Add(item2);
     }
     txtTotal.Text = ItemVendaBO.CalcularTotal().ToString();
 }