一霎清明雨,实现考勤管理。
生活随笔
收集整理的這篇文章主要介紹了
一霎清明雨,实现考勤管理。
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
1.首先是添加員工信息:
public int type;//保存父窗體的引用public FrmMain FrmParent { get; set; }// public FrmAdd(){InitializeComponent();this.cboSex.SelectedIndex = 0;} 2.寫在保存按鈕里去:
try{//創(chuàng)建SE的對象SE se = new SE();se.ID = this.txtid.Text.Trim();se.Age = Int32.Parse(this.txtAge.Text.Trim());se.Name = this.txtName.Text.Trim();//姓名if (this.cboSex.SelectedItem.ToString() == "男"){se.Gender = Gender.男.ToString();}else{se.Gender = Gender.女.ToString();}//循環(huán)打印foreach (SE item in FrmParent.AddList){if (item.ID == se.ID){MessageBox.Show("此工號已經(jīng)存在!");return;}}//添加泛型集合里 FrmParent.AddList.Add(se);this.Close();}catch (Exception ex){MessageBox.Show(ex.Message);}finally{//刷新列表this.FrmParent.BindGrid(FrmParent.AddList);}
理解:
主窗口
public partial class FrmMain : Form{public FrmMain(){InitializeComponent();}public Dictionary<string, Record> dic = new Dictionary<string, Record>();//泛型集合public List<SE> AddList = new List<SE>();//刷新DataGridView數(shù)據(jù)public void BindGrid(List<SE> list){this.divList.DataSource = new BindingList<SE>(list);}//主窗口private void FrmMain_Load(object sender, EventArgs e){}//新增private void toolStripButton1_Click(object sender, EventArgs e){FrmAdd fm = new FrmAdd();fm.type = 1;fm.FrmParent = this;fm.ShowDialog();}//查看private void btnLook_Click(object sender, EventArgs e){List<SE> tempList = new List<SE>();//用于臨時列表保存查詢到的信息foreach (SE item in this.AddList){//如果泛型集合的SE下標(biāo)不等于-1if (item.ID.IndexOf(this.txtId.Text.Trim()) !=-1){tempList.Add(item);}}this.divList.DataSource = new BindingList<SE>(tempList);}//刪除private void toolStripButton3_Click(object sender, EventArgs e){DialogResult = MessageBox.Show("是否確定刪除?","提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);if (DialogResult ==DialogResult.Yes){//通過索引訪問List<SE> tempList = new List<SE>();foreach (SE item in this.AddList){tempList.Remove(item);}this.divList.DataSource = new BindingList<SE>(tempList);}}//修改private void toolStripButton2_Click(object sender, EventArgs e){}private void 簽到ToolStripMenuItem_Click(object sender, EventArgs e){//判斷是否選中一行if (this.divList.SelectedRows.Count != 1){MessageBox.Show("請選中一行!");return;}string workNo = divList.CurrentRow.Cells[0].Value.ToString();//遍歷Key值foreach (string item in dic.Keys){if (workNo == item){MessageBox.Show("您已經(jīng)簽到過!");return;}}Record record = new Record();record.ID = workNo;//id號 record.Name = divList.CurrentRow.Cells[1].Value.ToString();//獲取選中的姓名record.SignInTime = DateTime.Now;//當(dāng)前的時間this.dic.Add(record.ID,record);//添加到記錄里MessageBox.Show("簽到成功!");}private void 簽退ToolStripMenuItem_Click(object sender, EventArgs e){if (this.divList.SelectedRows.Count !=1){MessageBox.Show("請選擇一行!");return;}string ID = divList.CurrentRow.Cells[0].Value.ToString();bool isOut = false;//標(biāo)識是否已經(jīng)簽到過foreach (string item in dic.Keys){if (item == ID){this.dic[item].SignOutTime = DateTime.Now;MessageBox.Show("簽退成功!");isOut = true;break;}}if (!isOut){MessageBox.Show("很抱歉,尚未簽到!");}}private void toolStripButton4_Click(object sender, EventArgs e){Frmclock fm = new Frmclock();fm.FrmParent = this;fm.ShowDialog();}} public Frmclock(){InitializeComponent();}//保存父級public FrmMain FrmParent { get; set; } public void show(){BindingSource bs = new BindingSource();bs.DataSource = FrmParent.dic.Values;this.dataGridView1.DataSource = bs;}private void Frmclock_Load(object sender, EventArgs e){show();}
?
?
?
??
轉(zhuǎn)載于:https://www.cnblogs.com/www-yang-com/p/8723440.html
總結(jié)
以上是生活随笔為你收集整理的一霎清明雨,实现考勤管理。的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 刷OJ时输入输出与字符串
- 下一篇: 元素水平垂直居中的几种常用方法