日期:2014-05-18  浏览次数:20481 次

阅读器关闭时尝试调用 Read 无效。关于考勤的,代码贴出来给大侠们看,小弟新手。
public override void FillingRecord()
  {
  int pid = 0;
  OutgoingWebResponseContext outgoingResponse = WebOperationContext.Current.OutgoingResponse;
  outgoingResponse.Headers.Add("Cache-Control", "no-cache");
  outgoingResponse.Headers.Add("Pragma", "no-cache");
  IList<AttendanceMember> list = new List<AttendanceMember>();
  DateTime now = DateTime.Now;

  int checkStatus = 0;
  using (SqlDatabase db = new SqlDatabase())
  {
  //获取考勤参考时间
  db.Parameters.Clear();
  db.CommandText = "SELECT * FROM [dk_Attendance_Members]";
  using (DataReaderWrapper dr = db.ExecuteReader())
  {
  while (dr.Read())
  {
  AttendanceMember msg = new AttendanceMember();
  msg.AttendanceID = dr.GetInt32("AttendanceID");
  msg.MemberID = dr.GetInt32("MemberID");
  msg.CheckInTime = dr.GetDateTime("CheckInTime");
  msg.CheckOutTime = dr.GetDateTime("CheckOutTime");
  msg.Status = (AttendanceStatus)dr.GetInt32("Status");

  list.Add(msg);
   

  if (dr.Read())
  {
  DateTime checkInTimeStr = dr.GetDateTime("CheckInTime");
  DateTime checkOutTimeStr = dr.GetDateTime("CheckOutTime");
  pid = dr.GetInt32("MemberID");
  checkStatus = dr.GetInt32("Status");
  dr.Close();

  string today = now.ToString("yyyy-MM-dd");

  //确定今天是否已有的考勤记录
  db.Parameters.Clear();
  db.CommandText = "SELECT MemberID,CheckInTime, CheckOutTime FROM [dk_Attendance_Records] WHERE [MemberID] = @PID AND [AttendanceDate] = @Today";
  db.CreateParameter<int>("@PID", pid, System.Data.SqlDbType.Int);
  db.CreateParameter<string>("@Today", today, System.Data.SqlDbType.VarChar, 10);

  bool hasRecord = false;
  DateTime amTime = new DateTime();
  DateTime pmTime = new DateTime();
  using (DataReaderWrapper drw = db.ExecuteReader())
  {
  if (drw.Read())
  {
  //已有考勤记录,读取上下班的时间记录。
  hasRecord = true;
  amTime = drw.GetDateTime("CheckInTime");
  pmTime = drw.GetDateTime("CheckOutTime");
  }