private void buttonFormatDelete_Click(object sender, EventArgs e) { PressureLossReportDataManager reportDataMgr = PressureLossReportDataManager.Instance; PressureLossReportFormats allFormats = reportDataMgr.getAllFormats(); if (allFormats == null || allFormats.Count < 1 || this.comboBoxFormat.Items.Count < 1) { return; } if (allFormats.Count == 1 || (allFormats.Count == 2 && reportDataMgr.getLastUsedReportData() != null)) { UIHelperFunctions.postWarning(ReportResource.deleteFormatTitle, ReportResource.deleteLastFormatMsg, ReportResource.deleteLastFormatSubMsg); return; } TaskDialog tdlg = new TaskDialog(ReportResource.deleteFormatTitle); tdlg.MainInstruction = ReportResource.deleteFormatMsg; tdlg.AllowCancellation = true; tdlg.CommonButtons = TaskDialogCommonButtons.Yes | TaskDialogCommonButtons.No; tdlg.DefaultButton = TaskDialogResult.No; tdlg.TitleAutoPrefix = false; // suppress the prefix of title. if (tdlg.Show() == TaskDialogResult.Yes) { // delete the report format, and update the combo list, set the next one as current string name = this.comboBoxFormat.SelectedItem.ToString(); if (name == reportDataMgr.getLastUsedReportName()) { PressureLossReportData lastData = reportDataMgr.getLastUsedReportData(); if (lastData != null) { reportDataMgr.remove(lastData.Name); } } reportDataMgr.remove(name); this.comboBoxFormat.Items.Remove(name); if (this.comboBoxFormat.Items.Count > 0) { this.comboBoxFormat.SelectedIndex = 0; } } }
private void FillingData() { try { //Way 1: //1. Fill in the combo: report format names or "untitled format" //?: Which i=one is the default selected? PressureLossReportHelper helper = PressureLossReportHelper.instance; PressureLossReportDataManager reportDataMgr = PressureLossReportDataManager.Instance; PressureLossReportFormats formats = reportDataMgr.getAllFormats(); if (formats != null && formats.Count > 0) { PressureLossReportData lastData = reportDataMgr.getLastUsedReportData(); string lastUsedName = ""; foreach (PressureLossReportData data in formats) { if (lastData != null && lastData.Name == data.Name) { lastUsedName = reportDataMgr.getLastUsedReportName(); if (formats.Count == 1) { this.comboBoxFormat.Items.Add(lastUsedName); } } else { this.comboBoxFormat.Items.Add(data.Name); } } if (lastUsedName.Length > 0 && this.comboBoxFormat.Items.IndexOf(lastUsedName) > -1) { this.comboBoxFormat.SelectedIndex = this.comboBoxFormat.Items.IndexOf(lastUsedName); } else { this.comboBoxFormat.SelectedIndex = 0; } settings = reportDataMgr.getData(this.comboBoxFormat.SelectedItem.ToString()); resetSettings(); } if (settings == null) //fill in default values { settings = new PressureLossReportData(); generateDefaultFormatData(); settings.Name = ReportResource.formatDefaultName; reportDataMgr.save(settings); this.comboBoxFormat.Items.Add(settings.Name); this.comboBoxFormat.SelectedIndex = 0; } if (settings != null) { fillSettingsControlsFromFormat(settings); } this.buttonUp.Enabled = false; this.buttonDown.Enabled = false; this.listBoxAvailableFields.Focus(); this.listBoxAvailableFields.SetSelected(0, true); //title if (helper.Domain == ReportResource.pipeDomain) { this.Text = ReportResource.pipeSettingsDlgTitle; } else { this.Text = ReportResource.ductSettingsDlgTitle; } } catch { //do nothing } }