private void btnBuild_Click(object sender, EventArgs e) { //是否为空 if (cmbYear.SelectedIndex == -1 || cmbMonth.SelectedIndex == -1 || cmbDepartment.SelectedIndex == -1) { CommonHelper.FailedReply("不能为空!"); return; } int year = int.Parse(cmbYear.Text); int month = int.Parse(cmbMonth.Text); Guid depId = (Guid)cmbDepartment.SelectedValue; Guid sheetId = ss.GetSalarySheetId(year, month, depId); if (sheetId == Guid.Empty) { //生成新的工资单 SalarySheet sheet = new SalarySheet(); sheet.Id = Guid.NewGuid(); sheet.Year = year; sheet.Month = month; sheet.DepartmentId = depId; ss.BuildNewSalarySheet(sheet); ss.BuildSalaryItems(sheet.Id, depId); DataGridView.DataSource = ss.GetSalarySheetItems(sheet.Id); } else { //是否重新生成 DialogResult dr = MessageBox.Show("已经生成该工资表,是否重新生成?", "警告", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { ss.DeleteSalaryItems(sheetId); ss.BuildSalaryItems(sheetId, depId); DataGridView.DataSource = ss.GetSalarySheetItems(sheetId); } else { DataGridView.DataSource = ss.GetSalarySheetItems(sheetId); } } }