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); }
/// <summary> /// 債権代表者マスター 登録前に AddCusotmer, DeleteCustomer を設定する処理 /// </summary> /// <param name="customerGroupDB"></param> private void PrepareCustomerGroup(List <CustomerGroup> customerGroupDB) { if (CustomerModifyList.Any()) { AddCustomer.Clear(); DeleteCustomer.Clear(); foreach (var item in CustomerModifyList .Where(x => !customerGroupDB.Any(y => y.ChildCustomerCode == x.ChildCustomerCode))) { item.ParentCustomerId = ParentCustomerId; item.CreateBy = Login.UserId; item.UpdateBy = Login.UserId; AddCustomer.Add(item); } } foreach (var item in customerGroupDB .Where(x => !CustomerModifyList.Any(y => y.ChildCustomerCode == x.ChildCustomerCode))) { DeleteCustomer.Add(item); } }