コード例 #1
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);
            }
        }