internal static object EntityDataToObject(EntityData data)
        {
            Type   tableType = TableCache.GetTableType(data.EntityName);
            object obj2      = Activator.CreateInstance(tableType);

            foreach (Column column in TableCache.GetTableOrCreate(tableType).Columns)
            {
                column.SetAction(obj2, data[column.ColumnName]);
            }
            return(obj2);
        }
        internal EntityData LoadWithEntity(SysEntity entity, int object_id)
        {
            EntityData data      = null;
            Type       tableType = TableCache.GetTableType(entity.EntityName);
            object     obj2      = this.context.FindById(tableType, new object[] { object_id });

            if (obj2 != null)
            {
                data = ObjectToEntityData(obj2, entity);
            }
            return(data);
        }
Example #3
0
        /// <summary>
        /// 收集条件,查询出基本数据
        /// </summary>
        /// <param name="_Report"></param>
        /// <param name="divCondition"></param>
        /// <param name="DataHelper"></param>
        /// <param name="_ReportQueryConditions"></param>
        /// <returns></returns>
        private DataTable GetBaseData(Control divCondition)
        {
            var _Parameters = new List <DbParameter>();

            foreach (var _Condition in _ReportQueryConditions)
            {
                var _control = divCondition.FindControl(_Condition.ControlName) as IDrisionControl;
                if (_control != null)
                {
                    var _value = _control.GetValue();
                    //是空值什么都不管,直接传空值查询
                    if (_value == null || string.IsNullOrEmpty(_value.ToString()))
                    {
                        _value = DBNull.Value;
                    }
                    //不是空值,如果是含子查询则将SysLevelCode查出来传进去,否则_value还是输入框的值
                    else if (_control.Tag == "IsSubQuery")
                    {
                        //这个控件的FieldName其实存的是FieldId
                        var  _Field     = _entityCache.FindById <SysField>(_control.FieldName.ToLong());
                        Type entityType = TableCache.GetTableType(_Field.RefEntity.EntityName);
                        //查出实体
                        var obj = this._DataHelper.FindById(entityType, _value.ToInt());
                        //获取SysLevelCode的值
                        _value = TableCache.GetTableOrCreate(entityType).GetColumnByColumnName("SystemLevelCode").GetFunction(obj);
                    }
                    _Parameters.Add(this._DataHelper.CreateParameter(this._DataHelper.AddPrefixToParameterName(_Condition.ControlName), _value));
                }
            }
            var strSQL = _Report.SQLScript.Replace("@CurrentUser", this.LoginUser.User_ID.ToString());

            //if (LoadEmpty)
            //{
            //    var _EntitySchema = Drision.Framework.Manager.IEntitySchemaHelper.Get(this._Report.EntityName);
            //    if (this._ReportQueryConditions.Count == 0 && this._ReportFixedConditions.Count == 0)
            //    {
            //        strSQL = string.Format("{0} where a.{1} = -1", strSQL, _EntitySchema.KeyName);
            //    }
            //    else
            //    {
            //        strSQL = string.Format("{0} and a.{1} = -1", strSQL, _EntitySchema.KeyName);
            //    }
            //}
            return(this._DataHelper.ExecuteDataTable(strSQL, _Parameters.ToArray()));
        }
        internal EntityData LoadFullWithEntity(SysEntity entity, int object_id, ProcessInstanceCacheFactory piCacheFactory)
        {
            EntityData data      = null;
            Type       tableType = TableCache.GetTableType(entity.EntityName);
            object     obj2      = this.context.FindById(tableType, new object[] { object_id });

            if (obj2 != null)
            {
                data = ObjectToEntityData(obj2, entity);
            }
            if (data != null)
            {
                EntityCache cache = new EntityCache(this);
                using (IEnumerator <SysField> enumerator = entity.Fields.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Func <SysEnumItem, bool> predicate = null;
                        SysField p = enumerator.Current;
                        if (p.DataType == 12)
                        {
                            if ((p.RefEntity != null) && (data[p.FieldName] != null))
                            {
                                string     displayFieldName = p.RefEntity.GetDisplayFieldName();
                                EntityData da = cache.GetObject(p.RefEntity, (int)data[p.FieldName]);
                                if (da == null)
                                {
                                    throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, object_id, p.FieldName, data[p.FieldName], p.RefEntity.EntityName }));
                                }
                                if (da.ContainsKey(displayFieldName))
                                {
                                    da[p.FieldName] = data[displayFieldName];
                                }
                            }
                        }
                        else
                        {
                            if (p.DataType == 13)
                            {
                                if (((p.RefEnum != null) && (p.RefEnum.EnumItems != null)) && (data[p.FieldName] != null))
                                {
                                    if (predicate == null)
                                    {
                                        predicate = delegate(SysEnumItem i) {
                                            int?itemValue = i.ItemValue;
                                            int num       = (int)data[p.FieldName];
                                            return((itemValue.GetValueOrDefault() == num) && itemValue.HasValue);
                                        };
                                    }
                                    SysEnumItem item = p.RefEnum.EnumItems.FirstOrDefault <SysEnumItem>(predicate);
                                    if (item != null)
                                    {
                                        data[p.FieldName] = item.DisplayText;
                                    }
                                }
                                continue;
                            }
                            if (p.DataType == 11)
                            {
                                if (data[p.FieldName].ToInt() == 0)
                                {
                                    data[p.FieldName] = "否";
                                }
                                else
                                {
                                    data[p.FieldName] = "是";
                                }
                                continue;
                            }
                            if ((p.DataType == 15) && (data[p.FieldName] != null))
                            {
                                string[] source = data[p.FieldName].ToString().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                if (source.Count <string>() != 2)
                                {
                                    throw new ApplicationException(string.Format("[{0}]中[entity_id]或者[object_id]缺失", data[p.FieldName]));
                                }
                                long      entityId    = source[0].ToLong();
                                int       num2        = source[1].ToInt();
                                SysEntity entityCache = piCacheFactory.PCacheFactory.GetEntityCache(entityId);
                                if (entityCache != null)
                                {
                                    string     key   = entityCache.GetDisplayFieldName();
                                    EntityData data2 = cache.GetObject(entityCache, num2);
                                    if (data2 == null)
                                    {
                                        throw new ApplicationException(string.Format("[{0}]-[{1}]的引用字段[{2}]有值[{3}],但是对应的[{4}]不存在", new object[] { entity.EntityName, num2, p.FieldName, data[p.FieldName], entityCache.EntityName }));
                                    }
                                    if (data2.ContainsKey(key))
                                    {
                                        data[p.FieldName] = data2[key];
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(data);
        }