using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _03_03员工项目
{
public enum Gendd
{
男,女
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _03_03员工项目
{
class Recor
{
//签到时间
public DateTime Time { get; set; }
//签退时间
public string outtime { get; set; }
//工号
public string ID { get; set; }
//员工姓名
public string name { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _03_03员工项目
{
public class SS
{
public string ID { get; set; }
public string name { get; set; }
public int age { get; set; }
public string Gender { 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;
namespace _03_03员工项目
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 新增ToolStripMenuItem_Click(object sender, EventArgs e)
{
xintian xt = new xintian();
xt.FromParment = this;
xt.Show();
}
//列表,用于保存SE对象
public List<SS> programmerlist = new List<SS>();
//刷新DataGridView数据
public void BindGrid(List<SS> list)
{
this.dataGridView1.DataSource = new BindingList<SS>(list);
}
private void button1_Click(object sender, EventArgs e) //查询
{
List<SS> templist = new List<SS>(); //用临时列表保存查询到的信息
foreach (SS item in this.programmerlist)
{
if (item.ID.IndexOf(this.textBox1.Text.Trim()) != -1)
{
templist.Add(item);
}
}
this.dataGridView1.DataSource = new BindingList<SS>(templist);
}
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult sanchu = MessageBox.Show("确定要删除吗","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Error);
if (sanchu == DialogResult.OK)
{
foreach (SS item in this.programmerlist)
{
if (dataGridView1.SelectedRows[0].Cells[0].Value == item.ID)
{
programmerlist.Remove(item);
break;
}
MessageBox.Show("删除成功");
this.dataGridView1.DataSource = new BindingList<SS>(programmerlist);
}
}
}
private Dictionary<string, Recor> recordlist = new Dictionary<string, Recor>();
private void 打卡记录ToolStripMenuItem_Click(object sender, EventArgs e)
{
qian();
tui();
}
private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
{
qian();
daka dd = new daka();
dd.Show();
}
public void qian()
{
//验证
//确保有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
//确保没有签到过
string work = dataGridView1.CurrentRow.Cells["work"].Value.ToString();
foreach (string id in recordlist.Keys)
{
if (work == id)
{
MessageBox.Show("您已经签到过!");
return;
}
}
//执行签到
Recor re = new Recor();
re.ID = work;
re.name = dataGridView1.CurrentRow.Cells["name"].Value.ToString();
re.Time = DateTime.Now;
this.recordlist.Add(re.ID, re);
MessageBox.Show("签到成功!");
}
private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
{
tui();
daka dd = new daka();
dd.Show();
}
public void tui()
{
//确保有选中的行
if (this.dataGridView1.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
string ID = dataGridView1.CurrentRow.Cells["work"].Value.ToString();
bool isout = false; //标识是否已经签到过
foreach (string key in recordlist.Keys)
{
if (key == ID)
{
//执行签到,设置签退时间
this.recordlist[key].Time = DateTime.Now;
MessageBox.Show("签退成功!");
break;
}
}
if (!isout)
{
MessageBox.Show("很抱歉,尚未签到!");
}
}
private void dataGridView1_Click(object sender, EventArgs e)
{
BindingSource bs = new BindingSource();
bs.DataSource = recordlist.Values;
this.dataGridView1.DataSource = bs;
}
private void Form1_Load(object sender, EventArgs e)
{
fujia();
}
public void fujia()
{
programmerlist.Add(new SS() { ID = "001", name = "陈翔", age = 20, Gender = "男" });
programmerlist.Add(new SS { ID = "002", name = "赵丽颖", age = 20, Gender = "女" });
programmerlist.Add(new SS { ID = "003", name = "唐嫣", age = 20, Gender = "女" });
dataGridView1.DataSource = new BindingList<SS>(programmerlist);
}
}
}
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 _03_03员工项目
{
public partial class xintian : Form
{
public Form1 FromParment { get; set; }
public xintian()
{
InitializeComponent();
this.sex.SelectedItem = 0;
}
private void button1_Click(object sender, EventArgs e) //保存
{
try
{
//输入处理
SS pr = new SS();
pr.ID = this.gonghao.Text.Trim();
pr.age = Int32.Parse(this.age.Text.Trim());
if (this.sex.SelectedItem.ToString() == "男")
{
pr.Gender = "男";
}
else
{
pr.Gender = "女";
}
pr.name = this.name.Text.Trim();
ArrayList list = new ArrayList();
//工号唯一
foreach (SS item in FromParment.programmerlist)
{
if (item.ID == pr.ID)
{
MessageBox.Show("此工号已经存在!");
return;
}
}
FromParment.programmerlist.Add(pr);
this.Close();
}
catch (Exception ex)
{
MessageBox.Show("出错", ex.Message);
}
finally
{
//刷新父窗体
this.FromParment.BindGrid(FromParment.programmerlist);
}
}
}
}