프로젝트

일반

사용자정보

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

markus / KCOM / Controls / Symbol.xaml.cs @ 91efe37a

이력 | 보기 | 이력해설 | 다운로드 (41.7 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
            ServiceDeepView.ServiceDeepViewClient client = new ServiceDeepView.ServiceDeepViewClient(App._binding, App._EndPoint);
98
            var symbol_Private = client.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 = client.GetPublicSymbolDeptList();
113

    
114
            List<SYMBOL_PUBLIC> symbol_Public;
115

    
116

    
117
            if (deptlist.SelectedValue != null)
118
            {
119
                symbol_Public = client.GetPublicSymbolList(deptlist.SelectedValue.ToString());
120
            }
121
            else
122
            {
123
                symbol_Public = client.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
            client.Close();
135
        }
136

    
137
        public PngBitmapEncoder symImage(string data)
138
        {
139

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

    
146
            BitmapEncoder encoder = new PngBitmapEncoder();
147

    
148

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

    
151
            DrawingVisual dv = new DrawingVisual();
152

    
153
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
154
            //_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)));
155
            _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)));
156

    
157
            using (DrawingContext ctx = dv.RenderOpen())
158
            {
159
                VisualBrush vb = new VisualBrush(_canvas);
160
                //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)));
161
                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)));
162
            }
163

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

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

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

    
185
        }
186

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

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

    
207
        #region Event
208

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

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

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

    
251
        }
252
        #endregion
253

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
589
        public Multi_Undo_data multi_Undo_Data;
590
        private void ApplyDragSelectionRect()
591
        {
592
            move = new Move();
593
            multi_Undo_Data = new Multi_Undo_data();
594

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

    
603
            this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Visibility = Visibility.Collapsed;
604

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

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

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

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

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

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

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

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

    
673
                IsMouseDown = true;
674

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

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

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

    
709
        }
710
        #endregion
711

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

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

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

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

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

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

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

    
796
        #endregion
797

    
798
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
799
        {
800

    
801
        }
802

    
803
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
804
        {
805

    
806
        }
807

    
808
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
809
        {
810

    
811
        }
812

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

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

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

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

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

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

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

    
879
                }
880
                else
881
                {
882
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.RefactoryCommentReact(menu);
883
                }
884
            }
885
            Application.Current.MainWindow.Focus();
886
            Common.ViewerDataModel.Instance.Capture_Opacity = 0.49;
887
            (Application.Current.MainWindow as MainWindow).dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Capture;
888
        }
889

    
890

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

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

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

    
927
            }
928
        }
929

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

    
950
                //((System.Windows.Controls.TextBox)sender).Text;
951

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