private void ExportData() { ClearStatusMessage(); List <Currency> list = null; string serverPath = null; try { var loadTask = LoadListAsync(); var pathTask = ServiceProxyFactory.LifeTime(async factory => { var service = factory.Create <GeneralSettingMasterClient>(); var result = await service.GetByCodeAsync( SessionKey, CompanyId, "サーバパス"); if (result.ProcessResult.Result) { serverPath = result.GeneralSetting?.Value; } if (!Directory.Exists(serverPath)) { serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } }); ProgressDialog.Start(ParentForm, Task.WhenAll(loadTask, pathTask), false, SessionKey); list = loadTask.Result; if (!list.Any()) { ShowWarningDialog(MsgWngNoExportData); return; } var filePath = string.Empty; var fileName = $"通貨マスター{DateTime.Today:yyyyMMdd}.csv"; if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath)) { return; } var definition = new CurrencyFileDefinition(new DataExpression(ApplicationControl)); definition.CurrencyToleranceField.Format = value => value.ToString("G29"); var exporter = definition.CreateExporter(); exporter.UserId = Login.UserId; exporter.UserCode = Login.UserCode; exporter.CompanyId = CompanyId; exporter.CompanyCode = Login.CompanyCode; 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; } DispStatusMessage(MsgInfFinishExport); Settings.SavePath <Receipt>(Login, filePath); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); DispStatusMessage(MsgErrExportError); } }
private void Import() { ClearStatusMessage(); try { ImportSetting importSetting = null; var task = Util.GetMasterImportSettingAsync(Login, ImportFileType.Currency); // 取込設定取得 ProgressDialog.Start(ParentForm, task, false, SessionKey); importSetting = task.Result; var definition = new CurrencyFileDefinition(new DataExpression(ApplicationControl)); //その他 definition.CurrencyCodeField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); if (((ImportMethod)param) != ImportMethod.Replace) { return(reports); } MasterDatasResult billResult = null; MasterDatasResult receiptResult = null; MasterDatasResult nettingResult = null; ServiceProxyFactory.LifeTime(factory => { var currencyMaster = factory.Create <CurrencyMasterClient>(); var codes = val.Values.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).Distinct().ToArray(); billResult = currencyMaster.GetImportItemsBilling(SessionKey, CompanyId, codes); receiptResult = currencyMaster.GetImportItemsReceipt(SessionKey, CompanyId, codes); nettingResult = currencyMaster.GetImportItemsNetting(SessionKey, CompanyId, codes); }); foreach (MasterData ca in billResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.CurrencyCodeField.FieldIndex, FieldName = definition.CurrencyCodeField.FieldName, Message = $"請求データに存在する{ca.Code}が存在しないため、インポートできません。", }); } foreach (var ca in receiptResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.CurrencyCodeField.FieldIndex, FieldName = definition.CurrencyCodeField.FieldName, Message = $"入金データに存在する{ca.Code}が存在しないため、インポートできません。", }); } foreach (var ca in nettingResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.CurrencyCodeField.FieldIndex, FieldName = definition.CurrencyCodeField.FieldName, Message = $"入金予定相殺データに存在する{ca.Code}が存在しないため、インポートできません。", }); } return(reports); }; definition.CurrencyToleranceField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); foreach (var pair in val) { if (pair.Value.Precision < 0) { continue; } var significant = (pair.Value.Tolerance * Amount.Pow10(pair.Value.Precision)); if (Math.Floor(significant) != significant) { reports.Add(new WorkingReport { LineNo = pair.Key, FieldNo = definition.CurrencyToleranceField.FieldIndex, FieldName = definition.CurrencyToleranceField.FieldName, Message = $"手数料誤差金額は小数点以下{pair.Value.Precision}桁までとなるよう入力してください。", }); } } return(reports); }; var importer = definition.CreateImporter(m => m.Code); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = Login.CompanyId; importer.CompanyCode = Login.CompanyCode; importer.LoadAsync = async() => await LoadListAsync(); importer.RegisterAsync = async unitOfWork => await RegisterForImportAsync(unitOfWork); var importResult = DoImport(importer, importSetting, Clear); if (!importResult) { return; } CurrencyList.Clear(); var loadListTask = LoadListAsync(); ProgressDialog.Start(ParentForm, loadListTask, false, SessionKey); CurrencyList.AddRange(loadListTask.Result); grdCurrencyMaster.DataSource = new BindingSource(CurrencyList, null); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); ShowWarningDialog(MsgErrImportErrorWithoutLog); } }