/// <summary> /// 查询标识 /// </summary> /// <returns></returns> public DownloadIdentify FindIdentify() { DownloadIdentify obj = new DownloadIdentify(); MySqlConnection conn = null; MySqlCommand cmd = new MySqlCommand(); string sql = "select * from download_identify where id = 1"; try { conn = GetConnection(); cmd.CommandText = sql; cmd.Connection = conn; var reader = cmd.ExecuteReader(); if (reader.Read()) { obj.Id = reader.IsDBNull(0) ? default(int) : reader.GetInt32(0); obj.UpdateTime = reader.IsDBNull(1) ? default(DateTime) : reader.GetDateTime(1); } } catch (Exception ex) { log.Error("获取下载数据标识发生异常", ex); } finally { cmd.Dispose(); CloseConnection(conn); } return(obj); }
/// <summary> /// 需要下载数据 /// </summary> /// <returns></returns> public bool NeedDownload() { DownloadIdentify obj = FindIdentify(); DateTime last = obj.UpdateTime; DateTime now = DateTime.Now; //表示上次下载数据是今天的某个时间 if (now.Year == last.Year && now.Month == last.Month && now.Day == last.Day) { return(false); } else { return(true); } }