Example #1
0
 public static MDataTable[] Split(MDataTable table, object whereObj)
 {
     MDataTable[] mdt2 = new MDataTable[2];
     mdt2[0] = table.GetSchema(false);
     mdt2[1] = table.GetSchema(false);
     if (table.Rows.Count > 0)
     {
         if (Convert.ToString(whereObj).Trim() == "")
         {
             mdt2[0] = table;
         }
         else
         {
             List <TFilter> group2  = null;
             List <TFilter> filters = GetTFilter(whereObj, table.Columns, out group2);
             if (filters.Count > 0)
             {
                 for (int i = 0; i < table.Rows.Count; i++)
                 {
                     MDataRow row = table.Rows[i];
                     if (CompareMore(row, filters) && (group2.Count == 0 || CompareMore(row, group2)))
                     {
                         mdt2[0].Rows.Add(row, false);
                     }
                     else
                     {
                         mdt2[1].Rows.Add(row, false);
                     }
                 }
             }
         }
     }
     return(mdt2);
 }
Example #2
0
 public static MDataTable[] Split(MDataTable table, object whereObj)
 {
     MDataTable[] mdt2 = new MDataTable[2];
     mdt2[0] = table.GetSchema(false);
     mdt2[1] = table.GetSchema(false);
     if (table.Rows.Count > 0)
     {
         if (Convert.ToString(whereObj).Trim() == "")
         {
             mdt2[0] = table;
         }
         else
         {
             TFilter[] filters = GetTFilter(whereObj, table.Columns);
             if (filters.Length > 0)
             {
                 for (int i = 0; i < table.Rows.Count; i++)
                 {
                     MDataRow row = table.Rows[i];
                     if (CompareMore(row, filters))
                     {
                         mdt2[0].Rows.Add(row, false);
                     }
                     else
                     {
                         mdt2[1].Rows.Add(row, false);
                     }
                 }
             }
         }
     }
     return(mdt2);
 }
Example #3
0
        public static MDataTable Select(MDataTable table, int pageIndex, int pageSize, object whereObj, params object[] selectColumns)
        {
            if (table == null)
            {
                return(null);
            }
            MDataTable sTable = table.GetSchema(true);

            sTable.RecordsAffected = table.Rows.Count;
            if (table.Rows.Count == 0)                    // 正常情况下,看是否需要处理列移除
            {
                FilterColumns(ref sTable, selectColumns); //列查询过滤
                return(sTable);
            }
            MDataRowCollection findRows = FindAll(table, whereObj);

            if (findRows != null)
            {
                sTable.RecordsAffected = findRows.Count;    //设置记录总数
                FilterPager(findRows, pageIndex, pageSize); //进行分页筛选,再克隆最后的数据。

                for (int i = 0; i < findRows.Count; i++)
                {
                    if (i < findRows.Count)//内存表时(表有可能在其它线程被清空)
                    {
                        MDataRow row = findRows[i];
                        if (row == null)
                        {
                            break;
                        }
                        sTable.NewRow(true).LoadFrom(row);
                    }
                }

                findRows = null;
            }
            if (selectColumns != null && selectColumns.Length > 0)
            {
                FilterColumns(ref sTable, selectColumns);//列查询过滤,由于查询的条件可能包含被移除列,所以只能在最后才过滤
            }
            //进行条件查询
            return(sTable);
        }
        public static MDataTable[] Split(MDataTable table, object whereObj)
        {
            MDataTable[] mdt2 = new MDataTable[2];
            mdt2[0] = table.GetSchema(false);
            mdt2[1] = table.GetSchema(false);
            if (table.Rows.Count > 0)
            {
                if (Convert.ToString(whereObj).Trim() == "")
                {
                    mdt2[0] = table;
                }
                else
                {

                    TFilter[] filters = GetTFilter(whereObj, table.Columns);
                    if (filters.Length > 0)
                    {
                        foreach (MDataRow row in table.Rows)
                        {
                            if (CompareMore(row, filters))
                            {
                                mdt2[0].Rows.Add(row, false);
                            }
                            else
                            {
                                mdt2[1].Rows.Add(row, false);
                            }
                        }
                    }
                }
            }
            return mdt2;
        }
        public static MDataTable Select(MDataTable table, int pageIndex, int pageSize, object whereObj, params object[] selectColumns)
        {
            if (table == null)
            {
                return null;
            }
            MDataTable sTable = table.GetSchema(true);
            sTable.RecordsAffected = table.Rows.Count;
            if (table.Rows.Count == 0)// 正常情况下,看是否需要处理列移除
            {
                FilterColumns(ref sTable, selectColumns);//列查询过滤
                return sTable;
            }
            List<MDataRow> findRows = FindAll(table, whereObj);
            if (findRows != null)
            {
                FilterPager(findRows, pageIndex, pageSize);//进行分页筛选,再克隆最后的数据。
                foreach (MDataRow mr in findRows)
                {
                    sTable.NewRow(true).LoadFrom(mr);
                }
                findRows = null;

            }
            if (selectColumns != null && selectColumns.Length > 0)
            {
                FilterColumns(ref sTable, selectColumns);//列查询过滤,由于查询的条件可能包含被移除列,所以只能在最后才过滤
            }
            //进行条件查询
            return sTable;
        }