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 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); } }