Example #1
0
        private void btnCambiarPrecio_Click(object sender, EventArgs e)
        {
            try
            {
                if (dgvProductos.SelectedRows.Count > 0)
                {
                    ElegirOpcion elegirOpcion = new ElegirOpcion(usuario, "Cambio de precio", "Seleccione a que precio desea cambiar el producto", "Detalle", "Mayor");
                    //MessageBoxManager.Retry = "Detalle";
                    //MessageBoxManager.Cancel = "Mayor";

                    DialogResult resultado = elegirOpcion.ShowDialog();//MessageBox.Show("Seleccione a que precio desea cambiar el producto", "Cambio de precio", MessageBoxButtons.RetryCancel, MessageBoxIcon.Exclamation);

                    if (resultado == DialogResult.Abort || resultado == DialogResult.Retry)
                    {
                        foreach (DataGridViewRow item in dgvProductos.SelectedRows)
                        {
                            int id = Convert.ToInt32(item.Cells[6].Value.ToString());
                            dataPro = adapterPro.BuscarPreciosPorId(id);
                            string precioDetalle = dataPro[0][dataPro.PrecioDetalleColumn].ToString();
                            string precioMayor   = dataPro[0][dataPro.PrecioMayorColumn].ToString();

                            string precio = "";

                            if (resultado == DialogResult.Retry)
                            {
                                precio = dataPro[0][dataPro.PrecioDetalleColumn].ToString();
                            }
                            else if (resultado == DialogResult.Abort)
                            {
                                precio = dataPro[0][dataPro.PrecioMayorColumn].ToString();
                            }

                            //precio = resultado == DialogResult.Retry ? dataPro[0][dataPro.PrecioDetalleColumn].ToString() :  dataPro[0][dataPro.PrecioMayorColumn].ToString();

                            item.Cells[1].Value = precio;
                            decimal importe = Convert.ToDecimal(precio) * Convert.ToDecimal(txtCantidad.Text);
                            decimal ITBIS   = 0;

                            if (aplicaITBIS)
                            {
                                ITBIS    = Convert.ToDecimal(importe * 18 / 100);
                                ITBIS    = Math.Round(ITBIS, 2);
                                importe += ITBIS;
                            }
                            item.Cells[3].Value = ITBIS;
                            item.Cells[5].Value = importe - Convert.ToDecimal(item.Cells[4].Value.ToString());
                        }
                        Total();
                        txtIdProducto.Focus();
                    }
                    else
                    {
                        MessageBox.Show("Debe seleccionar a que precio quiere cambiar el producto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Debe seleccionar un producto al que desea cambiarle el precio", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            catch (Exception error)
            {
                log.Error($"Error: {error.Message}", error);
                MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }