灵魂项目 , 深入.NET ------- 员工打卡项目

来源:互联网 发布:程序员保密费 编辑:程序博客网 时间:2024/05/20 10:12
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 员工记录项目{    public partial class FrmMain : Form    {        //记录打卡记录的Dictionary        public Dictionary<string, Record> recordList = new Dictionary<string, Record>();        //用来存放临时表        List<SE> temp = new List<SE>();        public FrmMain()        {            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 = 28, Sex = "男" });            dataGridView1.DataSource = new BindingList<SE>(programmerList);        }        private void toolStripButton1_Click(object sender, EventArgs e)        {            Form2 f = new Form2();            f.FrmParent = this;            f.ShowDialog();        }        private void button1_Click(object sender, EventArgs e)        {            this.temp.Clear();            chaxun();        }        private void FrmMain_Load(object sender, EventArgs e)        {            xianshi();        }        public void chaxun()        {            foreach (SE item in this.programmerList)            {                if (item.ID.IndexOf(this.txtno.Text.Trim()) != -1)                {                    temp.Add(item);                }            }            this.dataGridView1.DataSource = new BindingList<SE>(temp);        }        private void toolStripButton3_Click(object sender, EventArgs e)        {            DialogResult r = MessageBox.Show("确认删除吗?", "提示");            if (r == 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 签到ToolStripMenuItem_Click(object sender, EventArgs e)        {            //验证            //确保有选中的行            if (this.dataGridView1.SelectedRows.Count != 1)            {                MessageBox.Show("请选中一行");                return;            }             string Id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();            foreach (string id in recordList.Keys)            {                if (Id == id)                {                    MessageBox.Show("您已经签过到了");                    return;                }            }            //执行签到            Record re = new Record();            re.ID = Id;            re.Name = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();            re.SignInTime = DateTime.Now; //获取系统当前时间            this.recordList.Add(re.ID, re);            MessageBox.Show("签到成功");        }            private void toolStripButton4_Click(object sender, EventArgs e)        {            FrmRecord frm = new FrmRecord();            frm.re = this.recordList;            frm.ShowDialog();        }               //签退        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("很抱歉,尚未签到!");            }        }        private void dataGridView1_MouseClick(object sender, MouseEventArgs e)        {        }        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)        {        }        }    }

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 员工记录项目{    public partial class Form2 : Form    {        public FrmMain FrmParent { get; set; }        public Form2()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            try            {                SE pr = new SE();                pr.ID = this.txtno.Text.Trim(); //工号                pr.Name = this.txtname.Text.Trim(); //姓名                pr.Age = Int32.Parse(this.txtage.Text.Trim()); //年龄                pr.Sex = this.cbsex.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 Form2_Load(object sender, EventArgs e)        {        }    }}

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 员工记录项目{    public partial class FrmRecord : Form    {        //打卡记录        public Dictionary<string, Record> re { get; set; }        public FrmRecord()        {            InitializeComponent();        }        private void FrmRecord_Load(object sender, EventArgs e)        {            BindRecords();        }        public void BindRecords()        {            BindingSource bs = new BindingSource();            bs.DataSource = re.Values;            this.dataGridView1.DataSource = bs;        }    }}

0 0