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