/// <summary> /// 设置数据,保留2分钟内数据或50条记录,2分钟内有多余50条记录则保留最近100条记录 /// </summary> /// <param name="tag"></param> public void AddRecord(string tag) { if (string.IsNullOrEmpty(tag)) { return; } int min = 5, max = 20; TimeSpan ts = new TimeSpan(0, 2, 0); int count = this.rows.Count; if (count < min) { RecordDev rdnew = new RecordDev(); rdnew.tag = tag; this.rows.Add(rdnew); return; } if (count > max) { this.rows.RemoveRange(0, count - max); count = this.rows.Count; } DateTime dtmi = DateTime.Now.AddMinutes(-2); int index = 0; for (int i = 0; i < count; i++) { if (this.rows[i].dtReceive > dtmi) { break; } index++; } if (index > 0) { this.rows.RemoveRange(0, index); } RecordDev rd = null; if (max == this.rows.Count) { rd = this.rows[0]; this.rows.RemoveAt(0); rd.dtReceive = DateTime.Now; } else { rd = new RecordDev(); } rd.tag = tag; this.rows.Add(rd); }
/// <summary> /// ��������,����2���������ݻ�50����¼,2�������ж���50����¼�������100����¼ /// </summary> /// <param name="tag"></param> public void AddRecord(string tag) { int min = 50, max = 100; TimeSpan ts = new TimeSpan(0, 2, 0); int count = this.rows.Count; if (count < min) { RecordDev rdnew = new RecordDev(); rdnew.tag = tag; this.rows.Add(rdnew); return; } if (count > max) { this.rows.RemoveRange(0, count - max); count = this.rows.Count; } DateTime dtmi = DateTime.Now.AddMinutes(-2); int index = 0; for (int i = 0; i < count; i++) { if (this.rows[i].dtReceive > dtmi) break; index++; } if (index > 0) this.rows.RemoveRange(0, index); RecordDev rd = null; if (max == this.rows.Count) { rd = this.rows[0]; this.rows.RemoveAt(0); rd.dtReceive = DateTime.Now; } else rd = new RecordDev(); rd.tag = tag; this.rows.Add(rd); }