コード例 #1
0
ファイル: SqlReportFile.cs プロジェクト: ridgew/fmq
        /// <summary>
        /// 提取所有符合条件的数据项
        /// </summary>
        public List <ReportRow> QueryMatchItems(Predicate <ReportRow> match = null)
        {
            List <ReportRow> items = new List <ReportRow>();

            using (var c = new ReaderCursor(_txtContent))
            {
                c.SkipLine(ReportFile_HeadLine_Length);
                int chrPeek = -1;
                while ((chrPeek = c.__r__.Peek()) != -1)
                {
                    if (chrPeek == (int)'\r' || chrPeek == (int)'\n')
                    {
                        break;
                    }

                    ReportRow item = new ReportRow();
                    for (int i = 0, j = Columns.Count; i < j; i++)
                    {
                        var col = Columns[i];
                        if (i < j - 1)
                        {
                            char[] varChars  = new char[col.ColumnLength];
                            int    totalRead = c.__r__.Read(varChars, 0, varChars.Length);
                            item[col.ColumnName] = (new string(varChars, 0, totalRead)).TrimEnd();
                            c.SkipColumn(ReportFile_Space_Length);
                        }
                        else
                        {
                            StringBuilder sb       = new StringBuilder();
                            int           readChar = -1;
                            while ((readChar = c.__r__.Read()) != -1)
                            {
                                char chr = (char)readChar;
                                if (chr == '\n')
                                {
                                    break;
                                }
                                else
                                {
                                    sb.Append(chr);
                                }
                            }
                            item[col.ColumnName] = sb.ToString().TrimEnd();
                            continue;
                        }
                    }
                    if (match == null || match(item))
                    {
                        items.Add(item);
                    }
                }
            }
            return(items);
        }
コード例 #2
0
        public void FindRowAction(Action <ReportRow> rowAct, bool onErrorBreak = false)
        {
            Exception lastError = null;

            using (var c = new ReaderCursor(_txtContent))
            {
                c.SkipLine(ReportFile_HeadLine_Length);
                int chrPeek = -1;
                while ((chrPeek = c.__r__.Peek()) != -1)
                {
                    if (chrPeek == (int)'\r' || chrPeek == (int)'\n')
                    {
                        break;
                    }

                    ReportRow item = new ReportRow();
                    for (int i = 0, j = Columns.Count; i < j; i++)
                    {
                        var col = Columns[i];
                        if (i < j - 1)
                        {
                            char[] varChars  = new char[col.ColumnLength];
                            int    totalRead = c.__r__.Read(varChars, 0, varChars.Length);
                            item[col.ColumnName] = (new string(varChars, 0, totalRead)).TrimEnd();
                            c.SkipColumn(ReportFile_Space_Length);
                        }
                        else
                        {
                            StringBuilder sb       = new StringBuilder();
                            int           readChar = -1;
                            while ((readChar = c.__r__.Read()) != -1)
                            {
                                char chr = (char)readChar;
                                if (chr == '\n')
                                {
                                    break;
                                }
                                else
                                {
                                    sb.Append(chr);
                                }
                            }
                            item[col.ColumnName] = sb.ToString().TrimEnd();
                            continue;
                        }
                    }

                    try
                    {
                        rowAct(item);
                    }
                    catch (Exception ex)
                    {
                        lastError = ex;
                        if (onErrorBreak)
                        {
                            break;
                        }
                    }
                }
            }

            if (lastError != null)
            {
                throw lastError;
            }
        }