프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 1c7f408a

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

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

    
35
namespace KCOM
36
{
37
    /// <summary>
38
    /// MainWindow.xaml에 대한 상호 작용 논리
39
    /// </summary>
40
    public partial class MainWindow : RadWindow, System.Windows.Markup.IComponentConnector
41
    {
42
        bool isSaveCheck = false;
43
        
44
        ProgressControl progressControl = null;
45
        string destfilepath = string.Empty;
46
        static MainWindow()
47
        {
48
            StyleManager.ApplicationTheme = new VisualStudio2013Theme();
49
            RadRibbonWindow.IsWindowsThemeEnabled = false;
50
        }
51

    
52
        public MainWindow()
53
        {
54
            App.splashString(ISplashMessage.MAINWINDOW);
55
            this.Loaded += MainWindow_Loaded;
56
            this.KeyDown += new KeyEventHandler(KeyEventDownAction);
57
            //this.SourceInitialized += new EventHandler(win_SourceInitialized);
58
        }
59

    
60
        public static BitmapImage CursorChange()
61
        {
62
            BitmapImage bmp = new BitmapImage();
63
            bmp.BeginInit();
64
            bmp.StreamSource = System.Windows.Application.GetResourceStream(new Uri("/KCOM;Component/Resources/Cursor/customCursor2.cur", UriKind.Relative)).Stream;
65
            return bmp;
66
        }
67

    
68
        public void DialogMessage_Alert(string content, string header)
69
        {
70
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
71
            {
72
                Owner = Application.Current.MainWindow,
73
                Content = new TextBlock()
74
                { 
75
                    MinWidth = 400,
76
                    FontSize = 12,
77
                    Text = content,
78
                    TextWrapping = System.Windows.TextWrapping.Wrap
79
                },
80
                Header = header,
81
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
82
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
83
            };
84
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
85
        }
86

    
87
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
88
        {
89
            InitializeComponent();
90
            
91
            //cursor change  
92
            this.Cursor = new Cursor(CursorChange().StreamSource);
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

    
154
                try
155
                {
156
                    this.dzMainMenu.HubSet();
157
                    this.dzMainMenu.SetView(App.ViewInfo);
158
                }
159
                catch (Exception)
160
                {
161
                    MessageBox.Show("웹 서비스에 연결을 할 수 없습니다.");
162

    
163
                    System.Environment.Exit(0);
164
                }
165
            }
166

    
167
            //double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
168
            //double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
169
            ////this.Width += 40;
170

    
171
            var graphics = System.Drawing.Graphics.FromHwnd(IntPtr.Zero);
172
            var screenWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
173
            var screenHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
174
            var pixelToDPI = 96.0 / graphics.DpiX;
175
            this.Width = screenWidth * pixelToDPI;
176
            this.Height = screenHeight * pixelToDPI;
177

    
178
            //double windowWidth = this.Width;
179
            //double windowHeight = this.Height;
180

    
181
            this.Left = (screenWidth / 2) - (this.Width / 2);
182
            this.Top = (screenHeight / 2) - (this.Height / 2);
183

    
184

    
185
            //App.ViewInfo = new IKCOM.ViewInfo
186
            //{
187
            //    DocumentItemID = "11111112",
188
            //    //DocumentItemID = "10001",
189
            //    bPartner = false,
190
            //    CreateFinalPDFPermission = true,
191
            //    NewCommentPermission = true,
192
            //    ProjectNO = "000000",
193
            //    UserID = "H2011357",
194
            //    //UserID = "H2009115",
195
            //    //Mode = 0 , 1 , 2
196
            //};
197

    
198
            //this.dzMainMenu.ServiceOn();
199
            //this.dzMainMenu.SetView(App.ViewInfo);
200
        }
201

    
202

    
203
        bool restoreIfMove = false;
204

    
205
        private void WindowDragEvent(object sender, MouseButtonEventArgs e)
206
        {
207
            //if(string.IsNullOrEmpty(destfilepath))
208
            //{
209
            //    if (e.ClickCount == 2)
210
            //    {
211
            //        if ((ResizeMode == ResizeMode.CanResize) ||
212
            //            (ResizeMode == ResizeMode.CanResizeWithGrip))
213
            //        {
214
            //            SwitchState();
215
            //        }
216
            //    }
217
            //    else
218
            //    {
219
            //        if (WindowState == WindowState.Maximized)
220
            //        {
221
            //            restoreIfMove = true;
222
            //        }
223
                    
224
            //        this.DragMove();
225
            //    }
226
            //}            
227
        }   
228

    
229
        private void WindowDragEventUp(object sender, MouseButtonEventArgs e)
230
        {
231
            restoreIfMove = false;
232
        }
233

    
234
        private void WindowDragEventMove(object sender, MouseEventArgs e)
235
        {
236
            //if (restoreIfMove)
237
            //{
238
            //    if (Mouse.LeftButton == MouseButtonState.Pressed)
239
            //    {
240
            //        //this.WindowState = WindowState.Normal;
241

    
242
            //        restoreIfMove = false;
243

    
244
            //        double percentHorizontal = e.GetPosition(this).X / ActualWidth;
245
            //        double targetHorizontal = RestoreBounds.Width * percentHorizontal;
246

    
247
            //        double percentVertical = e.GetPosition(this).Y / ActualHeight;
248
            //        double targetVertical = RestoreBounds.Height * percentVertical;
249

    
250
            //        POINT lMousePosition;
251
            //        GetCursorPos(out lMousePosition);
252

    
253
            //        Left = lMousePosition.X - targetHorizontal;
254
            //        double top = lMousePosition.Y - targetVertical;
255
            //        if(top < 10)
256
            //        {
257
            //            top = 10;
258
            //        }
259
            //        Top = lMousePosition.Y;
260

    
261

    
262
            //        WindowState = WindowState.Normal;
263

    
264
            //        this.DragMove();
265
            //    }
266
            //}
267
        }
268

    
269
        [DllImport("user32.dll")]
270
        [return: MarshalAs(UnmanagedType.Bool)]
271
        static extern bool GetCursorPos(out POINT lpPoint);
272

    
273
        [StructLayout(LayoutKind.Sequential)]
274
        public struct POINT
275
        {
276
            public int X;
277
            public int Y;
278

    
279
            public POINT(int x, int y)
280
            {
281
                this.X = x;
282
                this.Y = y;
283
            }
284
        }
285

    
286
        private void SwitchState()
287
        {
288
            switch (WindowState)
289
            {
290
                case WindowState.Normal:
291
                    {
292
                        WindowState = WindowState.Maximized;
293
                        break;
294
                    }
295
                case WindowState.Maximized:
296
                    {
297
                        WindowState = WindowState.Normal;
298
                        break;
299
                    }
300
            }
301
        }
302

    
303
        private void RadButton_Click(object sender, RoutedEventArgs e)
304
        {
305
            Telerik.Windows.Controls.RadButton button = sender as Telerik.Windows.Controls.RadButton;
306

    
307
            switch (button.CommandParameter.ToString())
308
            {
309
                case ("Min"):
310
                    {
311
                        WindowState = WindowState.Minimized;
312
                    }
313
                    break;
314
                case ("Max"):
315
                    {
316
                        WindowState = WindowState.Maximized;
317
                    }
318
                    break;
319
                case ("Exit"):
320
                    {
321

    
322
                    }
323
                    break;
324
            }
325
        }
326

    
327
        private void WinState(object sender, MouseButtonEventArgs e)
328
        {
329
            switch ((e.Source as Image).Name)
330
            {
331
                case ("Win_min"):
332
                    {
333
                        WindowState = WindowState.Minimized;
334
                    }
335
                    break;
336
                case ("Win_max"):
337
                    {
338
                        if (WindowState == WindowState.Maximized)
339
                        {
340
                            WindowState = WindowState.Normal;
341
                        }
342
                        else
343
                        {
344
                            WindowState = WindowState.Maximized;
345
                        }
346
                    }
347
                    break;
348
                case ("Win_Close"):
349
                    {
350
                        SaveCheck();
351
                        //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
352
                        KeyValuePair<bool, string> updatecheck = UpdateCheck();
353
                        if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
354
                        {
355
                            CallUpdateProcess(updatecheck.Value);
356
                        }
357
                        this.Close();
358
                    }
359
                    break;
360
            }
361
        }
362
        
363
        private void SaveCheck()
364
        {
365
            if (ViewerDataModel.Instance.UndoDataList.Count > 0)
366
            {
367
                DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
368
                DateTime updatetime = DateTime.Now.AddDays(-1);
369
                if (ViewerDataModel.Instance._markupInfoList.Count > 0)
370
                {
371
                    updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
372
                }
373

    
374
                if (undoTime > updatetime)
375
                {
376
                    DialogParameters parameters = new DialogParameters()
377
                    {
378
                        Owner = Application.Current.MainWindow,
379
                        Content = new TextBlock()
380
                        {
381
                            MinWidth = 400,
382
                            FontSize = 11,
383
                            Text = "저장되지 않은 코멘트가 있습니다. 저장 하시겠습니까?",
384
                            TextWrapping = System.Windows.TextWrapping.Wrap
385
                        },
386
                        Header = "Confirm",
387
                        Theme = new VisualStudio2013Theme(),
388
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
389
                        Closed = OnClosingSave,
390
                    };
391
                    RadWindow.Confirm(parameters);
392
                }
393
                else
394
                {
395
                    isSaveCheck = true;
396
                }                    
397
            }else
398
            {
399
                isSaveCheck = true;
400
            }
401
        }
402
        private void OnClosingSave(object sender, WindowClosedEventArgs e)
403
        {
404
            if (e.DialogResult == true)
405
            {
406
                dzTopMenu.SaveEventCallback(null, null);
407
            }
408
            isSaveCheck = true;
409
        }
410
                
411
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
412
        {
413
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
414
            {
415
                double bytesIn = double.Parse(e.BytesReceived.ToString());
416
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
417
                double percentage = bytesIn / totalBytes * 100;
418
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
419
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());                
420
            }));
421
        }
422

    
423
        /// <summary>
424
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
425
        /// false : 업데이트 불필요.
426
        /// true : 업데이트 필요. url 을 같이 Return.
427
        /// </summary>
428
        /// <returns></returns>
429
        private KeyValuePair<bool, string> UpdateCheck()
430
        {
431
            bool isUpdateCheck = false;
432
            string updateurl = string.Empty;
433
            try
434
            {
435
                bool is64bit = Environment.Is64BitProcess;
436
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
437
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
438
                
439
                if (Check_Uri.isUri(updateurl))
440
                {                          
441
                    DialogParameters parameters = new DialogParameters()
442
                    {
443
                        Owner = Application.Current.MainWindow,
444
                        Content = new TextBlock()
445
                        {
446
                            MinWidth = 400,
447
                            FontSize = 11,
448
                            Text = "새로운 버전이 있습니다. \n업데이트 하시겠습니까?",
449
                            TextWrapping = System.Windows.TextWrapping.Wrap
450
                        },
451
                        Header = "Confirm",
452
                        Theme = new VisualStudio2013Theme(),
453
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },                        
454
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
455
                        {
456
                            if (e.DialogResult == true)
457
                            {   
458
                                isUpdateCheck = true;                                
459
                            }
460
                            else
461
                            {
462
                                isUpdateCheck = false;
463
                            }                            
464
                        }                    
465
                    };
466
                    RadWindow.Confirm(parameters);       
467
                    
468
                }
469
                else
470
                {
471
                    isUpdateCheck = false;
472
                }
473
            }
474
            catch (Exception)
475
            {
476
                throw;
477
            }
478
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
479
        }
480

    
481
        /// <summary>
482
        /// SmartUpdate 를 호출.
483
        /// </summary>
484
        /// <param name="updateurl">Download 할 설치파일 경로</param>
485
        private void CallUpdateProcess(string updateurl)
486
        {
487
            ProcessStartInfo proInfo = new ProcessStartInfo();
488
            string smartupdaterpath = string.Empty;
489
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
490
            Process.Start(smartupdaterpath, updateurl);
491
        }
492
        private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
493
        {
494
            try
495
            {
496
                Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
497
                {
498
                    progressControl.splashText.Text = "Download Completed";
499
                }));                
500
                if(progressControl != null)
501
                {
502
                    progressControl.Close();
503
                    progressControl = null;
504
                }
505
                if(File.Exists(destfilepath))
506
                {
507
                    ProcessStartInfo update_msi = new ProcessStartInfo();
508
                    update_msi.FileName = destfilepath;
509
                    Process.Start(update_msi);
510
                }                
511
                this.Close();
512
            }
513
            catch (Exception)
514
            {
515
                throw;
516
            }
517
            
518
        }
519

    
520
        void win_SourceInitialized(object sender, EventArgs e)
521
        {
522
            //System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
523
            //WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
524
        }
525

    
526
        private static System.IntPtr WindowProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled)
527
        {
528
            switch (msg)
529
            {
530
                case 0x0024:
531
                    WmGetMinMaxInfo(hwnd, lParam);
532
                    handled = true;
533
                    break;
534
            }
535
            return (System.IntPtr)0;
536
        }
537

    
538
        private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
539
        {
540
            MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
541
            int MONITOR_DEFAULTTONEAREST = 0x00000002;
542
            System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
543

    
544
            if (monitor != System.IntPtr.Zero)
545
            {
546
                MONITORINFO monitorInfo = new MONITORINFO();
547
                GetMonitorInfo(monitor, monitorInfo);
548
                RECT rcWorkArea = monitorInfo.rcWork;
549
                RECT rcMonitorArea = monitorInfo.rcMonitor;
550
                mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
551
                mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
552
                mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
553
                mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
554
            }
555
            Marshal.StructureToPtr(mmi, lParam, true);
556
        }
557

    
558
        [StructLayout(LayoutKind.Sequential)]
559
        public struct POINT2
560
        {
561
            public int x;
562
            public int y;
563
            public POINT2(int x, int y)
564
            {
565
                this.x = x;
566
                this.y = y;
567
            }
568
        }
569

    
570
        [StructLayout(LayoutKind.Sequential)]
571
        public struct MINMAXINFO
572
        {
573
            public POINT2 ptReserved;
574
            public POINT2 ptMaxSize;
575
            public POINT2 ptMaxPosition;
576
            public POINT2 ptMinTrackSize;
577
            public POINT2 ptMaxTrackSize;
578
        };
579

    
580
        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
581
        public class MONITORINFO
582
        {
583
            public int cbSize = Marshal.SizeOf(typeof(MONITORINFO));
584
            public RECT rcMonitor = new RECT();
585
            public RECT rcWork = new RECT();
586
            public int dwFlags = 0;
587
        }
588

    
589
        [StructLayout(LayoutKind.Sequential, Pack = 0)]
590
        public struct RECT
591
        {
592
            public int left;
593
            public int top;
594
            public int right;
595
            public int bottom;
596

    
597
            public static readonly RECT Empty = new RECT();
598

    
599
            public int Width
600
            {
601
                get { return Math.Abs(right - left); }  // Abs needed for BIDI OS
602
            }
603

    
604
            public int Height
605
            {
606
                get { return bottom - top; }
607
            }
608

    
609
            public RECT(int left, int top, int right, int bottom)
610
            {
611
                this.left = left;
612
                this.top = top;
613
                this.right = right;
614
                this.bottom = bottom;
615
            }
616

    
617
            public RECT(RECT rcSrc)
618
            {
619
                this.left = rcSrc.left;
620
                this.top = rcSrc.top;
621
                this.right = rcSrc.right;
622
                this.bottom = rcSrc.bottom;
623
            }
624

    
625
            public bool IsEmpty
626
            {
627
                get
628
                {
629
                    // BUGBUG : On Bidi OS (hebrew arabic) left > right
630
                    return left >= right || top >= bottom;
631
                }
632
            }
633

    
634
            public override bool Equals(object obj)
635
            {
636
                if (!(obj is Rect)) { return false; }
637
                return (this == (RECT)obj);
638
            }
639

    
640
            public override int GetHashCode()
641
            {
642
                return left.GetHashCode() + top.GetHashCode() + right.GetHashCode() + bottom.GetHashCode();
643
            }
644

    
645
            public static bool operator ==(RECT rect1, RECT rect2)
646
            {
647
                return (rect1.left == rect2.left && rect1.top == rect2.top && rect1.right == rect2.right && rect1.bottom == rect2.bottom);
648
            }
649

    
650
            public static bool operator !=(RECT rect1, RECT rect2)
651
            {
652
                return !(rect1 == rect2);
653
            }
654
        }
655

    
656
        [DllImport("user32")]
657
        internal static extern bool GetMonitorInfo(IntPtr hMonitor, MONITORINFO lpmi);
658
        [DllImport("User32")]
659
        internal static extern IntPtr MonitorFromWindow(IntPtr handle, int flags);
660
    }
661
}
클립보드 이미지 추가 (최대 크기: 500 MB)