} // end method RestoreColumnWidth /// <summary> /// Organise and show search results. /// </summary> private void ShowSearchResults() { // It seems to be no internet connection. if (_strikePriceVolumeRowCollection == null) { TextBlockNullData.Text = Properties.Resources.TextBlockNullData_Text_NetworkError; TextBlockNullData.Visibility = Visibility.Visible; return; } // end if // Wrong filters (symbol/start date/end date). if (_strikePriceVolumeRowCollection[0] == null) { TextBlockNullData.Text = Properties.Resources.TextBlockNullData_Text_WrongFilters; TextBlockNullData.Visibility = Visibility.Visible; return; } // end if switch (_strikePriceVolumeRowCollection[0].Length) { // The specified data source denies access. case 1: TextBlockNullData.Text = Properties.Resources.TextBlockNullData_Text_AccessDenied; TextBlockNullData.Visibility = Visibility.Visible; return; // The date range is too long. case 2: TextBlockNullData.Text = Properties.Resources.TextBlockNullData_Text_ImproperDateRange; TextBlockNullData.Visibility = Visibility.Visible; return; } // end switch-case // The specified data source partially denies access. if (_strikePriceVolumeRowCollection[0][2] == -1) { TextBlockNullData.Text = Properties.Resources.TextBlockNullData_Text_AccessDeniedPartially; TextBlockNullData.Visibility = Visibility.Visible; return; } // end if DataGridStrikePriceVolumeTable.Columns.Suspend(); // For improving performance. InitialiseDataGrid(); UpdateDataGrid(); DataGridStrikePriceVolumeTable.Columns.Resume(); DataGridStrikePriceVolumeTable.RefreshColumns(); // Modify the specified controls' properties when search results are ready. TextBoxSymbol.BorderBrush = Application.Current.Resources["Border"] as SolidColorBrush; TextBoxSymbol.IsEnabled = true; DatePickerStartDate.IsEnabled = true; DatePickerEndDate.IsEnabled = true; ButtonSearch.IsEnabled = true; BusyIndicatorSearchResultArea.IsBusy = false; DataGridStrikePriceVolumeTable.Visibility = Visibility.Visible; ButtonExportToExcel.IsEnabled = true; ButtonPrint.IsEnabled = true; } // end method ShowSearchResults
} // end method ButtonClearSelection_Click // Export to Excel. private void ButtonExportToExcel_Click(object sender, RoutedEventArgs e) { var application = DataGridStrikePriceVolumeTable.ExportToExcel(DataGridStrikePriceVolumeTable.View, _excelExportingOptions).Excel; var workbook = application.Workbooks[0]; application.DataProviderType = ExcelDataProviderType.ByteArray; var saveFileDialog = new SaveFileDialog { FileName = _dataTableTitle, Filter = Properties.Resources.SaveFileDialogueExportToExcel_Filter, FilterIndex = Properties.Settings.Default.ExcelFileFormat }; // Display a dialogue that allows the user to specify a filename to save as an Excel file. if (saveFileDialog.ShowDialog() != true) return; using (var stream = saveFileDialog.OpenFile()) { workbook.Version = saveFileDialog.FilterIndex == 1 ? ExcelVersion.Excel97to2003 : ExcelVersion.Excel2010; // Specify the version of the exported Excel file. workbook.Worksheets[0].AutoFilters.FilterRange = workbook.Worksheets[0].Range["A" + (DataGridStrikePriceVolumeTable.StackedHeaderRows.Count + 1) + ":" + workbook.Worksheets[0].UsedRange.End.AddressLocal]; // Enable filters for the exported range in the worksheet. workbook.Worksheets[0].SetRowHeight(2, 40); // Customise Row 2's height to show day volume headers completely. // Set borders to cells. workbook.Worksheets[0].UsedRange.BorderAround(); workbook.Worksheets[0].UsedRange.BorderInside(); workbook.SaveAs(stream); } // end using Process.Start("Explorer.exe", "/select," + saveFileDialog.FileName); // Start File Explorer and locate the created Excel file. } // end method ButtonExportToExcel_Click
} // end method ButtonExportToExcel_Click // Show the print preview window. private void ButtonPrint_Click(object sender, RoutedEventArgs e) { DataGridStrikePriceVolumeTable.PrintSettings.PrintManagerBase = new PrintManager(DataGridStrikePriceVolumeTable); DataGridStrikePriceVolumeTable.ShowPrintPreview(); } // end method ButtonPrint_Click