Пример #1
0
 /// <summary>
 /// Enter键打卡
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TextBox1_KeyDown(object sender, KeyEventArgs e)
 {
     if (this.txtCarNm.Text.Trim().Length == 0 && e.KeyValue == 13)
     {
         MessageBox.Show("卡号不能为空!", "提示信息");
         this.txtCarNm.Focus();
         return;
     }
     //执行显示学员信息与打开操作
     try
     {
         if (e.KeyValue == 13)
         {
             var studentInfo = studentService.GetStudentInfoByCardNo(this.txtCarNm.Text.Trim());
             if (studentInfo == null)
             {
                 MessageBox.Show("卡号不正确!", "信息提示");
                 this.txtCarNm.SelectAll();
                 return;
             }
             //显示学员信息
             this.lblName.Text      = studentInfo.StudentName;
             this.lblStudentId.Text = studentInfo.StudentId.ToString();
             this.lblClassName.Text = studentInfo.ClassName;
             Attendance attendance = new Attendance {
                 CardNo = this.txtCarNm.Text.Trim(), DTime = DateTime.Now
             };
             var result = attendanceService.CardRecode(attendance);
             if (result != "success")
             {
                 this.lblResult.Text      = "打卡失败!";
                 this.lblResult.ForeColor = Color.Red;
                 MessageBox.Show(result, "错误提示");
             }
             else
             {
                 this.lblResult.Text      = "打卡成功!";
                 this.lblResult.ForeColor = Color.Lime;
             }
             this.txtCarNm.Text = ""; //等待下一个打卡
             this.txtCarNm.Focus();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }