private void dgrd_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0 && e.ColumnIndex == 0) { btnModify.Enabled = true; cpModify.Visible = true; gbModify.Visible = true; btnModify.Visible = true; btnReturn.Visible = true; ddlTimerIntervalAdd.Text = dgrd.Rows[e.RowIndex].Cells[6].Value.ToString(); ddlDeptAdd.SelectedValue = dgrd.Rows[e.RowIndex].Cells[3].Value.ToString(); txtUserNameAdd.Text = dgrd.Rows[e.RowIndex].Cells[4].Value.ToString(); txtBlockAdd.Text = dgrd.Rows[e.RowIndex].Cells[2].Value.ToString(); dtpBeginTimeAdd.Value = Convert.ToDateTime(dgrd.Rows[e.RowIndex].Cells[7].Value.ToString()); dtpEndTimeAdd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); } if (e.RowIndex >= 0 && e.ColumnIndex == 1) { if (MessageBox.Show("你确定要删除吗?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { aBLL.GetEmployeeAttendanceRealTimeDelete(Convert.ToInt32(dgrd.Rows[e.RowIndex].Cells[2].Value.ToString()), out strErr); if (strErr == "") { lblErr.ForeColor = Color.Blue; lblErr.Text = "删除成功!"; } BindDataGridView(); } } }
void BindDataGridView() { int intRowsCount = 0; string strWhere = string.Empty; if (ddlDept.SelectedValue.ToString() != "0") { strWhere += " and RT.DeptID = " + ddlDept.SelectedValue.ToString(); } if (ddlTimerInterval.SelectedValue.ToString() != "0") { strWhere += " and RT.TimerIntervalID = " + ddlTimerInterval.SelectedValue.ToString(); } if (txtUserName.Text.Trim() != "") { strWhere += " and RT.EmployeeName = '" + txtUserName.Text.Trim() + "'"; } if (txtBlock.Text.Trim() != "") { try { Convert.ToInt32(txtBlock.Text.Trim()); strWhere += " and RT.BlockID =" + txtBlock.Text.Trim(); } catch { lblErr.ForeColor = Color.Red; lblErr.Text = "发码器编号只能为数字!"; return; } } intPageSize = Convert.ToInt32(ddlRowsSet.SelectedValue.ToString()); DataSet ds = aBLL.GetEmployeeAttendanceRealTime(strWhere, intPageIndex, intPageSize, out strErr); bool Flag = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i][5].ToString() == "") { aBLL.GetEmployeeAttendanceRealTimeDelete(int.Parse(ds.Tables[0].Rows[i][0].ToString()), out strErr); Flag = true; } } if (Flag) { ds = aBLL.GetEmployeeAttendanceRealTime(strWhere, intPageIndex, intPageSize, out strErr); } if (ds != null) { dgrd.DataSource = ds.Tables[0]; dgrd.Columns[3].Visible = false; dgrd.Columns[8].Visible = false; dgrd.Columns[9].Visible = false; dgrd.Columns[0].DisplayIndex = 8; dgrd.Columns[1].DisplayIndex = 8; dgrd.Columns[2].HeaderText = "发码器编号"; dgrd.Columns[4].HeaderText = "员工姓名"; dgrd.Columns[5].HeaderText = "所属部门"; dgrd.Columns[6].HeaderText = "班次"; dgrd.Columns[7].HeaderText = "下井时间"; intRowsCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString()); intPageCount = intRowsCount / intPageSize; if (intRowsCount % intPageSize != 0) { intPageCount++; } if (intPageCount == 0) { intPageCount = 1; } if (intPageIndex == 1) { btnPreview.Enabled = false; } else { btnPreview.Enabled = true; } if (intPageIndex == intPageCount) { btnNext.Enabled = false; } else { btnNext.Enabled = true; } btnRowsCount.CaptionTitle = "共有" + intRowsCount.ToString() + "条记录"; btnPageIndexAndPageCount.CaptionTitle = intPageIndex.ToString() + "/" + intPageCount.ToString(); } }
void BindDataGridView() { int intRowsCount = 0; string strWhere = string.Empty; if (DeptTree.SelectedNode != null) { if (DeptTree.SelectedNode.Name != "0") { strWhere += " and ei.DeptID = " + DeptTree.SelectedNode.Name.ToString(); } } if (ddlTimerInterval.SelectedValue != null && ddlTimerInterval.SelectedValue.ToString() != "0") { strWhere += " and RT.TimerIntervalID = " + ddlTimerInterval.SelectedValue.ToString(); } if (ddlClass.SelectedValue != null && ddlClass.SelectedValue.ToString() != "0") { strWhere += " And RT.ClassID = " + ddlClass.SelectedValue.ToString(); } if (txtUserName.Text.Trim() != "") { strWhere += " and ei.empName like '%" + txtUserName.Text.Trim() + "%'"; } if (txtBlock.Text.Trim() != "") { try { //Convert.ToInt32(txtBlock.Text.Trim()); //yc11 Convert.ToInt64(txtBlock.Text.Trim()); //yc12 strWhere += " and RTI.CodeSenderAddress =" + txtBlock.Text.Trim(); } catch { //lblCounts.ForeColor = Color.Red; //lblCounts.Text = "发码器编号只能为数字!"; return; } } //strWhere += " And RT.EmployeeID is not null "; //qyz 屏蔽 //if (cmbSelectCounts.Text.ToString() == "") //{ // intPageSize = 40; //} //else //{ // intPageSize = Convert.ToInt32(cmbSelectCounts.SelectedItem.ToString()); //} DataSet ds = aBLL.GetEmployeeAttendanceRealTime(strWhere, intPageIndex, intPageSize, out strErr); bool Flag = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i][5].ToString() == "") { aBLL.GetEmployeeAttendanceRealTimeDelete(int.Parse(ds.Tables[0].Rows[i][0].ToString()), out strErr); Flag = true; } } if (Flag) { ds = aBLL.GetEmployeeAttendanceRealTime(strWhere, intPageIndex, intPageSize, out strErr); } if (ds != null && ds.Tables.Count > 0) { // 重新设置页数 int sumPage = int.Parse(ds.Tables[1].Rows[0][0].ToString()); sumPage = sumPage % intPageSize != 0 ? sumPage / intPageSize + 1 : sumPage / intPageSize; intPageCount = sumPage; ds.Tables[0].TableName = "A_AttendanceRealTimeSave"; if (sumPage == 0) { dgrd.DataSource = ds.Tables[0]; lblCounts.Text = "共 0 条记录"; lblPageCounts.Text = "1"; lblSumPage.Text = "/1页"; btnUpPage.Enabled = false; btnDownPage.Enabled = false; } else { dgrd.DataSource = ds.Tables[0]; lblCounts.Text = "共 " + ds.Tables[1].Rows[0][0].ToString() + " 条记录"; lblPageCounts.Text = intPageIndex.ToString(); lblSumPage.Text = "/" + sumPage + "页"; //控制翻页状态 SetPageEnable(intPageIndex, sumPage); } if (dgrd.Columns.Count >= 9) { int width = (dgrd.Width - 50 - 2) / (dgrd.Columns.Count - 4); if (width < 0) { width = 0; } dgrd.Columns[1].HeaderText = "卡号"; dgrd.Columns[1].ReadOnly = true; dgrd.Columns[1].FillWeight = width; dgrd.Columns[3].HeaderText = "姓名"; dgrd.Columns[3].ReadOnly = true; dgrd.Columns[3].FillWeight = width; dgrd.Columns[4].HeaderText = "所属部门"; dgrd.Columns[4].ReadOnly = true; dgrd.Columns[4].FillWeight = width; dgrd.Columns[5].HeaderText = "班次"; dgrd.Columns[5].ReadOnly = true; dgrd.Columns[5].FillWeight = width; dgrd.Columns[6].HeaderText = "下井时间"; dgrd.Columns[6].ReadOnly = true; dgrd.Columns[6].FillWeight = width; dgrd.Columns[2].Visible = false; dgrd.Columns[7].Visible = false; dgrd.Columns[8].Visible = false; } } }