コード例 #1
0
        /// <summary>
        /// 递归生成过滤条件(字符串)
        /// </summary>
        /// <param name="parentGroup"></param>
        /// <param name="tableName"></param>
        /// <param name="jsonos"></param>
        /// <param name="cols"></param>
        /// <param name="sqlBuilder"></param>
        private void RecurseFilter(string parentGroup, string tableName, IEnumerable <JObject> jsonos, IEnumerable <FapColumn> cols, StringBuilder sqlBuilder)
        {
            foreach (var jsono in jsonos)
            {
                string         group = jsono.GetValue("groupOp").ToString();//AND、OR
                List <JObject> rules = jsono.GetValue("rules").Children <JObject>().ToList();
                int            i     = 0;
                if (rules.Count > 0)
                {
                    StringBuilder empSb = new StringBuilder();
                    foreach (JObject o in rules)
                    {
                        string colName = o.GetValue("field").ToString();
                        string op      = o.GetValue("op").ToString();
                        string data    = o.GetValue("data").ToString();
                        //下拉框 任意 跳过此条件
                        if (data.EqualsWithIgnoreCase("fapany"))
                        {
                            continue;
                        }
                        var    fcol  = _dbContext.Column(tableName, colName);
                        string field = tableName + "." + colName;
                        if (!string.IsNullOrEmpty(op))// && !string.IsNullOrEmpty(data))
                        {
                            i++;
                            //field = executeField(field);
                            data = ExecuteData(field, op, data);
                            if (i != 1)
                            {
                                empSb.Append(" ").Append(group).Append(" ");
                            }
                            empSb.Append(field).Append(Q2Oper[op]).Append(data);
                        }
                    }
                    if (empSb.Length > 0)
                    {
                        sqlBuilder.Append("(");
                        sqlBuilder.Append(empSb.ToString());
                        sqlBuilder.Append(")");
                    }
                    //处理AND和OR
                    sqlBuilder.Append(" ").Append(parentGroup).Append(" ");
                }

                //子条件
                if (jsono.GetValue("groups") != null)
                {
                    List <JObject> subs = jsono.GetValue("groups").Children <JObject>().ToList();
                    //foreach (var sub in subs)
                    //{
                    //    RecurseFilterCondition(tableName, filterConditions, sub);
                    //}

                    RecurseFilter(group, tableName, subs, cols, sqlBuilder);
                }
            }
        }
コード例 #2
0
ファイル: GridFormService.cs プロジェクト: zeroyou/FapCore3.0
        private void DataProcessed(Dictionary <string, string> ccSqlDics, string tableName, IEnumerable <GroupBy> groupBys, IEnumerable <dynamic> dataList, List <Aggregate> agglist)
        {
            var groupBy    = groupBys.First();
            var dataResult = dataList as IEnumerable <IDictionary <string, object> >;

            foreach (var ccSqlDic in ccSqlDics)
            {
                string colName = ccSqlDic.Key;
                var    dcolumn = _dbContext.Column(tableName, colName);
                var    dics    = _dbContext.Dictionarys(dcolumn.ComboxSource);
                var    ca      = agglist.First(a => a.Field == colName);
                foreach (var dic in dics)
                {
                    agglist.Add(new Aggregate {
                        Field = dic.Code, AggType = ca.AggType, Alias = dic.Name, ChartType = ca.ChartType
                    });
                }
                agglist.Remove(ca);
                var ccDataList = _dbContext.QueryOriSql(ccSqlDic.Value);
                dataResult.ToList().ForEach((di) =>
                {
                    foreach (var dic in dics)
                    {
                        var data = ccDataList.FirstOrDefault(d => ((d as IDictionary <string, object>)[groupBy.Alias]?.ToString() ?? "").EqualsWithIgnoreCase((di[groupBy.Alias]?.ToString() ?? "")) &&
                                                             ((d as IDictionary <string, object>)[colName]?.ToString() ?? "").EqualsWithIgnoreCase(dic.Code));
                        di[dic.Name] = data?.C ?? 0;
                    }
                });
            }
            if (groupBys.Count() > 1)
            {
                foreach (var gb in groupBys)
                {
                    if (gb.Field == groupBy.Field)
                    {
                        continue;
                    }
                    agglist.Add(new Aggregate {
                        Field = gb.Field, AggType = AggregateEnum.COUNT, Alias = gb.Alias, ChartType = "bar"
                    });
                }
            }
            var column = _dbContext.Column(tableName, groupBy.Field);

            if (column.CtrlType == FapColumn.CTRL_TYPE_COMBOBOX && column.ComboxSource.IsPresent())
            {
                var dics = _dbContext.Dictionarys(column.ComboxSource);
                dataResult.ToList().ForEach((di) =>
                {
                    di[groupBy.Alias] = dics.FirstOrDefault(d => d.Code == di[groupBy.Alias]?.ToString())?.Name ?? "未知";
                });
            }
            else if (column.CtrlType == FapColumn.CTRL_TYPE_REFERENCE)
            {
                string refSql = $"select {column.RefID} Code, {column.RefName} Name from {column.RefTable} where {column.RefID} in @Ids";
                var    Ids    = dataList.Select(d => (d as IDictionary <string, object>)[groupBy.Alias]);
                var    refs   = _dbContext.Query(refSql, new DynamicParameters(new { Ids }));
                dataResult.ToList().ForEach((di) =>
                {
                    di[groupBy.Alias] = refs.FirstOrDefault(d => d.Code == di[groupBy.Alias]?.ToString())?.Name ?? "未知";
                });
            }
        }