员工考勤

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
  
namespace day03_员工考勤信息管理  
{  
   public class dakalei  
    {         
        public DateTime SignInTime { get; set; }//签到时间        
        public DateTime SignOutTime { get; set; } //签退时间      
        public string  ID { get; set; }  //工号        
        public string Name { get; set; } //姓名  
    }  
    }  
  
  
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
  
namespace day03_员工考勤信息管理  
{  
    public partial class Form1 : Form  
    {  
        //记录打卡记录的Dictionary  
        public Dictionary<string, dakalei> recordList = new Dictionary<string, dakalei>();  
        //用来存放临时表  
        List<SE> temp = new List<SE>();  
        public Form1()  
        {  
            InitializeComponent();  
        }  
  
        //列表,用于保存 se对象  
        public List<SE> programmerList = new List<SE>();  
        //刷新DataGridview 数据  
        public void BindGrid(List<SE> list)   
        {  
            this.dataGridView1.DataSource = new BindingList<SE>(list);  
        }  
  
        private void xianShi()  
        {  
       
  
            programmerList.Add(new SE() { ID = "1", Name = "大豆", Age = 12, Sex = "男" });  
            programmerList.Add(new SE() { ID = "2", Name = "黄", Age = 12, Sex = "男" });  
            programmerList.Add(new SE() { ID = "2", Name = "小毛豆", Age = 12, Sex = "男" });  
  
            dataGridView1.DataSource = new BindingList<SE>(programmerList);  
        }  
  
    
  
        private void FrmMain_Load(object sender, EventArgs e)  
        {  
            xianShi();  
        }  
  
        /// <summary>  
        /// 根据员工工号进行模糊查询  
        /// </summary>  
        public void chaXun()   
        {  
            //用来存放临时表  
          //  List<SE> temp = new List<SE>();  
            foreach (SE item in this.programmerList)  
            {  
                if (item.ID.IndexOf(this.textBox1.Text.Trim())!=-1)  
                {  
                    temp.Add(item);  
                }  
            }  
            this.dataGridView1.DataSource = new BindingList<SE>(temp);  
        }  
  
         
         
  
        private void toolStripButton4_Click(object sender, EventArgs e)  
        {  
        
        }  
  
        private void Form1_Load(object sender, EventArgs e)  
        {  
            xianShi();  
        }  
  
        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)  
        {  
          
        }  
  
        private void toolStripLabel2_Click(object sender, EventArgs e)  
        {  
  
        }  
  
      
        private void toolStripButton3_Click_1(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.ID)  
                    {  
                        programmerList.Remove(item);  
                        break;  
                    }  
  
                }  
                MessageBox.Show("删除成功");  
                this.dataGridView1.DataSource = new BindingList<SE>(programmerList);  
            }  
        }  
  
        private void toolStripButton4_Click_1(object sender, EventArgs e)  
        {  
           dakajilu frm=new dakajilu();  
            frm.re = this.recordList;  
            frm.ShowDialog();  
        }  
  
        private void button1_Click_1(object sender, EventArgs e)  
        {  
            this.temp.Clear();  
            chaXun();  
        }  
  
        private void toolStripButton1_Click(object sender, EventArgs e)  
        {  
            xinxiweihu frm = new xinxiweihu();  
            frm.FrmParent = this;  
            frm.ShowDialog();  
        }  
  
        private void toolStripButton2_Click(object sender, EventArgs e)  
        {  
  
        }  
  
        private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)  
        {  
                 if (this.dataGridView1.SelectedRows.Count!=1)  
               {  
                MessageBox.Show("请选中一行");  
                return;  
               }   
            //确保没有签过到  
  
            string workID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();  
            foreach (string id in recordList.Keys)  
            {  
                if (workID==id)  
                {  
                    MessageBox.Show("您已经签过到了");  
                    return;  
                }  
            }  
            //执行签到  
            dakalei re = new dakalei();  
            re.ID=workID;  
           // re.Name = dataGridView1.CurrentRow.Cells["Column2"].Value.ToString();  
            re.Name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();  
            re.SignInTime = DateTime.Now; //获取系统当前时间  
            this.recordList.Add(re.ID,re);  
            MessageBox.Show("签到成功");  
        }  
  
        private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)  
        {  
             if (this.dataGridView1.SelectedRows.Count !=1)  
            {  
                MessageBox.Show("请选中一行");  
                return;  
            }  
            string ID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();  
            bool isOut = false;  //标识是否已经签到过  
            foreach (string key in recordList.Keys)  
            {  
                if (key==ID)  
                {  
                    //执行签退 设置签退时间  
                    this.recordList[key].SignOutTime = DateTime.Now;  
                    MessageBox.Show("签退成功");  
                    isOut = true;  
                    break;  
                }  
            }  
            if (isOut==false)  
            {  
                MessageBox.Show("很抱歉,尚未签到!");  
            }  
        }  
        }  
              
                  
            }  
   
      
  
  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
  
namespace day03_员工考勤信息管理  
{  
    static class Program  
    {  
        /// <summary>  
        /// 应用程序的主入口点。  
        /// </summary>  
        [STAThread]  
        static void Main()  
        {  
            Application.EnableVisualStyles();  
            Application.SetCompatibleTextRenderingDefault(false);  
            Application.Run(new Form1());  
        }  
    }  
}  
  
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
  
namespace day03_员工考勤信息管理  
{  
   public class SE  
    {  
       public string ID { get; set; }//工号  
       public int Age { get; set; }//年龄  
        public string Name { get; set; }//姓名  
       public string Sex { get; set; }//性别  
  
    }  
}  
  
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
  
namespace day03_员工考勤信息管理  
{  
    public partial class xinxiweihu : Form  
    {  
        public Form1 FrmParent { get; set; }  
        public xinxiweihu()  
        {  
            InitializeComponent();  
            //this.comboBox1.SelectedIndex = 0;  
        }  
        private void button1_Click(object sender, EventArgs e)  
        {  
            try  
            {  
                SE pr = new SE();  
                pr.ID = this.textBox1.Text.Trim();//工号  
                pr.Age = Int32.Parse(this.textBox2.Text.Trim());//年龄  
                if (this.comboBox1.SelectedItem.ToString() == "男")//性别  
                {  
                    pr.Sex = "男";  
                }  
                else  
                {  
                    pr.Sex = "女";  
                }  
                pr.Name = this.textBox3.Text.Trim();  
  
                //添加操作 工号唯一验证                  
                foreach (SE item in FrmParent.programmerList)  
                {  
                    if (item.ID == pr.ID)  
                    {  
                        MessageBox.Show("此工号以存在");  
                        return;  
                    }  
                }  
                FrmParent.programmerList.Add(pr);  
                this.Close();  
            }  
            catch (Exception ex)  
            {  
  
                MessageBox.Show("出错" + ex.Message);  
            }  
            finally  
            {  
                //刷新父窗体  
                this.FrmParent.BindGrid(FrmParent.programmerList);  
            }  
        }  
  
        private void xinxiweihu_Load(object sender, EventArgs e)  
        {  
  
        }  
  
    }  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值