📄 formempchange.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 FormEmpChange : Form
{
public FormEmpChange()
{
InitializeComponent();
employchange = this;
Position = 0;
}
//初始化
private void FormEmpChange_Load(object sender, EventArgs e)
{
DBDataGrid();
this.Init();
}
//初始化
private void Init()
{
string SqlText = "select * from SectionInfo";
DataAccess DA = new DataAccess();
DataTable dt = DA.ExeSQLdt(SqlText);
for (int i = 0; i < dt.Rows.Count; i++)
{
this.comboBox1.Items.Add(dt.Rows[i]["sName"].ToString());
this.comboBox2.Items.Add(dt.Rows[i]["sName"].ToString());
}
string str = "select * from Title";
DataTable table = DA.ExeSQLdt(str);
for (int j = 0; j < table.Rows.Count; j++)
{
this.comboBox3.Items.Add(table.Rows[j]["tName"].ToString());
this.comboBox4.Items.Add(table.Rows[j]["tName"].ToString());
}
}
//数据显示
public void DBDataGrid()
{
string SqlText = "select TransferInfo.aaId,TransferInfo.traId as 员工编号,EmployInfo.eName as 员工姓名,TransferInfo.tDate as 调动时间,TransferInfo.fSection as 调动前部门,";
SqlText += "TransferInfo.lSection as 调动后部门,TransferInfo.fJob as 调动前职务,TransferInfo.lJob as 调动后职务,TransferInfo.tReason as 调动原因,TransferInfo.tApp as 批准人,TransferInfo.tRemarks as [备注] ";
SqlText += " from TransferInfo,EmployInfo where EmployInfo.traId=TransferInfo.traId order by TransferInfo.traId asc";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.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 InsertEmpChange(System.Object sender, System.EventArgs e)
{
HRMan.HROper.FormEmpChange.employId = "insert";
if (FormMain.FM.CheckForm("FormAddEmpChange") == true)
{
return;
}
else
{
HRMan.HROper.FormAddEmpChange addempchange = new HRMan.HROper.FormAddEmpChange();
addempchange.MdiParent = FormMain.FM;
addempchange.Show();
addempchange.Text = "添加工作调动";
}
}
//修改
private void UpdateEmpChange(System.Object sender, System.EventArgs e)
{
HRMan.HROper.FormEmpChange.employId = "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("FormAddEmpChange") == true)
{
return;
}
else
{
HRMan.HROper.FormAddEmpChange addempchange = new HRMan.HROper.FormAddEmpChange();
addempchange.MdiParent = FormMain.FM;
addempchange.Show();
addempchange.Text = "修改工作调动";
}
}
//删除
private void DeleteEmpChange(System.Object sender, System.EventArgs e)
{
DialogResult result = MessageBox.Show("是否删除此记录?", "提示!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
string SqlText = "delete from TransferInfo where aaId=" + int.Parse(this.dataGrid1[0,this.dataGrid1.CurrentCellAddress.Y].Value.ToString());
DataAccess DA = new DataAccess();
DA.ExeSQL(SqlText);
MessageBox.Show("删除成功!");
this.DBDataGrid();
}
if (result == DialogResult.No)
{
return;
}
}
//退出
private void ExitEmpChange(System.Object sender, System.EventArgs e)
{
this.Close();
}
//查询
private void Search(System.Object sender, System.EventArgs e)
{
this.group1.Visible = true;
this.dataGrid1.Dock = DockStyle.None;
this.dataGrid1.Location = new Point(0, 120);
this.dataGrid1.Height = 336;
}
//刷新数据显示
private void FormEmpChange_EnabledChanged(object sender, EventArgs e)
{
this.DBDataGrid();
}
private void button2_Click(object sender, EventArgs e)
{
this.group1.Visible = false;
this.dataGrid1.Dock = DockStyle.Fill;
this.DBDataGrid();
}
//处理查询
private void button1_Click(object sender, EventArgs e)
{
string SqlText = "select TransferInfo.aaId,TransferInfo.traId as 员工编号,EmployInfo.eName as 员工姓名,TransferInfo.tDate as 调动时间,TransferInfo.fSection as 调动前部门,";
SqlText += "TransferInfo.lSection as 调动后部门,TransferInfo.fJob as 调动前职务,TransferInfo.lJob as 调动后职务,TransferInfo.tReason as 调动原因,TransferInfo.tApp as 批准人,TransferInfo.tRemarks as [备注] ";
SqlText += " from TransferInfo,EmployInfo where EmployInfo.traId=TransferInfo.traId";
if (this.ID_txt.Text.Trim() != "")
{
SqlText += " and TransferInfo.traId=" + int.Parse(this.ID_txt.Text.Trim());
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.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 like '%[" + this.name_txt.Text + "]%'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.cm = (CurrencyManager)BindingContext[this.dt];
}
if (this.comboBox1.Text != "")
{
SqlText += " and TransferInfo.fSection='" + this.comboBox1.SelectedItem.ToString() + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.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.comboBox2.Text != "")
{
SqlText += " and TransferInfo.lSection='" + this.comboBox2.SelectedItem.ToString() + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
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.comboBox3.Text != "")
{
SqlText += " and TransferInfo.fJob='" + this.comboBox3.SelectedItem.ToString() + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.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.comboBox4.Text != "")
{
SqlText += " and TransferInfo.lJob='" + this.comboBox4.SelectedItem.ToString() + "'";
DataAccess DA = new DataAccess();
this.dt = DA.ExeSQLdt(SqlText);
this.dataGrid1.DataSource = this.dt.DefaultView;
this.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.InsertEmpChange(sender, e);
}
private void toolStripButton6_Click(object sender, EventArgs e)
{
this.UpdateEmpChange(sender, e);
}
private void toolStripButton7_Click(object sender, EventArgs e)
{
this.DeleteEmpChange(sender, e);
}
private void toolStripButton8_Click(object sender, EventArgs e)
{
this.Search(sender, e);
}
private void toolStripButton9_Click(object sender, EventArgs e)
{
this.ExitEmpChange(sender, e);
}
//
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -