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 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 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);
        }
示例#4
0
        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 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);
        }
示例#6
0
        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();
        }