public List <RegExpMatchResult> GetRegExpMatchResults(string text)
        {
            IEnumerable <DataRow> listRegExps = null;

            //Then for every regExp highlight
            if (_viewBilling._filterId > -1)
            {
                //Find this filter all groups
                var filter = _views.MainForm.datasetBilling.ICDFilters.FindByFilterID(_viewBilling._filterId);
                if (filter != null && !filter.IsGroupIDsNull())
                {
                    var groupsIDsString = filter.GroupIDs;

                    var groupsIDs = groupsIDsString.Split(',');

                    listRegExps = from @group in groupsIDs
                                  from BillingDataSet.RegexpToGroupsRow item in _views.MainForm.datasetBilling.RegexpToGroups.Select("GroupID = " + @group)
                                  select _views.MainForm.datasetMain.RegExp.FindByID(item.ID /* RegExpID */);
                }
            }

            if (listRegExps == null)
            {
                listRegExps = _views.MainForm.datasetMain.RegExp.Rows.Cast <DataRow>();
            }

            ///////////////////////////////////////////////////////////////////////////////

            var processor = new RegExpProcessor(listRegExps);
            var matches   = processor.GetAllMatches(text);

            return(matches);
        }
        protected void FillValues(ListBox lbValues, string strColumn)
        {
            var processor = new RegExpProcessor(MainForm.ViewsManager.MainForm.datasetMain.RegExp);

            lbPrefixValues.Items.Clear();
            lbPrefixValues.Items.AddRange(processor.Items.Select(x => x.PrefixMatch)
                                          .Distinct()
                                          .Cast <object>()
                                          .ToArray());

            lbSuffixValues.Items.Clear();
            lbSuffixValues.Items.AddRange(processor.Items.Select(x => x.SuffixMatch)
                                          .Distinct()
                                          .Cast <object>()
                                          .ToArray());
        }
        public void UpdateText(string text, bool highlight)
        {
            if (textBox.IsDisposed)
            {
                return;
            }

            ClearStyleCache();

            ///////////////////////////////////////////////////////////////////////////////

            bool scrollToFirstMatch;

            if (text != _originalNoteText)
            {
                _originalNoteText = text;

                textBox.Text = text;

                _currentNoteText = textBox.Text;

                scrollToFirstMatch = true;
            }
            else
            {
                ClearHighlights();

                scrollToFirstMatch = false;
            }

            ///////////////////////////////////////////////////////////////////////////////

            List <MainDataSet.RegExpRow> regExps;

            if (_viewBilling._filterId > -1)
            {
                regExps = new List <MainDataSet.RegExpRow>();

                //Find this filter all groups
                var      groupsIDsString = _views.MainForm.datasetBilling.ICDFilters.FindByFilterID(_viewBilling._filterId).GroupIDs;
                string[] groupsIDs       = groupsIDsString.Split(',');

                foreach (var group in groupsIDs)
                {
                    foreach (BillingDataSet.RegexpToGroupsRow item in _views.MainForm.datasetBilling.RegexpToGroups.Select("GroupID = " + group))
                    {
                        var dataRowRegExp = _views.MainForm.datasetMain.RegExp.FindByID(item.ID);
                        if (dataRowRegExp != null && dataRowRegExp.RowState != DataRowState.Deleted)
                        {
                            regExps.Add(dataRowRegExp);
                        }
                    }
                }
            }
            else
            {
                regExps = _views.MainForm.datasetMain.RegExp.Rows.Cast <MainDataSet.RegExpRow>()
                          .Where(x => x.RowState != DataRowState.Deleted)
                          .ToList();
            }

            var processor = new RegExpProcessor(regExps);

            if (processor.HasEmptyItems)
            {
                MainForm.ShowErrorToolTip("Found empty regular expressions, skipping");
            }

            _listMatches = processor.GetAllMatches(text);

            ///////////////////////////////////////////////////////////////////////////////

            if (!_listMatches.Any())
            {
                return;
            }

            if (_listMatches.Count > 1000)
            {
                return;
            }

            if (highlight)
            {
                foreach (var match in _listMatches)
                {
                    HighlightMatch(match);
                }
            }

            ///////////////////////////////////////////////////////////////////////////////

            if (scrollToFirstMatch)
            {
                ScrollToMatch(_listMatches.First());
            }

            textBox.Refresh();
        }
        protected List <RegExpMatchResult> GetAllMatches()
        {
            var processor = new RegExpProcessor(_views.MainForm.datasetMain.RegExp);

            return(processor.GetAllMatches(textBox.Text));
        }
        protected bool WriteNote(OleDbConnection connection, double ED_ENC_NUM, string strOriginalText, int nScore, int nCategoryID, string tableName)
        {
            bool bResult = false;

            try
            {
                if (!String.IsNullOrEmpty(strOriginalText))
                {
                    var strModifiedText = strOriginalText;

                    var processor = new RegExpProcessor(_views.MainForm.datasetMain.RegExp.Rows.Cast <DataRow>());

                    var matches = processor.GetAllMatches(strModifiedText);

                    for (var i = matches.Count - 1; i >= 0; i--)
                    {
                        var match = matches[i];

                        var value = match.RegExp.PrefixMatch + match.Match.Value + match.RegExp.SuffixMatch;

                        strModifiedText = strModifiedText.Remove(match.Match.Index, match.Match.Length);
                        strModifiedText = strModifiedText.Insert(match.Match.Index, value);
                    }

                    ///////////////////////////////////////////////////////////////////////////////

                    if (strModifiedText != strOriginalText)
                    {
                        string       strCommand;
                        OleDbCommand command;

                        string strCategory = "";

                        if (nCategoryID != -1)
                        {
                            try
                            {
                                strCommand = "SELECT Category FROM Categories WHERE ID = " + nCategoryID.ToString();
                                command    = new OleDbCommand(strCommand, connection);

                                OleDbDataAdapter adapter = new OleDbDataAdapter(command);
                                DataSet          ds      = new DataSet();

                                adapter.Fill(ds, "Categories");

                                if (ds.Tables[0].Rows.Count == 1)
                                {
                                    strCategory = (string)ds.Tables[0].Rows[0][0];
                                }
                            }
                            catch
                            {
                                //TTrace(System.Reflection.MethodBase.GetCurrentMethod(), ex);
                            }
                        }

                        strCommand = "INSERT INTO  " + tableName
                                     + "  (ED_ENC_NUM, NoteText, Score, Category, CategoryID) "
                                     + "VALUES (?, ?, ?, ?, ?)";

                        command = new OleDbCommand(strCommand, connection);

                        command.Parameters.Add("ED_ENC_NUM", OleDbType.Double)
                        .Value = ED_ENC_NUM;
                        command.Parameters.Add("NoteText", OleDbType.Char)
                        .Value = strModifiedText;
                        command.Parameters.Add("Score", OleDbType.Integer)
                        .Value = nScore;
                        command.Parameters.Add("Category", OleDbType.Char)
                        .Value = strCategory;

                        if (nCategoryID != -1)
                        {
                            command.Parameters.Add("CategoryID", OleDbType.Integer)
                            .Value = nCategoryID;
                        }
                        else
                        {
                            command.Parameters.Add("CategoryID", OleDbType.Integer)
                            .Value = DBNull.Value;
                        }

                        if (command.ExecuteNonQuery() == 1)
                        {
                            bResult = true;
                        }
                    }
                }
            }
            catch
            {
                //TTrace(System.Reflection.MethodBase.GetCurrentMethod(), ex);
            }

            return(bResult);
        }
        public void UpdateText(string text, bool highlight)
        {
            if (textBox.IsDisposed)
            {
                return;
            }

            ClearStyleCache();

            ///////////////////////////////////////////////////////////////////////////////

            bool scrollToFirstMatch;

            if (text != _originalNoteText)
            {
                _originalNoteText = text;

                textBox.Text = text;

                _currentNoteText = textBox.Text;

                scrollToFirstMatch = true;
            }
            else
            {
                ClearHighlights();

                scrollToFirstMatch = false;
            }

            ///////////////////////////////////////////////////////////////////////////////

            if (!highlight)
            {
                _commands.SetLineSpacing(_views.LineSpacing);
                return;
            }

            ///////////////////////////////////////////////////////////////////////////////

            var processor = new RegExpProcessor(_views.MainForm.datasetMain.RegExp.Rows.Cast <DataRow>());

            if (processor.HasEmptyItems)
            {
                MainForm.ShowErrorToolTip("Found empty regular expressions, skipping");
            }

            _listMatches = processor.GetAllMatches(text);

            ///////////////////////////////////////////////////////////////////////////////

            if (!_listMatches.Any())
            {
                return;
            }

            if (_listMatches.Count > 1000)
            {
                return;
            }

            foreach (var match in _listMatches)
            {
                HighlightMatch(match);
            }

            _commands.SetLineSpacing(_views.LineSpacing);

            ///////////////////////////////////////////////////////////////////////////////

            if (scrollToFirstMatch)
            {
                ScrollToMatch(_listMatches.First());
            }

            textBox.Refresh();
        }