private async Task <bool> SaveAccountTitleData()
        {
            var accountTitle = new AccountTitle();

            accountTitle.ContraAccountCode    = txtContraAccountCode.Text ?? string.Empty;
            accountTitle.ContraAccountName    = txtContraAccountName.Text.Trim() ?? string.Empty;
            accountTitle.ContraAccountSubCode = txtContraAccountSubCode.Text ?? string.Empty;

            accountTitle.CompanyId = CompanyId;
            accountTitle.UpdateBy  = Login.UserId;
            accountTitle.CreateBy  = Login.UserId;
            accountTitle.Code      = txtCode.Text;
            accountTitle.Name      = txtName.Text.Trim();

            var success = false;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <AccountTitleMasterClient>();
                AccountTitleResult saveResult = null;
                saveResult     = await service.SaveAsync(SessionKey, accountTitle);
                success        = saveResult?.ProcessResult.Result ?? false;
                var syncResult = true;
                if (SavePostProcessor != null && success)
                {
                    syncResult = SavePostProcessor.Invoke(new IMasterData[] { saveResult.AccountTitle as IMasterData });
                }
                success &= syncResult;
                if (success)
                {
                    await LoadGrid();
                }
            });

            return(success);
        }
Example #2
0
        /// <summary>Update Billing Items </summary>
        private async Task UpdateBillingServiceItems()
        {
            grid.EndEdit();

            var success = true;

            var targets = grid.Rows.Select(x => x.DataBoundItem as Billing)
                          .Where(x => IsModifiedDueAtModified(x) || IsCollectCategoryModified(x))
                          .Select(x => {
                if (IsModifiedDueAtModified(x))
                {
                    x.NewDueAt = x.ModifiedDueAt;
                }
                if (IsCollectCategoryModified(x))
                {
                    x.NewCollectCategoryId = x.CollectCategoryId;
                }
                x.UpdateBy = Login.UserId;
                return(x);
            }).ToList();
            var result = await UpdateAsync(targets);

            if (!result.ProcessResult.Result ||
                SavePostProcessor != null && result.Billings == null)
            {
                success = false;
            }

            if (!success)
            {
                ShowWarningDialog(MsgErrUpdateError);
                return;
            }

            var syncResult = true;

            if (success && SavePostProcessor != null)
            {
                syncResult = SavePostProcessor.Invoke(result.Billings.Select(x => x as ITransactionData));
            }
            success &= syncResult;

            if (!syncResult)
            {
                ShowWarningDialog(MsgErrPostProcessFailure);
                return;
            }

            await LoadBillingsAsync();

            DispStatusMessage(MsgInfUpdateSuccess);
        }
Example #3
0
        private async Task <bool> UpdateStaff()
        {
            var success = true;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                StaffResult saveResult = null;
                Staff staff            = new Staff();
                staff.CompanyId        = CompanyId;
                staff.Code             = txtStaffCode.Text;
                staff.Name             = txtStaffName.Text.Trim();
                staff.DepartmentId     = DeparmentId;
                staff.Mail             = txtStaffMail.Text.Trim();
                staff.Tel            = txtStaffTel.Text.Trim();
                staff.Fax            = txtStaffFax.Text.Trim();
                staff.UpdateBy       = Login.UserId;
                staff.UpdateAt       = DateTime.Now;
                staff.CreateBy       = Login.UserId;
                staff.CreateAt       = DateTime.Now;
                staff.Id             = StaffId;
                staff.DepartmentCode = txtDepartmentCode.Text;
                staff.DepartmentName = lblDepartmentName.Text;

                var service = factory.Create <StaffMasterClient>();
                saveResult  = await service.SaveAsync(SessionKey, staff);

                success        = saveResult?.ProcessResult.Result ?? false;
                var syncResult = true;
                if (SavePostProcessor != null && success)
                {
                    syncResult = SavePostProcessor.Invoke(new IMasterData[] { saveResult.Staff as IMasterData });
                }
                success &= syncResult;

                if (success)
                {
                    await LoadStaffGrid();
                }
            });

            return(success);
        }
Example #4
0
        private async Task <ImportResult> RegisterForImportAsync(UnitOfWork <Staff> imported)
        {
            ImportResultStaff result = null;
            var syncResult           = true;

            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <StaffMasterClient>();
                result      = await service.ImportAsync(SessionKey, imported.New.ToArray(), imported.Dirty.ToArray(), imported.Removed.ToArray());
            });

            if (DeletePostProcessor != null && (imported.Removed?.Any() ?? false))
            {
                syncResult = DeletePostProcessor.Invoke(imported.Removed.Select(x => x as IMasterData));
            }

            if (syncResult && SavePostProcessor != null && (result.Staffs?.Any() ?? false))
            {
                syncResult = SavePostProcessor.Invoke(result.Staffs.Select(x => x as IMasterData));
            }

            return(result);
        }
Example #5
0
        private bool UpdateExcludeAmount(IEnumerable <ReceiptExclude> updateItems, System.Action errorMessaging)
        {
            var deleteItems  = new List <ReceiptExclude>();
            var newItems     = new List <ReceiptExclude>();
            var receiptItems = new List <Receipt>();
            var receiptId    = CurrentReceipt.Id;

            var success     = true;
            var syncResult  = true;
            var updateValid = true;

            ProgressDialog.Start(ParentForm, async(cancel, progress) =>
            {
                if (IsPostProessorImplemented)
                {
                    await ServiceProxyFactory.DoAsync(async(ReceiptExcludeServiceClient client) =>
                    {
                        var result = await client.GetByReceiptIdAsync(SessionKey, receiptId);
                        if (result.ProcessResult.Result &&
                            result.ReceiptExcludes != null &&
                            result.ReceiptExcludes.Any(x => x != null))
                        {
                            deleteItems.AddRange(result.ReceiptExcludes);
                        }
                    });
                }
                await ServiceProxyFactory.DoAsync(async(ReceiptServiceClient client) =>
                {
                    var saveResult = await client.SaveExcludeAmountAsync(SessionKey, updateItems.ToArray());
                    success        = saveResult?.ProcessResult.Result ?? false;
                    newItems.AddRange(saveResult.ReceiptExclude.Where(x => x.Id != 0L));

                    if (!success)
                    {
                        updateValid = !(saveResult.ProcessResult.ErrorCode == Rac.VOne.Common.ErrorCode.OtherUserAlreadyUpdated);
                    }

                    if (success)
                    {
                        var receiptResult  = await client.GetAsync(SessionKey, updateItems.Select(x => x.ReceiptId).Distinct().ToArray());
                        var updatedReceipt = receiptResult.Receipts.First();
                        CurrentReceipt     = updatedReceipt;
                        if (IsPostProessorImplemented)
                        {
                            receiptItems.AddRange(receiptResult.Receipts);
                        }
                    }
                });
                if (!success)
                {
                    return;
                }
                if (IsPostProessorImplemented)
                {
                    syncResult = DeletePostProcessor.Invoke(deleteItems.Select(x => x as ITransactionData));
                    if (!syncResult)
                    {
                        return;
                    }
                    syncResult = ExcludePostProcessor.Invoke(newItems.Select(x => x as ITransactionData));
                    if (!syncResult)
                    {
                        return;
                    }
                    syncResult = SavePostProcessor.Invoke(receiptItems.Select(x => x as ITransactionData));
                }
                IsSaved = true;
            }, false, SessionKey);
            if (!syncResult)
            {
                ShowWarningDialog(MsgErrPostProcessFailure);
                return(false);
            }
            if (!updateValid)
            {
                ShowWarningDialog(MsgWngAlreadyUpdated);
                return(false);
            }
            if (!success)
            {
                errorMessaging?.Invoke();
                return(false);
            }
            return(success);
        }