protected void btnAsignar_Click(object sender, EventArgs e)
    {
        Entidades.EntidadesConosud dcAux = new Entidades.EntidadesConosud();

        long idUsuario = long.Parse(Request.QueryString["IdUsuario"].ToString());

        Entidades.SegUsuario CurrentUsuario = (from M in dcAux.SegUsuario
                                               where M.IdSegUsuario == idUsuario
                                               select M).First <Entidades.SegUsuario>();


        List <Entidades.SegUsuarioRol> rolesEliminar = (from M in dcAux.SegUsuarioRol
                                                        where M.SegUsuario.IdSegUsuario == idUsuario
                                                        select M).ToList <Entidades.SegUsuarioRol>();

        foreach (Entidades.SegUsuarioRol item in rolesEliminar)
        {
            dcAux.DeleteObject(item);
        }
        dcAux.SaveChanges();



        foreach (GridDataItem item in gvRoles.Items)
        {
            if ((item.FindControl("chkSeleccion") as CheckBox).Checked)
            {
                long idRol = long.Parse(gvRoles.Items[item.DataSetIndex].GetDataKeyValue("IdSegRol").ToString());

                Entidades.SegRol CurrentRol = (from M in dcAux.SegRol
                                               where M.IdSegRol == idRol
                                               select M).First <Entidades.SegRol>();


                Entidades.SegUsuarioRol segRol = new Entidades.SegUsuarioRol();
                segRol.SegRol     = CurrentRol;
                segRol.SegUsuario = CurrentUsuario;


                dcAux.AddObject("EntidadesConosud.SegUsuarioRol", segRol);
            }
        }

        dcAux.SaveChanges();
        ScriptManager.RegisterStartupScript(Page, typeof(Page), "ocultar", "CloseWindows();", true);
    }
    protected void btnCambiar_Click(object sender, EventArgs e)
    {
        if (this.txtConfClave.Text != this.txtNuevaClave.Text)
        {
            this.Label4.Text = "No coincide confirmacion de la clave nueva";
            this.txtConfClave.Focus();
            return;
        }

        EntidadesConosud dc    = new EntidadesConosud();
        long             idusu = Convert.ToInt64(this.Session["idusu"]);

        Entidades.SegUsuario usuario = (from u in dc.SegUsuario
                                        where u.IdSegUsuario == idusu &&
                                        u.Password == this.txtClave.Text
                                        select u).FirstOrDefault <Entidades.SegUsuario>();

        //ConosudDataContext dc = new ConosudDataContext();
        //long idusu = Convert.ToInt64(this.Session["idusu"]);
        //SegUsuario usuario = (from u in dc.SegUsuarios
        //                                   where u.IdSegUsuario == idusu && u.Password == this.txtClave.Text
        //                                   select u).First();

        if (usuario == null)
        {
            this.Label4.Text = "Clave Actual Incorrecta";
            this.txtConfClave.Focus();
        }
        else
        {
            usuario.Password = this.txtNuevaClave.Text;
            dc.SaveChanges();
            Response.Redirect("~/Default.aspx");
            this.Label4.Text = string.Empty;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (this.Session["idusu"] == null)
            {
                Response.Redirect("~/LoginNew.aspx");
            }
            else
            {
                Session.Timeout = 30;
            }


            if (!this.IsPostBack)
            {
                Session.Timeout = 30;

                this.lblNombreUsu.Text = Convert.ToString(this.Session["nombreusu"]);

                Entidades.EntidadesConosud dcAux = new Entidades.EntidadesConosud();
                long IdSegUsuario        = (long)this.Session["idusu"];
                Entidades.SegUsuario usu = (from us in dcAux.SegUsuario
                                            .Include("SegUsuarioRol.SegRol.SegRolMenu.SegMenu.Padre")
                                            where us.IdSegUsuario == IdSegUsuario
                                            select us).First <Entidades.SegUsuario>();

                List <Entidades.SegMenu> menues = new List <Entidades.SegMenu>();

                foreach (Entidades.SegUsuarioRol UsuRol in usu.SegUsuarioRol)
                {
                    foreach (Entidades.SegRolMenu confseg in UsuRol.SegRol.SegRolMenu)
                    {
                        if (menues.FindAll(d => d.IdSegMenu == confseg.SegMenu.IdSegMenu).Count == 0)
                        {
                            menues.Add(confseg.SegMenu);
                        }
                    }
                }

                menues = (from M in menues
                          orderby M.Posicion
                          select M).ToList <Entidades.SegMenu>();

                if (menues.Count > 0)
                {
                    DataTable dt = Helpers.LINQToDataTable <Entidades.SegMenu>(menues);

                    RadMenu1.DataFieldID          = "IdSegMenu";
                    RadMenu1.DataFieldParentID    = "IdPadre";
                    RadMenu1.DataTextField        = "Descripcion";
                    RadMenu1.DataNavigateUrlField = "Url";

                    DataRow drSalir = dt.NewRow();
                    drSalir["Url"]         = "LoginNew.aspx";
                    drSalir["IdPadre"]     = System.DBNull.Value;
                    drSalir["Descripcion"] = "Salir Sistema";
                    drSalir["IdSegMenu"]   = "10000";
                    dt.Rows.Add(drSalir);

                    RadMenu1.DataSource = dt;
                    RadMenu1.DataBind();
                }
                else
                {
                    Response.Redirect("LoginNew.aspx");
                }
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
    protected void gvItemHoja_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
        {
            TempItemsHoja hoja = (TempItemsHoja)e.Item.DataItem;

            long IdPlantillla = hoja.IdPlantilla;


            long[] rolesAsignados = (from R in Contexto.RolesPlanilla
                                     where R.Plantilla.IdPlantilla == IdPlantillla
                                     select R.SegRol.IdSegRol).Distinct <long>().ToArray <long>();


            Entidades.SegUsuario usuario = (Entidades.SegUsuario) this.Session["usuario"];

            if (!usuario.SegUsuarioRol.IsLoaded)
            {
                usuario.SegUsuarioRol.Load();
            }
            foreach (Entidades.SegUsuarioRol item in usuario.SegUsuarioRol)
            {
                if (!item.SegRolReference.IsLoaded)
                {
                    item.SegRolReference.Load();
                }
            }

            int PoseeRol = (from R in usuario.SegUsuarioRol
                            where rolesAsignados.Contains(R.SegRol.IdSegRol)
                            select R).Count();



            if (PoseeRol == 0)
            {
                (e.Item.FindControl("chkAprobo") as CheckBox).Enabled           = false;
                (e.Item.FindControl("imgEdit") as ImageButton).Visible          = false;
                (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;
            }

            if (hoja.AuditadoPor != null && hoja.AuditadoPor.Trim() != "" && hoja.AuditadoPor != usuario.Login)
            {
                (e.Item.FindControl("chkAprobo") as CheckBox).Visible           = false;
                (e.Item.FindControl("imagenAuditadoPor") as Image).Visible      = true;
                (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;
            }

            if (hoja.AuditadoPor != null && hoja.AuditadoPor.Trim() != "" && hoja.AuditadoPor == usuario.Login &&
                hoja.HojaFechaAprobacion != null)
            {
                (e.Item.FindControl("chkAprobo") as CheckBox).Visible           = false;
                (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;
            }

            if (hoja.AuditoriaTerminada.HasValue && hoja.AuditoriaTerminada.Value)
            {
                (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Checked = true;

                if (hoja.HojaFechaAprobacion.HasValue)
                {
                    (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;
                }
                else
                {
                    (e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = true;
                }
            }



            if (hoja.HojaComentario == null || hoja.HojaComentario.Trim() == "")
            {
                (e.Item.FindControl("imgcomentarioitem") as Image).Visible = false;
            }

            if (hoja.DocFechaEntrega != null)
            {
                (e.Item.FindControl("imgcomentariodoc") as Image).Visible = true;
            }
            else
            {
                (e.Item.FindControl("imgcomentariodoc") as Image).Visible = false;
            }



            TempComentarioGrales CurrentComentario = (from C in ComentariosGrales
                                                      where C.IdPlantilla == hoja.IdPlantilla
                                                      select C).FirstOrDefault <TempComentarioGrales>();


            if (CurrentComentario != null && CurrentComentario.Comentario != "")
            {
                (e.Item.FindControl("imgcomentariogral") as Image).Attributes.Add("coment", CurrentComentario.Comentario);
            }
            else
            {
                (e.Item.FindControl("imgcomentariogral") as Image).Visible = false;
            }


            /// Si el usuario es de una empresa, entonces oculto los comentarios generales
            if (!usuario.EmpresaReference.IsLoaded)
            {
                usuario.EmpresaReference.Load();
            }
            if (usuario.Empresa != null)
            {
                gvItemHoja.Columns.FindByUniqueName("imgComentarioGral").Visible = false;
                gvItemHoja.Columns.FindByUniqueName("chkAproboColumn").Visible   = false;
            }
        }

        if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))
        {
            TempItemsHoja    hoja     = (TempItemsHoja)e.Item.DataItem;
            GridEditableItem edititem = (GridEditableItem)e.Item;
            TextBox          txtbx    = (TextBox)edititem.FindControl("txtComentarioGralEdit");

            TempComentarioGrales CurrentComentario = (from C in ComentariosGrales
                                                      where C.IdPlantilla == hoja.IdPlantilla
                                                      select C).FirstOrDefault <TempComentarioGrales>();

            if (CurrentComentario != null)
            {
                txtbx.Text = CurrentComentario.Comentario;
            }
            else
            {
                txtbx.Text = "";
            }



            ((System.Web.UI.WebControls.Table)(((Telerik.Web.UI.GridEditFormItem)(edititem)).FormColumns[0])).Rows[0].Visible       = false;
            ((System.Web.UI.WebControls.Table)(((Telerik.Web.UI.GridEditFormItem)(edititem)).FormColumns[0])).Rows[1].Cells[0].Text = "Comentario Item";
            ((System.Web.UI.WebControls.Table)(((Telerik.Web.UI.GridEditFormItem)(edititem)).FormColumns[0])).Rows[2].Cells[0].Text = "Comentario Gral";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        gvItemHoja.NeedDataSource += new GridNeedDataSourceEventHandler(gvItemHoja_NeedDataSource);

        if (!IsPostBack)
        {
            (Page.Master as DefaultMasterPage).OcultarEncabezado();
            this.Contexto = new EntidadesConosud();

            CargarDatosSession();

            gvItemHoja.DataSource = ItemsHojasDeRuta;
            gvItemHoja.DataBind();


            _periodoActual  = CurrentTempCabecera.Periodo;
            _CodigoContrato = CurrentTempCabecera.Codigo;


            /// Deteccion de si es o no la ultima hoja de ruta
            if (!CurrentTempCabecera.ContratoEmpresas.CabeceraHojasDeRuta.IsLoaded)
            {
                CurrentTempCabecera.ContratoEmpresas.CabeceraHojasDeRuta.Load();
            }
            var cabeceras = from C in CurrentTempCabecera.ContratoEmpresas.CabeceraHojasDeRuta
                            orderby C.Periodo
                            select C;

            if (cabeceras.Last().Periodo == CurrentTempCabecera.Periodo
                ||
                cabeceras.Last().Periodo == CurrentTempCabecera.Periodo.AddMonths(1))
            {
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "showAviso", "ShowAvisoUltimoCertificado();", true);
            }
            else
            {
                tdUltimoCertificado.Visible = false;
            }



            gvLegajos.ItemDataBound += new GridItemEventHandler(gvLegajos_ItemDataBound);
            gvLegajos.DataSource     = InfoSueldos.ToList();
            gvLegajos.DataBind();


            if (InfoSueldos.Count() > 0)
            {
                _tieneLegajo = true;
            }


            lblContrato.Text = CurrentTempCabecera.Servicio;
            lblPeriodo.Text  = string.Format("{0:MM/yyyy}", CurrentTempCabecera.Periodo);

            if (!CurrentTempCabecera.ContratoEmpresas.EmpresaReference.IsLoaded)
            {
                CurrentTempCabecera.ContratoEmpresas.EmpresaReference.Load();
            }
            if (CurrentTempCabecera.EsContratista.Value)
            {
                lblContratista.Text    = CurrentTempCabecera.ContratoEmpresas.Empresa.RazonSocial;
                lblSubContratista.Text = "-";
            }
            else
            {
                lblContratista.Text    = CurrentTempCabecera.ContratoEmpresas.ConstratistaParaSubConstratista;
                lblSubContratista.Text = CurrentTempCabecera.ContratoEmpresas.Empresa.RazonSocial;
            }



            if (CurrentTempCabecera.objCabecera.Aprobada.Contains("No"))
            {
                lblEstado.Text = CurrentTempCabecera.objCabecera.Aprobada.ToUpper();
                lblEstado.Style.Add(HtmlTextWriterStyle.Color, "Red");
            }
            else
            {
                lblEstado.Text = CurrentTempCabecera.objCabecera.Aprobada.ToUpper();
                lblEstado.Style.Add(HtmlTextWriterStyle.Color, "Blue");
                lblUsuarioAprobador.Text = "(" + CurrentTempCabecera.LoginName + ")";
            }

            lblTitulo.Text     = "Gestión Contrato Nro: " + CurrentTempCabecera.Codigo;
            txtEstimacion.Text = CurrentTempCabecera.Estimacion;

            lblFechaIncial.Text = CurrentTempCabecera.FechaInicio.ToShortDateString();

            if (!CurrentTempCabecera.Prorroga.HasValue)
            {
                lblFechaFinal.Text = CurrentTempCabecera.FechaVencimiento.ToShortDateString();
            }
            else
            {
                lblFechaFinal.Text = CurrentTempCabecera.Prorroga.Value.ToShortDateString();
            }

            /// Verificacion de acceso por Rol Aprobador
            string DescRol      = Helpers.RolesEspeciales.Aprobador.ToString();
            string DescRolAdmin = Helpers.RolesEspeciales.Administrador.ToString();

            Entidades.SegUsuario usuario = (Entidades.SegUsuario) this.Session["usuario"];


            int RolesAprobador = (from U in Contexto.SegUsuario
                                  from UR in U.SegUsuarioRol
                                  where U.IdSegUsuario == usuario.IdSegUsuario &&
                                  UR.SegRol.Descripcion == DescRol
                                  select UR).Count();


            int RolesAdministrador = (from U in Contexto.SegUsuario
                                      from UR in U.SegUsuarioRol
                                      where U.IdSegUsuario == usuario.IdSegUsuario &&
                                      UR.SegRol.Descripcion == DescRolAdmin
                                      select UR).Count();


            if (RolesAprobador > 0)
            {
                trAprobacion.Visible = true;
                trEstimacion.Visible = true;
                trReporte.Visible    = true;

                if (RolesAdministrador > 0)
                {
                    trDesaprobacion.Visible = true;
                }
                else
                {
                    trDesaprobacion.Visible = false;
                }
            }
            else
            {
                trAprobacion.Visible    = false;
                trEstimacion.Visible    = false;
                trDesaprobacion.Visible = false;
            }

            if (CurrentTempCabecera.Aprobada == "Aprobada")
            {
                trReporte.Visible = false;
            }
        }
    }
Beispiel #6
0
    public object getItemsHojaRuta(long IdCab)
    {
        using (EntidadesConosud dc = new EntidadesConosud())
        {
            var items = (from h in dc.HojasDeRuta
                         where h.CabeceraHojasDeRuta.IdCabeceraHojasDeRuta == IdCab
                         orderby h.Plantilla.Codigo
                         select new
            {
                AuditadoPor = h.AuditadoPor,
                DocFechaEntrega = h.DocFechaEntrega,
                HojaComentario = h.HojaComentario,
                IdCabecera = IdCab,
                IdHoja = h.IdHojaDeRuta,
                IdPlantilla = h.Plantilla.IdPlantilla,
                Descripcion = h.Plantilla.Descripcion,
                DocComentario = h.DocComentario,
                HojaFechaAprobacion = h.HojaFechaAprobacion,
                AuditoriaTerminada = h.AuditoriaTerminada,
                IdContratoEmpresa = h.CabeceraHojasDeRuta.IdContratoEmpresa
            }).ToList();

            List <long> idContratosEmpresa = items.Select(w => w.IdContratoEmpresa).ToList();
            var         ComentariosGrales  = (from c in dc.ComentariosGral
                                              where idContratosEmpresa.Contains(c.ContratoEmpresas.IdContratoEmpresas)
                                              select new
            {
                IdContratoEmpresa = c.ContratoEmpresa,
                Comentario = c.Comentario,
                IdPlantilla = c.Plantilla.Value,
                IdComentarioGel = c.IdComentarioGral
            }).ToList();


            #region  Consultas de seguridad de la pagina
            Entidades.SegUsuario usuario         = (Entidades.SegUsuario)HttpContext.Current.Session["usuario"];
            List <long>          idsPlantilla    = items.Select(w => w.IdPlantilla).ToList();
            List <SegPagina>     seguridadPagina = new List <SegPagina>();



            foreach (var item in items)
            {
                SegPagina sg = new SegPagina();
                sg.idPlantilla = item.IdPlantilla;

                long[] rolesAsignados = (from R in dc.RolesPlanilla
                                         where R.IdPlanilla == item.IdPlantilla
                                         select R.SegRol.IdSegRol).Distinct <long>().ToArray <long>();

                int PoseeRol = (from R in usuario.SegUsuarioRol
                                where rolesAsignados.Contains(R.SegRol.IdSegRol)
                                select R).Count();

                if (PoseeRol == 0)
                {
                    //(e.Item.FindControl("chkAprobo") as CheckBox).Enabled = false;
                    //(e.Item.FindControl("imgEdit") as ImageButton).Visible = false;
                    //(e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;

                    sg.permitirAprobarItem       = false;
                    sg.permitirEditarItem        = false;
                    sg.permitirTerminarAuditoria = false;
                }
                else
                {
                    sg.permitirAprobarItem       = true;
                    sg.permitirEditarItem        = true;
                    sg.permitirTerminarAuditoria = true;
                }

                seguridadPagina.Add(sg);

                if (item.AuditadoPor != null && item.AuditadoPor.Trim() != "" && item.AuditadoPor != usuario.Login)
                {
                    //(e.Item.FindControl("chkAprobo") as CheckBox).Visible = false;
                    //(e.Item.FindControl("imagenAuditadoPor") as System.Web.UI.WebControls.Image).Visible = true;
                    //(e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;

                    sg.permitirAprobarItem       = false;
                    sg.permitirVerAuditadoPor    = true;
                    sg.permitirTerminarAuditoria = false;
                }
                else
                {
                    sg.permitirAprobarItem       = true;
                    sg.permitirVerAuditadoPor    = false;
                    sg.permitirTerminarAuditoria = true;
                }


                if (item.AuditadoPor != null && item.AuditadoPor.Trim() != "" && item.AuditadoPor == usuario.Login && item.HojaFechaAprobacion == null)
                {
                    sg.permitirAprobarItem       = true;
                    sg.permitirTerminarAuditoria = true;
                }
                else
                {
                    sg.permitirAprobarItem       = false;
                    sg.permitirTerminarAuditoria = false;
                }


                if (item.AuditoriaTerminada.HasValue && item.AuditoriaTerminada.Value)
                {
                    // resuelto en la interface
                    //(e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Checked = true;


                    if (item.HojaFechaAprobacion.HasValue)
                    {
                        //(e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = false;
                        sg.permitirTerminarAuditoria = false;
                    }
                    else
                    {
                        //(e.Item.FindControl("chkTerminoAuditoria") as CheckBox).Enabled = true;
                        sg.permitirTerminarAuditoria = true;
                    }
                }



                ////TempComentarioGrales CurrentComentario = (from C in ComentariosGrales
                ////                                          where C.IdPlantilla == hoja.IdPlantilla
                ////                                          select C).FirstOrDefault<TempComentarioGrales>();


                ////if (CurrentComentario != null && CurrentComentario.Comentario != "")
                ////    (e.Item.FindControl("imgcomentariogral") as System.Web.UI.WebControls.Image).Attributes.Add("coment", CurrentComentario.Comentario);
                ////else
                ////    (e.Item.FindControl("imgcomentariogral") as System.Web.UI.WebControls.Image).Visible = false;


                ///// Si el usuario es de una empresa, entonces oculto los comentarios generales
                //if (!usuario.EmpresaReference.IsLoaded) { usuario.EmpresaReference.Load(); }
                //if (usuario.Empresa != null)
                //{
                //    gvItemHoja.Columns.FindByUniqueName("imgComentarioGral").Visible = false;
                //    gvItemHoja.Columns.FindByUniqueName("chkAproboColumn").Visible = false;

                //}
            }


            #endregion



            return((from h in items
                    join s in seguridadPagina on h.IdPlantilla equals s.idPlantilla
                    select new {
                h.AuditadoPor,
                h.DocFechaEntrega,
                h.HojaComentario,
                h.IdCabecera,
                h.IdHoja,
                h.IdPlantilla,
                h.Descripcion,
                h.DocComentario,
                HojaFechaAprobacion = h.HojaFechaAprobacion != null ? h.HojaFechaAprobacion.Value.ToShortDateString() : "",
                h.AuditoriaTerminada,
                ComentarioGral = ComentariosGrales.Any(w => w.IdContratoEmpresa == h.IdContratoEmpresa && w.IdPlantilla == h.IdPlantilla)  ? ComentariosGrales.Where(w => w.IdContratoEmpresa == h.IdContratoEmpresa && w.IdPlantilla == h.IdPlantilla).FirstOrDefault().Comentario:"",
                s.permitirAprobarItem,
                s.permitirEditarItem,
                s.permitirTerminarAuditoria,
                s.permitirVerAuditadoPor
            }).ToList());

            //string.Format("{0:dd/MM/yyyy}", h.HojaFechaAprobacion),
        }
    }