WorkCountManager.cs
3.0 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V.DeviceLibrary
{
public class WorkCountManager
{
public static CountInfo CountObj = null;
public static bool IsNeedCount = ConfigAppSettings.GetBoolValue(Setting_Init.IsNeedCount);
public static void LoadData()
{
try
{
string[] lines = FileUtil.ReadFileArray(GetConfigPath());
if (lines.Length > 0)
{
string countStr = lines[0];
CountObj = JsonHelper.DeserializeJsonToObject<CountInfo>(countStr);
}
if (CountObj == null)
{
CountObj = new CountInfo();
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
public static void AddWorkCount()
{
if (!IsNeedCount)
{
return;
}
CountObj.WorkCount++;
//判断是否是今日
if (!DateTime.Now.Date.Equals(CountObj.TodayTime.Date))
{
CountObj.TodayWorkCount = 0;
CountObj.TodayTime = DateTime.Now;
}
CountObj.TodayWorkCount++;
SaveListToFile(CountObj);
}
public static void ClearTodayCount()
{
LogUtil.info("清理今日统计数量");
CountObj.TodayWorkCount = 0;
CountObj.TodayTime = DateTime.Now;
SaveListToFile(CountObj);
}
public static void ClearCount()
{
LogUtil.info("清理统计数量");
CountObj = new CountInfo();
SaveListToFile(CountObj);
}
public static string GetConfigPath()
{
string appPath = Application.StartupPath;
string filePath = appPath + ConfigAppSettings.GetValue(Setting_Init.WorkCount_ConfigPath);
return filePath;
}
private static bool SaveListToFile(CountInfo obj)
{
string str = JsonHelper.SerializeObject(obj);
string filePath = GetConfigPath();
string[] strArray = new string[] { str };
return FileUtil.SaveListToFile(strArray, GetConfigPath());
}
}
public class CountInfo
{
public CountInfo()
{
WorkCount = 0;
StartTime = DateTime.Now;
TodayWorkCount = 0;
TodayTime = DateTime.Now;
}
public int WorkCount { get; set; }
/// <summary>
///开始记录的时间,清理后需要更新时间
/// </summary>
public DateTime StartTime { get; set; }
public int TodayWorkCount { get; set; }
public DateTime TodayTime { get; set; }
}
}