public List<clsEmpresaServicio> consulta()
        {
            try
            {
                List<clsEmpresaServicio> lista = new List<clsEmpresaServicio>();
                CuentasPorPagarEntities ent = new CuentasPorPagarEntities();
                var con = from w in ent.EmpresaServicio select w;
                foreach (var item in con)
                {
                    clsEmpresaServicio clas = new clsEmpresaServicio();
                    clas.IdEmpresaServicio = Convert.ToString(item.IdEmpresaServicio);
                    clas.fechaRegistro = item.FechaRegistro;
                    clas.RazonSocial = item.RazonSocial;
                    clas.Direccion = item.Direccion;
                    clas.email = item.Email;
                    clas.webpage = item.Webpage;
                    clas.Estado = item.Estado;
                    clas.IdTipoPersona = item.IdTipoPersona;
                    clas.IdEmpresa = item.IdEmpresa;
                    clas.IdUsuario = item.IdUsuario;
                    lista.Add(clas);
                }

                return lista;

            }
            catch (Exception)
            {
                return null;

            }
        }
        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;

            }
        }
        //=========================================================================================================================
        //============================================CONSULTA EMPRESA DE SERVICIOS================================================
        //=========================================================================================================================
        public List<clsEmpresaServicio> ConsultaEmpresaServicio()
        {
            try
            {
                List<clsEmpresaServicio> EmpresaServicio = new List<clsEmpresaServicio>();
                List<clsDetalleTelefonoCXP> DetalleTelefono = new List<clsDetalleTelefonoCXP>();
                List<clsCtaBancaria2> CuentaBancaria = new List<clsCtaBancaria2>();
                CuentasPorPagarEntities ent = new CuentasPorPagarEntities();
                var lst = from q in ent.EmpresaServicio select q;
                var lst2 = from i in ent.Telefono select i;
                var lst3 = from j in ent.CuentaBancaria2 select j;

                foreach (var item in lst)
                {
                    clsEmpresaServicio cls = new clsEmpresaServicio();
                    cls._IdEmpresaServicio = item.IdEmpresaServicio;
                    cls._FechaRegistro = item.FechaRegistro;
                    cls._RazonSocial = item.RazonSocial;
                    cls._TipoPersona = item.IdTipoPersona;
                    cls._Estado = item.Estado;
                    cls._Direccion = item.Direccion;
                    cls._Email = item.Email;
                    cls._Website = item.Webpage;
                    foreach (var item2 in lst2)
                    {
                        clsDetalleTelefonoCXP det = new clsDetalleTelefonoCXP();
                        det._TipoTelefono = item2.IdTipoTelefono;
                        det._numTelefono = item2.Numero;
                        DetalleTelefono.Add(det);
                    }
                    cls._DetalleTelefono = DetalleTelefono;
                    foreach (var item3 in lst3)
                    {
                        clsCtaBancaria2 det = new clsCtaBancaria2();
                        det._IdBanco = item3.IdBanco;
                        det._TipoCuenta = item3.TipoCuenta;
                        det._NroCuenta = item3.NroCta;
                        CuentaBancaria.Add(det);
                    }
                    cls._CuentaBancaria = CuentaBancaria;
                    EmpresaServicio.Add(cls);
                }
                return EmpresaServicio;
            }
            catch (Exception)
            {
                return null;
            }
        }
        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;
            }
        }
 private void btnBuscarProveedor_Click(object sender, EventArgs e)
 {
     clsEmpresaServicio clas = new clsEmpresaServicio();
     frmConsultas fre = new frmConsultas();
     fre.ShowDialog();
     clas = fre.GetSelection();
     txtRucProveedor.Text = clas._IdEmpresaServicio;
     txtNombreProveedor.Text = clas._RazonSocial;
 }
 private void btnConsulta_Click(object sender, EventArgs e)
 {
     clsEmpresaServicio empserv = new clsEmpresaServicio();
     frmConsultas Consulta = new frmConsultas();
     Consulta.ShowDialog();
 }
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            frmConsultaEmpresaServicio Ser = new frmConsultaEmpresaServicio();
            Ser.ShowDialog();
            clas = Ser.Es;
            clsCuentaBancaria cli = new clsCuentaBancaria();

            Set();
        }
        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(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 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();
     }
 }