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;

        CategoriaDTO theCategoriaDTO = new CategoriaDTO();

        theCategoriaDTO.IdCategoria          = decimal.Parse(this.hdnIdCategoria.Value);
        theCategoriaDTO.NombreCategoria      = this.txtNombre.Text;
        theCategoriaDTO.DescripcionCategoria = this.txtDescripcion.Text;

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

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

        YouCom.DTO.TipoCategoriaDTO myTipoCategoriaDTO = new YouCom.DTO.TipoCategoriaDTO();
        myTipoCategoriaDTO.IdTipoCategoria  = decimal.Parse(this.ddlTipo.SelectedValue);
        theCategoriaDTO.TheTipoCategoriaDTO = myTipoCategoriaDTO;

        theCategoriaDTO.UsuarioModificacion = myUsuario.Rut;

        bool respuesta = YouCom.bll.CategoriaBLL.Update(theCategoriaDTO);

        if (respuesta)
        {
            cargarCategoria();
            this.txtNombre.Text      = string.Empty;
            this.txtDescripcion.Text = string.Empty;
            this.ddlTipo.ClearSelection();

            if (!Page.ClientScript.IsClientScriptBlockRegistered("SET"))
            {
                string script = "alert('Categoria editada correctamente.');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
            }
        }
        else
        {
        }
    }
示例#2
0
    protected void rptTipoCategoria_OnItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        UserControl  wucCondominio = (UserControl)Page.Master.FindControl("ContentPlaceHolder1").FindControl("wucCondominio1");
        DropDownList ddlCondominio = (DropDownList)wucCondominio.FindControl("ddlCondominio");
        DropDownList ddlComunidad  = (DropDownList)wucCondominio.FindControl("ddlComunidad");

        if (e.CommandName == "Editar")
        {
            HiddenField hdnIdTipoCategoria = new HiddenField();
            hdnIdTipoCategoria = (HiddenField)e.Item.FindControl("hdnIdTipoCategoria");

            YouCom.DTO.TipoCategoriaDTO theTipoCategoriaDTO = new YouCom.DTO.TipoCategoriaDTO();
            theTipoCategoriaDTO = YouCom.bll.TipoCategoriaBLL.detalleTipoCategoria(decimal.Parse(hdnIdTipoCategoria.Value));

            txtNombre.Text = theTipoCategoriaDTO.NombreTipoCategoria;
            this.hdnIdTipoCategoria.Value = theTipoCategoriaDTO.IdTipoCategoria.ToString();

            ddlCondominio.SelectedIndex = ddlCondominio.Items.IndexOf(ddlCondominio.Items.FindByValue(theTipoCategoriaDTO.TheCondominioDTO.IdCondominio.ToString()));

            ddlComunidad.DataSource     = YouCom.bll.ComunidadBLL.getListadoComunidadByCondominio(decimal.Parse(ddlCondominio.SelectedValue));
            ddlComunidad.DataTextField  = "NombreComunidad";
            ddlComunidad.DataValueField = "IdComunidad";
            ddlComunidad.DataBind();
            ddlComunidad.Items.Insert(0, new ListItem("Seleccione Comunidad", string.Empty));

            ddlComunidad.SelectedIndex = ddlComunidad.Items.IndexOf(ddlComunidad.Items.FindByValue(theTipoCategoriaDTO.TheComunidadDTO.IdComunidad.ToString()));

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

            TipoCategoriaDTO theTipoCategoriaDTO = new TipoCategoriaDTO();
            theTipoCategoriaDTO.IdTipoCategoria     = decimal.Parse(hdnIdTipoCategoria.Value);
            theTipoCategoriaDTO.UsuarioModificacion = myUsuario.Rut;

            bool validacionIntegridad = YouCom.bll.TipoCategoriaBLL.ValidaEliminacionTipoCategoria(theTipoCategoriaDTO);
            if (validacionIntegridad)
            {
                string script = "alert(' No es posible eliminar un Tipo Categoria con aviso asociado.');";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                return;
            }
            else
            {
                bool respuesta = YouCom.bll.TipoCategoriaBLL.Delete(theTipoCategoriaDTO);
                if (respuesta)
                {
                    cargarTipoCategoria();
                    if (!Page.ClientScript.IsClientScriptBlockRegistered("SET"))
                    {
                        string script = "alert('Tipo Categoria 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 <CategoriaDTO> categoria = new List <CategoriaDTO>();

        categoria = (Session["categoria"] as List <CategoriaDTO>);

        CategoriaDTO theCategoriaDTO = new CategoriaDTO();

        theCategoriaDTO.NombreCategoria      = this.txtNombre.Text.ToUpper();
        theCategoriaDTO.DescripcionCategoria = this.txtDescripcion.Text.ToUpper();

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

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

        YouCom.DTO.TipoCategoriaDTO myTipoCategoriaDTO = new YouCom.DTO.TipoCategoriaDTO();
        myTipoCategoriaDTO.IdTipoCategoria  = decimal.Parse(this.ddlTipo.SelectedValue);
        theCategoriaDTO.TheTipoCategoriaDTO = myTipoCategoriaDTO;

        theCategoriaDTO.UsuarioIngreso = myUsuario.Rut;

        categoria = categoria.Where(x => x.NombreCategoria == theCategoriaDTO.NombreCategoria).ToList();
        if (categoria.Any())
        {
            foreach (var item in categoria)
            {
                if (item.Estado == "2")
                {
                    string script = "alert('Categoria Existe pero Fue Eliminado Para Activarlo dirigase a Papelera.');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                    return;
                }
                else
                {
                    string script = "alert('Categoria ya Existe .');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
                    return;
                }
            }
        }


        bool respuesta = YouCom.bll.CategoriaBLL.Insert(theCategoriaDTO);

        if (respuesta)
        {
            this.txtNombre.Text      = string.Empty;
            this.txtDescripcion.Text = string.Empty;
            this.ddlTipo.ClearSelection();
            string script = "alert('Categoria Ingresada correctamente.');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "SET", script, true);
            cargarCategoria();
        }
        else
        {
        }
    }