static internal string GetIDBySymbolicID(string symbolicID, CountryConfigFacade countryConfigFacade, string systemID)
        {
            ReplaceCountrySymbol(symbolicID, countryConfigFacade.GetCountryShortName());

            if (symbolicID.Contains(_symbolicID_ParameterSeparator))
            {
                CountryConfig.ParameterRow parameterRow = GetParameterRowBySymbolicID(symbolicID, countryConfigFacade, systemID);
                if (parameterRow != null)
                {
                    return(parameterRow.ID);
                }
            }
            else if (symbolicID.Contains(_symbolicID_OrderSeparator))
            {
                CountryConfig.FunctionRow functionRow = GetFunctionRowBySymbolicID(symbolicID, countryConfigFacade, systemID);
                if (functionRow != null)
                {
                    return(functionRow.ID);
                }
            }
            else
            {
                CountryConfig.PolicyRow policyRow = countryConfigFacade.GetPolicyRowByFullName(systemID, symbolicID);
                if (policyRow != null)
                {
                    return(policyRow.ID);
                }
            }

            return(string.Empty);
        }
Exemple #2
0
 internal void RemoveFromAvailablePolicies(CountryConfig.PolicyRow policyRow)
 {
     if (_availablePolicies.Contains(policyRow))
     {
         _availablePolicies.Remove(policyRow);
     }
 }
Exemple #3
0
        internal override void PerformAction()
        {
            TreeList treeList = _targetNode.TreeList;
            //-A- first move directly in treeview ...
            int targetIndex       = treeList.GetNodeIndex(_targetNode);
            int selectionTopIndex = treeList.GetNodeIndex(_moveNodes.First());
            int selectionBotIndex = treeList.GetNodeIndex(_moveNodes.Last());

            //move up (accomplished by moving the selection above target node - or above target node's next node, if move below target)
            if (targetIndex < selectionTopIndex)
            {
                int index = _moveAboveTarget ? targetIndex : targetIndex + 1;
                foreach (TreeListNode node in _moveNodes)
                {
                    treeList.SetNodeIndex(node, index++);
                }
            }

            //move down (accomplished by moving the nodes between selection and targetNode above selection - including target node itself, if move below target)
            else if (targetIndex > selectionBotIndex)
            {
                List <TreeListNode> shiftUpNodes = new List <TreeListNode>();
                foreach (TreeListNode node in _targetNode.ParentNode == null ? treeList.Nodes : _targetNode.ParentNode.Nodes)
                {
                    if (treeList.GetNodeIndex(node) > selectionBotIndex &&
                        (treeList.GetNodeIndex(node) < targetIndex || !_moveAboveTarget && treeList.GetNodeIndex(node) == targetIndex))
                    {
                        shiftUpNodes.Add(node);
                    }
                }
                foreach (TreeListNode node in shiftUpNodes)
                {
                    treeList.SetNodeIndex(node, selectionTopIndex++);
                }
            }

            //else: target inside selection: should not happen unless programming error (thus do nothing)

            //-B- then reenact in data: avoids flickering and saves time, compared to reorder in data and update tree, though the latter may be cleaner
            TreeListNodes nodes = _targetNode.ParentNode == null ? treeList.Nodes : _targetNode.ParentNode.Nodes;

            //this takes care of the "hidden" uprating-policy (which is in fact not hidden in the narrow sense, but only exists in data but not in the tree)
            int allowForNotDisplayedPolicy = 0;

            if (_targetNode.ParentNode == null) //moved node is a policy-node
            {                                   //re-order the policies starting with oder of hidden uprating-policy plus 1
                CountryConfig.PolicyRow firstPol = CountryConfigFacade.GetFirstPolicyRow((_targetNode.Tag as BaseTreeListTag).GetDefaultPolicyRow().SystemRow);
                if (firstPol.Name.StartsWith(EM_UI.UpratingIndices.UpratingIndicesForm._policyUprateFactors_Name))
                {
                    CountryAdministration.CountryAdministrator.GetCountryConfigFacade(EM_AppContext.Instance.GetActiveCountryMainForm().GetCountryShortName());
                }
                allowForNotDisplayedPolicy = EM_Helpers.SaveConvertToInt(firstPol.Order) + 1;
            }

            foreach (TreeListNode node in nodes)
            {
                (node.Tag as BaseTreeListTag).SetOrder(treeList.GetNodeIndex(node) + allowForNotDisplayedPolicy);
            }
        }
 static internal void ReplaceCountrySymbol(CountryConfig.PolicyRow policyRow, string countryShortName)
 {
     policyRow.Name = ReplaceCountrySymbol(policyRow.Name, countryShortName);
     foreach (CountryConfig.FunctionRow functionRow in policyRow.GetFunctionRows())
     {
         ReplaceCountrySymbol(functionRow, countryShortName);
     }
 }
 internal override int GetSpecialNodeColor()
 {
     CountryConfig.PolicyRow policyRow = GetDefaultPolicyRow();
     if (policyRow == null || policyRow.IsNull(CountryConfigFacade._columnName_Color))
     {
         return(DefPar.Value.NO_COLOR);
     }
     return(policyRow.Color);
 }
        static internal string GetSymbolicID(CountryConfig.PolicyRow policyRow, string replaceCountryShortName = "")
        {
            string symbolicID = policyRow.Name;

            if (replaceCountryShortName != string.Empty && symbolicID.ToLower().EndsWith(replaceCountryShortName.ToLower()))
            {
                symbolicID = symbolicID.Substring(0, symbolicID.Length - replaceCountryShortName.Length) + DefPar.Value.PLACEHOLDER_CC;
            }
            return(symbolicID);
        }
 internal static int GetStateImageIndex(CountryConfig.PolicyRow policyRow)
 {
     if (policyRow.ReferencePolID == null || policyRow.ReferencePolID == string.Empty)
     {
         return(policyRow.Private == DefPar.Value.YES ? DefGeneral.IMAGE_IND_PRIV_POL : DefGeneral.IMAGE_IND_POL);
     }
     else
     {
         return(policyRow.Private == DefPar.Value.YES ? DefGeneral.IMAGE_IND_PRIV_REF : DefGeneral.IMAGE_IND_REF);
     }
 }
        private Dictionary <string, Dictionary <string, ILInfo> > AssessILInfo(string country, bool core)
        {
            Dictionary <string, Dictionary <string, ILInfo> > ilInfos = new Dictionary <string, Dictionary <string, ILInfo> >();
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);

            foreach (CountryConfig.SystemRow system in GetPublicSystems(country))
            {
                // UDB (aka non-core) ILS are kept in a separate policy
                CountryConfig.PolicyRow ilPol = ccf.GetPolicyRowByName(system.ID, core ? DefPol.SPECIAL_POL_ILSDEF : DefPol.SPECIAL_POL_ILSUDBDEF);
                if (ilPol == null || ilPol.Switch != DefPar.Value.ON || ilPol.Private == DefPar.Value.YES)
                {
                    continue;
                }
                foreach (CountryConfig.FunctionRow ilFunc in ccf.GetFunctionRowsByPolicyIDAndFunctionName(ilPol.ID, DefFun.DefIl))
                {
                    if (ilFunc.Switch != DefPar.Value.ON || ilFunc.Private == DefPar.Value.YES)
                    {
                        continue;
                    }
                    ILInfo ilInfo = new ILInfo()
                    {
                        LabelEmpty = ilFunc.Comment == string.Empty
                    };
                    string ilName = string.Empty;

                    foreach (CountryConfig.ParameterRow ilPar in ilFunc.GetParameterRows())
                    {
                        if (ilPar.Name.ToLower() == DefPar.DefIl.Name.ToLower())
                        {
                            ilName = ilPar.Value.ToLower(); continue;
                        }
                        if (ilPar.Value == DefPar.Value.NA || ilPar.Private == DefPar.Value.YES)
                        {
                            continue;
                        }
                        ilInfo.Components.Add(ilPar);
                    }
                    if (ilName == string.Empty)
                    {
                        continue;                         // rather unlikely
                    }
                    if (!ilInfos.ContainsKey(ilName))
                    {
                        ilInfos.Add(ilName, new Dictionary <string, ILInfo>());
                    }
                    if (!ilInfos[ilName].ContainsKey(system.Name.ToLower())) // this is a security-request: ilName should be unique per system
                    {
                        ilInfos[ilName].Add(system.Name.ToLower(), ilInfo);
                    }
                }
            }
            return(ilInfos);
        }
        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);
            }
        }
Exemple #10
0
        internal void PolicySelectMenu_ItemSelected(CountryConfig.PolicyRow policyRow)
        {
            try
            {
                if (policyRow == null) //user selected menu item "Full Spine"
                {
                    PolicyViewChanged(false);
                    return;
                }

                CountryConfigFacade countryConfigFacade = CountryAdministration.CountryAdministrator.GetCountryConfigFacade(_mainForm.GetCountryShortName());
                if (_singlePolicyView) //in single-poliy-view: display the selected policy as "the" policy
                {
                    _idsDisplayedSinglePolicy.Clear();

                    //need to gather policy-ids of all systems as the FillTreeList function has just one of them
                    foreach (string systemID in GetSystemIDs())
                    {
                        System.Data.DataRow twinRow = CountryConfigFacade.GetTwinRow(policyRow, systemID);
                        if (twinRow != null && (twinRow as CountryConfig.PolicyRow) != null)
                        {
                            _idsDisplayedSinglePolicy.Add((twinRow as CountryConfig.PolicyRow).ID);
                        }
                    }

                    RedrawTreeForPolicyView(); //update the tree to realise the selected view
                }
                else //in full-spine-view: jump to the selected policy
                {
                    foreach (TreeListNode policyNode in _mainForm.treeList.Nodes)
                    {
                        PolicyTreeListTag policyTag = policyNode.Tag as PolicyTreeListTag;
                        //need to check policy-ids of all systems as the FillTreeList function (where the policies for the menu were gathered) provided just one of them
                        foreach (CountryConfig.PolicyRow nodePolicyRow in policyTag.GetPolicyRows())
                        {
                            if (nodePolicyRow.ID == policyRow.ID)
                            {
                                _mainForm.treeList.FocusedNode = policyNode;
                                return; //done
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                UserInfoHandler.RecordIgnoredException("TreeListBuilder.selectPolicyMenu_ItemClicked", exception);
            }
        }
Exemple #11
0
        void FillPolicyNodeWithFunctions(CountryConfig.SystemRow systemRow, CountryConfig.PolicyRow policyRow, TreeListNode policyNode, bool isFirstSystem)
        {
            //generate the functions of the policy
            int functionIndex = 0;
            var functionQuery = (from function in policyRow.GetFunctionRows() select function).OrderBy(function => long.Parse(function.Order));

            foreach (CountryConfig.FunctionRow functionRow in functionQuery.ToList <CountryConfig.FunctionRow>())
            {
                TreeListNode functionNode = isFirstSystem ? BuildFunctionNode(policyNode, functionRow) : policyNode.Nodes[functionIndex++];
                (functionNode.Tag as FunctionTreeListTag).AddFunctionRowOfSystem(systemRow.ID, functionRow);
                functionNode.SetValue(systemRow.Name, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(functionRow));

                //generate the parameters of the function
                FillFunctionNodeWithParameters(systemRow, functionRow, functionNode, isFirstSystem);
            }
        }
Exemple #12
0
        string IsPolicyMissing(string country, string policyName)
        {
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
            string faulty           = string.Empty;

            foreach (CountryConfig.SystemRow system in GetPublicSystems(country))
            {
                CountryConfig.PolicyRow pol = ccf.GetPolicyRowByFullName(system.ID, policyName + "_" + country);
                if (pol != null && pol.Private != DefPar.Value.YES &&
                    (pol.Switch == DefPar.Value.ON ||
                     (policyName == DefPol.SPECIAL_POL_OUTPUT_STD_HH && pol.Switch == DefPar.Value.OFF)))
                {
                    continue;
                }
                faulty += system.Name + ", ";
            }
            return(faulty);
        }
        static CountryConfig.FunctionRow GetFunctionRowByPolicyNameAndDisplayOrder(CountryConfigFacade countryConfigFacade,
                                                                                   string systemID, string policyName, string displayOrder)
        {
            try
            {
                CountryConfig.PolicyRow policyRow = countryConfigFacade.GetPolicyRowByFullName(systemID, policyName);
                int displayIndex = Convert.ToInt32(displayOrder) - 1;

                CountryConfig.FunctionRow func = null;
                if (policyRow != null && displayIndex >= 0)
                {
                    List <CountryConfig.FunctionRow> siblingFunctions = policyRow.GetFunctionRows().OrderBy(f => long.Parse(f.Order)).ToList();
                    if (displayIndex < siblingFunctions.Count)
                    {
                        func = siblingFunctions.ElementAt(displayIndex);
                    }
                }
                return(func);
            }
            catch { return(null); }
        }
Exemple #14
0
        internal void InsertPolicyNode(CountryConfig.PolicyRow distinctPolicyRow, int nodeIndex = -1)
        {
            TreeListNode policyNode = _mainForm.treeList.AppendNode(null, null);

            if (nodeIndex != -1)
            {
                _mainForm.treeList.SetNodeIndex(policyNode, nodeIndex);
            }

            //a reference policy is a policy that does not really exist, but marks (in the spine)
            //the re-calculation of a policy that was already calculated further up in the spine
            CountryConfig.PolicyRow referencePolicy = null;

            if (distinctPolicyRow.ReferencePolID != null && distinctPolicyRow.ReferencePolID != string.Empty)
            {
                referencePolicy = _countryConfigFacade.GetPolicyRowByID(distinctPolicyRow.ReferencePolID); //get the "real" policy to assess the necessary information (in essence the name)
            }
            //equip the node with the non system specific information about the policy
            policyNode.SetValue(_policyColumnName, referencePolicy == null ? distinctPolicyRow.Name : referencePolicy.Name);
            policyNode.SetValue(_commentColumnName, distinctPolicyRow.Comment);
            policyNode.Tag             = new PolicyTreeListTag(_mainForm); //here create the tag - (system specific) information will be filled in below
            policyNode.StateImageIndex = policyNode.SelectImageIndex = PolicyTreeListTag.GetStateImageIndex(distinctPolicyRow);
            policyNode.ImageIndex      = -1;                               //not used

            bool isFirstSystem = true;

            foreach (CountryConfig.SystemRow systemRow in _countryConfigFacade.GetSystemRowsOrdered())
            {
                //equip the policy node with the system specific information about the policy
                CountryConfig.PolicyRow policyRow = _countryConfigFacade.GetPolicyRowByNameOrderAndSystemID(distinctPolicyRow.Name,
                                                                                                            distinctPolicyRow.Order, systemRow.ID);
                (policyNode.Tag as PolicyTreeListTag).AddPolicyRowOfSystem(systemRow.ID, policyRow);
                policyNode.SetValue(systemRow.Name, ExtensionAndGroupManager.GetExtensionAdaptedSwitch(policyRow));

                FillPolicyNodeWithFunctions(systemRow, policyRow, policyNode, isFirstSystem);
                isFirstSystem = false;
            }
        }
Exemple #15
0
        private void EM2_FixUprating(CountryConfig.SystemRow sr1, Dictionary <string, string> upratingFactors, Dictionary <string, string> upratingFactors2, string countryShortName, double alpha, int uprateType, bool treatAsMarket)
        {
            // first get the ils_origy & ils_ben components
            CountryConfig.PolicyRow ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ilsdef_" + countryShortName).ToLower());
            if (ilsdef == null)
            {
                ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ildef_" + countryShortName).ToLower());
            }
            if (ilsdef == null)
            {
                return;
            }

            CountryConfig.FunctionRow[] il_funcs = ilsdef.GetFunctionRows();
            List <string> ils_origy       = ExpandIncomeList(DefVarName.ILSORIGY, il_funcs).Keys.ToList();
            List <string> ils_ben         = ExpandIncomeList(DefVarName.ILSBEN, il_funcs).Keys.ToList();
            List <string> overrideInclude = ExpandIncomeList("pet_override", il_funcs).Where(x => x.Value).Select(x => x.Key).ToList();
            List <string> overrideExclude = ExpandIncomeList("pet_override", il_funcs).Where(x => !x.Value).Select(x => x.Key).ToList();

            List <string> reservedWords = new List <string> {
                "dataset", "def_factor", "factor_name", "factor_value", "factor_condition", "aggvar_name", "aggvar_part", "aggvar_tolerance", "warnifnofactor", "run_cond"
            };

            // Then apply them to the appropriate variables of s1
            foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows())
            {
                if (fr.Name.ToLower() == "uprate")
                {
                    foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows())
                    {
                        string pn = pr.Name.ToLower();

                        if (!reservedWords.Contains(pn))
                        {
                            if (uprateType == 3)    // uprate all
                            {
                                double val;
                                if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                {
                                    pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) * alpha).ToString());
                                }
                                else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                {
                                    pr.Value = FixDecSep((val * alpha).ToString());
                                }
                            }
                            else
                            {
                                bool marketIncome = overrideInclude.Contains(pn);   // if in the override include list
                                if (!overrideExclude.Contains(pn) && !marketIncome) // else if not in the override exlcude list
                                {
                                    VarConfig.VariableRow v = EM_AppContext.Instance.GetVarConfigFacade().GetVariableByName(pn);
                                    if (v == null || v.Monetary != "1")
                                    {
                                        marketIncome = false;
                                    }
                                    else
                                    {
                                        if (treatAsMarket)
                                        {
                                            marketIncome = !pn.EndsWith(DefGeneral.POSTFIX_SIMULATED);
                                        }
                                        else
                                        {
                                            marketIncome = !ils_ben.Contains(pn) && (pn[0] == 'y' || pn[0] == 'a' || pn[0] == 'x' || ils_origy.Contains(pn));
                                        }
                                    }
                                }

                                // if this is a market income
                                if (marketIncome)
                                {
                                    if (uprateType == 1)
                                    {
                                        double val;
                                        if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()]) * alpha).ToString());
                                        }
                                        else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                        {
                                            pr.Value = FixDecSep((val * alpha).ToString());
                                        }
                                    }
                                    else if (uprateType == 2)
                                    {
                                        if (upratingFactors.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()])).ToString());
                                        }
                                    }
                                }
                                else    // if it is non-market income
                                {
                                    if (uprateType == 2)
                                    {
                                        double val;
                                        if (upratingFactors2.ContainsKey(pr.Value.ToLower()))
                                        {
                                            pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) / alpha).ToString());
                                        }
                                        else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val))
                                        {
                                            pr.Value = FixDecSep((val / alpha).ToString());
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (uprateType > 1)
            {
                string[] monetaryTypes = new string[] { DefPeriod.M, DefPeriod.Y, DefPeriod.Q, DefPeriod.W,
                                                        DefPeriod.D, DefPeriod.L, DefPeriod.S, DefPeriod.C };
                foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows())
                {
                    foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows())
                    {
                        string val = pr.Value.ToLower().Trim();
                        if (val.Length < 3)
                        {
                            continue;
                        }
                        string valType = val.Substring(val.Length - 2);

                        if (monetaryTypes.Contains(valType))
                        {
                            val = val.Substring(0, val.Length - 2);
                            if (uprateType == 2)
                            {
                                pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) / alpha).ToString()) + valType;
                            }
                            else if (uprateType == 3)
                            {
                                pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) * alpha).ToString()) + valType;
                            }
                        }
                    }
                }
            }
            try
            {
                // Then, fix the output filenames
                sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower())
                .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput")
                .GetParameterRows().First(p => p.Name.ToLower() == "file")
                .Value = sr1.Name + "_std";
                sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower())
                .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput")
                .GetParameterRows().First(p => p.Name.ToLower() == "file")
                .Value = sr1.Name + "_std_hh";
                // Finally, if required, do the scaling
                if (checkRadioMarket.Checked)
                {
                    CountryConfig.FunctionRow fr = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower())
                                                   .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput");
                    CountryConfig.FunctionRow fr_hh = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower())
                                                      .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput");

                    if (fr.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0)
                    {
                        CountryConfig.ParameterRow fpr = fr.GetParameterRows().First(p => p.Name.ToLower() == "file");
                        CountryConfig.ParameterRow cpr = CountryConfigFacade.AddParameterRow(fpr, false,
                                                                                             DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy));
                        cpr.Value = FixDecSep((1 / alpha).ToString());
                    }
                    else
                    {
                        CountryConfig.ParameterRow mpr = fr.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower());
                        double d;
                        if (!EM_Helpers.TryConvertToDouble(mpr.Value, out d))
                        {
                            d = 1;
                        }
                        mpr.Value = FixDecSep((d / alpha).ToString());
                    }

                    if (fr_hh.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0)
                    {
                        CountryConfig.ParameterRow fpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == "file");
                        CountryConfig.ParameterRow cpr    = CountryConfigFacade.AddParameterRow(fpr_hh, false,
                                                                                                DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy));
                        cpr.Value = FixDecSep((1 / alpha).ToString());
                    }
                    else
                    {
                        CountryConfig.ParameterRow mpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower());
                        double d;
                        if (!EM_Helpers.TryConvertToDouble(mpr_hh.Value, out d))
                        {
                            d = 1;
                        }
                        mpr_hh.Value = FixDecSep((d / alpha).ToString());
                    }
                }
            }
            catch
            {
                throw new Exception("Problem in default output functions.");
            }
        }
Exemple #16
0
 private static string GetCC(CountryConfig.PolicyRow polRow)
 {
     return(polRow.SystemRow.CountryRow.ShortName);
 }
Exemple #17
0
        internal static bool IsOldStyleExtensions(string cc, out bool openReadOnly)
        {
            openReadOnly = false; bool isOldStyle = false;
            // check for all policies with switch='switch' whether they are part of any extension ...
            foreach (CountryConfig.PolicyRow pol in from p in GetCountryConfig(cc).Policy where p.Switch == DefPar.Value.SWITCH select p)
            {
                if (!(from ep in GetCountryConfig(cc).Extension_Policy where ep.PolicyID == pol.ID && !ep.BaseOff select ep).Any())
                {
                    isOldStyle = true; break;
                }
            }
            if (!isOldStyle)
            {
                return(false);
            }

            // ... if not - suggest transformation to new style
            if (UserInfoHandler.GetInfo("The country needs to be updated to the new handling for Extensions (aka Switchable Policies)." + Environment.NewLine +
                                        "If you click Cancel the country will be opened in read-only mode.", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                openReadOnly = true; return(true);
            }

            // transform to new style: this assumes that the 'switch' settings in the spine are ok and just adds policies to extensions, which fulfill the name-pattern requirements
            CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(cc);

            try
            {
                foreach (GlobLocExtensionRow ext in GetGlobalExtensions())
                {
                    foreach (CountryConfig.PolicyRow polRow in ccf.GetPolicyRowsOrderedAndDistinct())
                    {
                        string polName = string.IsNullOrEmpty(polRow.ReferencePolID) ? polRow.Name : ccf.GetPolicyRowByID(polRow.ReferencePolID).Name;
                        if (!EM_Helpers.DoesValueMatchPattern(ext.ShortName, polName))
                        {
                            continue;
                        }

                        foreach (CountryConfig.SystemRow sysRow in ccf.GetSystemRows())
                        {
                            CountryConfig.PolicyRow polSysRow = ccf.GetPolicyRowByOrder(polRow.Order, sysRow.ID);
                            if (!(from e in ccf.GetCountryConfig().Extension_Policy
                                  where e.ExtensionID == ext.ID & e.PolicyID == polSysRow.ID
                                  select e).Any()) // avoid double adding, which could actually only be caused by "playing"
                            {
                                ccf.GetCountryConfig().Extension_Policy.AddExtension_PolicyRow(ext.ID, polSysRow, false);
                            }
                        }
                    }
                }
                GetCountryConfig(cc).AcceptChanges();
                CountryAdministrator.WriteXML(cc);
            }
            catch (Exception exception)
            {
                UserInfoHandler.ShowException(exception, "Adapting Extensions failed.", false);
                ccf.GetCountryConfig().RejectChanges();
            }

            return(true);
        }
Exemple #18
0
 internal static string GetExtensionAdaptedSwitch(CountryConfig.PolicyRow polRow)
 {
     return(ShowExtensionSwitchEditor(polRow) ? DefPar.Value.SWITCH : polRow.Switch);
 }
Exemple #19
0
 internal static bool ShowExtensionSwitchEditor(CountryConfig.PolicyRow polRow)
 {
     return((from ep in GetCountryConfig(GetCC(polRow)).Extension_Policy
             where ep.PolicyID == polRow.ID && ep.BaseOff == false select ep).Any());
 }
        void AddPolicies()
        {
            //analyse all AddOn_Pol functions
            foreach (CountryConfig.FunctionRow function_AddOnPolicy in
                     _addOnCountryConfigFacade.GetFunctionRowsBySystemIDAndFunctionName(_addOnSystemRow.ID, DefFun.AddOn_Pol))
            {
                if (function_AddOnPolicy.Switch.ToLower() != DefPar.Value.ON.ToLower())
                {
                    continue;
                }

                //assess which policy is to be merged and whereto by interpreting the AddOnPol-function's parameters
                CountryConfig.ParameterRow parameter_PolicyName         = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnPolicy.ID, DefPar.AddOn_Pol.Pol_Name);
                CountryConfig.ParameterRow parameter_InsertAfterPolicy  = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnPolicy.ID, DefPar.AddOn_Pol.Insert_After_Pol);
                CountryConfig.ParameterRow parameter_InsertBeforePolicy = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnPolicy.ID, DefPar.AddOn_Pol.Insert_Before_Pol);
                CountryConfig.ParameterRow parameter_AllowDuplicates    = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnPolicy.ID, "allow_duplicates");

                if (parameter_PolicyName == null || (parameter_InsertAfterPolicy == null && parameter_InsertBeforePolicy == null))
                {
                    if (parameter_PolicyName == null)
                    {
                        _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnPolicy,
                                                                                  "Compulsory parameter '" + DefPar.AddOn_Pol.Pol_Name + "' not defined.");
                    }
                    if (parameter_InsertAfterPolicy == null && parameter_InsertBeforePolicy == null)
                    {
                        _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnPolicy, "Compulsory parameter '" +
                                                                                  DefPar.AddOn_Pol.Insert_After_Pol +
                                                                                  "' (alternatively '" + DefPar.AddOn_Pol.Insert_Before_Pol + "') not defined.");
                    }
                    continue;
                }

                //search for the policy to insert in the add-on-system and for the link-policy (before/after the which the policy is to be inserted) in the just generated (copied) system
                CountryConfig.PolicyRow addOnPolicy_Policy = _addOnCountryConfigFacade.GetPolicyRowByName(_addOnSystemRow.ID, parameter_PolicyName.Value);
                bool   before = parameter_InsertBeforePolicy != null ? true : false;
                string referencePolicyName = before ? parameter_InsertBeforePolicy.Value : parameter_InsertAfterPolicy.Value;
                referencePolicyName = ImportExportHelper.ReplaceCountrySymbol(referencePolicyName, _mergeCountryConfigFacade.GetCountryShortName()); //replace =cc= by country-short-name
                CountryConfig.PolicyRow addOnPolicy_ReferencePolicy = _mergeCountryConfigFacade.GetPolicyRowByName(_mergeSystemRow.ID, referencePolicyName);

                if (addOnPolicy_Policy == null || addOnPolicy_ReferencePolicy == null)
                {
                    if (addOnPolicy_Policy == null)
                    {
                        _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnPolicy, "Unknown policy '" + parameter_PolicyName.Value + "'.");
                    }
                    if (addOnPolicy_ReferencePolicy == null)
                    {
                        _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnPolicy, "Unknown policy '" + referencePolicyName + "'.");
                    }
                    continue;
                }

                //if everything is ok, insert the policy at the indicated place
                bool allowDuplicates = parameter_AllowDuplicates != null && parameter_AllowDuplicates.Value == DefPar.Value.YES;
                CountryConfig.PolicyRow addOnPolicyRow = CountryConfigFacade.CopyPolicyRow(addOnPolicy_Policy,
                                                                                           addOnPolicy_Policy.Name,
                                                                                           addOnPolicy_ReferencePolicy, before,
                                                                                           addOnPolicy_Policy.Switch == DefPar.Value.NA,
                                                                                           !allowDuplicates);             //unless duplicates of policies are not foreseen: keep all ids identically
                                                                                                                          //otherwise the id-references (e.g. in ChangeParam, AddOn_Par, etc.) within the add-on would not work

                ImportExportHelper.ReplaceCountrySymbol(addOnPolicyRow, _mergeCountryConfigFacade.GetCountryShortName()); //replace all incidents of =cc= by country symbol
            }
        }
Exemple #21
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 void AddPolicyRowOfSystem(string systemID, CountryConfig.PolicyRow policyRow)
 {
     _policyRows.Add(systemID, policyRow);
 }
Exemple #23
0
 internal void AddToAvailablePolicies(CountryConfig.PolicyRow policyRow)
 {
     _availablePolicies.Add(policyRow);
 }