markus / KCOM / Common / TempFile.cs @ 036650a0
이력 | 보기 | 이력해설 | 다운로드 (11.2 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOM.Controls; |
3 |
using KCOM.Views; |
4 |
using MarkupToPDF.Common; |
5 |
using MarkupToPDF.Controls.Parsing; |
6 |
using Newtonsoft.Json; |
7 |
using Newtonsoft.Json.Converters; |
8 |
using Newtonsoft.Json.Linq; |
9 |
using Newtonsoft.Json.Serialization; |
10 |
using System; |
11 |
using System.Collections; |
12 |
using System.Collections.Generic; |
13 |
using System.ComponentModel; |
14 |
using System.Data; |
15 |
using System.IO; |
16 |
using System.Linq; |
17 |
using System.Reflection; |
18 |
using System.Runtime.Serialization.Formatters; |
19 |
using System.Runtime.Serialization.Formatters.Binary; |
20 |
using System.Runtime.Serialization.Json; |
21 |
using System.Text; |
22 |
using System.Windows; |
23 |
using System.Windows.Media; |
24 |
using System.Xml; |
25 |
using System.Xml.Serialization; |
26 |
|
27 |
namespace KCOM |
28 |
{ |
29 |
public class TempFile |
30 |
{ |
31 |
public static string PathString = AppDomain.CurrentDomain.BaseDirectory + "Temp"; |
32 |
public static string FilePath = PathString + "\\" + App.ViewInfo.DocumentItemID + ".tmp"; |
33 |
|
34 |
internal void WriteTemp(List<MainMenu.TempDt> tempDtList) |
35 |
{ |
36 |
if (tempDtList.Count > 0) |
37 |
{ |
38 |
XmlDocument xmlDoc; |
39 |
XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6; |
40 |
XmlNode newNode; |
41 |
xmlDoc = new XmlDocument(); |
42 |
|
43 |
if ((System.IO.File.Exists(FilePath)) == false) |
44 |
{ |
45 |
if (!File.Exists(PathString)) |
46 |
{ |
47 |
Directory.CreateDirectory(PathString); |
48 |
} |
49 |
|
50 |
XmlWriterSettings settings = new XmlWriterSettings(); |
51 |
settings.Indent = true; |
52 |
settings.NewLineOnAttributes = true; |
53 |
|
54 |
XmlWriter xmlWriter = XmlWriter.Create(FilePath); |
55 |
xmlWriter.WriteStartDocument(); |
56 |
xmlWriter.WriteStartElement("Root"); |
57 |
|
58 |
xmlWriter.WriteEndDocument(); |
59 |
|
60 |
xmlWriter.Flush(); |
61 |
xmlWriter.Close(); |
62 |
} |
63 |
|
64 |
xmlDoc.Load(FilePath); // XML문서 로딩 |
65 |
var nodes = xmlDoc.SelectNodes("/Root/CommentID"); |
66 |
for (int i = 0; i < tempDtList.Count; i++) |
67 |
{ |
68 |
bool check = true; |
69 |
|
70 |
foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID")) |
71 |
{ |
72 |
if (e.Attributes["Value"].Value.Equals(tempDtList[i].CommentID)) //CommentID가 같은경우 |
73 |
{ |
74 |
//데이터 수정 |
75 |
e.SelectSingleNode("ConvertData").InnerText = tempDtList[i].ConvertData; |
76 |
e.SelectSingleNode("DATA_TYPE").InnerText = tempDtList[i].DATA_TYPE.ToString(); |
77 |
e.SelectSingleNode("MarkupInfoID").InnerText = tempDtList[i].MarkupInfoID; |
78 |
e.SelectSingleNode("PageNumber").InnerText = tempDtList[i].PageNumber.ToString(); |
79 |
e.SelectSingleNode("IsUpdate").InnerText = tempDtList[i].IsUpdate.ToString(); |
80 |
|
81 |
xmlDoc.Save(FilePath); // XML문서 저장 |
82 |
|
83 |
check = false; |
84 |
break; |
85 |
} |
86 |
} |
87 |
|
88 |
if (check == true) |
89 |
{ |
90 |
newNode = xmlDoc.SelectSingleNode("Root"); // 추가할 부모 Node 찾기 |
91 |
xmlEle1 = xmlDoc.CreateElement("CommentID"); |
92 |
xmlEle1.SetAttribute("Value", tempDtList[i].CommentID); |
93 |
newNode.AppendChild(xmlEle1); |
94 |
|
95 |
xmlEle2 = xmlDoc.CreateElement("ConvertData"); // 추가할 Node 생성 |
96 |
xmlEle2.InnerText = tempDtList[i].ConvertData; |
97 |
xmlEle1.AppendChild(xmlEle2); |
98 |
|
99 |
xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); // 추가할 Node 생성 |
100 |
xmlEle3.InnerText = tempDtList[i].DATA_TYPE.ToString(); |
101 |
xmlEle1.AppendChild(xmlEle3); |
102 |
|
103 |
xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); // 추가할 Node 생성 |
104 |
xmlEle4.InnerText = tempDtList[i].MarkupInfoID; |
105 |
xmlEle1.AppendChild(xmlEle4); |
106 |
|
107 |
xmlEle5 = xmlDoc.CreateElement("PageNumber"); // 추가할 Node 생성 |
108 |
xmlEle5.InnerText = tempDtList[i].PageNumber.ToString(); |
109 |
xmlEle1.AppendChild(xmlEle5); |
110 |
|
111 |
xmlEle6 = xmlDoc.CreateElement("IsUpdate"); |
112 |
xmlEle6.InnerText = tempDtList[i].IsUpdate.ToString(); |
113 |
xmlEle1.AppendChild(xmlEle6); |
114 |
|
115 |
xmlDoc.Save(FilePath); // XML문서 저장.. |
116 |
} |
117 |
} |
118 |
xmlDoc = null; |
119 |
} |
120 |
} |
121 |
|
122 |
public void AddTemp(MarkupToPDF.Common.Undo_data undoDataList, int PageNumber, double x, double y) |
123 |
{ |
124 |
XmlDocument xmlDoc; |
125 |
XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6; |
126 |
XmlNode newNode; |
127 |
xmlDoc = new XmlDocument(); |
128 |
|
129 |
if ((System.IO.File.Exists(FilePath)) == false) |
130 |
{ |
131 |
if (!File.Exists(PathString)) |
132 |
{ |
133 |
Directory.CreateDirectory(PathString); |
134 |
} |
135 |
|
136 |
XmlWriterSettings settings = new XmlWriterSettings(); |
137 |
settings.Indent = true; |
138 |
settings.NewLineOnAttributes = true; |
139 |
|
140 |
XmlWriter xmlWriter = XmlWriter.Create(FilePath); |
141 |
xmlWriter.WriteStartDocument(); |
142 |
xmlWriter.WriteStartElement("Root"); |
143 |
|
144 |
xmlWriter.WriteEndDocument(); |
145 |
|
146 |
xmlWriter.Flush(); |
147 |
xmlWriter.Close(); |
148 |
} |
149 |
|
150 |
xmlDoc.Load(FilePath); // XML문서 로딩 |
151 |
var nodes = xmlDoc.SelectNodes("/Root/CommentID"); |
152 |
for (int i = 0; i < undoDataList.Markup_List.Count; i++) |
153 |
{ |
154 |
var root = MarkupParser.MarkupToString(undoDataList.Markup_List[i].Markup, App.ViewInfo.UserID); |
155 |
bool check = true; |
156 |
|
157 |
foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID")) |
158 |
{ |
159 |
if (e.Attributes["Value"].Value.Equals(root.CommentID)) //CommentID가 같은경우 |
160 |
{ |
161 |
//데이터 수정 |
162 |
e.SelectSingleNode("ConvertData").InnerText = root.ConvertData; |
163 |
e.SelectSingleNode("DATA_TYPE").InnerText = root.DATA_TYPE.ToString(); |
164 |
e.SelectSingleNode("MarkupInfoID").InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID; |
165 |
e.SelectSingleNode("PageNumber").InnerText = PageNumber.ToString(); |
166 |
e.SelectSingleNode("IsUpdate").InnerText = 1.ToString(); |
167 |
|
168 |
xmlDoc.Save(FilePath); // XML문서 저장 |
169 |
|
170 |
check = false; |
171 |
break; |
172 |
} |
173 |
} |
174 |
|
175 |
if (check == true) |
176 |
{ |
177 |
newNode = xmlDoc.SelectSingleNode("Root"); |
178 |
xmlEle1 = xmlDoc.CreateElement("CommentID"); |
179 |
xmlEle1.SetAttribute("Value", root.CommentID); |
180 |
newNode.AppendChild(xmlEle1); |
181 |
|
182 |
xmlEle2 = xmlDoc.CreateElement("ConvertData"); |
183 |
xmlEle2.InnerText = root.ConvertData; |
184 |
xmlEle1.AppendChild(xmlEle2); |
185 |
|
186 |
xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); |
187 |
xmlEle3.InnerText = root.DATA_TYPE.ToString(); |
188 |
xmlEle1.AppendChild(xmlEle3); |
189 |
|
190 |
xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); |
191 |
xmlEle4.InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID; |
192 |
xmlEle1.AppendChild(xmlEle4); |
193 |
|
194 |
xmlEle5 = xmlDoc.CreateElement("PageNumber"); |
195 |
xmlEle5.InnerText = PageNumber.ToString(); |
196 |
xmlEle1.AppendChild(xmlEle5); |
197 |
|
198 |
xmlEle6 = xmlDoc.CreateElement("IsUpdate"); |
199 |
xmlEle6.InnerText = 1.ToString(); |
200 |
xmlEle1.AppendChild(xmlEle6); |
201 |
|
202 |
xmlDoc.Save(FilePath); |
203 |
} |
204 |
} |
205 |
xmlDoc = null; |
206 |
} |
207 |
|
208 |
public void Remove() |
209 |
{ |
210 |
FileInfo fileDel = new FileInfo(FilePath); |
211 |
if (fileDel.Exists) |
212 |
{ |
213 |
fileDel.Delete(); |
214 |
} |
215 |
} |
216 |
|
217 |
internal void DelTemp(string CommentID, string PageNumber) //Control 삭제시 |
218 |
{ |
219 |
if ((System.IO.File.Exists(FilePath)) == false) |
220 |
{ |
221 |
if (!File.Exists(PathString)) |
222 |
{ |
223 |
Directory.CreateDirectory(PathString); |
224 |
} |
225 |
|
226 |
XmlWriterSettings settings = new XmlWriterSettings(); |
227 |
settings.Indent = true; |
228 |
settings.NewLineOnAttributes = true; |
229 |
|
230 |
XmlWriter xmlWriter = XmlWriter.Create(FilePath); |
231 |
xmlWriter.WriteStartDocument(); |
232 |
xmlWriter.WriteStartElement("Root"); |
233 |
|
234 |
xmlWriter.WriteEndDocument(); |
235 |
|
236 |
xmlWriter.Flush(); |
237 |
xmlWriter.Close(); |
238 |
} |
239 |
|
240 |
XmlDocument xmlDoc; |
241 |
xmlDoc = new XmlDocument(); |
242 |
xmlDoc.Load(FilePath); |
243 |
|
244 |
var nodes = xmlDoc.SelectNodes("/Root/CommentID"); |
245 |
XmlElement root = xmlDoc.DocumentElement; |
246 |
|
247 |
bool check = true; |
248 |
|
249 |
/* |
250 |
foreach (XmlNode node in nodes) |
251 |
{ |
252 |
string sCommentID = node.Attributes["Value"].Value; |
253 |
|
254 |
if (sCommentID == CommentID) |
255 |
{ |
256 |
root.RemoveChild(xmlDoc.SelectNodes("//CommentID[@Value='" + CommentID + "']")[0]); |
257 |
check = false; |
258 |
} |
259 |
}*/ |
260 |
|
261 |
if (check == true) |
262 |
{ |
263 |
XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6; |
264 |
XmlNode newNode; |
265 |
newNode = xmlDoc.SelectSingleNode("Root"); |
266 |
xmlEle1 = xmlDoc.CreateElement("CommentID"); |
267 |
xmlEle1.SetAttribute("Value", CommentID); |
268 |
newNode.AppendChild(xmlEle1); |
269 |
|
270 |
xmlEle2 = xmlDoc.CreateElement("ConvertData"); |
271 |
xmlEle2.InnerText = ""; |
272 |
xmlEle1.AppendChild(xmlEle2); |
273 |
|
274 |
xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); |
275 |
xmlEle3.InnerText = ""; |
276 |
xmlEle1.AppendChild(xmlEle3); |
277 |
|
278 |
xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); |
279 |
xmlEle4.InnerText = ""; |
280 |
xmlEle1.AppendChild(xmlEle4); |
281 |
|
282 |
xmlEle5 = xmlDoc.CreateElement("PageNumber"); |
283 |
xmlEle5.InnerText = PageNumber; |
284 |
xmlEle1.AppendChild(xmlEle5); |
285 |
|
286 |
xmlEle6 = xmlDoc.CreateElement("IsUpdate"); |
287 |
xmlEle6.InnerText = 2.ToString(); |
288 |
xmlEle1.AppendChild(xmlEle6); |
289 |
} |
290 |
|
291 |
xmlDoc.Save(FilePath); |
292 |
xmlDoc = null; |
293 |
} |
294 |
} |
295 |
} |
296 |
|