Example #1
0
        private void SaveCustomerGroup()
        {
            if (!string.IsNullOrWhiteSpace(txtCustomerCodeFrom.Text) ||
                !string.IsNullOrWhiteSpace(txtCustomerCodeTo.Text))
            {
                if (!CheckRangeData())
                {
                    return;
                }
                var addTask = AddCustomerGroupAsync();
                ProgressDialog.Start(ParentForm, addTask, false, SessionKey);
            }

            var loadTask = GetChildCustomersByParentId(ParentCustomerId)
                           .ContinueWith(t => PrepareCustomerGroup(t.Result));

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

            var success  = false;
            var saveTask = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service    = factory.Create <CustomerGroupMasterClient>();
                var saveResult = await service.SaveAsync(SessionKey,
                                                         AddCustomer.ToArray(), DeleteCustomer.ToArray());
                success = saveResult?.ProcessResult.Result ?? false;
                if (!success)
                {
                    return;
                }

                AddCustomer.Clear();
                DeleteCustomer.Clear();

                var customerGroup  = await GetChildCustomersByParentId(ParentCustomerId);
                customerGroup      = customerGroup.OrderBy((x => x.ChildCustomerCode)).ToList();
                CustomerModifyList = customerGroup;
                CustomerOriginList = customerGroup;
            });

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

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

            grdCustomerModify.DataSource = new BindingSource(CustomerModifyList, null);
            grdCustomerOrigin.DataSource = new BindingSource(CustomerOriginList, null);
            txtCustomerCodeFrom.Focus();
            ClearChildCustomerInfo();
            Modified = false;

            DispStatusMessage(MsgInfSaveSuccess);
        }