protected void rptComuna_OnItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "Editar")
        {
            HiddenField hdnIdComuna = new HiddenField();
            hdnIdComuna = (HiddenField)e.Item.FindControl("hdnIdComuna");

            YouCom.DTO.ComunaDTO myComunaDTO = new YouCom.DTO.ComunaDTO();
            myComunaDTO = YouCom.bll.ComunaBLL.detalleComuna(decimal.Parse(hdnIdComuna.Value));

            this.hdnIdComuna.Value  = myComunaDTO.IdComuna.ToString();
            txtNombre.Text          = myComunaDTO.NombreComuna;
            ddlCiudad.SelectedIndex = ddlCiudad.Items.IndexOf(ddlCiudad.Items.FindByValue(myComunaDTO.TheCiudadDTO.IdCiudad.ToString()));

            btnGrabar.Visible = false;
            btnEditar.Visible = true;
        }
        if (e.CommandName == "Eliminar")
        {
            HiddenField hdnIdCiudad = new HiddenField();
            hdnIdCiudad = (HiddenField)e.Item.FindControl("hdnIdCiudad");

            ComunaDTO theComunaDTO = new ComunaDTO();
            theComunaDTO.IdComuna            = decimal.Parse(hdnIdComuna.Value);
            theComunaDTO.UsuarioModificacion = myUsuario.Rut;

            bool validacionIntegridad = YouCom.bll.ComunaBLL.ValidaEliminacionComuna(theComunaDTO);
            if (validacionIntegridad)
            {
                string script = "alert(' No es posible eliminar un Comuna con registro asociado.');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                return;
            }
            else
            {
                bool respuesta = YouCom.bll.ComunaBLL.Delete(theComunaDTO);
                if (respuesta)
                {
                    cargarCiudad();
                    if (!Page.ClientScript.IsClientScriptBlockRegistered("SET"))
                    {
                        string script = "alert('Comuna Eliminada correctamente.');";
                        Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                    }
                }
                else
                {
                }
            }
        }
    }
    protected void btnGrabar_Click(object sender, EventArgs e)
    {
        UserControl  wucCondominio = (UserControl)Page.Master.FindControl("ContentPlaceHolder1").FindControl("wucCondominio1");
        DropDownList ddlCondominio = (DropDownList)wucCondominio.FindControl("ddlCondominio");
        DropDownList ddlComunidad  = (DropDownList)wucCondominio.FindControl("ddlComunidad");

        List <EmpresaServicioDTO> empresa_servicio = new List <EmpresaServicioDTO>();

        empresa_servicio = (Session["empresa_servicio"] as List <EmpresaServicioDTO>);

        EmpresaServicioDTO theEmpresaServicioDTO = new EmpresaServicioDTO();

        theEmpresaServicioDTO.RazonSocialEmpresaServicio = this.txtRazonSocialEmpresaServicio.Text.ToUpper();
        theEmpresaServicioDTO.RutEmpresaServicio         = this.txtRutEmpresaServicio.Text.ToUpper();
        theEmpresaServicioDTO.DireccionEmpresaServicio   = this.txtEmpresaServicioDireccion.Text.ToUpper();
        theEmpresaServicioDTO.TelefonoEmpresaServicio    = this.txtEmpresaServicioTelefono.Text;
        theEmpresaServicioDTO.CelularEmpresaServicio     = this.txtEmpresaServicioTelefono.Text;
        theEmpresaServicioDTO.UrlEmpresaServicio         = this.txtEmpresaServicioURL.Text.ToUpper();
        theEmpresaServicioDTO.EmailEmpresaServicio       = this.txtEmail.Text;

        YouCom.DTO.Servicio.ServiciosDTO myServiciosDTO = new YouCom.DTO.Servicio.ServiciosDTO();
        myServiciosDTO.IdServicio             = decimal.Parse(ddlServicio.SelectedValue);
        theEmpresaServicioDTO.TheServiciosDTO = myServiciosDTO;

        YouCom.DTO.GiroDTO myGiroDTO = new YouCom.DTO.GiroDTO();
        myGiroDTO.IdGiro = decimal.Parse(ddlGiro.SelectedValue);
        theEmpresaServicioDTO.TheGiroDTO = myGiroDTO;

        YouCom.DTO.Seguridad.CondominioDTO myCondominioDTO = new YouCom.DTO.Seguridad.CondominioDTO();
        myCondominioDTO.IdCondominio           = decimal.Parse(ddlCondominio.SelectedValue);
        theEmpresaServicioDTO.TheCondominioDTO = myCondominioDTO;

        YouCom.DTO.Seguridad.ComunidadDTO myComunidadDTO = new YouCom.DTO.Seguridad.ComunidadDTO();
        myComunidadDTO.IdComunidad            = decimal.Parse(ddlComunidad.SelectedValue);
        theEmpresaServicioDTO.TheComunidadDTO = myComunidadDTO;

        YouCom.DTO.ComunaDTO myComunaDTO = new YouCom.DTO.ComunaDTO();
        myComunaDTO.IdComuna = decimal.Parse(ddlComuna.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO = myComunaDTO;

        YouCom.DTO.CiudadDTO myCiudadDTO = new YouCom.DTO.CiudadDTO();
        myCiudadDTO.IdCiudad = decimal.Parse(ddlCiudad.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO = myCiudadDTO;

        YouCom.DTO.RegionDTO myRegionDTO = new YouCom.DTO.RegionDTO();
        myRegionDTO.IdRegion = decimal.Parse(ddlRegion.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO = myRegionDTO;

        YouCom.DTO.PaisDTO myPaisDTO = new YouCom.DTO.PaisDTO();
        myPaisDTO.IdPais = decimal.Parse(ddlPais.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO.ThePaisDTO = myPaisDTO;

        theEmpresaServicioDTO.UsuarioIngreso = myUsuario.Rut;

        if (this.FileImagenEmpresaServicio.HasFile)
        {
            if (System.IO.Path.GetExtension(FileImagenEmpresaServicio.PostedFile.FileName) == ".swf")
            {
                theEmpresaServicioDTO.LogoEmpresaServicio = this.ProcessOtherFile(FileImagenEmpresaServicio, null, YouCom.Service.Generales.General.GetPropiedad("UploadsPathEmpresaServicioPub"));
            }
            else
            {
                theEmpresaServicioDTO.LogoEmpresaServicio = YouCom.Service.Imagenes.Imagen.ProcessFileResize(FileImagenEmpresaServicio, YouCom.Service.Generales.General.GetPropiedad("UploadsPathEmpresaServicioPub"), 198, 118, Page);
            }
        }

        empresa_servicio = empresa_servicio.Where(x => x.RazonSocialEmpresaServicio == theEmpresaServicioDTO.RazonSocialEmpresaServicio).ToList();
        if (empresa_servicio.Any())
        {
            foreach (var item in empresa_servicio)
            {
                if (item.Estado == "2")
                {
                    string script = "alert('Empresa Servicio existe pero fue eliminado para activarlo dirigase a Papelera.');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                    return;
                }
                else
                {
                    string script = "alert('Empresa Servicio ya Existe .');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                    return;
                }
            }
        }

        bool respuesta = YouCom.bll.EmpresaServicioBLL.Insert(theEmpresaServicioDTO);

        if (respuesta)
        {
            this.txtRutEmpresaServicio.Text         = string.Empty;
            this.txtRazonSocialEmpresaServicio.Text = string.Empty;
            this.txtEmpresaServicioDireccion.Text   = string.Empty;
            this.txtEmpresaServicioTelefono.Text    = string.Empty;
            this.txtEmpresaServicioCelular.Text     = string.Empty;
            this.txtEmpresaServicioURL.Text         = string.Empty;
            this.txtEmail.Text = string.Empty;

            string script = "alert('Empresa Servicio ingresado correctamente.');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
            cargarEmpresaServicio();
        }
        else
        {
        }
    }
    protected void btnEditar_Click(object sender, EventArgs e)
    {
        UserControl  wucCondominio = (UserControl)Page.Master.FindControl("ContentPlaceHolder1").FindControl("wucCondominio1");
        DropDownList ddlCondominio = (DropDownList)wucCondominio.FindControl("ddlCondominio");
        DropDownList ddlComunidad  = (DropDownList)wucCondominio.FindControl("ddlComunidad");

        btnEditar.Visible = false;
        btnGrabar.Visible = true;

        EmpresaServicioDTO theEmpresaServicioDTO = new EmpresaServicioDTO();

        theEmpresaServicioDTO.IdEmpresaServicio          = decimal.Parse(this.hdnIdEmpresaServicio.Value);
        theEmpresaServicioDTO.RazonSocialEmpresaServicio = this.txtRazonSocialEmpresaServicio.Text.ToUpper();
        theEmpresaServicioDTO.RutEmpresaServicio         = this.txtRutEmpresaServicio.Text.ToUpper();
        theEmpresaServicioDTO.DireccionEmpresaServicio   = this.txtEmpresaServicioDireccion.Text.ToUpper();
        theEmpresaServicioDTO.TelefonoEmpresaServicio    = this.txtEmpresaServicioTelefono.Text;
        theEmpresaServicioDTO.CelularEmpresaServicio     = this.txtEmpresaServicioCelular.Text;
        theEmpresaServicioDTO.UrlEmpresaServicio         = this.txtEmpresaServicioURL.Text.ToUpper();
        theEmpresaServicioDTO.EmailEmpresaServicio       = this.txtEmail.Text;

        YouCom.DTO.Servicio.ServiciosDTO myServiciosDTO = new YouCom.DTO.Servicio.ServiciosDTO();
        myServiciosDTO.IdServicio             = decimal.Parse(ddlServicio.SelectedValue);
        theEmpresaServicioDTO.TheServiciosDTO = myServiciosDTO;

        YouCom.DTO.GiroDTO myGiroDTO = new YouCom.DTO.GiroDTO();
        myGiroDTO.IdGiro = decimal.Parse(ddlGiro.SelectedValue);
        theEmpresaServicioDTO.TheGiroDTO = myGiroDTO;

        YouCom.DTO.Seguridad.CondominioDTO myCondominioDTO = new YouCom.DTO.Seguridad.CondominioDTO();
        myCondominioDTO.IdCondominio           = decimal.Parse(ddlCondominio.SelectedValue);
        theEmpresaServicioDTO.TheCondominioDTO = myCondominioDTO;

        YouCom.DTO.Seguridad.ComunidadDTO myComunidadDTO = new YouCom.DTO.Seguridad.ComunidadDTO();
        myComunidadDTO.IdComunidad            = decimal.Parse(ddlComunidad.SelectedValue);
        theEmpresaServicioDTO.TheComunidadDTO = myComunidadDTO;

        YouCom.DTO.ComunaDTO myComunaDTO = new YouCom.DTO.ComunaDTO();
        myComunaDTO.IdComuna = decimal.Parse(ddlComuna.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO = myComunaDTO;

        YouCom.DTO.CiudadDTO myCiudadDTO = new YouCom.DTO.CiudadDTO();
        myCiudadDTO.IdCiudad = decimal.Parse(ddlCiudad.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO = myCiudadDTO;

        YouCom.DTO.RegionDTO myRegionDTO = new YouCom.DTO.RegionDTO();
        myRegionDTO.IdRegion = decimal.Parse(ddlRegion.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO = myRegionDTO;

        YouCom.DTO.PaisDTO myPaisDTO = new YouCom.DTO.PaisDTO();
        myPaisDTO.IdPais = decimal.Parse(ddlPais.SelectedValue);
        theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO.ThePaisDTO = myPaisDTO;

        theEmpresaServicioDTO.UsuarioModificacion = myUsuario.Rut;

        if (this.FileImagenEmpresaServicio.HasFile)
        {
            theEmpresaServicioDTO.LogoEmpresaServicio = YouCom.Service.Imagenes.Imagen.ProcessFileResize(FileImagenEmpresaServicio, YouCom.Service.Generales.General.GetPropiedad("UploadsPathEmpresaServicioPub"), 198, 118, Page);
        }
        else
        {
            EmpresaServicioDTO myEmpresaServicioDTO = new EmpresaServicioDTO();
            myEmpresaServicioDTO = YouCom.bll.EmpresaServicioBLL.detalleEmpresaServicio(decimal.Parse(hdnIdEmpresaServicio.Value));

            theEmpresaServicioDTO.LogoEmpresaServicio = myEmpresaServicioDTO.LogoEmpresaServicio;
        }


        bool respuesta = YouCom.bll.EmpresaServicioBLL.Update(theEmpresaServicioDTO);

        if (respuesta)
        {
            cargarEmpresaServicio();
            this.txtRutEmpresaServicio.Text         = string.Empty;
            this.txtRazonSocialEmpresaServicio.Text = string.Empty;
            this.txtEmpresaServicioDireccion.Text   = string.Empty;
            this.txtEmpresaServicioTelefono.Text    = string.Empty;
            this.txtEmpresaServicioCelular.Text     = string.Empty;
            this.txtEmpresaServicioURL.Text         = string.Empty;
            this.txtEmail.Text = string.Empty;

            if (!Page.ClientScript.IsClientScriptBlockRegistered("SET"))
            {
                string script = "alert('Empresa Servicio editado correctamente.');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
            }
        }
        else
        {
        }
    }
    protected bool setEnviaServicio()
    {
        bool retorno = false;
        bool salida  = false;

        ServiciosDTO theServiciosDTO = new ServiciosDTO();

        theServiciosDTO.NombreServicio      = this.txtServicioNombre.Text.ToUpper();
        theServiciosDTO.DescripcionServicio = this.txtServicioDescripcion.Text.ToUpper();

        theServiciosDTO.TheCondominioDTO = myUsuario.TheCondominioSeleccionDTO;
        theServiciosDTO.TheComunidadDTO  = myUsuario.TheComunidadSeleccionDTO;

        YouCom.DTO.CategoriaDTO myCategoriaDTO = new YouCom.DTO.CategoriaDTO();
        myCategoriaDTO.IdCategoria      = decimal.Parse(ddlCategoria.SelectedValue);
        theServiciosDTO.TheCategoriaDTO = myCategoriaDTO;

        theServiciosDTO.FechaInicio  = DateTime.ParseExact(this.FechaInicio.Text + " " + DateTime.Now.ToString("HH:mm"), "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture);
        theServiciosDTO.FechaTermino = DateTime.ParseExact(this.FechaTermino.Text + " " + DateTime.Now.ToString("HH:mm"), "dd/MM/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture);

        theServiciosDTO.UsuarioIngreso = myUsuario.Rut;

        retorno = YouCom.bll.ServiciosBLL.Insert(theServiciosDTO);

        if (retorno)
        {
            YouCom.DTO.Servicio.EmpresaServicioDTO theEmpresaServicioDTO = new YouCom.DTO.Servicio.EmpresaServicioDTO();
            theEmpresaServicioDTO.RutEmpresaServicio         = this.txtRutEmpresa.Text.ToUpper();
            theEmpresaServicioDTO.RazonSocialEmpresaServicio = this.txtNombreEmpresa.Text.ToUpper();
            theEmpresaServicioDTO.TelefonoEmpresaServicio    = this.txtTelefono.Text;
            theEmpresaServicioDTO.UrlEmpresaServicio         = this.txtURL.Text;
            theEmpresaServicioDTO.CelularEmpresaServicio     = this.txtCelular.Text;
            theEmpresaServicioDTO.DireccionEmpresaServicio   = this.txtDireccion.Text;
            theEmpresaServicioDTO.EmailEmpresaServicio       = this.txtEmail.Text;

            YouCom.DTO.ComunaDTO myComunaDTO = new YouCom.DTO.ComunaDTO();
            myComunaDTO.IdComuna = decimal.Parse(ddlComuna.SelectedValue);
            theEmpresaServicioDTO.TheComunaDTO = myComunaDTO;

            YouCom.DTO.CiudadDTO myCiudadDTO = new YouCom.DTO.CiudadDTO();
            myCiudadDTO.IdCiudad = decimal.Parse(ddlCiudad.SelectedValue);
            theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO = myCiudadDTO;

            YouCom.DTO.RegionDTO myRegionDTO = new YouCom.DTO.RegionDTO();
            myRegionDTO.IdRegion = decimal.Parse(ddlRegion.SelectedValue);
            theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO = myRegionDTO;

            YouCom.DTO.PaisDTO myPaisDTO = new YouCom.DTO.PaisDTO();
            myPaisDTO.IdPais = decimal.Parse(ddlPais.SelectedValue);
            theEmpresaServicioDTO.TheComunaDTO.TheCiudadDTO.TheRegionDTO.ThePaisDTO = myPaisDTO;

            theEmpresaServicioDTO.TheCondominioDTO = myUsuario.TheCondominioSeleccionDTO;
            theEmpresaServicioDTO.TheComunidadDTO  = myUsuario.TheComunidadSeleccionDTO;

            theEmpresaServicioDTO.TheServiciosDTO = theServiciosDTO;

            if (this.FileImagenServicio.HasFile)
            {
                theEmpresaServicioDTO.LogoEmpresaServicio = this.ProcessOtherFile(FileImagenServicio, null, YouCom.Service.Generales.General.GetPropiedad("UploadsPathServiciosPub"));
            }

            salida = YouCom.bll.EmpresaServicioBLL.Insert(theEmpresaServicioDTO);

            salida = true;
        }

        return(salida);
    }