bool CheckForUnusedVariables(double progressSoFar, double progressToAchieve, BackgroundWorker backgroundWorker) { if (_variablesToDisplay == null) { _variablesToDisplay = new List <VarConfig.VariableRow>(); } else { _variablesToDisplay.Clear(); } List <VarConfig.VariableRow> variableRows = _varConfigFacade.GetVariables(); for (int i = 0; i < variableRows.Count; ++i) { if (backgroundWorker.CancellationPending) { return(false); //user pressed Cancel button } VarConfig.VariableRow variableRow = variableRows.ElementAt(i); if (IsUnusedVariable(variableRow.Name)) { _variablesToDisplay.Add(variableRow); } double progressPart = (i + 1.0) / (variableRows.Count) * progressToAchieve; backgroundWorker.ReportProgress(Convert.ToInt32((progressSoFar + progressPart) * 100.0)); } //initialise list of variables which are marked to be deleted, to be used in function CheckForUnusedAcronyms _variablesToDelete = (from vR in _variablesToDisplay select vR.Name.ToLower()).ToList <string>(); return(true); }
internal void FillCountrySpecificDescriptionList() { _dgvDescriptions.Rows.Clear(); if (_dgvVariables.SelectedRows.Count != 1 || _dgvVariables.SelectedRows[0].Tag == null) { return; } VarConfig.VariableRow variableRow = _dgvVariables.SelectedRows[0].Tag as VarConfig.VariableRow; foreach (VarConfig.CountryLabelRow countryLabel in variableRow.GetCountryLabelRows()) { int index = _dgvDescriptions.Rows.Add(countryLabel.Country, countryLabel.Label); _dgvDescriptions.Rows[index].Tag = countryLabel; } _variablesForm.colCountry.Width = _variablesForm.colCountry.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); _variablesForm.colCountryDescription.Width = _variablesForm.colCountryDescription.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); if (_dgvDescriptions.SortedColumn == null) { _dgvDescriptions.Sort(_variablesForm.colCountry, System.ComponentModel.ListSortDirection.Ascending); } else { System.ComponentModel.ListSortDirection sortOrder = System.ComponentModel.ListSortDirection.Ascending; if (_dgvDescriptions.SortOrder == SortOrder.Descending) { sortOrder = System.ComponentModel.ListSortDirection.Descending; } _dgvDescriptions.Sort(_dgvDescriptions.SortedColumn, sortOrder); } }
internal override bool Perform() { if (_dgvVariables.SelectedRows.Count != 1) { return(false); } int index = _dgvVariables.Rows.IndexOf(_dgvVariables.SelectedRows[0]); VarConfig.VariableRow variableRow = _dgvVariables.Rows[index].Tag as VarConfig.VariableRow; if (!_varConfigFacade.IsNewRow(variableRow.ID)) { if (Tools.UserInfoHandler.GetInfo("You are deleting a variable that might be used in country implementations. Please consider using the 'clean variables' option to check usage." + Environment.NewLine + Environment.NewLine + "Cancel deleting variable?", MessageBoxButtons.YesNo) == DialogResult.Yes) { return(false); } } _varConfigFacade.DeleteVariable(variableRow); _dgvVariables.Rows.Remove(_dgvVariables.SelectedRows[0]); return(true); }
bool IsCheckedVariable(VarConfig.VariableRow variableRow) { return((!chkMonetary.Checked || variableRow.Monetary == "1") && (!chkNonMonetary.Checked || variableRow.Monetary != "1") && (!chkSimulated.Checked || variableRow.Name.EndsWith(DefGeneral.POSTFIX_SIMULATED)) && (!chkNonSimulated.Checked || !variableRow.Name.EndsWith(DefGeneral.POSTFIX_SIMULATED))); }
internal static VarConfig.VariableRow CopyVariableFromAnotherConfig(VarConfig varConfig, VarConfig.VariableRow originalVar) { VarConfig.VariableRow variableRow = varConfig.Variable.AddVariableRow(originalVar.ID, originalVar.Name, originalVar.Monetary, originalVar.HHLevel, originalVar.AutoLabel); foreach (VarConfig.CountryLabelRow originalLabel in originalVar.GetCountryLabelRows()) { varConfig.CountryLabel.AddCountryLabelRow(originalLabel.ID, variableRow, originalLabel.Country, originalLabel.Label); } return(variableRow); }
internal bool SetCountrySpecificDescription(VarConfig.VariableRow variableRow, string countryShortName, string description) { List <VarConfig.CountryLabelRow> countryLabelRows = (from countryLabel in variableRow.GetCountryLabelRows() where countryLabel.Country.ToLower() == countryShortName.ToLower() select countryLabel).ToList(); if (countryLabelRows.Count != 1) { return(false); //country specific descriptions does not exist (or is not unique, which shouldn't happen) } countryLabelRows.ElementAt(0).Label = description; return(true); }
void PerformImportVariables() { foreach (DataGridViewRow dgvRow in _dgvVariables.Rows) { if (EM_Helpers.SaveConvertToBoolean(dgvRow.Cells[_importVariablesForm.colPerformVariables.Name].Value) != true) { continue; //checkbox to perform change not checked } //adapt variables VarConfig.VariableRow internalVariable = null; VarConfig.VariableRow externalVariable = null; switch (dgvRow.Cells[_importVariablesForm.colAction.Name].Value.ToString()) { case ImportVariablesForm._actionAdd: externalVariable = dgvRow.Tag as VarConfig.VariableRow; internalVariable = _varConfigFacade.AddVariable(externalVariable.Name, externalVariable.Monetary, externalVariable.HHLevel, externalVariable.AutoLabel); foreach (VarConfig.CountryLabelRow externalLabel in externalVariable.GetCountryLabelRows()) { _varConfigFacade.SetCountrySpecificDescription(internalVariable, externalLabel.Country, externalLabel.Label); } _varConfigFacade.Commit(); break; case ImportVariablesForm._actionDelete: internalVariable = dgvRow.Tag as VarConfig.VariableRow; _varConfigFacade.DeleteVariable(internalVariable); _varConfigFacade.Commit(); break; case ImportVariablesForm._actionChange: internalVariable = (dgvRow.Tag as Dictionary <VarConfig.VariableRow, VarConfig.VariableRow>).Keys.ElementAt(0); externalVariable = (dgvRow.Tag as Dictionary <VarConfig.VariableRow, VarConfig.VariableRow>).Values.ElementAt(0); string info = dgvRow.Cells[_importVariablesForm.colInfo.Name].Value.ToString(); if (info == ImportVariablesForm._infoChangeCountryLabel) { foreach (VarConfig.CountryLabelRow externalLabel in externalVariable.GetCountryLabelRows()) { _varConfigFacade.SetCountrySpecificDescription(internalVariable, externalLabel.Country, externalLabel.Label); } } else { internalVariable.Monetary = externalVariable.Monetary; } _varConfigFacade.Commit(); break; } } }
internal override bool Perform() { DataGridViewRow changedRow = _dgvVariables.Rows[_eventArgs.RowIndex]; VarConfig.VariableRow variableRow = changedRow.Tag as VarConfig.VariableRow; if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colVariableName)) { //variables name edited if (variableRow.Name != changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString()) { //only (change and) return true if actually changed variableRow.Name = changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString(); int columnIndexAutoLabel = _variablesForm.dgvVariables.Columns.IndexOf(_variablesForm.colAutomaticLabel); variableRow.AutoLabel = changedRow.Cells[columnIndexAutoLabel].Value.ToString(); return(true); } } if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colMonetary)) {//checkbox monetary edited bool newValue_IsMonetary = (bool)changedRow.Cells[_eventArgs.ColumnIndex].Value; if (VariablesManager.IsMonetary(variableRow) && !newValue_IsMonetary) {//current value monetary, new value non-monetary variableRow.Monetary = "0"; return(true); } if (!VariablesManager.IsMonetary(variableRow) && newValue_IsMonetary) {//current value non-monetary, new value monetary variableRow.Monetary = "1"; return(true); } } if (_eventArgs.ColumnIndex == _dgvVariables.Columns.IndexOf(_variablesForm.colHHLevel)) {//checkbox HH Level edited bool newValue_IsHHLevel = (bool)changedRow.Cells[_eventArgs.ColumnIndex].Value; if (VariablesManager.IsHHLevel(variableRow) && !newValue_IsHHLevel) {//current value hh-level, new value ind-level variableRow.HHLevel = "0"; return(true); } if (!VariablesManager.IsHHLevel(variableRow) && newValue_IsHHLevel) {//current value ind-level, new value hh-level variableRow.HHLevel = "1"; return(true); } } return(false); }
void RestoreRowStates(string selectedRowID, string firstDisplayedRowID) { foreach (DataGridViewRow row in _dgvVariables.Rows) { VarConfig.VariableRow variableRow = row.Tag as VarConfig.VariableRow; if (variableRow.ID == selectedRowID) { row.Selected = true; } if (variableRow.ID == firstDisplayedRowID) { _dgvVariables.FirstDisplayedCell = row.Cells[0]; } } }
internal VarConfig.VariableRow AddVariable(string name = "", string monetary = "1", string hhLevel = "0", string autoLabel = "") { string guid = Guid.NewGuid().ToString(); _guidsOfNewRows.Add(guid); VarConfig.VariableRow variableRow = _varConfig.Variable.AddVariableRow(guid, name, monetary, hhLevel, autoLabel); foreach (string country in GetCountriesShortNames()) { _varConfig.CountryLabel.AddCountryLabelRow(Guid.NewGuid().ToString(), variableRow, country, "-"); } return(variableRow); }
internal void UpdateAutomaticLabelForSpecificAcronyms(List <KeyValuePair <string, string> > acronymsWithType) { foreach (DataGridViewRow row in _variablesForm.dgvVariables.Rows) { VarConfig.VariableRow variableRow = row.Tag as VarConfig.VariableRow; foreach (KeyValuePair <string, string> acronymWithType in acronymsWithType) { if (acronymWithType.Value.ToLower().Contains(VariablesManager.GetVariableType(variableRow.Name).ToLower()) && GetAcronymsUsedByVariable(variableRow.Name).Contains(acronymWithType.Key.ToLower())) { variableRow.AutoLabel = GetAutomaticLabel(variableRow.Name); } } } }
internal string GetVariablesUsingAcronym(string acronym, string acronymType) { string usingVariables = string.Empty; foreach (DataGridViewRow row in _variablesForm.dgvVariables.Rows) { VarConfig.VariableRow variableRow = row.Tag as VarConfig.VariableRow; if (acronymType.ToLower().Contains(VariablesManager.GetVariableType(variableRow.Name).ToLower()) && GetAcronymsUsedByVariable(variableRow.Name).Contains(acronym.ToLower())) { usingVariables += variableRow.Name + " "; } } return(usingVariables); }
internal override bool Perform() { VarConfig.VariableRow variableRow = _varConfigFacade.AddVariable(); int index = 0; if (_dgvVariables.SelectedRows.Count == 1) { index = _dgvVariables.Rows.IndexOf(_dgvVariables.SelectedRows[0]) + 1; } _dgvVariables.Rows.Insert(index, variableRow.Name, VariablesManager.IsMonetary(variableRow), VariablesManager.IsHHLevel(variableRow), false, variableRow.AutoLabel); _dgvVariables.Rows[index].Tag = variableRow; _dgvVariables.Rows[index].Cells[0].Selected = true; //set input focus to just added row (selecting row instead of cell does not work) _dgvVariables.Select(); //grid view must be selected too, otherwise another list may have the input focus return(true); }
internal void HandleEndVariableEdit(DataGridViewCellEventArgs e) { if (e.ColumnIndex == _variablesForm.dgvVariables.Columns.IndexOf(_variablesForm.colVariableName)) { VarConfig.VariableRow variableRow = _variablesForm.dgvVariables.Rows[e.RowIndex].Tag as VarConfig.VariableRow; object val = _variablesForm.dgvVariables[e.ColumnIndex, e.RowIndex].Value; string newVariableName = val == null ? string.Empty : val.ToString(); if (variableRow.Name == newVariableName) { return; //do nothing if not actually changed } string errorText = string.Empty; if (!_varConfigFacade.IsNewRow(variableRow.ID)) { errorText += "You are changing the name of a variable that might be used in country implementations. Please consider using the 'clean variables' option to check usage.\n\n"; } //set automatic label string automaticLabel = _variablesForm._acronymManager.GetAutomaticLabel(newVariableName); int autoLabelColumnIndex = _variablesForm.dgvVariables.Columns.IndexOf(_variablesForm.colAutomaticLabel); _variablesForm.dgvVariables[autoLabelColumnIndex, e.RowIndex].Value = automaticLabel; //set whether is categorical or not int categColumnIndex = _variablesForm.dgvVariables.Columns.IndexOf(_variablesForm.colCategorical); var bkupIsCateg = _variablesForm.dgvVariables[categColumnIndex, e.RowIndex].Value; _variablesForm.dgvVariables[categColumnIndex, e.RowIndex].Value = IsCateg(newVariableName); //check if valid errorText += IsValidVariableName(newVariableName, automaticLabel, e.RowIndex); if (errorText != string.Empty) { if (Tools.UserInfoHandler.GetInfo(errorText + "Undo change?", MessageBoxButtons.YesNo) == DialogResult.Yes) { _variablesForm.dgvVariables[e.ColumnIndex, e.RowIndex].Value = variableRow.Name; _variablesForm.dgvVariables[categColumnIndex, e.RowIndex].Value = bkupIsCateg; _variablesForm.dgvVariables[autoLabelColumnIndex, e.RowIndex].Value = variableRow.AutoLabel; } } } //write to dataset _variablesForm.PerformAction(new ChangeVariableAction(_variablesForm, e)); }
void StoreRowStates(ref string selectedRowID, ref string firstDisplayedRowID) { if (_dgvVariables.SelectedRows.Count == 1) { VarConfig.VariableRow variableRow = _dgvVariables.SelectedRows[0].Tag as VarConfig.VariableRow; if (variableRow.RowState == System.Data.DataRowState.Unchanged) //must be checked, because list may be redrawn because of an undo action { selectedRowID = variableRow.ID; } } if (_dgvVariables.FirstDisplayedCell != null) { VarConfig.VariableRow variableRow = _dgvVariables.Rows[_dgvVariables.FirstDisplayedCell.RowIndex].Tag as VarConfig.VariableRow; if (variableRow.RowState == System.Data.DataRowState.Unchanged) { firstDisplayedRowID = variableRow.ID; } } }
internal bool UpdateAutomaticLabel() { _variablesForm.Cursor = Cursors.WaitCursor; bool anyUpdates = false; foreach (DataGridViewRow row in _variablesForm.dgvVariables.Rows) { VarConfig.VariableRow variableRow = row.Tag as VarConfig.VariableRow; string updatedLabel = GetAutomaticLabel(variableRow.Name, variableRow.AutoLabel); if (updatedLabel.ToLower() != variableRow.AutoLabel.ToLower()) { variableRow.AutoLabel = updatedLabel; anyUpdates = true; } } _variablesForm.Cursor = Cursors.Default; return(anyUpdates); }
internal void FillCountrySpecificDescriptionList() { dgvDescriptions.Rows.Clear(); if (dgvVariables.SelectedRows.Count != 1 || dgvVariables.SelectedRows[0].Tag == null) { return; //don't show any definitions if no or more than one variable is selected } if (dgvVariables.SelectedRows[0].Cells[dgvVariables.Columns.IndexOf(colInfo)].Value.ToString() != _infoChangeCountryLabel) { return; //only need to fill list when selected row in variables list indicates different country labels } Dictionary <VarConfig.VariableRow, VarConfig.VariableRow> internalAndExternVariable = dgvVariables.SelectedRows[0].Tag as Dictionary <VarConfig.VariableRow, VarConfig.VariableRow>; //Tag is a Dictionary with one element as KeyValuePair cannot be casted back, because it does not allow for NULL values VarConfig.VariableRow internalVariable = internalAndExternVariable.Keys.ElementAt(0); VarConfig.VariableRow externalVariable = internalAndExternVariable.Values.ElementAt(0); foreach (VarConfig.CountryLabelRow internalLabel in internalVariable.GetCountryLabelRows()) { VarConfig.CountryLabelRow externalLabel = null; foreach (VarConfig.CountryLabelRow searchExternalLabel in externalVariable.GetCountryLabelRows()) { if (searchExternalLabel.Country.ToLower() == internalLabel.Country.ToLower()) { externalLabel = searchExternalLabel; break; //just break if no corresponding country-label found (warning was issued when variables list was generated) } } if (externalLabel == null || internalLabel.Label == externalLabel.Label) { continue; } dgvDescriptions.Rows.Add(internalLabel.Country, internalLabel.Label, externalLabel.Label); } colCountry.Width = colCountry.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); colOldCountryDescription.Width = colOldCountryDescription.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); colNewCountryDescription.Width = colNewCountryDescription.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); }
void AddLabelsWholeCountry(bool local) { foreach (MergeControl.NodeInfo nodeInfo in local ? _mcCountryLabels.GetNodeInfoLocal() : _mcCountryLabels.GetNodeInfoRemote()) { if (!nodeInfo.ID.StartsWith(MergeAdministrator.IDENTIFIER_ADD_DEL_COUNTRY_LABELS) || nodeInfo.changeType != (local ? MergeControl.ChangeType.removed : MergeControl.ChangeType.added) || nodeInfo.changeHandling != (local ? MergeControl.ChangeHandling.reject : MergeControl.ChangeHandling.accept)) { continue; } string countryShortName = nodeInfo.ID.Substring(MergeAdministrator.IDENTIFIER_ADD_DEL_COUNTRY_LABELS.Length).ToLower(); foreach (VarConfig.CountryLabelRow remoteLabel in (from lab in _vcRemote.CountryLabel where lab.Country.ToLower() == countryShortName select lab)) { VarConfig.VariableRow localParentVariable = _vcFacLocal.GetVariableByID(remoteLabel.VariableID); if (localParentVariable != null) { _vcFacLocal.CopyCountryLabelRow(remoteLabel, localParentVariable); } } } }
internal void SetFilter() { bool showSimulated = (bool)_variablesForm.chkSimulated.EditValue; bool showData = (bool)_variablesForm.chkData.EditValue; bool showMonetary = (bool)_variablesForm.chkMonetary.EditValue; bool showNonMonetary = (bool)_variablesForm.chkNonMonetary.EditValue; bool showWithCountrySpecificDescriptionOnly = (bool)_variablesForm.chkHasSpecificDescription.EditValue; bool showIndLevel = (bool)_variablesForm.chkIndLevel.EditValue; bool showHHLevel = (bool)_variablesForm.chkHHLevel.EditValue; bool showCategorical = (bool)_variablesForm.chkCategorical.EditValue; bool showNonCategorical = (bool)_variablesForm.chkNonCategorical.EditValue; //get all countries which have a(ny) country specific description if the respective filter is set //(assessing the existence of a country specific description for a certain country and variable in the loop below is way too slow) List <string> variablesWithCountrySpecificDescription = new List <string>(); if (showWithCountrySpecificDescriptionOnly) { string countryShortName = _variablesForm.cmbCountry.EditValue.ToString(); if (countryShortName == VariablesForm._anyCountry) { countryShortName = string.Empty; //filter for any country specific description (i.e. any description in addition to the automatic label) } foreach (VarConfig.VariableRow variableRow in _varConfigFacade.GetVariablesWithCountrySpecificDescription(countryShortName)) { variablesWithCountrySpecificDescription.Add(variableRow.Name.ToLower()); } } _dgvVariables.SuspendLayout(); //hopefully that enhences speed Dictionary <string, bool> isCateg = GetVariablesCategState(); foreach (DataGridViewRow dataGridViewRow in _dgvVariables.Rows) { VarConfig.VariableRow variableRow = dataGridViewRow.Tag as VarConfig.VariableRow; string variableName = variableRow.Name.ToLower(); //variable is visible if its type (benefit, demographic, ...) corresponds to an activated (i.e. checked) type ... bool visible = true; foreach (BarEditItem filterCheckbox in _variablesForm._typeFilterCheckboxes) { if ((bool)filterCheckbox.EditValue == true) { continue; } string typeShortName = filterCheckbox.Tag.ToString().ToLower(); if (typeShortName == DESCRIPTION_UNKNOWN) { if (!_varConfigFacade.GetTypeShortNames(true).Contains(GetVariableType(variableName).ToLower())) { visible = false; } } else { if (IsVariableOfType(variableName, typeShortName)) { visible = false; } } } //... however variable must still fulfill other criteria (monetary, simulated, ...) if (showWithCountrySpecificDescriptionOnly && !variablesWithCountrySpecificDescription.Contains(variableName.ToLower())) { visible = false; } else if (!showSimulated && IsSimulated(variableName)) { visible = false; } else if (!showData && !IsSimulated(variableName)) { visible = false; } else if (!showMonetary && IsMonetary(variableRow)) { visible = false; } else if (!showNonMonetary && !IsMonetary(variableRow)) { visible = false; } else if (!showCategorical && isCateg[variableRow.ID]) { visible = false; } else if (!showNonCategorical && !isCateg[variableRow.ID]) { visible = false; } else if (!showHHLevel && IsHHLevel(variableRow)) { visible = false; } else if (!showIndLevel && !IsHHLevel(variableRow)) { visible = false; } dataGridViewRow.Visible = visible; } _dgvVariables.ResumeLayout(); }
internal void DeleteVariable(VarConfig.VariableRow variableRow) { variableRow.Delete(); }
internal static bool IsMonetary(VarConfig.VariableRow variableRow) { return(variableRow.Monetary == "1"); }
internal void CopyCountryLabelRow(VarConfig.CountryLabelRow originalDescription, VarConfig.VariableRow parentVariable) { _varConfig.CountryLabel.AddCountryLabelRow(originalDescription.ID, parentVariable, originalDescription.Country, originalDescription.Label); }
void FillVariablesList() { //analyse the two lists of variables for variables existing only in one of them as well as variables with different properties (monetary-status, descriptions) List <VarConfig.VariableRow> internalVariables = _internalVarConfigFacade.GetVariablesSortedByName(); List <VarConfig.VariableRow> externalVariables = _externalVarConfigFacade.GetVariablesSortedByName(); List <string> internalVariablesNames = (from internalVariable in internalVariables select internalVariable.Name).ToList(); List <string> externalVariablesNames = (from externalVariable in externalVariables select externalVariable.Name).ToList(); Dictionary <int, int> compareIndexList = new Dictionary <int, int>(); List <int> addIndexList = new List <int>(); List <int> deleteIndexList = new List <int>(); AnalyseLists(internalVariablesNames, externalVariablesNames, ref compareIndexList, ref addIndexList, ref deleteIndexList); //add a row for each potential change to the variables list foreach (int addIndex in addIndexList) { int index = dgvVariables.Rows.Add(externalVariablesNames.ElementAt(addIndex), _actionAdd, _actionDefaultPerform, string.Empty); dgvVariables.Rows[index].Tag = externalVariables.ElementAt(addIndex); } foreach (int deleteIndex in deleteIndexList) { int index = dgvVariables.Rows.Add(internalVariablesNames.ElementAt(deleteIndex), _actionDelete, _actionDefaultPerform, string.Empty); dgvVariables.Rows[index].Tag = internalVariables.ElementAt(deleteIndex); } bool warningShown = false; foreach (int internalIndex in compareIndexList.Keys) { int externalIndex = compareIndexList[internalIndex]; VarConfig.VariableRow internalVariable = internalVariables.ElementAt(internalIndex); VarConfig.VariableRow externalVariable = externalVariables.ElementAt(externalIndex); Dictionary <VarConfig.VariableRow, VarConfig.VariableRow> tag = new Dictionary <VarConfig.VariableRow, VarConfig.VariableRow>(); tag.Add(internalVariable, externalVariable); //put a Dictionary with one element into Tag, as KeyValuePair cannot be casted back, because it does not allow for NULL values //check for different monetary status if (internalVariable.Monetary != externalVariable.Monetary) { int index = dgvVariables.Rows.Add(internalVariablesNames.ElementAt(internalIndex), _actionChange, _actionDefaultPerform, (externalVariable.Monetary == "1") ? "to monetary" : "to non-monetary"); dgvVariables.Rows[index].Tag = tag; } //check for different country specific descriptions foreach (VarConfig.CountryLabelRow internalLabel in internalVariable.GetCountryLabelRows()) { VarConfig.CountryLabelRow externalLabel = null; foreach (VarConfig.CountryLabelRow searchExternalLabel in externalVariable.GetCountryLabelRows()) { if (searchExternalLabel.Country.ToLower() == internalLabel.Country.ToLower()) { externalLabel = searchExternalLabel; break; } } if (externalLabel == null) { if (!warningShown) { Tools.UserInfoHandler.ShowError("The external variables file seems to refer to another set of countries, thus country descriptions may not be updated completely."); warningShown = true; } continue; } if (internalLabel.Label != externalLabel.Label) { int index = dgvVariables.Rows.Add(internalVariablesNames.ElementAt(internalIndex), _actionChange, _actionDefaultPerform, _infoChangeCountryLabel); dgvVariables.Rows[index].Tag = tag; break; //if one description different, variables needs to be marked as changed - no need to check all countries' descriptions here } } } //finally some formatting colPerformVariables.Width = colPerformVariables.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); colVariableName.Width = colVariableName.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); colAction.Width = colAction.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); colInfo.Width = colInfo.GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true); dgvVariables.Sort(colVariableName, System.ComponentModel.ListSortDirection.Ascending); FillCountrySpecificDescriptionList(); }
internal static bool IsHHLevel(VarConfig.VariableRow variableRow) { return(variableRow.HHLevel == "1"); // means default is not HH-level }
private void EM2_FixUprating(CountryConfig.SystemRow sr1, Dictionary <string, string> upratingFactors, Dictionary <string, string> upratingFactors2, string countryShortName, double alpha, int uprateType, bool treatAsMarket) { // first get the ils_origy & ils_ben components CountryConfig.PolicyRow ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ilsdef_" + countryShortName).ToLower()); if (ilsdef == null) { ilsdef = sr1.GetPolicyRows().FirstOrDefault(p => p.Name.ToLower() == ("ildef_" + countryShortName).ToLower()); } if (ilsdef == null) { return; } CountryConfig.FunctionRow[] il_funcs = ilsdef.GetFunctionRows(); List <string> ils_origy = ExpandIncomeList(DefVarName.ILSORIGY, il_funcs).Keys.ToList(); List <string> ils_ben = ExpandIncomeList(DefVarName.ILSBEN, il_funcs).Keys.ToList(); List <string> overrideInclude = ExpandIncomeList("pet_override", il_funcs).Where(x => x.Value).Select(x => x.Key).ToList(); List <string> overrideExclude = ExpandIncomeList("pet_override", il_funcs).Where(x => !x.Value).Select(x => x.Key).ToList(); List <string> reservedWords = new List <string> { "dataset", "def_factor", "factor_name", "factor_value", "factor_condition", "aggvar_name", "aggvar_part", "aggvar_tolerance", "warnifnofactor", "run_cond" }; // Then apply them to the appropriate variables of s1 foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows()) { if (fr.Name.ToLower() == "uprate") { foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows()) { string pn = pr.Name.ToLower(); if (!reservedWords.Contains(pn)) { if (uprateType == 3) // uprate all { double val; if (upratingFactors.ContainsKey(pr.Value.ToLower())) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) * alpha).ToString()); } else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val)) { pr.Value = FixDecSep((val * alpha).ToString()); } } else { bool marketIncome = overrideInclude.Contains(pn); // if in the override include list if (!overrideExclude.Contains(pn) && !marketIncome) // else if not in the override exlcude list { VarConfig.VariableRow v = EM_AppContext.Instance.GetVarConfigFacade().GetVariableByName(pn); if (v == null || v.Monetary != "1") { marketIncome = false; } else { if (treatAsMarket) { marketIncome = !pn.EndsWith(DefGeneral.POSTFIX_SIMULATED); } else { marketIncome = !ils_ben.Contains(pn) && (pn[0] == 'y' || pn[0] == 'a' || pn[0] == 'x' || ils_origy.Contains(pn)); } } } // if this is a market income if (marketIncome) { if (uprateType == 1) { double val; if (upratingFactors.ContainsKey(pr.Value.ToLower())) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()]) * alpha).ToString()); } else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val)) { pr.Value = FixDecSep((val * alpha).ToString()); } } else if (uprateType == 2) { if (upratingFactors.ContainsKey(pr.Value.ToLower())) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors[pr.Value.ToLower()])).ToString()); } } } else // if it is non-market income { if (uprateType == 2) { double val; if (upratingFactors2.ContainsKey(pr.Value.ToLower())) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(upratingFactors2[pr.Value.ToLower()]) / alpha).ToString()); } else if (EM_Helpers.TryConvertToDouble(pr.Value.ToLower(), out val)) { pr.Value = FixDecSep((val / alpha).ToString()); } } } } } } } } if (uprateType > 1) { string[] monetaryTypes = new string[] { DefPeriod.M, DefPeriod.Y, DefPeriod.Q, DefPeriod.W, DefPeriod.D, DefPeriod.L, DefPeriod.S, DefPeriod.C }; foreach (CountryConfig.FunctionRow fr in sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("Uprate_" + countryShortName).ToLower()).GetFunctionRows()) { foreach (CountryConfig.ParameterRow pr in fr.GetParameterRows()) { string val = pr.Value.ToLower().Trim(); if (val.Length < 3) { continue; } string valType = val.Substring(val.Length - 2); if (monetaryTypes.Contains(valType)) { val = val.Substring(0, val.Length - 2); if (uprateType == 2) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) / alpha).ToString()) + valType; } else if (uprateType == 3) { pr.Value = FixDecSep((EM_Helpers.SaveConvertToDouble(val) * alpha).ToString()) + valType; } } } } } try { // Then, fix the output filenames sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower()) .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput") .GetParameterRows().First(p => p.Name.ToLower() == "file") .Value = sr1.Name + "_std"; sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower()) .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput") .GetParameterRows().First(p => p.Name.ToLower() == "file") .Value = sr1.Name + "_std_hh"; // Finally, if required, do the scaling if (checkRadioMarket.Checked) { CountryConfig.FunctionRow fr = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_" + countryShortName).ToLower()) .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput"); CountryConfig.FunctionRow fr_hh = sr1.GetPolicyRows().First(p => p.Name.ToLower() == ("output_std_hh_" + countryShortName).ToLower()) .GetFunctionRows().First(f => f.Name.ToLower() == "defoutput"); if (fr.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0) { CountryConfig.ParameterRow fpr = fr.GetParameterRows().First(p => p.Name.ToLower() == "file"); CountryConfig.ParameterRow cpr = CountryConfigFacade.AddParameterRow(fpr, false, DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy)); cpr.Value = FixDecSep((1 / alpha).ToString()); } else { CountryConfig.ParameterRow mpr = fr.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()); double d; if (!EM_Helpers.TryConvertToDouble(mpr.Value, out d)) { d = 1; } mpr.Value = FixDecSep((d / alpha).ToString()); } if (fr_hh.GetParameterRows().Count(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()) == 0) { CountryConfig.ParameterRow fpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == "file"); CountryConfig.ParameterRow cpr = CountryConfigFacade.AddParameterRow(fpr_hh, false, DefPar.DefOutput.MultiplyMonetaryBy, DefinitionAdmin.GetParDefinition(DefFun.DefOutput, DefPar.DefOutput.MultiplyMonetaryBy)); cpr.Value = FixDecSep((1 / alpha).ToString()); } else { CountryConfig.ParameterRow mpr_hh = fr_hh.GetParameterRows().First(p => p.Name.ToLower() == DefPar.DefOutput.MultiplyMonetaryBy.ToLower()); double d; if (!EM_Helpers.TryConvertToDouble(mpr_hh.Value, out d)) { d = 1; } mpr_hh.Value = FixDecSep((d / alpha).ToString()); } } } catch { throw new Exception("Problem in default output functions."); } }