Dictionary <string, string> SyncGlobalExRatesIn(string countryShortName, CountryConfig.SystemDataTable systemTable)
        {
            Dictionary <string, string> diffRates = new Dictionary <string, string>();
            ExchangeRatesConfigFacade   excf      = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false);
            List <ExchangeRatesConfig.ExchangeRatesRow> globalExRates = (excf != null) ? excf.GetExchangeRates(countryShortName) : new List <ExchangeRatesConfig.ExchangeRatesRow>();

//            List<ExchangeRatesConfig.ExchangeRatesRow> globalExRates = new List<ExchangeRatesConfig.ExchangeRatesRow>();
            if (globalExRates.Count == 0)
            {
                return(diffRates);
            }

            foreach (CountryConfig.SystemRow systemRow in systemTable.Rows)
            {
                string globalExRate = DEFAULT_EXCHANGE_RATE;  // default value for missing exchange rates
                foreach (ExchangeRatesConfig.ExchangeRatesRow ger in globalExRates)
                {
                    List <string> vF = ExchangeRate.ValidForToList(ger.ValidFor);
                    if (vF.Contains(systemRow.Name.ToLower()))
                    {
                        globalExRate = ExchangeRate.DefaultRate(ger).ToString(); break;
                    }
                }
                diffRates.Add(systemRow.Name.ToLower(), globalExRate);
            }

            return(diffRates);
        }
        private void ChangeNameInExchangeRatesConfig(CountryConfig.SystemRow systemRow, string oldSystemName)
        {
            ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false); if (excf == null)
            {
                return;
            }
            bool anyChange = false;

            foreach (ExchangeRatesConfig.ExchangeRatesRow exchangeRate in
                     from er in excf.GetExchangeRates() where er.Country.ToLower() == systemRow.CountryRow.ShortName.ToLower() &&
                     ExchangeRate.ValidForToList(er.ValidFor).Contains(oldSystemName.ToLower()) select er)
            {
                if (!anyChange && UserInfoHandler.GetInfo("Do you want to update the system name in the global exchange rate table?" + Environment.NewLine + Environment.NewLine +
                                                          "Note that, if no exchange rate is found for a system name, the exchange rate is assumed to be 1.", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
                exchangeRate.ValidFor = ExchangeRate.RemoveFromValidFor(exchangeRate.ValidFor, oldSystemName);
                exchangeRate.ValidFor = ExchangeRate.AddToValidFor(exchangeRate.ValidFor, systemRow.Name); anyChange = true;
            }
            if (anyChange)
            {
                excf.WriteXML();
            }
        }
Example #3
0
        internal override void PerformAction()
        {
            CountryConfig.SystemRow systemRow = (_senderColumn.Tag as SystemTreeListTag).GetSystemRow();

            if (_showRequest && Tools.UserInfoHandler.GetInfo("Are you sure you want to delete system '" + _senderColumn.Caption + "'?", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                _actionIsCanceled = true;
                return;
            }

            //adapt exchange-rate in global table
            //note that the exchange-rate-config is not included in the undo-procedure, thus this will not be undone
            ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false);

            if (excf != null)
            {
                excf.RemoveSystems(systemRow.CountryRow.ShortName, new List <string>()
                {
                    systemRow.Name
                });
            }

            if (_dataConfigFacade != null)                                //if 'country' is an add-on it does not have a dataConfig
            {
                _dataConfigFacade.DeleteDBSystemConfigRows(systemRow.ID); //first delete all references of the system with datasets
            }
            CountryConfigFacade.DeleteSystemRow(systemRow);               //then delete the system itself
        }
Example #4
0
        internal ExchangeRatesConfigApplyAdministrator(MergeAdministrator mergeAdministrator, ExchangeRatesConfigMergeForm mergeForm,
                                                       ExchangeRatesConfigFacade vcFacLocal, ExchangeRatesConfigFacade vcFacRemote)
        {
            _mergeAdministrator = mergeAdministrator;

            _vcFacLocal  = vcFacLocal; _vcLocal = _vcFacLocal.GetExchangeRatesConfig();
            _vcFacRemote = vcFacRemote; _vcRemote = _vcFacRemote.GetExchangeRatesConfig();

            _mergeForm             = mergeForm;
            _mcExchangeRatesConfig = _mergeForm.GetMergeControlByName(EMPath.EM2_FILE_EXRATES);
        }
Example #5
0
        void AddExchangeRates(string idColumnNameID1, string idColumnNameID2, bool local)
        {
            foreach (string ID in GetRelevantIDs(_mcExchangeRatesConfig, local, true))
            {
                string country  = ID.Substring(0, ID.IndexOf("_"));
                string validFor = ID.Substring(ID.IndexOf("_") + 1);

                string whereClause = idColumnNameID1 + " = '" + country + "' AND " + idColumnNameID2 + " = '" + validFor + "'";

                ExchangeRatesConfig.ExchangeRatesRow dataRow = (ExchangeRatesConfig.ExchangeRatesRow)_vcRemote.ExchangeRates.Select(whereClause).First();

                ExchangeRatesConfigFacade.CopyExchangeRatesFromAnotherConfig(_vcLocal, dataRow);
            }
        }
        internal AddCountry_SaveAs_AdaptForm(string cc, SaveAsAdaptOptions _options)
        {
            InitializeComponent();

            // disable checks for adapting global files if they do not contain entries for the original country
            ExchangeRatesConfigFacade ercf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false);

            chkCloneExRates.Enabled = ercf != null && ercf.HasExchangeRates(cc);
            HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false);

            chkCloneHICP.Enabled = hcf != null && hcf.HasHICP(cc);

            options = _options;
            chkAdaptSystemNames.Checked     = options.adaptSystemNames;
            chkAdaptPolicyNames.Checked     = options.adaptPolicyNames;
            chkAdaptTUNames.Checked         = options.adaptTUNames;
            chkAdaptOutputFileNames.Checked = options.adaptOutputFileNames;
            chkAdaptComments.Checked        = options.adaptComments;
            chkCloneHICP.Checked            = options.cloneHICP == true;
            chkCloneExRates.Checked         = options.cloneExRates == true;
        }
        internal static void ShowExchangeRatesDialog()
        {
            ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(true); // true: create if not existent yet
            List <ExchangeRatesConfig.ExchangeRatesRow> exRates = null;

            if (excf != null)
            {
                exRates = excf.GetExchangeRates();
            }

            ExchangeRatesForm exRatesForm = new ExchangeRatesForm(exRates);

            if (exRatesForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            if (excf != null && excf.RefreshExchangeRates(exRatesForm.updatedExRates))
            {
                excf.WriteXML();
            }
        }
        void AddToExchangeRatesTable(string systemName, CountryConfig.SystemRow toCopySystemRow)
        {
            ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false); if (excf == null)
            {
                return;
            }
            bool found = false;

            foreach (ExchangeRatesConfig.ExchangeRatesRow exchangeRate in excf.GetExchangeRates())
            {
                if (exchangeRate.Country.ToLower() != toCopySystemRow.CountryRow.ShortName.ToLower() ||
                    !ExchangeRate.ValidForToList(exchangeRate.ValidFor).Contains(toCopySystemRow.Name.ToLower()))
                {
                    continue;
                }
                exchangeRate.ValidFor = ExchangeRate.AddToValidFor(exchangeRate.ValidFor, systemName); found = true; break;
            }
            if (found)
            {
                excf.WriteXML();
            }
        }
 internal void UnloadExchangeRatesConfigFacade()
 {
     _exchangeRatesConfigFacade = null;
 }
        private void EM3_WriteLog()
        {
            List <RunLogger.RunInfo> runInfoList = new List <RunLogger.RunInfo>();

            foreach (Run run in _runs)
            {
                // some info needs to be looked up in country-files
                string country = run._contentConfig[TAGS.EM2CONFIG_COUNTRY_FILE];
                if (country.ToLower().EndsWith(".xml"))
                {
                    country = country.Substring(0, country.Length - 4);
                }
                CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country);
                DataConfigFacade    dcf = CountryAdministrator.GetDataConfigFacade(country);
                string sysID            = (from e in run._contentConfig where e.Key.StartsWith(TAGS.EM2CONFIG_SYSTEM_ID) select e.Value).FirstOrDefault(); // SYSTEM_ID is followed by a GUID
                string dataID           = run._contentConfig[TAGS.EM2CONFIG_DATASET_ID];

                if (!EM_AppContext.Instance._runExeViaLib && run._process != null)
                {
                    run.em3RunInfo.duration     = new RunLogger.Duration(run._process.StartTime, run._process.ExitTime);
                    run.em3RunInfo.finishStatus = run._processStatus == Run._processStatus_Finished ? RunLogger.RunInfo.FINISH_STATUS.finished : RunLogger.RunInfo.FINISH_STATUS.aborted;
                }
                run.em3RunInfo.systemName = ccf.GetSystemRowByID(sysID).Name;
                run.em3RunInfo.ExtractAddonSystemNames(run._contentConfig, TAGS.EM2CONFIG_ADDON);
                run.em3RunInfo.databaseName = dcf.GetDataBaseRow(dataID).Name;
                run.em3RunInfo.currency     = run._contentConfig.ContainsKey(TAGS.EM2CONFIG_EXCHANGE_RATE_DATE) ? DefPar.Value.EURO
                         : ccf.GetSystemRowByID(sysID).CurrencyOutput; // config contains entry EXCHANGE_RATE_DATE only if "All Output in €" is checked
                run.em3RunInfo.exchangeRate = GetExchangeRate(run, country, ccf.GetSystemRowByID(sysID).Name);
                run.em3RunInfo.ExtractExtensionSwitches(run._contentConfig, TAGS.EM2CONFIG_POLICY_SWITCH);
                string runOutputPath = run._contentConfig.GetOrEmpty(TAGS.EM2CONFIG_OUTPUTPATH);
                if (!string.IsNullOrEmpty(runOutputPath) && !EMPath.IsSamePath(runOutputPath, _outputPath))
                {
                    run.em3RunInfo.nonDefaultOutputPath = runOutputPath;
                }
                runInfoList.Add(run.em3RunInfo);
            }

            new RunLogger(EM_AppContext.Instance.GetProjectName(), runInfoList).TxtWriteEMLog(_outputPath);

            string GetExchangeRate(Run run, string country, string sysName)
            {
                ExchangeRatesConfigFacade excf = EM_AppContext.Instance.GetExchangeRatesConfigFacade(false);

                if (excf == null)
                {
                    return(Dialogs.ConfigureSystemsForm.DEFAULT_EXCHANGE_RATE);
                }
                foreach (ExchangeRatesConfig.ExchangeRatesRow exRate in excf.GetExchangeRates(country))
                {
                    if (!exRate.ValidFor.ToLower().Trim().EndsWith(sysName.ToLower()) && !exRate.ValidFor.ToLower().Contains(sysName.ToLower() + ","))
                    {
                        continue;
                    }
                    string date = run._contentConfig.ContainsKey(TAGS.EM2CONFIG_EXCHANGE_RATE_DATE) &&
                                  run._contentConfig[TAGS.EM2CONFIG_EXCHANGE_RATE_DATE].ToLower() != "default"
                        ? run._contentConfig[TAGS.EM2CONFIG_EXCHANGE_RATE_DATE].ToLower() : exRate.Default.ToLower();
                    double value = 1.0;
                    if (date.StartsWith("june"))
                    {
                        value = exRate.June30;
                    }
                    else if (date.StartsWith("year"))
                    {
                        value = exRate.YearAverage;
                    }
                    else if (date.StartsWith("first"))
                    {
                        value = exRate.FirstSemester;
                    }
                    else if (date.StartsWith("second"))
                    {
                        value = exRate.SecondSemester;
                    }
                    return(value.ToString());
                }
                return(Dialogs.ConfigureSystemsForm.DEFAULT_EXCHANGE_RATE);
            }
        }