C# WinForm考勤信息管理系统
程序员文章站
2022-05-13 20:21:14
...
项目地址:https://gitee.com/qiuyuhan/YuanGongDaKaGuanLiXiTong
Form1.cs
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 考勤信息管理
{
public partial class Form1 : Form
{
private List<SE> _listSe;
private Dictionary<SE,Record> _DicRecored;
public List<SE> ListSe { get => _listSe; set => _listSe = value; }
public Dictionary<SE, Record> DicRecored { get => _DicRecored; set => _DicRecored = value; }
public Form1()
{
InitializeComponent();
MyDB db = new MyDB();
ListSe = db.getSE();
this.DicRecored = new Dictionary<SE, Record>();
//绑定数据
this.BindingData();
}
public void BindingData()
{
//视图里面编辑列 设置DataPropertyName设置列对应的属性
this.dataGridView.DataSource = new BindingList<SE>(this.ListSe);
}
/// <summary>
/// 增加员工
/// </summary>
/// <param name="se"></param>
public void addSE(SE se)
{
this.ListSe.Add(se);
}
/// <summary>
/// 通过索引删除员工信息
/// </summary>
/// <param name="i"></param>
public void delSE(int i)
{
this.ListSe.RemoveAt(i);
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
addForm df = new addForm(this);
df.Show();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
//获取选中行的索引
int i=this.dataGridView.CurrentRow.Index;
updateForm f = new updateForm(this, this.ListSe[i]);
f.ShowDialog();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
DialogResult re=MessageBox.Show("确定删除?", "确定删除?", MessageBoxButtons.OKCancel);
if (re == DialogResult.OK)
{
int i = dataGridView.CurrentRow.Index;
this.ListSe.RemoveAt(i);
this.BindingData();
// MessageBox.Show("删除成功!");
}
}
private void 签到ToolStripMenuItem_Click(object sender, EventArgs e)
{
int i = this.dataGridView.CurrentRow.Index;
SE tse = this.ListSe[i];
if (DicRecored.ContainsKey(tse)==false)
{
Record r = new Record();
r.Signined = true;
r.SignInTime = DateTime.Now;
DicRecored.Add(tse, r);
MessageBox.Show("签到成功!");
}
else {
if (DicRecored[tse].Signined == true)
{
MessageBox.Show("不能重复签到");
}
}
}
private void button1_Click(object sender, EventArgs e)
{
string content=txtboxsearch.Text;
if (content == null || content == "")
{
this.BindingData();
return;
}
List<SE> tmpses = new List<SE>();
//遍历 利用 InedxOf 模糊查询
foreach (SE item in this.ListSe)
{
if (item.Id.ToString().IndexOf(this.txtboxsearch.Text) != -1 || item.Name.ToString().IndexOf(this.txtboxsearch.Text) != -1 || item.Sex.ToString().IndexOf(this.txtboxsearch.Text) != -1)
{
tmpses.Add(item);
}
}
this.dataGridView.DataSource = new BindingList<SE>(tmpses);
}
private void 签退ToolStripMenuItem_Click(object sender, EventArgs e)
{
int i = this.dataGridView.CurrentRow.Index;
SE tse = this.ListSe[i];
if (DicRecored.ContainsKey(tse) == false)
{
MessageBox.Show("还没有签到");
}
else
{
if (DicRecored[tse].SignOuted == true)
{
MessageBox.Show("不能重复签退");
}
else {
DicRecored[tse].SignOuted = true;
DicRecored[tse].SignOutTime = DateTime.Now;
MessageBox.Show("签退成功!");
}
}
}
private void toolStripButton4_Click(object sender, EventArgs e)
{
RecordForm rf = new RecordForm(this.DicRecored);
rf.ShowDialog();
}
}
}
MyDB.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 考勤信息管理
{
/// <summary>
/// 模拟数据库 获取 List<>
/// </summary>
class MyDB
{
public List<SE> getSE()
{
List<SE> db = new List<SE>();
db.Add(new SE(100, "邱于涵", 19, "男"));
db.Add(new SE(20090101, "王小毛", 19, "男"));
db.Add(new SE(20090102, "周鑫于", 19, "男"));
return db;
}
}
}
Record.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 考勤信息管理
{
public class Record
{
private DateTime signInTime; //签到时间
private DateTime signOutTime; //签退时间
private bool signined; //是是否签到
private bool signOuted; //是否签退
public DateTime SignInTime { get => signInTime; set => signInTime = value; }
public DateTime SignOutTime { get => signOutTime; set => signOutTime = value; }
public bool Signined { get => signined; set => signined = value; }
public bool SignOuted { get => signOuted; set => signOuted = value; }
public Record()
{
this.signined = false;
this.signOuted = false;
}
}
}
SE.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 考勤信息管理
{
/// <summary>
///
/// </summary>
public class SE
{
private int _id;
private string _name;
private int _age;
private string _sex;
// private bool _isSignined;//是否已签到
// private bool _isSignouted;//是否已签退
// private DateTime _SigninTime; //签到时间
// private DateTime _SignOutTime; //签退时间
public int Id { get => _id; set => _id = value; }
public string Name { get => _name; set => _name = value; }
public int Age { get => _age; set => _age = value; }
public string Sex { get => _sex; set => _sex = value; }
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="name"></param>
/// <param name="age"></param>
/// <param name="sex"></param>
public SE(int id, string name, int age, string sex)
{
this.Id = id;
this.Name = name;
this.Age = age;
this.Sex = sex;
}
}
}
addForm.cs
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 考勤信息管理
{
public partial class addForm : Form
{
private Form1 _form;
public Form1 Form { get => _form; set => _form = value; }
public addForm(Form1 form)
{
InitializeComponent();
this.Form = form;
this.comboBoxSex.SelectedIndex = 0;
}
private void btnSave_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(this.txtID.Text);
string name = this.txtName.Text;
int age = Convert.ToInt32(this.txtAge.Text);
string sex =(string) this.comboBoxSex.SelectedItem;
//添加
this.Form.addSE(new SE(id,name,age,sex));
//重新绑定
this.Form.BindingData();
this.Close();
}
}
}
RecordForm.cs
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 考勤信息管理
{
public partial class RecordForm : Form
{
public RecordForm(Dictionary<SE,Record> d)
{
InitializeComponent();
foreach (var item in d)
{
if (item.Value.Signined == true)
{
string name = item.Key.Name;
string datet = item.Value.SignInTime.ToString();
//动态增加
int index = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[index].Cells[0].Value = name;
this.dataGridView1.Rows[index].Cells[1].Value = "签到";
this.dataGridView1.Rows[index].Cells[2].Value = datet;
}
if (item.Value.SignOuted == true)
{
string name = item.Key.Name;
string datet = item.Value.SignOutTime.ToString();
//动态增加
int index = this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[index].Cells[0].Value = name;
this.dataGridView1.Rows[index].Cells[1].Value = "签退";
this.dataGridView1.Rows[index].Cells[2].Value = datet;
}
}
}
}
}
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 考勤信息管理
{
public partial class updateForm : Form
{
private SE _mse;
private Form1 _mmainForm;
public updateForm(Form1 mainForm,SE se)
{
InitializeComponent();
this.txtId.Text = Convert.ToString(se.Id);
this.txtage.Text = Convert.ToString(se.Age);
this.txtName.Text = se.Name;
if (se.Sex == "男")
{
this.comboBoxsex.SelectedIndex = 0;
}
else {
this.comboBoxsex.SelectedIndex = 1;
}
this._mse = se;
this._mmainForm = mainForm;
}
private void button1_Click(object sender, EventArgs e)
{
this._mse.Id = Convert.ToInt32(this.txtId.Text);
this._mse.Age = Convert.ToInt32(this.txtage.Text);
_mse.Name = this.txtName.Text;
if (this.comboBoxsex.SelectedIndex == 0)
{
_mse.Sex = "男";
}
else {
_mse.Sex = "女";
}
this._mmainForm.BindingData();
this.Close();
}
}
}
上一篇: PHP中的面向对象