internal override bool Perform()
        {
            if (!AcronymManager.IsAcronymNode(_treeAcronyms.FocusedNode))
            {
                return(false);
            }

            VarConfig.AcronymRow acronymRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymRow;

            string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, acronymRow.AcronymLevelRow.AcronymTypeRow.ShortName);

            if (usingVariables != string.Empty)
            {
                if (Tools.UserInfoHandler.GetInfo("Acronym is used by variable(s) " + usingVariables + "\n\nCancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    return(false);
                }

                List <VarConfig.AcronymRow> usedAcronyms = new List <VarConfig.AcronymRow>();
                usedAcronyms.Add(acronymRow);
                acronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels
                _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronyms);
            }

            acronymRow.Delete();
            return(true);
        }
        bool DoChangeIfUsed(string typeShortName, string newValue)
        {
            string usage = string.Empty;

            foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(typeShortName))
            {
                string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, typeShortName);
                if (usingVariables != string.Empty)
                {
                    usage += acronymRow.Name + " used by " + usingVariables + "\n";
                }
            }
            if (usage != string.Empty)
            {
                if (usage.Length > 2000) //probably this will happen only per accident, if a user tries to change types like tax or benefit/pension (MessageBox is then too large for the screen)
                {
                    usage = usage.Substring(0, 2000) + "\n\netc., etc., etc.";
                }

                if (Tools.UserInfoHandler.GetInfo("The following acronyms of this type are used:\n" + usage + "\n\nUndo change?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    _updateVariables        = false;
                    _updateFilterCheckboxes = false;
                    return(false);
                }
            }
            return(true);
        }
        internal override bool Perform()
        {
            if (!AcronymManager.IsTypeNode(_treeAcronyms.FocusedNode))
            {
                return(false);
            }

            VarConfig.AcronymTypeRow typeRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymTypeRow;

            string usage = string.Empty;
            List <VarConfig.AcronymRow> usedAcronymRows = new List <VarConfig.AcronymRow>();

            foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(typeRow.ShortName))
            {
                string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, typeRow.ShortName);
                if (usingVariables != string.Empty)
                {
                    usedAcronymRows.Add(acronymRow);
                    usage += acronymRow.Name + " used by " + usingVariables + Environment.NewLine;
                }
            }

            if (usage != string.Empty)
            {
                if (usage.Length > 2000) //probably this will happen only per accident, if a user tries to delete types like tax or benefit/pension (MessageBox is then too large for the screen)
                {
                    usage = usage.Substring(0, 2000) + Environment.NewLine + Environment.NewLine + "etc., etc., etc.";
                }

                if (Tools.UserInfoHandler.GetInfo("The following acronyms of this type are used:" + Environment.NewLine + usage +
                                                  Environment.NewLine + Environment.NewLine + "Cancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    return(false);
                }

                foreach (VarConfig.AcronymRow usedAcronymRow in usedAcronymRows)
                {
                    usedAcronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels
                }
                typeRow.LongName = VariablesManager.DESCRIPTION_UNKNOWN;
                _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronymRows);
            }

            typeRow.Delete();

            return(true);
        }
Exemple #4
0
        internal override bool Perform()
        {
            if (!AcronymManager.IsLevelNode(_treeAcronyms.FocusedNode))
            {
                return(false);
            }

            VarConfig.AcronymLevelRow levelRow = _treeAcronyms.FocusedNode.Tag as VarConfig.AcronymLevelRow;

            string usage = string.Empty;
            List <VarConfig.AcronymRow> usedAcronymRows = new List <VarConfig.AcronymRow>();

            foreach (VarConfig.AcronymRow acronymRow in _varConfigFacade.GetAcronymsOfType(levelRow.AcronymTypeRow.ShortName))
            {
                if (levelRow.Name.ToLower() != acronymRow.AcronymLevelRow.Name.ToLower())
                {
                    continue;
                }
                string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, levelRow.AcronymTypeRow.ShortName);
                if (usingVariables != string.Empty)
                {
                    usedAcronymRows.Add(acronymRow);
                    usage += acronymRow.Name + " used by " + usingVariables + "\n";
                }
            }

            if (usage != string.Empty)
            {
                if (Tools.UserInfoHandler.GetInfo("The following acronyms of this level are used:\n" + usage + "\nCancel delete?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    return(false);
                }

                foreach (VarConfig.AcronymRow usedAcronymRow in usedAcronymRows)
                {
                    usedAcronymRow.Description = VariablesManager.DESCRIPTION_UNKNOWN; //temporarily rename, to allow for updating automatic labels
                }
                _acronymManager.UpdateAutomaticLabelForSpecificAcronyms(usedAcronymRows);
            }

            levelRow.Delete();

            return(true);
        }
Exemple #5
0
        internal override bool Perform()
        {
            string newValue = _eventArgs.Value.ToString();

            VarConfig.AcronymRow acronymRow = _eventArgs.Node.Tag as VarConfig.AcronymRow;

            List <KeyValuePair <string, string> > updateLabelAcronyms = new List <KeyValuePair <string, string> >();

            //change of acronym-description
            if (_eventArgs.Column.Name == _variablesForm.colAcronymDescription.Name)
            {
                if (newValue == acronymRow.Description)
                {
                    return(false); //only change if different
                }
                acronymRow.Description = newValue;
                updateLabelAcronyms.Add(new KeyValuePair <string, string>(acronymRow.Name, acronymRow.AcronymLevelRow.AcronymTypeRow.ShortName));
            }

            //change of acronym itself
            else
            {
                if (newValue == acronymRow.Name)
                {
                    return(false); //only change if different
                }
                //check for usage
                string usingVariables = _acronymManager.GetVariablesUsingAcronym(acronymRow.Name, acronymRow.AcronymLevelRow.AcronymTypeRow.ShortName);
                if (usingVariables != string.Empty)
                {
                    if (Tools.UserInfoHandler.GetInfo("Acronym is used by variable(s) " + usingVariables + "\n\nUndo change?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        _updateVariables = false;
                        return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables)
                    }
                }

                //check for correctness
                if (newValue.Length != 2)
                {
                    Tools.UserInfoHandler.ShowError("Acronym must have two characters. Please correct.");
                    _updateVariables = false;
                    return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables)
                }
                if (newValue.Contains('#'))
                {
                    Tools.UserInfoHandler.ShowError("Character # is reserved for footnotes and therefore cannot be used for acronyms. Please correct.");
                    _updateVariables = false;
                    return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables)
                }

                string acroType = _eventArgs.Node.ParentNode.ParentNode.GetDisplayText(_variablesForm.colAcronym);
                foreach (VarConfig.AcronymRow silblingRow in _varConfigFacade.GetAcronymsOfType(acroType))
                {
                    if (silblingRow.Name.ToLower() == newValue.ToLower())
                    {
                        Tools.UserInfoHandler.ShowError("Acronym already exists (see level " + silblingRow.AcronymLevelRow.Name + "). Please correct.");
                        _updateVariables = false;
                        return(true); //return true to allow for redraw, i.e. show the old value still stored in the datarow (but only update acronyms, no need to update variables)
                    }
                }

                //care for updating automatic labels of variables concerned
                updateLabelAcronyms.Add(new KeyValuePair <string, string>(newValue, acronymRow.AcronymLevelRow.AcronymTypeRow.ShortName)); //variables already using the new acro-name now get a valid auto-label
                if (usingVariables != string.Empty)
                {
                    updateLabelAcronyms.Add(new KeyValuePair <string, string>(acronymRow.Name, acronymRow.AcronymLevelRow.AcronymTypeRow.ShortName)); //variables, which used the old acro-name get an invalid auto-label
                }
                //finally reflect change in datarow
                acronymRow.Name = newValue;
            }

            //update automatic label of variables concerned
            _variablesForm._acronymManager.UpdateAutomaticLabelForSpecificAcronyms(updateLabelAcronyms);

            return(true);
        }