Esempio n. 1
0
 void SetExtensionDefaultSwitch(DataConfig.DBSystemConfigRow dbSystemConfigRow, string switchablePolicyID, string defaultValue)
 {
     foreach (ExtensionSwitchDefaultValue policySwitchDefaultValue in _extensionDefaultSwitches)
     {
         if (policySwitchDefaultValue._dbSystemConfigRow == dbSystemConfigRow && policySwitchDefaultValue._extensionID == switchablePolicyID)
         {
             policySwitchDefaultValue._defaultValue = defaultValue;
             return;
         }
     }
 }
Esempio n. 2
0
 string GetExtensionDefaultSwitch(DataConfig.DBSystemConfigRow dbSystemConfigRow, string switchablePolicyID)
 {
     foreach (ExtensionSwitchDefaultValue policySwitchDefaultValue in _extensionDefaultSwitches)
     {
         if (policySwitchDefaultValue._dbSystemConfigRow == dbSystemConfigRow && policySwitchDefaultValue._extensionID == switchablePolicyID)
         {
             return(policySwitchDefaultValue._defaultValue);
         }
     }
     return(DefPar.Value.NA); // switch is not (yet) existing
 }
        // if required, rename output-files to indicate if switches are set to non-default values
        bool EM3_AddNonDefaultSwitches_To_OutputFileName(Dictionary <ConfigKey, Dictionary <string, string> > contentEMConfigs, RunMainForm runMainForm)
        {
            try
            {
                // check if automatic renaming of the output-filenames is switched on
                if (!EM_UI.EM_AppContext.Instance.GetUserSettingsAdministrator().GetPolicySwitchAutoRenameValue())
                {
                    return(true);
                }

                foreach (DataGridViewRow systemRow in runMainForm.dgvRun.Rows) // loop over systems
                {
                    // assess whether any run-checkboxes (standard run, add-ons) are checked for the system
                    if (!EM_Helpers.SaveConvertToBoolean(systemRow.Cells[runMainForm.colRun.Name].Value))
                    {
                        continue;
                    }

                    // assess which dataset is selected for run
                    DataConfig.DBSystemConfigRow dbSystemConfigRow = runMainForm.GetSelectedDBSystemCombination(systemRow);
                    if (dbSystemConfigRow == null)
                    {
                        continue;                            // should not happen
                    }
                    // find the EMConfig (prepared in GenerateEMConfigs) where the output needs to be renamed
                    Dictionary <string, string> contentEMConfig = null;
                    ConfigKey key = new ConfigKey(systemRow.Cells[runMainForm.colCountry.Name].Value.ToString(), dbSystemConfigRow.DataBaseID, dbSystemConfigRow.SystemID);
                    if (contentEMConfigs.ContainsKey(key))
                    {
                        contentEMConfig = contentEMConfigs[key];
                    }
                    if (contentEMConfig == null)
                    {
                        continue;                          // should not happen
                    }
                    // instruct the executable to apply this suffix to standard output (i.e. concerns only DefOutputs in policies output_std and output_std_hh):
                    // specificly, change e.g. mt_2014_std to mt_2014_UAAon and/or mt_2014_std_hh to mt_2014_UAAon_hh
                    string renameString = GenerateSwitchRenamingSuffix(runMainForm, systemRow, dbSystemConfigRow);
                    if (renameString != string.Empty)
                    {
                        contentEMConfig.Add(TAGS.STDOUTPUT_FILENAME_SUFFIX, renameString);
                    }
                }
            }
            catch { }
            return(true);
        }
Esempio n. 4
0
        internal static void SetExtensionDefaultSwitch(DataConfig dataConfig, DataConfig.DBSystemConfigRow dbSystemConfigRow, string extensionID, string extensionSwitch)
        {
            // instead of changing a possibly existing value for this extension/db/sys-combination delete "all" existing and add new
            // actually "all" should always be one or zero, but obviously undo produces duplicates (e.g. by deleting system and undoing it)
            // this corrects for these wrong duplicates (in principle there should be a unique key, but I'm reluctant adding one ...)
            List <DataConfig.PolicySwitchRow> existing = (from es in dataConfig.PolicySwitch
                                                          where es.RowState != System.Data.DataRowState.Deleted &&
                                                          es.SwitchablePolicyID == extensionID &&
                                                          es.SystemID == dbSystemConfigRow.SystemID &&
                                                          es.DataBaseID == dbSystemConfigRow.DataBaseID
                                                          select es).ToList();

            foreach (DataConfig.PolicySwitchRow e in existing)
            {
                e.Delete();
            }
            dataConfig.PolicySwitch.AddPolicySwitchRow(extensionID, dbSystemConfigRow.SystemID, dbSystemConfigRow.DataBaseID, extensionSwitch);
        }
        internal void CopyDBSystemConfigRows(CountryConfig.SystemRow originalSystemRow, CountryConfig.SystemRow copySystemRow)
        {
            foreach (DataConfig.DBSystemConfigRow originalDBSystemConfigRow in
                     (from dbSystemConfig in _dataConfig.DBSystemConfig
                      where dbSystemConfig.SystemID == originalSystemRow.ID
                      select dbSystemConfig).ToList())
            {
                DataConfig.DBSystemConfigRow copyDBSystemConfigRow = _dataConfig.DBSystemConfig.AddDBSystemConfigRow(copySystemRow.ID, copySystemRow.Name, originalDBSystemConfigRow.DataBaseRow,
                                                                                                                     originalDBSystemConfigRow.UseDefault, originalDBSystemConfigRow.UseCommonDefault, originalDBSystemConfigRow.Uprate, //parameter transferred to database-level, can be deleted once not used in any cc_DataConfig.xml anymore
                                                                                                                     originalDBSystemConfigRow.BestMatch);

                foreach (DataConfig.PolicySwitchRow originalExtensionSwitchRow in originalDBSystemConfigRow.GetPolicySwitchRows())
                {
                    _dataConfig.PolicySwitch.AddPolicySwitchRow(originalExtensionSwitchRow.SwitchablePolicyID,
                                                                copySystemRow.ID, originalExtensionSwitchRow.DataBaseID, originalExtensionSwitchRow.Value);
                }
            }
        }
        static internal DataConfig.DBSystemConfigRow OvertakeDBSystemConfigRowFromAnotherCountry(DataConfig dataConfig,
                                                                                                 DataConfig.DBSystemConfigRow originalDBSystemConfigRow,
                                                                                                 DataConfig.DataBaseRow newDataBaseRow, CountryConfig.SystemRow newSystemRow, bool overtakeExtensionSwitches = true)
        {
            DataConfig.DBSystemConfigRow dbSystemConfigRow = dataConfig.DBSystemConfig.AddDBSystemConfigRow(newSystemRow.ID, newSystemRow.Name, newDataBaseRow,
                                                                                                            originalDBSystemConfigRow.UseDefault,
                                                                                                            originalDBSystemConfigRow.UseCommonDefault,
                                                                                                            originalDBSystemConfigRow.Uprate,
                                                                                                            originalDBSystemConfigRow.BestMatch);
            if (overtakeExtensionSwitches)
            {
                foreach (DataConfig.PolicySwitchRow extensionSwitchRow in originalDBSystemConfigRow.GetPolicySwitchRows())
                {
                    dataConfig.PolicySwitch.AddPolicySwitchRow(extensionSwitchRow.SwitchablePolicyID, newSystemRow.ID, newDataBaseRow.ID, extensionSwitchRow.Value);
                }
            }

            return(dbSystemConfigRow);
        }
Esempio n. 7
0
 void StoreDisplayedSwitches()
 {
     if (_selectedPolicyID != string.Empty)
     {
         foreach (DataGridViewRow row in dgvSwitches.Rows)
         {
             foreach (DataGridViewCell cell in row.Cells)
             {
                 if (cell.Tag == null)
                 {
                     continue; //dataset not applicable for system
                 }
                 DataConfig.DBSystemConfigRow dbSystemConfigRow = cell.Tag as DataConfig.DBSystemConfigRow;
                 if (dbSystemConfigRow == null)
                 {
                     continue; //should not happen
                 }
                 SetExtensionDefaultSwitch(dbSystemConfigRow, _selectedPolicyID, cell.Value.ToString());
             }
         }
     }
 }
Esempio n. 8
0
        internal static string GetExtensionDefaultSwitch(DataConfig.DBSystemConfigRow dbSystemConfigRow, string switchablePolicyID)
        {
            var policySwitchRow = (from ps in dbSystemConfigRow.GetPolicySwitchRows() where ps.SwitchablePolicyID == switchablePolicyID select ps).FirstOrDefault();

            return(policySwitchRow == null ? DefPar.Value.NA : policySwitchRow.Value);
        }
        // this does not only add the addOn-info, but also collects the country- and addOn-file that need to be transformed to EM3 format
        bool EM3_AddAddOnInfo(string outputPath, Dictionary <ConfigKey, Dictionary <string, string> > contentEMConfigs, RunMainForm runMainForm)
        {
            addOnsToTransform = new List <string>(); countriesToTransform = new List <string>(); // for collecting country- and addon-files which need to be transformed to EM3

            foreach (DataGridViewRow systemRow in runMainForm.dgvRun.Rows)                       // loop over systems
            {
                // assess whether any add-on is selected for run (theoretically more than one add-on can be selected for a system)
                List <AddOnSystemInfo> selectedAddOns = new List <AddOnSystemInfo>();
                foreach (DataGridViewColumn column in runMainForm.dgvRun.Columns)
                {
                    if (column.Name.StartsWith(RunMainForm._colAddOnPrefix) && EM_Helpers.SaveConvertToBoolean(systemRow.Cells[column.Name].Value))
                    {
                        if (!AddOnInfoHelper.GetSupportedSystemInfo(systemRow.Cells[runMainForm.colSystem.Name].Value.ToString(),
                                                                    column.Tag as List <AddOnSystemInfo>, out List <AddOnSystemInfo> supportedAOSystemInfo))
                        {
                            return(false);
                        }
                        selectedAddOns.AddRange(supportedAOSystemInfo);
                    }
                }

                // we need to know whether the system is selected, first to collect the country for transformation (see remark above)
                // and, if it is selected in addition to any add-on(s), we need to copy the configuration file (instead of just adapting it)
                bool   isSystemSelected = EM_Helpers.SaveConvertToBoolean(systemRow.Cells[runMainForm.colRun.Name].Value);
                string countryShortName = systemRow.Cells[runMainForm.colCountry.Name].Value.ToString().ToLower();
                if (isSystemSelected || selectedAddOns.Any())
                {
                    string countryToTransform = countryShortName;
                    if (!countriesToTransform.Contains(countryToTransform))
                    {
                        countriesToTransform.Add(countryToTransform);
                    }
                }

                if (!selectedAddOns.Any())
                {
                    continue;
                }

                // to find the config (prepared in GenerateEMConfigs) we need the dataset
                DataConfig.DBSystemConfigRow dbSystemConfigRow = runMainForm.GetSelectedDBSystemCombination(systemRow); if (dbSystemConfigRow == null)
                {
                    continue;                                                                                                                                    // should not happen
                }
                ConfigKey key = new ConfigKey(countryShortName, dbSystemConfigRow.DataBaseID, dbSystemConfigRow.SystemID);
                if (!contentEMConfigs.ContainsKey(key))
                {
                    continue;                                     // should not happen
                }
                Dictionary <string, string> contentEMConfig = contentEMConfigs[key];

                // if the system itself is selected too, we need to make a copy of the config (i.e. run the plain system and run the add-on)
                if (isSystemSelected)
                {
                    contentEMConfig = new Dictionary <string, string>();
                    foreach (var entry in contentEMConfigs[key])
                    {
                        contentEMConfig.Add(entry.Key, entry.Value);
                    }
                    ConfigKey someKey = new ConfigKey(Guid.NewGuid().ToString(), string.Empty, string.Empty); // the key is irrelevant
                    contentEMConfigs.Add(someKey, contentEMConfig);
                }

                int cnt = 0;
                foreach (AddOnSystemInfo addOnSystemInfo in selectedAddOns)                                       // loop over the add-ons which are selected for run (usually one)
                {
                    contentEMConfig[RunMainForm._labelRunFormInfoText] += addOnSystemInfo._addOnSystemName + " "; // add to text that is displayed in the window showing run status
                    // add: $"ADDON{cnt}", $"{addOn}|{addOnSys}"
                    contentEMConfig.Add(TAGS.EM2CONFIG_ADDON + (cnt++).ToString(), addOnSystemInfo._addOnShortName + "|" + addOnSystemInfo._addOnSystemName);

                    string addOnToTransform = addOnSystemInfo._addOnShortName.ToLower();
                    if (!addOnsToTransform.Contains(addOnToTransform))
                    {
                        EM_AppContext.Instance.WriteXml(addOnSystemInfo._addOnShortName, false, false); // make sure the EM2 version is saved
                        addOnsToTransform.Add(addOnToTransform);
                    }
                }
            }
            return(true);
        }
 internal ExtensionSwitchDefaultValue(string extensionID, DataConfig.DBSystemConfigRow dbSystemConfigRow, string defaultValue)
 {
     _extensionID       = extensionID;
     _dbSystemConfigRow = dbSystemConfigRow;
     _defaultValue      = defaultValue;
 }
Esempio n. 11
0
        internal override void PerformAction()
        {
            ConfigureDataForm configureDataForm = new ConfigureDataForm(_countryShortName);

            //firstly provide dialog with the information it needs to display (i.e. info on datasets and available system-dataset combinations) ...
            foreach (CountryConfig.SystemRow systemRow in CountryAdministrator.GetCountryConfigFacade(_countryShortName).GetSystemRows().OrderBy(s => long.Parse(s.Order)))
            {
                configureDataForm._systemInfo.Add(systemRow.ID, systemRow.Name);
            }

            foreach (DataConfig.DataBaseRow dataBaseRow in _dataConfigFacade.GetDataBaseRows())
            {
                ConfigureDataForm.RowTag rowTag = new ConfigureDataForm.RowTag();
                rowTag.ID                   = dataBaseRow.ID;
                rowTag.Name                 = dataBaseRow.Name;
                rowTag.Comment              = dataBaseRow.Comment;
                rowTag.YearCollection       = dataBaseRow.YearCollection;
                rowTag.YearInc              = dataBaseRow.YearInc;
                rowTag.Currency             = dataBaseRow.Currency;
                rowTag.FilePath             = dataBaseRow.FilePath;
                rowTag.DecimalSign          = dataBaseRow.DecimalSign;
                rowTag.Private              = dataBaseRow.Private;
                rowTag.UseCommonDefault     = dataBaseRow.UseCommonDefault;
                rowTag.ReadXVariables       = string.IsNullOrEmpty(dataBaseRow.ReadXVariables) ? DefPar.Value.NO : dataBaseRow.ReadXVariables;
                rowTag.IsCommonDefaultNull  = dataBaseRow.IsUseCommonDefaultNull();
                rowTag.ListStringOutVar     = dataBaseRow.ListStringOutVar;
                rowTag.IndirectTaxTableYear = dataBaseRow.IndirectTaxTableYear;

                foreach (DataConfig.DBSystemConfigRow dbSystemConfigRow in _dataConfigFacade.GetDBSystemConfigRows(dataBaseRow.ID))
                {
                    ConfigureDataForm.CellTag cellTag = new ConfigureDataForm.CellTag();
                    cellTag.SystemID         = dbSystemConfigRow.SystemID;
                    cellTag.UseDefault       = dbSystemConfigRow.UseDefault;
                    cellTag.UseCommonDefault = dbSystemConfigRow.UseCommonDefault;
                    cellTag.Uprate           = dbSystemConfigRow.Uprate;
                    cellTag.BestMatch        = dbSystemConfigRow.BestMatch;
                    rowTag.CellTags.Add(dbSystemConfigRow.SystemID, cellTag);
                }
                configureDataForm._dataBaseInfo.Add(rowTag);
            }

            //... then show the dialog ...
            if (configureDataForm.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {
                _actionIsCanceled = true;
                return;
            }

            //... finally store the modified information
            List <DataConfig.DataBaseRow>       dataBaseRowsToDelete       = new List <DataConfig.DataBaseRow>();
            List <DataConfig.DBSystemConfigRow> dbSystemConfigRowsToDelete = new List <DataConfig.DBSystemConfigRow>();

            foreach (ConfigureDataForm.RowTag dataBaseInfo in configureDataForm._dataBaseInfo)
            {
                DataConfig.DataBaseRow dataBaseRow = _dataConfigFacade.GetDataBaseRow(dataBaseInfo.ID);
                if (dataBaseInfo.ChangeState == ConfigureDataForm.ChangeStates.removed)
                {
                    dataBaseRowsToDelete.Add(dataBaseRow);
                    continue;
                }

                if (dataBaseInfo.ChangeState == ConfigureDataForm.ChangeStates.added)
                {
                    dataBaseRow   = _dataConfigFacade.AddDataBaseRow(dataBaseInfo.Name, dataBaseInfo.FilePath);
                    _datasetAdded = true;
                }

                if (dataBaseInfo.ChangeState != ConfigureDataForm.ChangeStates.unchanged)
                {
                    dataBaseRow.ID                   = dataBaseInfo.ID;
                    dataBaseRow.Name                 = dataBaseInfo.Name;
                    dataBaseRow.Comment              = dataBaseInfo.Comment;
                    dataBaseRow.YearCollection       = dataBaseInfo.YearCollection;
                    dataBaseRow.YearInc              = dataBaseInfo.YearInc;
                    dataBaseRow.Currency             = dataBaseInfo.Currency;
                    dataBaseRow.FilePath             = dataBaseInfo.FilePath;
                    dataBaseRow.DecimalSign          = dataBaseInfo.DecimalSign;
                    dataBaseRow.Private              = dataBaseInfo.Private;
                    dataBaseRow.UseCommonDefault     = dataBaseInfo.UseCommonDefault;
                    dataBaseRow.ReadXVariables       = dataBaseInfo.ReadXVariables;
                    dataBaseRow.ListStringOutVar     = dataBaseInfo.ListStringOutVar;
                    dataBaseRow.IndirectTaxTableYear = dataBaseInfo.IndirectTaxTableYear;
                }

                foreach (ConfigureDataForm.CellTag dbSystemCombination in dataBaseInfo.CellTags.Values)
                {
                    DataConfig.DBSystemConfigRow dbSystemConfigRow = _dataConfigFacade.GetDBSystemConfigRow(dataBaseInfo.ID, dbSystemCombination.SystemID);
                    if (dbSystemCombination.ChangeState == ConfigureDataForm.ChangeStates.removed)
                    {
                        dbSystemConfigRowsToDelete.Add(dbSystemConfigRow);
                        continue;
                    }

                    if (dbSystemCombination.ChangeState == ConfigureDataForm.ChangeStates.added)
                    {
                        dbSystemConfigRow = _dataConfigFacade.AddDBSystemConfigRow(dbSystemCombination.SystemID,
                                                                                   CountryAdministrator.GetCountryConfigFacade(_countryShortName).GetSystemRowByID(dbSystemCombination.SystemID).Name,
                                                                                   dataBaseRow);
                    }

                    if (dbSystemCombination.ChangeState != ConfigureDataForm.ChangeStates.unchanged)
                    {
                        dbSystemConfigRow.SystemID         = dbSystemCombination.SystemID;
                        dbSystemConfigRow.UseDefault       = dbSystemCombination.UseDefault;
                        dbSystemConfigRow.UseCommonDefault = dbSystemCombination.UseCommonDefault;
                        dbSystemConfigRow.Uprate           = dbSystemCombination.Uprate;
                        dbSystemConfigRow.BestMatch        = dbSystemCombination.BestMatch;
                    }
                }
            }

            foreach (DataConfig.DataBaseRow dataBaseRowToDelete in dataBaseRowsToDelete)
            {
                dataBaseRowToDelete.Delete();
            }
            foreach (DataConfig.DBSystemConfigRow dbSystemConfigRowToDelete in dbSystemConfigRowsToDelete)
            {
                dbSystemConfigRowToDelete.Delete();
            }
        }