public SettingsControl(Action closeAction) { if (closeAction == null) { throw new ArgumentNullException("Close action must be not null"); } _closeAction = closeAction; InitializeComponent(); _window = TMPApplication.ServiceInjector.Instance.GetService <TMPApplication.WpfDialogs.Contracts.IWindowWithDialogs>(); if (_window == null) { throw new ArgumentNullException("Not found Window that implementing IWindowWithDialogs"); } IsReportSettingsEnabled = false; ServerAvailability = false; ServiceAvailability = false; CheckCommand = new DelegateCommand(async(o) => { var dialog = _window.DialogWaitingScreen("Проверка корректности настроек ..."); dialog.Show(); if (await CheckServiceAvailability()) { await InitReportsGroupAsync(); } dialog.Close(); }); ToDefaultCommand = new DelegateCommand((o) => { Properties.Settings.Default.ServerAddress = "10.96.18.16"; Properties.Settings.Default.SiteName = "emcos"; Properties.Settings.Default.ServiceName = "testWebService/Service.asmx"; Properties.Settings.Default.UserName = "******"; Properties.Settings.Default.Password = "******"; Properties.Settings.Default.NetTimeOutInSeconds = 1800; }); SaveCommand = new DelegateCommand((o) => { Properties.Settings.Default.Save(); _closeAction(); }); DataContext = this; var dialog2 = _window.DialogWaitingScreen("Проверка корректности настроек ..."); dialog2.Show(); System.Threading.ThreadPool.QueueUserWorkItem(async o => { if (await CheckServiceAvailability()) { await InitReportsGroupAsync(); //await InitReportsAsync(); await InitDepartamentsAsync(); } dialog2.Close(); }); }
public GetDataControl() { InitializeComponent(); _window = TMPApplication.ServiceInjector.Instance.GetService <TMPApplication.WpfDialogs.Contracts.IWindowWithDialogs>(); if (_window == null) { throw new ArgumentNullException("Not found Window that implementing IWindowWithDialogs"); } CancelCommand = new DelegateCommand( o => { var q = _window.DialogQuestion(Strings.InterruptQuestion); q.Yes = () => { _cts.Cancel(); App.Current.MainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; }; q.Show(); }, o => _cts != null && (_cts.IsCancellationRequested == false)); CloseControlCommand = new DelegateCommand(o => { if (_onClosed != null) { _onClosed(); } }); SaveAllCommand = new DelegateCommand(o => { CommonOpenFileDialog cfd = new CommonOpenFileDialog(); cfd.Title = Strings.SelectFolderToSave; cfd.IsFolderPicker = true; cfd.AddToMostRecentlyUsedList = false; cfd.EnsurePathExists = true; cfd.Multiselect = false; cfd.ShowPlacesList = true; cfd.AllowNonFileSystemItems = true; if (cfd.ShowDialog() == CommonFileDialogResult.Ok) { App.Log("Сохранение всех отчётов в папку"); try { var folder = cfd.FileName; foreach (var item in _list) { if (item.Status == ListPointStatus.Готово) { if (item.ResultType == "txt") { System.IO.File.WriteAllText( System.IO.Path.Combine(folder, item.ResultName + ".csv"), TrimStringValue((string)item.ResultValue), Encoding.UTF8); } else if (item.ResultType == "xls") { byte[] bytes = (byte[])item.ResultValue; if (bytes != null) { System.IO.File.WriteAllBytes( System.IO.Path.Combine(folder, item.ResultName + ".xls"), bytes); } } else { System.IO.File.WriteAllText( System.IO.Path.Combine(folder, item.ResultName + ".txt"), TrimStringValue((string)item.ResultValue), Encoding.UTF8); } } } } catch (Exception ex) { _window.ShowDialogError(ex, Strings.ErrorOnSave); } } }, o => _list != null && _list.All(i => i.ResultValue != null)); SaveAllInSigleFileCommand = new DelegateCommand(o => { bool isStringContent = _list.Where(i => i.Status == ListPointStatus.Готово).All(i => i.ResultType != "xls"); if (isStringContent) { try { StringBuilder sb = new StringBuilder(); foreach (var item in _list) { if (item.Status == ListPointStatus.Готово) { sb.AppendLine(TrimStringValue((string)item.ResultValue)); } } Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.Filter = Strings.DialogCsvFilter; sfd.DefaultExt = ".csv"; sfd.AddExtension = true; sfd.FileName = DateTime.Now.AddMonths(-1).ToString(Strings.MultipleFileNameTemplate); Nullable <bool> result = sfd.ShowDialog(App.Current.MainWindow); if (result == true) { App.Log("Сохранение всех отчётов в один файл"); System.IO.File.WriteAllText(sfd.FileName, sb.ToString(), Encoding.UTF8); } } catch (Exception ex) { _window.ShowDialogError(ex, Strings.ErrorOnSave); } } }, o => _list != null && _list.All(i => i.ResultValue != null) && _list.All(i => i.ResultType != "xls")); SaveCommand = new DelegateCommand(o => { try { ListPointWithResult point = o as ListPointWithResult; if (point != null) { Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.FileName = String.Format(Strings.SingleFileNameTemplate, point.ResultName, DateTime.Now.AddMonths(-1)); sfd.AddExtension = true; if (point.ResultType == "xls") { sfd.Filter = Strings.DialogXlsFilter; sfd.DefaultExt = ".xls"; } else if (point.ResultType == "txt") { sfd.Filter = Strings.DialogCsvFilter; sfd.DefaultExt = ".csv"; } else { sfd.Filter = Strings.DialogTxtFilter; sfd.DefaultExt = ".txt"; } Nullable <bool> result = sfd.ShowDialog(App.Current.MainWindow); if (result == true) { App.Log("Сохранение отчёта"); if (point.ResultType == "xls") { byte[] bytes = (byte[])point.ResultValue; if (bytes != null) { System.IO.File.WriteAllBytes(sfd.FileName, bytes); } } else { System.IO.File.WriteAllText(sfd.FileName, TrimStringValue((string)point.ResultValue), Encoding.UTF8); } } } } catch (Exception ex) { _window.ShowDialogError(ex, Strings.ErrorOnSave); } }); DataContext = this; }