Exemplo n.º 1
0
        private void PB0701_Load(object sender, EventArgs e)
        {
            SetScreenName();
            try
            {
                var loadTask = new List <Task>();

                if (ApplicationControl == null)
                {
                    loadTask.Add(LoadApplicationControlAsync());
                }

                loadTask.Add(LoadControlColorAsync());

                if (Company == null)
                {
                    loadTask.Add(LoadCompanyAsync());
                }
                if (Authorities == null)
                {
                    loadTask.Add(LoadFunctionAuthorities(MasterImport, MasterExport));
                }
                var loadGridTask = LoadGridAsync();
                loadTask.Add(loadGridTask);
                ProgressDialog.Start(ParentForm, Task.WhenAll(loadTask), false, SessionKey);
                AccountTitleList.AddRange(loadGridTask.Result);

                CreateGridTemplate();
                Clear();
                grdAccountTitleMaster.DataSource = new BindingSource(AccountTitleList, null);
                SetFormat();
                Modified = false;
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }