Exemplo n.º 1
0
        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);
        }
        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;
        }
        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);
            }
        }