Ejemplo n.º 1
0
 internal bool DoesSelectionContainPolicyColumn(bool includeFocusedCell = false)
 {
     if (GetSelectedColumns().Contains(_mainForm.GetTreeListBuilder().GetPolicyColumn()))
     {
         return(true);
     }
     return(includeFocusedCell && _mainForm.treeList.FocusedColumn == _mainForm.GetTreeListBuilder().GetPolicyColumn());
 }
Ejemplo n.º 2
0
        internal static void StoreSettings(EM_UI_MainForm mainForm)
        {
            if (!keepMode)
            {
                return;
            }
            CountryViewSetting setting = new CountryViewSetting();
            string             cc      = mainForm.GetCountryShortName();

            try
            {
                foreach (TreeListColumn col in mainForm.treeList.Columns)
                {
                    setting.systemWidths.Add(col.Caption, col.Width);
                    if (!col.Visible)
                    {
                        setting.hiddenSystems.AddUnique(col.Caption, true);
                    }
                }
                foreach (TreeListNode polNode in mainForm.treeList.Nodes)
                {
                    AddHiddenNode(ref setting.hiddenNodes, polNode);
                    foreach (TreeListNode funcNode in polNode.Nodes)
                    {
                        AddHiddenNode(ref setting.hiddenNodes, funcNode);
                        foreach (TreeListNode parNode in funcNode.Nodes)
                        {
                            AddHiddenNode(ref setting.hiddenNodes, parNode);
                        }
                    }
                }
                if (mainForm.GetTreeListBuilder() != null)
                {
                    setting.textSize = mainForm.GetTreeListBuilder().GetTextSize();
                }

                if (countryViewSettings.ContainsKey(cc))
                {
                    countryViewSettings[cc] = setting;
                }
                else
                {
                    countryViewSettings.Add(cc, setting);
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception, "Failed to store view settings for " + cc + ". Settings are set back to default.", false);
                if (countryViewSettings.ContainsKey(cc))
                {
                    countryViewSettings.Remove(cc);
                }
            }
        }
        void mniAddFunction_Click(object senderMenuItem, EventArgs e)
        {
            TreeListNode senderNode = (senderMenuItem as ToolStripMenuItem).Tag as TreeListNode;

            //add the function
            AddFunctionAction action = new AddFunctionAction(_mainForm, senderNode, senderMenuItem.ToString(), _mainForm.GetTreeListManager().GetIDsOfHiddenSystems());

            _mainForm.PerformAction(action, false);

            //after redrawing treeview expand whatever is necessary to make the new function visible
            _mainForm.GetTreeListBuilder().ExpandSpecificNode(action.GetAddedFunctionsIDs());
        }
        internal override void PerformAction()
        {
            string countryShortName = string.Empty;
            string policyName       = string.Empty;

            CountryConfig.PolicyRow newPolicyRow = null;
            int newPolicyNodeIndex = -1;

            //add very first policy
            if (_senderNode == null)
            {
                countryShortName = _countryConfigFacade.GetCountryShortName().ToLower();
                if (!UserInfoHandler.GetPolicyName(ref policyName, countryShortName, null))
                {
                    _actionIsCanceled = true;
                    return;
                }

                foreach (CountryConfig.SystemRow systemRow in _countryConfigFacade.GetSystemRows()) //loop over systems
                {
                    newPolicyRow = _countryConfigFacade.AddFirstPolicyRow(policyName, _policyType, systemRow,
                                                                          DefPar.Value.NA); //policy is initially set to n/a
                }
            }

            //add policy after/before an existing policy
            else
            {
                countryShortName = CountryConfigFacade.GetCountryShortName((_senderNode.Tag as PolicyTreeListTag).GetDefaultPolicyRow()).ToLower();
                if (!UserInfoHandler.GetPolicyName(ref policyName, countryShortName, _senderNode.TreeList))
                {
                    return;
                }

                foreach (CountryConfig.PolicyRow policyRow in (_senderNode.Tag as PolicyTreeListTag).GetPolicyRows()) //loop over systems (actually over neighbour policies within systems)
                {
                    newPolicyRow = CountryConfigFacade.AddPolicyRow(policyName, _policyType, policyRow, _addBeforeSender,
                                                                    DefPar.Value.NA); //policy is initially switched off
                }

                newPolicyNodeIndex = _addBeforeSender ? _mainForm.treeList.GetNodeIndex(_senderNode) : _mainForm.treeList.GetNodeIndex(_senderNode) + 1;
            }

            if (newPolicyRow != null)
            {
                _mainForm.GetTreeListBuilder().InsertPolicyNode(newPolicyRow, newPolicyNodeIndex);
                _mainForm.GetTreeListBuilder().AddToAvailablePolicies(newPolicyRow);
            }
        }
        internal override void DoAfterCommitWork() // adapt spine switches for deleted extensions (directly in tree, as a full update takes too long)
        {
            foreach (CountryConfig.PolicyRow polRow in delExPolRows)
            {
                if (polRow == null)
                {
                    continue;
                }
                SetSwitch(polRow.ID, polRow.SystemID, false, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(polRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(polRow));
                foreach (CountryConfig.FunctionRow funRow in polRow.GetFunctionRows())
                {
                    SetSwitch(funRow.ID, polRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(funRow));
                }
            }
            foreach (CountryConfig.FunctionRow funRow in delExFunRows)
            {
                if (funRow == null)
                {
                    continue;
                }
                SetSwitch(funRow.ID, funRow.PolicyRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow), !ExtensionAndGroupManager.ShowExtensionSwitchEditor(funRow));
            }

            void SetSwitch(string rowID, string sysID, bool isFun, string origSwitch, bool changeOldStyleXmlSwitchToToggle)
            {
                KeyValuePair <TreeListNode, TreeListColumn> cell = mainForm.GetTreeListBuilder().GetCellByDataRow(rowID, sysID, isFun);

                if (cell.Key != null && cell.Value != null)
                {
                    cell.Key.SetValue(cell.Value,
                                      changeOldStyleXmlSwitchToToggle && origSwitch == DefPar.Value.SWITCH ? DefPar.Value.TOGGLE : origSwitch);
                }
            }
        }
Ejemplo n.º 6
0
        internal abstract void CopySymbolicIdentfierToClipboard(); //copy the symbolic identifier of a policy (=policy name), function (e.g. yse_#3) or parameter (e.g. yse_#3.4) to the clipboard

        internal virtual void CopyIdentfierToClipboard()           //copy the real (system specific) identifier of a policy, function or parameter to the clipboard
        {
            SelectSystemsForm selectSystemsForm = new SelectSystemsForm(_mainForm.GetCountryShortName(), null, true);

            selectSystemsForm.SetSingleSelectionMode();
            if (selectSystemsForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            if (selectSystemsForm.IsAllSystemsSelected())
            {
                string clipboardText = string.Empty;
                foreach (TreeListColumn column in (from col in _mainForm.GetTreeListBuilder().GetSystemColums()
                                                   where col.VisibleIndex >= 0 select col).OrderBy(col => col.VisibleIndex))
                {
                    clipboardText += GetID((column.Tag as SystemTreeListTag).GetSystemRow().ID) + "\t";
                }
                ;
                clipboardText = clipboardText.TrimEnd('\t');
                System.Windows.Forms.Clipboard.SetText(clipboardText);
            }
            else if (selectSystemsForm.GetSelectedSystemRows().Count > 0)
            {
                System.Windows.Forms.Clipboard.SetText(GetID(selectSystemsForm.GetSelectedSystemRows().First().ID));
            }
        }
        internal override void PerformAction()
        {
            PolicyTreeListTag policyTreeListTag = _senderNode.Tag as PolicyTreeListTag;
            string            countryShortName  = CountryConfigFacade.GetCountryShortName((_senderNode.Tag as PolicyTreeListTag).GetDefaultPolicyRow()).ToLower();
            string            policyName        = policyTreeListTag.GetPolicyName();
            string            currentName       = policyTreeListTag.GetDefaultPolicyRow().Name;

            if (!UserInfoHandler.GetPolicyName(ref policyName, countryShortName, _senderNode.TreeList, currentName))
            {
                _actionIsCanceled = true;
                return;
            }

            foreach (CountryConfig.PolicyRow policyRow in policyTreeListTag.GetPolicyRows()) //loop over systems (actually over neighbour policies within systems)
            {
                policyRow.Name = policyName;
                _senderNode.SetValue(_mainForm.GetTreeListBuilder().GetSystemColumnByID(policyRow.SystemID), policyRow.Switch);
            }
            _senderNode.SetValue(_mainForm.GetTreeListBuilder().GetPolicyColumn(), policyName);
        }
Ejemplo n.º 8
0
        internal static bool IsHiddenSystem(string countryShortName, string systemName)
        {
            EM_UI_MainForm openMainForm = (EM_AppContext.Instance.GetCountryMainForm(countryShortName));

            if (openMainForm == null)
            {
                return(countryViewSettings.ContainsKey(countryShortName) &&
                       countryViewSettings[countryShortName].hiddenSystems.Contains(systemName, true));
            }
            TreeListColumn sc = openMainForm.GetTreeListBuilder().GetSystemColumnByName(systemName);

            return(sc == null ? false : !sc.Visible);
        }
Ejemplo n.º 9
0
        internal override void PerformAction()
        {
            if (Tools.UserInfoHandler.GetInfo("Are you sure you want to use the current system order as default?", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                _actionIsCanceled = true;
                return;
            }

            foreach (TreeListColumn systemColumn in _mainForm.GetTreeListBuilder().GetSystemColums())
            {
                SystemTreeListTag systemTreeListTag = (systemColumn.Tag as SystemTreeListTag);
                systemTreeListTag.SetSystemOrder(systemColumn.VisibleIndex);
            }
        }
        void FillSystemsList()
        {
            bool firstFill = !_systemRows.Any(); List <string> selIds = new List <string>();

            try { if (!firstFill)
                  {
                      foreach (int index in lstSystems.CheckedIndices)
                      {
                          selIds.Add(_systemRows.ElementAt(index).ID);
                      }
                  }
            } catch { }

            lstSystems.Items.Clear();
            _systemRows.Clear();
            foreach (TreeListColumn systemColumn in _mainForm.GetTreeListBuilder().GetSystemColums())
            {
                CountryConfig.SystemRow systemRow = (systemColumn.Tag as SystemTreeListTag).GetSystemRow();
                int index = lstSystems.Items.Add(systemRow.Name);
                lstSystems.SetItemChecked(index, firstFill || selIds.Contains(systemRow.ID));
                _systemRows.Add(systemRow);
            }
        }
        void GreyState(TreeListNode senderNode)
        {
            if (senderNode == null)
            {
                return;
            }
            bool singlePolicyView = (_mainForm != null && _mainForm.GetTreeListBuilder() != null && _mainForm.GetTreeListBuilder().SinglePolicyView);

            mniMovePolicyDown.Enabled       = senderNode.NextNode != null && !singlePolicyView;
            mniMovePolicyUp.Enabled         = senderNode.PrevNode != null && !singlePolicyView;
            mniPastePolicyAfter.Enabled     = mniPastePolicyBefore.Enabled = EM_AppContext.Instance.GetPastePolicyAction() != null && !singlePolicyView;
            mniPasteReferenceBefore.Enabled = mniPasteReferenceAfter.Enabled = !_mainForm._isAddOn &&
                                                                               EM_AppContext.Instance.GetPastePolicyAction() != null &&
                                                                               EM_AppContext.Instance.GetPastePolicyAction().GetCopyCountryShortName() == _mainForm.GetCountryShortName() &&
                                                                               !singlePolicyView;
            mniPasteFunction.Enabled      = EM_AppContext.Instance.GetPasteFunctionAction() != null && !PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniCopyPolicy.Enabled         = !PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniRenamePolicy.Enabled       = !PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniChangePolicyType.Enabled   = !PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniPrivate.Enabled            = !_mainForm._isAddOn;
            mniGoToReferredPolicy.Enabled = PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniAddPolicyAfter.Enabled     = !singlePolicyView;
            mniAddPolicyBefore.Enabled    = !singlePolicyView;
            mniDeletePolicy.Enabled       = !singlePolicyView;
            //the following is in fact not really correct (a reasonable copy of the selection is only possible if the policy-name-cell lies within the selection and the selection contains editable cells)
            //it's aim is just to indicate that it is not possible to copy the values of the policy with this menu (unless they are selected)
            mniCopyValues.Enabled  = _mainForm.GetMultiCellSelector().HasSelection();
            mniPasteValues.Enabled = !MultiCellSelector.IsClipboardEmpty();
            if (_mniAddFunction == null)
            {
                return;
            }
            _mniAddFunction.Enabled = !PolicyTreeListTag.IsReferencePolicy(senderNode);
            mniGroups.Enabled       = !_mainForm._isAddOn;
            mniExtensions.Enabled   = !_mainForm._isAddOn;
        }
 void ExpandAllPolicies_MenuItemClick(object sender, EventArgs e)
 {
     _mainForm.GetTreeListBuilder().ExpandAllPolicies();
 }
        internal override void PerformAction()
        {
            try
            {
                TreeListNode pastePolicyNode = _pasteNode.ParentNode;
                if (pastePolicyNode == null)
                {
                    pastePolicyNode = _pasteNode; //'Paste Function' called from policy node
                }
                List <Dictionary <string, CountryConfig.FunctionRow> > copyFunctions = new List <Dictionary <string, CountryConfig.FunctionRow> >();
                foreach (Dictionary <string, CountryConfig.FunctionRow> copyFunction in _copyFunctions)
                {
                    copyFunctions.Add(copyFunction); //make a copy as possible reversing should not be permanent (there may be only one copy action, but several paste actions)
                }
                if (_pasteBefore == false &&
                    pastePolicyNode != _pasteNode) //do not reverse if functions are inserted as last (i.e. from the policy-context-menu)
                {
                    copyFunctions.Reverse();       //by reversing the order one spares changing the paste node
                }
                //link systems of origin country to systems of destination country
                Dictionary <string, string> systemAssignment = null;
                if (_copyCountryForm != _pasteCountryForm)
                {
                    systemAssignment = UserInfoHandler.GetSystemAssignement(_copyCountryForm, _pasteCountryForm, _hiddenSystems);
                    if (systemAssignment == null)
                    {
                        _actionIsCanceled = true;
                        return;
                    }
                }

                foreach (Dictionary <string, CountryConfig.FunctionRow> copyFunction in copyFunctions)
                {
                    List <CountryConfig.FunctionRow> pastedFunctionRows = null;
                    int pastedFunctionNodeIndex = -1;

                    //copy function within country
                    if (_copyCountryForm == _pasteCountryForm)
                    {
                        List <string> systemIDs = new List <string>();
                        foreach (CountryConfig.PolicyRow policyRow in (pastePolicyNode.Tag as PolicyTreeListTag).GetPolicyRows()) //gather systems
                        {
                            systemIDs.Add(policyRow.SystemID);
                        }

                        pastedFunctionRows = PasteFunction(copyFunction, systemIDs, pastePolicyNode, out pastedFunctionNodeIndex);
                    }

                    //copy function from one country to another
                    else
                    {
                        List <string> copySystemIDs  = new List <string>();
                        List <string> pasteSystemIDs = new List <string>();
                        foreach (CountryConfig.PolicyRow policyRow in (pastePolicyNode.Tag as PolicyTreeListTag).GetPolicyRows()) //gather systems
                        {
                            copySystemIDs.Add(systemAssignment.ContainsKey(policyRow.SystemID) ? systemAssignment[policyRow.SystemID] : null);
                            pasteSystemIDs.Add(policyRow.SystemID);
                        }

                        pastedFunctionRows = PasteFunction(copyFunction, copySystemIDs, pastePolicyNode, out pastedFunctionNodeIndex, pasteSystemIDs);
                    }

                    if (pastedFunctionRows != null)
                    {
                        _pasteCountryForm.GetTreeListBuilder().InsertFunctionNode(pastedFunctionRows, pastePolicyNode, pastedFunctionNodeIndex);
                    }
                }
            }
            catch (System.Collections.Generic.KeyNotFoundException)
            {
                Tools.UserInfoHandler.ShowError("Copied function(s) not available any more (due to add/remove systems).");
                EM_AppContext.Instance.SetPasteFunctionAction(null);
                _actionIsCanceled = true;
            }
            catch (System.Data.RowNotInTableException)
            {
                Tools.UserInfoHandler.ShowError("Copied function(s) not available any more (due to removal).");
                EM_AppContext.Instance.SetPasteFunctionAction(null);
                _actionIsCanceled = true;
            }
        }
Ejemplo n.º 14
0
        internal override void PerformAction()
        {
            TreeListNode policyNode = _senderNode;

            if (_senderNode.ParentNode != null)
            {
                policyNode = _senderNode.ParentNode;
            }

            int newFunctionNodeIndex = -1;
            List <CountryConfig.FunctionRow> newFunctionRows = new List <CountryConfig.FunctionRow>();

            foreach (CountryConfig.PolicyRow policyRow in (policyNode.Tag as PolicyTreeListTag).GetPolicyRows()) //loop over systems
            {
                CountryConfig.FunctionRow newFunctionRow = null;

                //(1) add function
                //if the sender node is a policy node: insert as last function ('Add Function' was called from policy node or 'Add Function After' was called from last function node in policy)
                if (_senderNode == policyNode)
                {
                    newFunctionRow = CountryConfigFacade.AddFunctionRowAtTail(_functionName, policyRow,
                                                                              // the switch of a function inside an extension-policy cannot be changed, therefore add as on (otherwise one would need to remove the policy from the extension to be able to change the switch to on)
                                                                              ExtensionAndGroupManager.ShowExtensionSwitchEditor(policyRow) ? DefPar.Value.ON : DefPar.Value.NA);
                }

                //if the sender node is a function node: insert before ('Add Function Before' was called from function node)
                else
                {
                    CountryConfig.FunctionRow neighbourFunction = (_senderNode.Tag as FunctionTreeListTag).GetFunctionRowOfSystem(policyRow.SystemRow.ID);
                    newFunctionRow = CountryConfigFacade.AddFunctionRow(_functionName, neighbourFunction, true,
                                                                        ExtensionAndGroupManager.ShowExtensionSwitchEditor(policyRow) ? DefPar.Value.ON : DefPar.Value.NA); // see comment above
                    newFunctionNodeIndex = _mainForm.treeList.GetNodeIndex(_senderNode);
                }
                _addedFunctionsIDs.Add(newFunctionRow.ID);

                //(2) add compulsory parameters
                DefinitionAdmin.Fun fun = DefinitionAdmin.GetFunDefinition(_functionName, false);
                if (fun != null)
                {
                    for (short doCommon = 0; doCommon < 2; ++doCommon) // add function-specific parameters before common
                    {
                        foreach (var p in fun.GetParList())
                        {
                            AddPar(p, false);
                        }
                        foreach (var pg in fun.GetGroupParList())
                        {
                            if (pg.minCount > 0)
                            {
                                foreach (var p in pg.par)
                                {
                                    AddPar(p, true);
                                }
                            }
                        }

                        void AddPar(KeyValuePair <string, DefinitionAdmin.Par> p, bool group)
                        {
                            string parName = p.Key.ToUpper() == DefPar.PAR_TYPE.PLACEHOLDER.ToString().ToUpper() ? DefinitionAdmin.ParTypeToString(DefPar.PAR_TYPE.PLACEHOLDER) : p.Key;

                            DefinitionAdmin.Par parDef = p.Value;
                            if (parDef.minCount > 0 && ((doCommon == 0 && !parDef.isCommon) || (doCommon == 1 && parDef.isCommon)))
                            {
                                CountryConfigFacade.AddParameterRowAtTail(newFunctionRow, parName, parDef, group ? "1" : string.Empty);
                            }
                        }
                    }
                }
                newFunctionRows.Add(newFunctionRow);
            }

            _mainForm.GetTreeListBuilder().InsertFunctionNode(newFunctionRows, policyNode, newFunctionNodeIndex);
        }
        void mniPrivateComment_Click(object sender, EventArgs e)
        {
            if (_senderNode == null || _senderNode.Tag == null)
            {
                return;
            }
            BaseTreeListTag nodeTag = _senderNode.Tag as BaseTreeListTag;

            if (nodeTag == null)
            {
                return;
            }

            string existingPrivateComment = nodeTag.GetPrivateComment();

            if (UserInput.Get("Insert/Edit Private Comment (for '" + _senderNode.GetDisplayText(_mainForm.GetTreeListBuilder().GetPolicyColumn()) + "')",
                              out existingPrivateComment, existingPrivateComment, true) != DialogResult.Cancel)
            {
                nodeTag.SetPrivateComment(existingPrivateComment);
            }
        }
Ejemplo n.º 16
0
        internal static void RestoreSettings(EM_UI_MainForm mainForm, bool exceptionCall = false)
        {
            if (!keepMode)
            {
                return;
            }
            string cc = mainForm.GetCountryShortName();

            try
            {
                if (!countryViewSettings.ContainsKey(cc))
                {
                    return;
                }
                CountryViewSetting setting = countryViewSettings[cc];
                foreach (TreeListColumn col in mainForm.treeList.Columns)
                {
                    if (setting.systemWidths.ContainsKey(col.Caption))
                    {
                        col.Width = setting.systemWidths[col.Caption];
                    }
                    if (setting.hiddenSystems.Contains(col.Caption, true))
                    {
                        col.Visible = false;
                    }
                    if (setting.hiddenSystems.Count > 0)
                    {
                        mainForm.showHiddenSystemsBox();
                    }
                }
                foreach (TreeListNode polNode in mainForm.treeList.Nodes)
                {
                    SetHiddenNode(setting.hiddenNodes, polNode);
                    foreach (TreeListNode funcNode in polNode.Nodes)
                    {
                        SetHiddenNode(setting.hiddenNodes, funcNode);
                        foreach (TreeListNode parNode in funcNode.Nodes)
                        {
                            SetHiddenNode(setting.hiddenNodes, parNode);
                        }
                    }
                }
                if (setting.textSize != null)
                {
                    mainForm.GetTreeListBuilder().SetTextSize(setting.textSize);
                }
            }
            catch (Exception exception)
            {
                if (exceptionCall)
                {
                    return;                // to avoid an infinite loop because of some unknown problem
                }
                UserInfoHandler.ShowException(exception, "Failed to restored view settings. Settings are set back to default.", false);
                if (countryViewSettings.ContainsKey(cc))
                {
                    countryViewSettings[cc] = new CountryViewSetting();
                }
                else
                {
                    countryViewSettings.Add(cc, new CountryViewSetting());
                }
                RestoreSettings(mainForm, true);
            }
        }
Ejemplo n.º 17
0
        internal override void PerformAction()
        {
            try
            {
                string policyName = _copyPolicyRows.Values.First().Name;                                                                                       //name of orgin policy

                string pasteCountryShortName = CountryConfigFacade.GetCountryShortName((_pasteNode.Tag as PolicyTreeListTag).GetDefaultPolicyRow()).ToLower(); //name of destination country
                if (!_pasteAsReference)
                {
                    if (!UserInfoHandler.GetPolicyName(ref policyName, pasteCountryShortName, _pasteNode.TreeList)) //note: uses treelist of destination country
                    {
                        _actionIsCanceled = true;
                        return;
                    }
                }

                CountryConfig.PolicyRow pastedPolicyRow = null;
                //copy policy within country
                if (_copyCountryForm == _pasteCountryForm)
                {
                    foreach (CountryConfig.PolicyRow pastePolicyRow in (_pasteNode.Tag as PolicyTreeListTag).GetPolicyRows()) //loop over systems
                    {
                        CountryConfig.PolicyRow policyRow = _copyPolicyRows[pastePolicyRow.SystemID];
                        bool switchNA = _hiddenSystems.Contains(pastePolicyRow.SystemID) ? true : false;
                        if (!_pasteAsReference)
                        {
                            pastedPolicyRow = CountryConfigFacade.CopyPolicyRow(policyRow, policyName, pastePolicyRow, _pasteBefore, switchNA);
                        }
                        else
                        {
                            pastedPolicyRow = CountryConfigFacade.AddReferencePolicyRow(policyRow, pastePolicyRow, _pasteBefore, switchNA);
                        }
                    }
                }

                //copy policy from one country to another
                else
                {
                    //link systems of origin country to systems of destination country
                    Dictionary <string, string> systemAssignment = UserInfoHandler.GetSystemAssignement(_copyCountryForm, _pasteCountryForm, _hiddenSystems);
                    if (systemAssignment == null)
                    {
                        _actionIsCanceled = true;
                        return;
                    }

                    foreach (CountryConfig.PolicyRow pastePolicyRow in (_pasteNode.Tag as PolicyTreeListTag).GetPolicyRows()) //loop over systems
                    {
                        //search for 'corresponding' policy, i.e. policy within the system of origin country assigned to current system (of loop)
                        CountryConfig.PolicyRow policyRow = null;
                        bool switchNA = !systemAssignment.Keys.Contains(pastePolicyRow.SystemID);
                        if (!switchNA) //policy found
                        {
                            policyRow = _copyPolicyRows[systemAssignment[pastePolicyRow.SystemID]];
                        }
                        else //policy not found because (a) system is not assigend to any system in origin country or (b) system is hidden
                        {
                            policyRow = _copyPolicyRows.Values.First(); //still copy (default) policy for symmetry but switch off and set paramters to n/a
                        }
                        pastedPolicyRow = CountryConfigFacade.CopyPolicyRow(policyRow, policyName, pastePolicyRow, _pasteBefore, switchNA);
                    }
                }

                if (pastedPolicyRow != null)
                {
                    _pasteCountryForm.GetTreeListBuilder().InsertPolicyNode(pastedPolicyRow,
                                                                            _pasteBefore ? _pasteCountryForm.treeList.GetNodeIndex(_pasteNode) : _pasteCountryForm.treeList.GetNodeIndex(_pasteNode) + 1);
                    _pasteCountryForm.GetTreeListBuilder().AddToAvailablePolicies(pastedPolicyRow);
                }
            }
            catch
            {
                Tools.UserInfoHandler.ShowError("Copied policy (or other necessary information) is not available any more." + Environment.NewLine
                                                + "Please repeat copying.");
                EM_AppContext.Instance.SetPastePolicyAction(null);
                _actionIsCanceled = true;
            }
        }
        internal override void PerformAction()
        {
            CountryConfig countryConfig = CountryAdministrator.GetCountryConfigFacade(cc).GetCountryConfig();

            ExtensionAndGroupMenuManager.GetSelectionPolFunPar(cc, out List <CountryConfig.PolicyRow> polRows, out List <CountryConfig.FunctionRow> funRows, out List <CountryConfig.ParameterRow> parRows);

            string extensionID = (from e in ExtensionAndGroupManager.GetExtensions(cc) where e.Name == extensionName select e.ID).FirstOrDefault(); if (extensionID == null)
            {
                return;
            }
            bool baseOff = !on;

            foreach (CountryConfig.PolicyRow polRow in polRows)
            {
                if (!(from pe in countryConfig.Extension_Policy where pe.PolicyID == polRow.ID && pe.ExtensionID == extensionID && pe.BaseOff == baseOff select pe).Any())
                {
                    countryConfig.Extension_Policy.AddExtension_PolicyRow(extensionID, polRow, baseOff); // make sure to not add twice (and thus crash)
                    if (polRow.Switch == DefPar.Value.NA)
                    {
                        polRow.Switch = DefPar.Value.OFF;                                   // if set to n/a the xml-reader would ignore the policy, before extensions are taken into account
                    }
                }
            }
            foreach (CountryConfig.FunctionRow funRow in funRows)
            {
                if (!(from fe in countryConfig.Extension_Function where fe.FunctionID == funRow.ID && fe.ExtensionID == extensionID && fe.BaseOff == baseOff select fe).Any())
                {
                    countryConfig.Extension_Function.AddExtension_FunctionRow(extensionID, funRow, baseOff);
                    if (funRow.Switch == DefPar.Value.NA)
                    {
                        funRow.Switch = DefPar.Value.OFF;
                    }
                }
            }
            foreach (CountryConfig.ParameterRow parRow in parRows)
            {
                if (!(from pe in countryConfig.Extension_Parameter where pe.ParameterID == parRow.ID && pe.ExtensionID == extensionID && pe.BaseOff == baseOff select pe).Any())
                {
                    countryConfig.Extension_Parameter.AddExtension_ParameterRow(extensionID, parRow, baseOff);
                }
            }

            if (!on)
            {
                return;
            }

            // adapt switches in treelist directly, as a full update takes too long
            foreach (CountryConfig.PolicyRow polRow in polRows)
            {
                SetSwitch(polRow.ID, polRow.SystemID, false, DefPar.Value.SWITCH);
                // for functions, which are part of an extension-policy one still needs to show off and n/a instead of switch (see GetExtensionAdaptedSwitch)
                foreach (CountryConfig.FunctionRow funRow in polRow.GetFunctionRows())
                {
                    SetSwitch(funRow.ID, polRow.SystemID, true, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(funRow));
                }
            }
            foreach (CountryConfig.FunctionRow funRow in funRows)
            {
                SetSwitch(funRow.ID, funRow.PolicyRow.SystemID, true, DefPar.Value.SWITCH);
            }

            void SetSwitch(string rowID, string sysID, bool isFun, string switchValue)
            {
                KeyValuePair <TreeListNode, TreeListColumn> cell = mainForm.GetTreeListBuilder().GetCellByDataRow(rowID, sysID, isFun);

                if (cell.Key != null && cell.Value != null)
                {
                    cell.Key.SetValue(cell.Value, switchValue);
                }
            }
        }