首页 > Python基础教程 >
-
C#教程之打卡系统
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 frmMaintance
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
this.dgvProgrammer.AutoGenerateColumns = false;
}
public List<SE> programmerList = new List<SE>();
private Dictionary<string, Record> recordList = new Dictionary<string, Record>();
public void BindGrid(List<SE> list)
{
this.dgvProgrammer.DataSource = new BindingList<SE>(list);
}
private void frmMain_Load(object sender, EventArgs e)
{
}
private void tsbtnAdd_Click(object sender, EventArgs e)
{
frmMaintance frm = new frmMaintance();
frm.MaintaceType = 1;
frm.FrmParent = this;
frm.ShowDialog();
}
private void tsbtnDelete_Click(object sender, EventArgs e)
{
if (this.dgvProgrammer.SelectedRows.Count != 1)
{
MessageBox.Show("请选中一行!");
return;
}
DialogResult rt = MessageBox.Show("确实要删除这个员工的信息吗?", "确认信息");
if (rt != DialogResult.OK)
{
return;
}
string workNo = dgvProgrammer.CurrentRow.Cells["workNo"].Value.ToString();
foreach (SE obj in programmerList)
{
if (obj.Id == workNo)
{
this.programmerList.Remove(obj);
break;
}
}
this.BindGrid(this.programmerList);
MessageBox.Show("删除成功!", "执行信息");
}
private void btnQuery_Click(object sender, EventArgs e)
{
List<SE> tempList = new List<SE>();
foreach(SE item in this.programmerList){
if (item.Id.IndexOf(this.txtID.Text.Trim()) != -1)
{
tempList.Add(item);
}
}
this.dgvProgrammer.DataSource = new BindingList<SE>(tempList);
}
private void tsmiSignIn_Click(object sender, EventArgs e)
{
if(this.dgvProgrammer.SelectedRows.Count!=1){
MessageBox.Show("请选中一行!");
return;
}
string workNo = dgvProgrammer.CurrentRow.Cells["workNo"].Value.ToString();
foreach(string id in recordList.Keys){
if(workNo==id){
MessageBox.Show("您已经签订过了!");
return;
}
}
Record record = new Record();
record.Id = workNo;
record.Name = dgvProgrammer.CurrentRow.Cells["name"].Value.ToString();
record.SignInTime = DateTime.Now;
this.recordList.Add(record.Id,record);
MessageBox.Show("签到成功!") ;
}
private void tsmiSignOut_Click(object sender, EventArgs e)
{
if(this.dgvProgrammer.SelectedRows.Count!=1){
MessageBox.Show("请选中一行!");
return;
}
string ID = dgvProgrammer.CurrentRow.Cells["workNo"].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){
MessageBox.Show("很抱歉,尚未签到!");
}
}
private void tbtnShowCardRecord_Click(object sender, EventArgs e)
{
frmmainready frm = new frmmainready();
frm.recordList = this.recordList;
frm.ShowDialog();
}
}
}
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 frmMaintance
{
public partial class frmmainready : Form
{
public frmmainready()
{
InitializeComponent();
}
public Dictionary<string,Record> recordList { get; set; }
private void frmmainready_Load(object sender, EventArgs e)
{
this.lbtitle.Text = string.Format("共有{0}条记录",this.recordList.Count);
BindingSource bs = new BindingSource();
bs.DataSource = recordList.Values;
dgvRecords.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 frmMaintance
{
public partial class frmMaintance : Form
{
public frmMain frmMain;
public frmMaintance()
{
InitializeComponent();
this.comboBox1.SelectedIndex = 0;
}
public int MaintaceType { get;set; }
public frmMain FrmParent { get; set; }
private void frmMaintance_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SE pr = new SE();
pr.Id =this.txt.Text.Trim();
pr.Age = Int32.Parse(this.textBox2.Text.Trim());
if (this.comboBox1.SelectedItem.ToString() == "男")
{
pr.Gender = Gender.男;
}
else
{
pr.Gender = Gender.女;
}
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);
}
}
}
}