public static bool AddNewLog(LogModel log) { string dateStr = Convert.ToDateTime(log.Date).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); String query = "INSERT IGNORE INTO " + TblLogs; query += " (`UserID`, `Date`, `MsgType`, `Symbol`, `Group`, `Status`,`Timeframe`,`Application`) VALUES"; query += "("; query += log.UserId + ","; query += "'" + dateStr + "',"; query += "'" + log.MsgType + "',"; query += "'" + log.Symbol + "',"; query += "'" + log.Group + "',"; query += "'" + log.Status + "',"; query += "'" + log.Timeframe + "',"; query += "'" + log.Application + "'" + ");COMMIT;"; return DoSql(query); }
public static List<LogModel> GetLogBetweenDates(DateTime startDate, DateTime endDate, bool desc = true) { string dateStart = Convert.ToDateTime(startDate).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); string dateEnd = Convert.ToDateTime(endDate).ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); var resultList = new List<LogModel>(); string sql = "SELECT * FROM " + TblLogs + " WHERE Date BETWEEN '" + dateStart + "' AND '" + dateEnd + "' ORDER BY `Date` " + (desc ? "DESC" : " ") + " , `ID` ASC;"; lock (LockReader) { var reader = GetReader(sql); if (reader != null) { while (reader.Read()) { var log = new LogModel { LogId = reader.GetInt32(0), UserId = reader.GetInt32(1), Date = reader.GetDateTime(2), MsgType = reader.GetInt32(3), Symbol = reader.GetString(4), Group = reader.GetString(5), Status = reader.GetInt32(6), Timeframe = reader.GetString(7), Application = reader.GetString(8), }; resultList.Add(log); } reader.Close(); } } return resultList; }