第三章制作打卡考勤项目

来源:互联网 发布:淘宝联盟机器人发单 编辑:程序博客网 时间:2024/05/14 13:51
[csharp] view plain copyusing System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Threading.Tasks;    namespace GenericDemo  {      public class SE      {          public string ID { get; set; }          public string Name { get; set; }          public int Age { get; set; }          public string Gender { get; set; }      }      }  [csharp] view plain copyusing System;  using System.Collections.Generic;  using System.Linq;  using System.Text;  using System.Threading.Tasks;    namespace GenericDemo  {     public class Records      {          public DateTime SignInTime { get; set; }          public DateTime SignOutTime { get; set; }          public string ID { get; set; }          public string Name { get; set; }      }  }  [csharp] view plain copyusing 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 GenericDemo  {      public partial class FrmMain : Form      {          public FrmMain()          {              InitializeComponent();          }          //窗体的跳转          private void toolStripButton1_Click(object sender, EventArgs e)          {              FrmMaintance frm = new FrmMaintance();              frm.MaintanceType = 1;              frm.FrmParent = this;              frm.Show();          }            //创建员工信息集合          public List<SE> programmerList = new List<SE>();          //显示数据          public void BindGrid(List<SE> list)          {              this.dvgprogrammer.DataSource = new BindingList<SE>(list);          }                        private void btnSee_Click(object sender, EventArgs e)          {              IndexOf();          }            //模糊查询          public string IndexOf()          {              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.dvgprogrammer.DataSource = new BindingList<SE>(tempList);              return null;          }                     //删除信息          private void toolStripButton3_Click(object sender, EventArgs e)          {              DialogResult result = MessageBox.Show("要删除员工信息吗?","输入提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);             // MessageBox.Show(result.ToString());  OK              if (result == DialogResult.OK)              {                  foreach (SE item in programmerList)                  {                      //选中整行时返回的值与员工ID相同时,删除所选中的                      if (this.dvgprogrammer.SelectedRows[0].Cells[0].Value.ToString() == item.ID)                      {                          this.programmerList.Remove(item);                          break;                      }                  }                  //刷新窗体                  this.dvgprogrammer.DataSource = new BindingList<SE>(programmerList);              }          }            //打卡记录的Dictionary          public Dictionary<string, Records> recordList = new Dictionary<string, Records>();            //签到操作          private void tsmiSignIn_Click(object sender, EventArgs e)          {              //验证是否有选中的行              if (this.dvgprogrammer.SelectedRows.Count != 1)              {                  MessageBox.Show("请选中一行!");                  return;              }              //确保没有签到过              string workNo = dvgprogrammer.CurrentRow.Cells["workNo"].Value.ToString();              MessageBox.Show(workNo);              foreach (string id in recordList.Keys)              {                  if (workNo == id)                  {                      MessageBox.Show("您已经签到过了!");                      return;                  }              }              //签到              Records record = new Records();              record.ID = workNo;              record.Name = this.dvgprogrammer.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.dvgprogrammer.SelectedRows.Count != 1)              {                  MessageBox.Show("请选中一行!");                  return;              }              string ID = dvgprogrammer.CurrentRow.Cells["workNo"].Value.ToString();              //标识是否已签到过              bool isOut = false;              //遍历key,与ID对比,若相等可以签退,反之不行.              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 toolStripButton4_Click(object sender, EventArgs e)          {              FrmRecords frms = new FrmRecords();              frms.recordList = this.recordList;              frms.Show();          }        }  }  [csharp] view plain copyusing 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 GenericDemo  {      public partial class FrmMaintance : Form      {          public FrmMain FrmParent { get; set; }          public FrmMaintance()          {              InitializeComponent();              //加载窗体时下拉框中为"男"              this.cmbGender.SelectedIndex = 0;          }           public  int MaintanceType;          private void FrmUpdate_Load(object sender, EventArgs e)          {                        }                     private void btnOK_Click(object sender, EventArgs e)          {              try              {                   //插入数据                  SE se = new SE();                  se.ID = this.txtId.Text.Trim();                  se.Name = this.txtName.Text.Trim();                  se.Age = Int32.Parse(this.txtAge.Text.Trim());                  if (this.cmbGender.SelectedItem.ToString() == "男")                  {                      se.Gender = "男";                  }                  else                  {                      se.Gender = "女";                  }                    //工号验证                  if (FrmParent.programmerList.Equals(se.ID))                  {                      MessageBox.Show("此工号存在!");                      return;                  }                  //将数据添加FrmMain窗体中的programmerList里                  FrmParent.programmerList.Add(se);                  MessageBox.Show("是否添加员工信息", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);                  //添加成功,关闭窗体                  this.Close();              }              catch (Exception ex)              {                    MessageBox.Show(ex.Message);              }              finally              {                  //刷新FrmMain窗体                  this.FrmParent.BindGrid(FrmParent.programmerList);              }            }                    }  }  [csharp] view plain copyusing 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 GenericDemo  {             public partial class FrmRecords : Form      {           //打卡记录          public Dictionary<string, Records> recordList { get; set; }            public FrmRecords()          {              InitializeComponent();          }            private void FrmRecords_Load(object sender, EventArgs e)          {              BindingSource bs = new BindingSource();              bs.DataSource = recordList.Values;              this.dvgRecords.DataSource = bs;              Rows();          }            public void Rows()          {              int row = this.dvgRecords.RowCount;              this.lbRecord.Text = "共有" + row + "条打卡记录";          }      }  }  

0 0
原创粉丝点击