Exemplo n.º 1
0
        private void btn_EditProducts_Click(object sender, EventArgs e)
        {
            try
            {
                Barcode = grid_SearchProducts.SelectedRows[0].Cells[0].Value.ToString();

                answer = tap.GetDataByCodBarras(Barcode);

                frm_EditProducts.txt_Code.Text        = answer[0].Codigo_Barras.ToString();
                frm_EditProducts.cmb_TypeProduct.Text = answer[0].Tipo_Producto.ToString();
                frm_EditProducts.txt_Name.Text        = answer[0].Nombre.ToString();
                frm_EditProducts.txt_Description.Text = answer[0].Descripcion.ToString();
                frm_EditProducts.txt_Amount.Text      = answer[0].Stock.ToString();
                frm_EditProducts.txt_Price.Text       = answer[0].Precio_Venta.ToString();
                frm_EditProducts.txt_vIva.Text        = answer[0].Porcentaje_Iva.ToString();

                this.Close();
                frm_EditProducts.Show();
                frm_EditProducts.found = true;
            }
            catch (Exception error)
            {
                MessageBox.Show("Error al Modificar! Seleccione un producto que sea Valido... Ha Ocurrido el Siguiente Error: " + error, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
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);
                }
            }
        }
        private void btn_AddProduct_Click(object sender, EventArgs e)
        {
            try
            {
                bool number = int.TryParse(txt_Amount.Text, out int n);

                if (number)
                {
                    if (txt_Amount.Text != "" && Convert.ToInt32(txt_Amount.Text) > 0 && Convert.ToInt32(txt_Amount.Text) <= limit)
                    {
                        amount = Convert.ToInt32(txt_Amount.Text);
                        SC     = new ShoppingCart();
                        prd    = new Product();

                        producto = pta.GetDataByCodBarras(barcode);

                        if (!Exist())
                        {
                            prd.Barcode     = barcode;
                            prd.Borrado     = producto[0].Borrado;
                            prd.Description = producto[0].Descripcion;
                            prd.Iva         = producto[0].Porcentaje_Iva;
                            prd.Name        = producto[0].Nombre;
                            prd.Price       = producto[0].Precio_Venta;
                            prd.Stock       = producto[0].Stock;

                            SC.Product    = prd;
                            SC.Quantity   = amount;
                            SC.Iva        = ((SC.Product.Iva * SC.Product.Price) / 100) * SC.Quantity;
                            SC.TotalPrice = SC.Product.Price * SC.Quantity;

                            returnList.Add(SC);
                        }
                        else
                        {
                            foreach (ShoppingCart prod in returnList)
                            {
                                if (prod.Product.Barcode == barcode)
                                {
                                    if ((limit - prod.Quantity) >= amount)
                                    {
                                        prod.Quantity += amount;
                                        SC.Iva        += ((SC.Product.Iva * SC.Product.Price) / 100) * SC.Quantity;
                                        SC.TotalPrice += SC.Product.Price * SC.Quantity;
                                    }
                                }
                            }
                        }


                        limit   = 0;
                        amount  = 0;
                        barcode = "";
                        dGrid_Dev.DataSource = null;
                        dGrid_Dev.DataSource = returnList;
                    }
                    else
                    {
                        MessageBox.Show("Ingrese un Valor válido", "Devolución",
                                        MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                else
                {
                    MessageBox.Show("Ingrese un entero válido");
                }
            }

            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Exemplo n.º 4
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();
                }
            }
        }