프로젝트

일반

사용자정보

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

markus / KCOM / Events / PasteCommand.cs @ 20ef6ffe

이력 | 보기 | 이력해설 | 다운로드 (11.1 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 Svg2Xaml;
11
using System;
12
using System.Collections;
13
using System.Collections.Generic;
14
using System.ComponentModel;
15
using System.Data;
16
using System.IO;
17
using System.Linq;
18
using System.Reflection;
19
using System.Runtime.Serialization.Formatters;
20
using System.Runtime.Serialization.Formatters.Binary;
21
using System.Runtime.Serialization.Json;
22
using System.Text;
23
using System.Windows;
24
using System.Windows.Media;
25
using System.Windows.Media.Imaging;
26
using System.Xml;
27
using System.Xml.Serialization;
28

    
29
namespace KCOM
30
{
31
    public class PasteCommand
32
    {
33
        private static readonly PasteCommand _instance = new PasteCommand();
34

    
35
        // Explicit static constructor to tell C# compiler
36
        // not to mark type as beforefieldinit
37
        static PasteCommand()
38
        {
39
        }
40

    
41
        private PasteCommand()
42
        {
43
        }
44

    
45
        public static PasteCommand Instance
46
        {
47
            get
48
            {
49
                return _instance;
50
            }
51
        }
52

    
53
        /// <summary>
54
        /// paste controls
55
        /// </summary>
56
        /// <author>humkyung</author>
57
        /// <date>2019.06.18</date>
58
        /// <param name="comments"></param>
59
        public void Execute()
60
        {
61
            if (Clipboard.GetText().Contains("|OR||DZ|"))
62
            {
63
                List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
64

    
65
                SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
66

    
67
                Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
68

    
69
                //강인구 Undo/Redo 보류
70
                MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
71
                {
72
                    IsUndo = false,
73
                    Event = Event_Type.Create,
74
                    EventTime = DateTime.Now,
75
                    Markup_List = new List<Multi_Undo_data>()
76
                };
77

    
78
                ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
79
                {
80
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
81
                });
82

    
83
                string[] delimiterChars = { "|OR|" };
84
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
85
                string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
86
                foreach (string parse in data)
87
                {
88
                    if (parse != "")
89
                    {
90
                        string[] data2 = new string[2];
91
                        data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
92

    
93
                        System.Windows.Controls.Control item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, data2[0], ViewerDataModel.Instance.MarkupControls_USER, string.Empty, string.Empty);
94
                        (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
95
                        if (data2.Length >= 2)
96
                        {
97
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = data2[1];
98
                        }
99
                        ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
100
                        ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
101

    
102
                        adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
103

    
104
                        multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
105

    
106
                        UndoData.Markup_List.Add(multi_Undo_Data);
107
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
108

    
109
                        ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
110
                        MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
111
                    }
112
                }
113
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
114

    
115
                /// place controls at current mouse position
116
                var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid);
117
                final.TranslateItems(diff.X, diff.Y);
118

    
119
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
120
               
121
            }
122
            /// 외부 이미지 붙여넣기
123
            else if (Clipboard.GetImage() != null)
124
            {
125
                try
126
                {
127
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
128

    
129
                    MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
130
                    {
131
                        IsUndo = false,
132
                        Event = Event_Type.Create,
133
                        EventTime = DateTime.Now,
134
                        Markup_List = new List<Multi_Undo_data>()
135
                    };
136

    
137
                    string temppath = System.IO.Path.GetTempPath();
138
                    string filename = Commons.shortFileKey();
139

    
140
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
141
                    clipboardImage.Save(Path.Combine(temppath , filename));
142

    
143
                    /// upload image file to server
144
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath , filename));
145
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
146
                    long numByte = fileInfo.Length;
147
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
148
                    kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
149
                    if (dLen < 4)
150
                    {
151
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
152
                        System.IO.FileMode.Open, System.IO.FileAccess.Read);
153
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
154
                        byte[] data = br.ReadBytes((int)numByte);
155

    
156
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
157
                        Check_Uri.UriCheck(filename);
158

    
159
                        br.Close();
160
                        fStream.Close();
161
                        fStream.Dispose();
162
                    }
163
                    else
164
                    {
165
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
166
                        return;
167
                    }
168

    
169
                    fileInfo.Delete();
170

    
171
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
172
                    IntPtr hBitmap = bmp.GetHbitmap();
173
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
174
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
175
                    if (filename.Contains(".svg"))
176
                    {
177
                        byte[] imageData = null;
178
                        DrawingImage image = null;
179
                        using (System.Net.WebClient web = new System.Net.WebClient())
180
                        {
181
                            imageData = web.DownloadData(new Uri(filename));
182
                            System.IO.Stream stream = new System.IO.MemoryStream(imageData);
183
                            image = SvgReader.Load(stream);
184
                        }
185
                        img.Source = image;
186
                    }
187
                    else
188
                    {
189
                        img.Source = new BitmapImage(new Uri(filename));
190
                    }
191

    
192

    
193
                    var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height);
194
                    var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize);
195
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
196
                    {
197
                        PointSet = new List<Point>(),
198
                        FilePath = filename,
199
                        ImageData = img.Source,
200
                        StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint,
201
                        EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize),
202
                        TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X,
203
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y),
204
                        LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, 
205
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y)
206
                    };
207

    
208
                    currentControl.PointSet = new List<Point>
209
                    {
210
                        currentControl.StartPoint,
211
                        currentControl.LeftBottomPoint,
212
                        currentControl.EndPoint,
213
                        currentControl.TopRightPoint,
214
                    };
215

    
216
                    multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
217
                    UndoData.Markup_List.Add(multi_Undo_Data);
218
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
219

    
220
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
221
                    currentControl.CommentID = Commons.shortGuid();
222

    
223
                    currentControl.ApplyTemplate();
224
                    currentControl.SetImage();
225

    
226
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
227
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
228
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
229

    
230
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
231
                        MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
232
                }
233
                catch (Exception ex)
234
                {
235
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
236
                }
237
            }
238
        }
239
    }
240
}
클립보드 이미지 추가 (최대 크기: 500 MB)