コード例 #1
0
        private void PB0801_Load(object sender, EventArgs e)
        {
            try
            {
                SetScreenName();

                var loadTask = new List <Task>();

                if (Company == null)
                {
                    loadTask.Add(LoadCompanyAsync());
                }

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

                loadTask.Add(LoadControlColorAsync());
                loadTask.Add(LoadFunctionAuthorities(MasterImport, MasterExport));

                Task <List <BankAccount> > loadListTask = LoadListAsync();
                loadTask.Add(loadListTask.ContinueWith(task => BankAccountList.AddRange(task.Result)));

                ProgressDialog.Start(ParentForm, Task.WhenAll(loadTask), false, SessionKey);

                InitializeGridTemplate();
                grdBankAccount.DataSource = new BindingSource(BankAccountList, null);

                ComboDataBind();
                DisplaySectionInput();
                txtCategoryCode.MaxLength   = 2;
                txtCategoryCode.PaddingChar = '0';
                ClearAll();

                BaseContext.SetFunction05Enabled(Authorities[MasterImport]);
                BaseContext.SetFunction06Enabled(Authorities[MasterExport]);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        private void Delete()
        {
            try
            {
                if (!ValidateChildren())
                {
                    return;
                }

                if (!ValidateInput(isDelete: true))
                {
                    return;
                }

                if (!ShowConfirmDialog(MsgQstConfirmDelete))
                {
                    DispStatusMessage(MsgInfProcessCanceled);
                    return;
                }

                var bankCode      = txtBankCode.Text;
                var branchCode    = txtBranchCode.Text;
                int accountTypeId = Convert.ToInt32(cmbAccountType.SelectedItem.SubItems[1].Value);
                var accountNumber = txtAccountNumber.Text;

                CurrentAccount = BankAccountList.Find(b => (b.BankCode == bankCode) &&
                                                      (b.BranchCode == branchCode) &&
                                                      (b.AccountTypeId == accountTypeId) &&
                                                      (b.AccountNumber == accountNumber));

                BankId = CurrentAccount != null ? CurrentAccount.Id : 0;

                CountResult        deleteResult = new CountResult();
                List <BankAccount> newList      = null;
                if (BankId > 0)
                {
                    var task = ServiceProxyFactory.LifeTime(async factory =>
                    {
                        var service  = factory.Create <BankAccountMasterClient>();
                        deleteResult = await service.DeleteAsync(
                            Login.SessionKey,
                            BankId);

                        if (deleteResult.ProcessResult.Result && deleteResult.Count > 0)
                        {
                            newList = await LoadListAsync();
                        }
                    });
                    ProgressDialog.Start(ParentForm, task, false, SessionKey);
                }

                if (deleteResult.Count > 0)
                {
                    BankAccountList.Clear();
                    BankAccountList.AddRange(newList);
                    grdBankAccount.DataSource = new BindingSource(BankAccountList, null);
                    ClearAll();
                    DispStatusMessage(MsgInfDeleteSuccess);
                }
                else
                {
                    ShowWarningDialog(MsgErrDeleteError);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
コード例 #4
0
        private void Save()
        {
            try
            {
                if (!ValidateChildren())
                {
                    return;
                }

                if (!ValidateInput())
                {
                    return;
                }

                ZeroLeftPaddingWithoutValidated();

                if (!ShowConfirmDialog(MsgQstConfirmSave))
                {
                    DispStatusMessage(MsgInfProcessCanceled);
                    return;
                }

                var bankAccount = BankAccountInfo();
                bankAccount.Id = 0;

                BankAccountResult  result  = null;
                List <BankAccount> newList = null;
                ProgressDialog.Start(ParentForm, Task.Run(async() =>
                {
                    var org = await GetBankAccountAsync(bankAccount);
                    if (org != null)
                    {
                        bankAccount.Id = org.Id;
                    }

                    await ServiceProxyFactory.LifeTime(async factory =>
                    {
                        var service = factory.Create <BankAccountMasterClient>();
                        result      = await service.SaveAsync(
                            Login.SessionKey,
                            bankAccount);
                        if (result.ProcessResult.Result && result.BankAccount != null)
                        {
                            newList = await LoadListAsync();
                        }
                    });
                }), false, SessionKey);

                if (result.BankAccount != null)
                {
                    BankAccountList.Clear();
                    BankAccountList.AddRange(newList);
                    grdBankAccount.DataSource = new BindingSource(BankAccountList, null);
                    ClearAll();
                    DispStatusMessage(MsgInfSaveSuccess);
                }
                else
                {
                    ShowWarningDialog(MsgErrSaveError);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }