프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 77cdac33

이력 | 보기 | 이력해설 | 다운로드 (16.5 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.ServiceOn();
151

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

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

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

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

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

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

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

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

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

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

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

    
220
            }
221

    
222

    
223
            return result;
224
        }
225

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

    
231
        protected override void OnClosing(CancelEventArgs e)
232
        {
233
            base.OnClosing(e);
234
            
235
            if(!ViewerDataModel.Instance.SaveCheck())
236
            {
237
                var IsConfirm = SaveConfirm();
238

    
239
                if (IsConfirm == null)
240
                {
241
                    e.Cancel = true;
242
                }
243
                else if(IsConfirm == true)
244
                { 
245
                    dzTopMenu.SaveEventCallback(null, null);
246
                }
247
            }
248

    
249
            if (App.ViewInfo.CreateFinalPDFPermission)
250
            {
251
                if (!ViewerDataModel.Instance.FinalPDFCheck())
252
                {
253
                    var result = FinalConfirm();
254

    
255
                    if (result == false)
256
                    {
257
                        e.Cancel = true;
258
                    }
259
                    else
260
                    {
261
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
262
                    }
263
                }
264
            }
265

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

    
274

    
275
        private bool? SaveConfirm()
276
        {
277
            bool? result = null;
278

    
279
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
280

    
281
            Closedhandler = (snd, evt) =>
282
            {
283
                result = evt.DialogResult;
284
            };
285

    
286
            DialogParameters parameters = new DialogParameters()
287
            {
288
                Content = new TextBlock()
289
                {
290
                    MinWidth = 300,
291
                    FontSize = 11,
292
                    Text = "Found unsaved comments. Save now?",
293
                    TextWrapping = System.Windows.TextWrapping.Wrap
294
                },
295

    
296
                Header = "Confirm",
297
                Theme = new VisualStudio2013Theme(),
298
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
299
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
300

    
301
                Owner = Application.Current.MainWindow,
302
                Opened = (s, openedEvent) =>
303
                {
304
                    RadWindow confirm = s as RadWindow;
305
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
306
                    //FocusManager.SetIsFocusScope(confirm, true);
307
                    //FocusManager.SetFocusedElement(confirm, Cancel);
308
                },
309

    
310
                Closed = Closedhandler
311
            };
312

    
313
            RadWindow.Confirm(parameters);
314

    
315
            return result;
316
        }
317

    
318
        private bool? FinalConfirm()
319
        {
320
            bool? result = false;
321

    
322
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
323

    
324
            Closedhandler = (snd, evt) =>
325
            {
326
                result = evt.DialogResult;
327
            };
328

    
329
            DialogParameters parameters = new DialogParameters()
330
            {
331
                Content = new TextBlock()
332
                {
333
                    MinWidth = 300,
334
                    FontSize = 11,
335
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
336
                    TextWrapping = System.Windows.TextWrapping.Wrap
337
                },
338

    
339
                Header = "Confirm",
340
                Theme = new VisualStudio2013Theme(),
341
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
342
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
343

    
344
                Owner = Application.Current.MainWindow,
345
                Opened = (s, openedEvent) =>
346
                {
347
                    RadWindow confirm = s as RadWindow;
348
                },
349

    
350
                Closed = Closedhandler
351
            };
352

    
353
            RadWindow.Confirm(parameters);
354

    
355
            return result;
356
        }
357

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

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

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

    
415
                }
416
                else
417
                {
418
                    isUpdateCheck = false;
419
                }
420
            }
421
            catch (Exception ex)
422
            {
423
                throw ex;
424
            }
425
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
426
        }
427

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

    
445
                if (progressControl != null)
446
                {
447
                    progressControl.Close();
448
                    progressControl = null;
449
                }
450
                if (File.Exists(destfilepath))
451
                {
452
                    ProcessStartInfo update_msi = new ProcessStartInfo();
453
                    update_msi.FileName = destfilepath;
454
                    Process.Start(update_msi);
455
                }
456
                this.Close();
457
            }
458
            catch (Exception)
459
            {
460
                throw;
461
            }
462

    
463
        }
464
    }
465
}
클립보드 이미지 추가 (최대 크기: 500 MB)