C#OOP窗体(第三章上机1234)!!!

C#第oop第三章上机1234!!!

——码农小峯敲

内容:员工签到,拳头和实现增删改!
C#OOP窗体(第三章上机1234)!!!_第1张图片
C#OOP窗体(第三章上机1234)!!!_第2张图片

C#OOP窗体(第三章上机1234)!!!_第3张图片
话不多说,开始:

SE类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sj01
{
   public class SE
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public Gender gender { get; set; }
        public string Id { get; set; }
    }
}

SE枚举类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sj01
{
    public enum Gender
    {,}
}

打卡类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sj01
{
    public class Record
    {
        public DateTime signIntime { get; set; }
        public DateTime Signoutime { get; set; }
        public string ID { get; set; }
        public String Name { get; set; }
    }
}

Frmshow窗体:

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;
using System.Collections;

namespace sj01
{
    public partial class FrmShow : Form
    {
        public FrmShow()
        {
            InitializeComponent();
        }   
        public List<SE> SElist= new List<SE>();
        public Dictionary<string, Record> recorD = new Dictionary<string, Record>();
        //加载
        private void FrmShow_Load(object sender, EventArgs e)
        {
            SE se= new SE();
            se.Id = "111";
            se.Name = "222";
            se.Age = 12;
            se.gender = Gender.;
            this.SElist.Add(se);
            Bandgdv();
        }
        public void Bandgdv()
        {
            this.dataGridView1.DataSource = new BindingList<SE>(SElist);
        }
        
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count <= 0)
            {
                MessageBox.Show("请选择要删除的一行!");
                return;
            }
            DialogResult dr = MessageBox.Show("请问是否删除","提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.No)
            {
                return;
            }
            string id = this.dataGridView1.SelectedRows[0].Cells["clid"].Value.ToString();
            foreach (SE item in this.SElist)
            {
                if (item.Id ==id)
                {
                    SElist.Remove(item);
                    MessageBox.Show("删除成功!");
                    this.Bandgdv();
                    return;
                }
            }
        }

        private void 新增ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAdd frm = new FrmAdd();
            frm.fack = 1;
            frm.frmShow = this;
            frm.Show();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAdd frm = new FrmAdd();
            frm.fack = 0;
            frm.frmShow = this;
            frm.Show();
        }

        private void 打卡记录ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmQ frm = new FrmQ();
            frm.recod = this.recorD;
            frm.Show();
        }

        private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count != 1)
            {
                MessageBox.Show("请选择一行!");
                return;
            }
            string id = dataGridView1.CurrentRow.Cells["clId"].Value.ToString();
            if (this.recorD.ContainsKey(id))
            {
                MessageBox.Show("该员工已经签到了!");
                return;
            }

            Record record = new Record();
            record.ID = id;
            record.Name = this.dataGridView1.SelectedRows[0].Cells["clName"].Value.ToString();
            record.signIntime = DateTime.Now;
            this.recorD.Add(record.ID, record);
            MessageBox.Show("签到成功!");
        }

        private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.dataGridView1.SelectedRows.Count<=0)
            {
                MessageBox.Show("请选择一行!");
                return;
            }
            string id = dataGridView1.CurrentRow.Cells["clId"].Value.ToString();
            if (this.recorD.ContainsKey(id)==false)
            {
                MessageBox.Show("你今天还没签到!");
                return;
            }
            Record re = this.recorD[id];
            re.Signoutime = DateTime.Now;
            MessageBox.Show("签退成功!");

        }
        #region 查看
        private void button1_Click(object sender, EventArgs e)
        {
            List<SE> newList = new List<SE>();
            foreach (SE item in this.SElist)
            {
                if (item.Id.IndexOf(this.txtid.Text)!=-1)
                {
                    newList.Add(item);
                }
            }
            this.dataGridView1.DataSource = new BindingList<SE>(newList);
        }
        #endregion

    }
}

打卡记录窗体:

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 sj01
{
    public partial class FrmQ : Form
    {
        public FrmQ()
        {
            InitializeComponent();
        }
        public Dictionary<string, Record> recod;
        private void FrmQ_Load(object sender, EventArgs e)
        {
            this.label1.Text = "共有"+ recod.Count+"条记录!";
            BindingSource bs = new BindingSource();
            bs.DataSource = recod.Values;
            this.dataGridView1.DataSource = bs;
          
        }
    }
}

添加员工窗体:

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 sj01
{
    public partial class FrmAdd : Form
    {
        public FrmAdd()
        {
            InitializeComponent();
        }
        public int fack;
        public FrmShow frmShow;
        private void btnsave_Click(object sender, EventArgs e)
        {
            if (fack == 1)
            {
                ShowAdd();
            }
            if (fack == 0)
            {
                ShowUpdete();
            }         
        }

        private void FrmAdd_Load(object sender, EventArgs e)
        {
            this.cboSex.SelectedIndex = 0;
        }

        public void ShowAdd()
        {
            SE se = new SE();
            se.Id = this.txtNo.Text;
            se.Name = this.txtName.Text;
            se.Age =int.Parse(this.txtAge.Text);
            se.gender = (Gender)Enum.Parse(typeof(Gender), this.cboSex.Text);
            this.frmShow.SElist.Add(se);//添加
            this.frmShow.Bandgdv();//刷新
            this.Close();       
        }

        public void ShowUpdete()
        {

        }
    }
}

奥力给,干就完了!

你可能感兴趣的:(C#,窗体)