public static void AddRange(this CollectionSourceBase collectionSourceBase, IEnumerable objects) { foreach (var o in objects) { collectionSourceBase.Add(o); } }
void CreateInterfaceInfo(Type type, CollectionSourceBase collectionSourceBase) { var info = (IInterfaceInfo)ObjectSpace.CreateObject(View.ObjectTypeInfo.Type); info.Name = type.FullName; info.Assembly = new AssemblyName(type.Assembly.FullName + "").Name; collectionSourceBase.Add(info); }
private void AddNewObjectToCollectionSource(CollectionSourceBase currentCollectionSource, object newObject, XPObjectSpace objectSpace) { var newObjectTypeInfo = XafTypesInfo.Instance.FindTypeInfo(newObject.GetType()); if ((currentCollectionSource == null) || !currentCollectionSource.ObjectTypeInfo.IsAssignableFrom(newObjectTypeInfo)) { return; } if (objectSpace == currentCollectionSource.ObjectSpace) { currentCollectionSource.Add(newObject); } else { var propertyCollectionSource = (currentCollectionSource as PropertyCollectionSource); if ((propertyCollectionSource != null) && (propertyCollectionSource.MasterObject != null)) { Object collectionOwner; IMemberInfo memberInfo = null; if (propertyCollectionSource.MemberInfo.GetPath().Count > 1) { collectionOwner = ImportUtils.GetCollectionOwner(propertyCollectionSource.MasterObject, propertyCollectionSource.MemberInfo); if (collectionOwner != null) { memberInfo = XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()) .FindMember(propertyCollectionSource.MemberInfo.LastMember.Name); } } else { collectionOwner = propertyCollectionSource.MasterObject; memberInfo = propertyCollectionSource.MemberInfo; } if ((collectionOwner != null) && XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()).IsPersistent) { var collectionSource = _application.CreatePropertyCollectionSource(objectSpace, null, objectSpace.GetObject(collectionOwner), memberInfo, "", CollectionSourceMode.Normal); collectionSource.Add(newObject); } } } }
public static void Import(Stream xml, IObjectSpace os, CollectionSourceBase collection) { try { var serializer = new XmlSerializer(typeof(InvoiceXml)); var invoiceXml = (InvoiceXml)serializer.Deserialize(xml); var mapper = new InvoiceXmlMapper(new ObjectSpaceEntityFactory(os)); var invoice = mapper.Map(invoiceXml); os.CommitChanges(); collection.Add(invoice); } catch (Exception ex) { os.Rollback(); throw ex; } }
private static void AddNewObjectToCollectionSource(CollectionSourceBase currentCollectionSource, object newObject, XPObjectSpace objectSpace) { var newObjectTypeInfo = XafTypesInfo.Instance.FindTypeInfo(newObject.GetType()); if ((currentCollectionSource != null) && currentCollectionSource.ObjectTypeInfo.IsAssignableFrom(newObjectTypeInfo)) { if (objectSpace == currentCollectionSource.ObjectSpace) { currentCollectionSource.Add(newObject); } else { var propertyCollectionSource = (currentCollectionSource as PropertyCollectionSource); if ((propertyCollectionSource != null) && (propertyCollectionSource.MasterObject != null)) { Object collectionOwner; if (propertyCollectionSource.MemberInfo.GetPath().Count > 1) { collectionOwner = GetCollectionOwner(propertyCollectionSource.MasterObject, propertyCollectionSource.MemberInfo); if (collectionOwner != null) { XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()).FindMember(propertyCollectionSource.MemberInfo.LastMember.Name); } } else { collectionOwner = propertyCollectionSource.MasterObject; } if ((collectionOwner != null) && XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()).IsPersistent) { //TODO: Fix this throw new NotImplementedException("Feature not completely implemented. Import win Create Collection Source"); //var collectionSource = Application.CreatePropertyCollectionSource( // objectSpace, null, objectSpace.GetObject(collectionOwner), memberInfo, "", CollectionSourceMode.Normal); //collectionSource.Add(newObject); } } } } }
private void AddNewObjectToCollectionSource(CollectionSourceBase currentCollectionSource, object newObject, XPObjectSpace objectSpace) { var newObjectTypeInfo = XafTypesInfo.Instance.FindTypeInfo(newObject.GetType()); if ((currentCollectionSource == null) || !currentCollectionSource.ObjectTypeInfo.IsAssignableFrom(newObjectTypeInfo)) return; if (objectSpace == currentCollectionSource.ObjectSpace) currentCollectionSource.Add(newObject); else { var propertyCollectionSource = (currentCollectionSource as PropertyCollectionSource); if ((propertyCollectionSource != null) && (propertyCollectionSource.MasterObject != null)) { Object collectionOwner; IMemberInfo memberInfo = null; if (propertyCollectionSource.MemberInfo.GetPath().Count > 1) { collectionOwner = ImportUtils.GetCollectionOwner(propertyCollectionSource.MasterObject, propertyCollectionSource.MemberInfo); if (collectionOwner != null) memberInfo = XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()) .FindMember(propertyCollectionSource.MemberInfo.LastMember.Name); } else { collectionOwner = propertyCollectionSource.MasterObject; memberInfo = propertyCollectionSource.MemberInfo; } if ((collectionOwner != null) && XafTypesInfo.Instance.FindTypeInfo(collectionOwner.GetType()).IsPersistent) { var collectionSource = _application.CreatePropertyCollectionSource(objectSpace, null, objectSpace.GetObject(collectionOwner), memberInfo, "", CollectionSourceMode.Normal); collectionSource.Add(newObject); } } } }
private void callbackPanel_Callback(object sender, CallbackEventArgsBase e) { if (e.Parameter == "add") { var newObject = (XPBaseObject)_objectSpace.CreateObject(Model.ModelClass.TypeInfo.Type); _collectionSource.Add(newObject); BindDataSource(); object itemOid = newObject.GetMemberValue(Model.ModelClass.KeyProperty); // newObject.Oid; try{ var firstOrDefault = Model.Columns.Where(t => t.Index.HasValue && t.Index.Value >= 0) .OrderBy(t => t.Index.Value) .FirstOrDefault(); if (firstOrDefault != null) { _controlsPerObjectInList[itemOid][ firstOrDefault .PropertyName].Focus(); } } catch { } } else if (e.Parameter != null && e.Parameter.StartsWith("changed_")) { string[] split = e.Parameter.Split('_'); string itemOid = split[2]; string propertyName = split[1]; BindDataSource(); try{ object key = _controlsPerObjectInList.Keys.FirstOrDefault(item => item.ToString() == itemOid); if (key != null && _controlsPerObjectInList.ContainsKey(key)) { _controlsPerObjectInList[key][propertyName].Focus(); } } catch { } } else if (e.Parameter != null && e.Parameter.StartsWith("rem_")) { string itemOid = e.Parameter.Replace("rem_", ""); if (_dataSourceList == null) { return; } XPBaseObject itemToBeDeleted = _dataSourceList.Cast <XPBaseObject>().FirstOrDefault(item => item.GetMemberValue(Model.ModelClass.KeyProperty).ToString() == itemOid); if (itemToBeDeleted != null) { _collectionSource.Remove(itemToBeDeleted); itemToBeDeleted.Delete(); } if (_collectionSource.GetCount() == 0 && _btnAddFirst != null) { _btnAddFirst.Visible = true; } BindDataSource(); FocusCorrectControl(); } ToggleHeadersVisibility(); OnCallbackPerformed(); }