コード例 #1
0
        private void btnCheck_Click(object sender, EventArgs e)
        {
            LogicaGo logica = new LogicaGo();

            Double value;

            if (txtRecibido.Text.Equals(""))
            {
                //txtRecibido.Text = "0";
                MessageBox.Show("Debe ingresar el valor entregado por el Cliente");
            }
            else
            {
                if (listaProductosVenta.Count == 0)
                {
                    MessageBox.Show("No ha Seleccionado Productos");
                }
                else
                {
                    if (txtNombre.Text.Equals(""))
                    {
                        txtNombre.Text = "Usuario No Definido";
                    }
                    if (Convert.ToDecimal(txtRecibido.Text) < valorFactura)
                    {
                        MessageBox.Show("El valor Recibido no debe ser inferior del total de la factura");
                    }

                    else
                    {
                        if (Double.TryParse((Convert.ToDecimal(txtRecibido.Text) - valorFactura).ToString(), out value))
                        {
                            lblCambio.Text = String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C2}", value);
                        }
                        lblCambioTitulo.Text = "Cambio: ";
                        int factura = logica.insertarFactura(txtNombre.Text, txtCelular.Text, txtDireccion.Text, valorFactura, user.Nombres + " " + user.Apellidos);
                        foreach (ProductoVenta p in listaProductosVenta)
                        {
                            logica.insertarVenta(factura, p.IdProducto, (int)p.Cantidad, (double)p.Valor, (double)p.Total);
                        }
                        //int factura = 100;
                        btnCheck.Enabled = false;

                        var confirmResult = MessageBox.Show("Desea Imprimir la factura?",
                                                            "Confirmar Impresión!!",
                                                            MessageBoxButtons.YesNo);
                        if (confirmResult == DialogResult.Yes)
                        {
                            LocalReport reporte = new LocalReport();
                            //reporte.ReportPath = @"..\..\rptFactura.rdlc";
                            reporte.ReportPath = ConfigurationManager.AppSettings["rutaReporteFactura"];
                            ReportParameter[] parameters = new ReportParameter[2];
                            parameters[0] = new ReportParameter("nombre", txtNombre.Text);
                            parameters[1] = new ReportParameter("facturaId", factura.ToString());
                            reporte.SetParameters(parameters);
                            ReportDataSource rds = new ReportDataSource("dsProductosVentas", ConvertToDataTable(listaProductosVenta));
                            reporte.DataSources.Add(rds);
                            Export(reporte);
                            Print();
                        }
                        else
                        {
                            MessageBox.Show("Venta Realizada Correctamente..");
                        }
                    }
                }
            }
            //frmReportFactura reporteFactura = new frmReportFactura();
            //reporteFactura.generarReporte(listaProductosVenta, txtNombre.Text, valorFactura, factura);
            //reporteFactura.Show();
            //MessageBox.Show("Factura generada con exito. Cambio: "+ String.Format(System.Globalization.CultureInfo.CurrentCulture, "{0:C2}", value) +" idFactura: "+factura);
        }