考勤信息管理 员工打卡

 1.主页面

代码如下:

 

  1 namespace 员工信息维护
  2 {
  3 public partial class FrmMain : Form
  4 {
  5 public FrmMain()
  6 {
  7 InitializeComponent();
  8 }
  9 
 10 //列表,用于保存 SE 对象
 11 public List<SE> programmerList = new List<SE>();
 12 //刷新DataGrindView数据
 13 public void BindGrid(List<SE> list)
 14 {
 15 this.dataGridView1.DataSource = new BindingList<SE>(list);
 16 }
 17 
 18 
 19 private void toolStripButton1_Click(object sender, EventArgs e)
 20 {
 21 frmMaintance jj = new frmMaintance();
 22 //调用父窗体
 23 jj.FrmParent = this;
 24 jj.Show();
 25 }
 26 
 27 private void toolStripButton4_Click(object sender, EventArgs e)
 28 {
 29 frmRecord dk = new frmRecord();
 30 dk.recordList = this.recordList;
 31 dk.Show();
 32 }
 33 
 34 private void big_Load(object sender, EventArgs e)
 35 {
 36 //xianshi();
 37 }
 38 //查询
 39 private void button1_Click(object sender, EventArgs e)
 40 {
 41 List<SE> tempList = new List<SE>();
 42 foreach(SE item in this.programmerList){
 43 if (item.no.IndexOf(this.textBox1.Text.Trim())!=-1) {
 44 tempList.Add(item);
 45 }
 46 
 47 this.dataGridView1.DataSource = new BindingList<SE>(tempList);
 48 }
 49 }
 50 
 51 private void toolStripButton3_Click(object sender, EventArgs e)
 52 {
 53 DialogResult re = MessageBox.Show("确认要删除该数据吗", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
 54 if (re == DialogResult.OK)
 55 {
 56 foreach (SE item in this.programmerList)
 57 {
 58 if (dataGridView1.SelectedRows[0].Cells[0].Value==item.no)
 59 {
 60 programmerList.Remove(item);
 61 break;
 62 }
 63 
 64 }
 65 MessageBox.Show("删除成功");
 66 this.dataGridView1.DataSource = new BindingList<SE>(programmerList);
 67 }
 68 //this.dataGridView1.DataSource = new BindingList<SE>(temp);
 69 
 70 }
 71 //签到
 72 
 73 
 74 public Dictionary<string, Records> recordList = new Dictionary<string, Records>();
 75 
 76 private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
 77 {
 78 //验证是否有选中的行
 79 if (this.dataGridView1.SelectedRows.Count != 1)
 80 {
 81 MessageBox.Show("请选中一行!");
 82 return;
 83 }
 84 //确保没有签到过
 85 string workNo = this.dataGridView1.CurrentRow.Cells[0].Value.ToString();
 86 MessageBox.Show(workNo);
 87 foreach (string id in recordList.Keys)
 88 {
 89 if (workNo == id)
 90 {
 91 MessageBox.Show("您已经签到过了!");
 92 return;
 93 }
 94 }
 95 //签到
 96 Records record = new Records();
 97 record.ID = workNo;
 98 record.Name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
 99 record.SignInTime = DateTime.Now;
100 //添加签到信息到记录中
101 this.recordList.Add(record.ID, record);
102 MessageBox.Show("签到成功!");
103 }
104 
105 private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
106 {
107 
108 //验证是否有选中的行
109 if (this.dataGridView1.SelectedRows.Count != 1)
110 {
111 MessageBox.Show("请选中一行!");
112 return;
113 }
114 string ID = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
115 //标识是否已签到过
116 bool isOut = false;
117 //遍历key,与ID对比,若相等可以签退,反之不行.
118 foreach (string key in recordList.Keys)
119 {
120 if (key == ID)
121 {
122 //签退时间
123 this.recordList[key].SignOutTime = DateTime.Now;
124 MessageBox.Show("签退成功!");
125 isOut = true;
126 break;
127 }
128 }
129 if (!isOut)
130 {
131 MessageBox.Show("很抱歉,尚未签到!");
132 }
133 
134 }
135 
136  
137 
138 }
139 
140 }

 

 

 

2.

 

 1 public partial class frmMaintance : Form
 2 {
 3 // big FrmParent = new big ();
 4 //初始化
 5 public frmMaintance()
 6 {
 7 InitializeComponent();
 8 this.comboBox1.SelectedIndex = 0;
 9 }
10 
11 
12 
13 //big FimParant=new big ();
14 //保存父窗体的引用
15 public FrmMain FrmParent { get; set; }
16 
17 // public static List<SE>programmerList=new List<SE>();
18 private void button1_Click(object sender, EventArgs e)
19 {
20 try
21 {
22 
23 SE pp = new SE();
24 pp.no = this.textBox1.Text.Trim();
25 pp.age = Int32.Parse(this.textBox2.Text.Trim());
26 pp.sex = this.comboBox1.Text;
27 pp.name = this.textBox3.Text;
28 foreach (SE item in FrmParent.programmerList)
29 {
30 if (pp.no == item.no)
31 {
32 MessageBox.Show("此工号已存在");
33 return;
34 }
35 }
36 FrmParent.programmerList.Add(pp);
37 this.Close();
38 
39 }
40 catch (Exception ex)
41 {
42 Console.WriteLine(ex.Message);
43 
44 }
45 finally 
46 {
47 //刷新父窗体信息
48 this.FrmParent.BindGrid(FrmParent.programmerList);
49 }
50 }
51 
52 private void frmMaintance_Load(object sender, EventArgs e)
53 {
54 
55 }
56 
57 }

 

posted @ 2017-03-22 11:07  <烟花易冷>  阅读(283)  评论(0编辑  收藏  举报