员工打卡
namespace 员工信息维护
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
//列表,用于保存 SE 对象
public List<SE> programmerList = new List<SE>();
//刷新DataGrindView数据
public void BindGrid(List<SE> list)
{
this.dataGridView1.DataSource = new BindingList<SE>(list);
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
frmMaintance jj = new frmMaintance();
//调用父窗体
jj.FrmParent = this;
jj.Show();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
frmRecord dk = new frmRecord();
dk.recordList = this.recordList;
dk.Show();
}
private void big_Load(object sender, EventArgs e)
{
//xianshi();
}
//查询
private void button1_Click(object sender, EventArgs e)
{
List<SE> tempList = new List<SE>();
foreach(SE item in this.programmerList){
if (item.no.IndexOf(this.textBox1.Text.Trim())!=-1) {
tempList.Add(item);
}
this.dataGridView1.DataSource = new BindingList<SE>(tempList);
}
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
DialogResult re = MessageBox.Show("确认要删除该数据吗", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
if (re == DialogResult.OK)
{
foreach (SE item in this.programmerList)
{
if (dataGridView1.SelectedRows[0].Cells[0].Value==item.no)
{
programmerList.Remove(item);
break;
}
}
MessageBox.Show("删除成功");
this.dataGridView1.DataSource = new BindingList<SE>(programmerList);
}
//this.dataGridView1.DataSource = new BindingList<SE>(temp);
}
//签到
public Dictionary<string, Records> recordList = new Dictionary<string, Records>();
private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
{
//验证是否有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
//确保没有签到过
string workNo = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
MessageBox.Show(workNo);
foreach (string id in recordList.Keys)
{
if (workNo == id)
{
MessageBox.Show("您已经签到过了!");
return;
}
}
//签到
Records record = new Records();
record.ID = workNo;
record.Name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
record.SignInTime = DateTime.Now;
//添加签到信息到记录中
this.recordList.Add(record.ID, record);
MessageBox.Show("签到成功!");
}
private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
{
//验证是否有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
string ID = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//标识是否已签到过
bool isOut = false;
//遍历key,与ID对比,若相等可以签退,反之不行.
foreach (string key in recordList.Keys)
{
if (key == ID)
{
//签退时间
this.recordList[key].SignOutTime = DateTime.Now;
MessageBox.Show("签退成功!");
isOut = true;
break;
}
}
if (!isOut)
{
MessageBox.Show("很抱歉,尚未签到!");
}
}
}
}
public partial class frmMaintance : Form
{
// big FrmParent = new big ();
//初始化
public frmMaintance()
{
InitializeComponent();
this.comboBox1.SelectedIndex = 0;
}
//big FimParant=new big ();
//保存父窗体的引用
public FrmMain FrmParent { get; set; }
// public static List<SE>programmerList=new List<SE>();
private void button1_Click(object sender, EventArgs e)
{
try
{
SE pp = new SE();
pp.no = this.textBox1.Text.Trim();
pp.age = Int32.Parse(this.textBox2.Text.Trim());
pp.sex = this.comboBox1.Text;
pp.name = this.textBox3.Text;
foreach (SE item in FrmParent.programmerList)
{
if (pp.no == item.no)
{
MessageBox.Show("此工号已存在");
return;
}
}
FrmParent.programmerList.Add(pp);
this.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
//刷新父窗体信息
this.FrmParent.BindGrid(FrmParent.programmerList);
}
}
private void frmMaintance_Load(object sender, EventArgs e)
{
}
}
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
//列表,用于保存 SE 对象
public List<SE> programmerList = new List<SE>();
//刷新DataGrindView数据
public void BindGrid(List<SE> list)
{
this.dataGridView1.DataSource = new BindingList<SE>(list);
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
frmMaintance jj = new frmMaintance();
//调用父窗体
jj.FrmParent = this;
jj.Show();
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
frmRecord dk = new frmRecord();
dk.recordList = this.recordList;
dk.Show();
}
private void big_Load(object sender, EventArgs e)
{
//xianshi();
}
//查询
private void button1_Click(object sender, EventArgs e)
{
List<SE> tempList = new List<SE>();
foreach(SE item in this.programmerList){
if (item.no.IndexOf(this.textBox1.Text.Trim())!=-1) {
tempList.Add(item);
}
this.dataGridView1.DataSource = new BindingList<SE>(tempList);
}
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
DialogResult re = MessageBox.Show("确认要删除该数据吗", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
if (re == DialogResult.OK)
{
foreach (SE item in this.programmerList)
{
if (dataGridView1.SelectedRows[0].Cells[0].Value==item.no)
{
programmerList.Remove(item);
break;
}
}
MessageBox.Show("删除成功");
this.dataGridView1.DataSource = new BindingList<SE>(programmerList);
}
//this.dataGridView1.DataSource = new BindingList<SE>(temp);
}
//签到
public Dictionary<string, Records> recordList = new Dictionary<string, Records>();
private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
{
//验证是否有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
//确保没有签到过
string workNo = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
MessageBox.Show(workNo);
foreach (string id in recordList.Keys)
{
if (workNo == id)
{
MessageBox.Show("您已经签到过了!");
return;
}
}
//签到
Records record = new Records();
record.ID = workNo;
record.Name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
record.SignInTime = DateTime.Now;
//添加签到信息到记录中
this.recordList.Add(record.ID, record);
MessageBox.Show("签到成功!");
}
private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
{
//验证是否有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
string ID = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//标识是否已签到过
bool isOut = false;
//遍历key,与ID对比,若相等可以签退,反之不行.
foreach (string key in recordList.Keys)
{
if (key == ID)
{
//签退时间
this.recordList[key].SignOutTime = DateTime.Now;
MessageBox.Show("签退成功!");
isOut = true;
break;
}
}
if (!isOut)
{
MessageBox.Show("很抱歉,尚未签到!");
}
}
}
}
public partial class frmRecord : Form
{
public Dictionary<string, Records> recordList { get; set; }
public frmRecord()
{
InitializeComponent();
}
private void DK_Load(object sender, EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = recordList.Values;
this.dataGridView1.DataSource = bs;
Rows();
}
public void Rows()
{
int row = this.dataGridView1.RowCount;
this.label1.Text = "共有" + row + "条打卡记录";
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
//员工类
public class SE
{
public string no { get; set; }
public int age { get; set; }
public string name { get; set; }
public string sex { get; set; }
//打卡信息类
public class Records
{
public DateTime SignInTime { get; set; }
public DateTime SignOutTime { get; set; }
public string ID { get; set; }
public string Name { get; set; }
}
static class Program
{
// 应用程序的主入口点。
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FrmMain());
}
}