private void LinkAdvanced_Click(object sender, EventArgs e) { if (this.groupAdvancedOptions.Visible) { if (UserInfoHandler.GetInfo("Advanced settings will not be applied if you close them. Would you like to close them?", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (chkSkipCountryLabelCheck.Visible) { chkSkipCountryLabelCheck.Checked = true; } this.groupAdvancedOptions.Visible = false; this.linkAdvancedOptions.Text = "Display advanced options"; txtParentVersion.Text = string.Empty; chkUseRemote.Checked = false; chkUseLocal.Checked = true; this.Size = new Size(539, 147); } } else { this.groupAdvancedOptions.Visible = true; this.linkAdvancedOptions.Text = "Hide advanced options."; this.Size = new Size(539, 267); txtParentVersion.Enabled = false; btnSelectParentVersion.Enabled = false; } }
void btnDelete_Click(object sender, EventArgs e) { if (dgvSwitchablePolicies.SelectedRows.Count != 1) { return; } try { //deleting an existing switchable policy may need to require an update of country files (which is too complex here) //example: delete bun*_??: all switches defined for the matching policies of the country would have to be changed from 'switch' to 'toggle' //removal in the country files however only takes place on closing the SetPolicySwitchesForm with 'OK' - thus this warning VarConfig.SwitchablePolicyRow switchablePolicyRow = (dgvSwitchablePolicies.SelectedRows[0].Tag as VarConfig.SwitchablePolicyRow); if (switchablePolicyRow.RowState != DataRowState.Added && UserInfoHandler.GetInfo(_noUpdateInCountriesWarning, MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { return; } switchablePolicyRow.Delete(); dgvSwitchablePolicies.Rows.Remove(dgvSwitchablePolicies.SelectedRows[0]); } catch (Exception exception) { UserInfoHandler.ShowException(exception); } dgvSwitchablePolicies.Update(); //if gridview is not updated it looks weired (text of two rows are displayed in one) }
private static void SetExtensionPrivateGlobal(string extName, bool set) { string message = "Setting components of extension '" + extName + "' to " + (set ? "private" : "'not private'"); if (EM_AppContext.Instance.IsAnythingOpen(false)) { if (UserInfoHandler.GetInfo(message + " requires all countries to be closed." + Environment.NewLine + "All open countries will be closed.", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { return; } EM_AppContext.Instance.CloseAllMainForms(false, false); } if (EM_AppContext.Instance.IsAnythingOpen(false)) { return; // user may have refused to save changes for an open country } using (ProgressIndicator progressIndicator = new ProgressIndicator(SetPrivate_BackgroundEventHandler, message, new Tuple <string, bool>(extName, set))) { if (progressIndicator.ShowDialog() == DialogResult.OK) { UserInfoHandler.ShowSuccess(message + " successfully accomplished."); } } }
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(); } }
void btnDeleteYear_Click(object sender, EventArgs e) { if (cmbYearToDelete.Text == string.Empty) { UserInfoHandler.ShowError("Please select a year."); return; } if (UserInfoHandler.GetInfo("Are you sure you want to delete this column?\n\nNote: you will not be able to undo this action or any action before this.", MessageBoxButtons.YesNo) == DialogResult.No) { return; } for (int index = table.Columns.Count - 1; index >= 0; --index) { if (table.Columns[index].HeaderText == cmbYearToDelete.Text) { dataTable.Columns.Remove(table.Columns[index].Name); //table.Columns.RemoveAt(index); break; } } foreach (DataRow row in dataTable.Rows) { row[0] = row[0]; // this is to make sure the deleted column counts as a DataSet change... } cmbYearToDelete.Items.RemoveAt(cmbYearToDelete.SelectedIndex); dataSet.AcceptChanges(); undoManager.Reset(); columnsChanged = true; }
void btnRemoveUsers_Click(object sender, EventArgs e) { List <ExtUserRightInfo> usersToRemove = new List <ExtUserRightInfo>(); string userNames = string.Empty; foreach (DataGridViewRow row in dgvUsers.SelectedRows) { ExtUserRightInfo extUserInfo = row.Tag as ExtUserRightInfo; VCAdministrator.AddUnitToMessage(ref userNames, extUserInfo.userInfo.username); if (!extUserInfo.added) { usersToRemove.Add(extUserInfo); //user only needs to be removed via API if it wasn't added during this session of the dialog } } if (UserInfoHandler.GetInfo("Are you sure you want to remove user(s) " + userNames + " from project?", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { return; } _usersToRemove.AddRange(usersToRemove); foreach (DataGridViewRow row in dgvUsers.SelectedRows) { dgvUsers.Rows.Remove(row); } }
private void ExchangeRatesForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == System.Windows.Forms.DialogResult.Cancel && dgvRates.HasChanges() && UserInfoHandler.GetInfo("Are you sure you want to close without saving?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { e.Cancel = true; } }
private bool AcceptRestrictions() { if (EM_AppContext.Instance.IsAnythingOpen(false)) { UserInfoHandler.ShowInfo("Deleting extensions needs all countries to be closed."); return(false); } return(UserInfoHandler.GetInfo("Please note that the necessary changes for countries using this/these extension(s) are accomplished once the country is next opened (automatically, but with a user request).", MessageBoxButtons.OKCancel) == DialogResult.OK); }
private bool EM3_Transform() { try { lock (transformLock) { string transformerErrors = string.Empty; foreach (string country in countriesToTransform) { EM3Country.Transform(EM_AppContext.FolderEuromodFiles, country, out List <string> errors); foreach (string error in errors) { transformerErrors += error + Environment.NewLine; } } foreach (string addOn in addOnsToTransform) { EM3Country.TransformAddOn(EM_AppContext.FolderEuromodFiles, addOn, out List <string> errors); foreach (string error in errors) { transformerErrors += error + Environment.NewLine; } } EM3Global.Transform(EM_AppContext.FolderEuromodFiles, out List <string> gErrors); foreach (string error in gErrors) { transformerErrors += error + Environment.NewLine; } EM3Variables.Transform(EM_AppContext.FolderEuromodFiles, out List <string> vErrors); foreach (string error in vErrors) { transformerErrors += error + Environment.NewLine; } if (transformerErrors == string.Empty) { return(true); } return(UserInfoHandler.GetInfo("Errors on transforming to EM3 structure:" + Environment.NewLine + transformerErrors + Environment.NewLine + "Do you want to continue?", MessageBoxButtons.YesNo) == DialogResult.Yes); } } catch (Exception exception) { return(UserInfoHandler.GetInfo("Errors on transforming to EM3 structure:" + Environment.NewLine + exception.Message + Environment.NewLine + Environment.NewLine + "Do you want to continue?", MessageBoxButtons.YesNo) == DialogResult.Yes); } }
internal static void UpdateCountryFiles(Dictionary <string, List <Tuple <string, string> > > changesCountryFiles, Form showWaitCursorForm = null) { try { if (showWaitCursorForm == null) { showWaitCursorForm = EM_AppContext.Instance.GetActiveCountryMainForm(); } showWaitCursorForm.Cursor = Cursors.WaitCursor; bool showOpenWarning = true; foreach (var ccChange in changesCountryFiles) { string country = ccChange.Key; EM_UI_MainForm ccMainForm = EM_AppContext.Instance.GetCountryMainForm(country); if (ccMainForm != null) { if (showOpenWarning) { switch (UserInfoHandler.GetInfo(country.ToUpper() + " is open." + Environment.NewLine + "Updating exchange rates requires a reset of the undo-functionality." + Environment.NewLine + "That means you will not be able to undo any of your changes so far." + Environment.NewLine + Environment.NewLine + "Do you still want to update exchange rates of " + country.ToUpper() + "?" + Environment.NewLine + Environment.NewLine + "(Press Cancel to not be requested with respect to further open countries.)", MessageBoxButtons.YesNoCancel)) { case DialogResult.No: continue; case DialogResult.Cancel: showOpenWarning = false; break; } } ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset(); } CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(country); foreach (var change in ccChange.Value) { ccf.GetSystemRowByName(change.Item1).ExchangeRateEuro = change.Item2; } if (ccMainForm != null) { ccMainForm.GetUndoManager().Commit(); ccMainForm.GetUndoManager().Reset(); ccMainForm.WriteXml(); } else { CountryAdministrator.WriteXML(country); } } } catch (Exception) { } finally { showWaitCursorForm.Cursor = Cursors.Default; } }
void UpratingIndicesForm_FormClosing(object sender, FormClosingEventArgs e) { if (DialogResult == System.Windows.Forms.DialogResult.Cancel) { if (dgvDataSet.GetChanges() != null || undoManager.HasChanges() || columnsChanged) { if (UserInfoHandler.GetInfo("Are you sure you want to close without saving?", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { e.Cancel = true; } } } }
internal static bool GetSupportedSystemInfo(string systemName, List <AddOnSystemInfo> totalAOSystemInfo, out List <AddOnSystemInfo> supportedAOSystemInfo) { supportedAOSystemInfo = new List <AddOnSystemInfo>(); foreach (AddOnSystemInfo addOnSystemInfo in totalAOSystemInfo) { if (IsSystemSupported(systemName, addOnSystemInfo)) { supportedAOSystemInfo.Add(addOnSystemInfo); } } return(supportedAOSystemInfo.Count() <= 1 || UserInfoHandler.GetInfo($"Warning: add-on {supportedAOSystemInfo[0]._addOnShortName} contains more than one system running with {systemName} ({supportedAOSystemInfo[0]._addOnSystemName}, {supportedAOSystemInfo[1]._addOnSystemName})", MessageBoxButtons.OKCancel) == DialogResult.OK); }
void btnOK_Click(object sender, EventArgs e) { if (!verifyNumericValues()) { UserInfoHandler.ShowError("Cell(s) with invalid value found!"); } else if (!haveEmptyCells() || UserInfoHandler.GetInfo("Empty cell(s) found; they will be treated as n/a when running the model." + Environment.NewLine + "Do you want to correct?", MessageBoxButtons.YesNo) == DialogResult.No) { mainForm.PerformAction(new IndirectTaxesAction(this), false); DialogResult = DialogResult.OK; Close(); } }
private static bool CheckSysNameYearMatch(string systemName, int year) { if (year < 0) { return(true); } string yYear = year.ToString(), sYear = EM_Helpers.ExtractSystemYear(systemName); if (string.IsNullOrEmpty(sYear) || yYear == sYear) { return(true); } return(UserInfoHandler.GetInfo($"Year does not match with year suggested by system name ({yYear} vs. {sYear})" + Environment.NewLine + "Do you want to correct?", MessageBoxButtons.YesNo) == DialogResult.No); }
void btnAddYear_Click(object sender, EventArgs e) { keepUndoData = false; string year = updwnYearToAdd.Value.ToString(); if (GetExistingYears().Contains(year)) { UserInfoHandler.ShowError(year + " already exits."); return; } if (UserInfoHandler.GetInfo("Are you sure you want to add a new column?\n\nNote: you will not be able to undo this action or any action before this.", MessageBoxButtons.YesNo) == DialogResult.No) { return; } AddYearColumn(year); keepUndoData = true; dataSet.AcceptChanges(); undoManager.Reset(); columnsChanged = true; }
public static bool GetRangeValues(out List <double> rangeValues, double start, double end, double step, bool showResults = false) { rangeValues = new List <double>(); if (start > end) { UserInfoHandler.ShowError("Start must not be higher than end (" + start.ToString() + ">" + end.ToString() + ")"); return(false); } int absMaxCount = showResults ? ALPHA_RANGE_MAX_SHOW // template allows for 50+2 (the 2 are for CPI+MII, : ALPHA_RANGE_MAX; // thus in fact it'll be 52 if they are not selected) for (double d = start; d <= end && rangeValues.Count <= ALPHA_RANGE_MAX + 1; d += step) { if (d == 0) { if (UserInfoHandler.GetInfo("The range contains zero." + Environment.NewLine + "Should zero be skipped?", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { return(false); } } else { rangeValues.Add(d); } } if (rangeValues.Count == 0) { UserInfoHandler.ShowError("The range contains no numbers."); return(false); } if (rangeValues.Count <= ALPHA_RANGE_MAX_SHOW) { return(true); // consider 50 as 'reasonable' (?) and do not issue a warning } // if template is not shown, allow for 500, but still warn if more than 50; if template is shown 50 is max, as the template does not allow for more (see above) string cnt = rangeValues.Count <= ALPHA_RANGE_MAX + 1 ? rangeValues.Count.ToString() : "too many"; string message = "The range contains " + cnt + " numbers." + Environment.NewLine + "Allowed are " + ALPHA_RANGE_MAX_SHOW + " for 'Run Only' and " + ALPHA_RANGE_MAX + " for 'Run & Show Results'."; if (rangeValues.Count > absMaxCount) { UserInfoHandler.ShowError(message); return(false); } return(UserInfoHandler.GetInfo(message + Environment.NewLine + "Do you want to continue?", MessageBoxButtons.YesNo) == DialogResult.Yes); }
private void deleteSelectedRows() { if (table.SelectedRows.Count < 1 || UserInfoHandler.GetInfo("Are you sure you want to remove the selected row(s)?\n\nNote: you will not be able to undo this action or any action before this.", MessageBoxButtons.YesNo) == DialogResult.No) { return; } keepUndoData = false; foreach (DataGridViewRow vrow in table.SelectedRows) { if (!vrow.IsNewRow) { dataTable.Rows.Remove((vrow.DataBoundItem as DataRowView).Row); // ignore delete for the empty new row } } keepUndoData = true; dataSet.AcceptChanges(); undoManager.Reset(); columnsChanged = true; }
internal bool CloseAnythingOpen() { if (IsAnythingOpen() || IsVariablesFormOpen()) { if (UserInfoHandler.GetInfo("All open countries/add-ons/variables need to be closed. Proceed?", MessageBoxButtons.YesNo) == DialogResult.No) { return(false); } EM_AppContext.Instance.CloseVariablesForm(); EM_AppContext.Instance.CloseAllMainForms(false); if (IsAnythingOpen() || IsVariablesFormOpen()) // check again in case something was not closed { UserInfoHandler.ShowError("Problems with automatic closing - please close all countries/add-ons/variables manually."); return(false); } } return(true); }
private static void SetExtensionPrivateCountry(string cc, EM_UI_MainForm mainForm, string extName, bool set) { bool isLocal = (from e in GetDataConfig(cc).Extension where e.Name.ToLower() == extName.ToLower() || e.ID == extName select e).Any(); if (!isLocal) { switch (UserInfoHandler.GetInfo("Do you want to perform this private-setting-action for all countries? Click" + Environment.NewLine + "'Yes' to perform the action for all countries" + "," + Environment.NewLine + "'No' to perform the action only for " + cc + ".", MessageBoxButtons.YesNoCancel)) { case DialogResult.Cancel: return; case DialogResult.Yes: SetExtensionPrivateGlobal(extName, set); return; case DialogResult.No: break; } } mainForm.PerformAction(new ExtensionSetPrivateAction(extName, cc, set)); }
void btnOK_Click(object sender, EventArgs e) { bool reload = false; if (EMPath.AddSlash(EM_AppContext.Instance.GetUserSettingsAdministrator().Get().EuromodFolder).ToLower() != EMPath.AddSlash(cmbEuromodFolder.Text).ToLower()) { if (!EM_AppContext.Instance.CloseAnythingOpen()) { return; // if there are any countries/add-ons/variables open, try to close them } reload = true; } if (!Directory.Exists(cmbEuromodFolder.Text)) { UserInfoHandler.ShowError(cmbEuromodFolder.Text + " is not a valid path."); return; } if (!Directory.Exists(EMPath.AddSlash(cmbEuromodFolder.Text) + EMPath.Folder_Countries_withoutPath())) { if (UserInfoHandler.GetInfo($"'{cmbEuromodFolder.Text}' does not (yet) contain the {DefGeneral.BRAND_TITLE} file structure." + Environment.NewLine + Environment.NewLine + "Do you want to change the 'Project Folder'?", MessageBoxButtons.YesNo) == DialogResult.Yes) { return; } } if (reload) { ReloadUserSettings(); CountryAdministration.CountryAdministrator.ClearCountryList(); EM_AppContext.Instance.SetBrand(); // allow UI to show another look, i.e. present a brand alternative to EUROMOD EM_AppContext.Instance.UpdateAllCountryMainFormGalleries(); //only the empty main form is open and must be updated EM_AppContext.Instance.UpdateMainFormCaption(); //set title (of single open mainform) to "EUROMOD Version (Path)" EM_AppContext.Instance.UnloadVarConfigFacade(); EM_AppContext.Instance.UnloadHICPConfigFacade(); EM_AppContext.Instance.UnloadExchangeRatesConfigFacade(); EM_AppContext.Instance.UnloadSwitchablePolicyConfigFacade(); } Close(); }
internal static void RenameOutputFiles(CountryConfigFacade countryConfigFacade, CountryConfig.SystemRow systemRow, string oldSystemName, bool request = false) { //search policies Output_Std_cc and Output_Std_HH_cc //CountryConfig.PolicyRow policyRow = countryConfigFacade.GetPolicyRowByName(systemRow.ID, standardOutputPolicyName); //if (policyRow == null) continue; //within these policies search for function(s) DefOutput //List<CountryConfig.FunctionRow> defOutputFunctionRows = countryConfigFacade.GetFunctionRowsByPolicyIDAndFunctionName(policyRow.ID, DefFun.DefOutput); var defOutputFunctionRows = from f in countryConfigFacade.GetCountryConfig().Function where f.PolicyRow.SystemID == systemRow.ID && f.Name.ToLower() == DefFun.DefOutput.ToLower() select f; foreach (CountryConfig.FunctionRow defOutputFunctionRow in defOutputFunctionRows) { //within these functions search for parameter File CountryConfig.ParameterRow parameterRow = countryConfigFacade.GetParameterRowByName(defOutputFunctionRow.ID, DefPar.DefOutput.File); if (parameterRow == null) { continue; } //if parameter file found replace system name (e.g. rename UK_2009_std to UK_2009_reform_std) int index = parameterRow.Value.ToLower().IndexOf(oldSystemName.ToLower()); if (index < 0) { continue; } string newOutputName = parameterRow.Value.Substring(0, index) + systemRow.Name + parameterRow.Value.Substring(index + oldSystemName.Length); if (request) { if (UserInfoHandler.GetInfo("Do you want to adapt the names of output-files to the new system name?" + Environment.NewLine + string.Format("(e.g. '{0}' to '{1}')", parameterRow.Value, newOutputName), MessageBoxButtons.YesNo) == DialogResult.Yes) { request = false; // do not ask again for any other output-policy } else { return; // do not rename } } parameterRow.Value = newOutputName; } }
void btnRemoveBundles_Click(object sender, EventArgs e) { if (lvBundles.CheckedItems.Count == 0) { UserInfoHandler.ShowInfo("Please select the bundles you want to remove."); return; } string warningContent = (_removeReleases) ? Environment.NewLine + Environment.NewLine + "This will remove an already commited merge!" : string.Empty; if (UserInfoHandler.GetInfo("Are you sure you want to irrevocably delete " + (lvBundles.CheckedItems.Count == 1 && warningContent == string.Empty ? "this item?" : "these items?" + warningContent), MessageBoxButtons.YesNo) == DialogResult.No) { return; } List <ReleaseInfo> bundles = new List <ReleaseInfo>(); foreach (ListViewItem item in lvBundles.CheckedItems) { bundles.Add(item.Tag as ReleaseInfo); } Cursor = Cursors.WaitCursor; bool success = _vcAPI.RemoveReleases(bundles, _vcAPI.vc_projectInfo.ProjectId); if (success) { UserInfoHandler.ShowSuccess("Removal accomplished."); } else { UserInfoHandler.ShowError(_vcAPI.GetErrorMessage()); } Cursor = Cursors.Default; Close(); }
void dgvSwitchablePolicies_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex < 0 || dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == null) { return; } try { string newValue = dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); VarConfig.SwitchablePolicyRow switchablePolicy = dgvSwitchablePolicies.Rows[e.RowIndex].Tag as VarConfig.SwitchablePolicyRow; //changing the name pattern (e.g. yem_??) of an existing switchable policy may need to require an update of country files (which is too complex here) //example: change yem_?? to yem*_??: the switches already set for this country would apply to more policies (the long name is not visible, therefore no problem changing it) //updating in the country files however only takes place on closing the SetPolicySwitchesForm with 'OK' - thus this warning if (e.ColumnIndex == colNamePattern.Index && switchablePolicy.RowState != DataRowState.Added && newValue != switchablePolicy.NamePattern && UserInfoHandler.GetInfo(_noUpdateInCountriesWarning, MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.Cancel) { dgvSwitchablePolicies.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = switchablePolicy.NamePattern; return; } if (e.ColumnIndex == colLongName.Index) { switchablePolicy.LongName = newValue; } else if (e.ColumnIndex == colNamePattern.Index) { switchablePolicy.NamePattern = newValue; } } catch (Exception exception) { UserInfoHandler.ShowException(exception); } }
void btnCreateInfoFile_Click(object sender, EventArgs e) { if (!Directory.Exists(txtInfoOutputFolder.Text)) { UserInfoHandler.ShowError("Please select an existing Output Folder."); return; } if (txtInfoOutputFile.Text.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { UserInfoHandler.ShowError("Output File contains invalid characters."); return; } if (!txtInfoOutputFile.Text.ToLower().EndsWith(".xlsx")) { txtInfoOutputFile.Text += ".xlsx"; } infoFilePath = Path.Combine(txtInfoOutputFolder.Text, txtInfoOutputFile.Text); if (File.Exists(infoFilePath) && UserInfoHandler.GetInfo("Should the existing file be overwritten?", MessageBoxButtons.YesNo) == DialogResult.No) { return; } selectedFunction = CREATE_INFO_FILE; DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
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); } }
public void CheckForGeneralChanges(string changeCausingUserSettingsPath) { try { if (_currentSettings == null || _bkupCurrentSettings == null) { return; } List <string> userSettingFullPaths; List <string> userSettingFolders = GetAvailableProjectPaths(out userSettingFullPaths); if (userSettingFullPaths.Count == 0 || // check if no other user-settings but the current (userSettingFullPaths.Count == 1 && userSettingFullPaths.First().ToLower() == changeCausingUserSettingsPath.ToLower())) { return; } Dictionary <string, KeyValuePair <string, object> > changedGeneralSettings = new Dictionary <string, KeyValuePair <string, object> >(); if (Get().OptionalWarnings != bkupGet().OptionalWarnings) { changedGeneralSettings.Add("Optional Warnings", new KeyValuePair <string, object>("OptionalWarnings", Get().OptionalWarnings)); } if (Get().AutoSaveInterval != bkupGet().AutoSaveInterval) { changedGeneralSettings.Add(string.Format("Autosave Interval: {0} min", Get().AutoSaveInterval / 60000), new KeyValuePair <string, object>("AutoSaveInterval", Get().AutoSaveInterval)); } if (Get().ParallelRunsAuto != bkupGet().ParallelRunsAuto) { changedGeneralSettings.Add(string.Format("Number of Parallel Executable-Runs: {0}", Get().ParallelRunsAuto ? "Auto" : "Custom"), new KeyValuePair <string, object>("ParallelRunsAuto", Get().ParallelRunsAuto)); } if (Get().ParallelRuns != bkupGet().ParallelRuns) { changedGeneralSettings.Add(string.Format("Number of Parallel Executable-Runs: Custom = {0}", Get().ParallelRuns), new KeyValuePair <string, object>("ParallelRuns", Get().ParallelRuns)); } if (Get().CloseInterfaceWithLastMainform != bkupGet().CloseInterfaceWithLastMainform) { changedGeneralSettings.Add(string.Format("Close Interface With Last Country: {0}", Get().CloseInterfaceWithLastMainform), new KeyValuePair <string, object>("CloseInterfaceWithLastMainform", Get().CloseInterfaceWithLastMainform)); } if (Get().VCLogInAtProjectLoad != bkupGet().VCLogInAtProjectLoad) { changedGeneralSettings.Add(string.Format("Version Control, Log In At ProjectLoad: {0}", Get().VCLogInAtProjectLoad ? "yes" : "no"), new KeyValuePair <string, object>("VCLogInAtProjectLoad", Get().VCLogInAtProjectLoad)); } if (!bkupGet().VCUseProxy&& Get().VCProxyURL != bkupGet().VCProxyURL&& Get().VCProxyPort != bkupGet().VCProxyPort) { changedGeneralSettings.Add(string.Format("Use Proxy: {0}", Get().VCUseProxy), new KeyValuePair <string, object>("VCUseProxy", Get().VCUseProxy)); } if (Get().VCProxyURL != bkupGet().VCProxyURL) { changedGeneralSettings.Add(string.Format("Version Control Proxy URL: {0}", Get().VCProxyURL), new KeyValuePair <string, object>("VCProxyURL", Get().VCProxyURL)); } if (Get().VCProxyPort != bkupGet().VCProxyPort) { changedGeneralSettings.Add(string.Format("Version Control Proxy Port: {0}", Get().VCProxyPort), new KeyValuePair <string, object>("VCProxyPort", Get().VCProxyPort)); } if (Get().InputFolder != bkupGet().InputFolder&& !Get().InputFolder.ToLower().StartsWith(Get().EuromodFolder.ToLower())) // only take into account if folder for data is not within current project { changedGeneralSettings.Add(string.Format("Input Folder: {0}", Get().InputFolder), new KeyValuePair <string, object>("InputFolder", Get().InputFolder)); } if (changedGeneralSettings.Count == 0) { return; } string request = string.Format("Should the following change{0} of your (current project's) user settings be transferred to all projects' user settings?", changedGeneralSettings.Count == 1 ? string.Empty : "s") + Environment.NewLine + Environment.NewLine; foreach (string descriptionChangedSetting in changedGeneralSettings.Keys) { request += "- " + descriptionChangedSetting + Environment.NewLine; } if (UserInfoHandler.GetInfo(request, MessageBoxButtons.YesNo) == DialogResult.No) { return; } for (int i = 0; i < userSettingFullPaths.Count; ++i) { if (userSettingFullPaths.First().ToLower() == changeCausingUserSettingsPath.ToLower()) { continue; } UserSettings userSettings = ReadSettings(userSettingFullPaths[i]); foreach (KeyValuePair <string, object> changedGeneralSetting in changedGeneralSettings.Values) { string settingName = changedGeneralSetting.Key; object settingValue = changedGeneralSetting.Value; userSettings.Settings.Rows[0][settingName] = settingValue; } userSettings.Settings.AcceptChanges(); SaveSettings(userSettings, userSettingFullPaths[i]); } } catch { } // do not jeopardise UI due to not being able to transfer user-setting }
internal static bool IsOldStyleExtensions(string cc, out bool openReadOnly) { openReadOnly = false; bool isOldStyle = false; // check for all policies with switch='switch' whether they are part of any extension ... foreach (CountryConfig.PolicyRow pol in from p in GetCountryConfig(cc).Policy where p.Switch == DefPar.Value.SWITCH select p) { if (!(from ep in GetCountryConfig(cc).Extension_Policy where ep.PolicyID == pol.ID && !ep.BaseOff select ep).Any()) { isOldStyle = true; break; } } if (!isOldStyle) { return(false); } // ... if not - suggest transformation to new style if (UserInfoHandler.GetInfo("The country needs to be updated to the new handling for Extensions (aka Switchable Policies)." + Environment.NewLine + "If you click Cancel the country will be opened in read-only mode.", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { openReadOnly = true; return(true); } // transform to new style: this assumes that the 'switch' settings in the spine are ok and just adds policies to extensions, which fulfill the name-pattern requirements CountryConfigFacade ccf = CountryAdministrator.GetCountryConfigFacade(cc); try { foreach (GlobLocExtensionRow ext in GetGlobalExtensions()) { foreach (CountryConfig.PolicyRow polRow in ccf.GetPolicyRowsOrderedAndDistinct()) { string polName = string.IsNullOrEmpty(polRow.ReferencePolID) ? polRow.Name : ccf.GetPolicyRowByID(polRow.ReferencePolID).Name; if (!EM_Helpers.DoesValueMatchPattern(ext.ShortName, polName)) { continue; } foreach (CountryConfig.SystemRow sysRow in ccf.GetSystemRows()) { CountryConfig.PolicyRow polSysRow = ccf.GetPolicyRowByOrder(polRow.Order, sysRow.ID); if (!(from e in ccf.GetCountryConfig().Extension_Policy where e.ExtensionID == ext.ID & e.PolicyID == polSysRow.ID select e).Any()) // avoid double adding, which could actually only be caused by "playing" { ccf.GetCountryConfig().Extension_Policy.AddExtension_PolicyRow(ext.ID, polSysRow, false); } } } } GetCountryConfig(cc).AcceptChanges(); CountryAdministrator.WriteXML(cc); } catch (Exception exception) { UserInfoHandler.ShowException(exception, "Adapting Extensions failed.", false); ccf.GetCountryConfig().RejectChanges(); } return(true); }
internal static void CheckForRemovedGlobalExtensions(string cc, out bool openReadOnly) { openReadOnly = false; List <string> existingExt = (from e in GetExtensions(cc) select e.ID).ToList(); List <CountryConfig.Extension_PolicyRow> delExtPol = new List <CountryConfig.Extension_PolicyRow>(); List <CountryConfig.Extension_FunctionRow> delExtFun = new List <CountryConfig.Extension_FunctionRow>(); List <CountryConfig.Extension_ParameterRow> delExtPar = new List <CountryConfig.Extension_ParameterRow>(); foreach (CountryConfig.Extension_PolicyRow ep in GetCountryConfig(cc).Extension_Policy) { if (!existingExt.Contains(ep.ExtensionID)) { delExtPol.Add(ep); } } foreach (CountryConfig.Extension_FunctionRow ef in GetCountryConfig(cc).Extension_Function) { if (!existingExt.Contains(ef.ExtensionID)) { delExtFun.Add(ef); } } foreach (CountryConfig.Extension_ParameterRow ep in GetCountryConfig(cc).Extension_Parameter) { if (!existingExt.Contains(ep.ExtensionID)) { delExtPar.Add(ep); } } if (!delExtPol.Any() && !delExtFun.Any() && !delExtPar.Any()) { return; } if (UserInfoHandler.GetInfo("The country needs to be updated for removed Global Extensions." + Environment.NewLine + "If you click Cancel the country will be opened in read-only mode.", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { openReadOnly = true; return; } try { foreach (CountryConfig.Extension_PolicyRow dep in delExtPol) { if (dep.PolicyRow.Switch == DefPar.Value.SWITCH) { dep.PolicyRow.Switch = DefPar.Value.TOGGLE; } dep.Delete(); } foreach (CountryConfig.Extension_FunctionRow def in delExtFun) { if (def.FunctionRow.Switch == DefPar.Value.SWITCH) { def.FunctionRow.Switch = DefPar.Value.TOGGLE; } def.Delete(); } foreach (CountryConfig.Extension_ParameterRow dep in delExtPar) { dep.Delete(); } ExtensionDefaultSwitches_RemoveRelics(cc); GetCountryConfig(cc).AcceptChanges(); CountryAdministrator.WriteXML(cc); } catch (Exception exception) { UserInfoHandler.ShowException(exception, "Adapting Extensions failed.", false); GetCountryConfig(cc).RejectChanges(); } }