프로젝트

일반

사용자정보

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

markus / KCOM / Controls / Symbol.xaml.cs @ 5ce56a3a

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

1 787a4489 KangIngu
using KCOM.Common;
2
using KCOM.Events;
3 5ce56a3a KangIngu
using KCOMDataModel.Common;
4
using KCOMDataModel.DataModel;
5 787a4489 KangIngu
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 5ce56a3a KangIngu
using Telerik.Windows.Controls.DragDrop;
20 787a4489 KangIngu
21
namespace KCOM.Controls
22
{
23
    public class Symbol_Custom
24
    {
25 5ce56a3a KangIngu
        public string ID { get; set; }
26 787a4489 KangIngu
        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 5ce56a3a KangIngu
        bool IsMouseDown = false;
37
        string moveItem_id = "";
38 787a4489 KangIngu
        public string filename { get; set; }
39
        MarkupToPDF.Controls.Parsing.LayerControl layer = new MarkupToPDF.Controls.Parsing.LayerControl();
40
41
        public Symbol()
42
        {
43
            InitializeComponent();
44 5ce56a3a KangIngu
            
45
            RadDragAndDropManager.AddDragInfoHandler(lstSymbolPrivate, OnDragPrivateInfo);
46
            RadDragAndDropManager.AddDragQueryHandler(lstSymbolPrivate, OnDragPrivateQuery);
47
            RadDragAndDropManager.SetAllowDrag(lstSymbolPrivate, true);
48 787a4489 KangIngu
49
            DataBind();
50
        }
51
52 5ce56a3a KangIngu
        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 787a4489 KangIngu
        private void DataBind()
87
        {
88 5ce56a3a KangIngu
            //lstSymbolPrivate.ItemsSource = null;
89
            //lstSymbolPublic.ItemsSource = null;
90 787a4489 KangIngu
91
            Symbol_Custom Custom = new Symbol_Custom();
92
            List<Symbol_Custom> Custom_List = new List<Symbol_Custom>();
93
94 5ce56a3a KangIngu
            using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
95
            {
96
                var symbol_Private = Entity.SYMBOL_PRIVATE.Where(data => data.MEMBER_USER_ID == App.ViewInfo.UserID).ToList();
97
                foreach(var item in symbol_Private)
98
                {
99
                    Custom.Name = item.NAME;
100
                    Custom.ImageUri = item.IMAGE_URL;
101
                    Custom.ID = item.ID;
102
                    Custom_List.Add(Custom);
103
                    Custom = new Symbol_Custom();
104
                }
105
                lstSymbolPrivate.ItemsSource = Custom_List;
106
107
                Custom = new Symbol_Custom();
108
                Custom_List = new List<Symbol_Custom>();
109
110
                deptlist.ItemsSource = Entity.SYMBOL_PUBLIC.Select(data => data.DEPARTMENT).ToList();
111
112
                var symbol_Public = Entity.SYMBOL_PUBLIC.ToList();
113
114
                if (deptlist.SelectedValue != null)
115
                {
116
                    symbol_Public = symbol_Public.Where(data => data.DEPARTMENT == deptlist.SelectedValue.ToString()).ToList();
117
                }
118
                //var symbol_Public = Entity.SYMBOL_PUBLIC.Where(data => data.DEPARTMENT == "PIPING").ToList();
119
120
                foreach (var item in symbol_Public)
121
                {
122
                    Custom.Name = item.NAME;
123
                    Custom.ImageUri = item.IMAGE_URL;
124
                    Custom.ID = item.ID;
125
                    Custom_List.Add(Custom);
126
                    Custom = new Symbol_Custom();
127
                }
128
                lstSymbolPublic.ItemsSource = Custom_List;
129
            }
130
        }
131
132
        public PngBitmapEncoder symImage(string data)
133
        {
134
135
            Canvas _canvas = new Canvas();
136
            _canvas.Background = Brushes.White;
137
            _canvas.Width = finalItem.BorderSize.Width;
138
            _canvas.Height = finalItem.BorderSize.Height;
139
            layer.markupParse(data, _canvas, "#FFFF0000", "");
140
141
            BitmapEncoder encoder = new PngBitmapEncoder();
142
143
144
            RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_canvas.Width + 50, (int)_canvas.Height + 50, 96d, 96d, PixelFormats.Pbgra32);
145
146
            DrawingVisual dv = new DrawingVisual();
147
148
            _canvas.Measure(new System.Windows.Size(finalItem.BorderSize.Width + 50, finalItem.BorderSize.Height + 50));
149
            //_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)));
150
            _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)));
151
152
            using (DrawingContext ctx = dv.RenderOpen())
153
            {
154
                VisualBrush vb = new VisualBrush(_canvas);
155
                //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)));
156
                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)));
157
            }
158
159
            try
160
            {
161
                renderBitmap.Render(dv);
162
163
                GC.Collect();
164
                GC.WaitForPendingFinalizers();
165
                GC.Collect();
166
                //bitmap.Render(controlToConvert);
167
                // encode png data
168
                PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
169
                // puch rendered bitmap into it
170
                pngEncoder.Interlace = PngInterlaceOption.Off;
171
                pngEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
172
                return pngEncoder;
173
174
            }
175
            catch (Exception ex)
176
            {
177
                return null;
178
            }
179 787a4489 KangIngu
180
        }
181
182 5ce56a3a KangIngu
        public void DialogMessage_Alert(string content, string header)
183
        {
184
            var box = new TextBlock();
185
            box.MinWidth = 400;
186
            box.FontSize = 11;
187
            //box.FontSize = 12;
188
            box.Text = content;
189
            box.TextWrapping = System.Windows.TextWrapping.Wrap;
190
191
            DialogParameters parameters = new DialogParameters()
192
            {
193
                Content = box,
194
                Header = header,
195
                Theme = new VisualStudio2013Theme(),
196
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
197
            };
198
            RadWindow.Alert(parameters);
199
        }
200
201
        #region Event
202
203
        #region Symbol Add Event
204 787a4489 KangIngu
        private void Create_Symbol(object sender, RoutedEventArgs e)
205
        {
206
            MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn markupReturn = new MarkupToPDF.Controls.Parsing.LayerControl.MarkupReturn();
207
208
            if (Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Count < 1) //선택된 것이 없으면
209
            {
210
                DialogMessage_Alert("Please Select Controls", "Alert");
211
            }
212
            else //선택된 것이 있으면
213
            {
214
                string MarkupData = "";
215
                finalItem = new AdornerFinal();
216
217
                foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children)
218
                {
219
                    if (item.GetType().Name == "AdornerFinal")
220
                    {
221
                        finalItem = (item as Controls.AdornerFinal);
222
                        foreach (var InnerItem in (item as Controls.AdornerFinal).MemberSet.Cast<Controls.AdornerMember>())
223
                        {
224
                            if (!ViewerDataModel.Instance.MarkupControls.Contains(InnerItem.DrawingData))
225
                            {
226
                                markupReturn = layer.MarkupToString(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo, App.ViewInfo.UserID);
227
                                MarkupData += markupReturn.ConvertData;
228
                            }
229
                        }
230
                    }
231
                }
232
                DialogParameters parameters = new DialogParameters()
233
                {
234
                    Closed = (obj, args) => this.MarkupNamePromptClose(MarkupData, args),
235
                    DefaultPromptResultValue = "Custom State",
236
                    Content = "Name :",
237
                    Header = "Insert Custom Symbol Name",
238
                    Theme = new VisualStudio2013Theme(),
239
                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
240
                };
241
                RadWindow.Prompt(parameters);
242
            }
243
244
        }
245 5ce56a3a KangIngu
        #endregion
246 787a4489 KangIngu
247 5ce56a3a KangIngu
        #region Symbol Add Close Event 
248 787a4489 KangIngu
        private void MarkupNamePromptClose(string data, WindowClosedEventArgs args)
249
        {
250
            Save save = new Save();
251
252
            if (args.DialogResult.Value)
253
            {
254
                PngBitmapEncoder _Encoder = symImage(data);
255
256
                System.IO.MemoryStream fs = new System.IO.MemoryStream();
257
                _Encoder.Save(fs);
258
                System.Drawing.Image ImgOut = System.Drawing.Image.FromStream(fs);
259
260
                byte[] Img_byte = fs.ToArray();
261
262
                kr.co.devdoftech.cloud.FileUpload fileUploader = new kr.co.devdoftech.cloud.FileUpload();
263
                filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, Save.shortGuid() + ".png", Img_byte);
264
265
                save.SymbolSave(args.PromptResult, filename, data);
266 5ce56a3a KangIngu
267
                DataBind();
268 787a4489 KangIngu
            }
269
        }
270 5ce56a3a KangIngu
        #endregion
271 787a4489 KangIngu
272 5ce56a3a KangIngu
        #region Symbol Delete Event
273
        private void Remove_Symbol(object sender, RoutedEventArgs e)
274 787a4489 KangIngu
        {
275 5ce56a3a KangIngu
            if (lstSymbolPrivate.SelectedItem == null)
276
            {
277
                DialogMessage_Alert("Please Select Symbol", "Alert");
278
                return;
279
            }
280 787a4489 KangIngu
281 5ce56a3a KangIngu
            using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
282
            {
283
                string delItem_ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
284
                var delitem = Entity.SYMBOL_PRIVATE.Where(data => data.ID == delItem_ID).FirstOrDefault();
285
                Entity.SYMBOL_PRIVATE.DeleteObject(delitem);
286
                Entity.SaveChanges();
287 787a4489 KangIngu
288 5ce56a3a KangIngu
                DataBind();
289
            }
290
        }
291
        #endregion
292 787a4489 KangIngu
293 5ce56a3a KangIngu
        #region Symbol DoubleClick Event
294
        private void Move_Symbol(object sender, MouseButtonEventArgs e)
295
        {
296
            moveItem_id = ((e.OriginalSource as Image).DataContext as Symbol_Custom).ID;
297 787a4489 KangIngu
298 5ce56a3a KangIngu
            IsMouseDown = true;
299 787a4489 KangIngu
300 5ce56a3a KangIngu
            if (e.ClickCount > 1)
301
            {
302
                //string moveItem_id = ((e.Source as ListBox).SelectedItem as Symbol_Custom).ID;
303
                string Data_ = "";
304 787a4489 KangIngu
305 5ce56a3a KangIngu
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
306
                {
307
                    if (RadTab.SelectedIndex == 0)
308
                        Data_ = Entity.SYMBOL_PRIVATE.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA;
309
                    else
310
                        Data_ = Entity.SYMBOL_PUBLIC.Where(data => data.ID == moveItem_id).FirstOrDefault().DATA;
311
                }
312 787a4489 KangIngu
313 5ce56a3a KangIngu
                if (Data_.Contains("|DZ|"))
314
                {
315
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
316
317
                    string[] delimiterChars = { "|DZ|" };
318
                    string[] data = Data_.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
319
320
                    foreach (string parse in data)
321
                    {
322
                        if (parse != "")
323
                        {
324
                            System.Windows.Controls.Control item = layer.markupParse_Paste(parse, ViewerDataModel.Instance.MarkupControls_USER);
325
                            (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Events.Save.shortGuid();
326
327
                            ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
328
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
329
330
                            adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
331
                        }
332
                    }
333
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
334
335
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
336
                }
337
            }
338
        }
339
        #endregion
340
341
        #region Symbol Rename Event
342
        private void Rename_Symbol(object sender, RoutedEventArgs e)
343
        {
344
            if (lstSymbolPrivate.SelectedItem == null)
345 787a4489 KangIngu
            {
346 5ce56a3a KangIngu
                DialogMessage_Alert("Please Select Symbol", "Alert");
347
                return;
348 787a4489 KangIngu
            }
349
350 5ce56a3a KangIngu
            DialogParameters parameters = new DialogParameters()
351 787a4489 KangIngu
            {
352 5ce56a3a KangIngu
                Closed = (obj, args) => this.MarkupReNamePromptClose("", args),
353
                //DefaultPromptResultValue = "Custom State",
354
                DefaultPromptResultValue = (lstSymbolPrivate.SelectedItem as Symbol_Custom).Name,
355
                Content = "Name :",
356
                Header = "Update Custom Symbol Name",
357
                Theme = new VisualStudio2013Theme(),
358
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
359
            };
360
            RadWindow.Prompt(parameters);
361 787a4489 KangIngu
362 5ce56a3a KangIngu
        }
363
        #endregion
364 787a4489 KangIngu
365 5ce56a3a KangIngu
        #region Symbol Rename Close Event
366
        private void MarkupReNamePromptClose(string data, WindowClosedEventArgs args)
367
        {
368
            if (args.DialogResult != null && args.DialogResult.Value)
369
            {
370
                using (KCOMEntities Entity = new KCOMEntities(ConnectStringBuilder.KCOMConnectionString().ToString()))
371
                {
372
                    string ID = (lstSymbolPrivate.SelectedItem as Symbol_Custom).ID;
373
                    var UpdateItem = Entity.SYMBOL_PRIVATE.Where(info => info.ID == ID).FirstOrDefault();
374
375
                    UpdateItem.NAME = args.PromptResult;
376
                    Entity.SaveChanges();
377
                    DataBind();
378
                    //args.PromptResult
379
                }
380 787a4489 KangIngu
            }
381 5ce56a3a KangIngu
        }
382
        #endregion
383
384
        #region Wheel Event
385
        private void lstSymbolPrivate_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
386
        {
387
            ScView.ScrollToVerticalOffset(ScView.ContentVerticalOffset - (e.Delta / 2));
388
        }
389
        private void lstSymbolPublic_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
390
        {
391
            ScView_Public.ScrollToVerticalOffset(ScView_Public.ContentVerticalOffset - (e.Delta / 2));
392
        }
393
        #endregion
394
395
        #region Tab Selection Event
396
        private void RadTabControl_PreviewSelectionChanged(object sender, RadSelectionChangedEventArgs e)
397
        {
398
            foreach (var item in (e.OriginalSource as RadTabControl).Items)
399 787a4489 KangIngu
            {
400 5ce56a3a KangIngu
                (item as RadTabItem).FontWeight = FontWeights.Normal;
401 787a4489 KangIngu
            }
402 5ce56a3a KangIngu
            ((e.OriginalSource as RadTabControl).SelectedItem as RadTabItem).FontWeight = FontWeights.Bold;
403
        }
404
        #endregion
405 787a4489 KangIngu
406 5ce56a3a KangIngu
        #region Department Selection Event
407
        private void deptlist_SelectionChanged(object sender, SelectionChangedEventArgs e)
408
        {
409
            DataBind();
410 787a4489 KangIngu
        }
411 5ce56a3a KangIngu
        #endregion
412 787a4489 KangIngu
413 5ce56a3a KangIngu
        #endregion
414 787a4489 KangIngu
415 5ce56a3a KangIngu
        private void lstSymbolPrivate_PreviewMouseUp(object sender, MouseButtonEventArgs e)
416
        {
417
418
        }
419
420
        private void lstSymbolPrivate_MouseLeave(object sender, MouseEventArgs e)
421
        {
422
423
        }
424
425
        private void lstSymbolPrivate_MouseDown(object sender, MouseButtonEventArgs e)
426 787a4489 KangIngu
        {
427
428
        }
429
430 5ce56a3a KangIngu
        private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
431 787a4489 KangIngu
        {
432 5ce56a3a KangIngu
            if(IsMouseDown && e.LeftButton == MouseButtonState.Pressed)
433
            {
434
                ViewerDataModel.Instance.SystemMain.dzMainMenu.Symbol_ID = moveItem_id;
435
            }
436
            else
437
            {
438
                IsMouseDown = false;
439
            }
440
        }
441 787a4489 KangIngu
442 5ce56a3a KangIngu
        private void StackPanel_MouseUp(object sender, MouseButtonEventArgs e)
443
        {
444
            IsMouseDown = false;
445 787a4489 KangIngu
        }
446
    }
447
}
클립보드 이미지 추가 (최대 크기: 500 MB)