private List <SectionWithDepartment> GetPrepareSaveData()
        {
            var deleteList = new List <SectionWithDepartment>();

            if (ModifySectionWithDepList.Any())
            {
                for (int i = 0; i < ModifySectionWithDepList.Count; i++)
                {
                    ModifySectionWithDepList[i].SectionId = SectionId.Value;
                    ModifySectionWithDepList[i].UpdateBy  = Login.UserId;
                    ModifySectionWithDepList[i].UpdateAt  = DateTime.Today.ToLocalTime();
                    ModifySectionWithDepList[i].CreateBy  = Login.UserId;
                    ModifySectionWithDepList[i].CreateAt  = DateTime.Today.ToLocalTime();
                }
            }
            for (int i = 0; i < OriginSectionWithDepList.Count; i++)
            {
                var isExists = ModifySectionWithDepList.Exists(x => x.DepartmentCode == OriginSectionWithDepList[i].DepartmentCode);
                if (!isExists)
                {
                    deleteList.Add(OriginSectionWithDepList[i]);
                }
            }
            return(deleteList);
        }
        /// <summary> Gridにある全データを削除 </summary>
        private void btnDeleteAll_Click(object sender, EventArgs e)
        {
            try
            {
                this.ButtonClicked(btnDeleteAll);
                ClearStatusMessage();

                if (!ModifySectionWithDepList.Any())
                {
                    ShowWarningDialog(MsgWngNoData, "削除");
                    return;
                }

                if (ShowConfirmDialog(MsgQstConfirmDeleteAll))
                {
                    ModifySectionWithDepList.Clear();
                    grdDepartmentModify.DataSource = new BindingSource(ModifySectionWithDepList, null);

                    Task <List <SectionWithDepartment> > task = LoadGridListAsync();
                    ProgressDialog.Start(ParentForm, task, false, SessionKey);
                    OriginSectionWithDepList       = task.Result;
                    grdDepartmentOrigin.DataSource = new BindingSource(OriginSectionWithDepList, null);

                    Modified = true;
                    ClearInput();
                }
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
        /// <summary> From/To Rangeにある請求部門データをSectionWithDepartmetListに追加 </summary>
        private async Task <bool> AddSectionWithDepartment()
        {
            var departmentListToCheck = await GetDepartmentDataForCheckAsync();

            var codeFrom = string.IsNullOrWhiteSpace(txtDepartmentFrom.Text) ? txtDepartmentTo.Text : txtDepartmentFrom.Text;
            var codeTo   = string.IsNullOrWhiteSpace(txtDepartmentTo.Text) ? txtDepartmentFrom.Text : txtDepartmentTo.Text;

            Func <Department, bool> range = d => (string.Compare(codeFrom, d.Code) <= 0 && string.Compare(d.Code, codeTo) <= 0);

            var newDepartments = (departmentListToCheck).Where(range)
                                 .Where(d => !ModifySectionWithDepList.Any(swd => swd.DepartmentCode == d.Code));

            if (!newDepartments.Any())
            {
                return(false);
            }

            ModifySectionWithDepList.AddRange(newDepartments.Select(d => new SectionWithDepartment
            {
                DepartmentId   = d.Id,
                DepartmentCode = d.Code,
                DepartmentName = d.Name
            }));
            ModifySectionWithDepList = ModifySectionWithDepList.OrderBy(d => d.DepartmentCode).ToList();
            return(true);
        }
        /// <summary> From/To RangeにあるデータをGridから削除 </summary>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                this.ButtonClicked(btnDelete);
                if (string.IsNullOrWhiteSpace(txtDepartmentFrom.Text) && string.IsNullOrWhiteSpace(txtDepartmentTo.Text))
                {
                    ShowWarningDialog(MsgWngInputRequired, "請求部門コード");
                    txtDepartmentFrom.Focus();
                    return;
                }
                if (!string.IsNullOrWhiteSpace(txtDepartmentFrom.Text) && !string.IsNullOrWhiteSpace(txtDepartmentTo.Text) &&
                    !txtDepartmentFrom.ValidateRange(txtDepartmentTo, () => ShowWarningDialog(MsgWngInputRangeChecked, "請求部門コード")))
                {
                    txtDepartmentFrom.Focus();
                    return;
                }

                var codeFrom = string.IsNullOrWhiteSpace(txtDepartmentFrom.Text) ? txtDepartmentTo.Text : txtDepartmentFrom.Text;
                var codeTo   = string.IsNullOrWhiteSpace(txtDepartmentTo.Text) ? txtDepartmentFrom.Text : txtDepartmentTo.Text;

                Func <SectionWithDepartment, bool> range = d => (string.Compare(codeFrom, d.DepartmentCode) <= 0 && string.Compare(d.DepartmentCode, codeTo) <= 0);

                if (!ModifySectionWithDepList.Any(range))
                {
                    ShowWarningDialog(MsgWngNoData, "削除");
                    ClearInput();
                    return;
                }

                ModifySectionWithDepList = ModifySectionWithDepList
                                           .Except(ModifySectionWithDepList.Where(range))
                                           .OrderBy(d => d.DepartmentCode).ToList();
                grdDepartmentModify.DataSource = new BindingSource(ModifySectionWithDepList, null);

                Task <List <SectionWithDepartment> > task = LoadGridListAsync();
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
                OriginSectionWithDepList       = task.Result;
                grdDepartmentOrigin.DataSource = new BindingSource(OriginSectionWithDepList, null);

                Modified = true;
                ClearInput();
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }