900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 员工考勤管理系统c语言 员工考勤信息管理小程序 考勤信息管理小程序

员工考勤管理系统c语言 员工考勤信息管理小程序 考勤信息管理小程序

时间:2021-08-23 05:01:12

相关推荐

员工考勤管理系统c语言 员工考勤信息管理小程序 考勤信息管理小程序

员工考勤信息管理小程序,考勤信息管理小程序

虽然这是个小程序,但是呢还是用到了许多的知识点的.主要是""使用集合组织相关数据."",这个知识点非常重要.

在以后搞大型的项目,绝对离不开"集合组织数据".例如:ArrayList动态存储数据,HashTable的数据结构(哈希表).

泛型集合:List和Dictionary

泛型类.

下面呢就是一个"员工信息管理"小程序.用来强化知识点.

首先,创几个类:

SE类

public classSE

{public string ID { get; set; }public int Age { get; set; }public Sex Gender { get; set; }public string Name { get; set; }

}

Gen类(枚举)

public classGen

{//public static 实现考勤信息管理.Gender 男 { get; set; }

}public enumSex

{

男, 女

}

Record类

{public classRecord

{//签到时间

public DateTime SingInTime { get; set; }//签退时间

public DateTime SingOutTime { get; set; }//工号

public string ID { get; set; }//员工姓名

public string Name { get; set; }

管理信息:

添加信息:

代码段:

public int MaintanceType { get; set; }//保存父窗体的引用

public FrmMain FrmParent { get; set; }//初始化//保存按钮的响应

private void btnOk_Click(objectsender, EventArgs e)

{try{

SE pr= newSE();

pr.ID= this.txtID1.Text.Trim();//工号

pr.Age = Int32.Parse(this.txtAge1.Text.Trim());//年龄

if (this.cmbgender1.SelectedIndex.ToString() == "男")//性别

{

pr.Gender=Sex.男;//这个也可以:pr.Gender=(Sex)(Enum.Parse(typeof(Sex),"男"));

}else{

pr.Gender=Sex.女;

}

pr.Name= this.txtName1.Text.Trim();//名字//添加操作//工号唯一性验证

if (this.MaintanceType == 1)

{foreach (SE item inFrmParent.programmerList)

{if (item.ID ==pr.ID)

{

MessageBox.Show("此工号已存在");return;

}

}

FrmParent.programmerList.Add(pr);

}this.Close();

}catch(Exception)

{

MessageBox.Show("出错啦");

}finally{this.FrmParent.BindGrid(FrmParent.programmerList);

}

看看主界面:

主界面的主要代码

查询信息:

//查询信息

private void btnLook_Click(objectsender, EventArgs e)

{//根据员工号进行模糊查询

List teapList = new List();//用临时列表保存查询到的信息

foreach (SE item in this.programmerList)

{if (item.ID.IndexOf(this.txtID.Text.Trim()) != -1)//indexof()实现模糊查询

{

teapList.Add(item);

}

}this.dgvlist.DataSource = new BindingList(teapList);

}

删除信息:

private void toolStripButton3_Click(objectsender, EventArgs e)

{if (this.dgvlist.SelectedRows.Count == 0)

{

MessageBox.Show("你还未选中要删除的信息,请选择!");return;

}

DialogResult result= MessageBox.Show("确认要删除吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);if (DialogResult.OK !=result)

{return;

}string sid = dgvlist.CurrentRow.Cells["ID"].Value.ToString();foreach (SE item inprogrammerList)

{if (item.ID ==sid)

{

programmerList.Remove(item);break;

}

}//刷新

BindGrid(programmerList);

MessageBox.Show("删除成功!");

}

签到:

代码段:

//签到菜单项,

private void 签到ToolStripMenuItem_Click(objectsender, EventArgs e)

{//验证//确保有选中的行

if (this.dgvlist.SelectedRows.Count != 1)

{

MessageBox.Show("请选择要签到的人");return;

}//确保没有签到过

string id = dgvlist.CurrentRow.Cells["ID"].Value.ToString();foreach (string item inrecordList.Keys)

{if (id ==item)

{

MessageBox.Show("您以前到过");return;

}

}//执行签到

Record record = newRecord();

record.ID=id;

record.Name= dgvlist.CurrentRow.Cells["Name"].Value.ToString();

record.SingInTime= DateTime.Now;//获取当前系统时间

this.recordList.Add(record.ID, record);//添加到记录中

MessageBox.Show("签到成功!!");

}

签退:

//签退操作

private void 签退ToolStripMenuItem_Click(objectsender, EventArgs e)

{//确保有选中行

if (this.dgvlist.SelectedRows.Count != 1)

{

MessageBox.Show("请选择!");return;

}string id = dgvlist.CurrentRow.Cells["ID"].Value.ToString();bool isOut = false;//标识是否已签过到

foreach (string item inrecordList.Keys)

{if (item ==id)

{//执行签到,设置签退时间

this.recordList[item].SingOutTime =DateTime.Now;

MessageBox.Show("签退成功!");

isOut= true;break;

}

}if (!isOut)

{

MessageBox.Show("很抱歉,尚未签到!");

}

}

打卡记录:

//打卡记录

public Dictionary recordList { get; set; }//数据绑定

private voidBindRecords()

{

lblcount.Text= "共有"+recordList.Count+"条打卡记录";//将Dictionary绑定到DataGridView控件

BindingSource bs= newBindingSource();#region 绑定数据源 BindingSource

/** 封装窗体的数据源。

public BindingSource();

//

// 摘要:

// 初始化 System.Windows.Forms.BindingSource 类的新实例,并将 System.Windows.Forms.BindingSource

// 添加到指定的容器。

//

// 参数:

// container:

// 要将当前 System.Windows.Forms.BindingSource 添加到的 ponentModel.IContainer。

*

public BindingSource(IContainer container);

//

// 摘要:

// 用指定的数据源和数据成员初始化 System.Windows.Forms.BindingSource 类的新实例。

//

// 参数:

// dataSource:

// System.Windows.Forms.BindingSource 的数据源。

//

// dataMember:

// 要绑定到的数据源中的特定列或列表名称。

public BindingSource(object dataSource, string dataMember);

// 摘要:

// 获取一个值,该值指示是否可以编辑基础列表中的项。

//

// 返回结果:

// true 指示列表项可以编辑;否则为 false。*/

#endregionbs.DataSource=recordList.Values;

dgvlist.DataSource=bs;

}private void FrmRecord_Load(objectsender, EventArgs e)

{

BindRecords();

}

这样最后呢,就可以完完整整的掌握了这些知识点------------------------------------

/C_jc/1101897.true/C_jc/1101897.htmlTechArticle员工考勤信息管理小程序,考勤信息管理小程序 虽然这是个小程序,但是呢还是用到了许多的知识点的.主要是""使用集合组织相关数据."",这...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。