프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ b627aa5a

이력 | 보기 | 이력해설 | 다운로드 (16.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.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
            //ViewerDataModel.Instance.ImageViewPath.UriSource = null;
68
            //ViewerDataModel.Instance.ImageViewPath_C.UriSource = null;
69
        }
70

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

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

    
92
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
93
        {
94
            InitializeComponent();
95

    
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
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
161
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
162
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
163
                }
164

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

    
174
                    System.Environment.Exit(0);
175
                }
176
            }
177

    
178
            //App.ViewInfo = new IKCOM.ViewInfo
179
            //{
180
            //    DocumentItemID = "11111112",
181
            //    //DocumentItemID = "10001",
182
            //    bPartner = false,
183
            //    CreateFinalPDFPermission = true,
184
            //    NewCommentPermission = true,
185
            //    ProjectNO = "000000",
186
            //    UserID = "H2011357",
187
            //    //UserID = "H2009115",
188
            //    //Mode = 0 , 1 , 2
189
            //};0
190

    
191
            //this.dzMainMenu.ServiceOn();
192
            //this.dzMainMenu.SetView(App.ViewInfo);
193
        }
194

    
195
        private Point GetScreenCenter()
196
        {
197
            Point result = new Point();
198

    
199
            //first get all the screens 
200
            System.Drawing.Rectangle ret;
201
            int ScreenWidth = 0;
202

    
203
            var mousePosition = System.Windows.Forms.Cursor.Position;
204

    
205
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
206
            {
207
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
208

    
209
                if (ret.Contains(mousePosition))
210
                {
211
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
212
                    result.Y = (ret.Height / 2 - this.Height / 2);
213

    
214
                    break;
215
                }
216
                else
217
                {
218
                    ScreenWidth += ret.Width;
219
                }
220

    
221
            }
222

    
223

    
224
            return result;
225
        }
226

    
227
        protected override void OnStateChanged(EventArgs e)
228
        {
229
            base.OnStateChanged(e);
230
        }
231

    
232
        protected override void OnClosing(CancelEventArgs e)
233
        {
234
            base.OnClosing(e);
235

    
236
            DownloadProcess.ProcessKill();
237

    
238
            if (!ViewerDataModel.Instance.SaveCheck())
239
            {
240
                var IsConfirm = SaveConfirm();
241

    
242
                if (IsConfirm == null)
243
                {
244
                    e.Cancel = true;
245
                }
246
                else if(IsConfirm == true)
247
                { 
248
                    if(dzTopMenu._SaveEvent(null, null))
249
                    {
250
                        System.Threading.Thread.Sleep(3000);
251
                    }
252
                }
253
            }
254

    
255
            if (App.ViewInfo.CreateFinalPDFPermission)
256
            {
257
                if (!ViewerDataModel.Instance.FinalPDFCheck())
258
                {
259
                    var result = FinalConfirm();
260

    
261
                    if (result == false)
262
                    {
263
                        e.Cancel = true;
264
                    }
265
                    else
266
                    {
267
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
268
                    }
269
                }
270
            }
271

    
272
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
273
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
274
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
275
            //{
276
            //    CallUpdateProcess(updatecheck.Value);
277
            //}
278
        }
279

    
280

    
281
        private bool? SaveConfirm()
282
        {
283
            bool? result = null;
284

    
285
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
286

    
287
            Closedhandler = (snd, evt) =>
288
            {
289
                result = evt.DialogResult;
290
            };
291

    
292
            DialogParameters parameters = new DialogParameters()
293
            {
294
                Content = new TextBlock()
295
                {
296
                    MinWidth = 300,
297
                    FontSize = 11,
298
                    Text = "Found unsaved comments. Save now?",
299
                    TextWrapping = System.Windows.TextWrapping.Wrap
300
                },
301

    
302
                Header = "Confirm",
303
                Theme = new VisualStudio2013Theme(),
304
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
305
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
306

    
307
                Owner = Application.Current.MainWindow,
308
                Opened = (s, openedEvent) =>
309
                {
310
                    RadWindow confirm = s as RadWindow;
311
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
312
                    //FocusManager.SetIsFocusScope(confirm, true);
313
                    //FocusManager.SetFocusedElement(confirm, Cancel);
314
                },
315

    
316
                Closed = Closedhandler
317
            };
318

    
319
            RadWindow.Confirm(parameters);
320

    
321
            return result;
322
        }
323

    
324
        private bool? FinalConfirm()
325
        {
326
            bool? result = false;
327

    
328
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
329

    
330
            Closedhandler = (snd, evt) =>
331
            {
332
                result = evt.DialogResult;
333
            };
334

    
335
            DialogParameters parameters = new DialogParameters()
336
            {
337
                Content = new TextBlock()
338
                {
339
                    MinWidth = 300,
340
                    FontSize = 11,
341
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
342
                    TextWrapping = System.Windows.TextWrapping.Wrap
343
                },
344

    
345
                Header = "Confirm",
346
                Theme = new VisualStudio2013Theme(),
347
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
348
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
349

    
350
                Owner = Application.Current.MainWindow,
351
                Opened = (s, openedEvent) =>
352
                {
353
                    RadWindow confirm = s as RadWindow;
354
                },
355

    
356
                Closed = Closedhandler
357
            };
358

    
359
            RadWindow.Confirm(parameters);
360

    
361
            return result;
362
        }
363

    
364
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
365
        {
366
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
367
            {
368
                double bytesIn = double.Parse(e.BytesReceived.ToString());
369
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
370
                double percentage = bytesIn / totalBytes * 100;
371
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
372
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
373
            }));
374
        }
375

    
376
        /// <summary>
377
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
378
        /// false : 업데이트 불필요.
379
        /// true : 업데이트 필요. url 을 같이 Return.
380
        /// </summary>
381
        /// <returns></returns>
382
        private KeyValuePair<bool, string> UpdateCheck()
383
        {
384
            bool isUpdateCheck = false;
385
            string updateurl = string.Empty;
386
            try
387
            {
388
                bool is64bit = Environment.Is64BitProcess;
389
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
390
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
391

    
392
                if (Check_Uri.isUri(updateurl))
393
                {
394
                    DialogParameters parameters = new DialogParameters()
395
                    {
396
                        Owner = Application.Current.MainWindow,
397
                        Content = new TextBlock()
398
                        {
399
                            MinWidth = 400,
400
                            FontSize = 11,
401
                            Text = "Update is available. \n Update now?",
402
                            TextWrapping = System.Windows.TextWrapping.Wrap
403
                        },
404
                        Header = "Confirm",
405
                        Theme = new VisualStudio2013Theme(),
406
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
407
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
408
                        {
409
                            if (e.DialogResult == true)
410
                            {
411
                                isUpdateCheck = true;
412
                            }
413
                            else
414
                            {
415
                                isUpdateCheck = false;
416
                            }
417
                        }
418
                    };
419
                    RadWindow.Confirm(parameters);
420

    
421
                }
422
                else
423
                {
424
                    isUpdateCheck = false;
425
                }
426
            }
427
            catch (Exception ex)
428
            {
429
                throw ex;
430
            }
431
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
432
        }
433

    
434
        /// <summary>
435
        /// SmartUpdate 를 호출.
436
        /// </summary>
437
        /// <param name="updateurl">Download 할 설치파일 경로</param>
438
        private void CallUpdateProcess(string updateurl)
439
        {
440
            ProcessStartInfo proInfo = new ProcessStartInfo();
441
            string smartupdaterpath = string.Empty;
442
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
443
            Process.Start(smartupdaterpath, updateurl);
444
        }
445
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
446
        {
447
            try
448
            {
449
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
450

    
451
                if (progressControl != null)
452
                {
453
                    progressControl.Close();
454
                    progressControl = null;
455
                }
456
                if (File.Exists(destfilepath))
457
                {
458
                    ProcessStartInfo update_msi = new ProcessStartInfo();
459
                    update_msi.FileName = destfilepath;
460
                    Process.Start(update_msi);
461
                }
462
                this.Close();
463
            }
464
            catch (Exception)
465
            {
466
                throw;
467
            }
468

    
469
        }
470
    }
471
}
클립보드 이미지 추가 (최대 크기: 500 MB)