internal static void ShowHICPDialog() { HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); // false: do not create if not existent yet (only if user demands below) List <HICPConfig.HICPRow> hicps = null; if (hcf != null) { hicps = hcf.GetHICPs(); } if ((hicps == null || hicps.Count == 0) && GenerateHICPTable(out hicps) == DialogResult.Cancel) { return; } HICPForm hicpForm = new HICPForm(hicps); if (hicpForm.ShowDialog() == DialogResult.Cancel) { return; } hcf = EM_AppContext.Instance.GetHICPConfigFacade(true); // true: if user actually decided to generate HICPs (and thus GlobalConfig) from scratch (unlikely case) if (hcf != null && hcf.RefreshHICPs(hicpForm.updatedHICPs)) { hcf.WriteXML(); } }
private void GetHICPFromGlobalTable() { hicpFromGlobalTable = false; HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); if (hcf == null) { return; } List <string> hicpRow = new List <string>() { "Harmonised Index of Consumer Prices", "$HICP" }; string comment = string.Empty; foreach (DataColumn col in dgvDataTable.Columns) { if (!col.Caption.StartsWith(_colYear)) { continue; } HICPConfig.HICPRow globalHICP = hcf.GetHICP(EM_AppContext.Instance.GetActiveCountryMainForm().GetCountryShortName(), col.Caption.Substring(_colYear.Length)); string hicpVal = "100"; if (globalHICP != null) { hicpVal = EM_Helpers.ConvertToString(globalHICP.Value); comment = globalHICP.Comment; hicpFromGlobalTable = true; } // make sure you always show "." as decimal separator hicpRow.Add(hicpVal); } hicpRow.Add(comment); hicpRow.Insert(0, null); if (hicpFromGlobalTable) { dgvDataTable.Rows.Add(hicpRow.ToArray()); } }
string BestMatchCheck(List <SystemAndData> systemsAndData, BestMatchCheckType check, string country = "") { string faulty = string.Empty; List <string> done = new List <string>(); foreach (SystemAndData systemAndData in systemsAndData) { if (systemAndData.bestMatches.Count != 1) { continue; // only consider unique best-matches for simplicity } DataConfig.DataBaseRow data = systemAndData.bestMatches[0].DataBaseRow; if (done.Contains(data.Name.ToLower())) { continue; // data can be best-match of several systems (just need to check once) } switch (check) { case BestMatchCheckType.Year_NotEqual_Collection: string cy = data.YearCollection.Trim() == string.Empty ? "-" : data.YearCollection.Trim(); if (!data.Name.Contains(cy)) { faulty += string.Format("{0} ({1}), ", data.Name, cy); } break; case BestMatchCheckType.Income_Greater_Year: int incYear, colYear; if (int.TryParse(data.YearInc, out incYear) && int.TryParse(data.YearCollection, out colYear) && incYear > colYear) { faulty += string.Format("{0} ({1}>{2}), ", data.Name, incYear, colYear); } break; case BestMatchCheckType.UseCommonDefault: if (data.UseCommonDefault == DefPar.Value.YES) { faulty += data.Name + ", "; } break; case BestMatchCheckType.NoHICP: HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); if (hcf == null) { return(string.Empty); // should not happen } int year; if (!int.TryParse(data.YearInc, out year) || hcf.GetHICP(country, year) == null) { faulty += data.Name + ", "; } break; } done.Add(data.Name.ToLower()); } return(faulty); }
internal HICPConfigApplyAdministrator(MergeAdministrator mergeAdministrator, HICPConfigMergeForm mergeForm, HICPConfigFacade vcFacLocal, HICPConfigFacade vcFacRemote) { _mergeAdministrator = mergeAdministrator; _vcFacLocal = vcFacLocal; _vcLocal = _vcFacLocal.GetHICPConfig(); _vcFacRemote = vcFacRemote; _vcRemote = _vcFacRemote.GetHICPConfig(); _mergeForm = mergeForm; _mcHICPConfig = _mergeForm.GetMergeControlByName(EMPath.EM2_FILE_HICP); }
void AddHICP(bool local) { foreach (string ID in GetRelevantIDs(_mcHICPConfig, local, true)) { string country = ID.Substring(0, ID.IndexOf("_")); string year = ID.Substring(ID.IndexOf("_") + 1); HICPConfig.HICPRow dataRow = _vcFacRemote.GetHICP(country, year); HICPConfigFacade.CopyHICPFromAnotherConfig(_vcLocal, dataRow); } }
string GetNoHICPSystems(List <CountryConfig.SystemRow> publicSystems, string country) { string faulty = string.Empty; HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); if (hcf == null) { return(faulty); // should not happen } foreach (CountryConfig.SystemRow system in publicSystems) { if (hcf.GetHICP(country, GetSystemYear(system)) == null) { faulty += system.Name + ", "; } } return(faulty); }
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; }
private void StoreHICPInGlobalTable() { HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(false); if (hcf == null) { return; // do nothing if HICPConfig does not exist yet } foreach (DataRow row in dgvDataTable.Rows) { if (row.Field <string>(colReference.Name) != "$HICP") { continue; } List <Tuple <string, int, double, string> > hicps = new List <Tuple <string, int, double, string> >(); string comment = row.Field <string>(colComment.Name); string country = EM_AppContext.Instance.GetActiveCountryMainForm().GetCountryShortName(); foreach (DataColumn col in dgvDataTable.Columns) { if (!col.Caption.StartsWith(_colYear)) { continue; } string sYear = col.Caption.Substring(_colYear.Length); int year; if (!int.TryParse(sYear, out year)) { continue; } string sVal = row.Field <string>(col.Caption); double dVal; if (!double.TryParse(sVal, out dVal)) { continue; } hicps.Add(new Tuple <string, int, double, string>(country, year, dVal, comment)); } if (hcf.SetHICPs(hicps)) { hcf.WriteXML(); } } }
private static DialogResult GenerateHICPTable(out List <HICPConfig.HICPRow> hicps) { DialogResult choice = UserInfoHandler.GetInfo("The HICP Table does not yet exist. Do you want to automatically generate it by extracting HICPs from country tables?", MessageBoxButtons.YesNoCancel); hicps = choice == DialogResult.Cancel ? null : new List <HICPConfig.HICPRow>(); if (choice != DialogResult.Yes) { return(choice); // if user's choice was No (or even on error in assessing HICPs below) show the empty HICP table (i.e. hicps != null) } HICPConfigFacade hcf = EM_AppContext.Instance.GetHICPConfigFacade(true); if (hcf == null) { return(DialogResult.Cancel); // bad error - shouldn't happen } try { ProgressIndicator progressIndicator = new ProgressIndicator(GetCountryHICPs_BackgroundEventHandler, "Assessing Country Info ..."); if (progressIndicator.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return(choice); // user cancelled the generation - show empty HICP table } List <Tuple <string, int, double, string> > hicpInfo = progressIndicator.Result as List <Tuple <string, int, double, string> >; if (hicpInfo == null) // an exception was thrown while loading countries { UserInfoHandler.ShowError(string.Format("Generating HICP Table failed with the following error:{0}{1}", Environment.NewLine, progressIndicator.Result.ToString())); return(choice); // show empty HICP table } if (hcf.RefreshHICPs(hicpInfo) && hcf.WriteXML()) { hicps = hcf.GetHICPs(); } return(choice); } catch (Exception exception) { UserInfoHandler.ShowException(exception); return(choice); } }
} //force re-reading on next access internal void UnloadHICPConfigFacade() { _HICPConfigFacade = null; }