6
6
using System . Xml . Serialization ;
7
7
using TimeControl . AppControl ;
8
8
using TimeControl . Data ;
9
+ using static System . Windows . Forms . VisualStyles . VisualStyleElement . TaskbarClock ;
9
10
10
11
namespace TimeControl . Tools
11
12
{
12
- public static class TimeControlFile
13
+ public static class TCFile
13
14
{
14
15
public static readonly string BaseLocation = Environment . GetFolderPath
15
16
( Environment . SpecialFolder . ApplicationData ) + "\\ TimeControl" ;
@@ -30,6 +31,14 @@ public static class TimeControlFile
30
31
public static readonly string ShutdownSpan = BaseLocation + "\\ Shutdown.txt" ;
31
32
//数据显示
32
33
public static readonly string SavedData = BaseLocation + "\\ SavedData.xml" ;
34
+ public static readonly string SavedDataDir = BaseLocation + "\\ SavedData" ;
35
+ public static string [ ] SavedDataFiles
36
+ {
37
+ get
38
+ {
39
+ return Directory . GetFiles ( SavedDataDir ) ;
40
+ }
41
+ }
33
42
34
43
public static void SaveApps ( List < App > apps )
35
44
{
@@ -60,7 +69,7 @@ public static List<App> ReadApps()
60
69
using ( StreamReader sr = new StreamReader ( latestFile . FullName ) )
61
70
{
62
71
XmlSerializer xmlSerializer = new ( typeof ( List < AppInformation > ) ) ;
63
- List < AppInformation > infos = null ;
72
+ List < AppInformation > infos = null ;
64
73
try
65
74
{
66
75
infos = ( List < AppInformation > ) xmlSerializer . Deserialize ( sr ) ;
@@ -104,19 +113,44 @@ public static FileInfo GetLatestAppsFile()
104
113
105
114
public static void SaveTimeData ( TimeData time )
106
115
{
107
- using ( StreamWriter sw = new ( SavedData ) )
116
+ using ( StreamWriter sw = new ( SavedData ) )
108
117
{
109
118
XmlSerializer xmlSerializer = new ( typeof ( TimeData ) ) ;
110
119
xmlSerializer . Serialize ( sw , time ) ;
111
120
}
112
121
}
113
122
public static TimeData ReadTimeData ( )
114
123
{
115
- using ( StreamReader sr = new ( SavedData ) )
124
+ using ( StreamReader sr = new ( SavedData ) )
116
125
{
117
126
XmlSerializer xmlSerializer = new ( typeof ( TimeData ) ) ;
118
127
return ( TimeData ) xmlSerializer . Deserialize ( sr ) ;
119
128
}
120
129
}
130
+ public static void ChangeGoal ( string name )
131
+ {
132
+ foreach ( string file in SavedDataFiles )
133
+ {
134
+ if ( Path . GetFileNameWithoutExtension ( file ) == name )
135
+ {
136
+ string currentName = ReadTimeData ( ) . GoalName ;
137
+ File . Move ( SavedData , SavedDataDir + "\\ " + currentName + ".xml" ) ;
138
+ File . Move ( file , SavedData ) ;
139
+ return ;
140
+ }
141
+ }
142
+ }
143
+ public static void AddGoal ( TimeData timeData )
144
+ {
145
+ using ( StreamWriter sw = new ( SavedDataDir + "\\ " + timeData . GoalName + ".xml" ) )
146
+ {
147
+ XmlSerializer xmlSerializer = new ( typeof ( TimeData ) ) ;
148
+ xmlSerializer . Serialize ( sw , timeData ) ;
149
+ }
150
+ }
151
+ public static void RemoveGoal ( string name )
152
+ {
153
+ File . Delete ( SavedDataDir + "\\ " + name + ".xml" ) ;
154
+ }
121
155
}
122
156
}
0 commit comments