프로젝트

일반

사용자정보

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

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

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

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

    
21
namespace KCOM.Controls
22
{
23
    public class Symbol_Custom
24
    {
25
        public string ID { get; set; }
26
        public string Name { get; set; }
27
        public string ImageUri { get; set; }
28
    }
29

    
30
    /// <summary>
31
    /// Symbol.xaml에 대한 상호 작용 논리
32
    /// </summary>
33
    public partial class Symbol : UserControl
34
    {
35
        AdornerFinal finalItem;
36
        bool IsMouseDown = false;
37
        string moveItem_id = "";
38
        public string filename { get; set; }
39
        MarkupToPDF.Controls.Parsing.LayerControl layer = new MarkupToPDF.Controls.Parsing.LayerControl();
40

    
41
        public Symbol()
42
        {
43
            InitializeComponent();
44
            
45
            RadDragAndDropManager.AddDragInfoHandler(lstSymbolPrivate, OnDragPrivateInfo);
46
            RadDragAndDropManager.AddDragQueryHandler(lstSymbolPrivate, OnDragPrivateQuery);
47
            RadDragAndDropManager.SetAllowDrag(lstSymbolPrivate, true);
48

    
49
            DataBind();
50
        }
51

    
52
        private void OnDragPrivateInfo(object sender, DragDropEventArgs e)
53
        {
54
        }
55

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

    
66
                //e.Options.Payload = im;
67
                //var dragCue = new Image();
68
                //dragCue.Source = img.Source;
69
                //dragCue.Width = 0;
70
                //dragCue.Height = 0;
71
                //e.Options.DragCue = dragCue;
72

    
73

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

    
82
            e.QueryResult = true;
83
            e.Handled = true;
84
        }
85

    
86
        private void DataBind()
87
        {
88
            //lstSymbolPrivate.ItemsSource = null;
89
            //lstSymbolPublic.ItemsSource = null;
90

    
91
            Symbol_Custom Custom = new Symbol_Custom();
92
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
93
            ServiceDeepView.ServiceDeepViewClient client = new ServiceDeepView.ServiceDeepViewClient(App._binding, App._EndPoint);
94
            var symbol_Private = client.GetSymbolList(App.ViewInfo.UserID);
95
            foreach (var item in symbol_Private)
96
            {
97
                Custom.Name = item.NAME;
98
                Custom.ImageUri = item.IMAGE_URL;
99
                Custom.ID = item.ID;
100
                Custom_List.Add(Custom);
101
                Custom = new Symbol_Custom();
102
            }
103
            lstSymbolPrivate.ItemsSource = Custom_List;
104

    
105
            Custom = new Symbol_Custom();
106
            Custom_List = new List<Symbol_Custom>();
107

    
108
            deptlist.ItemsSource = client.GetPublicSymbolDeptList();
109

    
110
            List<SYMBOL_PUBLIC> symbol_Public;
111

    
112
            
113
            if (deptlist.SelectedValue != null)
114
            {
115
                symbol_Public = client.GetPublicSymbolList(deptlist.SelectedValue.ToString());
116
            }
117
            else
118
            {
119
                symbol_Public = client.GetPublicSymbolList(null);
120
            }
121
            foreach (var item in symbol_Public)
122
            {
123
                Custom.Name = item.NAME;
124
                Custom.ImageUri = item.IMAGE_URL;
125
                Custom.ID = item.ID;
126
                Custom_List.Add(Custom);
127
                Custom = new Symbol_Custom();
128
            }
129
            lstSymbolPublic.ItemsSource = Custom_List;
130
            client.Close();
131
        }
132

    
133
        public PngBitmapEncoder symImage(string data)
134
        {
135

    
136
            Canvas _canvas = new Canvas();
137
            _canvas.Background = Brushes.White;
138
            _canvas.Width = finalItem.BorderSize.Width;
139
            _canvas.Height = finalItem.BorderSize.Height;
140
            layer.markupParse(data, _canvas, "#FFFF0000", "");
141

    
142
            BitmapEncoder encoder = new PngBitmapEncoder();
143

    
144

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

    
147
            DrawingVisual dv = new DrawingVisual();
148

    
149
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
150
            //_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)));
151
            _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)));
152

    
153
            using (DrawingContext ctx = dv.RenderOpen())
154
            {
155
                VisualBrush vb = new VisualBrush(_canvas);
156
                //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)));
157
                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)));
158
            }
159

    
160
            try
161
            {
162
                renderBitmap.Render(dv);
163

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

    
175
            }
176
            catch (Exception ex)
177
            {
178
                return null;
179
            }
180

    
181
        }
182

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

    
192
            DialogParameters parameters = new DialogParameters()
193
            {
194
                Content = box,
195
                Header = header,
196
                Theme = new VisualStudio2013Theme(),
197
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
198
            };
199
            RadWindow.Alert(parameters);
200
        }
201

    
202
        #region Event
203

    
204
        #region Symbol Add Event
205
        private void Create_Symbol(object sender, RoutedEventArgs e)
206
        {
207
            MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn();
208

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

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

    
245
        }
246
        #endregion
247

    
248
        #region Symbol Add Close Event 
249
        private void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
250
        {
251
            Save save = new Save();
252

    
253
            if (args.DialogResult.Value)
254
            {
255
                PngBitmapEncoder _Encoder = symImage(data);
256

    
257
                System.IO.MemoryStream fs = new System.IO.MemoryStream();
258
                _Encoder.Save(fs);
259
                System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
260

    
261
                byte[] Img_byte = fs.ToArray();
262

    
263
                kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
264
                filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Save.shortGuid() + ".png", Img_byte);
265

    
266
                save.SymbolSave(args.PromptResult, filename, data);
267

    
268
                DataBind();
269
            }
270
        }
271
        #endregion
272

    
273
        #region Symbol Delete Event
274
        private void Remove_Symbol(object sender, RoutedEventArgs e)
275
        {
276
            if (lstSymbolPrivate.SelectedItem == null)
277
            {
278
                DialogMessage_Alert("Please Select Symbol", "Alert");
279
                return;
280
            }
281
            string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
282
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolCompleted += BaseClient_DeleteSymbolCompleted;
283
            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.DeleteSymbolAsync(delItem_ID);
284
            
285
        }
286

    
287
        private void BaseClient_DeleteSymbolCompleted(object sender, ServiceDeepView.DeleteSymbolCompletedEventArgs e)
288
        {
289
            DataBind();
290
        }
291
        #endregion
292

    
293
        /// <summary>
294
        /// place symbol which has given id to original position which is created
295
        /// </summary>
296
        /// <date>2018.06.14</date>
297
        /// <param name="id"></param>
298
        private void PlaceSymbol(string id)
299
        {
300
            string Data_ = "";
301

    
302
            try
303
            {
304
                Data_ = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetSymbolData(id, RadTab.SelectedIndex);
305

    
306
                if (Data_.Contains("|DZ|"))
307
                {
308
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
309

    
310
                    string[] delimiterChars = { "|DZ|" };
311
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
312

    
313
                    foreach (string parse in data)
314
                    {
315
                        if (parse != "")
316
                        {
317
                            System.Windows.Controls.Control item = layer.markupParse_Paste(parse, ViewerDataModel.Instance.MarkupControls_USER);
318
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Events.Save.shortGuid();
319

    
320
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
321
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
322

    
323
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
324
                        }
325
                    }
326
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
327

    
328
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
329
                }
330
            }
331
            catch(Exception ex)
332
            {
333
                this.ParentOfType<MainWindow>().dzMainMenu.DialogMessage_Alert(ex.Message,  "Error");
334
            }
335
        }
336

    
337
        #region Symbol DoubleClick Event
338
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
339
        {
340
            string id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
341
            IsMouseDown = true;
342
            if (e.ClickCount > 1)
343
            {
344
                this.PlaceSymbol(id);
345
            }
346
        }
347
        #endregion
348

    
349
        #region Symbol Rename Event
350
        private void Rename_Symbol(object sender, RoutedEventArgs e)
351
        {
352
            if (lstSymbolPrivate.SelectedItem == null)
353
            {
354
                DialogMessage_Alert("Please Select Symbol", "Alert");
355
                return;
356
            }
357

    
358
            DialogParameters parameters = new DialogParameters()
359
            {
360
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
361
                //DefaultPromptResultValue = "Custom State",
362
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
363
                Content = "Name :",
364
                Header = "Update Custom Symbol Name",
365
                Theme = new VisualStudio2013Theme(),
366
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
367
            };
368
            RadWindow.Prompt(parameters);
369

    
370
        }
371
        #endregion
372

    
373
        #region Symbol Rename Close Event
374
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
375
        {
376
            if (args.DialogResult != null && args.DialogResult.Value)
377
            {
378
                string _id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
379
                string _name = args.PromptResult;
380
                
381
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolCompleted += BaseClient_RenameSymbolCompleted;
382
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.RenameSymbolAsync(_id, _name);
383
                
384
            }
385
        }
386

    
387
        private void BaseClient_RenameSymbolCompleted(object sender, ServiceDeepView.RenameSymbolCompletedEventArgs e)
388
        {
389
            DataBind();
390
        }
391
        #endregion
392

    
393
        #region Wheel Event
394
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
395
        {
396
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
397
        }
398
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
399
        {
400
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
401
        }
402
        #endregion
403

    
404
        #region Tab Selection Event
405
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
406
        {
407
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
408
            {
409
                (item as RadTabItem).FontWeight = FontWeights.Normal;
410
            }
411
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
412
        }
413
        #endregion
414

    
415
        #region Department Selection Event
416
        private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
417
        {
418
            DataBind();
419
        }
420
        #endregion
421

    
422
        #endregion
423

    
424
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
425
        {
426

    
427
        }
428

    
429
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
430
        {
431

    
432
        }
433

    
434
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
435
        {
436

    
437
        }
438

    
439
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
440
        {
441
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
442
            {
443
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
444
            }
445
            else
446
            {
447
                IsMouseDown = false;
448
            }
449
        }
450

    
451
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
452
        {
453
            IsMouseDown = false;
454
        }
455

    
456
        /// <summary>
457
        /// place symbol which user select
458
        /// </summary>
459
        /// <author>humkyung</author>
460
        /// <date>2018.06.14</date>
461
        /// <param name="sender"></param>
462
        /// <param name="e"></param>
463
        private void Place_Symbol(object sender, RoutedEventArgs e)
464
        {
465
            if (lstSymbolPrivate.SelectedItem == null)
466
            {
467
                DialogMessage_Alert("Please Select Symbol",  "Alert");
468
                return;
469
            }
470

    
471
            string id = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
472
            this.PlaceSymbol(id);
473
        }
474
    }
475
}
클립보드 이미지 추가 (최대 크기: 500 MB)