프로젝트

일반

사용자정보

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

markus / KCOM / Controls / Symbol.xaml.cs @ f65e6c02

이력 | 보기 | 이력해설 | 다운로드 (44.5 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.Threading.Tasks;
15
using System.Windows;
16
using System.Windows.Controls;
17
using System.Windows.Data;
18
using System.Windows.Documents;
19
using System.Windows.Input;
20
using System.Windows.Media;
21
using System.Windows.Media.Imaging;
22
using System.Windows.Navigation;
23
using System.Windows.Shapes;
24
using Telerik.Windows.Controls;
25
using Telerik.Windows.Controls.DragDrop;
26

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

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

    
47
        public Symbol()
48
        {
49
            //App.splashString(ISplashMessage.SYMBOL);
50
            InitializeComponent();
51

    
52
            //RadDragAndDropManager.AddDragInfoHandler(lstSymbolPrivate, OnDragPrivateInfo);
53
            //RadDragAndDropManager.AddDragQueryHandler(lstSymbolPrivate, OnDragPrivateQuery);
54
            //RadDragAndDropManager.SetAllowDrag(lstSymbolPrivate, true);
55
            this.Loaded += Symbol_Loaded;
56
 
57
        }
58

    
59
        
60

    
61
        private async void Symbol_Loaded(object sender, RoutedEventArgs e)
62
        {
63
            if (!_Initialize)
64
            {
65
                _Initialize = true;
66
                await DataBindAsync();
67

    
68
            }
69
        }
70

    
71
        private void OnDragPrivateInfo(object sender, DragDropEventArgs e)
72
        {
73
        }
74

    
75
        private void OnDragPrivateQuery(object sender, DragDropQueryEventArgs e)
76
        {
77
            if (e.Options.Status == DragStatus.DragQuery)
78
            {
79
                //var draggedListBoxItem = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem;
80
                //BitmapImage im = new BitmapImage(new Uri((draggedListBoxItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate).ImageUri));
81
                //ImageSource _source = im;
82
                //Image img = new Image();
83
                //img.Source = _source;
84

    
85
                //e.Options.Payload = im;
86
                //var dragCue = new Image();
87
                //dragCue.Source = img.Source;
88
                //dragCue.Width = 0;
89
                //dragCue.Height = 0;
90
                //e.Options.DragCue = dragCue;
91

    
92

    
93
                //PayLoadAdorner = new AdornerFinal();
94
                //DeepView.ServiceDeepView_Symbol.SymbolPrivate tempDragableControl = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate;
95
                //var xamldata = tempDragableControl.Data;
96
                ////this.DeepLayer.markupParse(xamldata, this.DeepLayer._TempLayer, "복사된 데이터_이름으로 수정해야함");
97
                //PayLoadAdorner = this.DeepLayer.markupParseToAdorner(xamldata, this.DeepLayer._SelectLayer, "");
98
                //this.DeepLayer._SelectLayer.Children.Add(PayLoadAdorner);
99
            }
100

    
101
            e.QueryResult = true;
102
            e.Handled = true;
103
        }
104

    
105
        private async Task DataBindAsync()
106
        {
107
            //lstSymbolPrivate.ItemsSource = null;
108
            //lstSymbolPublic.ItemsSource = null;
109

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

    
113
            try
114
            {
115

    
116
                var symbol_Private = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetSymbolListAsync(App.ViewInfo.UserID);
117

    
118
                foreach (var item in symbol_Private)
119
                {
120
                    Custom.Name = item.NAME;
121
                    Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL, App.isExternal);
122
                    Custom.ID = item.ID;
123
                    Custom_List.Add(Custom);
124
                    Custom = new Symbol_Custom();
125
                }
126
                lstSymbolPrivate.ItemsSource = Custom_List;
127
            }
128
            catch (Exception ex)
129
            {
130
                System.Diagnostics.Debug.WriteLine(ex.ToString());
131
            }
132

    
133
            Custom = new Symbol_Custom();
134
            Custom_List = new List<Symbol_Custom>();
135

    
136
            deptlist.ItemsSource = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetPublicSymbolDeptListAsync();
137

    
138
            List<SYMBOL_PUBLIC> symbol_Public;
139

    
140

    
141
            if (deptlist.SelectedValue != null)
142
            {
143
                symbol_Public = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetPublicSymbolListAsync(deptlist.SelectedValue.ToString());
144
            }
145
            else
146
            {
147
                symbol_Public = await ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseTaskClient.GetPublicSymbolListAsync(null);
148
            }
149
        
150
            foreach (var item in symbol_Public)
151
            {
152
                Custom.Name = item.NAME;
153
                Custom.ImageUri = CommonLib.Common.IPReplace(item.IMAGE_URL, App.isExternal);
154
                Custom.ID = item.ID;
155
                Custom_List.Add(Custom);
156
                Custom = new Symbol_Custom();
157
            }
158

    
159
            lstSymbolPublic.ItemsSource = Custom_List;
160
        }
161

    
162
        public PngBitmapEncoder symImage(string data)
163
        {
164

    
165
            Canvas _canvas = new Canvas();
166
            _canvas.Background = Brushes.White;
167
            _canvas.Width = finalItem.BorderSize.Width;
168
            _canvas.Height = finalItem.BorderSize.Height;
169
            MarkupParser.Parse(App.ViewInfo.ProjectNO, data, _canvas, "#FFFF0000", "");
170

    
171
            BitmapEncoder encoder = new PngBitmapEncoder();
172

    
173

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

    
176
            DrawingVisual dv = new DrawingVisual();
177

    
178
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
179
            //_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)));
180
            _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)));
181

    
182
            using (DrawingContext ctx = dv.RenderOpen())
183
            {
184
                VisualBrush vb = new VisualBrush(_canvas);
185
                //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)));
186
                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)));
187
            }
188

    
189
            try
190
            {
191
                renderBitmap.Render(dv);
192

    
193
                GC.Collect();
194
                GC.WaitForPendingFinalizers();
195
                GC.Collect();
196
                //bitmap.Render(controlToConvert);
197
                // encode png data
198
                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
199
                // puch rendered bitmap into it
200
                pngEncoder.Interlace = PngInterlaceOption.Off;
201
                pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
202
                return pngEncoder;
203

    
204
            }
205
            catch //(Exception ex)
206
            {
207
                return null;
208
            }
209

    
210
        }
211

    
212
        public void DialogMessage_Alert(string content, string header)
213
        {
214
            DialogParameters parameters = new DialogParameters()
215
            {
216
                Owner = Application.Current.MainWindow,
217
                Content = new TextBlock()
218
                {
219
                    MinWidth = 400,
220
                    FontSize = 11,
221
                    Text = content,
222
                    TextWrapping = System.Windows.TextWrapping.Wrap
223
                },
224
                Header = header,
225
                Theme = new VisualStudio2013Theme(),
226
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
227
            };
228
            RadWindow.Alert(parameters);
229
        }
230

    
231
        #region Event
232

    
233
        #region Private Symbol Add Event
234
        private void Create_Symbol(object sender, RoutedEventArgs e)
235
        {
236
            MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.MarkupParser.MarkupReturn();
237

    
238
            if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면
239
            {
240
                DialogMessage_Alert("Please Select Controls", "Alert");
241
            }
242
            else //선택된 것이 있으면
243
            {
244
                string MarkupData = "";
245
                finalItem = new AdornerFinal();
246

    
247
                foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children)
248
                {
249
                    if (item.GetType().Name == "AdornerFinal")
250
                    {
251
                        finalItem = (item as Controls.AdornerFinal);
252
                        foreach (var InnerItem in (item as Controls.AdornerFinal).Members.Cast<Controls.AdornerMember>())
253
                        {
254
                            if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData))
255
                            {
256
                                markupReturn = MarkupParser.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID);
257
                                MarkupData += markupReturn.ConvertData;
258
                            }
259
                        }
260
                    }
261
                }
262
                DialogParameters parameters = new DialogParameters()
263
                {
264
                    Owner = Application.Current.MainWindow,
265
                    Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args),
266
                    DefaultPromptResultValue = "Custom State",
267
                    Content = "Name :",
268
                    Header = "Insert Custom Symbol Name",
269
                    Theme = new VisualStudio2013Theme(),
270
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
271
                };
272
                RadWindow.Prompt(parameters);
273
            }
274

    
275
        }
276
        #endregion
277

    
278
        #region Symbol Add Close Event 
279
        private async void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
280
        {
281
            try
282
            {
283
                if (args.PromptResult != null)
284
                {
285
                    if (args.DialogResult.Value)
286
                    {
287
                        PngBitmapEncoder _Encoder = symImage(data);
288

    
289
                        System.IO.MemoryStream fs = new System.IO.MemoryStream();
290
                        _Encoder.Save(fs);
291
                        System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
292

    
293
                        byte[] Img_byte = fs.ToArray();
294

    
295
                        kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
296
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Commons.shortGuid() + ".png", Img_byte);
297
                        Check_Uri.UriCheck(filename);
298
                        if (RadTab.SelectedIndex == 0)
299
                        {
300
                            SymbolSave(args.PromptResult, filename, data);
301
                        }
302
                        else
303
                        {
304
                            SymbolSave_Public(args.PromptResult, filename, data, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.userData.DEPARTMENT);
305
                        }
306

    
307
                        await DataBindAsync();
308
                    }
309
                }
310
            }
311
            catch(Exception ex)
312
            {
313
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
314
            }
315
        }
316
        #endregion
317

    
318
        public void SymbolSave(string Name, string Url, string Data)
319
        {
320
            try
321
            {
322
                SYMBOL_PRIVATE symbol_private = new SYMBOL_PRIVATE
323
                {
324
                    ID = Commons.shortGuid(),
325
                    MEMBER_USER_ID = App.ViewInfo.UserID,
326
                    NAME = Name,
327
                    IMAGE_URL = Url,
328
                    DATA = Data
329
                };
330

    
331
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolCompleted += BaseClient_SaveSymbolCompleted;
332
                Logger.sendReqLog("SaveSymbolAsync: ", symbol_private.ID + "," + symbol_private.MEMBER_USER_ID + "," + symbol_private.NAME + "," + symbol_private.IMAGE_URL + "," + symbol_private.DATA, 1);
333
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveSymbolAsync(symbol_private);
334
            }
335
            catch (Exception)
336
            {
337
                throw;
338
            }
339
        }
340

    
341
        public void SymbolSave_Public(string Name, string Url, string Data, string Department)
342
        {
343
            try
344
            {
345
                SYMBOL_PUBLIC symbol_public = new SYMBOL_PUBLIC
346
                {
347
                    ID = Commons.shortGuid(),
348
                    DEPARTMENT = Department,
349
                    NAME = Name,
350
                    IMAGE_URL = Url,
351
                    DATA = Data
352
                };
353
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbolCompleted += BaseClient_AddPublicSymbolCompleted;
354
                Logger.sendReqLog("AddPublicSymbol: ", symbol_public.ID + "," + symbol_public.DEPARTMENT + "," + symbol_public.NAME + "," + symbol_public.IMAGE_URL + "," + symbol_public.DATA, 1);
355
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddPublicSymbol(symbol_public);
356
            }
357
            catch (Exception)
358
            {
359
                throw;
360
            }
361
        }
362

    
363
        private async void BaseClient_AddPublicSymbolCompleted(object sender, ServiceDeepView.AddPublicSymbolCompletedEventArgs e)
364
        {
365
            Logger.sendResLog("AddPublicSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
366
            await DataBindAsync();
367
        }
368

    
369
        private async void BaseClient_SaveSymbolCompleted(object sender, ServiceDeepView.SaveSymbolCompletedEventArgs e)
370
        {
371
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
372
            await DataBindAsync();
373
        }
374

    
375
        #region Private Symbol Delete Event
376
        private void Remove_Symbol(object sender, RoutedEventArgs e)
377
        {
378
            if (lstSymbolPrivate.SelectedItem == null)
379
            {
380
                DialogMessage_Alert("Please Select Symbol", "Alert");
381
                return;
382
            }
383
            string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
384

    
385
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
386
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
387
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
388
        }
389
        #endregion
390
        #region Public Symbol Delete Event
391
        private void Remove_Symbol_Public(object sender, RoutedEventArgs e)
392
        {
393
            if (lstSymbolPublic.SelectedItem == null)
394
            {
395
                DialogMessage_Alert("Please Select Symbol", "Alert");
396
                return;
397
            }
398
            string delItem_ID = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
399

    
400
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
401
            Logger.sendReqLog("DeleteSymbolAsync: ", delItem_ID, 1);
402
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID, RadTab.SelectedIndex);
403
        }
404

    
405
        private async void BaseClient_DeleteSymbolCompleted(object sender, ServiceDeepView.DeleteSymbolCompletedEventArgs e)
406
        {
407
            Logger.sendResLog("DeleteSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
408
             await DataBindAsync();
409
        }
410
        #endregion
411

    
412
        public Undo_data UndoData { get; set; }
413
        /// <summary>
414
        /// place symbol which has given id to original position which is created
415
        /// </summary>
416
        /// <date>2018.06.14</date>
417
        /// <param name="id"></param>
418
        private void PlaceSymbol(string id,Point CurrentMousePoint)
419
        {
420
            string Data_ = "";
421

    
422
            var systemMain = Common.ViewerDataModel.Instance.SystemMain;
423
            var mainMenu = systemMain.dzMainMenu;
424
            
425
            SelectionSet.Instance.UnSelect(mainMenu);  /// unselect alreay selected items
426

    
427
            try
428
            {
429
                Logger.sendReqLog("GetSymbolData: ", id + "," + RadTab.SelectedIndex, 1);
430
                Data_ = mainMenu.BaseClient.GetSymbolData(id, RadTab.SelectedIndex);
431

    
432
                if (Data_ != null || Data_ != "")
433
                {
434
                    Logger.sendResLog("GetSymbolData", "TRUE", 1);
435
                }
436
                else
437
                {
438
                    Logger.sendResLog("GetSymbolData", "FALSE", 1);
439
                }
440

    
441
                //MARKUP_DATA_GROUP INSERT
442
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
443
                //{
444
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
445
                //    STATE = 0,
446
                //};
447
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
448
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
449

    
450
                if (Data_.Contains("|DZ|"))
451
                {
452
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
453

    
454
                    string[] delimiterChars = { "|DZ|" };
455
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
456

    
457
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
458
                    UndoData = new Undo_data()
459
                    {
460
                        IsUndo = false,
461
                        Event = Event_Type.Create,
462
                        EventTime = DateTime.Now,
463
                        Markup_List = new List<Multi_Undo_data>()
464
                    };
465
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
466
                    {
467
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
468
                    });
469

    
470
                    foreach (string parse in data)
471
                    {
472
                        if (parse != "")
473
                        {
474
                            System.Windows.Controls.Control item = MarkupParser.ParseEx(App.ViewInfo.ProjectNO, parse, ViewerDataModel.Instance.MarkupControls_USER, string.Empty, string.Empty);
475
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
476
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = id;
477
                            //(item as MarkupToPDF.Common.CommentUserInfo).GroupID = group_id;
478

    
479
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
480
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
481

    
482
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
483

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

    
486
                            UndoData.Markup_List.Add(multi_Undo_Data);
487
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
488
                        }
489
                    }
490

    
491
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
492

    
493
                    // 마우스 클릭된 페이지 위치
494

    
495
                    var pageWidth = mainMenu.pageNavigator.CurrentPage.Width;
496
                    var pageHeight = mainMenu.pageNavigator.CurrentPage.Height;
497
                    var angle = Common.ViewerDataModel.Instance.Angle;
498

    
499
                    Point pagePoint = new Point(pageWidth/2, pageHeight/2);
500

    
501
                    var rotatePoint = Rotate(mainMenu.CanvasDrawingMouseDownPoint,pagePoint,angle);
502

    
503
                    var diff = Point.Subtract(rotatePoint, final.Centeroid);
504
                    final.TranslateItems(diff.X, diff.Y);
505

    
506
                    mainMenu.SelectLayer.Children.Add(final);
507
                    //var finalPosition = new Point(Canvas.GetLeft(final), Canvas.GetTop(final));
508
                    //Rect rect = new Rect(finalPosition, Point.Add(finalPosition,new Vector(final.Width,final.Height)));
509

    
510
                    //SelectionSet.Instance.SelectItemByRect(final.getAdornerSize(), mainMenu);
511

    
512
                }
513
                else
514
                {
515
                    PlaceImageSymbol(id, 0);
516
                }
517
            }
518
            catch (Exception ex)
519
            {
520
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
521
            }
522
        }
523

    
524

    
525
        //출처: https://icodebroker.tistory.com/3189 [ICODEBROKER]
526
        public Point Rotate(Point sourcePoint, Point centerPoint, double rotateAngle)
527
        {
528
            Point targetPoint = new Point();
529

    
530
            double radian = rotateAngle / 180 * Math.PI;
531

    
532
            targetPoint.X = Math.Cos(radian) * (sourcePoint.X - centerPoint.X) - Math.Sin(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.X;
533
            targetPoint.Y = Math.Sin(radian) * (sourcePoint.X - centerPoint.X) + Math.Cos(radian) * (sourcePoint.Y - centerPoint.Y) + centerPoint.Y;
534

    
535
            return targetPoint;
536
        }
537

    
538

    
539

    
540
        private void PlaceImageSymbol(string id, long group_id)
541
        {
542
           
543
            //canvasZoommovingMouseDownPoint
544
            string Data_ = "";
545

    
546
            try
547
            {
548
                Logger.sendReqLog("GetSymbolImageURL: ", id + "," + RadTab.SelectedIndex, 1);
549
                Data_ = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolImageURL(id, RadTab.SelectedIndex);
550
                if (Data_ != null || Data_ != "")
551
                {
552
                    Logger.sendResLog("GetSymbolImageURL", "TRUE", 1);
553
                }
554
                else
555
                {
556
                    Logger.sendResLog("GetSymbolImageURL", "FALSE", 1);
557
                }
558

    
559
                //MARKUP_DATA_GROUP INSERT
560
                //MARKUP_DATA_GROUP mARKUP_DATA_GROUP = new MARKUP_DATA_GROUP
561
                //{
562
                //    SYMBOL_ID = id,//InnerItem.Symbol_ID
563
                //    STATE = 0,
564
                //};
565
                //long group_id = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.AddMarkupDataGroup(mARKUP_DATA_GROUP, App.ViewInfo.ProjectNO);
566
                //Logger.sendReqLog("AddMarkupDataGroup: ", "", 1);
567

    
568
                if (Data_ != null)
569
                {
570
                    Image img = new Image();
571
                    //img.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(Data_));
572
                    if (Data_.Contains(".svg"))
573
                    {
574
                        byte[] imageData = null;
575
                        DrawingImage image = null;
576
                        using (System.Net.WebClient web = new System.Net.WebClient())
577
                        {
578
                            imageData = web.DownloadData(new Uri(Data_));
579
                            System.IO.Stream stream = new System.IO.MemoryStream(imageData);
580
                            image = SvgReader.Load(stream);
581
                        }
582
                        img.Source = image;
583
                    }
584
                    else
585
                    {
586
                        img.Source = new BitmapImage(new Uri(Data_));
587
                    }
588

    
589
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
590
                    {
591
                        PointSet = new List<Point>(),
592
                        FilePath = Data_,
593
                        ImageData = img.Source,
594
                        StartPoint = new Point(0, 0),
595
                        EndPoint = new Point(img.Source.Width, img.Source.Height),
596
                        TopRightPoint = new Point(img.Source.Width, 0),
597
                        LeftBottomPoint = new Point(0, img.Source.Height)
598
                    };
599

    
600
                    currentControl.PointSet = new List<Point>
601
                                        {
602
                                            currentControl.StartPoint,
603
                                            currentControl.LeftBottomPoint,
604
                                            currentControl.EndPoint,
605
                                            currentControl.TopRightPoint,
606
                                        };
607
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
608
                    UndoData = new Undo_data()
609
                    {
610
                        IsUndo = false,
611
                        Event = Event_Type.Create,
612
                        EventTime = DateTime.Now,
613
                        Markup_List = new List<Multi_Undo_data>()
614
                    };
615
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
616
                    {
617
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
618
                    });
619

    
620
                    //multi_Undo_Data = dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
621
                    multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
622
                    UndoData.Markup_List.Add(multi_Undo_Data);
623
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
624

    
625
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
626
                    currentControl.CommentID = Commons.shortGuid();
627
                    currentControl.SymbolID = id;
628
                    currentControl.GroupID = group_id;
629
                    currentControl.ApplyTemplate();
630
                    currentControl.SetImage();
631

    
632
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
633
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
634
                    this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
635

    
636
                    /*
637
                    // this.ParentOfType<MainWindow>().dzMainMenu.isLeftMouseButtonDownOnWindow = true;
638
                    // final.MoveAdorner(new System.Windows.Controls.Primitives.DragDeltaEventArgs(realPointX, realPointY));
639
                    double realPointX = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.X - final.BorderSize.X - (final.BorderSize.Width / 2);
640
                    double realPointY = this.ParentOfType<MainWindow>().dzMainMenu.getCurrentPoint.Y - final.BorderSize.Y - (final.BorderSize.Height / 2);
641
                      final.TranslateItems(realPointX, realPointY);
642
                    // move.control_Select(item, dragRect);
643
                    ApplyDragSelectionRect();
644
                    //this.ParentOfType<MainWindow>().dzMainMenu.mouseHandlingMode = MouseHandlingMode.DragSymbol;
645
                    ///this.ParentOfType<MainWindow>().dzMainMenu.mouseButtonDown = MouseButton.Left;
646
                    //this.ParentOfType<MainWindow>().dzMainMenu.symboldata(id, group_id, RadTab.SelectedIndex, Data_, img.Source);*/
647
                    
648
                }
649
            }
650
            catch(Exception ex)
651
            {
652
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message, "Error");
653
            }
654
        }
655

    
656
        public Multi_Undo_data multi_Undo_Data;
657
        private void ApplyDragSelectionRect()
658
        {
659
            multi_Undo_Data = new Multi_Undo_data();
660

    
661
            UndoData = new Undo_data()
662
            {
663
                IsUndo = false,
664
                Event = Event_Type.Select,
665
                EventTime = DateTime.Now,
666
                Markup_List = new List<Multi_Undo_data>()
667
            };
668

    
669
            this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Visibility = Visibility.Collapsed;
670

    
671
            double x = Canvas.GetLeft(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
672
            double y = Canvas.GetTop(this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder);
673
            double width = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Width;
674
            double height = this.ParentOfType<MainWindow>().dzMainMenu.dragSelectionBorder.Height;
675
            Rect dragRect = new Rect(x, y, width, height);
676
            Boolean Flag = false;
677
            dragRect.Inflate(width / 10, height / 10);
678
            List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
679
            var Items = ViewerDataModel.Instance.MarkupControls_USER.ToList();
680

    
681
            dragRect = new Rect(x, y, width, height);
682
            dragRect.Inflate(width / 10, height / 10);
683

    
684
            //move.mousemode = MarkupToPDF.Controls.Common.MouseMode.Selecting;
685
            //move.
686
            foreach (var item in Items)
687
            {
688
                Flag = SelectionSet.Instance.SelectControl(item, dragRect);
689

    
690
                if (Flag)
691
                {
692
                    adornerSet.Add(item);
693
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(item);
694

    
695
                    this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item);
696
                    UndoData.Markup_List.Add(multi_Undo_Data);
697
                    multi_Undo_Data = new Multi_Undo_data();
698
                    if (item.GroupID > 0)
699
                    {
700

    
701
                    }
702
                }
703
            }
704
            if (adornerSet.Count > 0)
705
            {
706
                ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
707
                {
708
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
709
                });
710
                ViewerDataModel.Instance.UndoDataList.Add(UndoData);
711

    
712
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
713
                this.ParentOfType<MainWindow>().dzMainMenu.SelectLayer.Children.Add(final);
714
            }
715
        }
716

    
717
        ///private Move move;
718
        #region Symbol DoubleClick Event
719
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
720
        {
721
            try
722
            {
723
                Type type = e.OriginalSource.GetType();
724
                string id = string.Empty;
725
                Logger.sendResLog("Move_Symbol", type.Name, 0);
726
                if (type.Name == "Image")
727
                {
728
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
729
                }
730
                else if (type.Name == "Border")
731
                {
732
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
733
                }
734
                else if (type.Name == "TextBox")
735
                {
736
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
737
                }
738

    
739
                IsMouseDown = true;
740

    
741
                if (e.ClickCount > 1)
742
                {
743
                    this.PlaceSymbol(id,ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
744
                }
745
            }
746
            catch(Exception ex)
747
            {
748
                Logger.sendResLog("Move_Symbol", ex.Message, 0);
749
            }
750
        }
751
        #endregion
752

    
753
        #region Private Symbol Rename Event
754
        private void Rename_Symbol(object sender, RoutedEventArgs e)
755
        {
756
            if (lstSymbolPrivate.SelectedItem == null)
757
            {
758
                DialogMessage_Alert("Please Select Symbol", "Alert");
759
                return;
760
            }
761

    
762
            DialogParameters parameters = new DialogParameters()
763
            {
764
                Owner = Application.Current.MainWindow,
765
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
766
                //DefaultPromptResultValue = "Custom State",
767
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
768
                Content = "Name :",
769
                Header = "Update Custom Symbol Name",
770
                Theme = new VisualStudio2013Theme(),
771
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
772
            };
773
            RadWindow.Prompt(parameters);
774

    
775
        }
776
        #endregion
777

    
778
        #region Public Symbol Rename Event
779
        private void Rename_Symbol_Public(object sender, RoutedEventArgs e)
780
        {
781
            if (lstSymbolPublic.SelectedItem == null)
782
            {
783
                DialogMessage_Alert("Please Select Symbol", "Alert");
784
                return;
785
            }
786

    
787
            DialogParameters parameters = new DialogParameters()
788
            {
789
                Owner = Application.Current.MainWindow,
790
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
791
                //DefaultPromptResultValue = "Custom State",
792
                DefaultPromptResultValue = (lstSymbolPublic.SelectedItem as Symbol_Custom).Name,
793
                Content = "Name :",
794
                Header = "Update Custom Symbol Name",
795
                Theme = new VisualStudio2013Theme(),
796
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
797
            };
798
            RadWindow.Prompt(parameters);
799

    
800
        }
801
        #endregion
802
        #region Symbol Rename Close Event
803
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
804
        {
805
            if (args.DialogResult != null && args.DialogResult.Value)
806
            {
807
                if(RadTab.SelectedIndex == 0)
808
                {
809
                    string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
810
                    string _name = args.PromptResult;
811
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
812
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
813
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
814
                }
815
                else
816
                {
817
                    string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
818
                    string _name = args.PromptResult;
819
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
820
                    Logger.sendReqLog("RenameSymbolAsync: ", _id + "," + _name, 1);
821
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name, RadTab.SelectedIndex);
822
                }
823
            }
824
        }
825

    
826
        private async void BaseClient_RenameSymbolCompleted(object sender, ServiceDeepView.RenameSymbolCompletedEventArgs e)
827
        {
828
            Logger.sendResLog("RenameSymbolCompleted", "UserState : " + e.UserState + "\r Result :" + e.Result + "\r Cancelled :" + e.Cancelled + "\r Error :" + e.Error, 1);
829
            await DataBindAsync();
830
        }
831
        #endregion
832

    
833
        #region Wheel Event
834
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
835
        {
836
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
837
        }
838
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
839
        {
840
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
841
        }
842
        #endregion
843

    
844
        #region Tab Selection Event
845
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
846
        {
847
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
848
            {
849
                (item as RadTabItem).FontWeight = FontWeights.Normal;
850
            }
851
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
852
        }
853
        #endregion
854

    
855
        #region Department Selection Event
856
        private async void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
857
        {
858
            await DataBindAsync();
859
        }
860
        #endregion
861

    
862
        #endregion
863

    
864
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
865
        {
866

    
867
        }
868

    
869
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
870
        {
871

    
872
        }
873

    
874
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
875
        {
876

    
877
        }
878

    
879
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
880
        {
881
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
882
            {
883
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
884
            }
885
            else
886
            {
887
                IsMouseDown = false;
888
            }
889
        }
890

    
891
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
892
        {
893
            IsMouseDown = false;
894
        }
895

    
896
        /// <summary>
897
        /// place symbol which user select
898
        /// </summary>
899
        /// <author>humkyung</author>
900
        /// <date>2018.06.14</date>
901
        /// <param name="sender"></param>
902
        /// <param name="e"></param>
903
        private void Place_Symbol(object sender, RoutedEventArgs e)
904
        {
905
            if (lstSymbolPrivate.SelectedItem == null)
906
            {
907
                DialogMessage_Alert("Please Select Symbol",  "Alert");
908
                return;
909
            }
910

    
911
            string id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
912
            this.PlaceSymbol(id, ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
913
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
914
        }
915

    
916
        private void Place_Symbol_Public(object sender, RoutedEventArgs e)
917
        {
918
            if (lstSymbolPublic.SelectedItem == null)
919
            {
920
                DialogMessage_Alert("Please Select Symbol", "Alert");
921
                return;
922
            }
923

    
924
            string id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
925
            this.PlaceSymbol(id, ViewerDataModel.Instance.SystemMain.dzMainMenu.CanvasDrawingMouseDownPoint);
926
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.None;
927
        }
928

    
929
        private void Image_Place_Register(object sender, RoutedEventArgs e)
930
        {
931
            SyncInit();
932
            ViewerDataModel.Instance.SystemMain.dzMainMenu.controlType = MarkupToPDF.Controls.Common.ControlType.ImgControl;
933
            //캡쳐 하기 전에 코멘트 저장
934
            if (Common.ViewerDataModel.Instance.MarkupControls_USER.Count > 0 || (Application.Current.MainWindow as MainWindow).dzMainMenu.SelectLayer.Children.Count > 0)
935
            {
936
                var menu = (Application.Current.MainWindow as MainWindow).dzMainMenu;
937
                SelectionSet.Instance.UnSelect(menu);
938
                if (menu.PreviewUserMarkupInfoItem != null && menu.PreviewUserMarkupInfoItem.IsPreviewUser == true)
939
                {
940
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEventCallback(null, null);
941
                }
942
                else if (menu.gridViewMarkup.SelectedItems.Count == 0 || (menu.gridViewMarkup.SelectedItems.FirstOrDefault() as IKCOM.MarkupInfoItem).UserID != App.ViewInfo.UserID)
943
                {
944

    
945
                }
946
                else
947
                {
948
                    (Application.Current.MainWindow as MainWindow).dzTopMenu.SaveEventCallback(null, null);
949
                }
950
            }
951
            Application.Current.MainWindow.Focus();
952
            Common.ViewerDataModel.Instance.Capture_Opacity = 0.49;
953
            (Application.Current.MainWindow as MainWindow).dzMainMenu.mouseHandlingMode = IKCOM.MouseHandlingMode.Capture;
954
        }
955

    
956

    
957
        private void SyncInit()
958
        {
959
            try
960
            {
961
                if (!ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden)
962
                {
963
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.testPanel2.IsHidden = true;
964
                    ViewerDataModel.Instance.PageBalanceMode = false;
965
                    ViewerDataModel.Instance.PageBalanceNumber = 0;
966
                    ViewerDataModel.Instance.PageNumber = 0;
967
                    ViewerDataModel.Instance.MarkupControls_Sync.Clear();
968
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.gridViewRevMarkup.Visibility = Visibility.Collapsed;
969
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.UserList.IsChecked = false;
970
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.BalanceMode.IsChecked = false;
971
                }
972
            }
973
            catch (Exception ex)
974
            {
975
                Logger.sendResLog("SyncInit", ex.Message, 0);
976
            }
977
        }
978

    
979
        private void TextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
980
        {
981
            var block = sender as TextBox;
982
            block.Focusable = true;
983
               
984
        }
985

    
986
        private void TextBlock_MouseEnter(object sender, MouseEventArgs e)
987
        {
988
            var block = sender as TextBox;
989
            if (block != null)
990
            {
991
                //block.Text = "Enter";
992

    
993
            }
994
        }
995

    
996
        private void OnKeyDownHandler(object sender, KeyEventArgs e)
997
        {
998
            if (e.Key == Key.Return)
999
            {
1000
                Type type = e.OriginalSource.GetType();
1001
                string id = string.Empty;
1002
                Logger.sendResLog("Move_Symbol", type.Name, 0);
1003
                if (type.Name == "Image")
1004
                {
1005
                    id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
1006
                }
1007
                else if (type.Name == "Border")
1008
                {
1009
                    id = ((e.OriginalSource as Border).DataContext as Symbol_Custom).ID;
1010
                }
1011
                else if (type.Name == "TextBox")
1012
                {
1013
                    id = ((e.OriginalSource as TextBox).DataContext as Symbol_Custom).ID;
1014
                }
1015

    
1016
                //((System.Windows.Controls.TextBox)sender).Text;
1017

    
1018
                if (RadTab.SelectedIndex == 0)
1019
                {
1020
                    //string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
1021
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
1022
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
1023
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
1024
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
1025
                }
1026
                else
1027
                {
1028
                    //string _id = (lstSymbolPublic.SelectedItem as Symbol_Custom).ID;
1029
                    string _name = ((System.Windows.Controls.TextBox)sender).Text;
1030
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
1031
                    Logger.sendReqLog("RenameSymbolAsync: ", id + "," + _name, 1);
1032
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(id, _name, RadTab.SelectedIndex);
1033
                }
1034
                
1035
            }
1036
        }
1037
        
1038
    }
1039
}
클립보드 이미지 추가 (최대 크기: 500 MB)