프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 0d2d2a08

이력 | 보기 | 이력해설 | 다운로드 (18.4 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 : KCOM.Controls.CustomizedWindow.CustomWindow
41
    {
42
        bool isSaveCheck = false;
43

    
44
        ProgressControl progressControl = null;
45
        string destfilepath = string.Empty;
46

    
47
        public MainWindow()
48
        {
49
            App.splashString(ISplashMessage.MAINWINDOW);
50

    
51
            this.Loaded += MainWindow_Loaded;
52
            this.Unloaded += MainWindow_Unloaded;
53
            //this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
54
            this.Activated += MainWindow_Activated;
55
        }
56

    
57
      
58

    
59
        private void MainWindow_Activated(object sender, EventArgs e)
60
        {
61
            this.Topmost = true;
62
            this.Topmost = false;
63
        }
64

    
65
        private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
66
        {
67
        }
68

    
69
        public void DialogMessage_Alert(string content, string header)
70
        {
71
            App.splashScreen.Close();
72

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

    
90
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
91
        {
92
            InitializeComponent();
93
            //Loaded 이벤트에서 MaxHeight를 설정 모니터가 1개일때만
94
            //MaxHeight = SystemParameters.WorkArea.Height;
95
            //LocationChanged : 모니터가 2개 이상이고, 모니터의 해상도가 다를 때에 설정
96
            this.LocationChanged += Window_LocationChanged;
97
            //cursor change  
98
            this.Cursor = new Cursor(App.DefaultArrowCursorStream);
99

    
100
            var point = GetScreenCenter();
101

    
102
            //this.Left = point.X;
103
            //this.Top = point.Y;
104

    
105
            ViewerDataModel.Instance.SystemMain = this;
106

    
107
            if (!App.ParameterMode)
108
            {
109
                //App.ViewInfo = new IKCOM.ViewInfo
110
                //{
111
                //    DocumentItemID = "11111112",
112
                //    //DocumentItemID = "10001",
113
                //    bPartner = false,
114
                //    CreateFinalPDFPermission = true,
115
                //    NewCommentPermission = true,
116
                //    ProjectNO = "000000",
117
                //    UserID = "H2011357",
118
                //    //UserID = "H2009115",
119
                //    //Mode = 0 , 1 , 2
120
                //};
121
                //DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
122

    
123
                //#if DEBUG
124
                //                App.ViewInfo = new IKCOM.ViewInfo
125
                //                {
126
                //                    DocumentItemID = "11111112",
127
                //                    //DocumentItemID = "10001",
128
                //                    bPartner = false,
129
                //                    CreateFinalPDFPermission = true,
130
                //                    NewCommentPermission = true,
131
                //                    ProjectNO = "000000",
132
                //                    UserID = "H2011357",
133
                //                    //UserID = "H2009115",
134
                //                    //Mode = 0 , 1 , 2
135
                //                };
136
                //                App.ParameterMode = true;
137
                //                this.dzMainMenu.ServiceOn();
138
                //                this.dzMainMenu.SetView(App.ViewInfo);
139
                //#else
140

    
141
                DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
142
                this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed;
143
                this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed;
144
                this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed;
145
                this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed;
146
                this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
147
                //#endif
148
            }
149
            else
150
            {
151
                this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
152
                this.dzMainMenu.ServiceOn();
153

    
154
                if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
155
                {
156
                    this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
157
                    var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
158
                    list.ForEach(item => item.Visibility = Visibility.Collapsed);
159
                    this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
160
                    this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
161
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
162
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
163
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
164
                }
165

    
166
                try
167
                {
168
                    ///this.dzMainMenu.HubSet();
169
                    this.dzMainMenu.SetView(App.ViewInfo);
170
                }
171
                catch (Exception ex)
172
                {
173
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
174

    
175
                    System.Environment.Exit(0);
176
                }
177
            }
178
        }
179
        /// <summary>
180
        /// 멤버 변수로 현 사용자의 모든 모니터들의 상태를 가져온다.
181
        /// Window의 LocationChanged Event를 통해 Window가 이동할 때마다 어떤 모니터에 있는지를 확인
182
        /// Window가 어떤 모니터에 있는지의 기준은 각 Window의 중앙 부분 
183
        /// Sum 은 모니터들의 왼쪽 끝 부터 오른쪽 끝까지의 합
184
        /// 현재 Window의 중앙은 Left 값 + Width의 반
185
        /// um보다 작다면 현재 더하게 된 Screen 안에 있다는 뜻이므로 현재 더한 item의 WorkingArea의 Height를MaxHeight로 설정   
186
        /// </summary>
187
        System.Windows.Forms.Screen[] screens = System.Windows.Forms.Screen.AllScreens;
188
        private void Window_LocationChanged(object sender, EventArgs e) 
189
        {             
190
            int sum = 0;
191
            foreach (var item in screens)
192
            {
193
                sum += item.WorkingArea.Width;
194
                if (sum >= this.Left + this.Width / 2)
195
                {
196
                    this.MaxHeight = item.WorkingArea.Height;
197
                this.MaxWidth = item.WorkingArea.Width;
198
                if (this.Left < 0)
199
                {
200
                    this.Left = 0;
201
                }
202

    
203
                if (this.Top < 0)
204
                {
205
                    this.Top = 0;
206
                }
207
                //   if(this.Tag.Equals("Normal"))
208
                //{
209
                //    this.WindowState = WindowState.Normal;
210
                //    this.CustomState = WindowState.Maximized;
211
                //}    
212
                //if (this.CustomState == WindowState.Maximized)
213
                //{
214
                //    this.WindowState = WindowState.Normal;
215
                //    this.CustomState = WindowState.Normal;
216

    
217

    
218
                //}
219
                //else
220
                //{
221
                //    this.WindowState = WindowState.Normal;
222
                //    this.CustomState = WindowState.Maximized;
223
                //    this.NomalWindowArea = new Rect(this.Left, this.Top, this.Width, this.Height);
224

    
225
                //}                        
226
                break;
227
                }  
228
            } 
229
        }
230
        
231
        private Point GetScreenCenter()
232
        {
233
            Point result = new Point();
234

    
235
            //first get all the screens 
236
            System.Drawing.Rectangle ret;
237
            int ScreenWidth = 0;
238

    
239
            var mousePosition = System.Windows.Forms.Cursor.Position;
240

    
241
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
242
            {
243
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
244

    
245
                if (ret.Contains(mousePosition))
246
                {
247
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
248
                    result.Y = (ret.Height / 2 - this.Height / 2);
249

    
250
                    break;
251
                }
252
                else
253
                {
254
                    ScreenWidth += ret.Width;
255
                }
256

    
257
            }
258

    
259

    
260
            return result;
261
        }
262

    
263
        protected override void OnStateChanged(EventArgs e)
264
        {
265
            base.OnStateChanged(e);
266
        }
267

    
268
        protected override void OnClosing(CancelEventArgs e)
269
        {
270
            base.OnClosing(e);
271
            
272
            if(!ViewerDataModel.Instance.SaveCheck())
273
            {
274
                var IsConfirm = SaveConfirm();
275

    
276
                if (IsConfirm == null)
277
                {
278
                    e.Cancel = true;
279
                }
280
                else if(IsConfirm == true)
281
                { 
282
                    dzTopMenu.SaveEventCallback(null, null);
283
                }
284
            }
285

    
286
            if (App.ViewInfo.CreateFinalPDFPermission)
287
            {
288
                if (!ViewerDataModel.Instance.FinalPDFCheck())
289
                {
290
                    var result = FinalConfirm();
291

    
292
                    if(result == null)
293
                        e.Cancel = true;
294

    
295
                    if (result == false)
296
                    {
297
                        e.Cancel = true;
298
                    }
299
                    else
300
                    {
301
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
302
                    }
303
                }
304
            }
305

    
306
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
307
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
308
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
309
            //{
310
            //    CallUpdateProcess(updatecheck.Value);
311
            //}
312
        }
313

    
314

    
315
        private bool? SaveConfirm()
316
        {
317
            bool? result = null;
318

    
319
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
320

    
321
            Closedhandler = (snd, evt) =>
322
            {
323
                result = evt.DialogResult;
324
            };
325

    
326
            DialogParameters parameters = new DialogParameters()
327
            {
328
                Content = new TextBlock()
329
                {
330
                    MinWidth = 300,
331
                    FontSize = 11,
332
                    Text = "Found unsaved comments. Save now?",
333
                    TextWrapping = System.Windows.TextWrapping.Wrap
334
                },
335

    
336
                Header = "Confirm",
337
                Theme = new VisualStudio2013Theme(),
338
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
339
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
340

    
341
                Owner = Application.Current.MainWindow,
342
                Opened = (s, openedEvent) =>
343
                {
344
                    RadWindow confirm = s as RadWindow;
345
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
346
                    //FocusManager.SetIsFocusScope(confirm, true);
347
                    //FocusManager.SetFocusedElement(confirm, Cancel);
348
                },
349

    
350
                Closed = Closedhandler
351
            };
352

    
353
            RadWindow.Confirm(parameters);
354

    
355
            return result;
356
        }
357

    
358
        private bool? FinalConfirm()
359
        {
360
            bool? result = false;
361

    
362
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
363

    
364
            Closedhandler = (snd, evt) =>
365
            {
366
                result = evt.DialogResult;
367
            };
368

    
369
            DialogParameters parameters = new DialogParameters()
370
            {
371
                Content = new TextBlock()
372
                {
373
                    MinWidth = 300,
374
                    FontSize = 11,
375
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
376
                    TextWrapping = System.Windows.TextWrapping.Wrap
377
                },
378

    
379
                Header = "Confirm",
380
                Theme = new VisualStudio2013Theme(),
381
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
382
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
383

    
384
                Owner = Application.Current.MainWindow,
385
                Opened = (s, openedEvent) =>
386
                {
387
                    RadWindow confirm = s as RadWindow;
388
                },
389

    
390
                Closed = Closedhandler
391
            };
392

    
393
            RadWindow.Confirm(parameters);
394

    
395
            return result;
396
        }
397

    
398
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
399
        {
400
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
401
            {
402
                double bytesIn = double.Parse(e.BytesReceived.ToString());
403
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
404
                double percentage = bytesIn / totalBytes * 100;
405
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
406
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
407
            }));
408
        }
409

    
410
        /// <summary>
411
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
412
        /// false : 업데이트 불필요.
413
        /// true : 업데이트 필요. url 을 같이 Return.
414
        /// </summary>
415
        /// <returns></returns>
416
        private KeyValuePair<bool, string> UpdateCheck()
417
        {
418
            bool isUpdateCheck = false;
419
            string updateurl = string.Empty;
420
            try
421
            {
422
                bool is64bit = Environment.Is64BitProcess;
423
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
424
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
425

    
426
                if (Check_Uri.isUri(updateurl))
427
                {
428
                    DialogParameters parameters = new DialogParameters()
429
                    {
430
                        Owner = Application.Current.MainWindow,
431
                        Content = new TextBlock()
432
                        {
433
                            MinWidth = 400,
434
                            FontSize = 11,
435
                            Text = "Update is available. \n Update now?",
436
                            TextWrapping = System.Windows.TextWrapping.Wrap
437
                        },
438
                        Header = "Confirm",
439
                        Theme = new VisualStudio2013Theme(),
440
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
441
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
442
                        {
443
                            if (e.DialogResult == true)
444
                            {
445
                                isUpdateCheck = true;
446
                            }
447
                            else
448
                            {
449
                                isUpdateCheck = false;
450
                            }
451
                        }
452
                    };
453
                    RadWindow.Confirm(parameters);
454

    
455
                }
456
                else
457
                {
458
                    isUpdateCheck = false;
459
                }
460
            }
461
            catch (Exception ex)
462
            {
463
                throw ex;
464
            }
465
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
466
        }
467

    
468
        /// <summary>
469
        /// SmartUpdate 를 호출.
470
        /// </summary>
471
        /// <param name="updateurl">Download 할 설치파일 경로</param>
472
        private void CallUpdateProcess(string updateurl)
473
        {
474
            ProcessStartInfo proInfo = new ProcessStartInfo();
475
            string smartupdaterpath = string.Empty;
476
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
477
            Process.Start(smartupdaterpath, updateurl);
478
        }
479
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
480
        {
481
            try
482
            {
483
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
484

    
485
                if (progressControl != null)
486
                {
487
                    progressControl.Close();
488
                    progressControl = null;
489
                }
490
                if (File.Exists(destfilepath))
491
                {
492
                    ProcessStartInfo update_msi = new ProcessStartInfo();
493
                    update_msi.FileName = destfilepath;
494
                    Process.Start(update_msi);
495
                }
496
                this.Close();
497
            }
498
            catch (Exception)
499
            {
500
                throw;
501
            }
502

    
503
        }
504
    }
505
}
클립보드 이미지 추가 (최대 크기: 500 MB)