프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Common / TempFile.cs @ 038c77fd

이력 | 보기 | 이력해설 | 다운로드 (11.3 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 PathString = Path.GetTempPath() + "\\MARKUS";
33
        public static string FilePath = PathString + "\\" + App.ViewInfo.DocumentItemID + ".tmp";
34

    
35
        internal static void WriteTemp(List<MainMenu.TempDt> tempDtList)
36
        {
37
            if (tempDtList.Count > 0)
38
            {
39
                XmlDocument xmlDoc;
40
                XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
41
                XmlNode newNode;
42
                xmlDoc = new XmlDocument();
43

    
44
                if ((System.IO.File.Exists(FilePath)) == false)
45
                {
46
                    if (!File.Exists(PathString))
47
                    {
48
                        Directory.CreateDirectory(PathString);
49
                    }
50

    
51
                    XmlWriterSettings settings = new XmlWriterSettings();
52
                    settings.Indent = true;
53
                    settings.NewLineOnAttributes = true;
54

    
55
                    XmlWriter xmlWriter = XmlWriter.Create(FilePath);
56
                    xmlWriter.WriteStartDocument();
57
                    xmlWriter.WriteStartElement("Root");
58

    
59
                    xmlWriter.WriteEndDocument();
60

    
61
                    xmlWriter.Flush();
62
                    xmlWriter.Close();
63
                }
64

    
65
                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

    
71
                    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

    
82
                            xmlDoc.Save(FilePath); // XML문서 저장                
83

    
84
                            check = false;
85
                            break;
86
                        }
87
                    }
88

    
89
                    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

    
96
                        xmlEle2 = xmlDoc.CreateElement("ConvertData"); // 추가할 Node 생성
97
                        xmlEle2.InnerText = tempDtList[i].ConvertData;
98
                        xmlEle1.AppendChild(xmlEle2);
99

    
100
                        xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); // 추가할 Node 생성
101
                        xmlEle3.InnerText = tempDtList[i].DATA_TYPE.ToString();
102
                        xmlEle1.AppendChild(xmlEle3);
103

    
104
                        xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); // 추가할 Node 생성
105
                        xmlEle4.InnerText = tempDtList[i].MarkupInfoID;
106
                        xmlEle1.AppendChild(xmlEle4);
107

    
108
                        xmlEle5 = xmlDoc.CreateElement("PageNumber"); // 추가할 Node 생성
109
                        xmlEle5.InnerText = tempDtList[i].PageNumber.ToString();
110
                        xmlEle1.AppendChild(xmlEle5);
111

    
112
                        xmlEle6 = xmlDoc.CreateElement("IsUpdate");
113
                        xmlEle6.InnerText = tempDtList[i].IsUpdate.ToString();
114
                        xmlEle1.AppendChild(xmlEle6);
115

    
116
                        xmlDoc.Save(FilePath); // XML문서 저장..
117
                    }
118
                }
119
                xmlDoc = null;
120
            }
121
        }
122
        
123
        public void AddTemp(MarkupToPDF.Common.Undo_data undoDataList, int PageNumber, double x, double y)
124
        {
125
            XmlDocument xmlDoc;
126
            XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
127
            XmlNode newNode;
128
            xmlDoc = new XmlDocument();
129

    
130
            if ((System.IO.File.Exists(FilePath)) == false)
131
            {
132
                if (!File.Exists(PathString))
133
                {
134
                    Directory.CreateDirectory(PathString);
135
                }
136

    
137
                XmlWriterSettings settings = new XmlWriterSettings();
138
                settings.Indent = true;
139
                settings.NewLineOnAttributes = true;
140

    
141
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
142
                xmlWriter.WriteStartDocument();
143
                xmlWriter.WriteStartElement("Root");
144

    
145
                xmlWriter.WriteEndDocument();
146

    
147
                xmlWriter.Flush();
148
                xmlWriter.Close();
149
            }
150

    
151
            xmlDoc.Load(FilePath); // XML문서 로딩
152
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
153
            for (int i = 0; i < undoDataList.Markup_List.Count; i++)
154
            {
155
                var root = MarkupParser.MarkupToString(undoDataList.Markup_List[i].Markup, App.ViewInfo.UserID);
156
                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

    
169
                        xmlDoc.Save(FilePath); // XML문서 저장                
170

    
171
                        check = false;
172
                        break;
173
                    }
174
                }                
175

    
176
                if (check == true)
177
                {
178
                    newNode = xmlDoc.SelectSingleNode("Root"); 
179
                    xmlEle1 = xmlDoc.CreateElement("CommentID");
180
                    xmlEle1.SetAttribute("Value", root.CommentID);
181
                    newNode.AppendChild(xmlEle1);
182

    
183
                    xmlEle2 = xmlDoc.CreateElement("ConvertData"); 
184
                    xmlEle2.InnerText = root.ConvertData;
185
                    xmlEle1.AppendChild(xmlEle2);
186

    
187
                    xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); 
188
                    xmlEle3.InnerText = root.DATA_TYPE.ToString();
189
                    xmlEle1.AppendChild(xmlEle3);
190

    
191
                    xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); 
192
                    xmlEle4.InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID;
193
                    xmlEle1.AppendChild(xmlEle4);
194

    
195
                    xmlEle5 = xmlDoc.CreateElement("PageNumber");
196
                    xmlEle5.InnerText = PageNumber.ToString();
197
                    xmlEle1.AppendChild(xmlEle5);
198

    
199
                    xmlEle6 = xmlDoc.CreateElement("IsUpdate");
200
                    xmlEle6.InnerText = 1.ToString();
201
                    xmlEle1.AppendChild(xmlEle6);
202

    
203
                    xmlDoc.Save(FilePath); 
204
                }
205
            }
206
            xmlDoc = null;
207
        }
208

    
209
        public static void Remove() 
210
        {
211
            FileInfo fileDel = new FileInfo(FilePath);
212
            if (fileDel.Exists) 
213
            {
214
                fileDel.Delete(); 
215
            }
216
        }
217

    
218
        internal static void DelTemp(string CommentID, string PageNumber) //Control 삭제시
219
        {
220
            if ((System.IO.File.Exists(FilePath)) == false)
221
            {
222
                if (!File.Exists(PathString))
223
                {
224
                    Directory.CreateDirectory(PathString);
225
                }
226

    
227
                XmlWriterSettings settings = new XmlWriterSettings();
228
                settings.Indent = true;
229
                settings.NewLineOnAttributes = true;
230

    
231
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
232
                xmlWriter.WriteStartDocument();
233
                xmlWriter.WriteStartElement("Root");
234

    
235
                xmlWriter.WriteEndDocument();
236

    
237
                xmlWriter.Flush();
238
                xmlWriter.Close();
239
            }
240

    
241
            XmlDocument xmlDoc;
242
            xmlDoc = new XmlDocument();
243
            xmlDoc.Load(FilePath);
244

    
245
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
246
            XmlElement root = xmlDoc.DocumentElement;
247

    
248
            bool check = true;
249

    
250
            /*
251
            foreach (XmlNode node in nodes)
252
            {
253
                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

    
262
            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
            }
291

    
292
            xmlDoc.Save(FilePath);           
293
            xmlDoc = null;
294
        }
295
    }
296
}
297

    
클립보드 이미지 추가 (최대 크기: 500 MB)