员工打卡课后小项目

Posted 大头杀马特

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了员工打卡课后小项目相关的知识,希望对你有一定的参考价值。

  public class Fm
    {
       //员工类
        public string Id { get; set; }
        public string Name { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
    }
 public class SI
    {
        //打卡类
        public string Name { get; set; }
        public DateTime Begin { get; set; }
        public DateTime End { get; set; }
    }

 

 
public partial class Yg : Form
    {
        public Yg()
        {
            InitializeComponent();
        }
        public static Qd qd;
        //初始化员工信息
        public static List<Fm> fm = new List<Fm>
        {
            new Fm{Id="20090101", Name="王小毛",Age=19,Gender=""},
            new Fm{Id="20090102", Name="周新宇",Age=19,Gender=""}
        };
        //保存打卡记录的集合
        public static List<SI> si = new List<SI>();
        private void Form1_Load(object sender, EventArgs e)
        {
            //绑定dgvlist
            dgv1.DataSource = fm;
        }

        public void info()
        {
            //更新dgvlist的数据源
            dgv1.DataSource = new BindingList<Fm>(fm);
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //打开新增员工的窗体)
            Wh frm = new Wh();
            frm.ygxx = this;
            frm.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //模糊查询的方法
            List<Fm> fm=new List<Fm>();
            foreach (Fm item in Yg.fm)
            {
                if (item.Id.IndexOf(txt1.Text.Trim()) >= 0)
                {
                    fm.Add(item);
                    
                }
                
            }
            dgv1.DataSource = new BindingList<Fm>(fm);
        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            //删除的方法
            if (dgv1.SelectedRows.Count > 0)
            {
                DialogResult dr = MessageBox.Show("确认要删除" + dgv1.SelectedRows[0].Cells[1].Value + "", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);
                if (dr == DialogResult.Yes)
                {
                    for (int i = 0; i < fm.Count; i++)
                    {
                        if (dgv1.SelectedRows[0].Cells[0].Value.ToString() == fm[i].Id)
                        {
                            fm.RemoveAt(i);
                            dgv1.DataSource = new BindingList<Fm>(fm);
                        }

                    }
                }
            }
        }

        private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //签到
            if (dgv1.SelectedRows.Count > 0)
            {
                int s = 0;
                foreach (SI item in si)
                {
                    if (item.Name == dgv1.SelectedRows[0].Cells[1].Value.ToString())
                    {
                        s++;
                    }
                }
                if (s == 0)
                {
                    SI sione = new SI();
                    sione.Name = dgv1.SelectedRows[0].Cells[1].Value.ToString();
                    sione.Begin = DateTime.Now;
                    si.Add(sione);
                    if (qd != null)
                    {
                        Qd.cishu = si.Count;
                        qd.info();
                    }
                }
                else
                {
                    MessageBox.Show("您已经签到过了", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                
            }
          
        }

        private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //签退
            if (dgv1.SelectedRows.Count > 0)
            {
                SI s = null;
                int count = 0;
                foreach (SI item in si)
                {
                    if (item.Name == dgv1.SelectedRows[0].Cells[1].Value.ToString() && item.End == Convert.ToDateTime("0001-1-1"))
                    {
                        s = item;
                    }
                    if (item.Name == dgv1.SelectedRows[0].Cells[1].Value.ToString())
                    {
                        count++;
                    }
                }
                if (s !=null)
                {
                    for (int i = 0; i < si.Count; i++)
                    {
                        if (si[i] == s)
                        {
                            si[i].End = DateTime.Now;
                            if (qd != null)
                            {
                                Qd.cishu = si.Count;
                                qd.info();
                            }
                        }
                    }
                }
                else if (count <= 0&&s==null)
                {
                    MessageBox.Show("您还未签到", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show("您已经签退过了", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
               
            }
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            //打开打卡记录
            Qd from = new Qd();
            Qd.cishu = si.Count;
            from.Show();

        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            //打开修改员工记录的窗体
            Wh from = new Wh();
            from.Text = "修改员工信息";
            from.ygxx = this;
            from.sid = dgv1.SelectedRows[0].Cells[0].Value.ToString();
            from.Show();
        }
    }

 private void button1_Click(object sender, EventArgs e)
        {
            //进入新增员工的方法
            if (this.Text == "员工信息维护")
            {
                int error = 0;
                //查看有没有该员工id
                foreach (Fm item in Yg.fm)
                {
                    if (txt1.Text == item.Id)
                    {
                        error++;
                    }
                }
                if (txt1.Text != null && txt2.Text != null && txt3.Text != null && cnb1.Text != null && error == 0)
                {

                    Fm fm = new Fm();
                    fm.Id = txt1.Text;
                    fm.Name = txt2.Text;
                    fm.Age = Convert.ToInt32(txt3.Text);
                    fm.Gender = cnb1.Text;
                    Yg.fm.Add(fm);
                    ygxx.info();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (error != 0)
                {
                    MessageBox.Show("员工号已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBox.Show("请完善员工信息", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
                //进入修改方法
            else
            {

                for (int i = 0; i < Yg.fm.Count; i++)
                {
                    if (Yg.fm[i].Id == sid)
                    {
                        Yg.fm[i].Id = txt1.Text;
                        Yg.fm[i].Name = txt2.Text;
                        Yg.fm[i].Age = Convert.ToInt32(txt3.Text);
                        Yg.fm[i].Gender = cnb1.Text;
                        ygxx.info();
                        MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
            }
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }
        //进入修改方法时传入要修改的员工信息
        private void Wh_Load(object sender, EventArgs e)
        {
            foreach (Fm item in Yg.fm)
            {
                if (item.Id == sid)
                {
                    txt1.Text = item.Id;
                    txt2.Text = item.Name;
                    txt3.Text = item.Age.ToString();
                    cnb1.Text = item.Gender;
                }
                
            }
        }
    }

    public partial class Qd : Form
    {
        public Qd()
        {
            InitializeComponent();
        }
        public static int cishu;
        private void qd_Load(object sender, EventArgs e)
        {
            Yg.qd = this;
            
            info();
            
        }
        //显示共有多少条记录
        public void info()
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = Yg.si;
            dataGridView1.DataSource = bs;
            this.label1.Text = "共有" + cishu + "条记录";
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
    }

 

以上是关于员工打卡课后小项目的主要内容,如果未能解决你的问题,请参考以下文章

经理评分课后小项目

简单的sql分组统计

请用sql实现查询出每个员工2019年10月份上班打卡次数,并按打卡次数从大到小排序卡次数从大到小排序?

使用C# WinForm制作 员工打卡项目 -- S2 2.3

微信小程序项目实例——打卡时钟

课后作业-阅读任务-阅读提问-3