Ejemplo n.º 1
0
        //From~ToテキストボックスのValidated
        private void GetDataFromValidate(VOneTextControl code, VOneDispLabelControl name, ref int?Id)
        {
            var secGetByCode = new List <Section>();

            var task = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service           = factory.Create <SectionMasterClient>();
                SectionsResult result = await service.GetByCodeAsync(SessionKey, CompanyId, new string[] { code.Text });
                if (result.ProcessResult.Result && result.Sections.Any())
                {
                    secGetByCode = result.Sections;
                }
            });

            ProgressDialog.Start(ParentForm, task, false, SessionKey);

            if (secGetByCode.Any())
            {
                SetSectionData(secGetByCode[0], code, name, ref Id);
                ClearStatusMessage();
            }
            else
            {
                ShowWarningDialog(MsgWngMasterNotExist, "入金部門", code.Text);
                code.Focus();
                name.Clear();
                code.Clear();
            }

            Modified = true;
        }
Ejemplo n.º 2
0
        public async Task <List <Section> > LoadGridAsync()
        {
            var            result = new SectionsResult();
            List <Section> list   = null;

            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <SectionMasterClient>();
                result      = await service.GetByCodeAsync(SessionKey, CompanyId, Code: null);

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

            for (var i = 0; i < list.Count; i++)
            {
                if (!string.IsNullOrWhiteSpace(list[i].PayerCode))
                {
                    list[i].PayerCodeLeft  = list[i].PayerCode.Substring(0, 3);
                    list[i].PayerCodeRight = list[i].PayerCode.Substring(3);
                }
            }

            return(list ?? new List <Section>());
        }
Ejemplo n.º 3
0
        private void txtSectionCode_Validated(object sender, EventArgs e)
        {
            // Clear Message
            ClearStatusMessage();

            try
            {
                string sectionCode = txtSectionCode.Text; // 入金部門

                // if Empty
                if (string.IsNullOrEmpty(sectionCode) ||
                    string.IsNullOrWhiteSpace(sectionCode))
                {
                    lblSectionName.Clear();
                    SectionId = 0;
                    return;
                }

                SectionsResult result = null;
                var            list   = new List <Web.Models.Section>();
                var            task   = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service = factory.Create <SectionMasterClient>();
                    result      = await service.GetByCodeAsync(
                        SessionKey,
                        CompanyId,
                        new string[] { sectionCode });
                });
                ProgressDialog.Start(ParentForm, task, false, SessionKey);

                if (result.ProcessResult.Result && result.Sections != null)
                {
                    list = result.Sections;
                }

                Web.Models.Section sectionResult = null;
                sectionResult = list.Find(s => s.Code == sectionCode);

                if (sectionResult == null)
                {
                    // テキストボックス未入力時、メッセージ【W00320】を表示
                    string code = txtSectionCode.Text;
                    ShowWarningDialog(MsgWngMasterNotExist, "入金部門", code);
                    txtSectionCode.Clear();
                    lblSectionName.Clear();
                    SectionId = 0;
                    txtSectionCode.Focus();
                }
                else
                {
                    lblSectionName.Text = sectionResult.Name;
                    SectionId           = sectionResult.Id;
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.StackTrace);
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
Ejemplo n.º 4
0
        private void txtSectionCode_Validated(object sender, EventArgs e)
        {
            try
            {
                ClearStatusMessage();
                var sectionCode = txtSectionCode.Text;

                if (string.IsNullOrEmpty(sectionCode) ||
                    string.IsNullOrWhiteSpace(sectionCode))
                {
                    lblSectionName.Clear();
                    SectionId = null;
                    return;
                }

                Section section = null;
                var     task    = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service           = factory.Create <SectionMasterClient>();
                    SectionsResult result = await service.GetByCodeAsync(
                        Login.SessionKey,
                        Login.CompanyId,
                        new string[] { sectionCode });

                    if (result.ProcessResult.Result && result.Sections.Any())
                    {
                        section = result.Sections[0];
                    }
                });
                ProgressDialog.Start(ParentForm, task, false, SessionKey);

                if (section != null)
                {
                    txtSectionCode.Text = section.Code;
                    lblSectionName.Text = section.Name;
                    SectionId           = section.Id;
                }
                else
                {
                    txtSectionCode.Clear();
                    lblSectionName.Clear();
                    SectionId = null;
                    ShowWarningDialog(MsgWngMasterNotExist, "入金部門", sectionCode);
                    txtSectionCode.Focus();
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
        private void txtSection_Validated(object sender, EventArgs e)
        {
            try
            {
                ClearStatusMessage();
                if (txtSection.Text != "")
                {
                    SectionsResult result = null;
                    var            task   = ServiceProxyFactory.LifeTime(async factory =>
                    {
                        var service = factory.Create <SectionMasterClient>();
                        result      = await service.GetByCodeAsync(SessionKey, CompanyId, new string[] { txtSection.Text });
                    });
                    ProgressDialog.Start(ParentForm, task, false, SessionKey);

                    if (result.ProcessResult.Result)
                    {
                        var section = result.Sections.FirstOrDefault();
                        if (section != null)
                        {
                            ProgressDialog.Start(ParentForm, SetSectionData(section), false, SessionKey);
                        }
                        else
                        {
                            ShowWarningDialog(MsgWngMasterNotExist, "入金部門", txtSection.Text);
                            txtSection.Clear();
                            lblPaymentName.Clear();
                            txtSection.Select();
                            SectionId = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
Ejemplo n.º 6
0
        private void Import()
        {
            ClearStatusMessage();
            try
            {
                ImportSetting importSetting = null;
                var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.SectionWithLoginUser);
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                importSetting = task.Result;
                var definition = new SectionWithLoginUserFileDefinition(new DataExpression(ApplicationControl));
                definition.SectionCodeField.GetModelsByCode = val =>
                {
                    Dictionary <string, Section> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var section           = factory.Create <SectionMasterClient>();
                        SectionsResult result = section.GetByCode(SessionKey, CompanyId, val);

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

                definition.LoginUserCodeField.GetModelsByCode = val =>
                {
                    Dictionary <string, LoginUser> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var loginUser   = factory.Create <LoginUserMasterClient>();
                        UsersResult res = loginUser.GetByCode(SessionKey, CompanyId, val);

                        if (res.ProcessResult.Result)
                        {
                            product = res.Users
                                      .ToDictionary(c => c.Code);
                        }
                    });
                    return(product ?? new Dictionary <string, LoginUser>());
                };

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

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

                var importResult = DoImport(importer, importSetting);
                if (!importResult)
                {
                    return;
                }
                ClearFromTo();
                BeforeParentSearch();
                txtLoginUserCode.Clear();
                lblLoginUserNames.Clear();
                grdLoginUserModify.DataSource = null;
                grdLoginUserOrigin.DataSource = null;
                txtLoginUserCode.Focus();
                Modified = false;
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrImportErrorWithoutLog);
            }
        }
Ejemplo n.º 7
0
        private void Import()
        {
            try
            {
                ImportSetting importSetting = null;
                var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.BankAccount);
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                importSetting = task.Result;

                var definition = new BankAccountFileDefinition(new DataExpression(ApplicationControl));
                definition.CategoryIdField.GetModelsByCode = val =>
                {
                    Dictionary <string, Category> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var categoryMaster      = factory.Create <CategoryMasterClient>();
                        CategoriesResult result = categoryMaster.GetByCode(
                            Login.SessionKey, Login.CompanyId, 2, val);
                        if (result.ProcessResult.Result)
                        {
                            product = result.Categories
                                      .ToDictionary(c => c.Code);
                        }
                    });
                    return(product ?? new Dictionary <string, Category>());
                };
                definition.SectionIdField.Ignored         = !UseSection;
                definition.SectionIdField.GetModelsByCode = val =>
                {
                    Dictionary <string, Section> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var sectionMaster     = factory.Create <SectionMasterClient>();
                        SectionsResult result = sectionMaster.GetByCode(
                            Login.SessionKey, Login.CompanyId, val);
                        if (result.ProcessResult.Result)
                        {
                            product = result.Sections
                                      .ToDictionary(c => c.Code);
                        }
                    });
                    return(product ?? new Dictionary <string, Section>());
                };

                var importer = definition.CreateImporter(m => new
                {
                    m.BankCode,
                    m.BranchCode,
                    m.AccountTypeId,
                    m.AccountNumber
                });
                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, ClearAll);
                if (!importResult)
                {
                    return;
                }

                BankAccountList.Clear();
                Task <List <BankAccount> > loadListTask = LoadListAsync();
                ProgressDialog.Start(ParentForm, loadListTask, false, SessionKey);
                BankAccountList.AddRange(loadListTask.Result);
                grdBankAccount.DataSource = new BindingSource(BankAccountList, null);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                ShowWarningDialog(MsgErrImportErrorWithoutLog);
            }
        }
Ejemplo n.º 8
0
        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);
            }
        }