private async Task <int> AddLoginUserWithSectionAsync() { List <Section> sectionListToCheck = await GetAllSectionAsync(); var codeFrom = string.IsNullOrWhiteSpace(txtSectionFrom.Text) ? txtSectionTo.Text : txtSectionFrom.Text; var codeTo = string.IsNullOrWhiteSpace(txtSectionTo.Text) ? txtSectionFrom.Text : txtSectionTo.Text; Func <Section, bool> range = d => (string.Compare(codeFrom, d.Code) <= 0 && string.Compare(d.Code, codeTo) <= 0); var newSections = (sectionListToCheck).Where(range) .Where(d => !ModifySection.Any(swd => swd.SectionCode == d.Code)).ToList(); if (!newSections.Any()) { //既存得意先を追加する場合 ShowWarningDialog(MsgWngNoData, "追加"); ClearFromTo(); } else { ModifySection.AddRange(newSections.Select(d => new SectionWithLoginUser { SectionId = d.Id, SectionCode = d.Code, SectionName = d.Name })); ModifySection = ModifySection.OrderBy(d => d.SectionCode).ToList(); } return(newSections.Count); }
private void btnDeleteAll_Click(object sender, EventArgs e) { try { this.ButtonClicked(btnDeleteAll); ClearStatusMessage(); if (!ModifySection.Any()) { ShowWarningDialog(MsgWngNoData, "削除"); return; } bool result = ShowConfirmDialog(MsgQstConfirmDeleteAll); if (result) { ModifySection.Clear(); grdLoginUserModify.DataSource = new BindingSource(ModifySection, null); Task <List <SectionWithLoginUser> > getTask = GetByLoginUser(); ProgressDialog.Start(ParentForm, getTask, false, SessionKey); OriginSection = getTask.Result; grdLoginUserOrigin.DataSource = new BindingSource(OriginSection, null); Modified = true; } ClearFromTo(); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } }
private void btnDelete_Click(object sender, EventArgs e) { try { this.ButtonClicked(btnDelete); ClearStatusMessage(); if (!CheckRangeData()) { return; } if (string.IsNullOrWhiteSpace(txtSectionFrom.Text) && string.IsNullOrWhiteSpace(txtSectionTo.Text)) { ShowWarningDialog(MsgWngInputRequired, "入金部門コード"); txtSectionFrom.Focus(); return; } var codeFrom = string.IsNullOrWhiteSpace(txtSectionFrom.Text) ? txtSectionTo.Text : txtSectionFrom.Text; var codeTo = string.IsNullOrWhiteSpace(txtSectionTo.Text) ? txtSectionFrom.Text : txtSectionTo.Text; Func <SectionWithLoginUser, bool> range = d => (string.Compare(codeFrom, d.SectionCode) <= 0 && string.Compare(d.SectionCode, codeTo) <= 0); if (!ModifySection.Any(range)) { ShowWarningDialog(MsgWngNoData, "削除"); ClearFromTo(); return; } ModifySection = ModifySection.Except(ModifySection.Where(range)).OrderBy(s => s.SectionCode).ToList(); grdLoginUserModify.DataSource = new BindingSource(ModifySection, null); Task <List <SectionWithLoginUser> > task = GetByLoginUser(); ProgressDialog.Start(ParentForm, task, false, SessionKey); OriginSection = task.Result; grdLoginUserOrigin.DataSource = new BindingSource(OriginSection, null); Modified = true; ClearFromTo(); } catch (Exception ex) { Debug.Fail(ex.ToString()); NLogHandler.WriteErrorLog(this, ex, SessionKey); } }
private Task SetSectionWithLoginUser(LoginUser loginUser) { if (loginUser == null) { txtLoginUserCode.Clear(); lblLoginUserNames.Clear(); return(null); } txtLoginUserCode.Text = loginUser.Code; lblLoginUserNames.Text = loginUser.Name; LoginUserId = loginUser.Id; AfterParentSearch(); if (string.IsNullOrWhiteSpace(txtLoginUserCode.Text)) { txtSectionFrom.Focus(); return(null); } return(GetByLoginUser() .ContinueWith(t => { ModifySection = t.Result; OriginSection = OriginSection.OrderBy(x => x.SectionCode).ToList(); OriginSection = ModifySection; grdLoginUserModify.DataSource = new BindingSource(ModifySection, null); grdLoginUserOrigin.DataSource = new BindingSource(OriginSection, null); if (!ModifySection.Any()) { DispStatusMessage(MsgInfSaveNewData, "ログインユーザー"); } txtSectionFrom.Focus(); }, TaskScheduler.FromCurrentSynchronizationContext())); }