예제 #1
0
 public EntidadNegocio.Entidades.Cliente Details(int id)
 {
     Dato.Modelo.Cliente _cliente = new Dato.Modelo.Cliente();
     if (id == 0)
     {
         _cliente = new Dato.Modelo.Cliente();
     }
     else
     {
         _cliente = db.ClienteSet.First(c => c.ID == id);
     }
     EntidadNegocio.Entidades.Cliente clienteDetail = new EntidadNegocio.Entidades.Cliente();
     clienteDetail.ID            = _cliente.ID;
     clienteDetail.Nombre        = _cliente.Nombre;
     clienteDetail.Telefono      = _cliente.Telefono;
     clienteDetail.Correo        = _cliente.Correo;
     clienteDetail.Direccion     = _cliente.Direccion;
     clienteDetail.NumAlquileres = 0;
     if (_cliente.Estatus == 1)
     {
         clienteDetail.Status = EntidadNegocio.Enumerados.EnumEstatus.Registro.Activo;
     }
     else
     {
         clienteDetail.Status = EntidadNegocio.Enumerados.EnumEstatus.Registro.Inactivo;
     }
     return(clienteDetail);
 }
예제 #2
0
        public Boolean Create(EntidadNegocio.Entidades.Cliente _cliente)
        {
            Dato.Modelo.Cliente clienteToAdd = new Dato.Modelo.Cliente();
            Boolean             resul        = false;

            clienteToAdd.ID        = _cliente.ID;
            clienteToAdd.Nombre    = _cliente.Nombre;
            clienteToAdd.Telefono  = _cliente.Telefono;
            clienteToAdd.Correo    = _cliente.Correo;
            clienteToAdd.Direccion = _cliente.Direccion;
            if (_cliente.Status == EntidadNegocio.Enumerados.EnumEstatus.Registro.Activo)
            {
                clienteToAdd.Estatus = 1;
            }
            else
            {
                clienteToAdd.Estatus = 0;
            }

            //valido claves primaria
            if (db.ClienteSet.FirstOrDefault(c => c.ID == clienteToAdd.ID) != null)
            {
                MessageBox.Show(EntidadNegocio.Entidades.Mensajes.Info_ErrorAlGuardarViolacionPK, EntidadNegocio.Entidades.Mensajes.Titulo_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (db.Connection.State != System.Data.ConnectionState.Open)
                {
                    db.Connection.Open();
                }

                DbTransaction dbTransaction = db.Connection.BeginTransaction();

                try
                {
                    // Guardar y confirmar el cliente.
                    db.AddToClienteSet(clienteToAdd);
                    db.SaveChanges();
                    dbTransaction.Commit();
                    /// Si la transaccion es exitosa enviamos true
                    Dato.Modelo.Cliente _entidadToIDAdd = db.ClienteSet.ToList().LastOrDefault();
                    Int32 _id = _entidadToIDAdd.ID;
                    _entidadToIDAdd.ID = _id;
                    resul = true;
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    HandleException excepcion = new HandleException();
                    String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                    excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                    resul = false;
                }
            }

            return(resul);
        }
예제 #3
0
        public Boolean Create(EntidadNegocio.Entidades.PagoCabecera _pago)
        {
            Int32 iIDCliente = _pago.IDCliente; Boolean resul = false;

            Dato.Modelo.Cliente cliente = db.ClienteSet.First(c => c.ID == iIDCliente);
            Int32 _iIDCliente           = cliente.ID;

            Dato.Modelo.PagoCabecera    pagoCabeceraToAdd = new PagoCabecera();
            List <Dato.Modelo.Alquiler> listAlquiler      = db.AlquilerSet.Where(a => a.IDCliente == iIDCliente && a.Estatus == 1).ToList();

            Double _dMontoEstimado = 0; _dMontoEstimado = (from monto in listAlquiler select monto.PrecioEstimado).Sum().Value;

            _pago.MontoExento = _dMontoEstimado;

            DateTime _dFecha = DateTime.Now;

            _pago.Fecha = _dFecha;

            pagoCabeceraToAdd.IDCliente   = _iIDCliente;
            pagoCabeceraToAdd.MontoExento = _pago.MontoExento;
            pagoCabeceraToAdd.Fecha       = _pago.Fecha;
            Int32 iEstatus = 1;

            pagoCabeceraToAdd.Estatus = iEstatus;

            if (db.Connection.State != System.Data.ConnectionState.Open)
            {
                db.Connection.Open();
            }

            DbTransaction dbTransaction = db.Connection.BeginTransaction();

            try
            {
                // Guardar y confirmar.
                db.AddToPagoCabeceraSet(pagoCabeceraToAdd);
                db.SaveChanges();
                dbTransaction.Commit();
                /// Si la transaccion es exitosa enviamos true
                PagoCabecera _entidadToIDAdd = db.PagoCabeceraSet.ToList().LastOrDefault();
                Int32        _id             = _entidadToIDAdd.ID;
                _entidadToIDAdd.ID = _id;
                resul = true;
            }
            catch (Exception ex)
            {
                dbTransaction.Rollback();
                HandleException excepcion = new HandleException();
                String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                resul = true;
            }

            return(resul);
        }
예제 #4
0
        public Boolean Delete(EntidadNegocio.Entidades.Cliente _cliente)
        {
            Int32 id = _cliente.ID; Boolean resul = false;

            Dato.Modelo.Cliente clienteToDelete = db.ClienteSet.First(c => c.ID == id);

            clienteToDelete.ID        = _cliente.ID;
            clienteToDelete.Nombre    = _cliente.Nombre;
            clienteToDelete.Telefono  = _cliente.Telefono;
            clienteToDelete.Correo    = _cliente.Correo;
            clienteToDelete.Direccion = _cliente.Direccion;
            if (_cliente.Status == EntidadNegocio.Enumerados.EnumEstatus.Registro.Activo)
            {
                clienteToDelete.Estatus = 1;
            }
            else
            {
                clienteToDelete.Estatus = 0;
            }

            //valido cliente tiene alquiler
            if (db.AlquilerSet.FirstOrDefault(b => b.IDCliente == id) != null)
            {
                MessageBox.Show(String.Format("Esta intentando Borrar un cliente que tiene un Alquiler"), EntidadNegocio.Entidades.Mensajes.Titulo_Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (db.Connection.State != System.Data.ConnectionState.Open)
                {
                    db.Connection.Open();
                }

                DbTransaction dbTransaction = db.Connection.BeginTransaction();

                try
                {
                    // Delete
                    db.DeleteObject(clienteToDelete);
                    db.SaveChanges();
                    dbTransaction.Commit();
                    /// Si la transaccion es exitosa enviamos true
                    resul = true;
                }
                catch (Exception ex)
                {
                    dbTransaction.Rollback();
                    HandleException excepcion = new HandleException();
                    String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                    excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                    resul = false;
                }
            }

            return(resul);
        }
예제 #5
0
        public Boolean Edit(EntidadNegocio.Entidades.Cliente _cliente)
        {
            Int32 id = _cliente.ID; Boolean resul = false;

            Dato.Modelo.Cliente clienteToUpdate = db.ClienteSet.First(c => c.ID == id);

            clienteToUpdate.ID        = _cliente.ID;
            clienteToUpdate.Nombre    = _cliente.Nombre;
            clienteToUpdate.Telefono  = _cliente.Telefono;
            clienteToUpdate.Correo    = _cliente.Correo;
            clienteToUpdate.Direccion = _cliente.Direccion;
            if (_cliente.Status == EntidadNegocio.Enumerados.EnumEstatus.Registro.Activo)
            {
                clienteToUpdate.Estatus = 1;
            }
            else
            {
                clienteToUpdate.Estatus = 0;
            }

            if (db.Connection.State != System.Data.ConnectionState.Open)
            {
                db.Connection.Open();
            }

            DbTransaction dbTransaction = db.Connection.BeginTransaction();

            try
            {
                // Guardar y confirmar el cliente.
                db.SaveChanges();
                dbTransaction.Commit();
                /// Si la transaccion es exitosa enviamos true
                resul = true;
            }
            catch (Exception ex)
            {
                dbTransaction.Rollback();
                HandleException excepcion = new HandleException();
                String          msjLog    = "Error en " + ObtenerMetodoEnEjecucion(false).ToString() + ".\n" + excepcion.RegistrarExcepcion(ex, ObtenerMetodoEnEjecucion(false).ToString());
                excepcion.EscribirLogExcepcion(msjLog); String clientMessage = excepcion.HandleExceptionEx(ex); excepcion = null;
                resul = false;
            }

            return(resul);
        }
예제 #6
0
        public EntidadNegocio.Entidades.PagoCabecera Details(int id)
        {
            Dato.Modelo.PagoCabecera _pagoCabeceraDetail = new Dato.Modelo.PagoCabecera();
            _pagoCabeceraDetail = new Dato.Modelo.PagoCabecera();
            EntidadNegocio.Entidades.PagoCabecera pagoCabeceraDetail = new EntidadNegocio.Entidades.PagoCabecera();
            Dato.Modelo.Cliente cliente = db.ClienteSet.First(c => c.ID == id); Int32 iIDCliente = cliente.ID;
            Dato.Modelo.Cantidad_Alquileres_Por_Pagar_VW clienteAlq = dbVW.Cantidad_Alquileres_Por_Pagar_VW_Set.First(c => c.IDCliente == iIDCliente);
            List <Dato.Modelo.Alquiler> listAlquiler = db.AlquilerSet.Where(a => a.IDCliente == iIDCliente && a.Estatus == 1).ToList();
            Double _dMontoEstimado = 0; _dMontoEstimado = (from e in listAlquiler select e.PrecioEstimado).Sum().Value;

            Dato.Modelo.Descuento descuento = db.DescuentoSet.First(d => d.Codigo == "DEC1");
            Double   _dPorcentajeDescuento  = 0; _dPorcentajeDescuento = descuento.PorcentajeDescuento ?? 0;
            Double   _dDescuento            = _dPorcentajeDescuento * _dMontoEstimado;
            Double   _dMontoTotal           = _dMontoEstimado - _dDescuento;
            Int32    _iIDCliente            = iIDCliente;
            Int32    _idCabecera            = UltimoID();
            DateTime _dFecha = DateTime.Now;

            pagoCabeceraDetail.Fecha = _dFecha;
            if (clienteAlq.NumAlquiler >= 3 && clienteAlq.NumAlquiler <= 5)
            {
                pagoCabeceraDetail.MontoExento = _dMontoEstimado;
                pagoCabeceraDetail.Descuento   = _dDescuento;
                pagoCabeceraDetail.MontoTotal  = _dMontoTotal;
            }
            else
            {
                pagoCabeceraDetail.MontoExento = _dMontoEstimado;
                pagoCabeceraDetail.Descuento   = 0;
                pagoCabeceraDetail.MontoTotal  = _dMontoEstimado;
            }
            pagoCabeceraDetail.IDCliente             = _iIDCliente;
            pagoCabeceraDetail.Cliente               = new EntidadNegocio.Entidades.Cliente();
            pagoCabeceraDetail.Cliente.ID            = _iIDCliente;
            pagoCabeceraDetail.Cliente.Nombre        = cliente.Nombre;
            pagoCabeceraDetail.Cliente.Telefono      = cliente.Telefono;
            pagoCabeceraDetail.Cliente.Correo        = cliente.Correo;
            pagoCabeceraDetail.Cliente.Direccion     = cliente.Direccion;
            pagoCabeceraDetail.Cliente.NumAlquileres = clienteAlq.NumAlquiler ?? 0;
            return(pagoCabeceraDetail);
        }