public Boolean Eliminar(clsImpuesto Imp)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.Impuesto where q.IdImpuesto == Imp.IdImpuesto select q).First();

                    ent.DeleteObject(x);

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public Boolean Eliminar(clsCuentaBancaria  Cuenta)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.CuentaBancaria where q.Serie == Cuenta.Serie select q).First();

                    ent.DeleteObject(x);

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public Boolean Eliminar(clsEmpresaServicio  Empresa)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.EmpresaServicio  where q.IdEmpresaServicio ==( Empresa .IdEmpresaServicio)  select q).First();

                    ent.DeleteObject(x);

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public Boolean Eliminar(clsMedioPago Medio)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.MedioPago where q.IdMedioPago == Medio.IdMedioPago select q).First();

                    ent.DeleteObject(x);

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        private Boolean GuardarImpuestos(List<clsImpuestoCuenta> a)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    int aux = a.Count;
                    List<clsImpuestoCuenta> Impuestito = a;
                    for (int i = 0; i < aux; i++)
                    {
                        ImpCta = new ImpuestoCuenta()
                        {
                            IdEmpresa = Impuestito[i]._IdEmpresa,
                            NumCuentaPorPagar = Impuestito[i]._NumCuentaPorPagar,
                            Valor = Impuestito[i]._Valor,
                            IdImpuesto = Impuestito[i]._IdImpuesto,
                        };
                        ent.AddToImpuestoCuenta(ImpCta);
                        ent.SaveChanges();
                    }
                    //ent.SaveChanges();
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        private Boolean GuardarDetCtaPorPagar(List<clsCuentaPorPagarDetalle> a)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    int aux = a.Count;
                    List<clsCuentaPorPagarDetalle> Detalle = a;
                    for (int i = 0; i < aux; i++)
                    {
                        int NumDetCtaxPag = getNumDetCtaxPag();
                        DeuDet = new DeudaDet()
                        {
                            IdEmpresa = Detalle[i]._IdEmpresa,
                            NumCuentaPorPagar = Detalle[i]._NumCuentaPorPagar,
                            NumDetalleDeuda = NumDetCtaxPag,
                            ValorLetra = Detalle[i]._ValorLetra,
                            FechaVencimiento = Detalle[i]._FechaVencimiento,
                            Estado = Detalle[i]._Estado,
                        };
                        ent.AddToDeudaDet(DeuDet);
                        ent.SaveChanges();
                    }
                    //ent.SaveChanges();
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
 public void Eliminar(clsEmpresaServicio Empresa)
 {
     using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
     {
         var x = (from q in ent.EmpresaServicio where q.IdEmpresaServicio == (Empresa._IdEmpresaServicio) select q).First();
         ent.DeleteObject(x);
         ent.SaveChanges();
     }
 }
        public Boolean Eliminar(clsOrdenPagoDet OrdenDet)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.OrdenPagoDet where q.NumLinea == OrdenDet.NumLinea select q).First();

                    ent.DeleteObject(x);

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public Boolean GuardarDetOrdenPago(List<clsOrdenPagoDet> a)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    int aux = a.Count;
                    List<clsOrdenPagoDet> Detalle = a;
                    for (int i = 0; i < aux; i++)
                    {
                        int NumDetOrden = getNumDetOrdenPago();
                        OrdenPagoDeta = new OrdenPagoDet()
                        {
                            NumLinea = Detalle[i].NumLinea,
                            NumCuentaPorPagar = Detalle[i].NumCuentaPorPagar,
                            NumDetalleDeuda = NumDetOrden,
                            SaldoDeuda = Detalle[i].SaldoDeuda,
                            NumeroPagosRealizar = Detalle[i].NumeroPagosRealizar,
                            NumOrdenCab = Detalle[i].NumOrdenPagoCab,
                            TotalPagar = Detalle[i].TotalPagar,
                            IdEmpresa = Detalle[i].IdEmpresa,
                            AutorizarPago = Detalle[i].AutorizarPago,
                        };
                        ent.AddToOrdenPagoDet(OrdenPagoDeta);
                        ent.SaveChanges();
                    }
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        public void ModificarSaldo(int numero, decimal Saldo)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.CuentaBancaria where q.idCuentaBancaria == numero select q).First();

                x.Saldo = Saldo;

                ent.SaveChanges();

            }
        }
        public void Modificar(clsPago Pago)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.PagoCab where q.NumPago == Pago.NumPago select q).First();
                x.NumPago = Pago.NumPago;
                x.FechaIngreso = Pago.FechaIngreso;
                x.NumOrdenPago = Pago.NumOrdenPago;

                x.TotalPagar = Pago.TotalPagar;
                x.IdUsuario = Pago.IdUsuario;
                x.IdEmpresa = Pago.IdEmpresa;
                x.Estado = Pago.IdEstado;
                x.NumComprobante = Pago.NumComprobante;
                ent.SaveChanges();

            }
        }
        public Boolean EliminarEstado(clsPago Pag)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    var x = (from q in ent.PagoCab where q.NumPago == Pag.NumPago select q).First();

                    x.Estado = Pag.IdEstado;

                    ent.SaveChanges();

                }
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void Modificar(clsImpuesto Imp)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.Impuesto where q.IdImpuesto == Imp.IdImpuesto select q).First();

                x.Descripcion = Imp.Descripcion;
                x.FechaRegistro = Imp.FechaRegistro;
                x.Estado = Imp.Estado;
                x.Porcentaje = Convert.ToDecimal( Imp.Porcentaje);
                x.IdEmpresa = Imp.IdEmpresa;
                x.IdUsuario = Imp.IdUsuario;
                ent.SaveChanges();

            }
        }
        public Boolean Guardar(clsEmpresaServicio Empresa)
        {
            try
            {

                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    EmpresaServicio servicio = new EmpresaServicio()
                    {
                        IdEmpresaServicio = Empresa.IdEmpresaServicio,
                        FechaRegistro = Empresa.fechaRegistro,
                        RazonSocial = Empresa.RazonSocial,
                        Direccion = Empresa.Direccion,
                        Email = Empresa.email,
                        Webpage = Empresa.webpage,
                        Estado = Empresa.Estado,
                        IdTipoPersona = Empresa.IdTipoPersona,
                        IdEmpresa = Empresa.IdEmpresa,
                        IdUsuario = Empresa.IdUsuario,

                    };
                    ent.AddToEmpresaServicio(servicio);
                    ent.SaveChanges();
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;

            }
        }
        public void Modificar(clsEmpresaServicio Empresa)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                  {
                var x = (from q in ent.EmpresaServicio where q.IdEmpresaServicio ==(Empresa.IdEmpresaServicio) select q).First();
                x.IdEmpresaServicio = Empresa.IdEmpresaServicio;

                x.RazonSocial = Empresa.RazonSocial;
                x.Direccion = Empresa.Direccion;
                x.Email = Empresa.email;
                x.Webpage = Empresa.webpage;
                x.Estado = Empresa.Estado;
                x.IdTipoPersona = Empresa.IdTipoPersona;
                x.IdEmpresa= Empresa.IdEmpresa;
                x.IdUsuario = Empresa.IdUsuario;
                ent.SaveChanges();

                     }
        }
        public Boolean Guardar(clsFrecuenciaPago Frecuencia)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    FrecuenciaPago pago = new FrecuenciaPago()
                    {
                        IdFrecuenciaPago = id,
                        Descripcion = Frecuencia.Descripcion,
                        FechaActual = DateTime.Today,//Frecuencia.FechaActual,
                        Estado = Frecuencia.Estado,
                        IdUsuario =Frecuencia.IdUsuario,
                        IdEmpresa =Frecuencia.IdEmpresa,
                            };
                    ent.AddToFrecuenciaPago(pago);
                    ent.SaveChanges();
                }

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void Modificar(clsFrecuenciaPago Frecuencia)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.FrecuenciaPago where q.IdFrecuenciaPago == Frecuencia.IdFrecuenciaPago select q).First();

                x.Descripcion = Frecuencia.Descripcion;
                x.FechaActual = Frecuencia.FechaActual;
               x.Estado = Frecuencia.Estado;
                x.IdEmpresa = Frecuencia.IdEmpresa;
                x.IdUsuario = Frecuencia.IdUsuario;
                ent.SaveChanges();

            }
        }
        public Boolean Guardar(clsEmpresaServicio EmpresaServiciocls)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    EmpSer = new EmpresaServicio()
                    {
                        IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                        IdTipoPersona = EmpresaServiciocls._TipoPersona,
                        FechaRegistro = DateTime.Today,
                        RazonSocial = EmpresaServiciocls._RazonSocial,
                        Estado = EmpresaServiciocls._Estado,
                        Direccion = EmpresaServiciocls._Direccion,
                        Email = EmpresaServiciocls._Email,
                        Webpage = EmpresaServiciocls._Website,
                        IdEmpresa = 1,
                        IdUsuario = 11,
                    };
                    ent.AddToEmpresaServicio(EmpSer);
                    ent.SaveChanges();

                    aux = EmpresaServiciocls._DetalleTelefono.Count();
                    for (int i = 0; i <= aux; i++)//Guardando los teléfonos, tanto en la tabla Telefono como en TelefonoEmpresaServicio
                    {
                        valTel = getIdSiguienteTelefono();
                        Tel = new Telefono()
                        {
                            IdTelefono = valTel,
                            IdTipoTelefono = EmpresaServiciocls._DetalleTelefono[i].getTipoTelefono(),
                            Numero = EmpresaServiciocls._DetalleTelefono[i].getNumTelefono(),
                        };
                        ent.AddToTelefono(Tel);
                        ent.SaveChanges();

                        TelEmpServ = new TelefonoEmpresaServicio()
                        {
                            IdEmpresa = EmpresaServiciocls._IdEmpresa,
                            IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                            IdTelefono = valTel,
                        };
                        ent.AddToTelefonoEmpresaServicio(TelEmpServ);
                        ent.SaveChanges();
                    }
                    //=============================================================================
                    aux = EmpresaServiciocls._CuentaBancaria.Count();
                    for (int i = 0; i <= aux; i++)//Guardando las cuentas bancarias
                    {
                        CtaBanc = new CuentaBancaria2()
                        {
                            IdEmpresaServicio = EmpresaServiciocls._IdEmpresaServicio,
                            IdEmpresa = EmpresaServiciocls._IdEmpresa,
                            Serie = getIdSiguienteCtaBanc(),
                            IdBanco = EmpresaServiciocls._CuentaBancaria[i].getIdBanco(),
                            TipoCuenta = EmpresaServiciocls._CuentaBancaria[i].getTipoCuenta(),
                            NroCta = EmpresaServiciocls._CuentaBancaria[i].getNroCuenta(),
                        };
                        ent.AddToCuentaBancaria2(CtaBanc);
                        ent.SaveChanges();
                    }
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        public Boolean GuardarNomina(clsPagoDos Pago)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    PagoCab otro = new PagoCab()
                    {
                        NumPago = id,
                        FechaIngreso = Pago.FechaIngreso,
                        TotalPagar = Pago.TotalPagar,
                        IdUsuario = Pago.IdUsuario,
                        IdEmpresa = Pago.IdEmpresa,
                        Estado = Pago.IdEstado,
                        NumComprobante = Pago.NumComprobante,
                    };
                    ent.AddToPagoCab(otro);
                    ent.SaveChanges();
                }
                return true;
            }
            catch (Exception ex)
            {
                return false;

            }
        }
        public Boolean Guardar(clsImpuesto Imp)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    Impuesto impu = new Impuesto()
                    {
                        IdImpuesto = id,
                        Descripcion = Imp.Descripcion,
                        FechaRegistro = DateTime.Today, // Medio.FechaRegistro,

                        Porcentaje=Convert.ToDecimal (Imp.Porcentaje),
                        Estado = Imp.Estado,
                        IdEmpresa = Imp.IdEmpresa,
                        IdUsuario = Imp.IdUsuario,

                    };
                    ent.AddToImpuesto(impu);
                    ent.SaveChanges();
                }

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public void ModificarEstadoOrden(int numero)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.OrdenPagoCab where q.NumOrdenPago == numero select q).First();

                x.Estado = 2;

                ent.SaveChanges();

            }
        }
        public Boolean GuardarDetalleNomina(clsPagoDetalleDos Det)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    PagoDet pago = new PagoDet()
                    {
                        NumLinea = id,
                        IdMedioPago = Det.IdMedioPago,
                        Monto = Det.Monto,
                        NumeroCuenta = Det.NumeroCuenta,
                        IdEmpresa = Det.IdEmpresa,
                        IdBanco = Det.IdBanco,
                        NumComprobante = Det.NumComprobante,
                        //  NumComision =Det.NumComision,
                        NumNominaCab = Det.NumNominaCab,
                        NumPago = Det.NumPago,

                    };
                    ent.AddToPagoDet(pago);
                    ent.SaveChanges();
                }

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public Boolean Guardar(clsOrdenPagoDet OrdenDet)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    OrdenPagoDet pago = new OrdenPagoDet()
                    {
                        NumLinea = id,
                        NumCuentaPorPagar = OrdenDet.NumCuentaPorPagar,
                        NumDetalleDeuda = OrdenDet.NumDetalleDeuda,
                        SaldoDeuda = OrdenDet.SaldoDeuda,
                        NumeroPagosRealizar = OrdenDet.NumeroPagosRealizar,
                        NumOrdenCab = OrdenDet.NumOrdenPagoCab,
                        TotalPagar = OrdenDet.TotalPagar,
                        IdEmpresa = OrdenDet.IdEmpresa,

                    };
                    ent.AddToOrdenPagoDet(pago);
                    ent.SaveChanges();
                }

                return true;

            }

            catch (Exception)
            {
                return false;
            }
        }
        public void Modificar(clsPagoDetalle Det)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.PagoDet where q.NumPago == Det.NumPago select q).First();

                x.NumLinea = Det.NumLinea;
                x.IdMedioPago = Det.IdMedioPago;
                x.Monto = Det.Monto;
                x.IdEmpresa = Det.IdEmpresa;
                x.IdBanco = Det.IdBanco;
                x.NumComprobante = Det.NumComprobante;
                // x.NumComision = Det.NumComision;
                // x.NumNominaCab = Det.NumNominaCab;
                x.NumPago = Det.NumPago;

                ent.SaveChanges();

            }
        }
        public void Modificar(clsOrdenPagoDet OrdenDet)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.OrdenPagoDet where q.NumOrdenCab == OrdenDet.NumOrdenPagoCab select q).First();

                x.NumLinea = OrdenDet.NumLinea;
                x.NumCuentaPorPagar = OrdenDet.NumCuentaPorPagar;
                x.NumDetalleDeuda = OrdenDet.NumDetalleDeuda;
                x.SaldoDeuda = OrdenDet.SaldoDeuda;
                x.NumeroPagosRealizar = OrdenDet.NumeroPagosRealizar;
                x.NumOrdenCab = OrdenDet.NumOrdenPagoCab;
                x.TotalPagar = OrdenDet.TotalPagar;
                x.IdEmpresa = OrdenDet.IdEmpresa;
                ent.SaveChanges();
            }
        }
 public void Eliminar(clsCuentaPorPagar CuentaPorPagar)
 {
     using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
     {
         var x = (from q in ent.CuentaPorPagar where q.NumCuentaPorPagar == (CuentaPorPagar._NumCuentaPorPagar) select q).First();
         ent.DeleteObject(x);
         ent.SaveChanges();
     }
 }
        public void Modificar(clsMedioPago Medio)
        {
            using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
            {
                var x = (from q in ent.MedioPago where q.IdMedioPago == Medio.IdMedioPago select q).First();

                x.Descripcion = Medio.Descripcion;
                x.fechaRegistro = Medio.FechaRegistro;
                x.Estado =Medio.Estado;
                x.IdEmpresa = Medio.IdEmpresa;
                x.IdUsuario = Medio.IdUsuario;
                ent.SaveChanges();

            }
        }
        public Boolean Guardar2(clsCuentaPorPagar CuentaPorPagar)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    CtaXPag = new CuentaPorPagar()
                    {
                        NumCuentaPorPagar = CuentaPorPagar._NumCuentaPorPagar,
                        FechaIngreso = CuentaPorPagar._FechaIngreso,
                        NumeroFactura = CuentaPorPagar._Factura,
                        FechaTransaccion = CuentaPorPagar._FechaTransaccion,
                        IdEmpresaServicio = CuentaPorPagar._IdEmpresaServicio,
                        Motivo = CuentaPorPagar._Motivo,
                        Detalle = CuentaPorPagar._Detalle,
                        Subtotal = CuentaPorPagar._Subtotal,
                        Total = CuentaPorPagar._Total,
                        FormaPago = CuentaPorPagar._FormaPago,
                        ValorEntrada = CuentaPorPagar._ValorEntrada,
                        NumeroLetra = CuentaPorPagar._NumeroLetra,
                        IdFrecuencia = CuentaPorPagar._IdFrecuencia,
                        ValorLetra = CuentaPorPagar._ValorLetra,
                        SaldoDeuda = CuentaPorPagar._SaldoDeuda,
                        IdUsuario = CuentaPorPagar._IdUsuario,
                        IdEmpresa = CuentaPorPagar._IdEmpresa,
                    };
                    ent.AddToCuentaPorPagar(CtaXPag);
                    ent.SaveChanges();

                    GuardarDetCtaPorPagar(CuentaPorPagar._DetCredito);

                    GuardarImpuestos(CuentaPorPagar._ImpuestoCuenta);
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }
        public Boolean Guardar(clsMedioPago Medio)
        {
            try
            {
                int id = getIdSiguiente();
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {

                    MedioPago pago = new MedioPago()
                    {
                        IdMedioPago =id,
                        Descripcion = Medio.Descripcion,
                        fechaRegistro = DateTime.Today, // Medio.FechaRegistro,
                        Estado = Medio.Estado,
                       IdEmpresa =Medio.IdEmpresa,
                        IdUsuario = Medio.IdUsuario,

                    };
                    ent.AddToMedioPago(pago);
                    ent.SaveChanges();
                }

                return true;

            }
            catch (Exception ex)
            {
                return false;
            }
        }
        public Boolean Guardar8(clsCuentaPorPagar CuentaPorPagar)
        {
            try
            {
                using (CuentasPorPagarEntities ent = new CuentasPorPagarEntities())
                {
                    CtaXPag = new CuentaPorPagar()
                    {
                        NumCuentaPorPagar = CuentaPorPagar._NumCuentaPorPagar,
                        NumIngresoEgreso = CuentaPorPagar._NumIngresoEgreso,
                        FechaIngreso = CuentaPorPagar._FechaIngreso,
                        NumeroFactura = CuentaPorPagar._Factura,
                        FechaTransaccion = CuentaPorPagar._FechaTransaccion,
                        IdProveedor = CuentaPorPagar._IdProveedor,
                        Motivo = CuentaPorPagar._Motivo,
                        Detalle = CuentaPorPagar._Detalle,
                        Subtotal = CuentaPorPagar._Subtotal,
                        Total = CuentaPorPagar._Total,
                        FormaPago = CuentaPorPagar._FormaPago,
                        IdUsuario = CuentaPorPagar._IdUsuario,
                        IdEmpresa = CuentaPorPagar._IdEmpresa,
                    };
                    ent.AddToCuentaPorPagar(CtaXPag);
                    ent.SaveChanges();

                    GuardarImpuestos(CuentaPorPagar._ImpuestoCuenta);
                }

                return true;

            }
            catch (Exception)
            {
                return false;
            }
        }