private void btn导入_Click(object sender, EventArgs e) { if (prevMonth.Year != Convert.ToInt32(year.Value) || prevMonth.Month != Convert.ToInt32(month.Text)) { if (MessageBox.Show("您导入的不是上月的数据,您要继续吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0, false) != DialogResult.Yes) { return; } } if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { CreateWaitDialog("正在导入数据...", "请稍等"); Workbook workbook = new Workbook(openFileDialog1.FileName); Worksheet sheet = workbook.Worksheets[0]; Cells cells = sheet.Cells; currRows.Clear(); int totalCount = 0; List <Row> errorRows = new List <Row>(); foreach (Row row in sheet.Cells.Rows) { try { EmpPayRateData item = new EmpPayRateData(); item.年 = Convert.ToInt32(year.Value); item.月 = Convert.ToInt32(month.Text); item.员工编号 = (string)cells[row.Index, 0].StringValue; item.姓名 = (string)cells[row.Index, 1].StringValue; item.系数 = Convert.ToDouble(cells[row.Index, 2].Value); currRows.Add(item); totalCount++; } catch { errorRows.Add(row); } } CloseWaitDialog(); gridControl1.RefreshDataSource(); string errMsg = ""; foreach (Row row in errorRows) { if (errMsg != "") { errMsg += "、"; } errMsg += (row.Index + 1).ToString(); } string msg = "导入完毕," + totalCount + " 成功, " + errorRows.Count + " 失败。\n\n失败行:" + errMsg; MessageBox.Show(msg); } }
private void btn添加_Click(object sender, EventArgs e) { EmpPayRateData item = new EmpPayRateData(); item.年 = Convert.ToInt32(year.Value); item.月 = Convert.ToInt32(month.Text); currRows.Add(item); gridControl1.RefreshDataSource(); gridView1.FocusedRowHandle = gridView1.RowCount - 1; }
private void btn删除_Click(object sender, EventArgs e) { ColumnView colView = (ColumnView)gridControl1.MainView; if (colView != null) { if (MessageBox.Show("确实删除当前记录吗?", "删除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, 0, false) == DialogResult.Yes) { EmpPayRateData currentItem = (EmpPayRateData)colView.GetFocusedRow(); currRows.Remove(currentItem); EmpPayRate.GetEmpPayRate(currentItem.员工编号, currentItem.年, currentItem.月); currentItem = null; gridControl1.RefreshDataSource(); MessageBox.Show("删除成功。", "删除提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e) { EmpPayRateData row = gridView1.GetRow(e.RowHandle) as EmpPayRateData; if (row != null) { if (e.Column.FieldName == "员工编号") { PersonalInfo pInfo = PersonalInfo.Get(row.员工编号); if (pInfo == null) { MessageBox.Show("找不到指定编号的员工"); } else { row.姓名 = pInfo.姓名; gridControl1.RefreshDataSource(); } } } }