private void ExportCustomer(CustomerSearch customerData) { List <Customer> list = null; string serverPath = null; var task = ServiceProxyFactory.LifeTime(async factory => { var service = factory.Create <CustomerMasterClient>(); CustomersResult result = await service.GetItemsAsync(SessionKey, CompanyId, customerData); if (result.ProcessResult.Result) { list = result.Customers; } }); Task <string> pathTask = GetServerPath(); ProgressDialog.Start(ParentForm, Task.WhenAll(task, pathTask), false, SessionKey); serverPath = pathTask.Result; if (!list.Any()) { ShowWarningDialog(MsgWngNoExportData); return; } if (!Directory.Exists(serverPath)) { serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var filePath = string.Empty; var fileName = $"得意先マスター{DateTime.Today:yyyyMMdd}.csv"; if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath)) { return; } var definition = new CustomerFileDefinition(new DataExpression(ApplicationControl)); definition.ExcludeInvoicePublishField.Ignored = !UsePublishInvoice; definition.ExcludeReminderPublishField.Ignored = !UseReminder; var exporter = definition.CreateExporter(); exporter.UserId = Login.UserId; exporter.UserCode = Login.UserCode; exporter.CompanyId = CompanyId; exporter.CompanyCode = Login.CompanyCode; Func <int[], Dictionary <int, Category> > getter = ids => { Dictionary <int, Category> product = null; ServiceProxyFactory.LifeTime(factory => { var categoryservice = factory.Create <CategoryMasterClient>(); CategoriesResult result = categoryservice.Get(SessionKey, ids); if (result.ProcessResult.Result) { product = result.Categories.ToDictionary(c => c.Id); } }); return(product ?? new Dictionary <int, Category>()); }; definition.CollectCategoryIdField.GetModelsById = getter; definition.LessThanCollectCategoryIdField.GetModelsById = getter; definition.GreaterThanCollectCategoryId3Field.GetModelsById = getter; definition.GreaterThanCollectCategoryId2Field.GetModelsById = getter; definition.GreaterThanCollectCategoryId1Field.GetModelsById = getter; NLogHandler.WriteDebug(this, "得意先マスター 出力開始"); ProgressDialog.Start(ParentForm, (cancel, progress) => { return(exporter.ExportAsync(filePath, list, cancel, progress)); }, true, SessionKey); if (exporter.Exception != null) { NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey); ShowWarningDialog(MsgErrExportError); return; } NLogHandler.WriteDebug(this, "得意先マスター 出力終了"); DispStatusMessage(MsgInfFinishExport); Settings.SavePath <Customer>(Login, filePath); }
private void OutputNewCustomer() { try { List <Customer> list = Importer.GetNewCustomers(); if (!list.Any()) { return; } var serverPath = string.Empty; ProgressDialog.Start(ParentForm, Task.Run(() => { serverPath = Util.GetGeneralSettingServerPathAsync(Login).Result; }), false, SessionKey); if (!Directory.Exists(serverPath)) { serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } var filePath = string.Empty; var fileName = $"新規得意先{DateTime.Today:yyyyMMdd}.csv"; if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath)) { return; } var definition = new CustomerFileDefinition(new DataExpression(ApplicationControl)); var exporter = definition.CreateExporter(); exporter.UserId = Login.UserId; exporter.UserCode = Login.UserCode; exporter.CompanyId = CompanyId; exporter.CompanyCode = Login.CompanyCode; Func <int[], Dictionary <int, Category> > getter = ids => { Dictionary <int, Category> product = null; ServiceProxyFactory.LifeTime(factory => { var categoryservice = factory.Create <CategoryMasterClient>(); CategoriesResult result = categoryservice.Get(SessionKey, ids); if (result.ProcessResult.Result) { product = result.Categories.ToDictionary(c => c.Id); } }); return(product ?? new Dictionary <int, Category>()); }; definition.CollectCategoryIdField.GetModelsById = getter; NLogHandler.WriteDebug(this, "新規得意先 出力開始"); ProgressDialog.Start(ParentForm, (cancel, progress) => { return(exporter.ExportAsync(filePath, list, cancel, progress)); }, true, SessionKey); if (exporter.Exception != null) { NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey); ShowWarningDialog(MsgErrExportError); return; } NLogHandler.WriteDebug(this, "新規得意先 出力終了"); DispStatusMessage(MsgInfFinishExport); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); DispStatusMessage(MsgErrExportError); } }