Пример #1
0
        /// <summary>
        /// 直接查询数据库视图
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="lstScope">条件</param>
        /// <param name="vParams">字段列表</param>
        /// <param name="lstSort">排序类型</param>
        /// <param name="objPage">分页对象</param>
        /// <returns></returns>
        public DataSet SelectTable(BQLOtherTableHandle table, ScopeList lstScope)
        {
            List <BQLParamHandle> lstParams = GetParam(table, lstScope);

            List <BQLParamHandle> lstOrders = new List <BQLParamHandle>();
            BQLParamHandle        order     = null;

            foreach (Sort objSort in lstScope.OrderBy)
            {
                order = table[objSort.PropertyName];
                if (objSort.SortType == SortType.ASC)
                {
                    order = order.ASC;
                }
                else
                {
                    order = order.DESC;
                }
                lstOrders.Add(order);
            }

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope, null);

            BQLQuery bql = BQL.Select(lstParams.ToArray()).From(table).Where(where).OrderBy(lstOrders.ToArray());

            if (lstScope.HasPage)
            {
                using (BatchAction ba = _oper.StarBatchAction())
                {
                    return(QueryDataSet(bql, null, lstScope.PageContent, lstScope.UseCache));
                }
            }
            return(QueryDataSet(bql, null, lstScope.UseCache));
        }
Пример #2
0
        /// <summary>
        /// 获取要显示的字段
        /// </summary>
        /// <param name="handle"></param>
        /// <param name="propertys"></param>
        /// <returns></returns>
        private List <BQLParamHandle> GetParam(BQLTableHandle handle, ScopeList lstScope)
        {
            List <BQLParamHandle> lstParams = lstScope.GetShowProperty(handle);


            return(lstParams);
        }
Пример #3
0
        /// <summary>
        /// 填充字类列表
        /// </summary>
        /// <param name="pks">ID集合</param>
        /// <param name="fatherInfo">父表对应类的信息</param>
        /// <param name="dicElement">元素</param>
        /// <param name="mappingInfo">当前父表对应属性的映射信息</param>
        private static void FillParent(object pk, EntityInfoHandle fatherInfo,
                                       EntityMappingInfo mappingInfo, string propertyName, EntityBase sender)
        {
            DBInfo          db       = fatherInfo.DBInfo;
            DataBaseOperate oper     = fatherInfo.DBInfo.DefaultOperate;
            BQLDbBase       dao      = new BQLDbBase(oper);
            ScopeList       lstScope = new ScopeList();

            sender.OnFillParent(propertyName, lstScope);
            lstScope.AddEqual(mappingInfo.TargetProperty.PropertyName, pk);
            IDataReader reader = dao.QueryReader(lstScope, fatherInfo.EntityType);

            try
            {
                //获取子表的get列表
                List <EntityPropertyInfo> lstParamNames = CacheReader.GenerateCache(reader, fatherInfo);//创建一个缓存数值列表
                while (reader.Read())
                {
                    object newObj = fatherInfo.CreateSelectProxyInstance();
                    mappingInfo.SetValue(sender, newObj);
                    CacheReader.FillObjectFromReader(reader, lstParamNames, newObj, db);
                }
                sender.OnPropertyUpdated(mappingInfo.PropertyName);
            }
            finally
            {
                reader.Close();
                oper.AutoClose();
            }
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of <see cref="Scope"/> having "Anonymous" as default name.
 /// </summary>
 public Scope()
   : base("Anonymous") {
   parent = null;
   variables = new VariableCollection();
   subScopes = new ScopeList();
   RegisterSubScopesEvents();
 }
Пример #5
0
        /// <summary>
        /// 解释Scope
        /// </summary>
        /// <param name="scope"></param>
        /// <param name="dbType"></param>
        /// <param name="paramName"></param>
        /// <param name="handle"></param>
        /// <param name="table"></param>
        /// <param name="entityInfo"></param>
        /// <returns></returns>
        internal static BQLCondition DoScope(Scope scope, DbType dbType, string paramName, BQLCondition handle, BQLTableHandle table, EntityInfoHandle entityInfo)
        {
            ScopeList lstInnerScope = scope.Value1 as ScopeList;

            handle = BQLConditionScope.FillCondition(handle, table, lstInnerScope, entityInfo);
            return(handle);
        }
Пример #6
0
        /// <summary>
        /// 查询是否存在符合条件的记录
        /// </summary>
        /// <param name="scopeList">范围查找的集合</param>
        /// <returns></returns>
        public bool ExistsRecord(ScopeList scopeList)
        {
            if (scopeList.HasInner)
            {
                return(_cdal.ExistsRecord <T>(scopeList));
            }
            ParamList list = null;

            SelectCondition           sc          = GetSelectContant(list, scopeList, CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(CurEntityInfo.PrimaryProperty[0].ParamName));
            string                    sql         = CurEntityInfo.DBInfo.CurrentDbAdapter.GetTopSelectSql(sc, 1);
            bool                      exists      = false;
            Dictionary <string, bool> cacheTables = null;

            if (scopeList.UseCache)
            {
                cacheTables = _oper.DBInfo.QueryCache.CreateMap(CurEntityInfo.TableName);
            }
            using (IDataReader reader = _oper.Query(sql, list, cacheTables))
            {
                if (reader.Read())
                {
                    exists = true;
                }
            }
            return(exists);
        }
Пример #7
0
        /// <summary>
        /// 根据ID删除记录
        /// </summary>
        /// <param name="id">要删除的记录ID</param>
        /// <returns></returns>
        public int DeleteById(object id)
        {
            int ret = -1;

            DeleteCondition con = new DeleteCondition(EntityInfo.DBInfo);

            con.Tables.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatTableName(EntityInfo.TableName));
            ParamList list = new ParamList();

            ScopeList      lstScope = new ScopeList();
            PrimaryKeyInfo pkInfo   = id as PrimaryKeyInfo;

            if (pkInfo == null)
            {
                lstScope.AddEqual(EntityInfo.PrimaryProperty[0].PropertyName, id);
            }
            else
            {
                pkInfo.FillScope(EntityInfo.PrimaryProperty, lstScope, true);
            }
            con.Condition.Append("1=1");
            con.Condition.Append(DataAccessCommon.FillCondition(EntityInfo, list, lstScope));
            Dictionary <string, bool> cacheTables = null;

            cacheTables = _oper.DBInfo.QueryCache.CreateMap(EntityInfo.TableName);

            ret = ExecuteCommand(con.GetSql(true), list, CommandType.Text, cacheTables);
            return(ret);
        }
Пример #8
0
        /// <summary>
        /// 查询符合指定条件的记录条数
        /// </summary>
        /// <param name="scopeList">范围查找的集合</param>
        /// <returns></returns>
        public long SelectCount(ScopeList scopeList)
        {
            if (scopeList.HasInner)
            {
                return(_cdal.SelectCount <T>(scopeList));
            }
            ParamList list = null;

            list = new ParamList();

            string sql   = GetSelectContant(list, scopeList, "count(*)").GetSql(scopeList.UseCache);
            long   count = 0;
            Dictionary <string, bool> cacheTables = null;

            if (scopeList.UseCache)
            {
                cacheTables = _oper.DBInfo.QueryCache.CreateMap(CurEntityInfo.TableName);
            }
            //try
            //{
            using (IDataReader reader = _oper.Query(sql, list, cacheTables))
            {
                if (reader.Read())
                {
                    if (!reader.IsDBNull(0))
                    {
                        count = Convert.ToInt64(reader[0]);
                    }
                }
            }
            return(count);
        }
Пример #9
0
        private static readonly Type compareType = typeof(IComparable);//可比较对象的接口类型

        /// <summary>
        /// 过滤集合
        /// </summary>
        /// <param name="sourceList">源集合</param>
        /// <param name="lstScope">过滤条件</param>
        /// <returns></returns>
        public static IList RowFilter(IList sourceList, ScopeList lstScope)
        {
            if (sourceList.Count <= 0)
            {
                return(sourceList);
            }
            IList retLst  = (IList)Activator.CreateInstance(sourceList.GetType());
            Type  objType = sourceList[0].GetType();
            //初始化属性信息列表
            List <CompareItemInfo> infos = new List <CompareItemInfo>();

            foreach (Scope objScope in lstScope)
            {
                PropertyInfoHandle pInfo = FastValueGetSet.GetPropertyInfoHandle(objScope.PropertyName, objType);
                infos.Add(new CompareItemInfo(pInfo, objScope));
            }
            foreach (object obj in sourceList)
            {
                List <CompareItem> lstCompareItem = new List <CompareItem>();
                //Dictionary<string, Scope>.Enumerator enums = lstScope.GetEnumerator();
                foreach (CompareItemInfo itemInfo in infos)
                {
                    bool resault = IsAccord(itemInfo.PropertyInfo.GetValue(obj), itemInfo.ScopeInfo);
                    lstCompareItem.Add(new CompareItem(resault, itemInfo.ScopeInfo.ConnectType));
                }
                if (IsAllAccord(lstCompareItem))
                {
                    retLst.Add(obj);
                }
            }
            return(retLst);
        }
        /// <summary>
        /// 查询特殊表或者视图
        /// </summary>
        /// <param name="table"></param>
        /// <param name="vParams"></param>
        /// <param name="lstScope"></param>
        /// <param name="objPage"></param>
        /// <returns></returns>
        public DataSet SelectTable(BQLOtherTableHandle table, ScopeList lstScope)
        {
            OnSelect(lstScope);
            BQLDataAccessBase <T> dao = new BQLDataAccessBase <T>();

            return(dao.SelectTable(table, lstScope));
        }
        /// <summary>
        /// 直接查询数据库视图
        /// </summary>
        /// <param name="tableName">表名称</param>
        /// <param name="lstScope">条件</param>
        /// <param name="vParams">字段列表</param>
        /// <param name="lstSort">排序类型</param>
        /// <param name="lstSort">排序</param>
        /// <returns></returns>
        public DataSet SelectTable(string tableName, ScopeList lstScope)
        {
            OnSelect(lstScope);
            BQLDataAccessBase <T> dao = new BQLDataAccessBase <T>();

            return(dao.SelectTable(tableName, lstScope));
        }
Пример #12
0
        /// <summary>
        /// 填充下拉框
        /// </summary>
        /// <param name="ddl">下拉框</param>
        /// <param name="objEntity">填充的实体</param>
        /// <param name="textPrm">显示的字段</param>
        /// <param name="valuePrm">值字段</param>
        public static void FillDorpDown <P>(DropDownList ddl,
                                            string textPrm, string valuePrm, bool hasAll) where P : EntityBase, new()
        {
            BusinessModelBaseForSelect <P> bo = new BusinessModelBaseForSelect <P>();
            ScopeList lstScope = new ScopeList();
            List <P>  lstEnt   = bo.SelectList(lstScope);

            ddl.Items.Clear();
            ListItem item = null;

            if (hasAll)
            {
                item = new ListItem("[全部]", "");
                ddl.Items.Add(item);
            }
            foreach (P obj in lstEnt)
            {
                object tmp = obj[textPrm];
                string txt = tmp == null?"":tmp.ToString();
                tmp = obj[valuePrm];
                string val = tmp == null?"":tmp.ToString();
                item = new ListItem(txt, val);
                ddl.Items.Add(item);
            }
        }
Пример #13
0
        /// <summary>
        /// 查询表
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public List <E> SelectList <E>(ScopeList lstScope)
            where E : EntityBase, new()
        {
            Type                 eType   = typeof(E);
            List <E>             retlist = null;
            BQLEntityTableHandle table   = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            BQLQuery BQL = GetSelectSql(lstScope, table);

            if (!lstScope.HasPage)
            {
                retlist = QueryList <E>(BQL, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
            using (BatchAction ba = _oper.StarBatchAction())
            {
                retlist = QueryPageList <E>(BQL, lstScope.PageContent, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
        }
Пример #14
0
        /// <summary>
        /// 填充子集合
        /// </summary>
        /// <param name="showTable"></param>
        /// <param name="?"></param>
        public static void FillEntityChidList(IList lst, ShowChildItem showTable)
        {
            Stack <BQLEntityTableHandle> stkTables = new Stack <BQLEntityTableHandle>();
            BQLEntityTableHandle         curTable  = showTable.ChildItem;

            while (true)
            {
                stkTables.Push(curTable);
                curTable = curTable.GetParentTable();
                if (CommonMethods.IsNull(curTable) || string.IsNullOrEmpty(curTable.GetPropertyName()))
                {
                    break;
                }
            }
            IEnumerable    curList     = lst;
            Queue <object> lastObjects = new Queue <object>();
            ScopeList      empty       = new ScopeList();

            while (stkTables.Count > 0)
            {
                BQLEntityTableHandle table    = stkTables.Pop();
                ScopeList            lstScope = null;
                if (stkTables.Count == 0)
                {
                    lstScope = showTable.FilterScope;
                }
                else
                {
                    lstScope = empty;
                }
                FillEntityChidList(curList, table.GetPropertyName(), lastObjects, table.GetParentTable().GetEntityInfo().EntityType, lstScope);
                curList     = lastObjects;
                lastObjects = new Queue <object>();
            }
        }
Пример #15
0
        /// <summary>
        /// 查询并填充子类信息
        /// </summary>
        /// <param name="pks"></param>
        /// <param name="mappingInfo"></param>
        /// <param name="dicEntity"></param>
        /// <param name="dao"></param>
        /// <param name="lstParamNames"></param>
        /// <param name="db"></param>
        /// <param name="curObjs"></param>
        /// <param name="filter"></param>
        private static void FillChildReader(Queue <object> pks, EntityMappingInfo mappingInfo, Dictionary <string, List <object> > dicEntity, BQLDbBase dao,
                                            ref List <EntityPropertyInfo> lstParamNames, DBInfo db, Queue <object> curObjs, ScopeList filter)
        {
            EntityInfoHandle childInfo = mappingInfo.TargetProperty.BelongInfo;
            string           fullName  = mappingInfo.TargetProperty.BelongInfo.EntityType.FullName;
            Type             childType = mappingInfo.TargetProperty.BelongInfo.EntityType;
            List <object>    senders   = null;

            while (pks.Count > 0)
            {
                Queue <object> searchPks = GetSearchPKs(pks);
                if (searchPks.Count <= 0)
                {
                    break;
                }

                ScopeList lstScope = new ScopeList();
                lstScope.AddScopeList(filter);
                lstScope.AddIn(mappingInfo.TargetProperty.PropertyName, searchPks);
                using (IDataReader reader = dao.QueryReader(lstScope, childInfo.EntityType))
                {
                    //获取子表的get列表
                    if (lstParamNames == null)
                    {
                        lstParamNames = CacheReader.GenerateCache(reader, childInfo);//创建一个缓存数值列表
                    }


                    while (reader.Read())
                    {
                        string fk = reader[mappingInfo.TargetProperty.ParamName].ToString();
                        if (!dicEntity.TryGetValue(fk, out senders))
                        {
                            continue;
                        }
                        object obj = childInfo.CreateSelectProxyInstance();

                        if (curObjs != null)
                        {
                            curObjs.Enqueue(obj);
                        }
                        CacheReader.FillObjectFromReader(reader, lstParamNames, obj, db);

                        foreach (object sender in senders)
                        {
                            if (mappingInfo.IsParent)
                            {
                                mappingInfo.SetValue(sender, obj);
                            }
                            else
                            {
                                IList lst = (IList)mappingInfo.GetValue(sender);
                                lst.Add(obj);
                            }
                        }
                    }
                }
            }
        }
Пример #16
0
        /// <summary>
        /// 获取全部查询的条件
        /// </summary>
        /// <param name="list">参数列表</param>
        /// <param name="scopeList">范围查找的集合</param>
        /// <returns></returns>
        protected string GetSelectPageContant(ParamList list, ScopeList scopeList)
        {
            SelectCondition condition = new SelectCondition(CurEntityInfo.DBInfo);

            condition.Oper = this._oper;
            condition.Tables.Append(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatTableName(CurEntityInfo.TableName));
            condition.SqlParams.Append(GetSelectParams(scopeList));
            if (scopeList.UseCache)
            {
                condition.CacheTables = CurEntityInfo.DBInfo.QueryCache.CreateMap(CurEntityInfo.TableName);
            }
            condition.Condition.Append("1=1");
            foreach (EntityPropertyInfo ep in CurEntityInfo.PrimaryProperty)
            {
                condition.PrimaryKey.Add(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(ep.ParamName));
            }
            string conditionWhere = "";

            SortList sortList = scopeList.OrderBy;


            if (scopeList != null)
            {
                condition.Condition.Append(DataAccessCommon.FillCondition(CurEntityInfo, list, scopeList));
            }

            if (conditionWhere.Length > 0)
            {
                condition.Condition.Append(conditionWhere);
            }
            //排序方式
            if (sortList != null && sortList.Count > 0)
            {
                string orderBy = GetSortCondition(sortList);
                if (orderBy != "")
                {
                    if (condition.Orders.Length > 0)
                    {
                        condition.Orders.Append("," + orderBy);
                    }
                    else
                    {
                        condition.Orders.Append(orderBy);
                    }
                }
            }
            condition.PageContent = scopeList.PageContent;
            //throw new Exception("");
            condition.DbParamList = list;

            //if (scopeList.UseCache)
            //{

            //    cachetables[CurEntityInfo.DBInfo.CurrentDbAdapter.FormatTableName(CurEntityInfo.TableName)]=true;
            //}

            return(condition.GetSql(true));
        }
        /// <summary>
        /// 查询符合指定条件的记录条数
        /// </summary>
        /// <param name="scpoeList">范围查找的集合</param>
        /// <returns></returns>
        public virtual long SelectCount(ScopeList scpoeList)
        {
            OnSelect(scpoeList);
            DataAccessBaseForSelect <T> entityDao = new DataAccessBaseForSelect <T>();
            long ret = 0;

            ret = entityDao.SelectCount(scpoeList);
            return(ret);
        }
        /// <summary>
        /// 查找(返回集合)
        /// </summary>
        /// <param name="lstScope">范围集合</param>
        /// <returns></returns>
        public virtual List <T> SelectList(ScopeList lstScope)
        {
            OnSelect(lstScope);
            DataAccessBaseForSelect <T> entityDao = new DataAccessBaseForSelect <T>();
            List <T> ret = null;

            ret = entityDao.SelectList(lstScope);
            return(ret);
        }
        /// <summary>
        /// 查询符合指定条件的记录条数
        /// </summary>
        /// <param name="scpoeList">范围查找的集合</param>
        /// <returns></returns>
        public virtual bool ExistsRecord(ScopeList scpoeList)
        {
            OnSelect(scpoeList);
            DataAccessBaseForSelect <T> entityDao = new DataAccessBaseForSelect <T>();
            bool ret = false;

            ret = entityDao.ExistsRecord(scpoeList);
            return(ret);
        }
Пример #20
0
        /// <summary>
        /// 查询数目
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        public static long SelectCount <T>(BQLCondition condition) where T : EntityBase, new()
        {
            ScopeList lstScope = new ScopeList();

            if (!CommonMethods.IsNull(condition))
            {
                lstScope.Add(condition);
            }
            return(SelectCount <T>(lstScope));
        }
Пример #21
0
        /// <summary>
        /// 获取唯一
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="condition">条件</param>
        /// <returns></returns>
        public static T GetUnique <T>(BQLCondition condition) where T : EntityBase, new()
        {
            ScopeList lstScope = new ScopeList();

            if (!CommonMethods.IsNull(condition))
            {
                lstScope.Add(condition);
            }
            return(GetUnique <T>(lstScope));
        }
Пример #22
0
    public override IOperation Apply() {
      ScopeList subScopes = new ScopeList(CurrentScope.SubScopes);

      for (int i = 0; i < NumberOfCopies.Value; i++) {
        foreach (Scope scope in subScopes) {
          CurrentScope.SubScopes.Add(scope.Clone() as IScope);
        }
      }

       return base.Apply();
    }
Пример #23
0
 private Scope(Scope original, Cloner cloner)
   : base(original, cloner) {
   if (original.variables.Count > 0) variables = cloner.Clone(original.variables);
   else variables = new VariableCollection();
   if (original.subScopes.Count > 0) {
     subScopes = cloner.Clone(original.subScopes);
     foreach (IScope child in SubScopes)
       child.Parent = this;
   } else subScopes = new ScopeList();
   RegisterSubScopesEvents();
 }
Пример #24
0
        /// <summary>
        /// 获取唯一
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public static T GetUnique <T>(ScopeList lstScope) where T : EntityBase, new()
        {
            string name = typeof(T).FullName;
            BusinessModelBase <T> bo = DataAccessLoader.GetBoInstance(name) as BusinessModelBase <T>;

            if (bo == null)
            {
                throw new MissingMemberException("找不到:" + name + " 对应的业务类");
            }
            return(bo.GetUnique(lstScope));
        }
Пример #25
0
        public static DataSet Search(string[] searchs, PageContent objPage)
        {
            ScopeList lstScope = new ScopeList();

            lstScope.PageContent = objPage;
            double per = Math.Pow(2, searchs.Length);

            lstScope.ShowProperty.Add(Management.SampleInfo.SampleName.As("SampleName"));
            lstScope.ShowProperty.Add(Management.SampleInfo.SamplingTerrace.As("SamplingTerrace"));
            lstScope.ShowProperty.Add(Management.SampleInfo.SampleNumber.As("SampleNumber"));
            BQLValueItem perValue = BQLValueItem.ToValueItem(0);
            BQLCondition nameCon  = BQLCondition.FalseValue;

            foreach (string search in searchs)
            {
                nameCon  = nameCon | Management.SampleInfo.SampleName.Like(search);
                perValue = perValue + BQL.Case().When(BQL.ToParam("SampleName").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per;
                per     /= 2;
            }
            lstScope.ShowProperty.Add(perValue.As("per1"));
            lstScope.Add(nameCon);
            lstScope.OrderBy.Add(perValue.As("").DESC);

            per      = Math.Pow(2, searchs.Length);
            perValue = BQLValueItem.ToValueItem(0);
            nameCon  = BQLCondition.FalseValue;
            foreach (string search in searchs)
            {
                nameCon  = nameCon | Management.SampleInfo.SamplingTerrace.Like(search);
                perValue = perValue + BQL.Case().When(BQL.ToParam("SamplingTerrace").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per;
                per     /= 2;
            }
            lstScope.ShowProperty.Add(perValue.As("per2"));
            lstScope.Add(nameCon, ConnectType.OR);
            lstScope.OrderBy.Add(perValue.As("").DESC);

            per      = Math.Pow(2, searchs.Length);
            perValue = BQLValueItem.ToValueItem(0);
            nameCon  = BQLCondition.FalseValue;
            foreach (string search in searchs)
            {
                nameCon  = nameCon | Management.SampleInfo.SampleNumber.Like(search);
                perValue = perValue + BQL.Case().When(BQL.ToParam("SampleNumber").IndexOf(search, 0) <= 0).Then(0).Else(1).End *per;
                per     /= 2;
            }
            lstScope.ShowProperty.Add(perValue.As("per3"));
            lstScope.Add(nameCon, ConnectType.OR);
            lstScope.OrderBy.Add(perValue.As("").DESC);

            //lstScope.OrderBy.Add(BQL.ToParam("per1").DESC);
            //lstScope.OrderBy.Add(BQL.ToParam("per2").DESC);
            //lstScope.OrderBy.Add(BQL.ToParam("per3").DESC);
            return(GetContext().Select(lstScope));
        }
Пример #26
0
        public SpanDefinition()
        {
            KeywordsList  = new PatternListList(this);
            OperatorsList = new PatternListList(this);

            Style = new TextStyle.TextStyle();
            KeywordsList.Parent      = this;
            KeywordsList.IsKeyword   = true;
            OperatorsList.Parent     = this;
            OperatorsList.IsOperator = true;
            ScopePatterns            = new ScopeList(this);
        }
Пример #27
0
 public void FillScope(List <EntityPropertyInfo> lstPkInfo, ScopeList lstScope, bool throwException)
 {
     foreach (EntityPropertyInfo info in lstPkInfo)
     {
         object value = this[info.PropertyName];
         if (value == null && throwException)
         {
             throw new KeyNotFoundException("主键属性:" + info.PropertyName + "未赋值");
         }
         lstScope.AddEqual(info.PropertyName, value);
     }
 }
Пример #28
0
        /// <summary>
        /// 范围更新(慎用)
        /// </summary>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public int UpdateByScope(T obj, ScopeList lstScope)
        {
            int  ret       = 0;
            bool conUpdate = this.obj.BeforeUpdateByScope(obj, lstScope, null, false);

            if (conUpdate)
            {
                ret = GetBaseContext().Update(obj, lstScope, null, false);
            }
            this.obj.AfterUpdateByScope(ret, obj, lstScope, null, false);
            return(ret);
        }
Пример #29
0
        /// <summary>
        /// 范围删除(慎用)
        /// </summary>
        /// <param name="lstScope"></param>
        /// <returns></returns>
        public int DeleteByScope(ScopeList lstScope)
        {
            int  ret       = 0;
            bool conUpdate = this.obj.BeforeDeleteByScope(lstScope);

            if (conUpdate)
            {
                ret = GetBaseContext().Delete(null, lstScope, false);
            }
            this.obj.AfterDeleteByScope(ret, lstScope);
            return(ret);
        }
Пример #30
0
        /// <summary>
        /// 获取本次查询需要显示的字段集合
        /// </summary>
        /// <param name="lstScope">范围查询集合</param>
        /// <returns></returns>
        private static string GetSelectParams(ScopeList lstScope)
        {
            if (lstScope == null)
            {
                return(AllParamNames);
            }

            StringBuilder ret = new StringBuilder();

            BQLEntityTableHandle table = CurEntityInfo.DBInfo.FindTable(typeof(T));

            if (CommonMethods.IsNull(table))
            {
                CurEntityInfo.DBInfo.ThrowNotFondTable(typeof(T));
            }
            List <BQLParamHandle> propertyNames = lstScope.GetShowProperty(table);


            if (propertyNames.Count > 0)
            {
                foreach (BQLParamHandle property in propertyNames)
                {
                    BQLEntityParamHandle eproperty = property as BQLEntityParamHandle;
                    if (CommonMethods.IsNull(eproperty))
                    {
                        continue;
                    }
                    EntityPropertyInfo info = eproperty.PInfo;
                    if (info != null)
                    {
                        ret.Append(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName) + ",");
                    }
                }
            }
            else
            {
                foreach (EntityPropertyInfo info in CurEntityInfo.PropertyInfo)
                {
                    if (info != null)
                    {
                        ret.Append(CurEntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName) + ",");
                    }
                }
            }


            if (ret.Length > 0)
            {
                return(ret.ToString(0, ret.Length - 1));
            }
            return(AllParamNames);
        }
Пример #31
0
        /// <summary>
        /// 执行sql语句,返回Reader
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="objPage">分页对象</param>
        public IDataReader QueryReader(ScopeList lstScope, Type tableType)
        {
            BQLEntityTableHandle table = _oper.DBInfo.FindTable(tableType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(tableType);
            }

            BQLQuery BQL = GetSelectSql(lstScope, table);

            return(QueryReader(BQL, null, lstScope.UseCache));
        }
Пример #32
0
        /// <summary>
        /// 填充子属性列表
        /// </summary>
        /// <param name="lst"></param>
        /// <param name="childName"></param>
        public static void FillEntityChidList(IList lst, ScopeList lstScope)
        {
            ShowChildCollection childs = lstScope.ShowChild;

            if (childs == null)
            {
                return;
            }
            foreach (ShowChildItem showTable in childs)
            {
                FillEntityChidList(lst, showTable);
            }
        }
        //----< display results of Scope List >-----------------------
        static public string showScope(ScopeList scopeList)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("[");
            stringBuilder.Append(scopeList[0]);
            for (int i = 1; i < scopeList.Count; i++)
            {
                stringBuilder.Append(" : " + scopeList[i]);
            }
            stringBuilder.Append("]");
            return(stringBuilder.ToString());
        }
Пример #34
0
    public override IOperation Apply() {
      ScopeList parents = new ScopeList();
      ScopeList offspring = new ScopeList();

      // split parents and offspring
      foreach (var scope in CurrentScope.SubScopes) {
        parents.AddRange(scope.SubScopes.Take(scope.SubScopes.Count - 1));
        offspring.AddRange(scope.SubScopes.Last().SubScopes);
      }

      CurrentScope.SubScopes.Clear();

      // attention: assumes that parents are distinct
      // distinction might cause a too small reference set (e.g. reference set = {1, 2, 2, 2,..., 2} -> union = {1, 2}

      var orderedParents = Maximization.Value ? parents.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
                                                parents.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
      var orderedOffspring = Maximization.Value ? offspring.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
                                                  offspring.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);

      CurrentScope.SubScopes.AddRange(orderedParents);

      double worstParentQuality = (orderedParents.Last().Variables[QualityParameter.ActualName].Value as DoubleValue).Value;

      var hasBetterQuality = Maximization.Value ? (Func<IScope, bool>)(x => { return (x.Variables[QualityParameter.ActualName].Value as DoubleValue).Value > worstParentQuality; }) :
                                                  (Func<IScope, bool>)(x => { return (x.Variables[QualityParameter.ActualName].Value as DoubleValue).Value < worstParentQuality; });

      // is there any offspring better than the worst parent?
      if (orderedOffspring.Any(hasBetterQuality)) {
        // produce the set union
        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), SimilarityCalculatorParameter.ActualValue);
        if (union.Count() > orderedParents.Count()) {
          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
                                                  union.OrderBy(x => x.Variables[QualityParameter.ActualName].Value);
          CurrentScope.SubScopes.Replace(orderedUnion.Take(ReferenceSetSize.Value));
          NewSolutions.Value = true;
        }
      }

      return base.Apply();
    }
Пример #35
0
 public Scope(string name, string description)
   : base(name, description) {
   parent = null;
   variables = new VariableCollection();
   subScopes = new ScopeList();
   RegisterSubScopesEvents();
 }
Пример #36
0
    public override IOperation Apply() {
      bool dominateOnEqualQualities = DominateOnEqualQualitiesParameter.ActualValue.Value;
      bool[] maximization = MaximizationParameter.ActualValue.ToArray();
      double[][] qualities = QualitiesParameter.ActualValue.Select(x => x.ToArray()).ToArray();
      if (qualities == null) throw new InvalidOperationException(Name + ": No qualities found.");

      IScope scope = ExecutionContext.Scope;
      int populationSize = scope.SubScopes.Count;

      List<ScopeList> fronts = new List<ScopeList>();
      Dictionary<IScope, List<int>> dominatedScopes = new Dictionary<IScope, List<int>>();
      int[] dominationCounter = new int[populationSize];
      ItemArray<IntValue> rank = new ItemArray<IntValue>(populationSize);

      for (int pI = 0; pI < populationSize - 1; pI++) {
        IScope p = scope.SubScopes[pI];
        List<int> dominatedScopesByp;
        if (!dominatedScopes.TryGetValue(p, out dominatedScopesByp))
          dominatedScopes[p] = dominatedScopesByp = new List<int>();
        for (int qI = pI + 1; qI < populationSize; qI++) {
          DominationResult test = Dominates(qualities[pI], qualities[qI], maximization, dominateOnEqualQualities);
          if (test == DominationResult.Dominates) {
            dominatedScopesByp.Add(qI);
            dominationCounter[qI] += 1;
          } else if (test == DominationResult.IsDominated) {
            dominationCounter[pI] += 1;
            if (!dominatedScopes.ContainsKey(scope.SubScopes[qI]))
              dominatedScopes.Add(scope.SubScopes[qI], new List<int>());
            dominatedScopes[scope.SubScopes[qI]].Add(pI);
          }
          if (pI == populationSize - 2
            && qI == populationSize - 1
            && dominationCounter[qI] == 0) {
            rank[qI] = new IntValue(0);
            AddToFront(scope.SubScopes[qI], fronts, 0);
          }
        }
        if (dominationCounter[pI] == 0) {
          rank[pI] = new IntValue(0);
          AddToFront(p, fronts, 0);
        }
      }
      int i = 0;
      while (i < fronts.Count && fronts[i].Count > 0) {
        ScopeList nextFront = new ScopeList();
        foreach (IScope p in fronts[i]) {
          List<int> dominatedScopesByp;
          if (dominatedScopes.TryGetValue(p, out dominatedScopesByp)) {
            for (int k = 0; k < dominatedScopesByp.Count; k++) {
              int dominatedScope = dominatedScopesByp[k];
              dominationCounter[dominatedScope] -= 1;
              if (dominationCounter[dominatedScope] == 0) {
                rank[dominatedScope] = new IntValue(i + 1);
                nextFront.Add(scope.SubScopes[dominatedScope]);
              }
            }
          }
        }
        i += 1;
        fronts.Add(nextFront);
      }

      RankParameter.ActualValue = rank;

      scope.SubScopes.Clear();

      for (i = 0; i < fronts.Count; i++) {
        Scope frontScope = new Scope("Front " + i);
        foreach (var p in fronts[i])
          frontScope.SubScopes.Add(p);
        if (frontScope.SubScopes.Count > 0)
          scope.SubScopes.Add(frontScope);
      }
      return base.Apply();
    }