프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ fd19a116

이력 | 보기 | 이력해설 | 다운로드 (19.7 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.Activated += MainWindow_Activated;
54
        }
55
      
56

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

    
63
        private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
64
        {
65
        }
66

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

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

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

    
99
            var point = GetScreenCenter();
100

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

    
104
            ViewerDataModel.Instance.SystemMain = this;
105

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

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

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

    
153
                if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
154
                {
155
                    this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
156
                    var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
157
                    list.ForEach(item => item.Visibility = Visibility.Collapsed);
158
                    this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
159
                    this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
160
                }
161
                else
162
                {
163
                    string signData = await this.dzMainMenu.BaseTaskClient.GetSignDataAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
164
                    string signStrokes = await this.dzMainMenu.BaseTaskClient.GetSignStrokesAsync(App.ViewInfo.ProjectNO, App.ViewInfo.UserID);
165

    
166
                    if (signData != null && signStrokes != null)
167
                    {
168
                        MarkupToPDF.MarkupContext.SetUserSignItem(App.ViewInfo.UserID, signData, signStrokes);
169
                    }
170
                    else
171
                    {
172
                        SignManager signManager = new SignManager();
173

    
174
                        RadWindow signManagerPop = new RadWindow
175
                        {
176
                            MinWidth = 1200,
177
                            MinHeight = 500,
178
                            //Header = "My Check List",
179
                            Header = "",
180
                            Content = signManager,
181
                            Owner = this,
182
                            //ResizeMode = System.Windows.ResizeMode.CanResizeWithGrip,
183
                            ResizeMode = System.Windows.ResizeMode.NoResize,
184
                            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen,
185
                        };
186
                        StyleManager.SetTheme(signManagerPop, new Office2013Theme());
187

    
188
                        //CheckPop.ShowDialog();
189
                        signManagerPop.Show();
190
                    }
191
                }
192

    
193
                try
194
                {
195
                    ///this.dzMainMenu.HubSet();
196
                    this.dzMainMenu.SetView(App.ViewInfo);
197
                }
198
                catch (Exception ex)
199
                {
200
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
201

    
202
                    System.Environment.Exit(0);
203
                }
204
            }
205
        }
206
        /// <summary>
207
        /// 멤버 변수로 현 사용자의 모든 모니터들의 상태를 가져온다.
208
        /// Window의 LocationChanged Event를 통해 Window가 이동할 때마다 어떤 모니터에 있는지를 확인
209
        /// Window가 어떤 모니터에 있는지의 기준은 각 Window의 중앙 부분 
210
        /// Sum 은 모니터들의 왼쪽 끝 부터 오른쪽 끝까지의 합
211
        /// 현재 Window의 중앙은 Left 값 + Width의 반
212
        /// um보다 작다면 현재 더하게 된 Screen 안에 있다는 뜻이므로 현재 더한 item의 WorkingArea의 Height를MaxHeight로 설정   
213
        /// </summary>
214
        System.Windows.Forms.Screen[] screens = System.Windows.Forms.Screen.AllScreens;
215
        private void Window_LocationChanged(object sender, EventArgs e) 
216
        {             
217
            int sum = 0;
218
            foreach (var item in screens)
219
            {
220
                sum += item.WorkingArea.Width;
221
                if (sum >= this.Left + this.Width / 2)
222
                {
223
                    this.MaxHeight = item.WorkingArea.Height;
224
                this.MaxWidth = item.WorkingArea.Width;
225
                if (this.Left < 0)
226
                {
227
                    this.Left = 0;
228
                }
229

    
230
                if (this.Top < 0)
231
                {
232
                    this.Top = 0;
233
                }
234
                //   if(this.Tag.Equals("Normal"))
235
                //{
236
                //    this.WindowState = WindowState.Normal;
237
                //    this.CustomState = WindowState.Maximized;
238
                //}    
239
                //if (this.CustomState == WindowState.Maximized)
240
                //{
241
                //    this.WindowState = WindowState.Normal;
242
                //    this.CustomState = WindowState.Normal;
243

    
244

    
245
                //}
246
                //else
247
                //{
248
                //    this.WindowState = WindowState.Normal;
249
                //    this.CustomState = WindowState.Maximized;
250
                //    this.NomalWindowArea = new Rect(this.Left, this.Top, this.Width, this.Height);
251

    
252
                //}                        
253
                break;
254
                }  
255
            } 
256
        }
257
        
258
        private Point GetScreenCenter()
259
        {
260
            Point result = new Point();
261

    
262
            //first get all the screens 
263
            System.Drawing.Rectangle ret;
264
            int ScreenWidth = 0;
265

    
266
            var mousePosition = System.Windows.Forms.Cursor.Position;
267

    
268
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
269
            {
270
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
271

    
272
                if (ret.Contains(mousePosition))
273
                {
274
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
275
                    result.Y = (ret.Height / 2 - this.Height / 2);
276

    
277
                    break;
278
                }
279
                else
280
                {
281
                    ScreenWidth += ret.Width;
282
                }
283

    
284
            }
285

    
286

    
287
            return result;
288
        }
289

    
290
        protected override void OnStateChanged(EventArgs e)
291
        {
292
            base.OnStateChanged(e);
293
        }
294

    
295
        protected override void OnClosing(CancelEventArgs e)
296
        {
297
            base.OnClosing(e);
298
            
299
            if(!ViewerDataModel.Instance.SaveCheck())
300
            {
301
                var IsConfirm = SaveConfirm();
302

    
303
                if (IsConfirm == null)
304
                {
305
                    e.Cancel = true;
306
                }
307
                else if(IsConfirm == true)
308
                { 
309
                    dzTopMenu.SaveEventCallback(null, null);
310
                }
311
            }
312

    
313
            if (App.ViewInfo.CreateFinalPDFPermission)
314
            {
315
                if (!ViewerDataModel.Instance.FinalPDFCheck())
316
                {
317
                    var result = FinalConfirm();
318

    
319
                    if(result == null)
320
                        e.Cancel = true;
321

    
322
                    if (result == false)
323
                    {
324
                        e.Cancel = true;
325
                    }
326
                    else
327
                    {
328
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
329
                    }
330
                }
331
            }
332

    
333
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
334
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
335
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
336
            //{
337
            //    CallUpdateProcess(updatecheck.Value);
338
            //}
339
        }
340

    
341

    
342
        private bool? SaveConfirm()
343
        {
344
            bool? result = null;
345

    
346
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
347

    
348
            Closedhandler = (snd, evt) =>
349
            {
350
                result = evt.DialogResult;
351
            };
352

    
353
            DialogParameters parameters = new DialogParameters()
354
            {
355
                Content = new TextBlock()
356
                {
357
                    MinWidth = 300,
358
                    FontSize = 11,
359
                    Text = "Found unsaved comments. Save now?",
360
                    TextWrapping = System.Windows.TextWrapping.Wrap
361
                },
362

    
363
                Header = "Confirm",
364
                Theme = new VisualStudio2013Theme(),
365
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
366
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
367

    
368
                Owner = Application.Current.MainWindow,
369
                Opened = (s, openedEvent) =>
370
                {
371
                    RadWindow confirm = s as RadWindow;
372
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
373
                    //FocusManager.SetIsFocusScope(confirm, true);
374
                    //FocusManager.SetFocusedElement(confirm, Cancel);
375
                },
376

    
377
                Closed = Closedhandler
378
            };
379

    
380
            RadWindow.Confirm(parameters);
381

    
382
            return result;
383
        }
384

    
385
        private bool? FinalConfirm()
386
        {
387
            bool? result = false;
388

    
389
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
390

    
391
            Closedhandler = (snd, evt) =>
392
            {
393
                result = evt.DialogResult;
394
            };
395

    
396
            DialogParameters parameters = new DialogParameters()
397
            {
398
                Content = new TextBlock()
399
                {
400
                    MinWidth = 300,
401
                    FontSize = 11,
402
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
403
                    TextWrapping = System.Windows.TextWrapping.Wrap
404
                },
405

    
406
                Header = "Confirm",
407
                Theme = new VisualStudio2013Theme(),
408
                ContentStyle = Application.Current.Resources["RadConfirmYCStyle"] as Style,
409
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
410

    
411
                Owner = Application.Current.MainWindow,
412
                Opened = (s, openedEvent) =>
413
                {
414
                    RadWindow confirm = s as RadWindow;
415
                },
416

    
417
                Closed = Closedhandler
418
            };
419

    
420
            RadWindow.Confirm(parameters);
421

    
422
            return result;
423
        }
424

    
425
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
426
        {
427
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
428
            {
429
                double bytesIn = double.Parse(e.BytesReceived.ToString());
430
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
431
                double percentage = bytesIn / totalBytes * 100;
432
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
433
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
434
            }));
435
        }
436

    
437
        /// <summary>
438
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
439
        /// false : 업데이트 불필요.
440
        /// true : 업데이트 필요. url 을 같이 Return.
441
        /// </summary>
442
        /// <returns></returns>
443
        private KeyValuePair<bool, string> UpdateCheck()
444
        {
445
            bool isUpdateCheck = false;
446
            string updateurl = string.Empty;
447
            try
448
            {
449
                bool is64bit = Environment.Is64BitProcess;
450
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
451
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
452

    
453
                if (Check_Uri.isUri(updateurl))
454
                {
455
                    DialogParameters parameters = new DialogParameters()
456
                    {
457
                        Owner = Application.Current.MainWindow,
458
                        Content = new TextBlock()
459
                        {
460
                            MinWidth = 400,
461
                            FontSize = 11,
462
                            Text = "Update is available. \n Update now?",
463
                            TextWrapping = System.Windows.TextWrapping.Wrap
464
                        },
465
                        Header = "Confirm",
466
                        Theme = new VisualStudio2013Theme(),
467
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
468
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
469
                        {
470
                            if (e.DialogResult == true)
471
                            {
472
                                isUpdateCheck = true;
473
                            }
474
                            else
475
                            {
476
                                isUpdateCheck = false;
477
                            }
478
                        }
479
                    };
480
                    RadWindow.Confirm(parameters);
481

    
482
                }
483
                else
484
                {
485
                    isUpdateCheck = false;
486
                }
487
            }
488
            catch (Exception ex)
489
            {
490
                throw ex;
491
            }
492
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
493
        }
494

    
495
        /// <summary>
496
        /// SmartUpdate 를 호출.
497
        /// </summary>
498
        /// <param name="updateurl">Download 할 설치파일 경로</param>
499
        private void CallUpdateProcess(string updateurl)
500
        {
501
            ProcessStartInfo proInfo = new ProcessStartInfo();
502
            string smartupdaterpath = string.Empty;
503
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
504
            Process.Start(smartupdaterpath, updateurl);
505
        }
506
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
507
        {
508
            try
509
            {
510
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
511

    
512
                if (progressControl != null)
513
                {
514
                    progressControl.Close();
515
                    progressControl = null;
516
                }
517
                if (File.Exists(destfilepath))
518
                {
519
                    ProcessStartInfo update_msi = new ProcessStartInfo();
520
                    update_msi.FileName = destfilepath;
521
                    Process.Start(update_msi);
522
                }
523
                this.Close();
524
            }
525
            catch (Exception)
526
            {
527
                throw;
528
            }
529

    
530
        }
531
    }
532
}
클립보드 이미지 추가 (최대 크기: 500 MB)