VB.net 2010 视频教程 VB.net 2010 视频教程 VB.net 2010 视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > c#教程 >
  • C#教程之员工打卡

  • 2019-01-12 21:39 来源:未知

一.主界面

 

复制代码
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 = "001", Name = "呵呵", Age = 20, Sex = "" });
            programmerList.Add(new SE() { ID = "002", Name = "哈哈", Age = 15, Sex = "" });
            programmerList.Add(new SE() { ID = "003", Name = "嘿嘿", Age = 12, Sex = "" });

            dataGridView1.DataSource = new BindingList<SE>(programmerList);
        }

  

        private void FrmMain_Load(object sender, EventArgs e)
        {
            xianShi();
        }

      
        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)
        {
           daka frm=new daka();
            frm.re = this.recordList;
            frm.Show();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            this.temp.Clear();
            chaXun();
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            zeng frm = new zeng();
            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("很抱歉,尚未签到!");
            }
        }

        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 day03_员工考勤信息管理
{
    public partial class zeng : Form
    {
        public Form1 FrmParent { get; set; }
        public zeng()
        {
            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)
        {

        }

        private void groupBox1_Enter(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 day03_员工考勤信息管理
{
    public partial class daka : Form
    {
        public Dictionary<string, dakalei> re { get; set; }
        public daka()
        {
            InitializeComponent();
        }

        private void dakajilu_Load(object sender, EventArgs e)
        {
              BindRecords();
        }
        public void BindRecords() 
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = re.Values;
            this.dataGridView1.DataSource = bs;
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

        }
        }
    }
复制代码

相关教程