• 用WinForm写的员工考勤项目!!!!!!


    地狱的镰刀

    这是我们所要用的到的三个窗体

    我们建一个辅助类,初始化一个单列的泛型集合,给单列的泛型集合付个初值

    class Worker
    
        {
    
            private string id;
    
            private string name;
    
            private int age;
    
            private string sex;
    
            public string ID
    
            {
    
                get
    
                {
    
                    return id;
    
                }
    
     
    
                set
    
                {
    
                    id = value;
    
                }
    
            }
    
     
    
            public string Name
    
            {
    
                get
    
                {
    
                    return name;
    
                }
    
     
    
                set
    
                {
    
                    name = value;
    
                }
    
            }
    
     
    
            public int Age
    
            {
    
                get
    
                {
    
                    return age;
    
                }
    
     
    
                set
    
                {
    
                    age = value;
    
                }
    
            }
    
     
    
            public string Sex
    
            {
    
                get
    
                {
    
                    return sex;
    
                }
    
     
    
                set
    
                {
    
                    sex = value;
    
                }
    
            }
    
             
    
            public static List<Worker> list = new List<Worker>();
    
            public static void Insert()
    
            {
    
                Worker w1 = new Worker();
    
                w1.ID = "20090101";
    
                w1.Name = "王小毛";
    
                w1.Age = 20;
    
                w1.Sex = "";
    
                list.Add(w1);
    
                Worker w2 = new Worker();
    
                w2.ID = "20090102";
    
                w2.Name = "周新雨";
    
                w2.Age = 19;
    
                w2.Sex = "";
    
                list.Add(w2);
    
            }
    
        
     
    这是员工信息维护窗体的Load事件的代码

    private
    void FrmSecond_Load(object sender, EventArgs e) {<br>如果list没有数据就添加数据,确保调用这个窗体是,只有在没有数据时才能添加数据! if (Worker.list.Count==0) { Worker.Insert(); }<br>清除datagridview的英文列,并且绑定数据 dgvList.AutoGenerateColumns = false; dgvList.DataSource = Worker.list; }
       这是新增里的代码
    ?
    private void toolStripButton1_Click(object sender, EventArgs e)
    
            {<br>调用添加员工员工信息窗体
    
                FrmFirst ff = new FrmFirst();
    
                this.Hide();
    
                ff.Show();
    
            }
     

     

    private void btn1_Click(object sender, EventArgs e)
    
            {<br>确保一个工号只能添加一次
    
                foreach (Worker item in Worker.list)
    
                {
    
                    if (item.ID==txt01.Text)
    
                    {
    
                        MessageBox.Show("工号已存在!!!!");
    
                        return;
    
                    }
    
                    
    
                }<br>添加一个员工信息
    
                Worker w1 = new Worker();
    
                w1.ID = txt01.Text;
    
                w1.Name = txt03.Text;
    
                w1.Age = Convert.ToInt32(txt02.Text);
    
                w1.Sex =cob01.Text;
    
                Worker.list.Add(w1);
    
                FrmSecond fs = new FrmSecond();
    
                this.Close();
    
                fs.Show();
    
     
    
            }
    这是删除的代码<br>private void toolStripButton3_Click(object sender, EventArgs e)
    
            {<br>提示点击是才会删除
    
                DialogResult result = MessageBox.Show("提示","是否删除",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
    
                if(result==DialogResult.Yes)
    
                {<br>
    
                    string id = dgvList.SelectedRows[0].Cells[0].Value.ToString();
    
                    //string id = dgvList.SelectedCells[0].Value.ToString();<br>如果ID和我选中的ID相等才会删除
    
                    foreach (Worker item in Worker.list)
    
                    {
    
                           if(item.ID==id)
    
                          {
    
                            Worker.list.Remove(item);
    
                            break;
    
                          }
    
                    }
    
                }
    
                //dgvList.AutoGenerateColumns = false;
    
                dgvList.DataSource = new BindingList<Worker>(Worker.list);
    
     
    
            }

     

    
    这是我们所要用的到的三个窗体
    
    我们建一个辅助类,初始化一个单列的泛型集合,给单列的泛型集合付个初值
    
    
    class Worker
    
        {
    
            private string id;
    
            private string name;
    
            private int age;
    
            private string sex;
    
            public string ID
    
            {
    
                get
    
                {
    
                    return id;
    
                }
    
     
    
                set
    
                {
    
                    id = value;
    
                }
    
            }
    
     
    
            public string Name
    
            {
    
                get
    
                {
    
                    return name;
    
                }
    
     
    
                set
    
                {
    
                    name = value;
    
                }
    
            }
    
     
    
            public int Age
    
            {
    
                get
    
                {
    
                    return age;
    
                }
    
     
    
                set
    
                {
    
                    age = value;
    
                }
    
            }
    
     
    
            public string Sex
    
            {
    
                get
    
                {
    
                    return sex;
    
                }
    
     
    
                set
    
                {
    
                    sex = value;
    
                }
    
            }
    
             
    
            public static List<Worker> list = new List<Worker>();
    
            public static void Insert()
    
            {
    
                Worker w1 = new Worker();
    
                w1.ID = "20090101";
    
                w1.Name = "王小毛";
    
                w1.Age = 20;
    
                w1.Sex = "";
    
                list.Add(w1);
    
                Worker w2 = new Worker();
    
                w2.ID = "20090102";
    
                w2.Name = "周新雨";
    
                w2.Age = 19;
    
                w2.Sex = "";
    
                list.Add(w2);
    
            }
    
        
    
    
    
    
    
    
    这是员工信息维护窗体的Load事件的代码
    
    private void FrmSecond_Load(object sender, EventArgs e)
    
           {<br>如果list没有数据就添加数据,确保调用这个窗体是,只有在没有数据时才能添加数据!
    
               if (Worker.list.Count==0)
    
               {
    
                   Worker.Insert();
    
               }<br>清除datagridview的英文列,并且绑定数据
    
               dgvList.AutoGenerateColumns = false;
    
               dgvList.DataSource = Worker.list;
    
           }
    
    
    
    
    
       这是新增里的代码
    
    
    
    
    ?
    private void toolStripButton1_Click(object sender, EventArgs e)
    
            {<br>调用添加员工员工信息窗体
    
                FrmFirst ff = new FrmFirst();
    
                this.Hide();
    
                ff.Show();
    
            }
    
    
    
    
    
     
    
    private void btn1_Click(object sender, EventArgs e)
    
            {<br>确保一个工号只能添加一次
    
                foreach (Worker item in Worker.list)
    
                {
    
                    if (item.ID==txt01.Text)
    
                    {
    
                        MessageBox.Show("工号已存在!!!!");
    
                        return;
    
                    }
    
                    
    
                }<br>添加一个员工信息
    
                Worker w1 = new Worker();
    
                w1.ID = txt01.Text;
    
                w1.Name = txt03.Text;
    
                w1.Age = Convert.ToInt32(txt02.Text);
    
                w1.Sex =cob01.Text;
    
                Worker.list.Add(w1);
    
                FrmSecond fs = new FrmSecond();
    
                this.Close();
    
                fs.Show();
    
     
    
            }
    
    
    
    
    
    
    
    ?
    
    这是删除的代码<br>private void toolStripButton3_Click(object sender, EventArgs e)
    
            {<br>提示点击是才会删除
    
                DialogResult result = MessageBox.Show("提示","是否删除",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
    
                if(result==DialogResult.Yes)
    
                {<br>
    
                    string id = dgvList.SelectedRows[0].Cells[0].Value.ToString();
    
                    //string id = dgvList.SelectedCells[0].Value.ToString();<br>如果ID和我选中的ID相等才会删除
    
                    foreach (Worker item in Worker.list)
    
                    {
    
                           if(item.ID==id)
    
                          {
    
                            Worker.list.Remove(item);
    
                            break;
    
                          }
    
                    }
    
                }
    
                //dgvList.AutoGenerateColumns = false;
    
                dgvList.DataSource = new BindingList<Worker>(Worker.list);
    
     
    
            }
    
    
    这段是重点难点在写这段之前先建好另一个辅助类<br>  class Record<br>    {<br>        public string id { get; set; }<br>        public string name { get; set; }<br>        public DateTime SignInTime { get; set; }<br>        public DateTime SignOutTime { get; set; }<br>        创建一个双列泛型集合<br>        public static Dictionary<string, Record> relist = new Dictionary<string, Record>();<br>       <br>    }<br> <br>public int num;
    
            private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
    
            {<br>给num赋值,把你选中的type值付给num
    
                Worker w = new Worker();
    
                foreach (Worker item in Worker.list)
    
                {
    
                    if (item.Name == dgvList.SelectedCells[1].Value.ToString())
    
                    {
    
                        w = item;
    
                        break;
    
                    }
    
                }
    
                num = w.type;<br>判断如果num是0才可以签到
    
                if (num == 0)
    
                {
    
                    Record r = new Record();
    
                    r.id = dgvList.SelectedRows[0].Cells[0].Value.ToString();
    
                    r.name = dgvList.SelectedRows[0].Cells[1].Value.ToString();
    
                    r.SignInTime = DateTime.Now;
    
                    Record.relist.Add(r.name, r);<br>给你选中的type赋值一个1
    
                    w.type = 1;
    
                    MessageBox.Show("签到成功");
    
                }
    
                else
    
                {
    
                    MessageBox.Show("您已经签到过了");
    
                }
    
            }
    
     
    
            private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
    
            {
    
                Worker w = new Worker();
    
                foreach (Worker item in Worker.list)
    
                {
    
                    if (item.Name == dgvList.SelectedCells[1].Value.ToString())
    
                    {
    
                        w = item;
    
                        break;
    
                    }
    
                }<br>把你选中的type赋值给num
    
                num = w.type;<br>如果num是1,才可以签退
    
                if (num == 1)
    
                {
    
                    foreach (string item in Record.relist.Keys)
    
                    {
    
                        if (item == dgvList.SelectedRows[0].Cells[1].Value.ToString())
    
                        {
    
                            Record.relist[dgvList.SelectedRows[0].Cells[1].Value.ToString()].SignOutTime = DateTime.Now;
    
                            w.type = 2;
    
                            MessageBox.Show("签退成功");
    
                            break;
    
                        }
    
                    }
    
                }<br>如果是0证明没有签到
    
                else if (num == 0)
    
                {
    
                    MessageBox.Show("没有签到,无法签退");
    
     
    
                }<br>否则已经签退过了
    
                else
    
                {
    
     
    
                    MessageBox.Show("您已经签退过了");
    
                }
    
     
    
            //dgvList.AutoGenerateColumns = false;
    
            //dgvList.DataSource = new BindingList<Worker>(Worker.list);
    
        } 
    
    
    <br>把员工的签到信息展示在DataGridView上<br><br>private void FrmThisd_Load(object sender, EventArgs e)
    
            {
    
                dgvList.AutoGenerateColumns = false;
    
                BindingSource bs = new BindingSource();
    
                bs.DataSource = Record.relist.Values;
    
                dgvList.DataSource = bs;
    
     
    
                lbl1.Text = dgvList.RowCount.ToString();
    
            } 
    
    
      
    
     
    
     
    <br>把员工的签到信息展示在DataGridView上<br><br>private void FrmThisd_Load(object sender, EventArgs e)
    
            {
    
                dgvList.AutoGenerateColumns = false;
    
                BindingSource bs = new BindingSource();
    
                bs.DataSource = Record.relist.Values;
    
                dgvList.DataSource = bs;
    
     
    
                lbl1.Text = dgvList.RowCount.ToString();
    
            }

      

      

     

  • 相关阅读:
    单位表示
    linux 文件权限
    php中高级基础知识点
    CodeIgniter配置之SESSION
    提高PHP开发质量的36个方法(精品)
    数据库优化举例详解
    ajax 跨域解决 网上资料
    static(静态)关键字
    假如java类里的成员变量是自身的对象
    Java 静态代码块&构造代码块&局部代码块
  • 原文地址:https://www.cnblogs.com/chengzixin/p/6539287.html
Copyright © 2020-2023  润新知