コード例 #1
0
        public static ActionGroup BuildActionGroup(XmlNode node)
        {
            var         name        = node.Attributes["name"].Value;
            var         description = node.Attributes["decription"]?.Value;
            var         path        = GeneratePath("library", "action_group", node.Attributes["src"].Value);
            var         srcCode     = ToCSCode(path);
            ActionGroup group       = new ActionGroup(name, description);

            group.Script = CSharpScript.Create(srcCode,
                                               ScriptOptions.Default.WithReferences(typeof(Superpower).Assembly), typeof(Global));

            foreach (XmlNode cmdComplex in node.ChildNodes)
            {
                switch (cmdComplex.Name)
                {
                case "ActionGroup":
                    group.AddSubGroup(BuildActionGroup(cmdComplex));
                    break;

                case "Execution":
                    group.AddAction(BuildExecution(cmdComplex, group));
                    break;

                case "Field":
                    group.AddAction(BuildField(cmdComplex, group));
                    break;

                default:
                    throw new InvalidOperationException($"\"{cmdComplex.Name}\" is bot a valid xml name");
                }
            }

            return(group);
        }
コード例 #2
0
        internal override void HandleValueChanged(TreeListNode node, TreeListColumn column, string value)
        {
            //check if a change value of a formula or condition requires to add new footnotes (e.g. user selected amount#x1 in itelli -> #x_amount needs to be added)
            Dictionary <KeyValuePair <string, string>, DefinitionAdmin.Par> footnoteParametersToAdd = ParameterValidation.GetFootnoteParametersToAdd(node, ref value);
            ActionGroup editActions = new ActionGroup();

            foreach (KeyValuePair <string, string> footnoteParameterToAdd in footnoteParametersToAdd.Keys)
            {
                editActions.AddAction(new AddParameterAction(node, footnoteParameterToAdd.Key, footnoteParametersToAdd[footnoteParameterToAdd], footnoteParameterToAdd.Value));
            }

            editActions.AddAction(new ChangeParameterValueAction(node, column, value)); //change formula/condition itself

            _mainForm.PerformAction(editActions,                                        //peform all necessary changes
                                    footnoteParametersToAdd.Count > 0,                  //update nodes only if parameters added
                                    false,                                              //no update of columns
                                    node.ParentNode);                                   //performance optimisation Aug 13: update only the concerned function instead of the whole tree
        }
コード例 #3
0
        void btnReplaceAll_Click(object sender, EventArgs e)
        {
            if (IsSearchFieldEmpty())
            {
                return;
            }

            if (cboFind.Text.IndexOfAny(new char[] { '?', '*' }) >= 0)
            {
                if (Tools.UserInfoHandler.GetInfo(_messageNoWildcards, MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
            }

            if (!FindMatches())
            {
                return;
            }

            ActionGroup actionGroup = new ActionGroup();

            foreach (KeyValuePair <TreeListColumn, TreeListNode> foundCell in _foundCells)
            {
                string currentValue = foundCell.Value.GetValue(foundCell.Key).ToString();

                if (TreeListBuilder.IsCommentColumn(foundCell.Key))
                {
                    actionGroup.AddAction(new ChangeParameterCommentAction(foundCell.Value, GetReplacement(currentValue), true,
                                                                           GetActiveMainForm().GetTreeListBuilder().GetCommentColumn()));
                }
                else if (TreeListBuilder.IsSystemColumn(foundCell.Key))
                {
                    actionGroup.AddAction(new ChangeParameterValueAction(foundCell.Value, foundCell.Key, GetReplacement(currentValue), true));
                }
                else if (TreeListBuilder.IsPolicyColumn(foundCell.Key) && foundCell.Value.Tag != null && (foundCell.Value.Tag as BaseTreeListTag).IsPolicyColumnEditable())
                {
                    actionGroup.AddAction(new ChangeParameterNameAction(foundCell.Value, GetReplacement(currentValue), true,
                                                                        GetActiveMainForm().GetTreeListBuilder().GetPolicyColumn()));
                }
            }
            GetActiveMainForm().PerformAction(actionGroup, false);
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        void btnApply_Click(object sender, EventArgs e)
        {
            List <DataGridViewRow> selectedRows = GetSelectedRows();

            if (selectedRows.Count == 0)
            {
                return;
            }

            ActionGroup actionGroup = new ActionGroup();
            List <KeyValuePair <string, string> > conflictParameters = new List <KeyValuePair <string, string> >(); //helper list for dedecting conflicts à la comp_perElig[grp1]/comp_perTU[grp1]

            foreach (DataGridViewRow selectedRow in selectedRows)
            {
                string countAsString = selectedRow.Cells[colCount.Index].Value == null ? "0" : selectedRow.Cells[colCount.Index].Value.ToString();
                uint   count = (countAsString != string.Empty && EM_Helpers.IsNonNegInteger(countAsString)) ? Convert.ToUInt32(countAsString) : 1;
                var    gon = selectedRow.Cells[colGroupNo.Index].Value; string groupOrNo = gon == null? string.Empty : gon.ToString();
                string initialGroupOrNo = groupOrNo;
                string substitute       = selectedRow.Cells[colReplaces.Index].Value.ToString();

                if (substitute != string.Empty)
                {
                    actionGroup.AddAction(new ChangeParameterNameAction((selectedRow.Tag as AddParameterTag)._parameterNode,
                                                                        selectedRow.Cells[colParameter.Index].Value.ToString()));
                    continue;
                }

                for (uint index = 0; index < count; ++index)
                {
                    DefinitionAdmin.Par      parDef   = (selectedRow.Tag as AddParameterTag)._parDef;
                    DefinitionAdmin.ParGroup parGroup = (selectedRow.Tag as AddParameterTag)._parGroup;
                    string parName = (selectedRow.Tag as AddParameterTag)._parName;

                    if (parDef.maxCount == 1 && (parGroup == null || parGroup.maxCount == 1) && count > 1)
                    {
                        count = 1;                 //if parameter is "single" make sure it is only added once!
                    }
                    if (groupOrNo != string.Empty) //group- or footnote-parameter
                    {
                        if (EM_Helpers.IsNonNegInteger(groupOrNo))
                        {
                            groupOrNo = (EM_Helpers.SaveConvertToInt(initialGroupOrNo) + index).ToString();
                        }

                        if (CountryConfigFacade.DoesParameterExist(_displayedFunctionRow, parName, groupOrNo))
                        {//may happen if user changes group or footnote number manually
                            UserInfoHandler.ShowError($"Parameter {parName} with Grp/No {groupOrNo} already exists. " +
                                                      "Please consider Grp/No and/or whether there is a conflict parameter.");
                            return;
                        }
                    }
                    if (parDef.substitutes.Count > 0)
                    {
                        foreach (string conflictPar in parDef.substitutes)
                        {
                            if (conflictParameters.Contains(new KeyValuePair <string, string>(conflictPar.ToLower(), groupOrNo)))
                            {//trying to add e.g. comp_perElig and comp_perTU with same group or output_var and output_add_var
                                string groupMessage = groupOrNo != string.Empty ? " with identical group " + groupOrNo : string.Empty;
                                UserInfoHandler.ShowError($"Cannot add parameter {parName} and parameter {conflictPar} {groupMessage}, as they are subsitudes.");
                                return;
                            }
                        }
                        conflictParameters.Add(new KeyValuePair <string, string>(parName.ToLower(), groupOrNo));
                    }

                    if ((_focusedNode.Tag as BaseTreeListTag).GetDefaultParameterRow() == null)
                    {
                        //if the dialog was opened via the function context menu, parameters are added at the end of the function
                        //thus they can be added simply one after the other, without changing the order ...
                        actionGroup.AddAction(new AddParameterAction(_focusedNode, parName, parDef, groupOrNo));
                    }
                    else
                    {
                        //if the dialog was opened via the parameter context menu, parameters are added after the selected parameter
                        //thus they have to be added in reverted order to keep the given order
                        actionGroup.InsertAction(0, new AddParameterAction(_focusedNode, parName, parDef, groupOrNo));
                    }
                }
            }

            _inApplyAction = true;

            TreeListNode   functionNode = (_focusedNode.Tag as BaseTreeListTag).GetDefaultParameterRow() == null ? _focusedNode : _focusedNode.ParentNode;
            EM_UI_MainForm mainForm     = EM_AppContext.Instance.GetCountryMainForm(_displayedFunctionRow.PolicyRow.SystemRow.CountryRow.ShortName);

            mainForm.PerformAction(actionGroup,
                                   true, false,
                                   functionNode); //performance optimisation Aug 13: update only the concerned function instead of the whole tree

            _inApplyAction = false;

            UpdateContent(functionNode);
        }