Example #1
0
        public MDataTable ExeMDataTable()
        {
            int        count = 0;
            MDataTable dt    = action.Select(1, topN, whereSql, out count);

            if (fieldItems.Count > 0)
            {
                //处理 a as B 的列。
                Dictionary <string, string> dic = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                foreach (string field in fieldItems)
                {
                    string[] items = field.Trim().Split(' ');
                    dic.Add(items[0], items.Length > 1 ? items[items.Length - 1] : "");
                }
                for (int i = dt.Columns.Count - 1; i >= 0; i--)
                {
                    string columnName = dt.Columns[i].ColumnName;
                    if (!dic.ContainsKey(columnName))
                    {
                        dt.Columns.RemoveAt(i);
                    }
                    else if (dic[columnName] != "")//处理 a as B 的列。
                    {
                        dt.Columns[i].ColumnName = dic[columnName];
                    }
                }
            }
            if (IsDistinct)
            {
                dt.Distinct();
            }
            return(dt);
        }
Example #2
0
        public MDataTable ExeMDataTable()
        {
            int        count = 0;
            MDataTable dt    = action.Select(1, ss.TopN, ss.Where, out count);

            if (ss.FieldItems.Count > 0)
            {
                //处理 a as B 的列。
                Dictionary <string, string> dic = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);
                string name, asName;
                foreach (string field in ss.FieldItems)
                {
                    string[] items = field.Trim().Split(' ');
                    name   = items[0];
                    asName = items[items.Length - 1];
                    if (!dic.ContainsKey(name))
                    {
                        dic.Add(items[0], items.Length > 1 ? asName : "");
                    }
                    else if (items.Length > 1 && dt.Columns.Contains(name))//同一个字段as多次
                    {
                        MCellStruct newCell = dt.Columns[name].Clone();
                        newCell.ColumnName = asName;
                        dt.Columns.Add(newCell);
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            dt.Rows[i].Set(asName, dt.Rows[i][name].Value);
                        }
                        dic.Add(asName, "");
                    }
                }
                for (int i = dt.Columns.Count - 1; i >= 0; i--)
                {
                    string columnName = dt.Columns[i].ColumnName;
                    if (!dic.ContainsKey(columnName))
                    {
                        dt.Columns.RemoveAt(i);
                    }
                    else if (dic[columnName] != "")//处理 a as B 的列。
                    {
                        dt.Columns[i].ColumnName = dic[columnName];
                    }
                }
            }
            if (ss.IsDistinct)
            {
                dt.Distinct();
            }
            return(dt);
        }
Example #3
0
        public MDataTable ExeMDataTable()
        {
            int        count = 0;
            MDataTable dt    = action.Select(1, topN, whereSql, out count);

            if (fieldItems.Count > 0)
            {
                for (int i = dt.Columns.Count - 1; i >= 0; i--)
                {
                    if (!fieldItems.Contains(dt.Columns[i].ColumnName.ToLower()))
                    {
                        dt.Columns.RemoveAt(i);
                    }
                }
            }
            if (IsDistinct)
            {
                dt.Distinct();
            }
            return(dt);
        }