/// <summary> /// 获取数据 /// </summary> private DataSet GetEnterOutLogs() { try { if (Progress != null) { Progress("正在获取进出记录……"); } SeatManage.ClassModel.EnterOutLogStatistics lastStatisticsLog = SeatManage.Bll.T_SM_EnterOutLogStatistics.GetLastEnterOutLogStatistics(); int id = 0; if (lastStatisticsLog != null) { id = lastStatisticsLog.LastEnterOutLogID; } StringBuilder strSql = new StringBuilder(); strSql.Append("select EnterOutLogID,CardNo,EnterOutLogNo,TerminalNum,ReadingRoomNo,SeatNo,EnterOutState,EnterOutTime,EnterOutType,EnterFlag,Remark,MarkTime "); strSql.Append(" FROM T_SM_EnterOutLog_bak "); strSql.AppendFormat(" where EnterOutLogID>{0} order by EnterOutLogNo,EnterOutLogID", id.ToString()); DataSet ds = Query(strSql.ToString(), _New_connectionString, null); return(ds); } catch (Exception e) { if (Progress != null) { Progress("获取进出记录失败!" + e.Message); } return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SeatManage.ClassModel.EnterOutLogStatistics model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into T_SM_EnterOutLogStatistics("); strSql.Append("EnterOutLogNo,LastEnterOutID,CardNo,SeatNo,ReadingRoomNo,SelectSeatMode,LeaveModel,SelectSeatTime,LeaveSeatTime,SeatTime,ShortLeaveCount,ContinueTimeCount,AllOperationCount,AdminOperationCount,ReaderOperationCount,OtherOperationCount,ServerOperationCount,IsViolation)"); strSql.Append(" values ("); strSql.Append("@EnterOutLogNo,@LastEnterOutID,@CardNo,@SeatNo,@ReadingRoomNo,@SelectSeatMode,@LeaveModel,@SelectSeatTime,@LeaveSeatTime,@SeatTime,@ShortLeaveCount,@ContinueTimeCount,@AllOperationCount,@AdminOperationCount,@ReaderOperationCount,@OtherOperationCount,@ServerOperationCount,@IsViolation)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EnterOutLogNo", SqlDbType.NVarChar, 100), new SqlParameter("@LastEnterOutID", SqlDbType.Int, 4), new SqlParameter("@CardNo", SqlDbType.NVarChar, 20), new SqlParameter("@SeatNo", SqlDbType.NVarChar, 100), new SqlParameter("@ReadingRoomNo", SqlDbType.NVarChar, 50), new SqlParameter("@SelectSeatMode", SqlDbType.Int, 4), new SqlParameter("@LeaveModel", SqlDbType.Int, 4), new SqlParameter("@SelectSeatTime", SqlDbType.DateTime), new SqlParameter("@LeaveSeatTime", SqlDbType.DateTime), new SqlParameter("@SeatTime", SqlDbType.Int, 4), new SqlParameter("@ShortLeaveCount", SqlDbType.Int, 4), new SqlParameter("@ContinueTimeCount", SqlDbType.Int, 4), new SqlParameter("@AllOperationCount", SqlDbType.Int, 4), new SqlParameter("@AdminOperationCount", SqlDbType.Int, 4), new SqlParameter("@ReaderOperationCount", SqlDbType.Int, 4), new SqlParameter("@OtherOperationCount", SqlDbType.Int, 4), new SqlParameter("@ServerOperationCount", SqlDbType.Int, 4), new SqlParameter("@IsViolation", SqlDbType.Bit, 1) }; parameters[0].Value = model.EnterOutLogNo; parameters[1].Value = model.LastEnterOutLogID; parameters[2].Value = model.CardNo; parameters[3].Value = model.SeatNo; parameters[4].Value = model.ReadingRoomNo; parameters[5].Value = (int)model.SelectSeat; parameters[6].Value = (int)model.LeaveSeat; parameters[7].Value = model.SelectSeatTime; parameters[8].Value = model.LeaveSeatTime; parameters[9].Value = model.SeatTime; parameters[10].Value = model.ShortLeaveCount; parameters[11].Value = model.ContinueTimeCount; parameters[12].Value = model.AllOperationCount; parameters[13].Value = model.AdminOperationCount; parameters[14].Value = model.ReaderOperationCount; parameters[15].Value = model.OtherOperationCount; parameters[16].Value = model.ServerOperationCount; parameters[17].Value = model.IsViolation; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 获取数据 /// </summary> private void GetEnterOutLogs() { try { SeatManage.ClassModel.EnterOutLogStatistics lastStatisticsLog = SeatManage.Bll.T_SM_EnterOutLogStatistics.GetLastEnterOutLogStatistics(); int id = 0; if (lastStatisticsLog != null) { id = lastStatisticsLog.LastEnterOutLogID; } enterOutLogList = SeatManage.Bll.T_SM_EnterOutLog_bak.GetStatisticsLogs(id); _AllLogCount = enterOutLogList.Count; } catch { throw; } }
/// <summary> /// 添加一条统计记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public SeatManage.EnumType.HandleResult AddEnterOutStatistics(SeatManage.ClassModel.EnterOutLogStatistics model) { try { if (enteroutlogStatistics.Add(model) > 0) { return(SeatManage.EnumType.HandleResult.Successed); } else { return(SeatManage.EnumType.HandleResult.Failed); } } catch { throw; } }
/// <summary> /// 得到一个对象实体 /// </summary> public SeatManage.ClassModel.EnterOutLogStatistics GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,EnterOutLogNo,LastEnterOutID,CardNo,SeatNo,ReadingRoomNo,SelectSeatMode,LeaveModel,SelectSeatTime,LeaveSeatTime,SeatTime,ShortLeaveCount,ContinueTimeCount,AllOperationCount,AdminOperationCount,ReaderOperationCount,OtherOperationCount,ServerOperationCount,IsViolation from T_SM_EnterOutLogStatistics "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; SeatManage.ClassModel.EnterOutLogStatistics model = new SeatManage.ClassModel.EnterOutLogStatistics(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["EnterOutLogNo"] != null && ds.Tables[0].Rows[0]["EnterOutLogNo"].ToString() != "") { model.EnterOutLogNo = ds.Tables[0].Rows[0]["EnterOutLogNo"].ToString(); } if (ds.Tables[0].Rows[0]["LastEnterOutID"] != null && ds.Tables[0].Rows[0]["LastEnterOutID"].ToString() != "") { model.LastEnterOutLogID = int.Parse(ds.Tables[0].Rows[0]["LastEnterOutID"].ToString()); } if (ds.Tables[0].Rows[0]["CardNo"] != null && ds.Tables[0].Rows[0]["CardNo"].ToString() != "") { model.CardNo = ds.Tables[0].Rows[0]["CardNo"].ToString(); } if (ds.Tables[0].Rows[0]["SeatNo"] != null && ds.Tables[0].Rows[0]["SeatNo"].ToString() != "") { model.SeatNo = ds.Tables[0].Rows[0]["SeatNo"].ToString(); } if (ds.Tables[0].Rows[0]["ReadingRoomNo"] != null && ds.Tables[0].Rows[0]["ReadingRoomNo"].ToString() != "") { model.ReadingRoomNo = ds.Tables[0].Rows[0]["ReadingRoomNo"].ToString(); } if (ds.Tables[0].Rows[0]["SelectSeatMode"] != null && ds.Tables[0].Rows[0]["SelectSeatMode"].ToString() != "") { model.SelectSeat = (SeatManage.ClassModel.EnterOutLogSelectSeatMode) int.Parse(ds.Tables[0].Rows[0]["SelectSeatMode"].ToString()); } if (ds.Tables[0].Rows[0]["LeaveModel"] != null && ds.Tables[0].Rows[0]["LeaveModel"].ToString() != "") { model.LeaveSeat = (SeatManage.ClassModel.EnterOutLogLeaveSeatMode) int.Parse(ds.Tables[0].Rows[0]["LeaveModel"].ToString()); } if (ds.Tables[0].Rows[0]["SelectSeatTime"] != null && ds.Tables[0].Rows[0]["SelectSeatTime"].ToString() != "") { model.SelectSeatTime = DateTime.Parse(ds.Tables[0].Rows[0]["SelectSeatTime"].ToString()); } if (ds.Tables[0].Rows[0]["LeaveSeatTime"] != null && ds.Tables[0].Rows[0]["LeaveSeatTime"].ToString() != "") { model.LeaveSeatTime = DateTime.Parse(ds.Tables[0].Rows[0]["LeaveSeatTime"].ToString()); } if (ds.Tables[0].Rows[0]["SeatTime"] != null && ds.Tables[0].Rows[0]["SeatTime"].ToString() != "") { model.SeatTime = int.Parse(ds.Tables[0].Rows[0]["SeatTime"].ToString()); } if (ds.Tables[0].Rows[0]["ShortLeaveCount"] != null && ds.Tables[0].Rows[0]["ShortLeaveCount"].ToString() != "") { model.ShortLeaveCount = int.Parse(ds.Tables[0].Rows[0]["ShortLeaveCount"].ToString()); } if (ds.Tables[0].Rows[0]["ContinueTimeCount"] != null && ds.Tables[0].Rows[0]["ContinueTimeCount"].ToString() != "") { model.ContinueTimeCount = int.Parse(ds.Tables[0].Rows[0]["ContinueTimeCount"].ToString()); } if (ds.Tables[0].Rows[0]["AllOperationCount"] != null && ds.Tables[0].Rows[0]["AllOperationCount"].ToString() != "") { model.AllOperationCount = int.Parse(ds.Tables[0].Rows[0]["AllOperationCount"].ToString()); } if (ds.Tables[0].Rows[0]["AdminOperationCount"] != null && ds.Tables[0].Rows[0]["AdminOperationCount"].ToString() != "") { model.AdminOperationCount = int.Parse(ds.Tables[0].Rows[0]["AdminOperationCount"].ToString()); } if (ds.Tables[0].Rows[0]["ReaderOperationCount"] != null && ds.Tables[0].Rows[0]["ReaderOperationCount"].ToString() != "") { model.ReaderOperationCount = int.Parse(ds.Tables[0].Rows[0]["ReaderOperationCount"].ToString()); } if (ds.Tables[0].Rows[0]["OtherOperationCount"] != null && ds.Tables[0].Rows[0]["OtherOperationCount"].ToString() != "") { model.OtherOperationCount = int.Parse(ds.Tables[0].Rows[0]["OtherOperationCount"].ToString()); } if (ds.Tables[0].Rows[0]["ServerOperationCount"] != null && ds.Tables[0].Rows[0]["ServerOperationCount"].ToString() != "") { model.ServerOperationCount = int.Parse(ds.Tables[0].Rows[0]["ServerOperationCount"].ToString()); } if (ds.Tables[0].Rows[0]["IsViolation"] != null && ds.Tables[0].Rows[0]["IsViolation"].ToString() != "") { if ((ds.Tables[0].Rows[0]["IsViolation"].ToString() == "1") || (ds.Tables[0].Rows[0]["IsViolation"].ToString().ToLower() == "true")) { model.IsViolation = true; } else { model.IsViolation = false; } } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SeatManage.ClassModel.EnterOutLogStatistics model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update T_SM_EnterOutLogStatistics set "); strSql.Append("EnterOutLogNo=@EnterOutLogNo,"); strSql.Append("LastEnterOutID=@LastEnterOutID,"); strSql.Append("CardNo=@CardNo,"); strSql.Append("SeatNo=@SeatNo,"); strSql.Append("ReadingRoomNo=@ReadingRoomNo,"); strSql.Append("SelectSeatMode=@SelectSeatMode,"); strSql.Append("LeaveModel=@LeaveModel,"); strSql.Append("SelectSeatTime=@SelectSeatTime,"); strSql.Append("LeaveSeatTime=@LeaveSeatTime,"); strSql.Append("SeatTime=@SeatTime,"); strSql.Append("ShortLeaveCount=@ShortLeaveCount,"); strSql.Append("ContinueTimeCount=@ContinueTimeCount,"); strSql.Append("AllOperationCount=@AllOperationCount,"); strSql.Append("AdminOperationCount=@AdminOperationCount,"); strSql.Append("ReaderOperationCount=@ReaderOperationCount,"); strSql.Append("OtherOperationCount=@OtherOperationCount,"); strSql.Append("ServerOperationCount=@ServerOperationCount,"); strSql.Append("IsViolation=@IsViolation"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@EnterOutLogNo", SqlDbType.NVarChar, 100), new SqlParameter("@LastEnterOutID", SqlDbType.Int, 4), new SqlParameter("@CardNo", SqlDbType.NVarChar, 20), new SqlParameter("@SeatNo", SqlDbType.NVarChar, 100), new SqlParameter("@ReadingRoomNo", SqlDbType.NVarChar, 50), new SqlParameter("@SelectSeatMode", SqlDbType.Int, 4), new SqlParameter("@LeaveModel", SqlDbType.Int, 4), new SqlParameter("@SelectSeatTime", SqlDbType.DateTime), new SqlParameter("@LeaveSeatTime", SqlDbType.DateTime), new SqlParameter("@SeatTime", SqlDbType.Int, 4), new SqlParameter("@ShortLeaveCount", SqlDbType.Int, 4), new SqlParameter("@ContinueTimeCount", SqlDbType.Int, 4), new SqlParameter("@AllOperationCount", SqlDbType.Int, 4), new SqlParameter("@AdminOperationCount", SqlDbType.Int, 4), new SqlParameter("@ReaderOperationCount", SqlDbType.Int, 4), new SqlParameter("@OtherOperationCount", SqlDbType.Int, 4), new SqlParameter("@ServerOperationCount", SqlDbType.Int, 4), new SqlParameter("@IsViolation", SqlDbType.Bit, 1), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.EnterOutLogNo; parameters[1].Value = model.LastEnterOutLogID; parameters[2].Value = model.CardNo; parameters[3].Value = model.SeatNo; parameters[4].Value = model.ReadingRoomNo; parameters[5].Value = (int)model.SelectSeat; parameters[6].Value = (int)model.LeaveSeat; parameters[7].Value = model.SelectSeatTime; parameters[8].Value = model.LeaveSeatTime; parameters[9].Value = model.SeatTime; parameters[10].Value = model.ShortLeaveCount; parameters[11].Value = model.ContinueTimeCount; parameters[12].Value = model.AllOperationCount; parameters[13].Value = model.AdminOperationCount; parameters[14].Value = model.ReaderOperationCount; parameters[15].Value = model.OtherOperationCount; parameters[16].Value = model.ServerOperationCount; parameters[17].Value = model.IsViolation; parameters[18].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 开始计算 /// </summary> private void Statistics() { DataSet ds = GetEnterOutLogs(); if (ds == null) { return; } if (ds.Tables[0].Rows.Count == 0) { if (Progress != null) { Progress("没有获取到进出记录!"); } return; } List <SeatManage.ClassModel.EnterOutLogInfo> enterOutLogList = new List <SeatManage.ClassModel.EnterOutLogInfo>(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { enterOutLogList.Add(DataRowToEnterOutLogBakInfo(ds.Tables[0].Rows[i])); if (Progress != null) { Progress("转换中……" + i + "/" + ds.Tables[0].Rows.Count); } } SeatManage.ClassModel.EnterOutLogStatistics newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); for (int i = 0; i < enterOutLogList.Count; i++) { if (Progress != null) { Progress("统计中……" + i + "/" + enterOutLogList.Count + "成功" + _validFullEnterOutLogCount + "条,失败" + _ErrorEnterOutLogCount + "条"); } //判断状态 switch (enterOutLogList[i].EnterOutState) { case SeatManage.EnumType.EnterOutLogType.BookingConfirmation: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.BookAdmission; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.WaitingSuccess: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.WaitAdmission; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.ReselectSeat: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.ReSelect; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.SelectSeat: if (enterOutLogList[i].Flag == SeatManage.EnumType.Operation.Admin) { newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.AdminAllocation; } else { newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.ReadCardSelect; } newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.ContinuedTime: newStatistics.ContinueTimeCount++; break; case SeatManage.EnumType.EnterOutLogType.ShortLeave: newStatistics.ShortLeaveCount++; break; case SeatManage.EnumType.EnterOutLogType.ComeBack: newStatistics.AllOperationCount++; continue; case SeatManage.EnumType.EnterOutLogType.Leave: switch (enterOutLogList[i].Flag) { case SeatManage.EnumType.Operation.Admin: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.AdminReleased; break; case SeatManage.EnumType.Operation.Reader: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.ReaderReleased; break; case SeatManage.EnumType.Operation.Service: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.ServerReleased; break; } newStatistics.LastEnterOutLogID = int.Parse(enterOutLogList[i].EnterOutLogID); newStatistics.LeaveSeatTime = enterOutLogList[i].EnterOutTime; break; } //操作次数赋值 newStatistics.AllOperationCount++; switch (enterOutLogList[i].Flag) { case SeatManage.EnumType.Operation.Admin: newStatistics.AdminOperationCount++; break; case SeatManage.EnumType.Operation.OtherReader: newStatistics.OtherOperationCount++; break; case SeatManage.EnumType.Operation.Reader: newStatistics.ReaderOperationCount++; break; case SeatManage.EnumType.Operation.Service: newStatistics.ServerOperationCount++; break; } //判断日期是否正确 if (newStatistics.AllOperationCount > 1) { if (enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.Leave || i + 1 >= enterOutLogList.Count || enterOutLogList[i + 1].EnterOutLogNo != newStatistics.EnterOutLogNo) { if (newStatistics.LeaveSeatTime < newStatistics.SelectSeatTime && newStatistics.SelectSeatTime < enterOutLogList[i].EnterOutTime) { newStatistics.LeaveSeatTime = enterOutLogList[i].EnterOutTime; } if ((newStatistics.LeaveSeatTime.Date - newStatistics.SelectSeatTime.Date).TotalDays != 0) { newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); _ErrorEnterOutLogCount++; continue; } newStatistics.SeatTime = int.Parse((newStatistics.LeaveSeatTime - newStatistics.SelectSeatTime).TotalMinutes.ToString().Split('.')[0]); try { if (SeatManage.Bll.T_SM_EnterOutLogStatistics.AddEnterOutLogStatistics(newStatistics) == SeatManage.EnumType.HandleResult.Failed) { throw new Exception("添加进出记录统计失败!"); } _validFullEnterOutLogCount++; } catch (Exception ex) { WriteLog.Write(ex.Message); } newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); } } else if (enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.Leave || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ComeBack || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ContinuedTime || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ShortLeave) { newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); _ErrorEnterOutLogCount++; continue; } } if (Progress != null) { Progress(string.Format("计算进出记录数据{0}条,有效计算记录{1}条,无效数据{2}条", _AllLogCount, _validFullEnterOutLogCount, _ErrorEnterOutLogCount)); } }
/// <summary> /// 开始计算 /// </summary> private void Statistics() { GetEnterOutLogs(); SeatManage.ClassModel.EnterOutLogStatistics newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); for (int i = 0; i < enterOutLogList.Count; i++) { //判断状态 switch (enterOutLogList[i].EnterOutState) { case SeatManage.EnumType.EnterOutLogType.BookingConfirmation: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.BookAdmission; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.WaitingSuccess: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.WaitAdmission; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.ReselectSeat: newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.ReSelect; newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.SelectSeat: if (enterOutLogList[i].Flag == SeatManage.EnumType.Operation.Admin) { newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.AdminAllocation; } else { newStatistics.SelectSeat = SeatManage.ClassModel.EnterOutLogSelectSeatMode.ReadCardSelect; } newStatistics.CardNo = enterOutLogList[i].CardNo; newStatistics.SeatNo = enterOutLogList[i].SeatNo; newStatistics.ReadingRoomNo = enterOutLogList[i].ReadingRoomNo; newStatistics.EnterOutLogNo = enterOutLogList[i].EnterOutLogNo; newStatistics.SelectSeatTime = enterOutLogList[i].EnterOutTime; break; case SeatManage.EnumType.EnterOutLogType.ContinuedTime: newStatistics.ContinueTimeCount++; break; case SeatManage.EnumType.EnterOutLogType.ShortLeave: newStatistics.ShortLeaveCount++; break; case SeatManage.EnumType.EnterOutLogType.ComeBack: newStatistics.AllOperationCount++; continue; case SeatManage.EnumType.EnterOutLogType.Leave: switch (enterOutLogList[i].Flag) { case SeatManage.EnumType.Operation.Admin: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.AdminReleased; break; case SeatManage.EnumType.Operation.Reader: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.ReaderReleased; break; case SeatManage.EnumType.Operation.Service: newStatistics.LeaveSeat = SeatManage.ClassModel.EnterOutLogLeaveSeatMode.ServerReleased; break; } newStatistics.LastEnterOutLogID = int.Parse(enterOutLogList[i].EnterOutLogID); newStatistics.LeaveSeatTime = enterOutLogList[i].EnterOutTime; break; } //操作次数赋值 newStatistics.AllOperationCount++; switch (enterOutLogList[i].Flag) { case SeatManage.EnumType.Operation.Admin: newStatistics.AdminOperationCount++; break; case SeatManage.EnumType.Operation.OtherReader: newStatistics.OtherOperationCount++; break; case SeatManage.EnumType.Operation.Reader: newStatistics.ReaderOperationCount++; break; case SeatManage.EnumType.Operation.Service: newStatistics.ServerOperationCount++; break; } //判断日期是否正确 if (newStatistics.AllOperationCount > 1) { if (enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.Leave || i + 1 >= enterOutLogList.Count || enterOutLogList[i + 1].EnterOutLogNo != newStatistics.EnterOutLogNo) { if (newStatistics.LeaveSeatTime < newStatistics.SelectSeatTime && newStatistics.SelectSeatTime < enterOutLogList[i].EnterOutTime) { newStatistics.LeaveSeatTime = enterOutLogList[i].EnterOutTime; } if ((newStatistics.LeaveSeatTime.Date - newStatistics.SelectSeatTime.Date).TotalDays != 0) { newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); _ErrorEnterOutLogCount++; continue; } newStatistics.SeatTime = int.Parse((newStatistics.LeaveSeatTime - newStatistics.SelectSeatTime).TotalMinutes.ToString().Split('.')[0]); try { if (SeatManage.Bll.T_SM_EnterOutLogStatistics.AddEnterOutLogStatistics(newStatistics) == SeatManage.EnumType.HandleResult.Failed) { throw new Exception("添加进出记录统计失败!"); } _validFullEnterOutLogCount++; } catch (Exception ex) { WriteLog.Write(ex.Message); } newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); } } else if (enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.Leave || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ComeBack || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ContinuedTime || enterOutLogList[i].EnterOutState == SeatManage.EnumType.EnterOutLogType.ShortLeave) { newStatistics = new SeatManage.ClassModel.EnterOutLogStatistics(); _ErrorEnterOutLogCount++; continue; } } }
//[LastEnterOutID]=(select max( [LastEnterOutID] ) from [SeatManageDBV2].[dbo].[ViewEnterOutLogStatistics]) private SeatManage.ClassModel.EnterOutLogStatistics DataRowToEnterOutLogStatisticsModel(DataRow dr) { SeatManage.ClassModel.EnterOutLogStatistics model = new SeatManage.ClassModel.EnterOutLogStatistics(); if (dr["ID"] != null && dr["ID"].ToString() != "") { model.ID = int.Parse(dr["ID"].ToString()); } if (dr["EnterOutLogNo"] != null && dr["EnterOutLogNo"].ToString() != "") { model.EnterOutLogNo = dr["EnterOutLogNo"].ToString(); } if (dr["LastEnterOutID"] != null && dr["LastEnterOutID"].ToString() != "") { model.LastEnterOutLogID = int.Parse(dr["LastEnterOutID"].ToString()); } if (dr["CardNo"] != null && dr["CardNo"].ToString() != "") { model.CardNo = dr["CardNo"].ToString(); } if (dr["SeatNo"] != null && dr["SeatNo"].ToString() != "") { model.SeatNo = dr["SeatNo"].ToString(); } if (dr["ReadingRoomNo"] != null && dr["ReadingRoomNo"].ToString() != "") { model.ReadingRoomNo = dr["ReadingRoomNo"].ToString(); } if (dr["SelectSeatMode"] != null && dr["SelectSeatMode"].ToString() != "") { model.SelectSeat = (SeatManage.ClassModel.EnterOutLogSelectSeatMode) int.Parse(dr["SelectSeatMode"].ToString()); } if (dr["LeaveModel"] != null && dr["LeaveModel"].ToString() != "") { model.LeaveSeat = (SeatManage.ClassModel.EnterOutLogLeaveSeatMode) int.Parse(dr["LeaveModel"].ToString()); } if (dr["SelectSeatTime"] != null && dr["SelectSeatTime"].ToString() != "") { model.SelectSeatTime = DateTime.Parse(dr["SelectSeatTime"].ToString()); } if (dr["LeaveSeatTime"] != null && dr["LeaveSeatTime"].ToString() != "") { model.LeaveSeatTime = DateTime.Parse(dr["LeaveSeatTime"].ToString()); } if (dr["SeatTime"] != null && dr["SeatTime"].ToString() != "") { model.SeatTime = int.Parse(dr["SeatTime"].ToString()); } if (dr["ShortLeaveCount"] != null && dr["ShortLeaveCount"].ToString() != "") { model.ShortLeaveCount = int.Parse(dr["ShortLeaveCount"].ToString()); } if (dr["ContinueTimeCount"] != null && dr["ContinueTimeCount"].ToString() != "") { model.ContinueTimeCount = int.Parse(dr["ContinueTimeCount"].ToString()); } if (dr["AllOperationCount"] != null && dr["AllOperationCount"].ToString() != "") { model.AllOperationCount = int.Parse(dr["AllOperationCount"].ToString()); } if (dr["AdminOperationCount"] != null && dr["AdminOperationCount"].ToString() != "") { model.AdminOperationCount = int.Parse(dr["AdminOperationCount"].ToString()); } if (dr["ReaderOperationCount"] != null && dr["ReaderOperationCount"].ToString() != "") { model.ReaderOperationCount = int.Parse(dr["ReaderOperationCount"].ToString()); } if (dr["OtherOperationCount"] != null && dr["OtherOperationCount"].ToString() != "") { model.OtherOperationCount = int.Parse(dr["OtherOperationCount"].ToString()); } if (dr["ServerOperationCount"] != null && dr["ServerOperationCount"].ToString() != "") { model.ServerOperationCount = int.Parse(dr["ServerOperationCount"].ToString()); } if (dr["IsViolation"] != null && dr["IsViolation"].ToString() != "") { if ((dr["IsViolation"].ToString() == "1") || (dr["IsViolation"].ToString().ToLower() == "true")) { model.IsViolation = true; } else { model.IsViolation = false; } } if (dr["ReadingRoomName"] != null && dr["ReadingRoomName"].ToString() != "") { model.ReadingRoomName = dr["ReadingRoomName"].ToString(); } if (dr["LibraryName"] != null && dr["LibraryName"].ToString() != "") { model.LibraryName = dr["LibraryName"].ToString(); } if (dr["SchoolName"] != null && dr["SchoolName"].ToString() != "") { model.SchoolName = dr["SchoolName"].ToString(); } if (dr["LibraryNo"] != null && dr["LibraryNo"].ToString() != "") { model.LibraryNo = dr["LibraryNo"].ToString(); } if (dr["SchoolNo"] != null && dr["SchoolNo"].ToString() != "") { model.SchoolNo = dr["SchoolNo"].ToString(); } if (dr["ReaderName"] != null && dr["ReaderName"].ToString() != "") { model.ReaderName = dr["ReaderName"].ToString(); } if (dr["ReaderDeptName"] != null && dr["ReaderDeptName"].ToString() != "") { model.DeptName = dr["ReaderDeptName"].ToString(); } if (dr["ReaderTypeName"] != null && dr["ReaderTypeName"].ToString() != "") { model.TypeName = dr["ReaderTypeName"].ToString(); } return(model); }