コード例 #1
0
        public void DiscardChanges(UnitOfWork unitOfWork, XPBaseCollection collection)
        {
            var deletedTLObjects = TransactionalChangeHandler.GetDeletedTLObjects <RoomBooking>(unitOfWork);

            foreach (var newObject in TransactionalChangeHandler.GetSavedNewObjects(unitOfWork))
            {
                TransactionalChangeHandler.ResetAssociations(newObject);

                // special behavior for this form
                if (newObject is RoomBooking)
                {
                    // remove the appointment from the collection, this doesn't
                    // happen automatically
                    var appt = schedulerStorage.Appointments.Items.Find(
                        a => object.ReferenceEquals(a.GetRow(schedulerStorage), newObject));
                    schedulerStorage.Appointments.Remove(appt);
                }
            }

            unitOfWork.ReloadChangedObjects();

            // special behavior: get the right collection first
            var roomBookingCollection = (IList <RoomBooking>)schedulerStorage.Appointments.DataSource;

            foreach (var item in deletedTLObjects)
            {
                roomBookingCollection.Add(item);
            }
        }
 protected override void ReadValueCore()
 {
     base.ReadValueCore();
     if (PropertyValue is XPBaseCollection)
     {
         Control.ItemCheck -= new DevExpress.XtraEditors.Controls.ItemCheckEventHandler(control_ItemCheck);
         checkedItems       = (XPBaseCollection)PropertyValue;
         XPCollection dataSource = new XPCollection(checkedItems.Session, MemberInfo.ListElementType);
         IModelClass  classInfo  = application.Model.BOModel.GetClass(MemberInfo.ListElementTypeInfo.Type);
         if (checkedItems.Sorting.Count > 0)
         {
             dataSource.Sorting = checkedItems.Sorting;
         }
         else if (!String.IsNullOrEmpty(classInfo.DefaultProperty))
         {
             dataSource.Sorting.Add(new SortProperty(classInfo.DefaultProperty, DevExpress.Xpo.DB.SortingDirection.Ascending));
         }
         Control.DataSource    = dataSource;
         Control.DisplayMember = classInfo.DefaultProperty;
         foreach (object obj in checkedItems)
         {
             Control.SetItemChecked(dataSource.IndexOf(obj), true);
         }
         Control.ItemCheck += new DevExpress.XtraEditors.Controls.ItemCheckEventHandler(control_ItemCheck);
     }
 }
コード例 #3
0
 protected override void ReadValueCore()
 {
     base.ReadValueCore();
     if (PropertyValue is XPBaseCollection)
     {
         ASPxCheckBoxList control = ViewEditMode == DevExpress.ExpressApp.Editors.ViewEditMode.Edit ? Editor : InplaceViewModeEditor;
         if (control == null)
         {
             return;
         }
         control.SelectedIndexChanged -= new EventHandler(Control_SelectedIndexChanged);
         checkedItems = (XPBaseCollection)PropertyValue;
         XPCollection dataSource = new XPCollection(checkedItems.Session, MemberInfo.ListElementType);
         IModelClass  classInfo  = application.Model.BOModel.GetClass(MemberInfo.ListElementTypeInfo.Type);
         if (checkedItems.Sorting.Count > 0)
         {
             dataSource.Sorting = checkedItems.Sorting;
         }
         else if (!String.IsNullOrEmpty(classInfo.DefaultProperty))
         {
             dataSource.Sorting.Add(new SortProperty(classInfo.DefaultProperty, DevExpress.Xpo.DB.SortingDirection.Ascending));
         }
         control.DataSource = dataSource;
         control.TextField  = classInfo.DefaultProperty;
         control.ValueField = classInfo.KeyProperty;
         control.ValueType  = classInfo.TypeInfo.KeyMember.MemberType;
         control.DataBind();
         control.UnselectAll();
         foreach (object obj in checkedItems)
         {
             control.Items.FindByValue(objectSpace.GetKeyValue(obj)).Selected = true;
         }
         control.SelectedIndexChanged += new EventHandler(Control_SelectedIndexChanged);
     }
 }
コード例 #4
0
 public ManyToManyCollectionHelper(IXPSimpleObject owner, XPBaseCollection hiddenCollection, string
                                   hiddenCollectionName)
 {
     intermediateClassInfo = owner.ClassInfo.GetMember(hiddenCollectionName).IntermediateClass;
     this.owner            = owner;
     this.hiddenCollection = hiddenCollection;
 }
コード例 #5
0
        public IXPSimpleObject Clone(IXPSimpleObject source)
        {
            if (source == null)
            {
                return(null);
            }
            if (copiedObjects.ContainsKey(source))
            {
                return(copiedObjects[source]);
            }
            XPClassInfo     targetClassInfo = targetSession.GetClassInfo(source.GetType());
            IXPSimpleObject clone           = (IXPSimpleObject)targetClassInfo.CreateNewObject(targetSession);

            copiedObjects.Add(source, clone);
            if (objectCopied != null)
            {
                objectCopied(this, EventArgs.Empty);
            }
            foreach (XPMemberInfo m in targetClassInfo.PersistentProperties)
            {
                if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                {
                    continue;
                }
                object val;
                if (m.ReferenceType != null)
                {
                    val = Clone((IXPSimpleObject)m.GetValue(source));
                }
                else
                {
                    val = m.GetValue(source);
                }
                m.SetValue(clone, val);
            }
            foreach (XPMemberInfo m in targetClassInfo.CollectionProperties)
            {
                XPBaseCollection col       = (XPBaseCollection)m.GetValue(clone);
                XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source);
                foreach (IXPSimpleObject obj in CollectionHelper.CreateList((colSource)))
                {
                    col.BaseAdd(Clone(obj));
                }
            }
            Dictionary <string, object> indexedProperties = RetrieveIndexedProperties(targetClassInfo, clone);

            if (indexedProperties.Count > 0)
            {
                string          requestString = BuildRequest(indexedProperties);
                object[]        values        = BuildValuesArray(indexedProperties);
                IXPSimpleObject foundedClone  = (IXPSimpleObject)targetSession.FindObject(PersistentCriteriaEvaluationBehavior.InTransaction, targetClassInfo, CriteriaOperator.Parse(requestString, values));
                if (foundedClone != null && foundedClone != clone)
                {
                    ((XPBaseObject)foundedClone).Delete();
                }
            }
            return(clone);
        }
コード例 #6
0
 public static int GetCount(this XPBaseCollection xpBaseCollection)
 {
     if (!xpBaseCollection.IsLoaded)
     {
         CriteriaOperator totalCriteria = CombineCriteria(xpBaseCollection.Criteria, xpBaseCollection.Filter);
         return(GetObjectsCount(xpBaseCollection.GetObjectClassInfo(), totalCriteria, xpBaseCollection.Session));
     }
     return(xpBaseCollection.Count);
 }
コード例 #7
0
        public static void RemoveTLObjects <T>(XPBaseCollection collection, XPBaseObject ob)
            where T : class
        {
            var obAsT = ob as T;

            if (obAsT != null)
            {
                collection.BaseRemove(ob);
            }
        }
コード例 #8
0
 private void CloneCollection(XPMemberInfo memberInfo, object source, object target, bool synchronize)
 {
     if (memberInfo.IsAssociation && (memberInfo.IsManyToMany || memberInfo.IsAggregated))
     {
         XPBaseCollection colTarget = (XPBaseCollection)memberInfo.GetValue(target);
         XPBaseCollection colSource = (XPBaseCollection)memberInfo.GetValue(source);
         foreach (IXPSimpleObject obj in colSource)
         {
             colTarget.BaseAdd(CloneValue(obj, synchronize, !memberInfo.IsManyToMany));
         }
     }
 }
コード例 #9
0
        static public BaseDictWrapper wrap(Object xpoObj)
        {
            BaseDictWrapper wrapper  = new BaseDictWrapper();
            Type            origType = xpoObj.GetType();

            wrapper.setWrappedType(origType);

            Type origBaseType = origType.BaseType;

            PropertyInfo[] origProps = origType.GetProperties();
            PropertyInfo[] baseProps = origBaseType.GetProperties();

            //filter base xpo props
            List <string> basePropNameList = new List <string>();

            foreach (PropertyInfo prop in baseProps)
            {
                //az enabled listan levoket nem tesszik tiltolistara
                if (!enabledBaseProps.Contains(prop.Name))
                {
                    basePropNameList.Add(prop.Name);
                }
            }
            //copy instance properties into wrapper
            foreach (PropertyInfo prop in origProps)
            {
                if (!basePropNameList.Contains(prop.Name))
                {
                    //xpcollection vagy egyéb field
                    if (prop.PropertyType.BaseType.Equals(xpoBaseCollectionType))
                    {
                        XPBaseCollection xpColl = (XPBaseCollection)prop.GetValue(xpoObj);
                        //wrapper.dict.Add (prop.Name + "_" + TYPENAME, prop.PropertyType.FullName);
                        if (xpColl.Count > 0)
                        {
                            List <BaseDictWrapper> wrapperCollection = new List <BaseDictWrapper>();
                            foreach (Object xpoo in xpColl)
                            {
                                BaseDictWrapper wrappedItem = wrap(xpoo);
                                wrapperCollection.Add(wrappedItem);
                            }
                            wrapper.dict.Add(prop.Name, wrapperCollection);
                        }
                    }
                    else
                    {
                        wrapper.dict.Add(prop.Name, prop.GetValue(xpoObj));
                    }
                }
            }
            return(wrapper);
        }
コード例 #10
0
            public TransactionalChangeEventHandlerContainer(BaseView view, UnitOfWork unitOfWork,
                                                            BarButtonItem saveChangesItem, BarButtonItem discardChangesItem,
                                                            XPBaseCollection topLevelCollection)
            {
                this.view               = view;
                this.unitOfWork         = unitOfWork;
                this.saveChangesItem    = saveChangesItem;
                this.discardChangesItem = discardChangesItem;
                this.topLevelCollection = topLevelCollection;

                this.unitOfWork.TrackPropertiesModifications = true;

                EvalTransactionState();
            }
コード例 #11
0
        public static void Sort(XPBaseCollection collection, string property, SortingDirection direction)
        {
            bool isSortingAdded = false;

            foreach (SortProperty sortProperty in collection.Sorting)
            {
                if (sortProperty.Property.Equals(CriteriaOperator.Parse(property)))
                {
                    isSortingAdded = true;
                }
            }
            if (!isSortingAdded)
            {
                collection.Sorting.Add(new SortProperty(property, direction));
            }
        }
コード例 #12
0
ファイル: CustomersListForm.cs プロジェクト: zjxstjg/XPO
        private void EditForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            EditCustomerForm form     = (EditCustomerForm)sender;
            Customer         modified = Session.GetLoadedObjectByKey <Customer>(form.CustomerId);

            if (modified == null)
            {
                XPBaseCollection collection = (XPBaseCollection)CustomersBindingSource.DataSource;
                collection.Reload();
                CustomersView.FocusedRowHandle = CustomersView.LocateByValue("Oid", form.CustomerId);
            }
            else
            {
                Session.Reload(modified);
            }
        }
コード例 #13
0
ファイル: VersionHelper.cs プロジェクト: ewin66/IntecoAG.ERM
        /// <summary>
        /// Копирование объекта. Результат - это копия объекта, в котором все обычные, но неверсионные, свойства копируются из прежнего объекта
        /// </summary>
        /// <param name="source"></param>
        /// <param name="targetSession"></param>
        /// <param name="synchronize"></param>
        /// <returns></returns>
        public object CopyForVersion(IXPSimpleObject source)
        {
            if (source == null)
            {
                return(null);
            }

            XPClassInfo classInfo = sourceSession.GetClassInfo(source.GetType());

            // Копия объекта. Есть проблема. Если в AfterConstruction объекта создаётся некий версионный объект, то
            // этот версионный объект окажется незамещённым никакой копией из исходного объекта и тем самым "повиснет"
            IVersionSupport copy = (IVersionSupport)classInfo.CreateNewObject(sourceSession);

            // Паша
            copy.IsProcessCloning = true;
            foreach (XPMemberInfo m in classInfo.PersistentProperties)
            {
                if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                {
                    continue;
                }
                if (m is IVersionSupport)
                {
                    continue;
                }
                m.SetValue(copy, m.GetValue(source));
            }

            foreach (XPMemberInfo m in classInfo.CollectionProperties)
            {
                if (m.HasAttribute(typeof(AggregatedAttribute)))
                {
                    XPBaseCollection colCopy   = (XPBaseCollection)m.GetValue(copy);
                    XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source);
                    foreach (IXPSimpleObject obj in new ArrayList(colSource))
                    {
                        if (obj is IVersionSupport)
                        {
                            continue;
                        }
                        colCopy.BaseAdd(obj);
                    }
                }
            }

            return(copy);
        }
コード例 #14
0
        private void GenerateForm <T>(IModelClass f, IModelClass t, XPBaseCollection cols)
            where T : PropertyMapping
        {
            Session.Delete(cols);

            //var f = From as FlowChartFormNode;
            //var t = To as FlowChartFormNode;
            foreach (var p in t.AllMembers)
            {
                //类上没有设置忽略单据转换属性
                if (p.ModelClass.TypeInfo.FindAttribute <IgnoreFormConvertAttribute>() == null)
                {
                    //目标属性上也没有设置
                    if (!p.MemberInfo.IsAutoGenerate &&
                        !p.MemberInfo.IsKey &&
                        !p.MemberInfo.IsService &&
                        !p.MemberInfo.IsReadOnly &&
                        !p.MemberInfo.IsList &&
                        p.AllowEdit &&
                        p.MemberInfo.FindAttribute <IgnoreFormConvertAttribute>() == null
                        )
                    {
                        //名字一样,类型一样,可以导入!
                        var fp = f.FindMember(p.Name);
                        if (fp != null)
                        {
                            if (fp.MemberInfo.MemberType == p.MemberInfo.MemberType)
                            {
                                var mpm = ReflectionHelper.CreateObject <T>(Session);
                                mpm.FromBill     = f.Name;
                                mpm.FromProperty = new StringObject(p.Name);
                                mpm.ToBill       = t.Name;
                                mpm.ToProperty   = new StringObject(fp.Name);
                                cols.BaseAdd(mpm);
                            }
                        }
                    }
                }
                else
                {
                    Debug.WriteLine(p.ModelClass.Name + "忽略单据转换");
                }
            }
        }
コード例 #15
0
ファイル: VersionHelper.cs プロジェクト: ewin66/IntecoAG.ERM
        /// <summary>
        /// Снятие непосредственно прилегающих к объекту версионных объектов
        /// </summary>
        /// <param name="sourceObj"></param>
        /// <param name="dependentObjectList"></param>
        /// <param name="vHelper"></param>
        /// <returns></returns>
        public List <IVersionSupport> GetFirstDependentList(IVersionSupport sourceObj, VersionHelper vHelper)
        {
            List <IVersionSupport> ResList = new List <IVersionSupport>();

            if (sourceObj == null)
            {
                return(ResList);
            }

            IXPSimpleObject sourceObject    = (IXPSimpleObject)sourceObj;
            XPClassInfo     sourceClassInfo = sourceObject.ClassInfo; // sourceSession.GetClassInfo(sourceObject);

            foreach (XPMemberInfo m in sourceClassInfo.PersistentProperties)
            {
                if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                {
                    continue;
                }
                if (m.ReferenceType != null)
                {
                    IVersionSupport ob = m.GetValue(sourceObj) as IVersionSupport;
                    if (ob != null)
                    {
                        AddObjectToList(ob, ResList);
                    }
                }
            }

            foreach (XPMemberInfo m in sourceClassInfo.CollectionProperties)
            {
                //if (m.HasAttribute(typeof(AggregatedAttribute))) {
                XPBaseCollection colSource = (XPBaseCollection)m.GetValue(sourceObj);
                foreach (IXPSimpleObject obj in colSource)
                {
                    if (obj is IVersionSupport)
                    {
                        AddObjectToList((IVersionSupport)obj, ResList);
                    }
                }
                //}
            }

            return(ResList);
        }
コード例 #16
0
        public static void Hookup <T>(BaseView view, UnitOfWork unitOfWork,
                                      BarButtonItem saveChangesItem, BarButtonItem discardChangesItem,
                                      XPBaseCollection topLevelCollection,
                                      SessionManipulationEventHandler afterCommitTransactionEventHandler,
                                      SessionManipulationEventHandler afterRollbackTransactionEventHandler,
                                      ObjectChangeEventHandler objectChangedEventHandler,
                                      ObjectManipulationEventHandler objectDeletedEventHandler,
                                      ObjectManipulationEventHandler objectSavedEventHandler,
                                      DocumentCancelEventHandler documentClosingHandler,
                                      ItemClickEventHandler saveChangesItemClickEventHandler,
                                      ItemClickEventHandler discardChangesItemClickEventHandler)
            where T : class
        {
            var container = new TransactionalChangeEventHandlerContainer <T>(
                view, unitOfWork, saveChangesItem,
                discardChangesItem, topLevelCollection
                );

            unitOfWork.AfterCommitTransaction +=
                afterCommitTransactionEventHandler ??
                container.SessionManipulationHandler;
            unitOfWork.AfterRollbackTransaction +=
                afterRollbackTransactionEventHandler ??
                container.SessionManipulationHandler;
            unitOfWork.ObjectChanged +=
                objectChangedEventHandler ?? container.ObjectChangeHandler;
            unitOfWork.ObjectDeleted +=
                objectDeletedEventHandler ??
                container.ObjectManipulationHandler;
            unitOfWork.ObjectSaved +=
                objectSavedEventHandler ?? container.ObjectManipulationHandler;

            view.DocumentClosing +=
                documentClosingHandler ?? container.DocumentClosingHandler;

            saveChangesItem.ItemClick +=
                saveChangesItemClickEventHandler ??
                container.SaveChangesItemClickHandler;
            discardChangesItem.ItemClick +=
                discardChangesItemClickEventHandler ??
                container.DiscardChangesItemClickHandler;
        }
コード例 #17
0
        protected override void ReadValueCore()
        {
            base.ReadValueCore();

            var collectionType     = this.MemberInfo.MemberType.GenericTypeArguments[0];
            var collectionTypeInfo = (DevExpress.ExpressApp.DC.TypeInfo)XafTypesInfo.Instance.FindTypeInfo(collectionType.FullName);

            if (PropertyValue is XPBaseCollection)
            {
                _Control = (ASPxTokenBox)(ViewEditMode == DevExpress.ExpressApp.Editors.ViewEditMode.Edit ? Editor : InplaceViewModeEditor);

                if (_Control != null)
                {
                    _Control.TokensChanged -= new EventHandler(Control_TokensChanged);
                    tokenItems              = (XPBaseCollection)PropertyValue;
                    XPCollection dataSource = new XPCollection(tokenItems.Session, MemberInfo.ListElementType);
                    IModelClass  classInfo  = _Application.Model.BOModel.GetClass(MemberInfo.ListElementTypeInfo.Type);
                    if (tokenItems.Sorting.Count > 0)
                    {
                        dataSource.Sorting = tokenItems.Sorting;
                    }
                    else if (!String.IsNullOrEmpty(classInfo.DefaultProperty))
                    {
                        dataSource.Sorting.Add(new SortProperty(classInfo.DefaultProperty, DevExpress.Xpo.DB.SortingDirection.Ascending));
                    }
                    _Control.DataSource    = dataSource;
                    _Control.TextField     = classInfo.DefaultProperty;
                    _Control.ValueField    = classInfo.KeyProperty;
                    _Control.ItemValueType = classInfo.TypeInfo.KeyMember.MemberType;
                    _Control.DataBind();

                    foreach (object obj in tokenItems)
                    {
                        _Control.Tokens.Add(((XPBaseObject)obj).GetMemberValue(MemberInfo.ListElementTypeInfo.DefaultMember.Name).ToString());
                    }
                    _Control.TokensChanged += new EventHandler(Control_TokensChanged);
                }
            }
        }
コード例 #18
0
        public static void DiscardChanges <T>(UnitOfWork unitOfWork, XPBaseCollection collection) where T : class
        {
            // remember which top-level objects were going to be deleted
            // so we can restore them back into the UI collection
            var deletedTLObjects = GetDeletedTLObjects <T>(unitOfWork);

            // as long as the unit of work hasn't been committed, the newly added
            // objects are recognized by the IsNewObject method
            // for the elements that had been added, find their association
            // properties and set their values to null, so that they are
            // removed from the collections they had been added to
            foreach (var newObject in GetSavedNewObjects(unitOfWork))
            {
                ResetAssociations(newObject);
                RemoveTLObjects <T>(collection, newObject);
            }

            unitOfWork.ReloadChangedObjects();

            // add the deleted objects back into the top level collection
            collection.BaseAddRange(deletedTLObjects);
        }
コード例 #19
0
        public void SetupGridView(DevExpress.XtraGrid.Views.Grid.GridView targetGV, XPBaseCollection _listXPC)
        {
            //DevExpress.XtraGrid.Views.Grid.GridView targetGV = col.Properties.View;
            if (targetGV.GridControl != null)
            {
                targetGV.GridControl.ForceInitialize();
            }
            targetGV.Columns.Clear();
            targetGV.OptionsView.ColumnAutoWidth        = false;
            targetGV.OptionsView.ShowAutoFilterRow      = true;
            targetGV.OptionsView.ShowFooter             = true;
            targetGV.OptionsView.ShowGroupPanel         = false;
            targetGV.OptionsView.EnableAppearanceOddRow = true;
            targetGV.OptionsView.ShowFilterPanelMode    = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.ShowAlways;
            var classInfo = _listXPC.GetObjectClassInfo();
            var objName   = AppListSession.FindObject <UIObjectBase>(CriteriaOperator.Parse("[ObjectName] = ? ", classInfo.FullName));
            var labels    = objName.ObjectLabels.Where(x => x.LookupMember != CoreLib.MyEnums.AutoLookUp.None);

            foreach (var item in labels)
            {
                string filedName = item.FieldName.Substring(item.FieldName.LastIndexOf('.') + 1);
                string caption   = item.ChooseValueForCurrentLang(CoreLib.MyEnums.UILabelType.FieldCaption);
                var    grdCol    = targetGV.Columns.AddVisible(filedName, caption);
                //Calc estimated width according to LookUp char width
                Size columnSize = TextRenderer.MeasureText("".PadLeft(item.LookupMemberCharWidth, 'A'), targetGV.Appearance.HeaderPanel.Font);
                grdCol.Width = columnSize.Width;
                if (item.LookupMember == CoreLib.MyEnums.AutoLookUp.ValueMemberVisiable ||
                    item.LookupMember == CoreLib.MyEnums.AutoLookUp.ValueMemberHidden)
                {
                    ValueMember = filedName;
                }
                if (item.LookupMember == CoreLib.MyEnums.AutoLookUp.DisplayMember1)
                {
                    DisplayMember = filedName;
                }
            }
        }
コード例 #20
0
 public XpoObservableCollection(Session session, XPBaseCollection originalCollection, CriteriaOperator copyFilter) : base(session, originalCollection, copyFilter)
 {
 }
コード例 #21
0
 public XpoObservableCollection(Session session, XPBaseCollection originalCollection, CriteriaOperator copyFilter, bool caseSensitive) : base(session, originalCollection, copyFilter, caseSensitive)
 {
 }
コード例 #22
0
 public XpoObservableCollection(Session session, XPBaseCollection originalCollection) : base(session, originalCollection)
 {
 }
コード例 #23
0
 public XpoObservableCollection(XPBaseCollection originalCollection) : base(originalCollection)
 {
 }
コード例 #24
0
 public XpoObservableCollection(XPBaseCollection originalCollection, CriteriaOperator filter, bool caseSensitive) : base(originalCollection, filter, caseSensitive)
 {
 }
コード例 #25
0
 public XpoObservableCollection(XPBaseCollection originalCollection, CriteriaOperator filter) : base(originalCollection, filter)
 {
 }
コード例 #26
0
            /// <summary>
            /// Clones and / or synchronizes the given IXPSimpleObject.
            /// </summary>
            /// <param name="source"></param>
            /// <param name="targetSession"></param>
            /// <param name="synchronize">If set to true, reference properties are only cloned in case
            /// the reference object does not exist in the targetsession. Otherwise the exising object will be
            /// reused and synchronized with the source. Set this property to false when knowing at forehand
            /// that the targetSession will not contain any of the objects of the source.</param>
            /// <returns></returns>
            object Clone(IXPSimpleObject source, Session targetSession, bool synchronize)
            {
                if (source == null)
                {
                    return(null);
                }
                if (clonedObjects.ContainsKey(source))
                {
                    return(clonedObjects[source]);
                }
                XPClassInfo targetClassInfo = targetSession.GetClassInfo(source.GetType());

                if (_excluded.Contains(targetClassInfo))
                {
                    return(null);
                }

                object clone;

                if (synchronize)
                {
                    clone = targetSession.GetObjectByKey(targetClassInfo, source.Session.GetKeyValue(source));
                }
                else
                {
                    clone = null;
                }

                if (clone == null)
                {
                    clone = targetClassInfo.CreateNewObject(targetSession);
                }

                clonedObjects.Add(source, clone);

                foreach (XPMemberInfo m in targetClassInfo.PersistentProperties)
                {
                    if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                    {
                        continue;
                    }
                    object val;
                    // makes sure when copying details entities in a master/detail relation, that the master is copied as well.
                    if (m.ReferenceType != null)
                    {
                        object createdByClone = m.GetValue(clone);
                        if ((createdByClone != null) && !synchronize)
                        {
                            val = createdByClone;
                        }
                        else if (_syncProps.Contains(m.MappingField))
                        {
                            object targetSource = targetSession.GetObjectByKey(targetClassInfo, source.Session.GetKeyValue(source));
                            val = m.GetValue(targetSource);
                        }
                        else
                        {
                            val = Clone((IXPSimpleObject)m.GetValue(source), targetSession, synchronize);
                        }
                    }
                    else
                    {
                        val = m.GetValue(source);
                    }
                    m.SetValue(clone, val);
                }
                foreach (XPMemberInfo m in targetClassInfo.CollectionProperties)
                {
                    if (m.HasAttribute(typeof(AggregatedAttribute)))
                    {
                        XPBaseCollection col       = (XPBaseCollection)m.GetValue(clone);
                        XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source);
                        if (col != null)
                        {
                            foreach (IXPSimpleObject obj in new ArrayList(colSource))
                            {
                                col.BaseAdd(Clone(obj, targetSession, synchronize));
                            }
                        }
                    }
                }
                return(clone);
            }
コード例 #27
0
        private void DetailForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            XPBaseCollection collection = (XPBaseCollection)employeeBindingSource.DataSource;

            collection.Reload();
        }
コード例 #28
0
ファイル: DBCollection.cs プロジェクト: aries544/eXpand
 public static int GetCount(XPBaseCollection collection, Type type)
 {
     return GetCount(collection.Session, type, collection.Criteria);
 }
コード例 #29
0
 public static void Hookup <T>(BaseView view, UnitOfWork unitOfWork, BarButtonItem saveChangesItem, BarButtonItem discardChangesItem, XPBaseCollection topLevelCollection)
     where T : class
 {
     Hookup <T>(view, unitOfWork, saveChangesItem, discardChangesItem, topLevelCollection,
                null, null, null, null, null, null, null, null);
 }
コード例 #30
0
 public XpandXPCollection(XPBaseCollection originalCollection, Expression <Func <T, bool> > filter, bool caseSensitive)
     : base(originalCollection, new XPQuery <T>(originalCollection.Session).TransformExpression(filter), caseSensitive)
 {
 }
コード例 #31
0
 public XpandXPCollection(XPBaseCollection originalCollection) : base(originalCollection)
 {
 }
コード例 #32
0
        protected override void ReadValueCore()
        {
            base.ReadValueCore();
            if (PropertyValue is XPBaseCollection)
            {
                // отписка от старого обработчика
                Control.ItemCheck -= new DevExpress.XtraEditors.Controls.ItemCheckEventHandler(control_ItemCheck);
                checkedItems = (XPBaseCollection)PropertyValue;

                // дополнительные условия
                CriteriaOperator criteria = null;
                if (!string.IsNullOrEmpty(Model.DataSourceCriteria))
                {
                    criteria = CriteriaOperator.Parse(Model.DataSourceCriteria);
                }
                if (!string.IsNullOrEmpty(Model.DataSourceCriteriaProperty))
                {
                    CriteriaOperator criteria2 = null;

                    IMemberInfo propWithCriteria = MemberInfo.Owner.FindMember(Model.DataSourceCriteriaProperty);
                    criteria2 = (CriteriaOperator)propWithCriteria.GetValue(this.CurrentObject);

                    if (!ReferenceEquals(criteria2, null))
                    {
                        criteria = !ReferenceEquals(criteria, null) ? CriteriaOperator.And(criteria, criteria2) : criteria2;
                    }
                }

                // коллекция данных для списка
                XPCollection dataSource = new XPCollection(
                    checkedItems.Session,
                    MemberInfo.ListElementType,
                    !ReferenceEquals(criteria, null) ? CriteriaOperator.And(checkedItems.Criteria, criteria) : checkedItems.Criteria,
                    checkedItems.Sorting.ToArray<SortProperty>());
                IModelClass classInfo = application.Model.BOModel.GetClass(MemberInfo.ListElementTypeInfo.Type);
                if (checkedItems.Sorting.Count > 0)
                {
                    dataSource.Sorting = checkedItems.Sorting;
                }
                else if (checkedItems.Sorting.Count == 0 && !String.IsNullOrEmpty(classInfo.DefaultProperty))
                {
                    dataSource.Sorting.Add(new SortProperty(classInfo.DefaultProperty, DevExpress.Xpo.DB.SortingDirection.Ascending));
                }
                Control.DataSource = dataSource;
                Control.DisplayMember = classInfo.DefaultProperty;

                //Выполняем условие для отображения текста в контроле.
                IModelPropertyEditorDisplayItem displayItem = Model as IModelPropertyEditorDisplayItem;
                if (displayItem != null)
                {
                    if (!ReferenceEquals(displayItem.DisplayItemCriteriaProperty, null))
                    {
                        IMemberInfo propWithCriteria = MemberInfo.Owner.FindMember(displayItem.DisplayItemCriteriaProperty);
                        Control.ItemTextCriteria = (CriteriaOperator)propWithCriteria.GetValue(this.CurrentObject);
                    }
                    if (!String.IsNullOrWhiteSpace(displayItem.DisplayItemCriteriaString))
                    {
                        Control.ItemTextCriteriaString = (displayItem.DisplayItemCriteriaString);
                    }
                }

                foreach (object obj in checkedItems)
                {
                    Control.SetItemChecked(dataSource.IndexOf(obj), true);
                }
                Control.ItemCheck += new DevExpress.XtraEditors.Controls.ItemCheckEventHandler(control_ItemCheck);
            }
        }