1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using FLY.OBJComponents.Server;
using FLY.OBJComponents.Server.Model;
using FObjBase;
using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FLY.IBC.Server.Model
{
/// <summary>
/// 数据库 写操作
/// </summary>
public class HistoryDb
{
DbModel dbModel;
public BufferSQLite<Db_Width> WidthBuffer;
public BufferError ErrorBuffer;
/// <summary>
///
/// </summary>
/// <param name="dBModel"></param>
public void Init(DbModel dBModel)
{
this.dbModel = dBModel;
WidthBuffer = new BufferSQLite<Db_Width>();
WidthBuffer.Init(dBModel.TbWidth);
ErrorBuffer = new BufferError();
ErrorBuffer.Init(dBModel.TbError);
}
/// <summary>
/// 按时间删除数据库
/// </summary>
/// <param name="month"></param>
public void KeepDBSize(int month)
{
if (month <= 3)
month = 3;
DateTime del_time = DateTime.Now - TimeSpan.FromDays(month * 30);
string det_time_str = del_time.ToStringOfSQLiteFieldType();
List<string> sqls = new List<string>();
sqls.Add(
$"DELETE FROM {dbModel.TbWidth.TableName}" +
$" WHERE Time < {det_time_str}");
sqls.Add(
$"DELETE FROM {dbModel.TbError.TableName}" +
$" WHERE Time < {det_time_str}");
dbModel.sqliteHelper.QueryTran(sqls);
}
public void AddWidth(
Db_Width width
)
{
WidthBuffer.Add(width);
}
public void AddWidthRange(IEnumerable<Db_Width> widths)
{
WidthBuffer.AddRange(widths);
}
}
}