internal override bool Perform() { DataGridViewRow changedRow = _dgvDescriptions.Rows[_eventArgs.RowIndex]; VarConfig.CountryLabelRow countryLabelRow = changedRow.Tag as VarConfig.CountryLabelRow; string changedVal = changedRow.Cells[_eventArgs.ColumnIndex].Value == null ? string.Empty : changedRow.Cells[_eventArgs.ColumnIndex].Value.ToString(); if (countryLabelRow.Label != changedVal) {//only (change and) return true if actually changed countryLabelRow.Label = changedVal; return(true); } return(false); }
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); }
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(); }