private void PopulateTreeGrid(object item)
        {
            if (item == null)
            {
                return;
            }

            IType itemType = ResolveType(DataLayerCommon.ReflectClassFor(item));

            if (itemType.IsPrimitive)
            {
                PopulatePrimitiveValues(item, itemType.DisplayName);
            }
            else
            {
                container.Ext().Activate(item, 1);
                Type type = item.GetType();

                if (item is DictionaryEntry || (type.IsGenericType && type.GetGenericTypeDefinition() != null && type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>)))
                {
                    PopulateDictionaryEntry(item);
                }
                else
                {
                    TreeGridViewRenderer treeviewRenderer = PopulateTreeGridViewRenderer(item, itemType);
                    listTreeGridViewRenderers.Add(treeviewRenderer);
                }
            }
        }
        public List <TreeGridViewRenderer> ExpandObjectNode(object obj, bool activate)
        {
            try
            {
                //object obj = Db4oClient.Client.Ext().GetByID(id);
                if (obj == null)
                {
                    return(null);
                }

                IReflectClass rclass = DataLayerCommon.ReflectClassFor(obj);
                if (rclass == null)
                {
                    return(null);
                }
                string classname = rclass.GetName();
                if (classname != string.Empty)
                {
                    TraverseObjTree(GetLocalID(obj), classname);
                }
                return(listTreeGridViewRenderers);
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
                return(null);
            }
        }
Exemple #3
0
 public void SaveValues(object targetObject, string attribName, object newValue, int offset, IType type)
 {
     try
     {
         IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject);
         IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
         if (rfield != null && !(rfield is GenericVirtualField))
         {
             if (type.IsArray || type.IsCollection)
             {
                 IList list = rfield.Get(targetObject) as IList;
                 if (null != list)
                 {
                     list[offset] = newValue;
                     rfield.Set(targetObject, list);
                 }
             }
             else
             {
                 SetObject(rfield, targetObject, newValue);
             }
         }
     }
     catch (Exception oEx)
     {
         objectContainer.Rollback();
         LoggingHelper.HandleException(oEx);
     }
 }
        public static void SetFieldToNull(long id, string fieldName)
        {
            try
            {
                object obj = Db4oClient.Client.Ext().GetByID(id);
                Db4oClient.Client.Ext().Activate(obj, 1);
                IReflectClass klass = DataLayerCommon.ReflectClassFor(obj);
                if (klass != null)
                {
                    IReflectField field = DataLayerCommon.GetDeclaredFieldInHeirarchy(klass, fieldName);
                    if (field == null)
                    {
                        return;
                    }

                    field.Set(obj, null);
                    Db4oClient.Client.Store(obj);

                    Db4oClient.Client.Commit();
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }
        }
Exemple #5
0
        public void ExpandObjectNode(TreeGridNode node, bool activate)
        {
            try
            {
                object obj = node.Tag;
                if (obj == null)
                {
                    return;
                }

                IReflectClass rclass = DataLayerCommon.ReflectClassFor(obj);
                if (rclass == null)
                {
                    return;
                }

                string classname = rclass.GetName();
                if (classname != string.Empty)
                {
                    TraverseObjTree(ref node, obj, classname);
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }
        }
Exemple #6
0
        private void PopulateTreeGrid(object item, TreeGridNode parentNode)
        {
            if (item == null)
            {
                return;
            }

            IType itemType = ResolveType(DataLayerCommon.ReflectClassFor(item));

            if (itemType.IsPrimitive)
            {
                TraverseObjTree(ref parentNode, item, container.Ext().Reflector().ForObject(item).GetName());
            }
            else
            {
                container.Ext().Activate(item, 1);
                TreeGridNode collNode = new TreeGridNode();
                parentNode.Nodes.Add(collNode);
                collNode.Cells[0].Value = AppendIDTo(item.ToString(), GetLocalID(item), itemType);

                SetFieldType(collNode, itemType);
                collNode.Cells[1].Value    = ClassNameFor(item.ToString());
                collNode.Tag               = item;
                collNode.ImageIndex        = 0;
                collNode.Cells[1].ReadOnly = true;
                TraverseObjTree(ref collNode, item, itemType.FullName);
            }
        }
        public static bool CheckForCollection(long id)
        {
            object        obj   = GetObjById(id);
            IReflectClass clazz = DataLayerCommon.ReflectClassFor(obj);
            IType         type  = Db4oClient.TypeResolver.Resolve(clazz);

            return(CheckIsCollection(type));
        }
Exemple #8
0
        private static object SetField(string attribName, object subObject, object newValue)
        {
            try
            {
                IReflectClass rclass = DataLayerCommon.ReflectClassFor(subObject);
                if (rclass == null)
                {
                    return(null);
                }

                IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
                if (rfield == null)
                {
                    return(null);
                }

                if (rfield is GenericVirtualField || rfield.IsStatic())
                {
                    return(null);
                }



                IType fieldType = Db4oClient.TypeResolver.Resolve(rfield.GetFieldType());
                if (!fieldType.IsEditable)
                {
                    if (!fieldType.IsCollection && !fieldType.IsArray)
                    {
                        subObject = rfield.Get(subObject);
                        Db4oClient.Client.Ext().Activate(subObject, 2);
                        return(subObject);
                    }
                }
                else if (subObject != null)
                {
                    rfield.Set(subObject, fieldType.Cast(newValue));
                    return(subObject);
                }
                return(null);
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
                return(null);
            }
        }
 public object getClass(string attribName, object subObject, string fullattribName)
 {
     try
     {
         IReflectClass rclass = DataLayerCommon.ReflectClassFor(subObject);
         if (rclass != null)
         {
             IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
             if (rfield != null)
             {
                 string fieldType = rfield.GetFieldType().GetName();
                 IType  type      = Db4oClient.TypeResolver.Resolve(fieldType);
                 if (m_hashRowContent == null)
                 {
                     m_hashRowContent = new Hashtable();
                 }
                 if (!type.IsEditable)
                 {
                     if (!rfield.GetFieldType().IsCollection() && !rfield.GetFieldType().IsArray())
                     {
                         object getObj = rfield.Get(subObject);
                         if (getObj == null)
                         {
                             m_hashRowContent.Add(fullattribName, BusinessConstants.DB4OBJECTS_NULL);
                         }
                         return(getObj);
                     }
                 }
                 else
                 {
                     object objValue = rfield.Get(subObject);
                     m_hashRowContent.Add(fullattribName, objValue);
                 }
             }
         }
     }
     catch (Exception oEx)
     {
         LoggingHelper.HandleException(oEx);
     }
     return(null);
 }
 public static void SaveDictionary(object targetObject, string attribName, object newValue, object key)
 {
     try
     {
         IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject);
         if (rclass != null)
         {
             IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
             if (rfield != null)
             {
                 if (!(rfield is GenericVirtualField || rfield.IsStatic()))
                 {
                     object      obj = rfield.Get(targetObject);
                     ICollection col = (ICollection)obj;
                     if (col is Hashtable)
                     {
                         Hashtable hash = (Hashtable)col;
                         hash.Remove(key);
                         hash.Add(key, newValue);
                         rfield.Set(targetObject, hash);
                     }
                     else if (col is IDictionary)
                     {
                         IDictionary dict = (IDictionary)col;
                         dict.Remove(key);
                         dict.Add(key, newValue);
                         rfield.Set(targetObject, dict);
                     }
                 }
             }
         }
     }
     catch (Exception oEx)
     {
         Db4oClient.Client.Rollback();
         LoggingHelper.HandleException(oEx);
     }
 }
        public static void SaveValues(long id, string attribName, object newValue, int offset)
        {
            try
            {
                object targetObject = Db4oClient.Client.Ext().GetByID(id);
                Db4oClient.Client.Ext().Activate(targetObject, 2);
                IReflectClass rclass = DataLayerCommon.ReflectClassFor(targetObject);
                IReflectField rfield = DataLayerCommon.GetDeclaredFieldInHeirarchy(rclass, attribName);
                IType         type   = new FieldDetails(rclass.GetName(), attribName).GetFieldType();
                object        obj    = rfield.Get(targetObject);

                if (obj is IDictionary)
                {
                    SaveDictionary(targetObject, attribName, newValue, KeyAtIndex((IDictionary)obj, offset / 2));
                }
                else
                {
                    if (rfield != null && !(rfield is GenericVirtualField || rfield.IsStatic()))
                    {
                        if (type.IsArray || type.IsCollection)
                        {
                            IList list = obj as IList;
                            if (null != list)
                            {
                                list[offset] = newValue;
                                rfield.Set(targetObject, list);
                            }
                        }
                    }
                }
            }
            catch (Exception oEx)
            {
                Db4oClient.Client.Rollback();
                LoggingHelper.HandleException(oEx);
            }
        }
        public int GetDepth(long id)
        {
            try
            {
                object obj = Db4oClient.Client.Ext().GetByID(id);
                Db4oClient.Client.Ext().Activate(obj, 1);
                level++;
                IReflectClass rclass = DataLayerCommon.ReflectClassFor(obj);
                if (rclass != null)
                {
                    IReflectField[] fieldArr = DataLayerCommon.GetDeclaredFieldsInHeirarchy(rclass);
                    if (fieldArr != null)
                    {
                        foreach (IReflectField field in fieldArr)
                        {
                            object getObject    = field.Get(obj);
                            string getFieldType = field.GetFieldType().GetName();
                            IType  fieldType    = Db4oClient.TypeResolver.Resolve(getFieldType);
                            if (getObject != null)
                            {
                                if (!fieldType.IsEditable)
                                {
                                    if (fieldType.IsCollection)
                                    {
                                        ICollection coll    = (ICollection)field.Get(obj);
                                        ArrayList   arrList = new ArrayList(coll);

                                        for (int i = 0; i < arrList.Count; i++)
                                        {
                                            object colObject = arrList[i];
                                            if (colObject != null)
                                            {
                                                if (colObject is GenericObject)
                                                {
                                                    if (!m_listforObjects.Contains(colObject))
                                                    {
                                                        m_listforObjects.Add(colObject);
                                                        long objId = new ObjectDetails(colObject).GetLocalID();

                                                        level = GetDepth(objId);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else if (fieldType.IsArray)
                                    {
                                        int length = objectContainer.Ext().Reflector().Array().GetLength(field.Get(obj));
                                        for (int i = 0; i < length; i++)
                                        {
                                            object arrObject =
                                                objectContainer.Ext().Reflector().Array().Get(field.Get(obj), i);
                                            if (arrObject != null)
                                            {
                                                if (arrObject is GenericObject)
                                                {
                                                    if (!m_listforObjects.Contains(arrObject))
                                                    {
                                                        m_listforObjects.Add(arrObject);
                                                        long objId = new ObjectDetails(arrObject).GetLocalID();
                                                        level = GetDepth(objId);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (!m_listforObjects.Contains(getObject))
                                        {
                                            m_listforObjects.Add(getObject);
                                            long objId = new ObjectDetails(getObject).GetLocalID();
                                            level = GetDepth(objId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.HandleException(oEx);
            }

            return(level);
        }
        public static string GetClassName(long id)
        {
            object obj = GetObjById(id);

            return(DataLayerCommon.ReflectClassFor(obj).GetName());
        }