📄 formawardinfo.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace HRMan.HROper
{
public partial class FormAwardInfo : Form
{
public FormAwardInfo()
{
InitializeComponent();
HRMan.HROper.FormAwardInfo.awardform = this;
}
private void FormAwardInfo_Load(object sender, EventArgs e)
{
this.DBDataGrid();
DBDataGrid();
if (this.dataGrid1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGrid1.Rows.Count; )
{
this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2;
}
}
}
//数据显示
public void DBDataGrid()
{
string SqlText = "select PpInfo.pppId,PpInfo.pId as 员工编号,EmployInfo.eName as 员工姓名,PpInfo.pDate as 奖惩时间,PpInfo.pType as 奖惩类别,";
SqlText += "PpInfo.pReason as 奖惩原因,PpInfo.pContext as 奖惩内容,PpInfo.pAppS as 批准部门,PpInfo.pApp as 批准人,PpInfo.pRepealDate as 撤消日期,";
SqlText += "PpInfo.pRepealReason as 撤消原因,PpInfo.pRemarks as [备注] from PpInfo,EmployInfo where EmployInfo.pId=PpInfo.pId order by PpInfo.pId asc";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
cm = (CurrencyManager)BindingContext[this.dt];
if (this.dataGrid1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGrid1.Rows.Count; )
{
this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2;
}
}
}
//刷新
private void FormAwardInfo_EnabledChanged(object sender, EventArgs e)
{
this.DBDataGrid();
}
//处理按钮事件
//添加记录
private void InsertAward(object sender, System.EventArgs e)
{
HRMan.HROper.FormAwardInfo.awardID = "insert";
if (FormMain.FM.CheckForm("FormAddAward") == true )
{
return;
}
else
{
HRMan.HROper.FormAddAward addaward = new FormAddAward();
addaward.MdiParent = FormMain.FM;
addaward.Show();
addaward.Text = "添加奖惩";
}
}
//修改记录
private void UpdateAward(object sender, System.EventArgs e)
{
HRMan.HROper.FormAwardInfo.awardID = "update";
this.sb.Remove(0, this.sb.ToString().Length);
for (int i = 0; i < this.dt.Columns.Count; i++)
{
this.sb.Append(this.dataGrid1[i, this.dataGrid1.CurrentCellAddress.Y].Value.ToString() + "#");
}
if (FormMain.FM.CheckForm("FormAddAward") == true)
{
return;
}
else
{
HRMan.HROper.FormAddAward addaward = new FormAddAward();
addaward.MdiParent = FormMain.FM;
addaward.Show();
addaward.Text = "修改奖惩";
}
}
//删除记录
private void DeleteAward(object sender, System.EventArgs e)
{
DialogResult result = MessageBox.Show("是否删除此记录?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
string SqlText = "delete PpInfo where pppId=" + int.Parse(this.dataGrid1[0, this.dataGrid1.CurrentCellAddress.Y].Value.ToString());
DataAccess DA = new DataAccess();
DA.ExeSQL(SqlText);
MessageBox.Show("删除成功!");
}
if (result == DialogResult.No)
{
return;
}
this.DBDataGrid();
}
//退出
private void ExitAward(object sender, System.EventArgs e)
{
this.Close();
}
//查询
private void Search(object sender, System.EventArgs e)
{
this.groupBox1.Visible = true;
this.dataGrid1.Dock = DockStyle.None;
this.dataGrid1.Location = new Point(0, 128);
this.dataGrid1.Height = 330;
}
//取消查询
private void button2_Click(object sender, EventArgs e)
{
this.groupBox1.Visible = false;
this.dataGrid1.Dock = DockStyle.Fill;
this.DBDataGrid();
}
//执行查询
private void button1_Click(object sender, EventArgs e)
{
string SqlText = "select PpInfo.pppId,PpInfo.pId as 员工编号,EmployInfo.eName as 员工姓名,PpInfo.pDate as 奖惩时间,PpInfo.pType as 奖惩类别,";
SqlText += "PpInfo.pReason as 奖惩原因,PpInfo.pContext as 奖惩内容,PpInfo.pAppS as 批准部门,PpInfo.pApp as 批准人,PpInfo.pRepealDate as 撤消日期,";
SqlText += "PpInfo.pRepealReason as 撤消原因,PpInfo.pRemarks as [备注] from PpInfo,EmployInfo where EmployInfo.pId=PpInfo.pId";
if (this.ID_txt.Text.Trim() != "")
{
SqlText += " and PpInfo.pId=" + int.Parse(this.ID_txt.Text.Trim());
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
cm = (CurrencyManager)BindingContext[this.dt];
if (this.dataGrid1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGrid1.Rows.Count; )
{
this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2;
}
}
}
if (this.name_txt.Text.Trim() != "")
{
SqlText += " and EmployInfo.eName='" + this.name_txt.Text + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
cm = (CurrencyManager)BindingContext[this.dt];
if (this.dataGrid1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGrid1.Rows.Count; )
{
this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2;
}
}
}
if (this.comboBox1.Text != "")
{
SqlText += " and PpInfo.pType='" + this.comboBox1.SelectedItem.ToString() + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
cm = (CurrencyManager)BindingContext[this.dt];
if (this.dataGrid1.Rows.Count != 0)
{
for (int i = 0; i < this.dataGrid1.Rows.Count; )
{
this.dataGrid1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.Pink;
i += 2;
}
}
}
}
//首记录
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (this.Position != 0)
{
foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
{
dvrow.Selected = false;
}
this.dataGrid1.Rows[0].Selected = true;
this.Position = 0;
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (this.Position > 0)
{
foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
{
dvrow.Selected = false;
}
this.Position--;
this.dataGrid1.Rows[this.Position].Selected = true;
}
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
if (this.Position < this.dataGrid1.Rows.Count - 1)
{
foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
{
dvrow.Selected = false;
}
this.Position++;
this.dataGrid1.Rows[this.Position].Selected = true;
}
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
if (this.Position != this.dataGrid1.Rows.Count - 1)
{
foreach (DataGridViewRow dvrow in this.dataGrid1.Rows)
{
dvrow.Selected = false;
}
this.Position = this.dataGrid1.Rows.Count;
this.dataGrid1.Rows[this.Position - 1].Selected = true;
}
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
this.InsertAward(sender,e);
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
this.UpdateAward(sender,e);
}
private void toolStripButton7_Click(object sender, EventArgs e)
{
this.DeleteAward(sender,e);
}
private void toolStripButton8_Click(object sender, EventArgs e)
{
this.Search(sender,e);
}
private void toolStripButton9_Click(object sender, EventArgs e)
{
this.ExitAward(sender,e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -