第三章制作打卡考勤项目

[csharp] view plain copy
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
  
namespace GenericDemo  
{  
    public class SE  
    {  
        public string ID { get; set; }  
        public string Name { get; set; }  
        public int Age { get; set; }  
        public string Gender { get; set; }  
    }  
  
  
}  
[csharp] view plain copy
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
  
namespace GenericDemo  
{  
   public class Records  
    {  
        public DateTime SignInTime { get; set; }  
        public DateTime SignOutTime { get; set; }  
        public string ID { get; set; }  
        public string Name { get; set; }  
    }  
}  

[csharp] view plain copy
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 GenericDemo  
{  
    public partial class FrmMain : Form  
    {  
        public FrmMain()  
        {  
            InitializeComponent();  
        }  
        //窗体的跳转  
        private void toolStripButton1_Click(object sender, EventArgs e)  
        {  
            FrmMaintance frm = new FrmMaintance();  
            frm.MaintanceType = 1;  
            frm.FrmParent = this;  
            frm.Show();  
        }  
  
        //创建员工信息集合  
        public List<SE> programmerList = new List<SE>();  
        //显示数据  
        public void BindGrid(List<SE> list)  
        {  
            this.dvgprogrammer.DataSource = new BindingList<SE>(list);  
        }  
  
          
  
        private void btnSee_Click(object sender, EventArgs e)  
        {  
            IndexOf();  
        }  
  
        //模糊查询  
        public string IndexOf()  
        {  
            List<SE> tempList = new List<SE>();  
            foreach (SE item in this.programmerList)  
            {  
                if (item.ID.IndexOf(this.txtID.Text.Trim()) != -1)  
                {  
                    tempList.Add(item);  
                }                 
            }  
            //刷新  
            this.dvgprogrammer.DataSource = new BindingList<SE>(tempList);  
            return null;  
        }  
  
         
        //删除信息  
        private void toolStripButton3_Click(object sender, EventArgs e)  
        {  
            DialogResult result = MessageBox.Show("要删除员工信息吗?","输入提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);  
           // MessageBox.Show(result.ToString());  OK  
            if (result == DialogResult.OK)  
            {  
                foreach (SE item in programmerList)  
                {  
                    //选中整行时返回的值与员工ID相同时,删除所选中的  
                    if (this.dvgprogrammer.SelectedRows[0].Cells[0].Value.ToString() == item.ID)  
                    {  
                        this.programmerList.Remove(item);  
                        break;  
                    }  
                }  
                //刷新窗体  
                this.dvgprogrammer.DataSource = new BindingList<SE>(programmerList);  
            }  
        }  
  
        //打卡记录的Dictionary  
        public Dictionary<string, Records> recordList = new Dictionary<string, Records>();  
  
        //签到操作  
        private void tsmiSignIn_Click(object sender, EventArgs e)  
        {  
            //验证是否有选中的行  
            if (this.dvgprogrammer.SelectedRows.Count != 1)  
            {  
                MessageBox.Show("请选中一行!");  
                return;  
            }  
            //确保没有签到过  
            string workNo = dvgprogrammer.CurrentRow.Cells["workNo"].Value.ToString();  
            MessageBox.Show(workNo);  
            foreach (string id in recordList.Keys)  
            {  
                if (workNo == id)  
                {  
                    MessageBox.Show("您已经签到过了!");  
                    return;  
                }  
            }  
            //签到  
            Records record = new Records();  
            record.ID = workNo;  
            record.Name = this.dvgprogrammer.CurrentRow.Cells["name"].Value.ToString();  
            record.SignInTime = DateTime.Now;  
            //添加签到信息到记录中  
            this.recordList.Add(record.ID, record);  
            MessageBox.Show("签到成功!");  
        }  
  
        //签退操作  
        private void tsmiSignOut_Click(object sender, EventArgs e)  
        {  
            //验证是否有选中的行  
            if (this.dvgprogrammer.SelectedRows.Count != 1)  
            {  
                MessageBox.Show("请选中一行!");  
                return;  
            }  
            string ID = dvgprogrammer.CurrentRow.Cells["workNo"].Value.ToString();  
            //标识是否已签到过  
            bool isOut = false;  
            //遍历key,与ID对比,若相等可以签退,反之不行.  
            foreach (string key in recordList.Keys)  
            {  
                if (key == ID)  
                {  
                    //签退时间  
                    this.recordList[key].SignOutTime = DateTime.Now;  
                    MessageBox.Show("签退成功!");  
                    isOut = true;  
                    break;  
                }  
            }  
            if (!isOut)  
            {  
                MessageBox.Show("很抱歉,请签到!");  
            }  
        }  
  
         
        private void toolStripButton4_Click(object sender, EventArgs e)  
        {  
            FrmRecords frms = new FrmRecords();  
            frms.recordList = this.recordList;  
            frms.Show();  
        }  
  
    }  
}  

[csharp] view plain copy
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 GenericDemo  
{  
    public partial class FrmMaintance : Form  
    {  
        public FrmMain FrmParent { get; set; }  
        public FrmMaintance()  
        {  
            InitializeComponent();  
            //加载窗体时下拉框中为"男"  
            this.cmbGender.SelectedIndex = 0;  
        }  
  
       public  int MaintanceType;  
        private void FrmUpdate_Load(object sender, EventArgs e)  
        {  
              
        }  
  
         
        private void btnOK_Click(object sender, EventArgs e)  
        {  
            try  
            {   
                //插入数据  
                SE se = new SE();  
                se.ID = this.txtId.Text.Trim();  
                se.Name = this.txtName.Text.Trim();  
                se.Age = Int32.Parse(this.txtAge.Text.Trim());  
                if (this.cmbGender.SelectedItem.ToString() == "男")  
                {  
                    se.Gender = "男";  
                }  
                else  
                {  
                    se.Gender = "女";  
                }  
  
                //工号验证  
                if (FrmParent.programmerList.Equals(se.ID))  
                {  
                    MessageBox.Show("此工号存在!");  
                    return;  
                }  
                //将数据添加FrmMain窗体中的programmerList里  
                FrmParent.programmerList.Add(se);  
                MessageBox.Show("是否添加员工信息", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);  
                //添加成功,关闭窗体  
                this.Close();  
            }  
            catch (Exception ex)  
            {  
  
                MessageBox.Show(ex.Message);  
            }  
            finally  
            {  
                //刷新FrmMain窗体  
                this.FrmParent.BindGrid(FrmParent.programmerList);  
            }  
  
        }  
  
          
  
    }  
}  

[csharp] view plain copy
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 GenericDemo  
{  
     
  
    public partial class FrmRecords : Form  
    {   
        //打卡记录  
        public Dictionary<string, Records> recordList { get; set; }  
  
        public FrmRecords()  
        {  
            InitializeComponent();  
        }  
  
        private void FrmRecords_Load(object sender, EventArgs e)  
        {  
            BindingSource bs = new BindingSource();  
            bs.DataSource = recordList.Values;  
            this.dvgRecords.DataSource = bs;  
            Rows();  
        }  
  
        public void Rows()  
        {  
            int row = this.dvgRecords.RowCount;  
            this.lbRecord.Text = "共有" + row + "条打卡记录";  
        }  
    }  
}  

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值