Exemple #1
0
        public Task <IEnumerable <SectionWithDepartment> > GetAsync(SectionWithDepartmentSearch option, CancellationToken token = default(CancellationToken))
        {
            var query = @"
SELECT        swd.*
            , sc.Code As SectionCode
            , sc.Name As SectionName
            , dp.Code As DepartmentCode
            , dp.Name As DepartmentName
FROM        SectionWithDepartment swd
INNER JOIN  Department dp               ON dp.Id            = swd.DepartmentId
INNER JOIN  Section sc                  ON sc.Id            = swd.SectionId
WHERE       swd.SectionId       = swd.SectionId";

            if (option.SectionId.HasValue)
            {
                query += @"
AND         swd.SectionId       = @SectionId";
            }
            if (option.CompanyId.HasValue)
            {
                query += @"
AND         dp.CompanyId        = @CompanyId";
            }
            if (option.DepartmentId.HasValue)
            {
                query += @"
AND         swd.DepartmentId    = @DepartmentId";
            }
            query += @"
ORDER BY      sc.Code           ASC
            , dp.Code           ASC";

            return(dbHelper.GetItemsAsync <SectionWithDepartment>(query, option, token));
        }
        private async Task <List <SectionWithDepartment> > GetSectionWithDepartmentData()
        {
            List <SectionWithDepartment> list = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <SectionWithDepartmentMasterClient>();
                var sectionWithDepartmentSearch = new SectionWithDepartmentSearch();
                var result = await service.GetItemsAsync(SessionKey, CompanyId, sectionWithDepartmentSearch);

                if (result.ProcessResult.Result)
                {
                    list = result.SectionDepartments;
                }
            });

            return(list ?? new List <SectionWithDepartment>());
        }
Exemple #3
0
 public async Task <IEnumerable <SectionWithDepartment> > GetItems(SectionWithDepartmentSearch option, CancellationToken token)
 => (await sectionWithDepartmentProcessor.GetAsync(option, token)).ToArray();
 public async Task <SectionWithDepartmentsResult> GetItemsAsync(string SessionKey, int CompanyId, SectionWithDepartmentSearch SectionWithDepartmentSearch)
 {
     return(await authorizationProcessor.DoAuthorizeAsync(SessionKey, async token =>
     {
         var result = (await sectionWithDepartmentProcessor.GetAsync(SectionWithDepartmentSearch, token)).ToList();
         return new SectionWithDepartmentsResult
         {
             ProcessResult = new ProcessResult {
                 Result = true
             },
             SectionDepartments = result,
         };
     }, logger));
 }
        private void Import()
        {
            ClearStatusMessage();
            try
            {
                ImportSetting importSetting = null;
                var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.SectionWithDepartment);
                // 取込設定取得
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                importSetting = task.Result;

                var definition = new SectionWithDepartmentFileDefinition(new DataExpression(ApplicationControl));

                definition.SectionCodeField.GetModelsByCode = val =>
                {
                    Dictionary <string, Section> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var section = factory.Create <SectionMasterClient>();
                        var result  = section.GetByCode(SessionKey, CompanyId, val);

                        if (result.ProcessResult.Result)
                        {
                            product = result.Sections
                                      .ToDictionary(c => c.Code);
                        }
                    });
                    return(product ?? new Dictionary <string, Section>());
                };

                definition.DepartmentCodeField.GetModelsByCode = val =>
                {
                    Dictionary <string, Department> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var department = factory.Create <DepartmentMasterClient>();
                        var result     = department.GetByCode(SessionKey, CompanyId, val);

                        if (result.ProcessResult.Result)
                        {
                            product = result.Departments.ToDictionary(d => d.Code);
                        }
                    });
                    return(product ?? new Dictionary <string, Department>());
                };

                definition.DepartmentCodeField.ValidateAdditional = (val, param) =>
                {
                    var reports = new List <WorkingReport>();

                    Func <SortedList <int, SectionWithDepartment[]>, int,
                          Func <SectionWithDepartment[], bool>, bool> dupeCheck
                        = (list, key, condition) =>
                        {
                        if (!list.ContainsKey(key))
                        {
                            return(false);
                        }
                        return(condition?.Invoke(list[key]) ?? false);
                        };

                    List <SectionWithDepartment> dbItems = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var sectionWithDepartment       = factory.Create <SectionWithDepartmentMasterClient>();
                        var sectionWithDepartmentSearch = new SectionWithDepartmentSearch();
                        dbItems = sectionWithDepartment
                                  .GetItems(SessionKey, CompanyId, sectionWithDepartmentSearch)
                                  .SectionDepartments;
                    });
                    var dbDepartmentCheckList = new SortedList <int, SectionWithDepartment[]>(dbItems.GroupBy(x => x.DepartmentId)
                                                                                              .ToDictionary(x => x.Key, x => x.ToArray()));
                    var csvDepartmentCheckList = new SortedList <int, SectionWithDepartment[]>(val.Select(x => x.Value)
                                                                                               .GroupBy(x => x.DepartmentId)
                                                                                               .ToDictionary(x => x.Key, x => x.ToArray()));

                    foreach (var pair in val)
                    {
                        if (dupeCheck(dbDepartmentCheckList,
                                      pair.Value.DepartmentId,
                                      g => g.Any(x => x.SectionId != pair.Value.SectionId)))
                        {
                            reports.Add(new WorkingReport(pair.Key,
                                                          definition.DepartmentCodeField.FieldIndex,
                                                          definition.DepartmentCodeField.FieldName,
                                                          "他の入金部門に登録されているため、インポートできません。"
                                                          ));
                        }

                        if (dupeCheck(csvDepartmentCheckList,
                                      pair.Value.DepartmentId,
                                      g => g.Any(x => x.SectionId != pair.Value.SectionId && pair.Value.DepartmentId != 0)))
                        {
                            reports.Add(new WorkingReport(pair.Key,
                                                          definition.DepartmentCodeField.FieldIndex,
                                                          definition.DepartmentCodeField.FieldName,
                                                          "他の入金部門に登録されているため、インポートできません。"
                                                          ));
                        }
                    }
                    return(reports);
                };

                var importer = definition.CreateImporter(m => new { m.SectionId, m.DepartmentId });
                importer.UserId      = Login.UserId;
                importer.UserCode    = Login.UserCode;
                importer.CompanyId   = CompanyId;
                importer.CompanyCode = Login.CompanyCode;
                importer.LoadAsync   = async() => await GetSectionWithDepartmentData();

                importer.RegisterAsync = async unitOfWork => await RegisterForImportAsync(unitOfWork);

                var importResult = DoImport(importer, importSetting, Clear);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrImportErrorWithoutLog);
            }
        }
 public async Task <IEnumerable <SectionWithDepartment> > GetAsync(SectionWithDepartmentSearch option, CancellationToken token = default(CancellationToken))
 => await sectionWithDepartmentQueryProcessor.GetAsync(option, token);