프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ e31e5b1b

이력 | 보기 | 이력해설 | 다운로드 (16 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

    
94
            //cursor change  
95
            this.Cursor = new Cursor(App.DefaultArrowCursorStream);
96

    
97
            var point = GetScreenCenter();
98

    
99
            //this.Left = point.X;
100
            //this.Top = point.Y;
101

    
102
            ViewerDataModel.Instance.SystemMain = this;
103

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

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

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

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

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

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

    
177
        private Point GetScreenCenter()
178
        {
179
            Point result = new Point();
180

    
181
            //first get all the screens 
182
            System.Drawing.Rectangle ret;
183
            int ScreenWidth = 0;
184

    
185
            var mousePosition = System.Windows.Forms.Cursor.Position;
186

    
187
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
188
            {
189
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
190

    
191
                if (ret.Contains(mousePosition))
192
                {
193
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
194
                    result.Y = (ret.Height / 2 - this.Height / 2);
195

    
196
                    break;
197
                }
198
                else
199
                {
200
                    ScreenWidth += ret.Width;
201
                }
202

    
203
            }
204

    
205

    
206
            return result;
207
        }
208

    
209
        protected override void OnStateChanged(EventArgs e)
210
        {
211
            base.OnStateChanged(e);
212
        }
213

    
214
        protected override void OnClosing(CancelEventArgs e)
215
        {
216
            base.OnClosing(e);
217
            
218
            if(!ViewerDataModel.Instance.SaveCheck())
219
            {
220
                var IsConfirm = SaveConfirm();
221

    
222
                if (IsConfirm == null)
223
                {
224
                    e.Cancel = true;
225
                }
226
                else if(IsConfirm == true)
227
                { 
228
                    dzTopMenu.SaveEventCallback(null, null);
229
                }
230
            }
231

    
232
            if (App.ViewInfo.CreateFinalPDFPermission)
233
            {
234
                if (!ViewerDataModel.Instance.FinalPDFCheck())
235
                {
236
                    var result = FinalConfirm();
237

    
238
                    if(result == null)
239
                        e.Cancel = true;
240

    
241
                    if (result == false)
242
                    {
243
                        e.Cancel = true;
244
                    }
245
                    else
246
                    {
247
                        //Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
248
                    }
249
                }
250
            }
251

    
252
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
253
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
254
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
255
            //{
256
            //    CallUpdateProcess(updatecheck.Value);
257
            //}
258
        }
259

    
260

    
261
        private bool? SaveConfirm()
262
        {
263
            bool? result = null;
264

    
265
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
266

    
267
            Closedhandler = (snd, evt) =>
268
            {
269
                result = evt.DialogResult;
270
            };
271

    
272
            DialogParameters parameters = new DialogParameters()
273
            {
274
                Content = new TextBlock()
275
                {
276
                    MinWidth = 300,
277
                    FontSize = 11,
278
                    Text = "Found unsaved comments. Save now?",
279
                    TextWrapping = System.Windows.TextWrapping.Wrap
280
                },
281

    
282
                Header = "Confirm",
283
                Theme = new VisualStudio2013Theme(),
284
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
285
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
286

    
287
                Owner = Application.Current.MainWindow,
288
                Opened = (s, openedEvent) =>
289
                {
290
                    RadWindow confirm = s as RadWindow;
291
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
292
                    //FocusManager.SetIsFocusScope(confirm, true);
293
                    //FocusManager.SetFocusedElement(confirm, Cancel);
294
                },
295

    
296
                Closed = Closedhandler
297
            };
298

    
299
            RadWindow.Confirm(parameters);
300

    
301
            return result;
302
        }
303

    
304
        private bool? FinalConfirm()
305
        {
306
            bool? result = false;
307

    
308
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
309

    
310
            Closedhandler = (snd, evt) =>
311
            {
312
                result = evt.DialogResult;
313
            };
314

    
315
            DialogParameters parameters = new DialogParameters()
316
            {
317
                Content = new TextBlock()
318
                {
319
                    MinWidth = 300,
320
                    FontSize = 11,
321
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
322
                    TextWrapping = System.Windows.TextWrapping.Wrap
323
                },
324

    
325
                Header = "Confirm",
326
                Theme = new VisualStudio2013Theme(),
327
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
328
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
329

    
330
                Owner = Application.Current.MainWindow,
331
                Opened = (s, openedEvent) =>
332
                {
333
                    RadWindow confirm = s as RadWindow;
334
                },
335

    
336
                Closed = Closedhandler
337
            };
338

    
339
            RadWindow.Confirm(parameters);
340

    
341
            return result;
342
        }
343

    
344
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
345
        {
346
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
347
            {
348
                double bytesIn = double.Parse(e.BytesReceived.ToString());
349
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
350
                double percentage = bytesIn / totalBytes * 100;
351
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
352
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
353
            }));
354
        }
355

    
356
        /// <summary>
357
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
358
        /// false : 업데이트 불필요.
359
        /// true : 업데이트 필요. url 을 같이 Return.
360
        /// </summary>
361
        /// <returns></returns>
362
        private KeyValuePair<bool, string> UpdateCheck()
363
        {
364
            bool isUpdateCheck = false;
365
            string updateurl = string.Empty;
366
            try
367
            {
368
                bool is64bit = Environment.Is64BitProcess;
369
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
370
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
371

    
372
                if (Check_Uri.isUri(updateurl))
373
                {
374
                    DialogParameters parameters = new DialogParameters()
375
                    {
376
                        Owner = Application.Current.MainWindow,
377
                        Content = new TextBlock()
378
                        {
379
                            MinWidth = 400,
380
                            FontSize = 11,
381
                            Text = "Update is available. \n Update now?",
382
                            TextWrapping = System.Windows.TextWrapping.Wrap
383
                        },
384
                        Header = "Confirm",
385
                        Theme = new VisualStudio2013Theme(),
386
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
387
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
388
                        {
389
                            if (e.DialogResult == true)
390
                            {
391
                                isUpdateCheck = true;
392
                            }
393
                            else
394
                            {
395
                                isUpdateCheck = false;
396
                            }
397
                        }
398
                    };
399
                    RadWindow.Confirm(parameters);
400

    
401
                }
402
                else
403
                {
404
                    isUpdateCheck = false;
405
                }
406
            }
407
            catch (Exception ex)
408
            {
409
                throw ex;
410
            }
411
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
412
        }
413

    
414
        /// <summary>
415
        /// SmartUpdate 를 호출.
416
        /// </summary>
417
        /// <param name="updateurl">Download 할 설치파일 경로</param>
418
        private void CallUpdateProcess(string updateurl)
419
        {
420
            ProcessStartInfo proInfo = new ProcessStartInfo();
421
            string smartupdaterpath = string.Empty;
422
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
423
            Process.Start(smartupdaterpath, updateurl);
424
        }
425
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
426
        {
427
            try
428
            {
429
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
430

    
431
                if (progressControl != null)
432
                {
433
                    progressControl.Close();
434
                    progressControl = null;
435
                }
436
                if (File.Exists(destfilepath))
437
                {
438
                    ProcessStartInfo update_msi = new ProcessStartInfo();
439
                    update_msi.FileName = destfilepath;
440
                    Process.Start(update_msi);
441
                }
442
                this.Close();
443
            }
444
            catch (Exception)
445
            {
446
                throw;
447
            }
448

    
449
        }
450
    }
451
}
클립보드 이미지 추가 (최대 크기: 500 MB)