protected void dgEstado_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
 {
     if (e.NewSelectedIndex > -1)
     {
         estadoUsuario ob = eBLL.GetById(Convert.ToInt32(dgEstado.DataKeys[e.NewSelectedIndex].Value));
         FillText(ob);
     }
 }
        //METODOS

        //Salvar
        static public void Save(this estadoUsuarioBLL a, estadoUsuario obj)
        {
            var x = ctx.estadoUsuario.Find(obj.id);

            if (x != null)
            {
                ctx.Entry(x).CurrentValues.SetValues(obj);
            }
            else
            {
                ctx.estadoUsuario.Add(obj);
            }
            ctx.SaveChanges();
        }
 //Buscar y cargar estado
 private void FillText(estadoUsuario ob = null, bool initial = false)
 {
     if (ob != null)
     {
         txtId.Text          = ob.id.ToString();
         txtNombre.Text      = ob.nombre;
         txtDescripcion.Text = ob.descripcion;;
     }
     else
     {
         txtId.Text          = "";
         txtNombre.Text      = "";
         txtDescripcion.Text = "";
         if (initial)
         {
             txtId.Text = "";
         }
     }
 }
 //Botón Buscar
 protected void btnBuscar_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtId.Text.Trim() != "")
         {
             estadoUsuario obj = new estadoUsuario();
             obj = eBLL.GetById(Convert.ToInt32(txtId.Text));
             FillText(obj);
         }
         else
         {
             FillText();
         }
     }
     catch (Exception ex)
     {
         msgBox.InnerText = "Error: " + ex.Message;
     }
 }
 //Boton Guardar
 protected void btnGuardar_Click(object sender, EventArgs e)
 {
     try
     {
         estadoUsuario obj = new estadoUsuario();
         obj.nombre      = txtNombre.Text;
         obj.descripcion = txtDescripcion.Text;
         if (txtId.Text.Trim() != "")
         {
             obj.id = Convert.ToInt32(txtId.Text);
         }
         eBLL.Save(obj);
         FillGrid();
         msgBox.InnerText = "";
         FillText(null, true);
     }
     catch (Exception ex)
     {
         msgBox.InnerText = "Error: " + ex.Message;
     }
 }
Exemple #6
0
	void OnEnable()
	{
		estadosUsuario = estadoUsuario.enJuego;
	}