员工考勤系统

 

 

员工考勤系统中的主要思想是,窗体间的传递以及datagridview之间的数据绑定刷新

public class SE

    {

        public string Id { get; set; }

        public string Name { get; set; }

        public int Age { get; set; }

        public string Sex { get; set; }

        

}

创建se类储存对象

public class Record

    {

        public DateTime intime { get; set; }

        public DateTime outtime { get; set; }

        public string id { get; set; }

        public string name { get; set; }

    }

创建 Record 储存打卡记录

public void Initial()

        {     

            SE student1=new SE();

            student1.Name="王小毛";

            student1.Sex="";

            student1.Id="001";

            student1.Age=19;

            SE student12=new SE();

            student12.Name="周新宇";

            student12.Sex="";

            student12.Id="002";

            student12.Age=19;

            SE student123 = new SE();

            student123.Name = "李四";

            student123.Sex = "";

            student123.Id = "003";

            student123.Age = 29;

            engineers.Add(student1);

            engineers.Add(student12);

            engineers.Add(student123);

            this.dataGridView1.DataSource = new BindingList<SE>(engineers);

        }

初始对象!

private void toolStripButton3_Click(object sender, EventArgs e)

        {

            string id = this.dataGridView1.SelectedRows[0].Cells[0] .Value.ToString();

                if (this.dataGridView1.SelectedRows.Count > 0)

                {

                    foreach (SE item in engineers)

                    {

                        if (item.Id == id)

                        {

                            this.engineers.Remove(item);

                            bindgrind(engineers);

                            return;

                        }

                    }

                }

                else

                {

                    MessageBox.Show("请选中一行!", "提示");

                }          

        }

这是实现删除功能最主要是搞清对象的字段值和当前datagridview中的选中的行的某一列值做对比

实现判断以便删除

private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            if (this.dataGridView1.SelectedRows.Count !=1)

            {

                MessageBox.Show("请选中一行!", "提示");

                return;

            }

                string ids = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();

                if (recordlist.Keys.Count==0)

                {

                    Record rd = new Record();

                    rd.id = ids;

                    //MessageBox.Show(rd.id);

                    rd.name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

                   // MessageBox.Show(rd.name);

                    rd.intime = DateTime.Now;

                    //MessageBox.Show(rd.intime.ToString());

                    recordlist.Add(rd.id, rd);

                    MessageBox.Show("签到成功!");

                }

                else

                {

                    foreach (string item in recordlist.Keys)

                    {

                        if (item == ids)

                        {

                            MessageBox.Show("你已经签过到!");

                            return;

                        }

                        else

                        {

                            Record rd = new Record();

                            rd.id = ids;

                            rd.name = this.dataGridView1.SelectedRows[0].Cells[1].Value.ToString();

                            rd.intime = DateTime.Now;

                            recordlist.Add(rd.id, rd);

                            MessageBox.Show("签到成功!");

                            return;

                        }

                    }

                }   

        }

签到功能这里最主要是判断签到过后再次签到时的判断这里注意一点如果你用的dictionary的话用foreach循环遍历的话如果是dictionary是空的话就不会循环遍历