private async Task <int> AddCustomerGroupAsync() { List <Customer> customers = await GetChildCustomersWithParentOrOrphans(); var codeFrom = string.IsNullOrEmpty(txtCustomerCodeFrom.Text) ? txtCustomerCodeTo.Text : txtCustomerCodeFrom.Text; var codeTo = string.IsNullOrEmpty(txtCustomerCodeTo.Text) ? txtCustomerCodeFrom.Text : txtCustomerCodeTo.Text; Func <Customer, bool> isNewChildCustomer = x => (string.Compare(codeFrom, x.Code) <= 0 && string.Compare(x.Code, codeTo) <= 0) && !CustomerModifyList.Any(group => group.ChildCustomerCode == x.Code); var newCustomers = customers.Where(isNewChildCustomer).ToList(); if (newCustomers.Any()) { CustomerModifyList.AddRange(newCustomers.Select(x => new CustomerGroup { ChildCustomerId = x.Id, ChildCustomerCode = x.Code, ChildCustomerName = x.Name })); CustomerModifyList = CustomerModifyList.OrderBy(x => x.ChildCustomerCode).ToList(); } return(newCustomers.Count); }
private void BindParentCustomerData(Customer customer) { var valid = customer?.IsParent == 1; if (valid) { txtParentCustomerCode.Text = customer.Code; lblParentCustomerKana.Text = customer.Kana; ParentCustomerId = customer.Id; AfterParentSearch(); grdCustomerModify.DataSource = new BindingSource(CustomerModifyList, null); grdCustomerOrigin.DataSource = new BindingSource(CustomerModifyList, null); //Console.WriteLine($"{DateTime.Now:yy/MM/dd HH:mm:ss.000} : set grid bindings"); } var messageId = string.Empty; var args = new string[] { }; var isNewCode = valid && !(CustomerModifyList?.Any() ?? false); if (customer == null) { messageId = MsgWngMasterNotExist; args = new string[] { "得意先", txtParentCustomerCode.Text }; } else if (customer.IsParent == 0) { messageId = MsgWngNotParentCustomer; args = new string[] { txtParentCustomerCode.Text }; } else { if (isNewCode) { messageId = MsgInfSaveNewData; args = new string[] { "債権代表者" }; } } if (!valid) { ShowWarningDialog(messageId, args); txtParentCustomerCode.Clear(); lblParentCustomerKana.Clear(); txtParentCustomerCode.Focus(); } else { if (isNewCode) { DispStatusMessage(messageId, args); } txtCustomerCodeFrom.Focus(); } }
private void btnDelete_Click(object sender, EventArgs e) { this.ButtonClicked(btnDelete); try { ClearStatusMessage(); if (!CheckRangeData()) { return; } string codeFrom = string.IsNullOrWhiteSpace(txtCustomerCodeFrom.Text) ? txtCustomerCodeTo.Text : txtCustomerCodeFrom.Text; string codeTo = string.IsNullOrWhiteSpace(txtCustomerCodeTo.Text) ? txtCustomerCodeFrom.Text : txtCustomerCodeTo.Text; Func <CustomerGroup, bool> range = d => (string.Compare(codeFrom, d.ChildCustomerCode) <= 0 && string.Compare(d.ChildCustomerCode, codeTo) <= 0); if (!CustomerModifyList.Any(range)) { ShowWarningDialog(MsgWngNoData, "削除"); ClearChildCustomerInfo(); return; } CustomerModifyList = CustomerModifyList.Except(CustomerModifyList.Where(range)).OrderBy(s => s.ChildCustomerCode).ToList(); grdCustomerModify.DataSource = new BindingSource(CustomerModifyList, null); Task <List <CustomerGroup> > loadTask = GetChildCustomersByParentId(ParentCustomerId); ProgressDialog.Start(ParentForm, loadTask, false, SessionKey); CustomerOriginList = loadTask.Result.OrderBy(s => s.ChildCustomerCode).ToList(); grdCustomerOrigin.DataSource = new BindingSource(CustomerOriginList, null); Modified = true; ClearChildCustomerInfo(); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } }
private void txtParentCustomerCode_Validated(object sender, EventArgs e) { ClearStatusMessage(); if (string.IsNullOrEmpty(txtParentCustomerCode.Text)) { lblParentCustomerKana.Clear(); return; } Customer customer = null; try { var task = GetCustomerByCode(txtParentCustomerCode.Text) .ContinueWith(t => { customer = t.Result.FirstOrDefault(); if (customer?.IsParent == 1) { CustomerModifyList = GetChildCustomersByParentId(customer.Id).Result; CustomerModifyList = CustomerModifyList.OrderBy(x => x.ChildCustomerCode).ToList(); //Console.WriteLine($"{DateTime.Now:yy/MM/dd HH:mm:ss.000} : getchildcustomer done"); } else { CustomerModifyList = new List <CustomerGroup>(); } }); ProgressDialog.Start(ParentForm, task, false, SessionKey); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } BindParentCustomerData(customer); }
/// <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); } }
private void btnDeleteAll_Click(object sender, EventArgs e) { this.ButtonClicked(btnDeleteAll); try { ClearStatusMessage(); if (!CustomerModifyList.Any()) { ShowWarningDialog(MsgWngNoData, "削除"); return; } if (ShowConfirmDialog(MsgQstConfirmDeleteAll)) { ClearChildCustomerInfo(); CustomerModifyList.Clear(); CustomerModifyList = CustomerModifyList.OrderBy(s => s.ChildCustomerCode).ToList(); grdCustomerModify.DataSource = new BindingSource(CustomerModifyList, null); Task <List <CustomerGroup> > loadTask = GetChildCustomersByParentId(ParentCustomerId); ProgressDialog.Start(ParentForm, loadTask, false, SessionKey); List <CustomerGroup> customerOriginList = loadTask.Result.OrderBy(x => x.ChildCustomerCode).ToList(); grdCustomerOrigin.DataSource = new BindingSource(customerOriginList, null); Modified = true; ErrorFlag = false; } } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } }