프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 264c9309

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

1
using KCOM.Common;
2
using KCOM.Views;
3
using KCOMDataModel;
4
using KCOMDataModel.DataModel;
5
using MarkupToPDF.Common;
6
using MarkupToPDF.Controls.Parsing;
7
using MarkupToPDF.Serialize.Core;
8
using MarkupToPDF.Serialize.S_Control;
9
using System;
10
using System.Collections.Generic;
11
using System.ComponentModel;
12
using System.Diagnostics;
13
using System.IO;
14
using System.Linq;
15
using System.Net;
16
using System.Reflection;
17
using System.Runtime.InteropServices;
18
using System.Text;
19
using System.Threading;
20
using System.Threading.Tasks;
21
using System.Windows;
22
using System.Windows.Controls;
23
using System.Windows.Data;
24
using System.Windows.Documents;
25
using System.Windows.Input;
26
using System.Windows.Media;
27
using System.Windows.Media.Imaging;
28
using System.Windows.Navigation;
29
using System.Windows.Shapes;
30
using System.Xml;
31
using Telerik.Windows.Controls;
32
using WinInterop = System.Windows.Interop;
33

    
34
namespace KCOM
35
{
36
    /// <summary>
37
    /// MainWindow.xaml에 대한 상호 작용 논리
38
    /// </summary>
39
    public partial class MainWindow : Window
40
    {
41
        public MainWindow()
42
        {
43
            App.splashString(ISplashMessage.MAINWINDOW);
44
            this.Loaded += MainWindow_Loaded;
45
            this.KeyDown += new KeyEventHandler(KeyEventDownAction);
46
            this.KeyUp += new KeyEventHandler(KeyEventUpAction);
47
            this.SourceInitialized += new EventHandler(win_SourceInitialized);
48
            this.Closed += MainWindow_Closed;
49
            
50
        }
51

    
52
        public static BitmapImage CursorChange()
53
        {
54
            BitmapImage bmp = new BitmapImage();
55
            bmp.BeginInit();
56
            bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream;
57
            return bmp;
58
        }
59

    
60
        public void DialogMessage_Alert(string content, string header)
61
        {
62
            var box = new TextBlock();
63
            box.MinWidth = 400;
64
            box.FontSize = 12;
65
            box.Text = content;
66
            box.TextWrapping = System.Windows.TextWrapping.Wrap;
67

    
68
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
69
            {
70
                Owner = Application.Current.MainWindow,
71
                Content = box,
72
                Header = header,
73
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
74
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
75
            };
76
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
77
        }
78

    
79
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
80
        {
81
            InitializeComponent();
82

    
83
            //cursor change  
84
            this.Cursor = new Cursor(CursorChange().StreamSource);
85

    
86
            double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
87
            double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
88
            //this.Width += 40;
89
            double windowWidth = this.Width;
90
            double windowHeight = this.Height;
91
            this.Left = (screenWidth / 2) - (windowWidth / 2);
92
            this.Top = (screenHeight / 2) - (windowHeight / 2);
93

    
94
            ViewerDataModel.Instance.SystemMain = this;
95

    
96
            if (!App.ParameterMode)
97
            {
98
                //App.ViewInfo = new IKCOM.ViewInfo
99
                //{
100
                //    DocumentItemID = "11111112",
101
                //    //DocumentItemID = "10001",
102
                //    bPartner = false,
103
                //    CreateFinalPDFPermission = true,
104
                //    NewCommentPermission = true,
105
                //    ProjectNO = "000000",
106
                //    UserID = "H2011357",
107
                //    //UserID = "H2009115",
108
                //    //Mode = 0 , 1 , 2
109
                //};
110
                //DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
111

    
112
                //#if DEBUG
113
                //                App.ViewInfo = new IKCOM.ViewInfo
114
                //                {
115
                //                    DocumentItemID = "11111112",
116
                //                    //DocumentItemID = "10001",
117
                //                    bPartner = false,
118
                //                    CreateFinalPDFPermission = true,
119
                //                    NewCommentPermission = true,
120
                //                    ProjectNO = "000000",
121
                //                    UserID = "H2011357",
122
                //                    //UserID = "H2009115",
123
                //                    //Mode = 0 , 1 , 2
124
                //                };
125
                //                App.ParameterMode = true;
126
                //                this.dzMainMenu.ServiceOn();
127
                //                this.dzMainMenu.SetView(App.ViewInfo);
128
                //#else
129

    
130
                DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
131
                this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed;
132
                this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed;
133
                this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed;
134
                this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed;
135
                this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
136
                //#endif
137
            }
138
            else
139
            {
140
                this.dzMainMenu.ServiceOn();
141

    
142
                if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
143
                {
144
                    this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
145
                    var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
146
                    list.ForEach(item => item.Visibility = Visibility.Collapsed);
147
                    this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
148
                    this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
149
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
150
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
151
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
152
                }
153
                this.dzMainMenu.SetView(App.ViewInfo);
154
                this.dzMainMenu.HubSet();
155
            }
156

    
157
            //App.ViewInfo = new IKCOM.ViewInfo
158
            //{
159
            //    DocumentItemID = "11111112",
160
            //    //DocumentItemID = "10001",
161
            //    bPartner = false,
162
            //    CreateFinalPDFPermission = true,
163
            //    NewCommentPermission = true,
164
            //    ProjectNO = "000000",
165
            //    UserID = "H2011357",
166
            //    //UserID = "H2009115",
167
            //    //Mode = 0 , 1 , 2
168
            //};
169

    
170
            //this.dzMainMenu.ServiceOn();
171
            //this.dzMainMenu.SetView(App.ViewInfo);
172
        }
173

    
174

    
175
        bool restoreIfMove = false;
176

    
177
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
178
        {
179
            if(filename == null)
180
            {
181
                if (e.ClickCount == 2)
182
                {
183
                    if ((ResizeMode == ResizeMode.CanResize) ||
184
                        (ResizeMode == ResizeMode.CanResizeWithGrip))
185
                    {
186
                        SwitchState();
187
                    }
188
                }
189
                else
190
                {
191
                    if (WindowState == WindowState.Maximized)
192
                    {
193
                        restoreIfMove = true;
194
                    }
195

    
196
                    this.DragMove();
197
                }
198
            }            
199
        }
200

    
201
        private void WindowDragEventUp(object sender, MouseButtonEventArgs e)
202
        {
203
            restoreIfMove = false;
204
        }
205

    
206
        private void WindowDragEventMove(object sender, MouseEventArgs e)
207
        {
208
            if (restoreIfMove)
209
            {
210
                if (Mouse.LeftButton == MouseButtonState.Pressed)
211
                {
212
                    //this.WindowState = WindowState.Normal;
213

    
214
                    restoreIfMove = false;
215

    
216
                    double percentHorizontal = e.GetPosition(this).X / ActualWidth;
217
                    double targetHorizontal = RestoreBounds.Width * percentHorizontal;
218

    
219
                    double percentVertical = e.GetPosition(this).Y / ActualHeight;
220
                    double targetVertical = RestoreBounds.Height * percentVertical;
221

    
222
                    POINT lMousePosition;
223
                    GetCursorPos(out lMousePosition);
224

    
225
                    Left = lMousePosition.X - targetHorizontal;
226
                    double top = lMousePosition.Y - targetVertical;
227
                    if(top < 10)
228
                    {
229
                        top = 10;
230
                    }
231
                    Top = lMousePosition.Y;
232

    
233

    
234
                    WindowState = WindowState.Normal;
235

    
236
                    this.DragMove();
237
                }
238
            }
239
        }
240

    
241
        [DllImport("user32.dll")]
242
        [return: MarshalAs(UnmanagedType.Bool)]
243
        static extern bool GetCursorPos(out POINT lpPoint);
244

    
245
        [StructLayout(LayoutKind.Sequential)]
246
        public struct POINT
247
        {
248
            public int X;
249
            public int Y;
250

    
251
            public POINT(int x, int y)
252
            {
253
                this.X = x;
254
                this.Y = y;
255
            }
256
        }
257

    
258
        private void SwitchState()
259
        {
260
            switch (WindowState)
261
            {
262
                case WindowState.Normal:
263
                    {
264
                        WindowState = WindowState.Maximized;
265
                        break;
266
                    }
267
                case WindowState.Maximized:
268
                    {
269
                        WindowState = WindowState.Normal;
270
                        break;
271
                    }
272
            }
273
        }
274

    
275
        private void RadButton_Click(object sender, RoutedEventArgs e)
276
        {
277
            Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton;
278

    
279
            switch (button.CommandParameter.ToString())
280
            {
281
                case ("Min"):
282
                    {
283
                        WindowState = WindowState.Minimized;
284
                    }
285
                    break;
286
                case ("Max"):
287
                    {
288
                        WindowState = WindowState.Maximized;
289
                    }
290
                    break;
291
                case ("Exit"):
292
                    {
293

    
294
                    }
295
                    break;
296
            }
297
        }
298

    
299
        private void WinState(object sender, MouseButtonEventArgs e)
300
        {
301
            switch ((e.Source as Image).Name)
302
            {
303
                case ("Win_min"):
304
                    {
305
                        WindowState = WindowState.Minimized;
306
                    }
307
                    break;
308
                case ("Win_max"):
309
                    {
310
                        if (WindowState == WindowState.Maximized)
311
                        {
312
                            WindowState = WindowState.Normal;
313
                        }
314
                        else
315
                        {
316
                            WindowState = WindowState.Maximized;
317
                        }
318
                    }
319
                    break;
320
                case ("Win_Close"):
321
                    {
322
                        if (ViewerDataModel.Instance.UndoDataList.Count > 0)
323
                        {
324
                            DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
325
                            DateTime updatetime = DateTime.Now.AddDays(-1);
326
                            if (ViewerDataModel.Instance._markupInfoList.Count > 0)
327
                            {
328
                                updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
329
                            }
330

    
331
                            if (undoTime > updatetime)
332
                            {
333
                                var box = new TextBlock();
334
                                box.MinWidth = 400;
335
                                box.FontSize = 11;
336
                                box.Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?";
337
                                box.TextWrapping = System.Windows.TextWrapping.Wrap;
338

    
339
                                DialogParameters parameters = new DialogParameters()
340
                                {
341
                                    Owner = Application.Current.MainWindow,
342
                                    Content = box,
343
                                    Header = "Confirm",
344
                                    Theme = new VisualStudio2013Theme(),
345
                                    ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
346
                                    Closed = Onclose,
347
                                };
348
                                RadWindow.Confirm(parameters);
349
                            }
350
                        }
351
                        
352
                        MainWindow_Close();
353
                    }
354
                    break;
355
            }
356
        }
357

    
358
        private void MainWindow_Closed(object sender, EventArgs e)
359
        {
360
            splashScreen.Close();
361
            ProcessStartInfo proInfo = new ProcessStartInfo();
362
            proInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + filename;
363
            Process.Start(proInfo);
364
        }
365

    
366
        //파일 다운로드 상황을 반영(수정 필요)
367
        private void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
368
        {
369

    
370
            if (i <= 100)
371
            {
372
                i++;
373
            }
374
            Thread.Sleep(3);
375
            splashScreen.Progress = i;
376
            splashScreen.Close();
377

    
378
            //splashScreen.Close();
379
        }
380
        private Thread theProgBarThread;
381
        string filename = null;
382
        int i = 1;
383

    
384

    
385
        public static SplashScreenWindow splashScreen = new SplashScreenWindow();
386
        private void MainWindow_Close()
387
        {
388
            try
389
            {
390
                string url = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(Environment.Is64BitProcess, Assembly.GetExecutingAssembly().GetName().Version.ToString());
391
                if (!string.IsNullOrEmpty(url))
392
                {
393
                    if (MessageBox.Show("새로운 버전이 있습니다. \n업데이트 하시겠습니까?", "MARKUS", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
394
                    {
395
                        //splashScreen.splashText.Text = "  DownLoad...";                        
396

    
397
                        splashScreen.Show();
398
                        WebClient theDownloadThread = new WebClient();
399
                        //Uri url = new Uri(itemInfoList[i].FileName);
400
                        theDownloadThread.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
401
                        theDownloadThread.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
402
                        filename = System.IO.Path.GetFileName(url);
403

    
404
                        if (!File.Exists(TempFile.TempFolder))
405
                        {
406
                            Directory.CreateDirectory(TempFile.TempFolder);
407
                        }
408

    
409
                        theDownloadThread.DownloadFileAsync(new Uri(url), System.IO.Path.Combine(TempFile.TempFolder, filename));
410
                       
411
                    }
412
                    else
413
                    {
414
                        this.Close();
415
                    }
416
                }
417
                else
418
                {
419
                    this.Close();
420
                }
421

    
422
            }
423
            catch (Exception)
424
            {
425
                this.Close();
426
            }            
427
        }
428

    
429
        private void Completed(object sender, AsyncCompletedEventArgs e)
430
        {            
431
            try
432
            {
433
                this.Close();                
434
            }
435
            catch (Exception ee)
436
            {
437
            }       
438

    
439
        }
440

    
441
        private void Onclose(object sender, WindowClosedEventArgs e)
442
        {
443
            if (e.DialogResult == true)
444
            {
445
                dzTopMenu.SaveEventCallback(null, null);
446
            }
447
        }
448

    
449
        void win_SourceInitialized(object sender, EventArgs e)
450
        {
451
            System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
452
            WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
453
        }
454

    
455
        private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
456
        {
457
            switch (msg)
458
            {
459
                case 0x0024:
460
                    WmGetMinMaxInfo(hwnd, lParam);
461
                    handled = true;
462
                    break;
463
            }
464
            return (System.IntPtr)0;
465
        }
466

    
467
        private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
468
        {
469
            MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
470
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
471
            System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
472

    
473
            if (monitor != System.IntPtr.Zero)
474
            {
475
                MONITORINFO monitorInfo = new MONITORINFO();
476
                GetMonitorInfo(monitor, monitorInfo);
477
                RECT rcWorkArea = monitorInfo.rcWork;
478
                RECT rcMonitorArea = monitorInfo.rcMonitor;
479
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
480
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
481
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
482
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
483
            }
484
            Marshal.StructureToPtr(mmi, lParam, true);
485
        }
486

    
487
        [StructLayout(LayoutKind.Sequential)]
488
        public struct POINT2
489
        {
490
            public int x;
491
            public int y;
492
            public POINT2(int x, int y)
493
            {
494
                this.x = x;
495
                this.y = y;
496
            }
497
        }
498

    
499
        [StructLayout(LayoutKind.Sequential)]
500
        public struct MINMAXINFO
501
        {
502
            public POINT2 ptReserved;
503
            public POINT2 ptMaxSize;
504
            public POINT2 ptMaxPosition;
505
            public POINT2 ptMinTrackSize;
506
            public POINT2 ptMaxTrackSize;
507
        };
508

    
509
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
510
        public class MONITORINFO
511
        {
512
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
513
            public RECT rcMonitor = new RECT();
514
            public RECT rcWork = new RECT();
515
            public int dwFlags = 0;
516
        }
517

    
518
        [StructLayout(LayoutKind.Sequential, Pack = 0)]
519
        public struct RECT
520
        {
521
            public int left;
522
            public int top;
523
            public int right;
524
            public int bottom;
525

    
526
            public static readonly RECT Empty = new RECT();
527

    
528
            public int Width
529
            {
530
                get { return Math.Abs(right - left); }  // Abs needed for BIDI OS
531
            }
532

    
533
            public int Height
534
            {
535
                get { return bottom - top; }
536
            }
537

    
538
            public RECT(int left, int top, int right, int bottom)
539
            {
540
                this.left = left;
541
                this.top = top;
542
                this.right = right;
543
                this.bottom = bottom;
544
            }
545

    
546
            public RECT(RECT rcSrc)
547
            {
548
                this.left = rcSrc.left;
549
                this.top = rcSrc.top;
550
                this.right = rcSrc.right;
551
                this.bottom = rcSrc.bottom;
552
            }
553

    
554
            public bool IsEmpty
555
            {
556
                get
557
                {
558
                    // BUGBUG : On Bidi OS (hebrew arabic) left > right
559
                    return left >= right || top >= bottom;
560
                }
561
            }
562

    
563
            public override bool Equals(object obj)
564
            {
565
                if (!(obj is Rect)) { return false; }
566
                return (this == (RECT)obj);
567
            }
568

    
569
            public override int GetHashCode()
570
            {
571
                return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
572
            }
573

    
574
            public static bool operator ==(RECT rect1, RECT rect2)
575
            {
576
                return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
577
            }
578

    
579
            public static bool operator !=(RECT rect1, RECT rect2)
580
            {
581
                return !(rect1 == rect2);
582
            }
583
        }
584

    
585
        [DllImport("user32")]
586
        internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
587
        [DllImport("User32")]
588
        internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
589
    }
590
}
클립보드 이미지 추가 (최대 크기: 500 MB)