Example #1
0
 public void CopyAndNew(object sender, EventArgs e)
 {
     View.PostEditors();
     OnSaving();
     if (!View.ValidateData())
     {
         return;
     }
     if (NewEntityId == Guid.Empty)
     {
         _dynamicDataServiceContext = new DynamicDataServiceContext();
         EntityId = NewEntityId;
         var newEntity  = GetEntity();
         var metaEntity = MetadataProvider.Instance.EntiyMetadata.Where(c => c.PhysicalName == EntityName).FirstOrDefault();
         foreach (var att in metaEntity.Attributes)
         {
             if (att.IsCopyEnabled ?? false)
             {
                 object targetValue = GetDynamicMember(DynamicEntity, att.TableColumnName);
                 newEntity.GetType().GetProperty(att.TableColumnName).SetValue(newEntity, targetValue, null);
             }
         }
         DynamicEntity = new SysBits.DynamicProxies.DynamicProxy(newEntity);
         WorkingMode   = EntityDetailWorkingMode.Add;
         RefreshEntityId(newEntity);
         NewEntityId = EntityId;
         Type entityType      = newEntity.GetType();
         Type listGenericType = typeof(List <>);
         Type listType        = listGenericType.MakeGenericType(entityType);
         var  list            = (IList)Activator.CreateInstance(listType);
         list.Add(newEntity);
         BindData(list);
     }
     OnEntitySaved(new EventArgs <bool>(true));
 }