Esempio n. 1
0
        private RiCi FindRowColumn(DataTable dt, Regex re)
        {
            Int32 maxCnt = 16; // количество первых строчек для поиска
            RiCi  rici   = new RiCi {
                RowIndex = -1, ColumnIndex = -1
            };

            if (dt != null)
            {
                // ищем только в первых строчках пока не найдём.
                for (int ri = 0; (ri < Math.Min(dt.Rows.Count, maxCnt)) && (rici.RowIndex == -1); ri++)
                {
                    DataRow dr = dt.Rows[ri];
                    for (int ci = 0; ci < dt.Columns.Count; ci++)
                    {
                        DataColumn dc = dt.Columns[ci];
                        if ((dr[dc] != DBNull.Value) && (re.IsMatch((String)dr[dc])))
                        {
                            rici.RowIndex    = ri;
                            rici.ColumnIndex = ci;
                            break;
                        }
                    }
                }
            }
            return(rici);
        }
Esempio n. 2
0
        private Boolean FindColunm(DataTable dt, String columnName, String pattern)
        {
            Boolean isFinded = false;
            RiCi    rici     = FindRowColumn(dt, new Regex(pattern));

            if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
            {
                DataColumn column = dt.Columns[rici.ColumnIndex];
                if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                {
                    column.ColumnName = columnName;
                    column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                }
                isFinded = true;
            }
            return(isFinded);
        }
Esempio n. 3
0
        private void FindNeededColumns()
        {
            if (ParsingTables != null)
            {
                int ti = 0;
                while (ti < ParsingTables.Tables.Count)
                {
                    DataTable dt = ParsingTables.Tables[ti];
                    // в таблице должно быть не меньше 4-х столбцов

                    /*
                     * if (dt.Columns.Count < 4)
                     * {
                     *  ParsingTables.Tables.Remove(dt);
                     *  continue;
                     * }
                     */

                    Boolean isFinded = false;

                    RiCi rici = FindRowColumn(dt, new Regex(@"(?i)(международное\s*непатентованное\s*наименование)|(мнн)|(фарм\.?\s*группа)"));
                    if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    {
                        DataColumn column = dt.Columns[rici.ColumnIndex];
                        if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                        {
                            column.ColumnName = "МНН";
                            column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                        }
                        isFinded = true;
                    }
                    //rici = FindRowColumn(dt, new Regex(@"(?i)(торговое)|(наименование)"));
                    //if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    //{
                    //    DataColumn column = dt.Columns[rici.ColumnIndex];
                    //    if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                    //    {
                    //        column.ColumnName = "Наименование";
                    //        column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                    //    }
                    //    isFinded = true;
                    //}
                    rici = FindRowColumn(dt, new Regex("([Оо]писание)|([Хх]арактеристика)|([Фф]орма)|([Дд]озировка)|([Уу]паковка)"));
                    if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    {
                        DataColumn column = dt.Columns[rici.ColumnIndex];
                        if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                        {
                            column.ColumnName = "Описание";
                            column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                        }
                        isFinded = true;
                    }
                    rici = FindRowColumn(dt, new Regex("([Ее]д\\.)|([Ее]д\\.? *[Ии]зм.*)"));
                    if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    {
                        DataColumn column = dt.Columns[rici.ColumnIndex];
                        if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                        {
                            column.ColumnName = "Ед. изм.";
                            column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                        }
                        isFinded = true;
                    }
                    rici = FindRowColumn(dt, new Regex("([Кк]ол *- *во)|([Кк]оличество)"));
                    if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    {
                        DataColumn column = dt.Columns[rici.ColumnIndex];
                        if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                        {
                            column.ColumnName = "Кол-во";
                            column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                        }
                        isFinded = true;
                    }
                    //rici = FindRowColumn(dt, new Regex(@"(?i)(цена)"));
                    //if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    //{
                    //    DataColumn column = dt.Columns[rici.ColumnIndex];
                    //    if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                    //    {
                    //        column.ColumnName = "Цена с НДС";
                    //        column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                    //    }
                    //    isFinded = true;
                    //}
                    //rici = FindRowColumn(dt, new Regex(@"(?i)(сумма)"));
                    //if (rici.RowIndex >= 0 && rici.ColumnIndex >= 0)
                    //{
                    //    DataColumn column = dt.Columns[rici.ColumnIndex];
                    //    if (!column.ExtendedProperties.Contains("HeadRowIndex"))
                    //    {
                    //        column.ColumnName = "Сумма с НДС";
                    //        column.ExtendedProperties.Add("HeadRowIndex", rici.RowIndex);
                    //    }
                    //    isFinded = true;
                    //}

                    if (!isFinded)
                    {
                        ParsingTables.Tables.Remove(dt);
                    }
                    else
                    {
                        ti++;
                    }
                }
            }
        }