프로젝트

일반

사용자정보

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

markus / KCOM / Common / TempFile.cs @ b3c2d962

이력 | 보기 | 이력해설 | 다운로드 (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 FilePath = PathString + "\\" + App.ViewInfo.DocumentItemID + ".tmp";        
41

    
42
        internal void WriteTemp(List<MainMenu.TempDt> tempDtList)
43
        {
44
            if (tempDtList.Count > 0)
45
            {
46
                XmlDocument xmlDoc;
47
                XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
48
                XmlNode newNode;
49
                xmlDoc = new XmlDocument();
50

    
51
                if ((System.IO.File.Exists(FilePath)) == false)
52
                {
53
                    if (!File.Exists(PathString))
54
                    {
55
                        Directory.CreateDirectory(PathString);
56
                    }
57

    
58
                    XmlWriterSettings settings = new XmlWriterSettings();
59
                    settings.Indent = true;
60
                    settings.NewLineOnAttributes = true;
61

    
62
                    XmlWriter xmlWriter = XmlWriter.Create(FilePath);
63
                    xmlWriter.WriteStartDocument();
64
                    xmlWriter.WriteStartElement("Root");
65

    
66
                    xmlWriter.WriteEndDocument();
67

    
68
                    xmlWriter.Flush();
69
                    xmlWriter.Close();
70
                }
71

    
72
                xmlDoc.Load(FilePath); // XML문서 로딩
73
                var nodes = xmlDoc.SelectNodes("/Root/CommentID");
74
                for (int i = 0; i < tempDtList.Count; i++)
75
                {
76
                    bool check = true;
77

    
78
                    foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID"))
79
                    {
80
                        if (e.Attributes["Value"].Value.Equals(tempDtList[i].CommentID)) //CommentID가 같은경우
81
                        {
82
                            //데이터 수정
83
                            e.SelectSingleNode("ConvertData").InnerText = tempDtList[i].ConvertData;
84
                            e.SelectSingleNode("DATA_TYPE").InnerText = tempDtList[i].DATA_TYPE.ToString();
85
                            e.SelectSingleNode("MarkupInfoID").InnerText = tempDtList[i].MarkupInfoID;
86
                            e.SelectSingleNode("PageNumber").InnerText = tempDtList[i].PageNumber.ToString();
87
                            e.SelectSingleNode("IsUpdate").InnerText = tempDtList[i].IsUpdate.ToString();
88

    
89
                            xmlDoc.Save(FilePath); // XML문서 저장                
90

    
91
                            check = false;
92
                            break;
93
                        }
94
                    }
95

    
96
                    if (check == true)
97
                    {
98
                        newNode = xmlDoc.SelectSingleNode("Root"); // 추가할 부모 Node 찾기
99
                        xmlEle1 = xmlDoc.CreateElement("CommentID");
100
                        xmlEle1.SetAttribute("Value", tempDtList[i].CommentID);
101
                        newNode.AppendChild(xmlEle1);
102

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

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

    
111
                        xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); // 추가할 Node 생성
112
                        xmlEle4.InnerText = tempDtList[i].MarkupInfoID;
113
                        xmlEle1.AppendChild(xmlEle4);
114

    
115
                        xmlEle5 = xmlDoc.CreateElement("PageNumber"); // 추가할 Node 생성
116
                        xmlEle5.InnerText = tempDtList[i].PageNumber.ToString();
117
                        xmlEle1.AppendChild(xmlEle5);
118

    
119
                        xmlEle6 = xmlDoc.CreateElement("IsUpdate");
120
                        xmlEle6.InnerText = tempDtList[i].IsUpdate.ToString();
121
                        xmlEle1.AppendChild(xmlEle6);
122

    
123
                        xmlDoc.Save(FilePath); // XML문서 저장..
124
                    }
125
                }
126
                xmlDoc = null;
127
            }
128
        }
129
        
130
        public void AddTemp(MarkupToPDF.Common.Undo_data undoDataList, int PageNumber, double x, double y)
131
        {
132
            XmlDocument xmlDoc;
133
            XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
134
            XmlNode newNode;
135
            xmlDoc = new XmlDocument();
136

    
137
            if ((System.IO.File.Exists(FilePath)) == false)
138
            {
139
                if (!File.Exists(PathString))
140
                {
141
                    Directory.CreateDirectory(PathString);
142
                }
143

    
144
                XmlWriterSettings settings = new XmlWriterSettings();
145
                settings.Indent = true;
146
                settings.NewLineOnAttributes = true;
147

    
148
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
149
                xmlWriter.WriteStartDocument();
150
                xmlWriter.WriteStartElement("Root");
151

    
152
                xmlWriter.WriteEndDocument();
153

    
154
                xmlWriter.Flush();
155
                xmlWriter.Close();
156
            }
157

    
158
            xmlDoc.Load(FilePath); // XML문서 로딩
159
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
160
            for (int i = 0; i < undoDataList.Markup_List.Count; i++)
161
            {
162
                var root = layerControl.MarkupToString(undoDataList.Markup_List[i].Markup, App.ViewInfo.UserID);
163
                bool check = true;
164
                                
165
                foreach (XmlNode e in xmlDoc.GetElementsByTagName("CommentID"))
166
                {
167
                    if (e.Attributes["Value"].Value.Equals(root.CommentID)) //CommentID가 같은경우
168
                    {
169
                        //데이터 수정
170
                        e.SelectSingleNode("ConvertData").InnerText = root.ConvertData;
171
                        e.SelectSingleNode("DATA_TYPE").InnerText = root.DATA_TYPE.ToString();
172
                        e.SelectSingleNode("MarkupInfoID").InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID;
173
                        e.SelectSingleNode("PageNumber").InnerText = PageNumber.ToString();
174
                        e.SelectSingleNode("IsUpdate").InnerText = 1.ToString();
175

    
176
                        xmlDoc.Save(FilePath); // XML문서 저장                
177

    
178
                        check = false;
179
                        break;
180
                    }
181
                }                
182

    
183
                if (check == true)
184
                {
185
                    newNode = xmlDoc.SelectSingleNode("Root"); 
186
                    xmlEle1 = xmlDoc.CreateElement("CommentID");
187
                    xmlEle1.SetAttribute("Value", root.CommentID);
188
                    newNode.AppendChild(xmlEle1);
189

    
190
                    xmlEle2 = xmlDoc.CreateElement("ConvertData"); 
191
                    xmlEle2.InnerText = root.ConvertData;
192
                    xmlEle1.AppendChild(xmlEle2);
193

    
194
                    xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); 
195
                    xmlEle3.InnerText = root.DATA_TYPE.ToString();
196
                    xmlEle1.AppendChild(xmlEle3);
197

    
198
                    xmlEle4 = xmlDoc.CreateElement("MarkupInfoID"); 
199
                    xmlEle4.InnerText = undoDataList.Markup_List[i].Markup.MarkupInfoID;
200
                    xmlEle1.AppendChild(xmlEle4);
201

    
202
                    xmlEle5 = xmlDoc.CreateElement("PageNumber");
203
                    xmlEle5.InnerText = PageNumber.ToString();
204
                    xmlEle1.AppendChild(xmlEle5);
205

    
206
                    xmlEle6 = xmlDoc.CreateElement("IsUpdate");
207
                    xmlEle6.InnerText = 1.ToString();
208
                    xmlEle1.AppendChild(xmlEle6);
209

    
210
                    xmlDoc.Save(FilePath); 
211
                }
212
            }
213
            xmlDoc = null;
214
        }
215

    
216
        public void Remove() 
217
        {
218
            FileInfo fileDel = new FileInfo(FilePath);
219
            if (fileDel.Exists) 
220
            {
221
                fileDel.Delete(); 
222
            }
223
        }
224

    
225
        internal void DelTemp(string CommentID, string PageNumber) //Control 삭제시
226
        {
227
            if ((System.IO.File.Exists(FilePath)) == false)
228
            {
229
                if (!File.Exists(PathString))
230
                {
231
                    Directory.CreateDirectory(PathString);
232
                }
233

    
234
                XmlWriterSettings settings = new XmlWriterSettings();
235
                settings.Indent = true;
236
                settings.NewLineOnAttributes = true;
237

    
238
                XmlWriter xmlWriter = XmlWriter.Create(FilePath);
239
                xmlWriter.WriteStartDocument();
240
                xmlWriter.WriteStartElement("Root");
241

    
242
                xmlWriter.WriteEndDocument();
243

    
244
                xmlWriter.Flush();
245
                xmlWriter.Close();
246
            }
247

    
248
            XmlDocument xmlDoc;
249
            xmlDoc = new XmlDocument();
250
            xmlDoc.Load(FilePath);
251

    
252
            var nodes = xmlDoc.SelectNodes("/Root/CommentID");
253
            XmlElement root = xmlDoc.DocumentElement;
254

    
255
            bool check = true;
256

    
257
            /*
258
            foreach (XmlNode node in nodes)
259
            {
260
                string sCommentID = node.Attributes["Value"].Value;
261

    
262
                if (sCommentID == CommentID)
263
                {
264
                    root.RemoveChild(xmlDoc.SelectNodes("//CommentID[@Value='" + CommentID + "']")[0]);
265
                    check = false;
266
                }
267
            }*/
268

    
269
            if (check == true)
270
            {
271
                XmlElement xmlEle1, xmlEle2, xmlEle3, xmlEle4, xmlEle5, xmlEle6;
272
                XmlNode newNode;
273
                newNode = xmlDoc.SelectSingleNode("Root");
274
                xmlEle1 = xmlDoc.CreateElement("CommentID");
275
                xmlEle1.SetAttribute("Value", CommentID);
276
                newNode.AppendChild(xmlEle1);
277

    
278
                xmlEle2 = xmlDoc.CreateElement("ConvertData");
279
                xmlEle2.InnerText = "";
280
                xmlEle1.AppendChild(xmlEle2);
281

    
282
                xmlEle3 = xmlDoc.CreateElement("DATA_TYPE"); 
283
                xmlEle3.InnerText = "";
284
                xmlEle1.AppendChild(xmlEle3);
285

    
286
                xmlEle4 = xmlDoc.CreateElement("MarkupInfoID");
287
                xmlEle4.InnerText = "";
288
                xmlEle1.AppendChild(xmlEle4);
289

    
290
                xmlEle5 = xmlDoc.CreateElement("PageNumber");
291
                xmlEle5.InnerText = PageNumber;
292
                xmlEle1.AppendChild(xmlEle5);
293

    
294
                xmlEle6 = xmlDoc.CreateElement("IsUpdate");
295
                xmlEle6.InnerText = 2.ToString();
296
                xmlEle1.AppendChild(xmlEle6);
297
            }
298

    
299
            xmlDoc.Save(FilePath);           
300
            xmlDoc = null;
301
        }
302
    }
303
}
304

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