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() { 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; } }