示例#1
0
        public CustomerGroupImporterWorker(
            LogWriter logger,
            ILogin login,
            TaskSchedule task,
            ApplicationControl appControl,
            DataExpression expression)
            : base(logger, login, task, appControl, expression)
        {
            var difinition = new CustomerGroupFileDefinition(expression);

            difinition.GetCustomerDictionary = val
                                               => Screen.Util.ConvertToDictionary(Screen.Util.GetCustomerList(Login, val), x => x.Code);
            difinition.GetDbCsutomerGroups = ()
                                             => Task.Run(async() => await Screen.Util.GetCustomerGroupListAsync(Login)).Result;
            var importer = difinition.CreateImporter(x => new { x.ParentCustomerId, x.ChildCustomerId });

            importer.UserId      = Login.UserId;
            importer.UserCode    = Login.UserCode;
            importer.CompanyId   = Login.CompanyId;
            importer.CompanyCode = Login.CompanyCode;
            importer.LoadAsync   = async() => await Screen.Util.GetCustomerGroupListAsync(Login);

            importer.RegisterAsync = async unitOfWork => await Screen.Util.ImportCustomerGroupAsync(Login, unitOfWork);

            importer.ErrorLogPath = logger.GetOutputPath();
            Importer = importer;
        }
        /// <summary>インポート処理</summary>
        /// <param name="source"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task <ImportResult> ImportAsync(MasterImportSource source, CancellationToken token = default(CancellationToken))
        {
            var mode     = (ImportMethod)source.ImportMethod;
            var encoding = Encoding.GetEncoding(source.EncodingCodePage);
            var csv      = encoding.GetString(source.Data);

            var companyTask = companyProcessor.GetAsync(new CompanySearch {
                Id = source.CompanyId,
            }, token);
            var loginUsersTask = loginUserProcessor.GetAsync(new LoginUserSearch {
                CompanyId = source.CompanyId,
            }, token);
            var appConTask   = applicationControlProcessor.GetAsync(source.CompanyId, token);
            var customerTask = customerProcessor.GetAsync(new CustomerSearch {
                CompanyId = source.CompanyId,
            }, token);
            var customerGroupTask = customerGroupProcessor.GetAsync(new CustomerGroupSearch {
                CompanyId = source.CompanyId,
            }, token);

            await Task.WhenAll(companyTask, loginUsersTask, appConTask, customerTask, customerGroupTask);

            var company             = companyTask.Result.First();
            var loginUserDictionary = loginUsersTask.Result.ToDictionary(x => x.Code);
            var loginUser           = loginUsersTask.Result.First(x => x.Id == source.LoginUserId);
            var appCon             = appConTask.Result;
            var customerDictionary = customerTask.Result.ToDictionary(x => x.Code);
            var customerGroups     = customerGroupTask.Result.ToList();

            var definition = new CustomerGroupFileDefinition(new DataExpression(appCon));
            var parser     = new CsvParser {
                Encoding      = encoding,
                StreamCreator = new PlainTextMemoryStreamCreator(),
            };

            definition.GetCustomerDictionary = val => customerDictionary;
            definition.GetDbCsutomerGroups   = () => customerGroups;

            var importer = definition.CreateImporter(x => new { x.ParentCustomerId, x.ChildCustomerId }, parser);

            importer.UserId      = source.LoginUserId;
            importer.UserCode    = loginUser.Code;
            importer.CompanyId   = source.CompanyId;
            importer.CompanyCode = company.Code;

            importer.LoadAsync = () => customerGroupProcessor.GetAsync(new CustomerGroupSearch {
                CompanyId = source.CompanyId,
            }, token);
            importer.RegisterAsync = x => customerGroupProcessor.ImportAsync(x.New, x.Dirty, x.Removed, token);

            var result = await importer.ImportAsync(csv, mode, token, null);

            result.Logs = importer.GetErrorLogs();

            return(result);
        }
示例#3
0
        private void Import()
        {
            ClearStatusMessage();
            try
            {
                var customerGroupList = new List <CustomerGroup>();

                ImportSetting importSetting = null;
                var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.CustomerGroup);
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                importSetting = task.Result;

                var definition = new CustomerGroupFileDefinition(new DataExpression(ApplicationControl));
                definition.GetCustomerDictionary = val => Util.ConvertToDictionary(Util.GetCustomerList(Login, val), x => x.Code);
                definition.GetDbCsutomerGroups   = () => Task.Run(async() => await LoadListAsync()).Result;

                var importer = definition.CreateImporter(m => new { m.ParentCustomerId, m.ChildCustomerId });
                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, ClearControlValues);
                if (!importResult)
                {
                    return;
                }
                Modified = false;
                Task <List <CustomerGroup> > loadTask = LoadListAsync();
                ProgressDialog.Start(ParentForm, loadTask, false, SessionKey);
                customerGroupList.AddRange(loadTask.Result);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrImportErrorWithoutLog);
            }
        }
示例#4
0
        private void Export()
        {
            ClearStatusMessage();
            try
            {
                List <CustomerGroup> listCustomerGroup = null;
                string serverPath = null;
                var    task       = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service = factory.Create <GeneralSettingMasterClient>();
                    GeneralSettingResult result = await service.GetByCodeAsync(
                        SessionKey, CompanyId, "サーバパス");
                    if (result.ProcessResult.Result)
                    {
                        serverPath = result.GeneralSetting?.Value;
                    }
                });

                Task <List <CustomerGroup> > printDataTask = GetPrintDataAsync();
                ProgressDialog.Start(ParentForm, Task.WhenAll(task, printDataTask), false, SessionKey);

                listCustomerGroup = printDataTask.Result;

                if (!listCustomerGroup.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 CustomerGroupFileDefinition(new DataExpression(ApplicationControl));
                var exporter   = definition.CreateExporter();
                exporter.UserId      = Login.UserId;
                exporter.UserCode    = Login.UserCode;
                exporter.CompanyId   = CompanyId;
                exporter.CompanyCode = Login.CompanyCode;
                definition.ParentCustomerField.GetModelsById = ids =>
                {
                    Dictionary <int, Customer> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var customer           = factory.Create <CustomerMasterClient>();
                        CustomersResult result = customer.Get(SessionKey, ids);
                        if (result.ProcessResult.Result)
                        {
                            product = result.Customers.ToDictionary(c => c.Id);
                        }
                    });
                    return(product ?? new Dictionary <int, Customer>());
                };
                definition.ChildCustomerField.GetModelsById = definition.ParentCustomerField.GetModelsById;
                ProgressDialog.Start(ParentForm, (cancel, progress) =>
                {
                    return(exporter.ExportAsync(filePath, listCustomerGroup, cancel, progress));
                }, true, SessionKey);

                if (exporter.Exception != null)
                {
                    NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey);
                    ShowWarningDialog(MsgErrExportError);
                    return;
                }

                DispStatusMessage(MsgInfFinishExport);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                DispStatusMessage(MsgErrExportError);
            }
        }