private void ImportAccountTitle() { try { ClearStatusMessage(); ImportSetting importSetting = null; // 取込設定取得 var task = Util.GetMasterImportSettingAsync(Login, ImportFileType.AccountTitle); ProgressDialog.Start(ParentForm, task, false, SessionKey); importSetting = task.Result; var definition = new AccountTitleFileDefinition(new DataExpression(ApplicationControl)); definition.AccountTitleCodeField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); if (((ImportMethod)param) != ImportMethod.Replace) { return(reports); } MasterDatasResult categoryResult = null; MasterDatasResult customerResult = null; MasterDatasResult debitBillingResult = null; MasterDatasResult creditBillingResult = null; ServiceProxyFactory.LifeTime(factory => { var accountTitle = factory.Create <AccountTitleMasterClient>(); var codes = val.Values.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).Distinct().ToArray(); categoryResult = accountTitle.GetImportItemsForCategory(SessionKey, CompanyId, codes); customerResult = accountTitle.GetImportItemsForCustomerDiscount(SessionKey, CompanyId, codes); debitBillingResult = accountTitle.GetImportItemsForDebitBilling(SessionKey, CompanyId, codes); creditBillingResult = accountTitle.GetImportItemsForCreditBilling(SessionKey, CompanyId, codes); }); foreach (MasterData ca in categoryResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.AccountTitleCodeField.FieldIndex, FieldName = definition.AccountTitleCodeField.FieldName, Message = $"区分マスターに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } foreach (MasterData ca in customerResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.AccountTitleCodeField.FieldIndex, FieldName = definition.AccountTitleCodeField.FieldName, Message = $"得意先マスター歩引設定に存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } foreach (MasterData ca in debitBillingResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.AccountTitleCodeField.FieldIndex, FieldName = definition.AccountTitleCodeField.FieldName, Message = $"請求データに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } foreach (MasterData ca in creditBillingResult.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.AccountTitleCodeField.FieldIndex, FieldName = definition.AccountTitleCodeField.FieldName, Message = $"請求データに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } return(reports); }; var importer = definition.CreateImporter(m => m.Code); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = CompanyId; importer.CompanyCode = Login.CompanyCode; importer.LoadAsync = async() => await LoadGridAsync(); importer.RegisterAsync = async unitOfWork => await RegisterForImportAsync(unitOfWork); System.Action clear = () => { AccountTitleList.Clear(); var loadTask = LoadGridAsync(); ProgressDialog.Start(ParentForm, loadTask, false, SessionKey); AccountTitleList.AddRange(loadTask.Result); grdAccountTitleMaster.DataSource = new BindingSource(AccountTitleList, null); }; var importResult = DoImport(importer, importSetting, clear); if (!importResult) { return; } txtCode.Clear(); txtName.Clear(); txtContraAccountCode.Clear(); txtContraAccountName.Clear(); txtContraAccountSubCode.Clear(); AccountTitleId = 0; txtCode.Enabled = true; this.ActiveControl = txtCode; BaseContext.SetFunction03Enabled(false); Modified = false; } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); ShowWarningDialog(MsgErrImportErrorWithoutLog); } }
private void Import() { ClearStatusMessage(); try { ImportSetting importSetting = null; var task = Util.GetMasterImportSettingAsync(Login, ImportFileType.Staff); ProgressDialog.Start(ParentForm, task, false, SessionKey); importSetting = task.Result; if (importSetting == null) { return; } var definition = new StaffFileDefinition(new DataExpression(ApplicationControl)); definition.MailField.Required = UseDistribution; definition.DepartmentIdField.GetModelsByCode = val => { Dictionary <string, Department> product = null; ServiceProxyFactory.LifeTime(factory => { var departmentMaster = factory.Create <DepartmentMasterClient>(); DepartmentsResult result = departmentMaster.GetByCode(SessionKey, CompanyId, val); if (result.ProcessResult.Result) { product = result.Departments.ToDictionary(c => c.Code); } }); return(product ?? new Dictionary <string, Department>()); }; //その他 definition.StaffCodeField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); if (((ImportMethod)param) != ImportMethod.Replace) { return(reports); } var codes = val.Values.Where(x => !string.IsNullOrEmpty(x.Code)).Select(x => x.Code).Distinct().ToArray(); MasterDatasResult resultlogin = null; ServiceProxyFactory.LifeTime(factory => { var staffMaster = factory.Create <StaffMasterClient>(); resultlogin = staffMaster.GetImportItemsLoginUser(SessionKey, CompanyId, codes); }); foreach (MasterData ca in resultlogin.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.StaffCodeField.FieldIndex, FieldName = definition.StaffCodeField.FieldName, Message = $"ログインユーザーマスターに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } MasterDatasResult resultcustomer = null; MasterDatasResult resultbilling = null; ServiceProxyFactory.LifeTime(factory => { var staffMaster = factory.Create <StaffMasterClient>(); resultcustomer = staffMaster.GetImportItemsCustomer(SessionKey, CompanyId, codes); resultbilling = staffMaster.GetImportItemsBilling(SessionKey, CompanyId, codes); }); foreach (MasterData ca in resultcustomer.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.StaffCodeField.FieldIndex, FieldName = definition.StaffCodeField.FieldName, Message = $"得意先マスターに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } foreach (MasterData ca in resultbilling.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.StaffCodeField.FieldIndex, FieldName = definition.StaffCodeField.FieldName, Message = $"請求データに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } return(reports); }; var importer = definition.CreateImporter(m => m.Code); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = 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; } StaffProgress.Clear(); Task <List <Staff> > loadTask = LoadListAsync(); ProgressDialog.Start(ParentForm, loadTask, false, SessionKey); StaffProgress.AddRange(loadTask.Result); grdStaff.DataSource = new BindingSource(StaffProgress, null); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); ShowWarningDialog(MsgErrImportErrorWithoutLog); } }
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); } }
private void Import() { ClearStatusMessage(); try { ImportSetting importSetting = null; var task = Util.GetMasterImportSettingAsync(Login, ImportFileType.Section); ProgressDialog.Start(ParentForm, task, false, SessionKey); importSetting = task.Result; var definition = new SectionFileDefinition(new DataExpression(ApplicationControl)); definition.SectionCodeField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); if (((ImportMethod)param) != ImportMethod.Replace) { return(reports); } if (val.Any(a => a.Value.Code == null)) { return(reports); } if (val.Select(x => x.Value.Code).Distinct().Count() != val.Values.Count) { return(reports); } ServiceProxyFactory.LifeTime(factory => { var section = factory.Create <SectionMasterClient>(); MasterDatasResult resBankAccount = section.GetImportItemsForBankAccount( SessionKey, CompanyId, val.Values.Select(x => x.Code).ToArray()); foreach (MasterData ca in resBankAccount.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.SectionCodeField.FieldIndex, FieldName = definition.SectionCodeField.FieldName, Message = $"銀行口座マスターに存在する{ca.Code}:{ca.Name}が存在しないため、インポートできません。", }); } MasterDatasResult resSectionWithDept = section.GetImportItemsForSectionWithDepartment( SessionKey, CompanyId, val.Values.Select(x => x.Code).ToArray()); foreach (MasterData item in resSectionWithDept.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.SectionCodeField.FieldIndex, FieldName = definition.SectionCodeField.FieldName, Message = $"入金・請求部門対応マスターに存在する{item.Code}:{item.Name}が存在しないため、インポートできません。", }); } MasterDatasResult resSectionWithLoginUser = section.GetImportItemsForSectionWithLoginUser( SessionKey, CompanyId, val.Values.Select(l => l.Code).ToArray()); foreach (MasterData item in resSectionWithLoginUser.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.SectionCodeField.FieldIndex, FieldName = definition.SectionCodeField.FieldName, Message = $"入金部門・担当者対応マスターに存在する{item.Code}:{item.Name}が存在しないため、インポートできません。", }); } MasterDatasResult resReceipt = section.GetImportItemsForReceipt( SessionKey, CompanyId, val.Values.Select(l => l.Code).ToArray()); foreach (MasterData item in resReceipt.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.SectionCodeField.FieldIndex, FieldName = definition.SectionCodeField.FieldName, Message = $"入金データに存在する{item.Code}:{item.Name}が存在しないため、インポートできません。", }); } MasterDatasResult resNetting = section.GetImportItemsForNetting( SessionKey, CompanyId, val.Values.Select(l => l.Code).ToArray()); foreach (MasterData item in resNetting.MasterDatas.Where(p => !val.Any(a => a.Value.Code == p.Code))) { reports.Add(new WorkingReport { LineNo = null, FieldNo = definition.SectionCodeField.FieldIndex, FieldName = definition.SectionCodeField.FieldName, Message = $"相殺データに存在する{item.Code}:{item.Name}が存在しないため、インポートできません。", }); } }); return(reports); }; definition.PayerCodeLeftField.ValidateAdditional = (val, param) => { var reports = new List <WorkingReport>(); var uniqueKeys = new Dictionary <string, int>(); var duplicatedLines = new List <int>(); SectionsResult res = null; ServiceProxyFactory.LifeTime(factory => { var section = factory.Create <SectionMasterClient>(); res = section.GetImportItemsForSection( SessionKey, CompanyId, val.Values.Select(l => l.PayerCodeLeft + l.PayerCodeRight).ToArray()); }); foreach (var pair in val) { var branchCodeIsEmpty = false; var accountNumberIsEmpty = false; if (pair.Value.PayerCodeLeft == "") { branchCodeIsEmpty = true; } if (pair.Value.PayerCodeRight == "") { accountNumberIsEmpty = true; } if ((branchCodeIsEmpty && !accountNumberIsEmpty) || (!branchCodeIsEmpty && accountNumberIsEmpty)) { StringFieldDefinition <Section> field = null; var value = string.Empty; if (branchCodeIsEmpty) { field = definition.PayerCodeLeftField; value = pair.Value.PayerCodeLeft; } else { field = definition.PayerCodeRightField; value = pair.Value.PayerCodeRight; } reports.Add(new WorkingReport { LineNo = pair.Key, FieldNo = field.FieldIndex, FieldName = field.FieldName, Message = "仮想支店コード・仮想口座番号のどちらかが未入力のため、インポートできません。", }); } if (res.Sections.Count != 0) { if (((ImportMethod)param) == ImportMethod.InsertOnly) { reports.Add(new WorkingReport { LineNo = pair.Key, FieldNo = definition.PayerCodeLeftField.FieldIndex, FieldName = "仮想支店コード、仮想口座番号", Message = "既に登録されている仮想支店コード、仮想口座番号のため、インポートできません。", }); } else { if (res.Sections.Any(p => p.Code != pair.Value.Code && p.PayerCode == pair.Value.PayerCodeLeft + pair.Value.PayerCodeRight && p.PayerCode != "")) { reports.Add(new WorkingReport { LineNo = pair.Key, FieldNo = definition.PayerCodeLeftField.FieldIndex, FieldName = "仮想支店コード、仮想口座番号", Message = "既に登録されている仮想支店コード、仮想口座番号のため、インポートできません。", }); } } } string key = pair.Value.PayerCodeLeft + pair.Value.PayerCodeRight; if (key.Length == 10) { if (string.IsNullOrEmpty(key)) { continue; } if (uniqueKeys.ContainsKey(key)) { var duplicated = uniqueKeys[key]; if (uniqueKeys.ContainsKey(key)) { duplicatedLines.Add(duplicated); } duplicatedLines.Add(pair.Key); } else { uniqueKeys.Add(key, pair.Key); } } } duplicatedLines.ForEach(lineNo => { reports.Add(new WorkingReport() // キー重複 { LineNo = lineNo, FieldNo = definition.PayerCodeLeftField.FieldIndex, FieldName = "仮想支店コード、仮想口座番号", Message = "仮想支店コード、仮想口座番号が重複しているため、インポートできません。", Value = val[lineNo].PayerCodeLeft + val[lineNo].PayerCodeRight, }); }); return(reports); }; var importer = definition.CreateImporter(m => new { m.Code }); importer.UserId = Login.UserId; importer.UserCode = Login.UserCode; importer.CompanyId = CompanyId; importer.CompanyCode = Login.CompanyCode; importer.LoadAsync = async() => await LoadGridAsync(); importer.RegisterAsync = async unitOfWork => await RegisterForImportAsync(unitOfWork); var importResult = DoImport(importer, importSetting); if (!importResult) { return; } Clears(); SectionList.Clear(); Task <List <Section> > loadTask = LoadGridAsync(); ProgressDialog.Start(ParentForm, loadTask, false, SessionKey); SectionList.AddRange(loadTask.Result); grdSectionMaster.DataSource = new BindingSource(SectionList, null); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); ShowWarningDialog(MsgErrImportErrorWithoutLog); } }