Beispiel #1
0
        private void Btn_generarReporte_Click(object sender, EventArgs e)
        {
            Frm_reporteFactura     reporteFactura = new Frm_reporteFactura();
            ReportDocument         oRep           = new ReportDocument();
            ParameterField         pf             = new ParameterField();
            ParameterFields        pfs            = new ParameterFields();
            ParameterDiscreteValue pdv            = new ParameterDiscreteValue();

            pf.Name   = "numFac";            // variable del store procedure
            pdv.Value = Lbl_codFactura.Text; // variable donde se  guarda el numero de factura
            pf.CurrentValues.Add(pdv);
            pfs.Add(pf);
            reporteFactura.crystalReportViewer1.ParameterFieldInfo = pfs;
            oRep.Load("C:/Reportes/reporteFactura.rpt");
            reporteFactura.crystalReportViewer1.ReportSource = oRep;
            reporteFactura.Show();
        }
Beispiel #2
0
        private void Btn_facturar_Click(object sender, EventArgs e)
        {
            //algoritmo para obtener la dirección IP de la máquina
            IPHostEntry host;
            string      localIP = "?";

            host = Dns.GetHostEntry(Dns.GetHostName());

            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily.ToString() == "InterNetwork")
                {
                    localIP = ip.ToString();
                }
            } //fin de algoritmo

            if (contadorFila > 0)
            {
                try
                {
                    int idCliente = Convert.ToInt32(Txt_codigoCliente.Text);

                    //inserta registro de factura encabezado a la BD
                    string consultaInsertar = "INSERT INTO tbl_facturaencabezado (Pk_idCliente, Pk_idEmpleado, fechaCotizacion," +
                                              "cantidadPasajeros, Fk_idTipoPago, Total, Factura_Cotizacion) VALUES('" + idCliente + "' , " +
                                              "'" + idEmpleado + "', '" + Lbl_fechaEmision.Text + "', '" + Convert.ToInt32(Cbo_Pasajero.Text) + "', " +
                                              "'" + Convert.ToInt32(Cbo_tipoPago.SelectedValue) + "', '" + Convert.ToInt32(Lbl_resultado.Text) + "', " +
                                              "'" + factura_cotizacion + "')";

                    OdbcCommand comm = new OdbcCommand(consultaInsertar, Conexion.nuevaConexion());
                    comm.ExecuteNonQuery();
                    comm.Connection.Close();

                    //Selecciona el Id actual de la factura
                    comm = new OdbcCommand("SELECT MAX(Pk_idFactura) FROM tbl_facturaencabezado;", Conexion.nuevaConexion());
                    OdbcDataReader consulta = comm.ExecuteReader();

                    while (consulta.Read())
                    {
                        numFactura = consulta.GetInt32(0);
                    }
                    comm.Connection.Close();
                    consulta.Close();

                    Random rnd = new Random();
                    //Recorrera cada fila del Dgv
                    foreach (DataGridViewRow Fila in Dgv_detalleFactura.Rows)
                    {
                        codLinea         = rnd.Next();
                        consultaInsertar = "INSERT INTO tbl_facturadetalle (Pk_idFactura, Pk_codigoLinea, " +
                                           "Fk_idTipoHabitacion, FK_idMenus, Fk_idLugarTuristico, cantidadHabitaciones) VALUES(" +
                                           "'" + numFactura + "', '" + codLinea + "', '" + Convert.ToInt32(Fila.Cells[0].Value.ToString()) + "'," +
                                           "'" + Convert.ToInt32(Fila.Cells[1].Value.ToString()) + "', '" + Fila.Cells[2].Value.ToString() + "'," +
                                           "'" + Convert.ToInt32(Fila.Cells[3].Value.ToString()) + "')";

                        comm = new OdbcCommand(consultaInsertar, Conexion.nuevaConexion());
                        comm.ExecuteNonQuery();
                    }
                    comm.Connection.Close();

                    MessageBox.Show("Se realizo la factura correctamente");
                    Dgv_detalleFactura.Rows.Clear();
                    Limpiar();
                    Grpbx_encabezado.Enabled = true;
                    contadorFila             = 0;

                    OdbcCommand commBitacora = new OdbcCommand("{call SP_InsertarBitacora(?,?,?,?,?)}", Conexion.nuevaConexion());
                    commBitacora.CommandType = CommandType.StoredProcedure;
                    commBitacora.Parameters.Add("ope", OdbcType.Text).Value   = "PROCESO DE FACTURACIÓN";
                    commBitacora.Parameters.Add("usr", OdbcType.Text).Value   = usuario;
                    commBitacora.Parameters.Add("fecha", OdbcType.Text).Value = fecha.ToString("yyyy/MM/dd HH:mm:ss");
                    commBitacora.Parameters.Add("proc", OdbcType.Text).Value  = "VENTAS";
                    commBitacora.Parameters.Add("dirIp", OdbcType.Text).Value = localIP;
                    commBitacora.ExecuteNonQuery();

                    commBitacora.Connection.Close();

                    Frm_reporteFactura     reporteFactura = new Frm_reporteFactura();
                    ReportDocument         oRep           = new ReportDocument();
                    ParameterField         pf             = new ParameterField();
                    ParameterFields        pfs            = new ParameterFields();
                    ParameterDiscreteValue pdv            = new ParameterDiscreteValue();
                    pf.Name   = "numFac";   // variable del store procedure
                    pdv.Value = numFactura; // variable donde se  guarda el numero de factura
                    pf.CurrentValues.Add(pdv);
                    pfs.Add(pf);
                    reporteFactura.crystalReportViewer1.ParameterFieldInfo = pfs;
                    oRep.Load("C:/Reportes/reporteFactura.rpt");
                    reporteFactura.crystalReportViewer1.ReportSource = oRep;
                    reporteFactura.Show();
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                    MessageBox.Show("Error al realizar la factura");
                }
            }
            else
            {
                MessageBox.Show("No se han ingresado campos para facturar");
            }
        }