Exemplo n.º 1
0
    protected void EntityDataSourceItems_Updating(object sender, EntityDataSourceChangingEventArgs e)
    {
        Entidades.Plantilla ItemPlantilla = (Entidades.Plantilla)e.Entity;

        long id = Convert.ToInt64(ViewState["IdRol"]);

        IEnumerable <KeyValuePair <string, object> > entityKeyValues =
            new KeyValuePair <string, object>[] {
            new KeyValuePair <string, object>("IdSegRol", id)
        };

        System.Data.EntityKey key  = new System.Data.EntityKey("EntidadesConosud.SegRol", entityKeyValues);
        Entidades.SegRol      _rol = (Entidades.SegRol)e.Context.GetObjectByKey(key);
        ItemPlantilla.RolesPlanilla.Load();

        if (ItemPlantilla.RolesPlanilla.Count == 0)
        {
            Entidades.RolesPlanilla rolP = new Entidades.RolesPlanilla();
            rolP.Plantilla = ItemPlantilla;
            rolP.SegRol    = _rol;
            e.Context.AddObject("EntidadesConosud.RolesPlanilla", rolP);
        }
        else
        {
            ItemPlantilla.RolesPlanilla.First().SegRol = _rol;
        }

        e.Context.SaveChanges();
    }
Exemplo n.º 2
0
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
 {
     if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
     {
         Entidades.Plantilla hoja = EntityDataSourceExtensions.GetItemObject <Entidades.Plantilla>(e.Item.DataItem);
         hoja.RolesPlanilla.Load();
         if (hoja.RolesPlanilla.Count > 0)
         {
             hoja.RolesPlanilla.First().SegRolReference.Load();
             (e.Item.FindControl("lblRol") as Label).Text = hoja.RolesPlanilla.First().SegRol.Descripcion;
         }
     }
     else if (e.Item.ItemType == GridItemType.EditFormItem)
     {
         Entidades.Plantilla hoja = EntityDataSourceExtensions.GetItemObject <Entidades.Plantilla>(e.Item.DataItem);
         if (hoja != null)
         {
             hoja.RolesPlanilla.Load();
             if (hoja.RolesPlanilla.Count > 0)
             {
                 hoja.RolesPlanilla.First().SegRolReference.Load();
                 if (e.Item.FindControl("cboRoles") != null)
                 {
                     (e.Item.FindControl("cboRoles") as RadComboBox).SelectedValue = hoja.RolesPlanilla.First().SegRol.IdSegRol.ToString();
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
        {
            Entidades.Plantilla hoja = EntityDataSourceExtensions.GetItemObject <Entidades.Plantilla>(e.Item.DataItem);
            if (hoja != null)
            {
                if (hoja.RolesPlanilla.Count > 0)
                {
                    (e.Item.FindControl("lblRol") as Label).Text    = hoja.RolesPlanilla.First().SegRol.Descripcion;
                    (e.Item.FindControl("lblRiesgo") as Label).Text = hoja.Riesgo;
                    (e.Item.FindControl("lblGrado") as Label).Text  = string.Format("Grado {0}", hoja.Grado);
                }
            }
        }
        else if (e.Item.ItemType == GridItemType.EditFormItem)
        {
            Entidades.Plantilla hoja = EntityDataSourceExtensions.GetItemObject <Entidades.Plantilla>(e.Item.DataItem);

            if (hoja != null)
            {
                if (hoja.RolesPlanilla.Count > 0)
                {
                    if (e.Item.FindControl("cboRoles") != null)
                    {
                        (e.Item.FindControl("cboRoles") as RadComboBox).SelectedValue = hoja.RolesPlanilla.First().SegRol.IdSegRol.ToString();

                        Dictionary <string, string> riesgos = new Dictionary <string, string>();
                        riesgos.Add("ALTO", "ALTO");
                        riesgos.Add("MEDIO", "MEDIO");
                        riesgos.Add("BAJO", "BAJO");

                        (e.Item.FindControl("cboRiesgos") as RadComboBox).DataSource = riesgos;
                        (e.Item.FindControl("cboRiesgos") as RadComboBox).DataBind();
                        (e.Item.FindControl("cboRiesgos") as RadComboBox).SelectedValue = hoja.Riesgo;


                        Dictionary <string, string> grados = new Dictionary <string, string>();
                        grados.Add("1", "Grado 1");
                        grados.Add("2", "Grado 2");
                        grados.Add("3", "Grado 3");
                        grados.Add("4", "Grado 4");
                        grados.Add("5", "Grado 5");


                        (e.Item.FindControl("cboGrados") as RadComboBox).DataSource = grados;
                        (e.Item.FindControl("cboGrados") as RadComboBox).DataBind();
                        (e.Item.FindControl("cboGrados") as RadComboBox).SelectedValue = hoja.Grado.ToString();
                    }
                }
            }
        }
    }