コード例 #1
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show(
                    @"Confirme la insercion del abono", "Agregar el abono?",
                    MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result.Equals(DialogResult.Yes))
                {
                    decimal monto = int.Parse(txtMonto.Text);
                    //Obteniendo el codigo de el detalle a abonar
                    int id = (int)dgvCreditos.SelectedRows[0].Cells["Detalle"].Value;
                    //Obteniendo el codigo del vehiculo
                    int id_vehiculo = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                    //Registramos la transaccion
                    int i = TransaccionController.agregar(MainContainer.sesion.Id_usuario, id_vehiculo, DateTime.Now.Date, true);
                    if (i > 0)
                    {
                        //si se guardo el encabezado de la factura
                        int j = _AbonoController.Agregar(TransaccionController.getUltima().IdTransaccion, id, monto);
                        if (j > 0)
                        {
                            MessageBox.Show("Abono Agregado Correctamente!", "Cambios Guardados");
                            //Mostramos factura
                            var tra   = TransaccionController.getUltima();
                            var abono = _AbonoController.getAllAbono().OrderByDescending(x => x.Id_transaccion).FirstOrDefault();

                            var form = new Factura_Abono(
                                tra.Vehiculo.Placa, tra.IdTransaccion, tra.FechaTransaccion,
                                MainContainer.sesion.Nickname, abono.Detalle.IdTransaccion,
                                abono.Detalle.Transaccion.FechaTransaccion, abono.Detalle.TipoEgreso.ToString(),
                                abono.Detalle.Cantidad, abono.Monto, (abono.Detalle.Saldo_detalle.Saldo)
                                );
                            form.ShowDialog();
                            //Recargamos los datos
                            AgregarAbono_Load(sender, e);
                        }
                        else
                        {
                            throw new Exception("No se ha logrado la insercion del Abono!!!");
                        }
                    }
                    else
                    {
                        throw new NullReferenceException("No se ha registrado la transaccion", new Exception("El codigo de la transaccion no se genero correctamente!"));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error durante la insercion de la factura", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
 void ActualizarNoFactura()
 {
     try
     {
         var ultima = TransaccionController.getUltima();
         if (ultima != null)
         {
             lblFactura.Text = String.Format("{0}", ultima.IdTransaccion + 1);
         }
         else
         {
             lblFactura.Text = "1";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error al obtener el numero de facturacion actual", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #3
0
 void ActualizarNoFactura()
 {
     try
     {
         var ultima = TransaccionController.getUltima();
         if (ultima != null)
         {
             lblNoFactura.Text = String.Format("{0}", ultima.IdTransaccion + 1);
         }
         else
         {
             lblNoFactura.Text = "1";
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #4
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (CombosValidos())
            {
                var confirmacion = MessageBox.Show("Guardar Factura?", "Los Cambios no se pueden deshacer!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (confirmacion.Equals(DialogResult.Yes))
                {
                    try
                    {
                        //Obtiendo el encabezado de la transaccion
                        int      id_cajero   = MainContainer.sesion.Personas.Id_persona;
                        int      id_vehiculo = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                        DateTime Fecha       = dtFecha.Value.Date;
                        //Insertando la transaccion
                        int i = TransaccionController.agregar(id_cajero, id_vehiculo, Fecha, true);
                        //Si la transaccion tuvo exito
                        if (i > 0)
                        {
                            int t = 0;
                            //Obtiendo el utimo id de la transaccion
                            int     idTransaccion = TransaccionController.getUltima().IdTransaccion;
                            decimal ing           = 0;
                            decimal eg            = 0;
                            for (int j = 0; j < dgvEgresos.Rows.Count; j++)
                            {
                                int    TipoDetalle   = (int)dgvEgresos.Rows[j].Cells[0].Value;
                                string Descripcion   = (string)dgvEgresos.Rows[j].Cells[2].Value;
                                string tipo          = dgvEgresos.Rows[j].Cells[3].Value.ToString();
                                int    tpTransaccion = 0; //Egreso
                                if (tipo.Equals("INGRESO"))
                                {
                                    tpTransaccion = 1;
                                }
                                else if (tipo.Equals("CREDITO"))
                                {
                                    tpTransaccion = 2;
                                }

                                decimal monto = (decimal)dgvEgresos.Rows[j].Cells[4].Value;

                                t = DetalleController.agregar(idTransaccion, TipoDetalle, Descripcion, monto, tpTransaccion, true);
                                float dec = Convert.ToSingle(monto);

                                if (tipo == "INGRESO")
                                {
                                    ing += monto;
                                }

                                else if (tipo.Equals("EGRESO"))
                                {
                                    eg += monto;
                                }
                                totalFactura = 0;
                            }
                            if (t == 0) //Si no se registraron transacciones
                            {
                                throw new Exception("No se registraron las transacciones de Entrada/Salida!");
                            }
                            else
                            {
                                decimal total = ing - eg;
                                MessageBox.Show("Se ha insertado la transacion", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ImprimirTicket(idTransaccion, MainContainer.sesion.ToString(), ((Vehiculo)cboVehiculo.SelectedItem).Placa, total, ing, eg);
                                LimpiarControles();
                            }
                        }
                        else
                        {
                            throw new Exception("No se pudo insertar la transaccion");
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("Todos los campos son requeridos!", "Faltan campos por completar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #5
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //Validar Selecciones
            bool txts, cbos;

            txts = TextosValidos();
            cbos = CombosValidos();
            //fechas = FechasValidas();
            if (txts && cbos)
            {
                try
                {
                    //Obtencion de la informacion para registrar una carrera
                    int      id_cajero    = MainContainer.sesion.Personas.Id_persona;
                    int      id_conductor = ((Conductor)cboConductor.SelectedItem).Id_conductor;
                    int      id_vehiculo  = ((Vehiculo)cboVehiculo.SelectedItem).Id_Vehiculo;
                    DateTime Fecha        = dtFecha.Value.Date;
                    TimeSpan salida       = dtSalida.Value.TimeOfDay;
                    TimeSpan llegada      = dtLlegada.Value.TimeOfDay;
                    bool     vuelta       = cbVueltaCompleta.Checked;
                    //Agregando Transaccion
                    int t = TransaccionController.agregar(id_cajero, id_vehiculo, Fecha, true);
                    //Comprobamos que se haya insertado la transaccion
                    if (t > 0)
                    {
                        //Obtenemos el id de la ultima transaccion
                        int idTransaccion = TransaccionController.getUltima().IdTransaccion;
                        t = CarreraController.Agregar(idTransaccion, id_vehiculo, id_conductor, salida, llegada, Fecha, vuelta);
                        //Si se inserto correctamente la carrera, procedemos a ingresar los gastos
                        if (t > 0)
                        {
                            t = 0;
                            decimal ingreso = Decimal.Parse(QuitarEspacios(txtIngreso.Text));
                            //Registrando Ingreso
                            t = DetalleController.agregar(idTransaccion, TipoDetalleController.leer("CICLO").IdTipoDetalle, "CICLO", ingreso, 0, true);
                            //Verificando y registrando los egresos
                            decimal totalEgreso = 0;
                            if (dgvEgresos.Rows.Count > 0) // Si hay egresos
                            {
                                for (int j = 0; j < dgvEgresos.RowCount; j++)
                                {
                                    int     id_egreso   = (int)dgvEgresos.Rows[j].Cells[0].Value;
                                    string  descripcion = dgvEgresos.Rows[j].Cells[2].Value.ToString();
                                    decimal monto       = (decimal)dgvEgresos.Rows[j].Cells[3].Value;
                                    totalEgreso += monto;
                                    t           += DetalleController.agregar(idTransaccion, id_egreso, descripcion, monto, 1, true);
                                }
                            }
                            if (t == 0) //Si no se registraron transacciones
                            {
                                throw new Exception("No se registraron las transacciones de Entrada/Salida!");
                            }
                            //Se imprime la factura
                            else
                            {
                                var result = MessageBox.Show("Imprimir factura?", "Confirme Impresion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (result.Equals(DialogResult.Yes))
                                {
                                    var ultima = CarreraController.getUltima();
                                    //var cond = ConductorController.leer(ultima.Id_conductor);
                                    //Creando instancia de reporte
                                    TicketFisicoForm ticket = new TicketFisicoForm(
                                        CapaControlador.TransaccionController.getUltima().IdTransaccion,
                                        ultima.FechaCarrera.ToShortDateString(),
                                        MainContainer.sesion.ToString(),
                                        ultima.Vehiculo.Placa,
                                        ultima.Vehiculo.Socio.ToString(),
                                        cboConductor.SelectedItem.ToString(),
                                        ingreso,
                                        totalEgreso,
                                        (ingreso - totalEgreso)
                                        );
                                    ticket.ShowDialog();
                                }
                                limpiarControles();
                                actualizarNoFactura();
                            }
                        }
                        else
                        {
                            throw new Exception("No se Completo el registro de la carrera");
                        }
                    }
                    else
                    {
                        throw new Exception("No se Ingreso la carrera");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Todos los campos son requeridos!", "Faltan campos por completar", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }