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