示例#1
0
        private void btnImprimirFactura_Click(object sender, EventArgs e)
        {
            if (!validarSoloNumeros(edtidEncabezado))
            {
            }
            else
            {
                String idEncabezadoFactura = edtidEncabezado.Text.Trim();

                //Verificando si existe
                Boolean existe;
                String  consultaExiste = String.Format("select * from factura_encabezado where idfactura_encabezado= '{0}'", idEncabezadoFactura);
                existe = Utilidades.Existe(consultaExiste);

                if (existe == true)
                {
                    try
                    {
                        DataSet dtConsultaFactura;
                        String  consultaFactura = String.Format("exec listarPorEncabezadoFactura '{0}'", idEncabezadoFactura);
                        dtConsultaFactura = Utilidades.Ejecutar(consultaFactura);


                        HacerFactura hacerFactura = new HacerFactura();
                        hacerFactura.reportViewer1.LocalReport.DataSources[0].Value = dtConsultaFactura.Tables[0];
                        hacerFactura.ShowDialog();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Error al traer datos para la factura" + err.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Esta factura no se ha generado");
                }
            } //fin validando campo vacio
        }     //fin imprimir
示例#2
0
        private void btnFacturar_Click(object sender, EventArgs e)
        {
            if (datagridFacturar.Rows.Count > 0)
            {
                String idEncabezadoFactura = "";

                int    idcliente = Convert.ToInt32(txtIdCliente.Text);
                Double total     = Convert.ToDouble(txtTotal.Text);
                //insertar encabezado factura
                try
                {
                    DataSet dtInsertarEncabezadoFactura;
                    String  consultaInsertar = String.Format("exec insertarEncabezadoFactura '{0}','{1}'", idcliente, total);

                    dtInsertarEncabezadoFactura = Utilidades.Ejecutar(consultaInsertar);
                    //obtener el ecabezado
                    idEncabezadoFactura = (dtInsertarEncabezadoFactura.Tables[0].Rows[0]["idfactura_encabezado"].ToString().Trim());
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error al insertar Encabezado factura" + err.Message);
                }
                //Para insertar el detalle
                foreach (DataGridViewRow fila in datagridFacturar.Rows)
                {
                    int    iddetalleServicio = Convert.ToInt32(fila.Cells[0].Value.ToString());
                    Double cantidad          = Convert.ToDouble(fila.Cells[3].Value.ToString());
                    Double precio            = Convert.ToDouble(fila.Cells[4].Value.ToString());
                    Double descuento         = Convert.ToDouble(fila.Cells[5].Value.ToString());
                    Double subtot            = Convert.ToDouble(fila.Cells[6].Value.ToString());

                    //Hacer la inserción
                    try
                    {
                        DataSet dtInsertar;
                        String  consultaInsertar = String.Format("exec insertarFactura '{0}','{1}','{2}','{3}','{4}','{5}'", idEncabezadoFactura, cantidad, precio, descuento, subtot, iddetalleServicio);

                        dtInsertar = Utilidades.Ejecutar(consultaInsertar);
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Error al insertar factura" + err.Message);
                    }
                }//fin del foreach

                //Traer los datos para el reporte de factura
                if (idEncabezadoFactura != "")
                {
                    try
                    {
                        DataSet dtConsultaFactura;
                        String  consultaFactura = String.Format("exec listarPorEncabezadoFactura '{0}'", idEncabezadoFactura);
                        dtConsultaFactura = Utilidades.Ejecutar(consultaFactura);


                        HacerFactura hacerFactura = new HacerFactura();
                        hacerFactura.reportViewer1.LocalReport.DataSources[0].Value = dtConsultaFactura.Tables[0];
                        hacerFactura.ShowDialog();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show("Error al traer datos para la factura" + err.Message);
                    }
                }
            }//fin verificando si hay datos para insertar
            else
            {
                MessageBox.Show("Debe agregar servicios!");
            }
        }