프로젝트

일반

사용자정보

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

markus / KCOM / Controls / Symbol.xaml.cs @ 01cbc243

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

1 787a4489 KangIngu
using KCOM.Common;
2
using KCOM.Events;
3 5ce56a3a KangIngu
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5 d4b0c723 KangIngu
using MarkupToPDF.Common;
6 787a4489 KangIngu
using System;
7
using System.Collections.Generic;
8
using System.Linq;
9
using System.Text;
10
using System.Windows;
11
using System.Windows.Controls;
12
using System.Windows.Data;
13
using System.Windows.Documents;
14
using System.Windows.Input;
15
using System.Windows.Media;
16
using System.Windows.Media.Imaging;
17
using System.Windows.Navigation;
18
using System.Windows.Shapes;
19
using Telerik.Windows.Controls;
20 5ce56a3a KangIngu
using Telerik.Windows.Controls.DragDrop;
21 787a4489 KangIngu
22
namespace KCOM.Controls
23
{
24
    public class Symbol_Custom
25
    {
26 5ce56a3a KangIngu
        public string ID { get; set; }
27 787a4489 KangIngu
        public string Name { get; set; }
28
        public string ImageUri { get; set; }
29
    }
30
31
    /// <summary>
32
    /// Symbol.xaml에 대한 상호 작용 논리
33
    /// </summary>
34
    public partial class Symbol : UserControl
35
    {
36
        AdornerFinal finalItem;
37 5ce56a3a KangIngu
        bool IsMouseDown = false;
38
        string moveItem_id = "";
39 787a4489 KangIngu
        public string filename { get; set; }
40
        MarkupToPDF.Controls.Parsing.LayerControl layer = new MarkupToPDF.Controls.Parsing.LayerControl();
41 d4b0c723 KangIngu
        public MarkupToPDF.Common.Undo_data UndoData;
42 787a4489 KangIngu
43
        public Symbol()
44
        {
45
            InitializeComponent();
46
47
            DataBind();
48
        }
49
50 5ce56a3a KangIngu
        private void OnDragPrivateInfo(object sender, DragDropEventArgs e)
51
        {
52
        }
53
54
        private void OnDragPrivateQuery(object sender, DragDropQueryEventArgs e)
55
        {
56
            if (e.Options.Status == DragStatus.DragQuery)
57
            {
58
                //var draggedListBoxItem = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem;
59
                //BitmapImage im = new BitmapImage(new Uri((draggedListBoxItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate).ImageUri));
60
                //ImageSource _source = im;
61
                //Image img = new Image();
62
                //img.Source = _source;
63
64
                //e.Options.Payload = im;
65
                //var dragCue = new Image();
66
                //dragCue.Source = img.Source;
67
                //dragCue.Width = 0;
68
                //dragCue.Height = 0;
69
                //e.Options.DragCue = dragCue;
70
71
72
                //PayLoadAdorner = new AdornerFinal();
73
                //DeepView.ServiceDeepView_Symbol.SymbolPrivate tempDragableControl = (e.Options.Source as System.Windows.Controls.ListBox).SelectedItem as DeepView.ServiceDeepView_Symbol.SymbolPrivate;
74
                //var xamldata = tempDragableControl.Data;
75
                ////this.DeepLayer.markupParse(xamldata, this.DeepLayer._TempLayer, "복사된 데이터_이름으로 수정해야함");
76
                //PayLoadAdorner = this.DeepLayer.markupParseToAdorner(xamldata, this.DeepLayer._SelectLayer, "");
77
                //this.DeepLayer._SelectLayer.Children.Add(PayLoadAdorner);
78
            }
79
80
            e.QueryResult = true;
81
            e.Handled = true;
82
        }
83
84 787a4489 KangIngu
        private void DataBind()
85
        {
86 5ce56a3a KangIngu
            //lstSymbolPrivate.ItemsSource = null;
87
            //lstSymbolPublic.ItemsSource = null;
88 787a4489 KangIngu
89
            Symbol_Custom Custom = new Symbol_Custom();
90
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
91
92 5ce56a3a KangIngu
            using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
93
            {
94
                var symbol_Private = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == App.ViewInfo.UserID).ToList();
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 = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).ToList();
109
110
                var symbol_Public = Entity.SYMBOL_PUBLIC.ToList();
111
112
                if (deptlist.SelectedValue != null)
113
                {
114
                    symbol_Public = symbol_Public.Where(data => data.DEPARTMENT == deptlist.SelectedValue.ToString()).ToList();
115
                }
116
                //var symbol_Public = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == "PIPING").ToList();
117
118
                foreach (var item in symbol_Public)
119
                {
120
                    Custom.Name = item.NAME;
121
                    Custom.ImageUri = item.IMAGE_URL;
122
                    Custom.ID = item.ID;
123
                    Custom_List.Add(Custom);
124
                    Custom = new Symbol_Custom();
125
                }
126
                lstSymbolPublic.ItemsSource = Custom_List;
127
            }
128
        }
129
130
        public PngBitmapEncoder symImage(string data)
131
        {
132
133
            Canvas _canvas = new Canvas();
134
            _canvas.Background = Brushes.White;
135
            _canvas.Width = finalItem.BorderSize.Width;
136
            _canvas.Height = finalItem.BorderSize.Height;
137
            layer.markupParse(data, _canvas, "#FFFF0000", "");
138
139
            BitmapEncoder encoder = new PngBitmapEncoder();
140
141
142
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32);
143
144
            DrawingVisual dv = new DrawingVisual();
145
146
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
147
            //_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)));
148
            _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)));
149
150
            using (DrawingContext ctx = dv.RenderOpen())
151
            {
152
                VisualBrush vb = new VisualBrush(_canvas);
153
                //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)));
154
                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)));
155
            }
156
157
            try
158
            {
159
                renderBitmap.Render(dv);
160
161
                GC.Collect();
162
                GC.WaitForPendingFinalizers();
163
                GC.Collect();
164
                //bitmap.Render(controlToConvert);
165
                // encode png data
166
                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
167
                // puch rendered bitmap into it
168
                pngEncoder.Interlace = PngInterlaceOption.Off;
169
                pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
170
                return pngEncoder;
171
172
            }
173
            catch (Exception ex)
174
            {
175
                return null;
176
            }
177 787a4489 KangIngu
178
        }
179
180 5ce56a3a KangIngu
        public void DialogMessage_Alert(string content, string header)
181
        {
182
            var box = new TextBlock();
183
            box.MinWidth = 400;
184
            box.FontSize = 11;
185
            //box.FontSize = 12;
186
            box.Text = content;
187
            box.TextWrapping = System.Windows.TextWrapping.Wrap;
188
189
            DialogParameters parameters = new DialogParameters()
190
            {
191
                Content = box,
192
                Header = header,
193
                Theme = new VisualStudio2013Theme(),
194
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
195
            };
196
            RadWindow.Alert(parameters);
197
        }
198
199
        #region Event
200
201
        #region Symbol Add Event
202 787a4489 KangIngu
        private void Create_Symbol(object sender, RoutedEventArgs e)
203
        {
204
            MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn();
205
206
            if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면
207
            {
208
                DialogMessage_Alert("Please Select Controls", "Alert");
209
            }
210
            else //선택된 것이 있으면
211
            {
212
                string MarkupData = "";
213
                finalItem = new AdornerFinal();
214
215
                foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children)
216
                {
217
                    if (item.GetType().Name == "AdornerFinal")
218
                    {
219
                        finalItem = (item as Controls.AdornerFinal);
220
                        foreach (var InnerItem in (item as Controls.AdornerFinal).MemberSet.Cast<Controls.AdornerMember>())
221
                        {
222
                            if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData))
223
                            {
224
                                markupReturn = layer.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID);
225
                                MarkupData += markupReturn.ConvertData;
226
                            }
227
                        }
228
                    }
229
                }
230
                DialogParameters parameters = new DialogParameters()
231
                {
232
                    Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args),
233
                    DefaultPromptResultValue = "Custom State",
234
                    Content = "Name :",
235
                    Header = "Insert Custom Symbol Name",
236
                    Theme = new VisualStudio2013Theme(),
237
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
238
                };
239
                RadWindow.Prompt(parameters);
240
            }
241
242
        }
243 5ce56a3a KangIngu
        #endregion
244 787a4489 KangIngu
245 5ce56a3a KangIngu
        #region Symbol Add Close Event 
246 787a4489 KangIngu
        private void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
247
        {
248
            Save save = new Save();
249
250
            if (args.DialogResult.Value)
251
            {
252
                PngBitmapEncoder _Encoder = symImage(data);
253
254
                System.IO.MemoryStream fs = new System.IO.MemoryStream();
255
                _Encoder.Save(fs);
256
                System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
257
258
                byte[] Img_byte = fs.ToArray();
259
260
                kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
261
                filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Save.shortGuid() + ".png", Img_byte);
262
263
                save.SymbolSave(args.PromptResult, filename, data);
264 5ce56a3a KangIngu
265
                DataBind();
266 787a4489 KangIngu
            }
267
        }
268 5ce56a3a KangIngu
        #endregion
269 787a4489 KangIngu
270 5ce56a3a KangIngu
        #region Symbol Delete Event
271
        private void Remove_Symbol(object sender, RoutedEventArgs e)
272 787a4489 KangIngu
        {
273 5ce56a3a KangIngu
            if (lstSymbolPrivate.SelectedItem == null)
274
            {
275
                DialogMessage_Alert("Please Select Symbol", "Alert");
276
                return;
277
            }
278 787a4489 KangIngu
279 5ce56a3a KangIngu
            using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
280
            {
281
                string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
282
                var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
283
                Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
284
                Entity.SaveChanges();
285 787a4489 KangIngu
286 5ce56a3a KangIngu
                DataBind();
287
            }
288
        }
289
        #endregion
290 787a4489 KangIngu
291 5ce56a3a KangIngu
        #region Symbol DoubleClick Event
292
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
293
        {
294
            moveItem_id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
295 787a4489 KangIngu
296 5ce56a3a KangIngu
            IsMouseDown = true;
297 787a4489 KangIngu
298 d4b0c723 KangIngu
            //더블 클릭
299 5ce56a3a KangIngu
            if (e.ClickCount > 1)
300
            {
301
                //string moveItem_id = ((e.Source as ListBox).SelectedItem as Symbol_Custom).ID;
302
                string Data_ = "";
303 787a4489 KangIngu
304 5ce56a3a KangIngu
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
305
                {
306
                    if (RadTab.SelectedIndex == 0)
307
                        Data_ = Entity.SYMBOL_PRIVATE.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA;
308
                    else
309
                        Data_ = Entity.SYMBOL_PUBLIC.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA;
310
                }
311 787a4489 KangIngu
312 5ce56a3a KangIngu
                if (Data_.Contains("|DZ|"))
313
                {
314
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
315
316
                    string[] delimiterChars = { "|DZ|" };
317
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
318
319 d4b0c723 KangIngu
                    this.ParentOfType<MainWindow>().dzMainMenu.ReleaseAdorner();
320
321
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
322
323
                    //강인구 Undo/Redo 보류
324
                    UndoData = new Undo_data()
325
                    {
326
                        IsUndo = false,
327
                        Event = Event_Type.Create,
328
                        EventTime = DateTime.Now,
329
                        Markup_List = new List<Multi_Undo_data>()
330
                    };
331
332
                    ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
333
                    {
334
                        ViewerDataModel.Instance.UndoDataList.Remove(i);
335
                    });
336
337 5ce56a3a KangIngu
                    foreach (string parse in data)
338
                    {
339
                        if (parse != "")
340
                        {
341
                            System.Windows.Controls.Control item = layer.markupParse_Paste(parse, ViewerDataModel.Instance.MarkupControls_USER);
342
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Events.Save.shortGuid();
343
344
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
345
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
346
347
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
348 d4b0c723 KangIngu
349
                            multi_Undo_Data = this.ParentOfType<MainWindow>().dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
350
351
                            UndoData.Markup_List.Add(multi_Undo_Data);
352
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
353 5ce56a3a KangIngu
                        }
354
                    }
355
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
356
357
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
358
                }
359
            }
360
        }
361
        #endregion
362
363
        #region Symbol Rename Event
364
        private void Rename_Symbol(object sender, RoutedEventArgs e)
365
        {
366
            if (lstSymbolPrivate.SelectedItem == null)
367 787a4489 KangIngu
            {
368 5ce56a3a KangIngu
                DialogMessage_Alert("Please Select Symbol", "Alert");
369
                return;
370 787a4489 KangIngu
            }
371
372 5ce56a3a KangIngu
            DialogParameters parameters = new DialogParameters()
373 787a4489 KangIngu
            {
374 5ce56a3a KangIngu
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
375
                //DefaultPromptResultValue = "Custom State",
376
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
377
                Content = "Name :",
378
                Header = "Update Custom Symbol Name",
379
                Theme = new VisualStudio2013Theme(),
380
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
381
            };
382
            RadWindow.Prompt(parameters);
383 787a4489 KangIngu
384 5ce56a3a KangIngu
        }
385
        #endregion
386 787a4489 KangIngu
387 5ce56a3a KangIngu
        #region Symbol Rename Close Event
388
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
389
        {
390
            if (args.DialogResult != null && args.DialogResult.Value)
391
            {
392
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
393
                {
394
                    string ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
395
                    var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == ID).FirstOrDefault();
396
397
                    UpdateItem.NAME = args.PromptResult;
398
                    Entity.SaveChanges();
399
                    DataBind();
400
                    //args.PromptResult
401
                }
402 787a4489 KangIngu
            }
403 5ce56a3a KangIngu
        }
404
        #endregion
405
406
        #region Wheel Event
407
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
408
        {
409
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
410
        }
411
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
412
        {
413
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
414
        }
415
        #endregion
416
417
        #region Tab Selection Event
418
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
419
        {
420
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
421 787a4489 KangIngu
            {
422 5ce56a3a KangIngu
                (item as RadTabItem).FontWeight = FontWeights.Normal;
423 787a4489 KangIngu
            }
424 5ce56a3a KangIngu
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
425
        }
426
        #endregion
427 787a4489 KangIngu
428 5ce56a3a KangIngu
        #region Department Selection Event
429
        private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
430
        {
431
            DataBind();
432 787a4489 KangIngu
        }
433 5ce56a3a KangIngu
        #endregion
434 787a4489 KangIngu
435 5ce56a3a KangIngu
        #endregion
436 787a4489 KangIngu
437 5ce56a3a KangIngu
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
438
        {
439
440
        }
441
442
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
443
        {
444
445
        }
446
447
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
448 787a4489 KangIngu
        {
449
450
        }
451
452 5ce56a3a KangIngu
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
453 787a4489 KangIngu
        {
454 5ce56a3a KangIngu
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
455
            {
456
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
457
            }
458
            else
459
            {
460
                IsMouseDown = false;
461
            }
462
        }
463 787a4489 KangIngu
464 5ce56a3a KangIngu
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
465
        {
466
            IsMouseDown = false;
467 787a4489 KangIngu
        }
468
    }
469
}
클립보드 이미지 추가 (최대 크기: 500 MB)