public WindowSqlQueryView(CustomReports.ItemReport itemReport) { InitializeComponent(); if (itemReport == null) { MessageBox.Show(this, "ItemReport is null", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } TextBoxQuery.Text = itemReport.Query; Title = "Редактирование запроса для: '" + itemReport.Name + "'"; TextBlockAbout.Text = "Формируемый отчет будет выгружать данные из БД в соответствии с запросом, без дополнительной обработки." + Environment.NewLine + "Для удобства пользователей отчета называйте поля отчета понятными именами, они будут использоваться как заголовки." + Environment.NewLine + Environment.NewLine + "В тексте запроса можно использовать два параметра - @dateBegin и @dateEnd" + Environment.NewLine + "Вместо этих параметров будут подставляться даты, за которые необходимо выгрузить данные"; Closed += (s, e) => { string queryEntered = TextBoxQuery.Text; itemReport.Query = queryEntered; }; Loaded += (s, e) => { using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("CustomReportsManager.sql.xshd")) { using (var reader = new System.Xml.XmlTextReader(stream)) { TextBoxQuery.SyntaxHighlighting = ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader, ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance); } } TextBoxQuery.Focus(); }; }
public WindowDetails(string title, string text, Window owner, CustomReports.ItemReport itemReport = null) { InitializeComponent(); Title = title; TextBoxMain.Text = text; Owner = owner; if (itemReport != null) { CreateReport(itemReport); ButtonClose.IsEnabled = false; Cursor = Cursors.Wait; } }
private void CreateReport(CustomReports.ItemReport itemReport) { BackgroundWorker bw = new BackgroundWorker(); bw.WorkerReportsProgress = true; bw.ProgressChanged += (s, e) => { if (e.UserState != null) { TextBoxMain.Text += e.UserState.ToString() + Environment.NewLine; TextBoxMain.ScrollToEnd(); } }; bw.DoWork += (s, e) => { CustomReports.Program.CreateReport(itemReport); }; bw.RunWorkerCompleted += (s, e) => { if (e.Error != null) { MessageBox.Show(this, e.Error.Message + Environment.NewLine + e.Error.StackTrace, "", MessageBoxButton.OK, MessageBoxImage.Error); } else { MessageBox.Show(this, "Завершено", "", MessageBoxButton.OK, MessageBoxImage.Information); } ButtonClose.IsEnabled = true; Cursor = Cursors.Arrow; if (!string.IsNullOrEmpty(itemReport.FileResult)) { try { string argument = "/select, \"" + itemReport.FileResult + "\""; Process.Start("explorer.exe", argument); } catch (Exception exc) { MessageBox.Show(this, exc.Message, string.Empty, MessageBoxButton.OK, MessageBoxImage.Error); } } }; CustomReports.Logging.bw = bw; bw.RunWorkerAsync(); }
private void ButtonCreate_Click(object sender, RoutedEventArgs e) { string errorMessage = string.Empty; if (DataGridReports.SelectedItem == null) { errorMessage = "Не выбран отчет для формирования" + Environment.NewLine; } if (string.IsNullOrEmpty(((DataGridReports.SelectedItem as CustomReports.ItemReport).SaveFormat))) { errorMessage += "Не задан формат выгрузки" + Environment.NewLine; } if (CustomReports.Configuration.Instance.DateBegin > CustomReports.Configuration.Instance.DateEnd) { errorMessage += "Дата окончания не быть может быть меньше даты начала"; } if (!string.IsNullOrEmpty(errorMessage)) { MessageBox.Show(this, errorMessage, "", MessageBoxButton.OK, MessageBoxImage.Warning); return; } CustomReports.ItemReport itemReport = DataGridReports.SelectedItem as CustomReports.ItemReport; itemReport.SetPeriod( CustomReports.Configuration.Instance.DateBegin, CustomReports.Configuration.Instance.DateEnd); string title = itemReport.Name + ", формирование за период с " + itemReport.DateBegin.ToShortDateString() + " по " + itemReport.DateEnd.ToShortDateString(); WindowDetails windowDetails = new WindowDetails(title, string.Empty, this, itemReport); windowDetails.ShowDialog(); }
public WindowRecipientsListView(CustomReports.ItemReport itemReport, bool isAdminAddress = false) { InitializeComponent(); string addresses = string.Empty; if (isAdminAddress) { addresses = CustomReports.Configuration.Instance.MailAdminAddress; Title = "Редактирования списка получателей системных уведомлений"; } else if (itemReport == null) { MessageBox.Show(this, "ItemReport is null", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } else { addresses = itemReport.Recipients; Title = "Редактирование списка получателей для: '" + itemReport.Name + "'"; } string[] splitted = CustomReports.Configuration.GetSplittedAddresses(addresses); foreach (string address in splitted) { Addresses.Add(new MailAddress(address)); } DataGridAddresses.DataContext = this; Closed += (s, e) => { List <MailAddress> emptyOrWrong = new List <MailAddress>(); foreach (MailAddress item in Addresses) { if (string.IsNullOrEmpty(item.Address)) { emptyOrWrong.Add(item); continue; } try { System.Net.Mail.MailAddress mailAddress = new System.Net.Mail.MailAddress(item.Address); } catch (Exception) { emptyOrWrong.Add(item); } } foreach (MailAddress item in emptyOrWrong) { Addresses.Remove(item); } string addressesEdited = string.Join(" | ", Addresses); if (isAdminAddress) { CustomReports.Configuration.Instance.MailAdminAddress = addressesEdited; } else { itemReport.Recipients = addressesEdited; } }; }
private void ButtonItemReport_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; CustomReports.ItemReport itemReport = button.DataContext as CustomReports.ItemReport; if (itemReport == null) { MessageBox.Show(this, "ItemReport is null", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } string tag = button.Tag as string; if (string.IsNullOrEmpty(tag)) { MessageBox.Show(this, "Button.Tag is null", "", MessageBoxButton.OK, MessageBoxImage.Error); return; } Window windowToShow = null; if (tag.Equals("CleanFolderToSave")) { itemReport.FolderToSave = string.Empty; } else if (tag.Equals("EditFolderToSave")) { CommonOpenFileDialog dlg = new CommonOpenFileDialog { Title = "Выбор пути сохранения", IsFolderPicker = true, AddToMostRecentlyUsedList = false, AllowNonFileSystemItems = false, EnsureFileExists = true, EnsurePathExists = true, EnsureReadOnly = false, EnsureValidNames = true, Multiselect = false, ShowPlacesList = true }; if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { itemReport.FolderToSave = dlg.FileName; } } else if (tag.Equals("EditQuery")) { windowToShow = new WindowSqlQueryView(itemReport); } else if (tag.Equals("EditRecipients")) { windowToShow = new WindowRecipientsListView(itemReport); } else { MessageBox.Show(this, "Button.Tag unknown: " + tag, "", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (windowToShow != null) { windowToShow.Owner = this; windowToShow.ShowDialog(); } }