프로젝트

일반

사용자정보

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

markus / KCOM / Controls / Symbol.xaml.cs @ 5928384e

이력 | 보기 | 이력해설 | 다운로드 (41.8 KB)

1
using IKCOM;
2
using KCOM.Common;
3
using KCOM.Events;
4
using KCOMDataModel.Common;
5
using KCOMDataModel.DataModel;
6
using MarkupToPDF.Common;
7
using MarkupToPDF.Controls.Parsing;
8
using Svg2Xaml;
9
using System;
10
using System.Collections.Generic;
11
using System.ComponentModel;
12
using System.Linq;
13
using System.Text;
14
using System.Windows;
15
using System.Windows.Controls;
16
using System.Windows.Data;
17
using System.Windows.Documents;
18
using System.Windows.Input;
19
using System.Windows.Media;
20
using System.Windows.Media.Imaging;
21
using System.Windows.Navigation;
22
using System.Windows.Shapes;
23
using Telerik.Windows.Controls;
24
using Telerik.Windows.Controls.DragDrop;
25

    
26
namespace KCOM.Controls
27
{
28
    public class Symbol_Custom
29
    {
30
        public string ID { get; set; }
31
        public string Name { get; set; }
32
        public string ImageUri { get; set; }
33
    }
34

    
35
    /// <summary>
36
    /// Symbol.xaml에 대한 상호 작용 논리
37
    /// </summary>
38
    public partial class Symbol : UserControl
39
    {
40
        AdornerFinal finalItem;
41
        bool IsMouseDown = false;
42
        string moveItem_id = "";
43
        public string filename { get; set; }
44

    
45
        public Symbol()
46
        {
47
            InitializeComponent();
48

    
49
            //RadDragAndDropManager.AddDragInfoHandler(lstSymbolPrivate, OnDragPrivateInfo);
50
            //RadDragAndDropManager.AddDragQueryHandler(lstSymbolPrivate, OnDragPrivateQuery);
51
            //RadDragAndDropManager.SetAllowDrag(lstSymbolPrivate, true);
52

    
53
            DataBind();
54
        }
55

    
56
        private void OnDragPrivateInfo(object sender, DragDropEventArgs e)
57
        {
58
        }
59

    
60
        private void OnDragPrivateQuery(object sender, DragDropQueryEventArgs e)
61
        {
62
            if (e.Options.Status == DragStatus.DragQuery)
63
            {
64
                //var draggedListBoxItem = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem;
65
                //BitmapImage im = new BitmapImage(new Uri((draggedListBoxItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate).ImageUri));
66
                //ImageSource _source = im;
67
                //Image img = new Image();
68
                //img.Source = _source;
69

    
70
                //e.Options.Payload = im;
71
                //var dragCue = new Image();
72
                //dragCue.Source = img.Source;
73
                //dragCue.Width = 0;
74
                //dragCue.Height = 0;
75
                //e.Options.DragCue = dragCue;
76

    
77

    
78
                //PayLoadAdorner = new AdornerFinal();
79
                //DeepView.ServiceDeepView_Symbol.SymbolPrivate tempDragableControl = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate;
80
                //var xamldata = tempDragableControl.Data;
81
                ////this.DeepLayer.markupParse(xamldata, this.DeepLayer._TempLayer, "복사된 데이터_이름으로 수정해야함");
82
                //PayLoadAdorner = this.DeepLayer.markupParseToAdorner(xamldata, this.DeepLayer._SelectLayer, "");
83
                //this.DeepLayer._SelectLayer.Children.Add(PayLoadAdorner);
84
            }
85

    
86
            e.QueryResult = true;
87
            e.Handled = true;
88
        }
89

    
90
        private void DataBind()
91
        {
92
            //lstSymbolPrivate.ItemsSource = null;
93
            //lstSymbolPublic.ItemsSource = null;
94

    
95
            Symbol_Custom Custom = new Symbol_Custom();
96
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();           
97
            
98
            var symbol_Private = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolList(App.ViewInfo.UserID);
99
            foreach (var item in symbol_Private)
100
            {
101
                Custom.Name = item.NAME;
102
                Custom.ImageUri = item.IMAGE_URL;
103
                Custom.ID = item.ID;
104
                Custom_List.Add(Custom);
105
                Custom = new Symbol_Custom();
106
            }
107
            lstSymbolPrivate.ItemsSource = Custom_List;
108

    
109
            Custom = new Symbol_Custom();
110
            Custom_List = new List<Symbol_Custom>();
111

    
112
            deptlist.ItemsSource = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolDeptList();
113

    
114
            List<SYMBOL_PUBLIC> symbol_Public;
115

    
116

    
117
            if (deptlist.SelectedValue != null)
118
            {
119
                symbol_Public = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolList(deptlist.SelectedValue.ToString());
120
            }
121
            else
122
            {
123
                symbol_Public = ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetPublicSymbolList(null);
124
            }
125
            foreach (var item in symbol_Public)
126
            {
127
                Custom.Name = item.NAME;
128
                Custom.ImageUri = item.IMAGE_URL;
129
                Custom.ID = item.ID;
130
                Custom_List.Add(Custom);
131
                Custom = new Symbol_Custom();
132
            }
133
            lstSymbolPublic.ItemsSource = Custom_List;            
134
        }
135

    
136
        public PngBitmapEncoder symImage(string data)
137
        {
138

    
139
            Canvas _canvas = new Canvas();
140
            _canvas.Background = Brushes.White;
141
            _canvas.Width = finalItem.BorderSize.Width;
142
            _canvas.Height = finalItem.BorderSize.Height;
143
            MarkupParser.Parse(App.ViewInfo.ProjectNO, data, _canvas, "#FFFF0000", "");
144

    
145
            BitmapEncoder encoder = new PngBitmapEncoder();
146

    
147

    
148
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32);
149

    
150
            DrawingVisual dv = new DrawingVisual();
151

    
152
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
153
            //_canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 50, Y = -finalItem.BorderSize.Y - 50 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20)));
154
            _canvas.Arrange(new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20)));
155

    
156
            using (DrawingContext ctx = dv.RenderOpen())
157
            {
158
                VisualBrush vb = new VisualBrush(_canvas);
159
                //ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X - 20, Y = -finalItem.BorderSize.Y - 20 }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20)));
160
                ctx.DrawRectangle(vb, null, new Rect(new System.Windows.Point { X = -finalItem.BorderSize.X, Y = -finalItem.BorderSize.Y }, new Point(finalItem.BorderSize.Width + 20, finalItem.BorderSize.Height + 20)));
161
            }
162

    
163
            try
164
            {
165
                renderBitmap.Render(dv);
166

    
167
                GC.Collect();
168
                GC.WaitForPendingFinalizers();
169
                GC.Collect();
170
                //bitmap.Render(controlToConvert);
171
                // encode png data
172
                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
173
                // puch rendered bitmap into it
174
                pngEncoder.Interlace = PngInterlaceOption.Off;
175
                pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
176
                return pngEncoder;
177

    
178
            }
179
            catch //(Exception ex)
180
            {
181
                return null;
182
            }
183

    
184
        }
185

    
186
        public void DialogMessage_Alert(string content, string header)
187
        {
188
            var box = new TextBlock();
189
            box.MinWidth = 400;
190
            box.FontSize = 11;
191
            //box.FontSize = 12;
192
            box.Text = content;
193
            box.TextWrapping = System.Windows.TextWrapping.Wrap;
194

    
195
            DialogParameters parameters = new DialogParameters()
196
            {
197
                Owner = Application.Current.MainWindow,
198
                Content = box,
199
                Header = header,
200
                Theme = new VisualStudio2013Theme(),
201
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
202
            };
203
            RadWindow.Alert(parameters);
204
        }
205

    
206
        #region Event
207

    
208
        #region Private Symbol Add Event
209
        private void Create_Symbol(object sender, RoutedEventArgs e)
210
        {
211
            MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn();
212

    
213
            if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면
214
            {
215
                DialogMessage_Alert("Please Select Controls", "Alert");
216
            }
217
            else //선택된 것이 있으면
218
            {
219
                string MarkupData = "";
220
                finalItem = new AdornerFinal();
221

    
222
                foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children)
223
                {
224
                    if (item.GetType().Name == "AdornerFinal")
225
                    {
226
                        finalItem = (item as Controls.AdornerFinal);
227
                        foreach (var InnerItem in (item as Controls.AdornerFinal).MemberSet.Cast<Controls.AdornerMember>())
228
                        {
229
                            if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData))
230
                            {
231
                                markupReturn = MarkupParser.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID);
232
                                MarkupData += markupReturn.ConvertData;
233
                            }
234
                        }
235
                    }
236
                }
237
                DialogParameters parameters = new DialogParameters()
238
                {
239
                    Owner = Application.Current.MainWindow,
240
                    Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args),
241
                    DefaultPromptResultValue = "Custom State",
242
                    Content = "Name :",
243
                    Header = "Insert Custom Symbol Name",
244
                    Theme = new VisualStudio2013Theme(),
245
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
246
                };
247
                RadWindow.Prompt(parameters);
248
            }
249

    
250
        }
251
        #endregion
252

    
253
        #region Symbol Add Close Event 
254
        private void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
255
        {
256
            try
257
            {
258
                if (args.PromptResult != null)
259
                {
260
                    if (args.DialogResult.Value)
261
                    {
262
                        PngBitmapEncoder _Encoder = symImage(data);
263

    
264
                        System.IO.MemoryStream fs = new System.IO.MemoryStream();
265
                        _Encoder.Save(fs);
266
                        System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
267

    
268
                        byte[] Img_byte = fs.ToArray();
269

    
270
                        kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
271
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Commons.shortGuid() + ".png", Img_byte);
272
                        Check_Uri.UriCheck(filename);
273
                        if (RadTab.SelectedIndex == 0)
274
                        {
275
                            SymbolSave(args.PromptResult, filename, data);
276
                        }
277
                        else
278
                        {
279
                            SymbolSave_Public(args.PromptResult, filename, data, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.userData.DEPARTMENT);
280
                        }
281

    
282
                        DataBind();
283
                    }
284
                }
285
            }
286
            catch(Exception ex)
287
            {
288
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
289
            }
290
        }
291
        #endregion
292

    
293
        public void SymbolSave(string Name, string Url, string Data)
294
        {
295
            try
296
            {
297
                SYMBOL_PRIVATE symbol_private = new SYMBOL_PRIVATE
298
                {
299
                    ID = Commons.shortGuid(),
300
                    MEMBER_USER_ID = App.ViewInfo.UserID,
301
                    NAME = Name,
302
                    IMAGE_URL = Url,
303
                    DATA = Data
304
                };
305

    
306
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
307
                Logger.sendReqLog("SaveSymbolAsync: ", symbol_private.ID + "," + symbol_private.MEMBER_USER_ID + "," + symbol_private.NAME + "," + symbol_private.IMAGE_URL + "," + symbol_private.DATA, 1);
308
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolAsync(symbol_private);
309
            }
310
            catch (Exception)
311
            {
312
                throw;
313
            }
314
        }
315

    
316
        public void SymbolSave_Public(string Name, string Url, string Data, string Department)
317
        {
318
            try
319
            {
320
                SYMBOL_PUBLIC symbol_public = new SYMBOL_PUBLIC
321
                {
322
                    ID = Commons.shortGuid(),
323
                    DEPARTMENT = Department,
324
                    NAME = Name,
325
                    IMAGE_URL = Url,
326
                    DATA = Data
327
                };
328
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
329
                Logger.sendReqLog("AddPublicSymbol: ", symbol_public.ID + "," + symbol_public.DEPARTMENT + "," + symbol_public.NAME + "," + symbol_public.IMAGE_URL + "," + symbol_public.DATA, 1);
330
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbol(symbol_public);
331
            }
332
            catch (Exception)
333
            {
334
                throw;
335
            }
336
        }
337

    
338
        private void BaseClient_AddPublicSymbolCompleted(object sender, ServiceDeepView.AddPublicSymbolCompletedEventArgs e)
339
        {
340
            Logger.sendResLog("AddPublicSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
341
            DataBind();
342
        }
343

    
344
        private void BaseClient_SaveSymbolCompleted(object sender, ServiceDeepView.SaveSymbolCompletedEventArgs e)
345
        {
346
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
347
            DataBind();
348
        }
349

    
350
        #region Private Symbol Delete Event
351
        private void Remove_Symbol(object sender, RoutedEventArgs e)
352
        {
353
            if (lstSymbolPrivate.SelectedItem == null)
354
            {
355
                DialogMessage_Alert("Please Select Symbol", "Alert");
356
                return;
357
            }
358
            string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
359

    
360
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
361
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
362
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
363
        }
364
        #endregion
365
        #region Public Symbol Delete Event
366
        private void Remove_Symbol_Public(object sender, RoutedEventArgs e)
367
        {
368
            if (lstSymbolPublic.SelectedItem == null)
369
            {
370
                DialogMessage_Alert("Please Select Symbol", "Alert");
371
                return;
372
            }
373
            string delItem_ID = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
374

    
375
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
376
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
377
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
378
        }
379

    
380
        private void BaseClient_DeleteSymbolCompleted(object sender, ServiceDeepView.DeleteSymbolCompletedEventArgs e)
381
        {
382
            Logger.sendResLog("DeleteSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
383
            DataBind();
384
        }
385
        #endregion
386

    
387
        public Undo_data UndoData { get; set; }
388
        /// <summary>
389
        /// place symbol which has given id to original position which is created
390
        /// </summary>
391
        /// <date>2018.06.14</date>
392
        /// <param name="id"></param>
393
        private void PlaceSymbol(string id)
394
        {
395
            string Data_ = "";
396

    
397
            try
398
            {
399
                Logger.sendReqLog("GetSymbolData: ", id + "," + RadTab.SelectedIndex, 1);
400
                Data_ = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolData(id, RadTab.SelectedIndex);
401
                if (Data_ != null || Data_ != "")
402
                {
403
                    Logger.sendResLog("GetSymbolData", "TRUE", 1);
404
                }
405
                else
406
                {
407
                    Logger.sendResLog("GetSymbolData", "FALSE", 1);
408
                }
409

    
410
                //MARKUP_DATA_GROUP INSERT
411
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
412
                //{
413
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
414
                //    STATE = 0,
415
                //};
416
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
417
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
418

    
419
                if (Data_.Contains("|DZ|"))
420
                {
421
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
422

    
423
                    string[] delimiterChars = { "|DZ|" };
424
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
425

    
426
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
427
                    UndoData = new Undo_data()
428
                    {
429
                        IsUndo = false,
430
                        Event = Event_Type.Create,
431
                        EventTime = DateTime.Now,
432
                        Markup_List = new List<Multi_Undo_data>()
433
                    };
434
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
435
                    {
436
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
437
                    });
438

    
439
                    foreach (string parse in data)
440
                    {
441
                        if (parse != "")
442
                        {
443
                            System.Windows.Controls.Control item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, parse, ViewerDataModel.Instance.MarkupControls_USER, string.Empty, string.Empty);
444
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
445
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = id;
446
                            //(item as MarkupToPDF.Common.CommentUserInfo).GroupID = group_id;
447
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
448
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
449

    
450
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
451

    
452
                            multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
453

    
454
                            UndoData.Markup_List.Add(multi_Undo_Data);
455
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
456
                        }
457
                    }
458
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
459

    
460
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
461
                }
462
                else
463
                {
464
                    PlaceImageSymbol(id, 0);
465
                }
466
            }
467
            catch (Exception ex)
468
            {
469
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
470
            }
471
        }
472

    
473
        private void PlaceImageSymbol(string id, long group_id)
474
        {
475
           
476
            //canvasZoommovingMouseDownPoint
477
            string Data_ = "";
478

    
479
            try
480
            {
481
                Logger.sendReqLog("GetSymbolImageURL: ", id + "," + RadTab.SelectedIndex, 1);
482
                Data_ = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolImageURL(id, RadTab.SelectedIndex);
483
                if (Data_ != null || Data_ != "")
484
                {
485
                    Logger.sendResLog("GetSymbolImageURL", "TRUE", 1);
486
                }
487
                else
488
                {
489
                    Logger.sendResLog("GetSymbolImageURL", "FALSE", 1);
490
                }
491

    
492
                //MARKUP_DATA_GROUP INSERT
493
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
494
                //{
495
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
496
                //    STATE = 0,
497
                //};
498
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
499
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
500

    
501
                if (Data_ != null)
502
                {
503
                    Image img = new Image();
504
                    //img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(Data_));
505
                    if (Data_.Contains(".svg"))
506
                    {
507
                        byte[] imageData = null;
508
                        DrawingImage image = null;
509
                        using (System.Net.WebClient web = new System.Net.WebClient())
510
                        {
511
                            imageData = web.DownloadData(new Uri(Data_));
512
                            System.IO.Stream stream = new System.IO.MemoryStream(imageData);
513
                            image = SvgReader.Load(stream);
514
                        }
515
                        img.Source = image;
516
                    }
517
                    else
518
                    {
519
                        img.Source = new BitmapImage(new Uri(Data_));
520
                    }
521

    
522
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
523
                    {
524
                        PointSet = new List<Point>(),
525
                        FilePath = Data_,
526
                        ImageData = img.Source,
527
                        StartPoint = new Point(0, 0),
528
                        EndPoint = new Point(img.Source.Width, img.Source.Height),
529
                        TopRightPoint = new Point(img.Source.Width, 0),
530
                        LeftBottomPoint = new Point(0, img.Source.Height)
531
                    };
532

    
533
                    currentControl.PointSet = new List<Point>
534
                                        {
535
                                            currentControl.StartPoint,
536
                                            currentControl.LeftBottomPoint,
537
                                            currentControl.EndPoint,
538
                                            currentControl.TopRightPoint,
539
                                        };
540
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
541
                    UndoData = new Undo_data()
542
                    {
543
                        IsUndo = false,
544
                        Event = Event_Type.Create,
545
                        EventTime = DateTime.Now,
546
                        Markup_List = new List<Multi_Undo_data>()
547
                    };
548
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
549
                    {
550
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
551
                    });
552

    
553
                    //multi_Undo_Data = dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
554
                    multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
555
                    UndoData.Markup_List.Add(multi_Undo_Data);
556
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
557

    
558
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
559
                    currentControl.CommentID = Commons.shortGuid();
560
                    currentControl.SymbolID = id;
561
                    currentControl.GroupID = group_id;
562
                    currentControl.ApplyTemplate();
563
                    currentControl.SetImage();
564

    
565
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
566
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
567
                    this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
568

    
569
                    // this.ParentOfType<MainWindow>().dzMainMenu.isLeftMouseButtonDownOnWindow = true;
570
                    // final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
571
                    double realPointX = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.X - final.BorderSize.X - (final.BorderSize.Width / 2);
572
                    double realPointY = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.Y - final.BorderSize.Y - (final.BorderSize.Height / 2);
573
                      final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
574
                    // move.control_Select(item, dragRect);
575
                    ApplyDragSelectionRect();
576
                    this.ParentOfType<MainWindow>().dzMainMenu.mouseHandlingMode = MouseHandlingMode.DragSymbol;
577
                    ///this.ParentOfType<MainWindow>().dzMainMenu.mouseButtonDown = MouseButton.Left;
578
                    this.ParentOfType<MainWindow>().dzMainMenu.symboldata(id, group_id, RadTab.SelectedIndex, Data_, img.Source);
579
                    
580
                }
581
            }
582
            catch(Exception ex)
583
            {
584
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
585
            }
586
        }
587

    
588
        public Multi_Undo_data multi_Undo_Data;
589
        private void ApplyDragSelectionRect()
590
        {
591
            multi_Undo_Data = new Multi_Undo_data();
592

    
593
            UndoData = new Undo_data()
594
            {
595
                IsUndo = false,
596
                Event = Event_Type.Select,
597
                EventTime = DateTime.Now,
598
                Markup_List = new List<Multi_Undo_data>()
599
            };
600

    
601
            this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Visibility = Visibility.Collapsed;
602

    
603
            double x = Canvas.GetLeft(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
604
            double y = Canvas.GetTop(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
605
            double width = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Width;
606
            double height = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Height;
607
            Rect dragRect = new Rect(x, y, width, height);
608
            Boolean Flag = false;
609
            dragRect.Inflate(width / 10, height / 10);
610
            List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
611
            var Items = ViewerDataModel.Instance.MarkupControls_USER.ToList();
612

    
613
            dragRect = new Rect(x, y, width, height);
614
            dragRect.Inflate(width / 10, height / 10);
615

    
616
            //move.mousemode = MarkupToPDF.Controls.Common.MouseMode.Selecting;
617
            //move.
618
            foreach (var item in Items)
619
            {
620
                Flag = SelectionSet.Instance.SelectControl(item, dragRect);
621

    
622
                if (Flag)
623
                {
624
                    adornerSet.Add(item);
625
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(item);
626

    
627
                    this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item);
628
                    UndoData.Markup_List.Add(multi_Undo_Data);
629
                    multi_Undo_Data = new Multi_Undo_data();
630
                    if (item.GroupID > 0)
631
                    {
632

    
633
                    }
634
                }
635
            }
636
            if (adornerSet.Count > 0)
637
            {
638
                ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
639
                {
640
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
641
                });
642
                ViewerDataModel.Instance.UndoDataList.Add(UndoData);
643

    
644
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
645
                this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
646
            }
647
        }
648

    
649
        ///private Move move;
650
        #region Symbol DoubleClick Event
651
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
652
        {
653
            try
654
            {
655
                Type type = e.OriginalSource.GetType();
656
                string id = string.Empty;
657
                Logger.sendResLog("Move_Symbol", type.Name, 0);
658
                if (type.Name == "Image")
659
                {
660
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
661
                }
662
                else if (type.Name == "Border")
663
                {
664
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
665
                }
666
                else if (type.Name == "TextBox")
667
                {
668
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
669
                }
670

    
671
                IsMouseDown = true;
672

    
673
                if (e.ClickCount > 1)
674
                {
675
                    this.PlaceSymbol(id);
676
                }
677
            }
678
            catch(Exception ex)
679
            {
680
                Logger.sendResLog("Move_Symbol", ex.Message, 0);
681
            }
682
        }
683
        #endregion
684

    
685
        #region Private Symbol Rename Event
686
        private void Rename_Symbol(object sender, RoutedEventArgs e)
687
        {
688
            if (lstSymbolPrivate.SelectedItem == null)
689
            {
690
                DialogMessage_Alert("Please Select Symbol", "Alert");
691
                return;
692
            }
693

    
694
            DialogParameters parameters = new DialogParameters()
695
            {
696
                Owner = Application.Current.MainWindow,
697
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
698
                //DefaultPromptResultValue = "Custom State",
699
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
700
                Content = "Name :",
701
                Header = "Update Custom Symbol Name",
702
                Theme = new VisualStudio2013Theme(),
703
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
704
            };
705
            RadWindow.Prompt(parameters);
706

    
707
        }
708
        #endregion
709

    
710
        #region Public Symbol Rename Event
711
        private void Rename_Symbol_Public(object sender, RoutedEventArgs e)
712
        {
713
            if (lstSymbolPublic.SelectedItem == null)
714
            {
715
                DialogMessage_Alert("Please Select Symbol", "Alert");
716
                return;
717
            }
718

    
719
            DialogParameters parameters = new DialogParameters()
720
            {
721
                Owner = Application.Current.MainWindow,
722
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
723
                //DefaultPromptResultValue = "Custom State",
724
                DefaultPromptResultValue = (lstSymbolPublic.SelectedItem as Symbol_Custom).Name,
725
                Content = "Name :",
726
                Header = "Update Custom Symbol Name",
727
                Theme = new VisualStudio2013Theme(),
728
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
729
            };
730
            RadWindow.Prompt(parameters);
731

    
732
        }
733
        #endregion
734
        #region Symbol Rename Close Event
735
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
736
        {
737
            if (args.DialogResult != null && args.DialogResult.Value)
738
            {
739
                if(RadTab.SelectedIndex == 0)
740
                {
741
                    string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
742
                    string _name = args.PromptResult;
743
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
744
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
745
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
746
                }
747
                else
748
                {
749
                    string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
750
                    string _name = args.PromptResult;
751
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
752
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
753
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
754
                }
755
            }
756
        }
757

    
758
        private void BaseClient_RenameSymbolCompleted(object sender, ServiceDeepView.RenameSymbolCompletedEventArgs e)
759
        {
760
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
761
            DataBind();
762
        }
763
        #endregion
764

    
765
        #region Wheel Event
766
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
767
        {
768
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
769
        }
770
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
771
        {
772
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
773
        }
774
        #endregion
775

    
776
        #region Tab Selection Event
777
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
778
        {
779
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
780
            {
781
                (item as RadTabItem).FontWeight = FontWeights.Normal;
782
            }
783
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
784
        }
785
        #endregion
786

    
787
        #region Department Selection Event
788
        private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
789
        {
790
            DataBind();
791
        }
792
        #endregion
793

    
794
        #endregion
795

    
796
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
797
        {
798

    
799
        }
800

    
801
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
802
        {
803

    
804
        }
805

    
806
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
807
        {
808

    
809
        }
810

    
811
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
812
        {
813
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
814
            {
815
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
816
            }
817
            else
818
            {
819
                IsMouseDown = false;
820
            }
821
        }
822

    
823
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
824
        {
825
            IsMouseDown = false;
826
        }
827

    
828
        /// <summary>
829
        /// place symbol which user select
830
        /// </summary>
831
        /// <author>humkyung</author>
832
        /// <date>2018.06.14</date>
833
        /// <param name="sender"></param>
834
        /// <param name="e"></param>
835
        private void Place_Symbol(object sender, RoutedEventArgs e)
836
        {
837
            if (lstSymbolPrivate.SelectedItem == null)
838
            {
839
                DialogMessage_Alert("Please Select Symbol",  "Alert");
840
                return;
841
            }
842

    
843
            string id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
844
            this.PlaceSymbol(id);
845
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
846
        }
847

    
848
        private void Place_Symbol_Public(object sender, RoutedEventArgs e)
849
        {
850
            if (lstSymbolPublic.SelectedItem == null)
851
            {
852
                DialogMessage_Alert("Please Select Symbol", "Alert");
853
                return;
854
            }
855

    
856
            string id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
857
            this.PlaceSymbol(id);
858
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
859
        }
860

    
861
        private void Image_Place_Register(object sender, RoutedEventArgs e)
862
        {
863
            SyncInit();
864
            ViewerDataModel.Instance.SystemMain.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.ImgControl;
865
            //캡쳐 하기 전에 코멘트 저장
866
            if (Common.ViewerDataModel.Instance.MarkupControls_USER.Count > 0 || (Application.Current.MainWindow as MainWindow).dzMainMenu.SelectLayer.Children.Count > 0)
867
            {
868
                var menu = (Application.Current.MainWindow as MainWindow).dzMainMenu;
869
                SelectionSet.Instance.UnSelect(menu);
870
                if (menu.PreviewUserMarkupInfoItem != null && menu.PreviewUserMarkupInfoItem.IsPreviewUser == true)
871
                {
872
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEvent(null, null);
873
                }
874
                else if (menu.gridViewMarkup.SelectedItems.Count == 0 || (menu.gridViewMarkup.SelectedItems.FirstOrDefault() as IKCOM.MarkupInfoItem).UserID != App.ViewInfo.UserID)
875
                {
876

    
877
                }
878
                else
879
                {
880
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEvent(null, null);
881
                }
882
            }
883
            Application.Current.MainWindow.Focus();
884
            Common.ViewerDataModel.Instance.Capture_Opacity = 0.49;
885
            (Application.Current.MainWindow as MainWindow).dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Capture;
886
        }
887

    
888

    
889
        private void SyncInit()
890
        {
891
            try
892
            {
893
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden)
894
                {
895
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden = true;
896
                    ViewerDataModel.Instance.PageBalanceMode = false;
897
                    ViewerDataModel.Instance.PageBalanceNumber = 0;
898
                    ViewerDataModel.Instance.PageNumber = 0;
899
                    ViewerDataModel.Instance.MarkupControls_Sync.Clear();
900
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewRevMarkup.Visibility = Visibility.Collapsed;
901
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.UserList.IsChecked = false;
902
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.BalanceMode.IsChecked = false;
903
                }
904
            }
905
            catch (Exception ex)
906
            {
907
                Logger.sendResLog("SyncInit", ex.Message, 0);
908
            }
909
        }
910

    
911
        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
912
        {
913
            var block = sender as TextBox;
914
            block.Focusable = true;
915
               
916
        }
917

    
918
        private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
919
        {
920
            var block = sender as TextBox;
921
            if (block != null)
922
            {
923
                //block.Text = "Enter";
924

    
925
            }
926
        }
927

    
928
        private void OnKeyDownHandler(object sender, KeyEventArgs e)
929
        {
930
            if (e.Key == Key.Return)
931
            {
932
                Type type = e.OriginalSource.GetType();
933
                string id = string.Empty;
934
                Logger.sendResLog("Move_Symbol", type.Name, 0);
935
                if (type.Name == "Image")
936
                {
937
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
938
                }
939
                else if (type.Name == "Border")
940
                {
941
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
942
                }
943
                else if (type.Name == "TextBox")
944
                {
945
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
946
                }
947

    
948
                //((System.Windows.Controls.TextBox)sender).Text;
949

    
950
                if (RadTab.SelectedIndex == 0)
951
                {
952
                    //string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
953
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
954
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
955
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
956
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
957
                }
958
                else
959
                {
960
                    //string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
961
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
962
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
963
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
964
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
965
                }
966
                
967
            }
968
        }
969
    }
970
}
클립보드 이미지 추가 (최대 크기: 500 MB)