Ejemplo n.º 1
0
        internal void SetSystemFormats()
        {//set backcolor and foreColor of systems' cells according to the conditional formatting settings defined by the user
            //first clear all current formats
            foreach (TreeListColumn formatColumn in _mainForm._specialFormatCells.Keys)
            {
                _mainForm._specialFormatCells[formatColumn].Clear();
            }
            _mainForm._specialFormatCells.Clear();

            foreach (TreeListColumn column in _mainForm.treeList.Columns)
            {
                if (IsFixedColumnLeft(column) || IsFixedColumnRight(column))
                {
                    continue; //no conditional formatting for policy-, group- and comment-column
                }
                SystemTreeListTag systemTag = column.Tag as SystemTreeListTag;
                foreach (CountryConfig.ConditionalFormatRow conditionalFormatRow in _countryConfigFacade.GetConditionalFormatRowsOfSystem(systemTag.GetSystemRow()))
                {
                    //first define condition ...
                    IsSpecificBase condition = null;

                    //'standard' conditional formatting: does cell value correspond to specific patterns
                    if (conditionalFormatRow.BaseSystemName == null || conditionalFormatRow.BaseSystemName == string.Empty)
                    {
                        condition = new DoesNodeMatchPatterns(conditionalFormatRow.Condition, column);
                    }
                    //special conditional formatting: show differences between the system and its base-system
                    else
                    {
                        TreeListColumn columnBaseSystem = _mainForm.treeList.Columns.ColumnByName(conditionalFormatRow.BaseSystemName);
                        if (columnBaseSystem == null)
                        {
                            continue; //base system does for whatever reason not exist (was e.g. deleted)
                        }
                        condition = new IsNodeValueDifferent(column, columnBaseSystem);
                    }

                    //... then find all cells which match condition ...
                    TreatSpecificNodes treater = new TreatSpecificNodes(condition, null, false);
                    _mainForm.treeList.NodesIterator.DoOperation(treater);

                    //... finally add to list of cells to be formatted: formatting is accomplished in MainForm's treeList_NodeCellStyle-callback (based on the list)
                    Color backColor = conditionalFormatRow.BackColor == ConditionalFormattingHelper._noSpecialColor ? Color.Empty : ConditionalFormattingHelper.GetColorFromDisplayText(conditionalFormatRow.BackColor);
                    Color foreColor = conditionalFormatRow.ForeColor == ConditionalFormattingHelper._noSpecialColor ? Color.Empty : ConditionalFormattingHelper.GetColorFromDisplayText(conditionalFormatRow.ForeColor);

                    AddToSpecialFormatCells(column, treater.GetSpecificNodes(), backColor, foreColor);
                }
            }
        }
        bool FindMatches()
        {
            //if combo-box 'Search In' is not visible (replace mode) search in values and comments otherwise follow user's directions
            bool searchInNames    = (radSearchInPolicyColumn.Checked || radSearchInAllColumns.Checked);
            bool searchInValues   = (radSeachInSystemColumns.Checked || radSearchInAllColumns.Checked);
            bool searchInComments = (radSearchInCommentColumn.Checked || radSearchInAllColumns.Checked);

            List <TreeListColumn> searchColumns = new List <TreeListColumn>();

            if (searchInNames)
            {
                searchColumns.Add(GetActiveMainForm().GetTreeListBuilder().GetPolicyColumn());
            }
            if (searchInValues)
            {
                searchColumns.AddRange(GetActiveMainForm().GetTreeListBuilder().GetSystemColums());
            }
            if (searchInComments)
            {
                searchColumns.Add(GetActiveMainForm().GetTreeListBuilder().GetCommentColumn());
            }

            string regularExpression = cboFind.Text;

            if (!checkEntireCell.Checked && !chkMatchExactWord.Checked)
            {
                if (!regularExpression.StartsWith("*"))
                {
                    regularExpression = "*" + regularExpression;
                }
                if (!regularExpression.EndsWith("*"))
                {
                    regularExpression += "*";
                }
            }

            //check wheter search criteria or search base (treelist current state, selection) has changed to assess whether search has to be renewed ...
            //... did search criteria change ...
            string searchCriteria = "°" + regularExpression + "°" + chkMatchCase.Checked.ToString() + "°" + radSearchInVisibleCells.Checked.ToString() + "°"
                                    + radSearchInSelectedCells.Checked.ToString() + "°" + chkIncludePrivateComments.Checked.ToString() + "°" + chkMatchExactWord.Checked.ToString() + "°"
                                    + searchInNames.ToString() + searchInValues.ToString() + searchInComments.ToString() + "°";
            //... was treelist changed since last search ...
            int changeStatus = GetActiveMainForm().GetChangesStatus();
            //... was selection changed since last search ...
            List <TreeListNode>   selectedNodes   = null;
            List <TreeListColumn> selectedColumns = null;

            if (radSearchInSelectedCells.Checked)
            {
                selectedNodes   = GetActiveMainForm().GetMultiCellSelector().GetSelectedNodes();
                selectedColumns = GetActiveMainForm().GetMultiCellSelector().GetSelectedColumns();
            }

            //perform search if first search-call or if criteria have changed
            if (_foundCells == null || changeStatus != _changesStatusAtLastSearch || searchCriteria != _searchCriteriaAtLastSearch ||
                _mainFormAtLastSearch != GetActiveMainForm() || HasSelectionChanged(selectedNodes, selectedColumns))
            {
                if (_foundCells == null)
                {
                    _foundCells = new List <KeyValuePair <TreeListColumn, TreeListNode> >();
                }
                _foundCells.Clear();

                GetActiveMainForm().Cursor = Cursors.WaitCursor;
                foreach (TreeListColumn searchColumn in searchColumns)
                {
                    if (selectedColumns != null && !selectedColumns.Contains(searchColumn))
                    {
                        continue;
                    }
                    DoesNodeMatchPatterns matchFinder = new DoesNodeMatchPatterns(regularExpression, searchColumn, chkMatchCase.Checked,
                                                                                  radSearchInVisibleCells.Checked, selectedNodes, chkIncludePrivateComments.Checked, chkMatchExactWord.Checked);
                    TreatSpecificNodes treater = new TreatSpecificNodes(matchFinder, null, false);
                    GetActiveMainForm().treeList.NodesIterator.DoOperation(treater);
                    foreach (TreeListNode node in treater.GetSpecificNodes())
                    {
                        _foundCells.Add(new KeyValuePair <TreeListColumn, TreeListNode>(searchColumn, node));
                    }
                }
                GetActiveMainForm().Cursor = Cursors.Default;
            }

            if (_foundCells.Count == 0)
            {
                Tools.UserInfoHandler.ShowError("No match found.");
            }

            _selectedNodesAtLastSearch   = selectedNodes;
            _selectedColumnsAtLastSearch = selectedColumns;
            _changesStatusAtLastSearch   = changeStatus;
            _searchCriteriaAtLastSearch  = searchCriteria;
            _mainFormAtLastSearch        = GetActiveMainForm();
            return(_foundCells.Count > 0);
        }