internal static bool ValidateEditorInput(string value, TreeListNode node, TreeListColumn column, ref string errorText) { if (value == DefPar.Value.NA) { return(true); } CountryConfig.ParameterRow countryParameterRow = (node.Tag as ParameterTreeListTag).GetDefaultParameterRow(); SystemTreeListTag systemColumnTag = column.Tag as SystemTreeListTag; switch (DefinitionAdmin.GetParDefinition(countryParameterRow.FunctionRow.Name, countryParameterRow.Name).valueType) { case DefPar.PAR_TYPE.FORMULA: return(ValidateFormula(value, systemColumnTag, ref errorText)); case DefPar.PAR_TYPE.CONDITION: return(ValidateCondition(value, systemColumnTag, ref errorText)); case DefPar.PAR_TYPE.TEXT: return(ValidateString(value, systemColumnTag, ref errorText)); case DefPar.PAR_TYPE.NUMBER: return(ValidateAmount(value, systemColumnTag, ref errorText)); case DefPar.PAR_TYPE.VAR: return(ValidateVariable(value, systemColumnTag, ref errorText)); case DefPar.PAR_TYPE.VARorIL: return(ValidateVariableIncomelist(value, systemColumnTag, ref errorText)); } return(true); }
static bool ValidateString(string value, SystemTreeListTag systemColumnTag, ref string errorText) { if (EM_Helpers.ContainsIllegalChar(value, ref errorText, _additionallyAllowedChar_TypeString)) { return(false); } return(true); }
internal override void PerformAction() { if (Tools.UserInfoHandler.GetInfo("Are you sure you want to use the current system order as default?", MessageBoxButtons.YesNo) == DialogResult.No) { _actionIsCanceled = true; return; } foreach (TreeListColumn systemColumn in _mainForm.GetTreeListBuilder().GetSystemColums()) { SystemTreeListTag systemTreeListTag = (systemColumn.Tag as SystemTreeListTag); systemTreeListTag.SetSystemOrder(systemColumn.VisibleIndex); } }
static bool ValidateAmount(string value, SystemTreeListTag systemColumnTag, ref string errorText) { //double min = double.MinValue; //double max = double.MaxValue; //bool isInteger = false; //bool allowsPeriod = true; //EM_AppContext.Instance.GetFunctionConfigFacade().GetAmountParameterInfo(configParameterRow, ref isInteger, ref min, ref max, ref allowsPeriod); //if (allowsPeriod) // value = RemoveTailPeriodSymbol(value); //remove #m, #w, etc. at the end //if (isInteger) //{ // if (!EM_Helpers.IsNonNegInteger(value)) // { // errorText = value + " is not a valid integer"; // return false; // } //} //else //{ // if (!EM_Helpers.IsNumeric(value)) // { // errorText = value + " is not a valid number"; // return false; // } //} //bool errorOccured = true; //issuing an error message is not wanted here (error happens if value is empty) //double valueAsNumber = ConvertToDouble(value, ref errorOccured); //if (errorOccured) //{ // errorText = value + " is not a valid number"; // return false; //} //if (valueAsNumber < min) //{ // errorText = value + " is lower than minimum (" + min.ToString() + ")"; // return false; //} //if (valueAsNumber > max) //{ // errorText = value + " exceeds maximum (" + min.ToString() + ")"; // return false; //} return(true); // validation is since ever switched off, as it was not reliable enough, with removing FuncConfig we also drop the (actually never properly filled) info }
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); } } }
static bool ValidateFormula(string value, SystemTreeListTag systemColumnTag, ref string errorText) { if (EM_Helpers.ContainsIllegalChar(value, ref errorText, _additionallyAllowedChar_TypeFormula)) { return(false); } Dictionary <char, char> parenthesesPairsToCheck = new Dictionary <char, char>(); parenthesesPairsToCheck.Add('(', ')'); if (!DoParenthesesMatch(value, ref errorText, parenthesesPairsToCheck)) { return(false); } return(true); }
static bool ValidateVariableIncomelist(string value, SystemTreeListTag systemColumnTag, ref string errorText) { if ((from ILGeneratedByDefIL in systemColumnTag.GetParameterRowsILs() where ILGeneratedByDefIL.Value.ToLower() == value.ToLower() select ILGeneratedByDefIL).ToList().Count > 0) { return(true); } if (ValidateVariable(value, systemColumnTag, ref errorText)) { return(true); } errorText = "neither a valid variable nor incomelist name"; return(false); }
static bool ValidateVariable(string value, SystemTreeListTag systemColumnTag, ref string errorText) { //if ((from variableGeneratedByDefVar in systemColumnTag.vars // where variableGeneratedByDefVar.Value.ToLower() == value.ToLower() // select variableGeneratedByDefVar).ToList().Count > 0) // return true; //if ((from variableGeneratedByDefConst in systemColumnTag.consts // where variableGeneratedByDefConst.Value.ToLower() == value.ToLower() // select variableGeneratedByDefConst).ToList().Count > 0) // return true; //if ((from standardVariable in EM_AppContext.Instance.VarConfigFacade.getVariableNames() // where standardVariable.ToLower() == value.ToLower() // select standardVariable).ToList().Count > 0) // return true; //errorText = "not a valid variable name"; //return false; return(true); //currently not reasonable, as not all possible variables are considered (e.g. those generated by Store) }
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(); } } } }
void mniDescriptionAsComment_Click(object sender, EventArgs e) { //a(ny) system is necessary to find out which incomelists (via DefIL), constants (via DefConst) and variables (via DefVar) are defined and to gather their descriptions TreeListColumn anySystemColumn = null; foreach (TreeListColumn column in _mainForm.treeList.Columns) { if (TreeListBuilder.IsSystemColumn(column)) { anySystemColumn = column; break; } } if (anySystemColumn == null || anySystemColumn.Tag == null) { return; } _mainForm.Cursor = Cursors.WaitCursor; Dictionary <string, string> descriptionsILVarConst = new Dictionary <string, string>(); //gather incomelists and their description in a dictionary to be applied below SystemTreeListTag systemTag = anySystemColumn.Tag as SystemTreeListTag; foreach (DataSets.CountryConfig.ParameterRow ilParameterRow in systemTag.GetParameterRowsILs()) { if (!descriptionsILVarConst.Keys.Contains(ilParameterRow.Value.ToLower())) { descriptionsILVarConst.Add(ilParameterRow.Value.ToLower(), systemTag.GetILTUComment(ilParameterRow)); } } foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsConstants()) { if (!descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower())) { descriptionsILVarConst.Add(parameterRow.Name.ToLower(), parameterRow.Comment); } } foreach (DataSets.CountryConfig.ParameterRow parameterRow in systemTag.GetParameterRowsDefVariables()) { if (!descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower())) { descriptionsILVarConst.Add(parameterRow.Name.ToLower(), parameterRow.Comment); } } //the necessary comment-changes must be gathered in an action-group (to allow for a common undo) ActionGroup actionGroup = new ActionGroup(); //loop over the parameters of the DefIL-function to put the respective descriptions of its components in the comment column BaseTreeListTag treeListTag = _mainForm.treeList.FocusedNode.Tag as BaseTreeListTag; TreeListNode functionNode = treeListTag.GetDefaultParameterRow() != null ? _mainForm.treeList.FocusedNode.ParentNode : _mainForm.treeList.FocusedNode; foreach (TreeListNode parameterNode in functionNode.Nodes) { CountryConfig.ParameterRow parameterRow = (parameterNode.Tag as ParameterTreeListTag).GetDefaultParameterRow(); string description = string.Empty; if (descriptionsILVarConst.Keys.Contains(parameterRow.Name.ToLower())) //component is an incomelist, variable or constant { description = descriptionsILVarConst[parameterRow.Name.ToLower()]; } else //component is a variable (defined in the variables description file) { description = EM_AppContext.Instance.GetVarConfigFacade().GetDescriptionOfVariable(parameterRow.Name, _mainForm.GetCountryShortName()); } if (description != string.Empty) { actionGroup.AddAction(new ChangeParameterCommentAction(parameterNode, description, true, _mainForm.GetTreeListBuilder().GetCommentColumn())); } //else: 'name' parameter, no description or unknown component } if (actionGroup.GetActionsCount() > 0) { _mainForm.PerformAction(actionGroup, false); } _mainForm.Cursor = Cursors.Default; }
// 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); } }
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); } }