Example #1
0
 private void BtnAgregar_Click(object sender, EventArgs e)
 {
     using (var context = new ChoppinEntities())
     {
         var contextTabla = context.GetType().GetProperty(TablaNombre);
         var data         = contextTabla.GetValue(context);
         var typeData     = data.GetType().GenericTypeArguments[0];
         var registro     = Activator.CreateInstance(GridTabla.Rows[0].DataBoundItem.GetType());
         var registros    = ((IList <object>)GridTabla.DataSource);
         registros.Add(registro);
         GridTabla.DataSource = registros;
         GridTabla.Refresh();
     }
 }
Example #2
0
        private void GridTabla_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            var registro = GridTabla.Rows[e.RowIndex].DataBoundItem;

            using (var context = new ChoppinEntities())
            {
                var contextTabla = context.GetType().GetProperty(TablaNombre);
                var data         = contextTabla.GetValue(context);
                var methodAdd    = data.GetType().GetMethod("Add");
                methodAdd.Invoke(data, new [] { registro });
                context.Entry(registro).State = EntityState.Modified;
                var count = context.SaveChanges();
                lblEstado.Text = $"Actualizado {DateTime.Now} - {count}";
            }
        }
Example #3
0
 private void RefrescarTabla()
 {
     try {
         using (var context = new ChoppinEntities())
         {
             var contextTabla = context.GetType().GetProperty(TablaNombre);
             var data         = contextTabla.GetValue(context);
             var datos        = ((IEnumerable <object>)data).ToList();
             var registros    = datos;
             GridTabla.AutoGenerateColumns = true;
             GridTabla.DataSource          = registros;
             GridTabla.Refresh();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }