private async Task clearMedia() { MessageBoxResult result = MessageBox.Show("Are you sure you want to clear all Media from the database?", "Clear All Media", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); if (result == MessageBoxResult.No) { return; } List <BaseMetadata> media; using (MetadataDbCommands mediaCommands = new MetadataDbCommands()) { media = mediaCommands.getAllMetadata(); } List <MediaFileItem> items = new List <MediaFileItem>(); foreach (BaseMetadata m in media) { items.Add(MediaFileItem.Factory.create(m.Location)); } ExportProgressViewModel export = new ExportProgressViewModel(MediaFileWatcher.Instance.MediaFileState); CancellableOperationProgressView exportView = new CancellableOperationProgressView(); exportView.DataContext = export; exportView.ShowDialog(); await export.exportAsync(items); NrMedia = 0; }
public void SetUp() { _closeExecuted = false; _repository = new Mock <IRepository>(); InitializeSaveDataAsync(false, OnCompleteEventArgs.CompleteResult.Ok, 50); _loader = new Mock <ILoader>(); _loader.Setup(m => m.GetZippedRepository(It.Is <string>(f => f == FileName))). Returns(_repository.Object). Verifiable(); _viewModel = new ExportProgressViewModel(_loader.Object); _messenger = new Messenger(); _messenger.Register <ViewMessage>(this, Views.Views.ExportProgress, message => { if (message.Action == ViewAction.Close) { _closeExecuted = true; } }); }
private void ExecuteExportCommand() { DataTable dt = new DataTable("机票总表"); KeyValuePair <string, Type>[] headArray = new KeyValuePair <string, Type>[] { new KeyValuePair <string, Type>("票号", typeof(string)), new KeyValuePair <string, Type>("PNR", typeof(string)), new KeyValuePair <string, Type>("舱位价", typeof(decimal)), new KeyValuePair <string, Type>("机建费", typeof(decimal)), new KeyValuePair <string, Type>("燃油费", typeof(decimal)), new KeyValuePair <string, Type>("返点", typeof(decimal)), new KeyValuePair <string, Type>("佣金", typeof(decimal)), new KeyValuePair <string, Type>("交易时间", typeof(DateTime)), new KeyValuePair <string, Type>("订单金额", typeof(string)), new KeyValuePair <string, Type>("支付方式", typeof(string)), new KeyValuePair <string, Type>("机票状态", typeof(string)), new KeyValuePair <string, Type>("起飞时间", typeof(string)), new KeyValuePair <string, Type>("航班号", typeof(string)), new KeyValuePair <string, Type>("航程", typeof(string)), new KeyValuePair <string, Type>("航位", typeof(string)), new KeyValuePair <string, Type>("乘客姓名", typeof(string)), //new KeyValuePair<string,Type>("行程单号",typeof(string)), new KeyValuePair <string, Type>("交易号", typeof(string)), new KeyValuePair <string, Type>("原订单号", typeof(string)), new KeyValuePair <string, Type>("售后订单号", typeof(string)) }; foreach (var item in headArray) { dt.Columns.Add(item.Key, item.Value); } SaveFileDialog dlg = new SaveFileDialog(); dlg.FileName = "机票总表"; dlg.DefaultExt = ".xls"; dlg.Filter = "Excel documents (.xls)|*.xls"; var result = dlg.ShowDialog(); if (result == true) { try { string filename = dlg.FileName; int? orderStatus = GetOrderState(); isAbort = false; ExportProgressViewModel vm = new ExportProgressViewModel(AbortExport); var action = new Action(() => { int totalCount = GetTotalCount(OrderId, PNRCode, null, PassengerName, createTime, endCreateTime); int pageCount = (int)Math.Ceiling((double)totalCount / PageSize); vm.Maximum = pageCount; for (int i = 0; i < pageCount; i++) { if (isAbort) { break; } vm.Message = "下载数据" + i; vm.Value = i; DataPack <ReponseTicketSum> data = GetTicketInfo(OrderId, PNRCode, TicketNum, PassengerName, createTime, endCreateTime, (i) * PageSize, PageSize, SelectedTicketStatus); AddData(dt, data.List); } vm.Message = "导出Excel"; ExcelHelper.RenderToExcel(dt, filename); vm.Value++; vm.IsClose = true; if (isAbort) { UIManager.ShowMessage("导出终止"); } else { UIManager.ShowMessage("导出成功"); } }); Task.Factory.StartNew(action); UIManager.ShowExportProgress(vm); } catch (Exception ex) { UIManager.ShowErr(ex); } } }