예제 #1
0
        //Constructor.
        public FrmBuscarProducto(FrmIngresoProductos _FormIngresoProductos)
        {
            InitializeComponent();
            FormIngresoProductos = _FormIngresoProductos;

            //Estable la búqueda por defecto (Código)
            cbxTipoBusqueda.SelectedIndex = 0;

            //Rellena los resultados con las coincidencias que encuentre.
            this.dgvProductos.DataSource = NProductos.Buscar("", "Código");
        }
예제 #2
0
        //btnAgregar - Evento Click - Inserta el producto que se ha seleccionado en el dgvProductos y calcula los totales.
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            //Muestra el form para ingresar el producto.
            FrmIngresoProductos FormIngresoProductos = new FrmIngresoProductos(this);

            FormIngresoProductos.ShowDialog();
            FormIngresoProductos.Dispose();

            if (!String.IsNullOrEmpty(IdProducto))
            {
                try
                {
                    int Bandera       = 0;
                    int FilaIngresado = 0;

                    //Revisa que el producto no haya sido ingresado previamente.
                    for (int Fila = 0; Fila < dgvProductos.Rows.Count; Fila++)
                    {
                        //Si ha sido ingresado activa la bandera.
                        if (dgvProductos.Rows[Fila].Cells["ColumnDescripcion"].Value.ToString() == Descripcion)
                        {
                            Bandera       = 1;
                            FilaIngresado = Fila;
                        }
                    }

                    //Asigan formato al codigo
                    IdProducto = String.Format("{0:0000}", Convert.ToInt32(IdProducto));

                    //Si la bandera fue activada suma el valor a lo que ya fue iingresado.
                    if (Bandera == 1)
                    {
                        Cantidad = Convert.ToString(Convert.ToDecimal(Cantidad) +
                                                    Convert.ToDecimal(dgvProductos.SelectedRows[FilaIngresado].Cells[2].Value));
                        Importe = String.Format("{0:#,##0.00}", Double.Parse(Convert.ToString(Convert.ToDecimal(Cantidad)
                                                                                              * Convert.ToDecimal(Precio))));
                        dgvProductos.SelectedRows[FilaIngresado].SetValues(IdProducto, Descripcion, Cantidad, Precio, Importe, Impuesto);
                    }
                    else //En caso contrario agrega una nueva linea.
                    {
                        this.dgvProductos.Rows.Add(IdProducto, Descripcion, Cantidad, Precio, Importe, Impuesto);
                    }
                    //Calcula los totales con los respectivos impuestos.
                    string  ImpuestoActual  = "";
                    string  NombreImpuesto1 = "";
                    string  NombreImpuesto2 = "";
                    decimal SumaImpuesto1   = 0;
                    decimal SumaImpuesto2   = 0;
                    decimal Exento          = 0;

                    //Busca los precios relacionados con los impuestos.
                    for (int Fila = 0; Fila < dgvProductos.Rows.Count; Fila++)
                    {
                        ImpuestoActual = dgvProductos.Rows[Fila].Cells["ColumnImpuesto"].Value.ToString();

                        //Si el impuesto no ha sido creado se crea.
                        if (NombreImpuesto1 != ImpuestoActual && NombreImpuesto2 != ImpuestoActual && "EXENTO 00.00" != ImpuestoActual)
                        {
                            if (NombreImpuesto1 == "")
                            {
                                NombreImpuesto1            = ImpuestoActual;
                                this.lblBaseImpuesto1.Text = NombreImpuesto1;
                            }
                            else if (NombreImpuesto2 == "")
                            {
                                NombreImpuesto2            = ImpuestoActual;
                                this.lblBaseImpuesto2.Text = NombreImpuesto2;
                            }
                        }

                        //Suma el impuesto al correspondiente.
                        if (ImpuestoActual == NombreImpuesto1)
                        {
                            SumaImpuesto1 += Convert.ToDecimal(dgvProductos.Rows[Fila].Cells["ColumnImporte"].Value);
                        }
                        else if (ImpuestoActual == NombreImpuesto2)
                        {
                            SumaImpuesto2 += Convert.ToDecimal(dgvProductos.Rows[Fila].Cells["ColumnImporte"].Value);
                        }
                        else
                        {
                            Exento += Convert.ToDecimal(dgvProductos.Rows[Fila].Cells["ColumnImporte"].Value);
                        }
                    }

                    //Calcula los valores de los impuestos.
                    decimal Impuesto1 = 0;
                    decimal Impuesto2 = 0;

                    //Ingresa los valores en los cuadros de texto.
                    if (NombreImpuesto1 != "")
                    {
                        Impuesto1 = SumaImpuesto1 * (Convert.ToDecimal(NombreImpuesto1.Substring(NombreImpuesto1.Length - 5).
                                                                       Replace(" %", "").Replace(".", ",")) / 100);
                        this.lblNombreBaseImpuesto1.Text      = "B.I. " + NombreImpuesto1;
                        this.lblNombreBaseImpuesto1.ForeColor = Color.Black;
                        this.lblBaseImpuesto1.Text            = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(SumaImpuesto1)));
                        this.lblBaseImpuesto1.ForeColor       = Color.Black;
                        this.lblNombreImpuesto1.Text          = NombreImpuesto1;
                        this.lblNombreImpuesto1.ForeColor     = Color.Black;
                        this.lblImpuesto1.Text      = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(Impuesto1)));
                        this.lblImpuesto1.ForeColor = Color.Black;
                    }
                    if (NombreImpuesto2 != "")
                    {
                        Impuesto2 = SumaImpuesto2 * (Convert.ToDecimal(NombreImpuesto2.Substring(NombreImpuesto2.Length - 5).
                                                                       Replace(" %", "").Replace(".", ",")) / 100);
                        this.lblNombreBaseImpuesto2.Text      = "B.I. " + NombreImpuesto2;
                        this.lblNombreBaseImpuesto2.ForeColor = Color.Black;
                        this.lblBaseImpuesto2.Text            = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(SumaImpuesto2)));
                        this.lblBaseImpuesto2.ForeColor       = Color.Black;
                        this.lblNombreImpuesto2.Text          = NombreImpuesto2;
                        this.lblNombreImpuesto2.ForeColor     = Color.Black;
                        this.lblImpuesto2.Text      = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(Impuesto2)));
                        this.lblImpuesto2.ForeColor = Color.Black;
                    }
                    if (Exento != 0)
                    {
                        this.lblExento.Text = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(Exento)));
                    }


                    //Asigna los valores y los formatos.
                    lblSubTotal.Text = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(SumaImpuesto1 + SumaImpuesto2)));
                    lblTotal.Text    = String.Format("{0:#,##0.00}", decimal.Parse(Convert.ToString(SumaImpuesto1 +
                                                                                                    SumaImpuesto2 + Impuesto1 + Impuesto2 + Exento)));
                }
                catch (Exception ex)
                {
                    new Configuracion().Mensaje("Los valores ingresados son incorrectos. " + ex.Message, "Datos Inválidos",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }