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