Пример #1
0
        private void txt_Barcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    answer = tap.GetDataByCodBarras(txt_Barcode.Text);

                    if (answer.Count > 0)
                    {
                        Product = new Product();
                        SCP     = new ShoppingCart();

                        SelectedProduct = answer[0];

                        Product.Barcode     = SelectedProduct.Codigo_Barras;
                        Product.Name        = SelectedProduct.Nombre;
                        Product.Price       = SelectedProduct.Precio_Venta;
                        Product.Iva         = SelectedProduct.Porcentaje_Iva;
                        Product.Description = SelectedProduct.Descripcion;
                        Product.Stock       = SelectedProduct.Stock;
                        Product.TypeProduct = SelectedProduct.Tipo_Producto;
                        Product.Borrado     = SelectedProduct.Borrado;


                        frm_ChooseQuantityBuy = new ChooseQuantityBuy(this);
                        frm_ChooseQuantityBuy.Show();

                        frm_ChooseQuantityBuy.FormClosed += new FormClosedEventHandler(ChooseAmount);
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show(err.Message);
                }
            }
        }
Пример #2
0
        private void txt_barcode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    answer = pta.GetDataByCodBarras(txt_barcode.Text);

                    if (answer.Count > 0)
                    {
                        if (checkBox_DeleteProductSP.Checked == true)
                        {
                            if (ProductExist())
                            {
                                ShoppingCart prod = null;

                                foreach (ShoppingCart prd in CartList)
                                {
                                    if (prd.Product.Barcode == txt_barcode.Text)
                                    {
                                        if (prd.Quantity == 1)
                                        {
                                            prod = prd;
                                        }
                                        else
                                        {
                                            prd.Quantity--;
                                            prd.TotalPrice -= prd.Product.Price;
                                            prd.Iva        -= (prd.Product.Price * prd.Product.Iva) / 100;
                                        }

                                        break;
                                    }
                                }

                                if (prod != null)
                                {
                                    CartList.Remove(prod);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Producto Inexistente en Carrito", "Ventas",
                                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                        else
                        {
                            if (checkBox_DeleteQuantity.Checked == true)
                            {
                                if (ProductExist())
                                {
                                    foreach (ShoppingCart prd in CartList)
                                    {
                                        if (prd.Product.Barcode == txt_barcode.Text)
                                        {
                                            cQuantity = new ChooseQuantity(this, prd.Quantity);
                                            cQuantity.Show();

                                            cQuantity.FormClosed += new FormClosedEventHandler(DeleteQuantity);
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    txt_barcode.ResetText();

                                    MessageBox.Show("Producto Inexistente en Carrito", "Ventas",
                                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                            }
                            else
                            {
                                Product = new Product();
                                SCP     = new ShoppingCart();

                                ProductSelected = answer[0];

                                Product.Barcode     = ProductSelected.Codigo_Barras;
                                Product.Name        = ProductSelected.Nombre;
                                Product.Description = ProductSelected.Descripcion;
                                Product.Price       = ProductSelected.Precio_Venta;
                                Product.Iva         = ProductSelected.Porcentaje_Iva;
                                Product.Stock       = ProductSelected.Stock;
                                Product.TypeProduct = ProductSelected.Tipo_Producto;
                                Product.Borrado     = ProductSelected.Borrado;

                                if (checkBox_AddQuantity.Checked == true)
                                {
                                    bool status = false;

                                    foreach (ShoppingCart sc in CartList)
                                    {
                                        if (sc.Product.Barcode == txt_barcode.Text)
                                        {
                                            cQuantity = new ChooseQuantity(this, (Product.Stock - sc.Quantity));
                                            status    = true;
                                            break;
                                        }
                                    }

                                    if (status == false)
                                    {
                                        cQuantity = new ChooseQuantity(this, Product.Stock);
                                    }

                                    cQuantity.Show();
                                    cQuantity.FormClosed += new FormClosedEventHandler(AddQuantity);
                                }
                                else
                                {
                                    if (!ProductExist())
                                    {
                                        if (Product.Stock > 0)
                                        {
                                            SCP.Product    = Product;
                                            SCP.Quantity   = 1;
                                            SCP.TotalPrice = SCP.Product.Price * SCP.Quantity;
                                            SCP.Iva        = (SCP.Product.Price * SCP.Product.Iva) / 100;

                                            CartList.Add(SCP);
                                        }
                                        else
                                        {
                                            MessageBox.Show("Cantidades Insuficientes", "Ventas",
                                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        }
                                    }
                                    else
                                    {
                                        foreach (ShoppingCart prd in CartList)
                                        {
                                            if (prd.Product.Barcode == txt_barcode.Text)
                                            {
                                                if (prd.Quantity + 1 <= Product.Stock)
                                                {
                                                    prd.Quantity++;
                                                    prd.TotalPrice += prd.Product.Price;
                                                    prd.Iva        += (prd.Product.Price * prd.Product.Iva) / 100;
                                                    break;
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Cantidades Insuficientes", "Ventas",
                                                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        ActCurrentPrice();
                    }
                    else
                    {
                        MessageBox.Show("Producto Inexistente", "Ventas",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                catch (Exception err)
                {
                    MessageBox.Show("" + err);
                }

                dGrid_ShoppingCart.DataSource = null;
                dGrid_ShoppingCart.DataSource = CartList;

                if (checkBox_AddQuantity.Checked == false && checkBox_DeleteQuantity.Checked == false)
                {
                    txt_barcode.Clear();
                }
            }
        }