// called when the mouse rests over a formula: if the formula contains contants, returns their value (e.g. $Const1=123, $Const2=456, etc.) static internal string GetDisplayText_ValueOfConstants(CountryConfigFacade ccf, SystemTreeListTag systemTag, string cellContent) { try { if (systemTag == null || cellContent == string.Empty) { return(string.Empty); } string[] parts = cellContent.ToLower().Split(textSplitCharacters); string displayText = string.Empty; foreach (CountryConfig.ParameterRow constant in systemTag.GetParameterRowsConstants()) { if (parts.Contains(constant.Name.ToLower())) { displayText += constant.Name + " = " + GetConstDescription(constant) + Environment.NewLine; } } foreach (CountryConfig.UpratingIndexRow ui in ccf.GetUpratingIndices()) { if (parts.Contains(ui.Reference.ToLower())) { if (string.IsNullOrEmpty(systemTag.GetSystemRow().Year) || !int.TryParse(systemTag.GetSystemRow().Year, out int year)) { break; } Dictionary <int, double> yearValues = ccf.GetUpratingIndexYearValues(ui); if (yearValues.ContainsKey(year)) { displayText += $"{ui.Reference} = {yearValues[year]}"; } } } return(displayText); } 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(string.Empty); } }
internal void UpdateView(SystemTreeListTag systemTag) { this.Text = _defaultCaption + systemTag.GetSystemRow().CountryRow.Name + " " + systemTag.GetSystemRow().Name; Show(); //unhide dialog if closed dgvMatrix.Rows.Clear(); dgvMatrix.Columns.Clear(); _ILDefParameterRows_ContainingILNames = systemTag.GetParameterRowsILs(); if (_ILDefParameterRows_ContainingILNames.Count == 0) { return; } Dictionary <string, Dictionary <string, double> > matrix = new Dictionary <string, Dictionary <string, double> >(); GenerateMatrix(ref matrix); foreach (CountryConfig.ParameterRow _ILDefParameterRows_ContainingILName in _ILDefParameterRows_ContainingILNames) //generate columns with incomelist names as headers { int columnIndex = dgvMatrix.Columns.Add(_ILDefParameterRows_ContainingILName.Value, _ILDefParameterRows_ContainingILName.Value); dgvMatrix.Columns[columnIndex].Width = _columnWidth; //if AutoSizeMode is set to something else than none (e.g. DisplayedCellsExceptHeader) user cannot resize columns anymore } foreach (string variableName in matrix.Keys) //generate rows with variables as header { int rowIndex = dgvMatrix.Rows.Add(); dgvMatrix.Rows[rowIndex].HeaderCell.Value = variableName; foreach (string ILName in matrix[variableName].Keys) { double factor = matrix[variableName][ILName]; if (factor != 0) { dgvMatrix[ILName, rowIndex].Value = factor.ToString(); } } } }
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); } }
internal void SetSystemFormats() {//set backcolor and foreColor of systems' cells according to the conditional formatting settings defined by the user //first clear all current formats foreach (TreeListColumn formatColumn in _mainForm._specialFormatCells.Keys) { _mainForm._specialFormatCells[formatColumn].Clear(); } _mainForm._specialFormatCells.Clear(); foreach (TreeListColumn column in _mainForm.treeList.Columns) { if (IsFixedColumnLeft(column) || IsFixedColumnRight(column)) { continue; //no conditional formatting for policy-, group- and comment-column } SystemTreeListTag systemTag = column.Tag as SystemTreeListTag; foreach (CountryConfig.ConditionalFormatRow conditionalFormatRow in _countryConfigFacade.GetConditionalFormatRowsOfSystem(systemTag.GetSystemRow())) { //first define condition ... IsSpecificBase condition = null; //'standard' conditional formatting: does cell value correspond to specific patterns if (conditionalFormatRow.BaseSystemName == null || conditionalFormatRow.BaseSystemName == string.Empty) { condition = new DoesNodeMatchPatterns(conditionalFormatRow.Condition, column); } //special conditional formatting: show differences between the system and its base-system else { TreeListColumn columnBaseSystem = _mainForm.treeList.Columns.ColumnByName(conditionalFormatRow.BaseSystemName); if (columnBaseSystem == null) { continue; //base system does for whatever reason not exist (was e.g. deleted) } condition = new IsNodeValueDifferent(column, columnBaseSystem); } //... then find all cells which match condition ... TreatSpecificNodes treater = new TreatSpecificNodes(condition, null, false); _mainForm.treeList.NodesIterator.DoOperation(treater); //... finally add to list of cells to be formatted: formatting is accomplished in MainForm's treeList_NodeCellStyle-callback (based on the list) Color backColor = conditionalFormatRow.BackColor == ConditionalFormattingHelper._noSpecialColor ? Color.Empty : ConditionalFormattingHelper.GetColorFromDisplayText(conditionalFormatRow.BackColor); Color foreColor = conditionalFormatRow.ForeColor == ConditionalFormattingHelper._noSpecialColor ? Color.Empty : ConditionalFormattingHelper.GetColorFromDisplayText(conditionalFormatRow.ForeColor); AddToSpecialFormatCells(column, treater.GetSpecificNodes(), backColor, foreColor); } } }