static internal void ReplaceCountrySymbol(CountryConfig.FunctionRow functionRow, string countryShortName) { foreach (CountryConfig.ParameterRow parameterRow in functionRow.GetParameterRows()) { ReplaceCountrySymbol(parameterRow, countryShortName); } }
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); }
static System.Data.DataRow GetDataRowBySymbolicID(string symbolicID, CountryConfigFacade countryConfigFacade, string systemID, bool function) { string policyName = string.Empty; string functionDisplayOrder = string.Empty; string parameterDisplayOrder = string.Empty; CountryConfig.FunctionRow functionRow = null; CountryConfig.ParameterRow parameterRow = null; if (GetPolicyAndOrderFromSymbolicID(symbolicID, countryConfigFacade.GetCountryShortName(), ref policyName, ref functionDisplayOrder, ref parameterDisplayOrder)) { if (EM_Helpers.IsNonNegInteger(functionDisplayOrder)) { functionRow = GetFunctionRowByPolicyNameAndDisplayOrder(countryConfigFacade, systemID, policyName, functionDisplayOrder); } else //take account of functions DefIL and DefTU, which use the (value of the) name parameter as identifier instead of the order { functionRow = GetFunctionRowByPolicyNameAndValueOfSpecialParameter(countryConfigFacade, systemID, policyName, DefPar.DefIl.Name, functionDisplayOrder); } } if (function) { return(functionRow); } if (functionRow != null) { parameterRow = GetParameterRowByDisplayOrder(countryConfigFacade, functionRow.ID, parameterDisplayOrder); } return(parameterRow); }
internal override int GetSpecialNodeColor() { CountryConfig.FunctionRow functionRow = GetDefaultFunctionRow(); if (functionRow == null || functionRow.IsNull(CountryConfigFacade._columnName_Color)) { return(DefPar.Value.NO_COLOR); } return(functionRow.Color); }
//intermediate solution for error-output, needs to be integrated into a user interface produced error-log once available (currently error-log is generated by executable) static internal string GenerateErrorMessage(CountryConfig.FunctionRow addOnFunction, string error) { string errorMessage = "Error: " + error + Environment.NewLine + "System: " + addOnFunction.PolicyRow.SystemRow.Name + " (Order: " + addOnFunction.PolicyRow.SystemRow.Order + ")" + Environment.NewLine + "Policy: " + addOnFunction.PolicyRow.Name + " (Order: " + addOnFunction.PolicyRow.Order + ")" + Environment.NewLine + "Function: " + addOnFunction.Name + " (Order: " + addOnFunction.Order + ")" + Environment.NewLine + "Identifier: " + addOnFunction.ID + Environment.NewLine + Environment.NewLine; return(errorMessage); }
internal static string GetExtensionAdaptedSwitch(CountryConfig.FunctionRow funRow) { if (!ShowExtensionSwitchEditor(funRow)) { return(funRow.Switch); } // function-rows should not show 'switch' if they are only part of an extension-policy (i.e. not themselves extension-functions) and if they are not on // because in that case they are in fact not switchable, but permanently off (or n/a) return(!(from ef in GetCountryConfig(GetCC(funRow)).Extension_Function where ef.FunctionID == funRow.ID && ef.BaseOff == false select ef).Any() && funRow.Switch != DefPar.Value.ON ? funRow.Switch : DefPar.Value.SWITCH); }
TreeListNode BuildFunctionNode(TreeListNode policyNode, CountryConfig.FunctionRow functionRow) { TreeListNode functionNode = _mainForm.treeList.AppendNode(null, policyNode); functionNode.SetValue(_policyColumnName, functionRow.Name); functionNode.SetValue(_commentColumnName, functionRow.Comment); functionNode.StateImageIndex = (functionRow.Private == DefPar.Value.YES) ? DefGeneral.IMAGE_IND_PRIV_FUN : DefGeneral.IMAGE_IND_FUN; functionNode.ImageIndex = functionNode.SelectImageIndex = -1; //not used functionNode.Tag = new FunctionTreeListTag(_mainForm); return(functionNode); }
//performance optimisation Aug 13: for updating just one function instead of the whole tree internal void RefillFunctionNode(TreeListNode functionNode) { functionNode.Nodes.Clear(); bool isFirstSystem = true; foreach (CountryConfig.SystemRow systemRow in _countryConfigFacade.GetSystemRowsOrdered()) { CountryConfig.FunctionRow functionRow = (functionNode.Tag as FunctionTreeListTag).GetFunctionDictionary()[systemRow.ID]; FillFunctionNodeWithParameters(systemRow, functionRow, functionNode, isFirstSystem); isFirstSystem = false; } }
void FillFunctionNodeWithParameters(CountryConfig.SystemRow systemRow, CountryConfig.FunctionRow functionRow, TreeListNode functionNode, bool isFirstSystem) { //generate the parameters of the function int parameterIndex = 0; var parameterQuery = (from parameter in functionRow.GetParameterRows() select parameter).OrderBy(parameter => long.Parse(parameter.Order)); foreach (CountryConfig.ParameterRow parameterRow in parameterQuery.ToList()) { TreeListNode parameterNode = isFirstSystem ? BuildParameterNode(functionNode, parameterRow) : functionNode.Nodes[parameterIndex++]; (parameterNode.Tag as ParameterTreeListTag).AddParameterRowOfSystem(systemRow.ID, parameterRow); parameterNode.SetValue(systemRow.Name, parameterRow.Value); } }
List <CountryConfig.FunctionRow> PasteFunction(Dictionary <string, CountryConfig.FunctionRow> copyFunction, List <string> copySystemIDs, TreeListNode pastePolicyNode, out int pastedFunctionNodeIndex, List <string> pasteSystemIDs = null) { List <CountryConfig.FunctionRow> pastedFunctionRows = new List <CountryConfig.FunctionRow>(); pastedFunctionNodeIndex = -1; if (pasteSystemIDs == null) { pasteSystemIDs = copySystemIDs; //copy within country/add-on (i.e. not to another country/add-on) } for (int index = 0; index < pasteSystemIDs.Count; ++index) //loop over systems { string pasteSystemID = pasteSystemIDs.ElementAt(index); string copySystemID = copySystemIDs.ElementAt(index); bool switchNA = copySystemID == null || //set to n/a if no "twin"-system was assigned in copying the function from one country to another _hiddenSystems.Contains(pasteSystemID); //or destination system is hidden CountryConfig.FunctionRow copyFunctionInSystem = null; if (copySystemID != null) { copyFunctionInSystem = copyFunction[copySystemID]; } else //no "twin"-system was assigned in copying the function from one country to another: still need to copy (default) function for symmetry { copyFunctionInSystem = copyFunction.Values.ElementAt(0); } //'Paste Function Before/After' called from function node if (pastePolicyNode != _pasteNode) { CountryConfig.FunctionRow pasteFunctionRow = (_pasteNode.Tag as FunctionTreeListTag).GetFunctionRowOfSystem(pasteSystemID); pastedFunctionRows.Add(CountryConfigFacade.CopyFunctionRow(copyFunctionInSystem, pasteFunctionRow, _pasteBefore, switchNA)); pastedFunctionNodeIndex = _pasteBefore ? _pasteCountryForm.treeList.GetNodeIndex(_pasteNode) : _pasteCountryForm.treeList.GetNodeIndex(_pasteNode) + 1; } //'Paste Function' called from policy node (paste as last function) else { pastedFunctionRows.Add(CountryConfigFacade.CopyFunctionRowAtTailOrUseOriginalOrder(copyFunctionInSystem, (pastePolicyNode.Tag as PolicyTreeListTag).GetPolicyRowOfSystem(pasteSystemID), true, //copyToEnd switchNA)); } } return(pastedFunctionRows); }
static CountryConfig.ParameterRow GetParameterRowByDisplayOrder(CountryConfigFacade countryConfigFacade, string functionID, string displayOrder) { try { CountryConfig.FunctionRow functionRow = countryConfigFacade.GetFunctionRowByID(functionID); int displayIndex = Convert.ToInt32(displayOrder) - 1; CountryConfig.ParameterRow par = null; if (functionRow != null && displayIndex >= 0) { List <CountryConfig.ParameterRow> siblingParameters = functionRow.GetParameterRows().OrderBy(p => long.Parse(p.Order)).ToList(); if (displayIndex < siblingParameters.Count) { par = siblingParameters.ElementAt(displayIndex); } } return(par); } catch { return(null); } }
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); } }
static internal string GetSymbolicID(CountryConfig.FunctionRow functionRow, string replaceCountryShortName = "") { //for functions DefIL and DefTU use a more practical and less insecure identifier than display order, i.e. the name if (functionRow.Name.ToLower() == DefFun.DefIl.ToLower() || functionRow.Name.ToLower() == DefFun.DefTu.ToLower()) { foreach (CountryConfig.ParameterRow parameterRow in functionRow.GetParameterRows()) { if (parameterRow.Name.ToLower() == DefPar.DefIl.Name.ToLower()) { string symbolicID = parameterRow.Value; //replace country symbol in taxunit name if required (e.g. tu_individual_sl -> tu_individua_=cc=) if (replaceCountryShortName != string.Empty && functionRow.Name.ToLower() == DefFun.DefTu.ToLower() && symbolicID.ToLower().EndsWith(replaceCountryShortName.ToLower())) { symbolicID = symbolicID.Substring(0, symbolicID.Length - replaceCountryShortName.Length) + DefPar.Value.PLACEHOLDER_CC; } return(GetSymbolicID(functionRow.PolicyRow, replaceCountryShortName) + _symbolicID_OrderSeparator + symbolicID); //e.g. ILDef_sl_#ils_dispy for the function defining ils_dispy in policy ILDef_sl } } //should not happen, but if no name-parameter found still use order } //for all other functions use display order return(GetSymbolicID(functionRow.PolicyRow, replaceCountryShortName) + _symbolicID_OrderSeparator + OrderToDisplayOrder(functionRow)); //e.g. ILDef_sl_#10 for the 10th function in policy ILDef_sl }
private int GetMaxGroupUsedByFunction(CountryConfig.FunctionRow functionRow, string groupName) { int maxGroup = 0; List <string> potentialGroupPars = new List <string>(); DefinitionAdmin.Fun fun = DefinitionAdmin.GetFunDefinition(functionRow.Name, false); if (fun != null) // find all parameters belonging to this group, e.g. functionRow.Name=BenCalc, groupName=Comp_X: { // find: Comp_PerTU, Comp_PerElig, Comp_Cond, Comp_LowLim, Comp_UpLim var pgs = from pg in fun.GetGroupParList() where pg.groupName.ToLower() == groupName.ToLower() select pg; if (pgs.Count() > 0) // this should always be fulfilled (i.e. the function has such a group) { foreach (var p in pgs.First().par) { potentialGroupPars.Add(p.Key.ToLower()); foreach (string s in p.Value.substitutes) { potentialGroupPars.Add(s); } } } } foreach (CountryConfig.ParameterRow countryConfigParameterRow in functionRow.GetParameterRows()) { if (countryConfigParameterRow.Group == string.Empty || !EM_Helpers.IsNonNegInteger(countryConfigParameterRow.Group)) { continue; //no group parameter } if (!potentialGroupPars.Contains(countryConfigParameterRow.Name.ToLower()) && !IsPlaceholderSibling(countryConfigParameterRow, potentialGroupPars)) { continue; //no sibling } if (EM_Helpers.SaveConvertToInt(countryConfigParameterRow.Group) > maxGroup) { maxGroup = EM_Helpers.SaveConvertToInt(countryConfigParameterRow.Group); } } return(maxGroup); }
void AddParameters() { //analyse all AddOn_Par functions foreach (CountryConfig.FunctionRow function_AddOnParameters in _addOnCountryConfigFacade.GetFunctionRowsBySystemIDAndFunctionName(_addOnSystemRow.ID, DefFun.AddOn_Par)) { if (function_AddOnParameters.Switch.ToLower() != DefPar.Value.ON.ToLower()) { continue; } //assess which parameters are to be merged and into which function by interpreting the AddOnPar-function's parameters CountryConfig.ParameterRow parameter_InsertFunctionID = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnParameters.ID, DefPar.AddOn_Par.Insert_Func); if (parameter_InsertFunctionID == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnParameters, "Compulsory parameter '" + DefPar.AddOn_Par.Insert_Func + "' not defined."); continue; } //search for the function where parameters are to be added in the just generated (copied) system CountryConfig.FunctionRow addOnParameters_InsertFunction = _mergeCountryConfigFacade.GetFunctionRowByID(parameter_InsertFunctionID.Value); if (addOnParameters_InsertFunction == null) //take account of 'symbolic' identifier, e.g. output_std_sl_#3 { addOnParameters_InsertFunction = ImportExportHelper.GetFunctionRowBySymbolicID(parameter_InsertFunctionID.Value, _mergeCountryConfigFacade, _mergeSystemRow.ID); } if (addOnParameters_InsertFunction == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnParameters, "Unknown function '" + parameter_InsertFunctionID.Value + "'."); continue; } //if everything is ok, insert the parameters (all other parameters than insert_func in AddOn_Par) into the function foreach (CountryConfig.ParameterRow addOnParameters_ParameterNameAndValue in function_AddOnParameters.GetParameterRows()) { if (addOnParameters_ParameterNameAndValue.Name.ToLower() == DefPar.AddOn_Par.Insert_Func.ToLower()) { continue; } DefinitionAdmin.Par parDef = DefinitionAdmin.GetParDefinition(addOnParameters_InsertFunction.Name, addOnParameters_ParameterNameAndValue.Name, false); if (parDef == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnParameters, "Function '" + addOnParameters_InsertFunction.Name + "' does not allow for parameter '" + addOnParameters_ParameterNameAndValue.Name + "'."); continue; } //add parameter, however if a respective parameter with value n/a exists, it can be used //this is even necessary for single parameters (which may only exist once) if an add-on is added more than once (i.e. there is already the n/a parameter of the first adding-on) CountryConfig.ParameterRow parameterRow = null; List <CountryConfig.ParameterRow> parameterList = (from pR in addOnParameters_InsertFunction.GetParameterRows() where pR.Name.ToLower() == addOnParameters_ParameterNameAndValue.Name.ToLower() && pR.Group == addOnParameters_ParameterNameAndValue.Group && pR.Value == DefPar.Value.NA select pR).ToList(); if (parameterList.Count != 0) { parameterRow = parameterList.First(); } if (parameterRow == null) { parameterRow = CountryConfigFacade.AddParameterRowAtTail(addOnParameters_InsertFunction, addOnParameters_ParameterNameAndValue.Name, parDef); } if (parameterRow.Name.ToLower() == DefinitionAdmin.ParTypeToString(DefPar.PAR_TYPE.PLACEHOLDER).ToLower()) { parameterRow.Name = addOnParameters_ParameterNameAndValue.Name; //for adding parameters e.g. to function DefIL } parameterRow.Value = addOnParameters_ParameterNameAndValue.Value; parameterRow.Comment = addOnParameters_ParameterNameAndValue.Comment; ImportExportHelper.ReplaceCountrySymbol(parameterRow, _mergeCountryConfigFacade.GetCountryShortName()); //replace all incidents of =cc= by country symbol } } }
internal void AddFunctionRowOfSystem(string systemID, CountryConfig.FunctionRow functionRow) { _functionRows.Add(systemID, functionRow); }
static string OrderToDisplayOrder(CountryConfig.FunctionRow functionRow) { List <CountryConfig.FunctionRow> siblingFunctions = functionRow.PolicyRow.GetFunctionRows().OrderBy(f => long.Parse(f.Order)).ToList(); return((siblingFunctions.IndexOf(functionRow) + 1).ToString()); }
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."); } }
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); }
private static string GetCC(CountryConfig.FunctionRow funRow) { return(funRow.PolicyRow.SystemRow.CountryRow.ShortName); }
internal void UpdateContent(TreeListNode focusedNode) { try { if (_inApplyAction) { return; } _displayedFunctionRow = null; _focusedNode = focusedNode; //needed to know where to put the parameters within the function if (_focusedNode != null && _focusedNode.Tag != null) { _displayedFunctionRow = (_focusedNode.Tag as BaseTreeListTag).GetDefaultFunctionRow(); //selected function or function where selected parameter is part of (null if policy selelcted) } ClearContent(); //empty controls and activate/deactivate corresponding to whether a function is selected in the tree or not if (_displayedFunctionRow == null) { return; //no function selected in tree } lblFunction.Text = _displayedFunctionRow.Name + " (order: " + _displayedFunctionRow.Order + ") in policy " + _displayedFunctionRow.PolicyRow.Name; Dictionary <string, string> groupList = new Dictionary <string, string>(); //helper list for group parameters foreach (AddParameterTag apt in GetFullParList(_displayedFunctionRow.Name)) { string parName = apt._parName; DefinitionAdmin.Par parDef = apt._parDef; string groupName = apt._parGroup == null ? string.Empty : apt._parGroup.groupName; bool isGroup = apt._parGroup != null; //parameter belongs/doesn't belong to a group; does: comp_Cond, comp_perTU bool isSingle = parDef.maxCount == 1; //parameter can/cannot be used more than once; can: DefOuput/Var, cannot: TAX_UNIT bool isFootnote = parDef.isFootnote; //parameter is/isn't a footnote parameter; is: #_UpLim, #_Amount bool isConflict = parDef.substitutes.Count > 0; //parameter has/hasn't a Substitute; has: Output_Var / Output_Add_Var bool isIn = false; //parameter isn't ... foreach (CountryConfig.ParameterRow countryConfigParameterRow in _displayedFunctionRow.GetParameterRows()) { if (countryConfigParameterRow.Name.ToLower() == parName.ToLower()) { isIn = true; //.. is already used in the function break; } } string subsitude = string.Empty; string groupOrNo = string.Empty; string count = string.Empty; if (isSingle && !isGroup && !isFootnote && isIn) { continue; //parameter is already used (and multi use is not possible) } if (!isSingle || isGroup || isFootnote) { count = "1"; //as default multiple useable parameter is added once } if (isGroup) //group parameter, e.g. comp_Cond, comp_perTU { //propse the likely group identifier, i.e. the next available number if (groupList.Keys.Contains(groupName.ToLower())) { groupOrNo = groupList[groupName.ToLower()]; //for all group parameters of the same group the same group identifier is proposed } else { int maxGroup = GetMaxGroupUsedByFunction(_displayedFunctionRow, groupName) + 1; groupOrNo = maxGroup.ToString(); groupList.Add(groupName.ToLower(), groupOrNo); } } if (isFootnote) //footnote parameter, e.g. #_UpLim, #_Amount { //propse the likely footnote identifier, i.e. the next available number groupOrNo = (CountryConfigFacade.GetMaxFootnoteUsedByFunction(_displayedFunctionRow, parName) + 1).ToString(); } if (isConflict && !isGroup) {//if e.g. output_var is already used, still show output_add_var, but put out_var in substitute column TreeListNode functionNode = ((focusedNode.Tag as BaseTreeListTag).GetDefaultParameterRow() == null) ? focusedNode : focusedNode.ParentNode; foreach (TreeListNode parameterNode in functionNode.Nodes) { string parameterName = parameterNode.GetDisplayText(TreeListBuilder._policyColumnName); foreach (string conflictPar in parDef.substitutes) { if (parameterName.ToLower() == conflictPar.ToLower()) { subsitude = parameterName; apt._parameterNode = parameterNode; break; } } if (subsitude != string.Empty) { break; } } } int index = dgvParameter.Rows.Add(false, parName, subsitude, groupOrNo, count, parDef.description); dgvParameter.Rows[index].Tag = apt; } ShowHideRows(); dgvParameter.Select(); } catch (Exception exception) { UserInfoHandler.ShowException(exception); } }
internal static bool ShowExtensionSwitchEditor(CountryConfig.FunctionRow funRow) { return(ShowExtensionSwitchEditor(funRow.PolicyRow) || (from ef in GetCountryConfig(GetCC(funRow)).Extension_Function where ef.FunctionID == funRow.ID && ef.BaseOff == false select ef).Any()); }
void AddILToMatrix(string ILName, CountryConfig.FunctionRow ILDefFunctionRow, Dictionary <string, CountryConfig.FunctionRow> ILNamesAndILDefFunctionRows, ref Dictionary <string, Dictionary <string, double> > matrix, double inhertitedFactor = 1) { foreach (CountryConfig.ParameterRow ILDefParameterRow in ILDefFunctionRow.GetParameterRows()) { if (ILDefParameterRow.Name.ToLower() == DefPar.DefIl.Name.ToLower()) { continue; } string ILEntry = string.Empty; double factor = 0; //new style: incomelist entry (i.e. variable or incomelist) stored in parameter.Name, factor stored in parameter.Value if (EM_Helpers.IsNumeric(ILDefParameterRow.Value) || ILDefParameterRow.Value == "+" || ILDefParameterRow.Value == "-") { if (ILDefParameterRow.Value == "+") { factor = inhertitedFactor; } else if (ILDefParameterRow.Value == "-") { factor = inhertitedFactor * -1.0; } else { factor = inhertitedFactor * EM_Helpers.SaveConvertToDouble(ILDefParameterRow.Value); } ILEntry = ILDefParameterRow.Name.ToLower(); } //old style: incomelist entry (i.e. variable or incomelist) stored in parameter.Value, +/- stored in parameter.Name, factor stored in parameter.Group else { if (ILDefParameterRow.Group == string.Empty) { factor = inhertitedFactor; } else { factor = inhertitedFactor * EM_Helpers.SaveConvertToDouble(ILDefParameterRow.Group); //either there is a factor in the group column or factor is 1 } if (ILDefParameterRow.Name.StartsWith("-")) { factor = inhertitedFactor * (-1); } else if (!ILDefParameterRow.Name.StartsWith("+")) { continue; //should not happen } ILEntry = ILDefParameterRow.Value.ToLower(); } if (ILNamesAndILDefFunctionRows.Keys.Contains(ILEntry)) { AddILToMatrix(ILName, ILNamesAndILDefFunctionRows[ILEntry], ILNamesAndILDefFunctionRows, ref matrix, factor); //recursive call: break incomelist down in its variables } else { if (!matrix.Keys.Contains(ILEntry)) {//variable not yet in matrix: add a variable-row with a column for each incomelist (cell is empty if variable is not contained in an incomelist) Dictionary <string, double> variableNamesAndInitialValues = new Dictionary <string, double>(); foreach (string variableName in ILNamesAndILDefFunctionRows.Keys) { variableNamesAndInitialValues.Add(variableName, 0); } matrix.Add(ILEntry, variableNamesAndInitialValues); } matrix[ILEntry][ILName] += factor; } } }
void AddFunctions() { //analyse all AddOn_Func functions foreach (CountryConfig.FunctionRow function_AddOnFunction in _addOnCountryConfigFacade.GetFunctionRowsBySystemIDAndFunctionName(_addOnSystemRow.ID, DefFun.AddOn_Func)) { if (function_AddOnFunction.Switch.ToLower() != DefPar.Value.ON.ToLower()) { continue; } //assess which function is to be merged and whereto by interpreting the AddOnFunc-function's parameters CountryConfig.ParameterRow parameter_FunctionID = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnFunction.ID, DefPar.AddOn_Func.Id_Func); CountryConfig.ParameterRow parameter_InsertAfterFunction = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnFunction.ID, DefPar.AddOn_Func.Insert_After_Func); CountryConfig.ParameterRow parameter_InsertBeforeFunction = _addOnCountryConfigFacade.GetParameterRowByName(function_AddOnFunction.ID, DefPar.AddOn_Func.Insert_Before_Func); if (parameter_FunctionID == null || (parameter_InsertAfterFunction == null && parameter_InsertBeforeFunction == null)) { if (parameter_FunctionID == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnFunction, "Compulsory parameter '" + DefPar.AddOn_Func.Id_Func + "' not defined."); } if (parameter_InsertAfterFunction == null && parameter_InsertBeforeFunction == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnFunction, "Compulsory parameter '" + DefPar.AddOn_Func.Insert_After_Func + "' (alternatively '" + DefPar.AddOn_Func.Insert_Before_Func + "') not defined."); } continue; } //search for the function to insert in the add-on-system and for the link-function (before/after the which the function is to be inserted) in the just generated (copied) system CountryConfig.FunctionRow addOnFunction_Function = _addOnCountryConfigFacade.GetFunctionRowByID(parameter_FunctionID.Value); if (addOnFunction_Function == null) //take account of 'symbolic' identifier, e.g. ADDON_DOSOMEWHAT_#3 { addOnFunction_Function = ImportExportHelper.GetFunctionRowBySymbolicID(parameter_FunctionID.Value, _addOnCountryConfigFacade, _addOnSystemRow.ID); } bool before = parameter_InsertBeforeFunction != null ? true : false; string referenceFunctionID = before ? parameter_InsertBeforeFunction.Value : parameter_InsertAfterFunction.Value; CountryConfig.FunctionRow addOnFunction_ReferenceFunction = _mergeCountryConfigFacade.GetFunctionRowByID(referenceFunctionID); if (addOnFunction_ReferenceFunction == null) //take account of 'symbolic' identifier { addOnFunction_ReferenceFunction = ImportExportHelper.GetFunctionRowBySymbolicID(referenceFunctionID, _mergeCountryConfigFacade, _mergeSystemRow.ID); } if (addOnFunction_Function == null || addOnFunction_ReferenceFunction == null) { if (addOnFunction_Function == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnFunction, "Unknown function '" + parameter_FunctionID.Value + "'."); } if (addOnFunction_ReferenceFunction == null) { _errorMessages += ImportExportHelper.GenerateErrorMessage(function_AddOnFunction, "Unknown function '" + referenceFunctionID + "'."); } continue; } //if everything is ok, insert the function at the indicated place CountryConfig.FunctionRow addOnFunctionRow = CountryConfigFacade.CopyFunctionRow(addOnFunction_Function, addOnFunction_ReferenceFunction, before, addOnFunction_Function.Switch == DefPar.Value.NA, true); //keep all ids identically: otherwise the id-references (e.g. in ChangeParam, AddOn_Par, etc.) within the add-on would not work ImportExportHelper.ReplaceCountrySymbol(addOnFunctionRow, _mergeCountryConfigFacade.GetCountryShortName()); //replace all incidents of =cc= by country symbol } }