コード例 #1
0
ファイル: MDataTableFilter.cs プロジェクト: zjy040191/cyqdata
        public static MDataRowCollection FindAll(MDataTable table, object whereObj)
        {
            if (table != null && table.Rows.Count > 0)
            {
                MDataRowCollection findRows = new MDataRowCollection();
                string where = Convert.ToString(whereObj).Trim();
                if (where == "" || where == "1=1")
                {
                    findRows.AddRange(table.Rows);
                    return(findRows);
                }
                string whereStr = SqlFormat.GetIFieldSql(whereObj);
                string orderby;
                SplitWhereOrderby(ref whereStr, out orderby);

                List <TFilter>   group2  = null;
                List <TFilter>   filters = GetTFilter(whereStr, table.Columns, out group2);
                IList <MDataRow> rows    = table.Rows;
                if (filters.Count > 0)
                {
                    rows = table.Rows.FindAll(delegate(MDataRow row)
                    {
                        return(CompareMore(row, filters) && (group2.Count == 0 || CompareMore(row, group2)));
                    }
                                              );
                }
                findRows.AddRange(rows);                              //添加找到的行。
                filters = null;
                if (!string.IsNullOrEmpty(orderby) && rows.Count > 1) //进行数组排序
                {
                    findRows.Sort(orderby);
                    //MDataRowCollection sortRows = new MDataRowCollection();
                    //sortRows.AddRange(rows);
                    //sortRows.Sort(orderby);
                    //return sortRows;
                }
                return(findRows);
            }
            return(null);
        }
コード例 #2
0
ファイル: MDataTableFilter.cs プロジェクト: zjy040191/cyqdata
        public static MDataRow FindRow(MDataTable table, object whereObj)
        {
            if (table.Rows.Count > 0)
            {
                if (Convert.ToString(whereObj).Trim() == "")
                {
                    return(table.Rows[0]);
                }
                string whereStr = SqlFormat.GetIFieldSql(whereObj);
                string orderby;
                SplitWhereOrderby(ref whereStr, out orderby);
                MDataRowCollection sortRows = null;
                if (!string.IsNullOrEmpty(orderby) && table.Rows.Count > 1)//进行数组排序
                {
                    sortRows = new MDataRowCollection();
                    sortRows.AddRange(table.Rows);
                    sortRows.Sort(orderby);
                }
                List <TFilter> group2  = null;
                List <TFilter> filters = GetTFilter(whereStr, table.Columns, out group2);

                if (filters.Count > 0)
                {
                    if (sortRows == null)
                    {
                        sortRows = table.Rows;
                    }
                    for (int i = 0; i < sortRows.Count; i++)
                    {
                        if (CompareMore(sortRows[i], filters) && (group2.Count == 0 || CompareMore(sortRows[i], group2)))
                        {
                            return(sortRows[i]);
                        }
                    }
                }
            }
            return(null);
        }