internal override bool Execute(TreeListNode senderNode) { BaseTreeListTag tag = senderNode.Tag as BaseTreeListTag; if (tag.GetDefaultParameterRow() != null) { return(parameterIDs.Contains(tag.GetDefaultParameterRow().ID)); } if (tag.GetDefaultFunctionRow() != null) { return(functionIDs.Contains(tag.GetDefaultFunctionRow().ID)); } return(policyIDs.Contains(tag.GetDefaultPolicyRow().ID)); }
internal static List <ExtensionOrGroup> GetExtensionDrawInfo(string cc, TreeListNode node) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { return(new List <ExtensionOrGroup>()); } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; Dictionary <string, LookDef.STYLE> extIdsAndStyles = new Dictionary <string, LookDef.STYLE>(); foreach (CountryConfig.Extension_PolicyRow extPolRow in from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol) { extIdsAndStyles.Add(extPolRow.ExtensionID, extPolRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON); } if (nodeTag.GetDefaultFunctionRow() != null) { foreach (CountryConfig.Extension_FunctionRow extFunRow in from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun) { // function-setting with regard to BaseOff overwrites policy-setting (in fact only BaseOff=true may overwrite BaseOff=false, but this is not the point to check for observing this rule) if (extIdsAndStyles.ContainsKey(extFunRow.ExtensionID)) { extIdsAndStyles[extFunRow.ExtensionID] = extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON; } else { extIdsAndStyles.Add(extFunRow.ExtensionID, extFunRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON); } } } if (nodeTag.GetDefaultParameterRow() != null) { foreach (CountryConfig.Extension_ParameterRow extParRow in from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar) { // see overwriting rule above if (extIdsAndStyles.ContainsKey(extParRow.ExtensionID)) { extIdsAndStyles[extParRow.ExtensionID] = extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON; } else { extIdsAndStyles.Add(extParRow.ExtensionID, extParRow.BaseOff ? LookDef.STYLE.EXTENSION_OFF : LookDef.STYLE.EXTENSION_ON); } } } List <ExtensionOrGroup> extensions = new List <ExtensionOrGroup>(); foreach (GlobLocExtensionRow e in GetExtensions(cc)) { if (extIdsAndStyles.ContainsKey(e.ID)) { extensions.Add(new ExtensionOrGroup(e, extIdsAndStyles[e.ID])); } } return(extensions); }
internal static List <ExtensionOrGroup> GetLookGroupDrawInfo(string cc, TreeListNode node) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { return(new List <ExtensionOrGroup>()); } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; List <string> lookGroupIds = (from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol.LookGroupID).ToList(); if (nodeTag.GetDefaultFunctionRow() != null) { lookGroupIds.AddRange((from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun.LookGroupID)); } if (nodeTag.GetDefaultParameterRow() != null) { lookGroupIds.AddRange((from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar.LookGroupID)); } List <ExtensionOrGroup> lookGroups = new List <ExtensionOrGroup>(); foreach (CountryConfig.LookGroupRow lg in GetCountryConfig(cc).LookGroup) { if (lookGroupIds.Contains(lg.ID)) { lookGroups.Add(new ExtensionOrGroup(lg)); } } return(lookGroups); }
List <IntelliItem> GetIntelliItems() { List <IntelliItem> intelliItems = new List <IntelliItem>(); intelliItems.Clear(); try { if (_treeList.FocusedNode.Tag == null) { return(intelliItems); //should not happen } BaseTreeListTag nodeTag = _treeList.FocusedNode.Tag as BaseTreeListTag; SystemTreeListTag systemTag = null; //first assess which intelli-items should be shown in dependece of the edited cell ... List <int> specficIntelliItems = null; if (TreeListBuilder.IsPolicyColumn(_treeList.FocusedColumn)) //editited cell is an exceptionally editable policy-column-cell (e.g. functions DefIL, DefConst, SetDefault, etc.) { //take system specific intelli-items (e.g. incomelists) from any existing system, as one cannot know for which system the user wants to define the parameter TreeListColumn anySystemColumn = _treeList.Columns.ColumnByName(nodeTag.GetDefaultPolicyRow().SystemRow.Name); if (anySystemColumn != null) { systemTag = anySystemColumn.Tag as SystemTreeListTag; } //in dependence of the function define the available intelli-items (e.g. only variables or variables and incomelists, etc.) specficIntelliItems = GetIntelliItemsForEditablePolicyColumn(nodeTag.GetDefaultFunctionRow().Name); } else if (TreeListBuilder.IsSystemColumn(_treeList.FocusedColumn)) { //in dependence of the parameter-value-type define the available intelli-items (usually everything, but e.g. for output_variables only variables) systemTag = _treeList.FocusedColumn.Tag as SystemTreeListTag; specficIntelliItems = nodeTag.GetTypeSpecificIntelliItems(systemTag); } else { return(intelliItems); //should not happen } //... then gather the respective intelli-items //constants defined by function DefConst if ((specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsDefConst)) && systemTag != null) { foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsConstants()) { if (parameterRow.Name.ToLower() == DefPar.DefVar.EM2_Var_Name.ToLower()) { intelliItems.Add(new IntelliItem(parameterRow.Value, parameterRow.Comment, _intelliImageConstant)); } else if (parameterRow.Name.ToLower() == DefPar.DefConst.Condition.ToLower()) { continue; } else { intelliItems.Add(new IntelliItem(parameterRow.Name, GetConstDescription(parameterRow) + " " + parameterRow.Comment, _intelliImageConstant)); } } } //variables defined by function DefVar if ((specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsDefVar)) && systemTag != null) { foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsDefVariables()) { if (parameterRow.Name.ToLower() == DefPar.DefVar.EM2_Var_Name.ToLower()) { intelliItems.Add(new IntelliItem(parameterRow.Value, parameterRow.Comment, _intelliImageVariable)); } else { intelliItems.Add(new IntelliItem(parameterRow.Name, parameterRow.Comment, _intelliImageVariable)); } } } // uprating factors if (specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsUpRateFactor)) { string cc = EM_AppContext.Instance.GetActiveCountryMainForm().GetCountryShortName(); CountryConfigFacade ccf = CountryAdministration.CountryAdministrator.GetCountryConfigFacade(cc); foreach (CountryConfig.UpratingIndexRow ur in ccf.GetUpratingIndices()) { intelliItems.Add(new IntelliItem(ur.Reference, ur.Description, _intelliImageConstant)); } } //standard variables defined in VarConfig (idhh, yem, poa, ...) if (specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsStandardVar)) { string countryShortName = systemTag == null ? string.Empty : systemTag.GetSystemRow().CountryRow.ShortName; Dictionary <string, string> standardVariables = EM_AppContext.Instance.GetVarConfigFacade().GetVariables_NamesAndDescriptions(countryShortName); foreach (string standardVariable in standardVariables.Keys) { intelliItems.Add(new IntelliItem(standardVariable, standardVariables[standardVariable], _intelliImageVariable)); } } //incomelists defined by function DefIL if ((specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsDefIL)) && systemTag != null) { foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsILs()) { intelliItems.Add(new IntelliItem(parameterRow.Value, systemTag.GetILTUComment(parameterRow), _intelliImageIL)); } } //queries (IsDepChild, ...) if (specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsQueries)) { foreach (var q in DefinitionAdmin.GetQueryNamesAndDesc()) { string queryName = q.Key, queryDesc = q.Value; intelliItems.Add(new IntelliItem(queryName, queryDesc, _intelliImageConfiguration)); //first add normally ... intelliItems.Add(new IntelliItem(_queryPrefix + queryName, //.. then add with query prefix to allow users to see all available queries (is removed before query is inserted) queryDesc, _intelliImageConfiguration)); } } //footnotes if (specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsFootnotes)) { //placeholders for new footnote parameters (#x1[_Level], #x2[_UpLim], etc.) Dictionary <string, string> footnotes = GetFootnoteParametersForIntelli(); foreach (string footnote in footnotes.Keys) { intelliItems.Add(new IntelliItem(footnote, footnotes[footnote], _intelliImageFootnote)); } //existing footnote amount parameters (#_Amount reverserd to Amount#x) footnotes = TreeListManager.GetFunctionsExistingAmountParameters(_treeList.FocusedNode.ParentNode, _treeList.FocusedColumn.GetCaption()); foreach (string footnote in footnotes.Keys) { intelliItems.Add(new IntelliItem(footnote, footnotes[footnote], _intelliImageFootnote)); } //other existing footnote parameters (#_Level, #_UpLim, etc.) footnotes = TreeListManager.GetFunctionsExistingFootnoteParameters(_treeList.FocusedNode.ParentNode, _treeList.FocusedColumn.GetCaption()); foreach (string footnote in footnotes.Keys) { intelliItems.Add(new IntelliItem(footnote, footnotes[footnote], _intelliImageFootnote)); } } if (specficIntelliItems == null || specficIntelliItems.Contains(_intelliContainsRandAbsMinMax)) { intelliItems.Add(new IntelliItem("rand", "Random number", _intelliImageConfiguration)); intelliItems.Add(new IntelliItem("<abs>()", "Absolute value operator", _intelliImageConfiguration)); intelliItems.Add(new IntelliItem("<min> ", "Minimum operator", _intelliImageConfiguration)); intelliItems.Add(new IntelliItem("<max> ", "Maximum operator", _intelliImageConfiguration)); } // special case for parameter DefTU/Members: show the options, e.g. Partner, OwnDepChild, ... if (specficIntelliItems != null && specficIntelliItems.Contains(_intelliContainsDefTUMembers)) { ParameterTreeListTag parTag = nodeTag as ParameterTreeListTag; if (parTag != null) { foreach (string tuMember in new List <string>() { DefPar.DefTu.MEMBER_TYPE.PARTNER_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.OWNCHILD_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.DEPCHILD_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.OWNDEPCHILD_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.LOOSEDEPCHILD_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.DEPPARENT_CAMEL_CASE, DefPar.DefTu.MEMBER_TYPE.DEPRELATIVE_CAMEL_CASE }) { intelliItems.Add(new IntelliItem(tuMember, string.Empty, _intelliImageConfiguration)); } } } //taxunits defined by function DefTU: only for add-ons, which use formulas for all parameters (i.e. also for taxunit parameters) if ((_treeList.Parent as EM_UI_MainForm)._isAddOn && systemTag != null) { foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsTUs()) { intelliItems.Add(new IntelliItem(parameterRow.Value, systemTag.GetILTUComment(parameterRow), _intelliImageTU)); } } return(intelliItems); } catch { //do not jeopardise the UI-stability because IntelliItems cannot be gathered but try if problem can be fixed by updating the info UpdateInfo(); return(intelliItems); } List <int> GetIntelliItemsForEditablePolicyColumn(string functionName) { functionName = functionName.ToLower(); List <int> items = new List <int>(); if (functionName == DefFun.SetDefault.ToLower() || functionName == DefFun.Uprate.ToLower()) { items.Add(_intelliContainsStandardVar); items.Add(_intelliContainsDefVar); //not sure whether variables defined by DefVar should be displayed (?) } if (functionName == DefFun.DefIl.ToLower()) { items.Add(_intelliContainsStandardVar); items.Add(_intelliContainsDefVar); items.Add(_intelliContainsDefConst); items.Add(_intelliContainsDefIL); } //other functions with editable policy column (DefConst, DefVar): no intelliItems (i.e. no suggestions for e.g. constant names) return(items); } }
private static Dictionary <string, Image> GetRelevantGroupMenuItems(string cc, string menuItemName) { Dictionary <string, Image> relevantGroups = new Dictionary <string, Image>(); // (1) add to group: only show groups which still can be added, i.e. where not already all selected elements belong to if (menuItemName == MENU_GROUP_ADD) { foreach (CountryConfig.LookGroupRow groupRow in GetCountryConfig(cc).LookGroup) { bool canBeAdded = false; foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { if ((from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.LookGroupID == groupRow.ID && lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar).Any()) { continue; // node belongs to group } } if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow || isParameterRow) { if ((from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.LookGroupID == groupRow.ID && lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun).Any()) { continue; // node belongs to group } } // means: if (isPolicyRow || isFunctionRow || isParameterRow) if ((from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.LookGroupID == groupRow.ID && lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol).Any()) { continue; // node belongs to group } canBeAdded = true; break; // node, nor parent nodes, do belong to group: can be added } if (!canBeAdded) { continue; } ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } // (2) remove from group: only show groups which can be removed, i.e. where any of the selected elements belongs to else if (menuItemName == MENU_GROUP_REMOVE) { List <string> lookGroupIds = new List <string>(); foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; // "belongs to" means, that the function/parameter itself has to belong to the group, not only the parent if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { lookGroupIds.AddRange(from lgPar in GetCountryConfig(cc).LookGroup_Parameter where lgPar.ParameterID == nodeTag.GetDefaultParameterRow().ID select lgPar.LookGroupID); } else if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow) { lookGroupIds.AddRange(from lgFun in GetCountryConfig(cc).LookGroup_Function where lgFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select lgFun.LookGroupID); } else // means: if (isPolicyRow) { lookGroupIds.AddRange(from lgPol in GetCountryConfig(cc).LookGroup_Policy where lgPol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select lgPol.LookGroupID); } } foreach (CountryConfig.LookGroupRow groupRow in from lg in GetCountryConfig(cc).LookGroup where lookGroupIds.Contains(lg.ID) select lg) { ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } // (3) all other menu items (Expand,etc.): show all groups else { foreach (CountryConfig.LookGroupRow groupRow in GetCountryConfig(cc).LookGroup) { ExtensionOrGroup eg = new ExtensionOrGroup(groupRow); relevantGroups.Add(eg.name, eg.look.GetMenuImage()); } } return(relevantGroups.Any() ? relevantGroups : new Dictionary <string, Image>() { { NO_ITEMS_DEFINED, null } }); }
private static Dictionary <string, Image> GetRelevantExtensionMenuItems(string cc, string menuItemName) { Dictionary <string, Image> relevantExtensions = new Dictionary <string, Image>(); bool globalOnly = menuItemName == MENU_EXTENSION_PRIVATE_ALL || menuItemName == MENU_EXTENSION_NOT_PRIVATE_ALL; // (1) add to extension: only show extensions which still can be added, i.e. where not already all selected elements belong to if (menuItemName == MENU_EXTENSION_ADDON || menuItemName == MENU_EXTENSION_ADDOFF) { foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc)) { bool canBeAdded = false; foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { if ((from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ExtensionID == extRow.ID && ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar).Any()) { continue; // node belongs to extension } } if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow || isParameterRow) { var ef = from eFun in GetCountryConfig(cc).Extension_Function where eFun.ExtensionID == extRow.ID && eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun; if (ef.Any()) { if (nodeTag.GetDefaultParameterRow() == null) { continue; // is actually function-node and belongs to extension } // a parameter-node can still be added as switch-off, if function-node is added as switch-on if (ef.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON) { continue; } } } // means: if (isPolicyRow || isFunctionRow || isParameterRow) var ep = from ePol in GetCountryConfig(cc).Extension_Policy where ePol.ExtensionID == extRow.ID && ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol; if (ep.Any()) { if (nodeTag.GetDefaultParameterRow() == null && nodeTag.GetDefaultFunctionRow() == null) { continue; // is actually policy-node and belongs to extension } // a parameter- or function-node can still be added as switch-off, if policy-node is added as switch-on if (ep.First().BaseOff || menuItemName == MENU_EXTENSION_ADDON) { continue; } } canBeAdded = true; break; // node, nor parent nodes, do belong to extension: can be added } if (!canBeAdded) { continue; } ExtensionOrGroup eg = new ExtensionOrGroup(extRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } // (2) remove from extension: only show extensions which can be removed, i.e. where any of the selected elements belongs to else if (menuItemName == MENU_EXTENSION_REMOVE) { List <string> extIds = new List <string>(); foreach (TreeListNode node in GetSelectedNodes(cc)) { if (CountryAdministrator.IsAddOn(cc) || node.Tag == null || node.Tag as BaseTreeListTag == null) { continue; } BaseTreeListTag nodeTag = node.Tag as BaseTreeListTag; // "belongs to" means, that the function/parameter itself has to belong to the extension, not only the parent if (nodeTag.GetDefaultParameterRow() != null) // means: if (isParameterRow) { extIds.AddRange(from ePar in GetCountryConfig(cc).Extension_Parameter where ePar.ParameterID == nodeTag.GetDefaultParameterRow().ID select ePar.ExtensionID); } else if (nodeTag.GetDefaultFunctionRow() != null) // means: if (isFunctionRow) { extIds.AddRange(from eFun in GetCountryConfig(cc).Extension_Function where eFun.FunctionID == nodeTag.GetDefaultFunctionRow().ID select eFun.ExtensionID); } else // means: if (isPolicyRow) { extIds.AddRange(from ePol in GetCountryConfig(cc).Extension_Policy where ePol.PolicyID == nodeTag.GetDefaultPolicyRow().ID select ePol.ExtensionID); } } foreach (GlobLocExtensionRow gleRow in from e in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc) where extIds.Contains(e.ID) select e) { ExtensionOrGroup eg = new ExtensionOrGroup(gleRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } // (3) all other menu items (Expand,etc.): show all extensions else { foreach (GlobLocExtensionRow extRow in globalOnly ? ExtensionAndGroupManager.GetGlobalExtensions() : ExtensionAndGroupManager.GetExtensions(cc)) { ExtensionOrGroup eg = new ExtensionOrGroup(extRow); relevantExtensions.Add(eg.name, eg.look.GetMenuImage()); } } return(relevantExtensions.Any() ? relevantExtensions : new Dictionary <string, Image>() { { NO_ITEMS_DEFINED, null } }); }