——码农小峯敲
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; }
}
}
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; }
}
}
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()
{
}
}
}
奥力给,干就完了!