프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ bae83c92

이력 | 보기 | 이력해설 | 다운로드 (16.5 KB)

1 787a4489 KangIngu
using KCOM.Common;
2 32af2c3b djkim
using KCOM.Controls;
3 264c9309 ljiyeon
using KCOM.Views;
4 787a4489 KangIngu
using KCOMDataModel;
5
using KCOMDataModel.DataModel;
6 b0fb3ad7 ljiyeon
using MarkupToPDF.Common;
7 5529d2a2 humkyung
using MarkupToPDF.Controls.Parsing;
8 b0fb3ad7 ljiyeon
using MarkupToPDF.Serialize.Core;
9
using MarkupToPDF.Serialize.S_Control;
10 787a4489 KangIngu
using System;
11
using System.Collections.Generic;
12 264c9309 ljiyeon
using System.ComponentModel;
13
using System.Diagnostics;
14 6707a5c7 ljiyeon
using System.IO;
15 787a4489 KangIngu
using System.Linq;
16 264c9309 ljiyeon
using System.Net;
17
using System.Reflection;
18 71bfd53e ljiyeon
using System.Runtime.InteropServices;
19 787a4489 KangIngu
using System.Text;
20 264c9309 ljiyeon
using System.Threading;
21
using System.Threading.Tasks;
22 787a4489 KangIngu
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 6707a5c7 ljiyeon
using System.Xml;
32 992a98b4 KangIngu
using Telerik.Windows.Controls;
33 7e2d29a0 ljiyeon
using WinInterop = System.Windows.Interop;
34 787a4489 KangIngu
35
namespace KCOM
36
{
37
    /// <summary>
38
    /// MainWindow.xaml에 대한 상호 작용 논리
39
    /// </summary>
40 68302e9d taeseongkim
    public partial class MainWindow : KCOM.Controls.CustomizedWindow.CustomWindow
41 787a4489 KangIngu
    {
42 32af2c3b djkim
        bool isSaveCheck = false;
43 d33ef543 taeseongkim
44 32af2c3b djkim
        ProgressControl progressControl = null;
45
        string destfilepath = string.Empty;
46
47 787a4489 KangIngu
        public MainWindow()
48
        {
49 c362d2a5 taeseongkim
50 e0cfc73c ljiyeon
            App.splashString(ISplashMessage.MAINWINDOW);
51 c362d2a5 taeseongkim
52 787a4489 KangIngu
            this.Loaded += MainWindow_Loaded;
53 eeb0a39c taeseongkim
            this.Unloaded += MainWindow_Unloaded;
54 8e6884a5 taeseongkim
            //this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
55 d97dbc7f taeseongkim
            this.Activated += MainWindow_Activated;
56
        }
57
58 9d5b4bc2 taeseongkim
      
59 2007ecaa taeseongkim
60 d97dbc7f taeseongkim
        private void MainWindow_Activated(object sender, EventArgs e)
61
        {
62
            this.Topmost = true;
63 448c5399 taeseongkim
            this.Topmost = false;
64 787a4489 KangIngu
        }
65 ca16abb2 ljiyeon
66 eeb0a39c taeseongkim
        private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
67
        {
68
            //ViewerDataModel.Instance.ImageViewPath.UriSource = null;
69
            //ViewerDataModel.Instance.ImageViewPath_C.UriSource = null;
70
        }
71
72 787a4489 KangIngu
        public void DialogMessage_Alert(string content, string header)
73
        {
74 c362d2a5 taeseongkim
            App.splashScreen.Close();
75
76 787a4489 KangIngu
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
77
            {
78 b9b01f8e ljiyeon
                Owner = Application.Current.MainWindow,
79 0d32593b ljiyeon
                Content = new TextBlock()
80 d33ef543 taeseongkim
                {
81 0d32593b ljiyeon
                    MinWidth = 400,
82
                    FontSize = 12,
83
                    Text = content,
84
                    TextWrapping = System.Windows.TextWrapping.Wrap
85
                },
86 787a4489 KangIngu
                Header = header,
87
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
88
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
89
            };
90
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
91
        }
92 7e2d29a0 ljiyeon
93 787a4489 KangIngu
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
94
        {
95 0c997b99 ljiyeon
            InitializeComponent();
96 d33ef543 taeseongkim
97 ca16abb2 ljiyeon
            //cursor change  
98 902faaea taeseongkim
            this.Cursor = new Cursor(App.DefaultArrowCursorStream);
99 ca16abb2 ljiyeon
100 d33ef543 taeseongkim
            var point = GetScreenCenter();
101
102 c362d2a5 taeseongkim
            //this.Left = point.X;
103
            //this.Top = point.Y;
104 787a4489 KangIngu
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 7e2d29a0 ljiyeon
                //#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 787a4489 KangIngu
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 7e2d29a0 ljiyeon
                //#endif
148 787a4489 KangIngu
            }
149
            else
150
            {
151
                this.dzMainMenu.ServiceOn();
152 992a98b4 KangIngu
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 e0204db0 djkim
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
161
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
162
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
163 992a98b4 KangIngu
                }
164 3d31db34 송근호
165
                try
166
                {
167 ff01c725 humkyung
                    ///this.dzMainMenu.HubSet();
168 3d31db34 송근호
                    this.dzMainMenu.SetView(App.ViewInfo);
169
                }
170 5a6493ad humkyung
                catch (Exception ex)
171 3d31db34 송근호
                {
172 5a6493ad humkyung
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
173 3724d2a2 송근호
174
                    System.Environment.Exit(0);
175 3d31db34 송근호
                }
176 787a4489 KangIngu
            }
177 6707a5c7 ljiyeon
178 787a4489 KangIngu
            //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 40a810fc taeseongkim
            //};0
190 787a4489 KangIngu
191
            //this.dzMainMenu.ServiceOn();
192
            //this.dzMainMenu.SetView(App.ViewInfo);
193
        }
194 6707a5c7 ljiyeon
195 d33ef543 taeseongkim
        private Point GetScreenCenter()
196 787a4489 KangIngu
        {
197 d33ef543 taeseongkim
            Point result = new Point();
198 3933072f ljiyeon
199 d33ef543 taeseongkim
            //first get all the screens 
200
            System.Drawing.Rectangle ret;
201
            int ScreenWidth = 0;
202 787a4489 KangIngu
203 d33ef543 taeseongkim
            var mousePosition = System.Windows.Forms.Cursor.Position;
204 71bfd53e ljiyeon
205 d33ef543 taeseongkim
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
206 71bfd53e ljiyeon
            {
207 d33ef543 taeseongkim
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
208 3933072f ljiyeon
209 d33ef543 taeseongkim
                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 71bfd53e ljiyeon
214 d33ef543 taeseongkim
                    break;
215
                }
216
                else
217
                {
218
                    ScreenWidth += ret.Width;
219 71bfd53e ljiyeon
                }
220
221 d33ef543 taeseongkim
            }
222 71bfd53e ljiyeon
223
224 d33ef543 taeseongkim
            return result;
225 71bfd53e ljiyeon
        }
226
227 d33ef543 taeseongkim
        protected override void OnStateChanged(EventArgs e)
228 71bfd53e ljiyeon
        {
229 d33ef543 taeseongkim
            base.OnStateChanged(e);
230 71bfd53e ljiyeon
        }
231
232 d33ef543 taeseongkim
        protected override void OnClosing(CancelEventArgs e)
233 787a4489 KangIngu
        {
234 d33ef543 taeseongkim
            base.OnClosing(e);
235 787a4489 KangIngu
236 bae83c92 taeseongkim
            if(!ViewerDataModel.Instance.SaveCheck())
237 75f6ff19 taeseongkim
            {
238 c362d2a5 taeseongkim
                var IsConfirm = SaveConfirm();
239
240
                if (IsConfirm == null)
241 75f6ff19 taeseongkim
                {
242
                    e.Cancel = true;
243
                }
244 c362d2a5 taeseongkim
                else if(IsConfirm == true)
245
                { 
246
                    dzTopMenu.SaveEventCallback(null, null);
247
                }
248 75f6ff19 taeseongkim
            }
249 787a4489 KangIngu
250 bae83c92 taeseongkim
            if (App.ViewInfo.CreateFinalPDFPermission)
251
            {
252
                if (!ViewerDataModel.Instance.FinalPDFCheck())
253
                {
254
                    var result = FinalConfirm();
255
256
                    if (result == false)
257
                    {
258
                        e.Cancel = true;
259
                    }
260
                    else
261
                    {
262
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨.");
263
                    }
264
                }
265
            }
266
267 d33ef543 taeseongkim
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
268 9d5b4bc2 taeseongkim
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
269
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
270
            //{
271
            //    CallUpdateProcess(updatecheck.Value);
272
            //}
273 787a4489 KangIngu
        }
274 d33ef543 taeseongkim
275 bae83c92 taeseongkim
276
        private bool? SaveConfirm()
277 264c9309 ljiyeon
        {
278 bae83c92 taeseongkim
            bool? result = null;
279
280
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
281 75f6ff19 taeseongkim
282 bae83c92 taeseongkim
            Closedhandler = (snd, evt) =>
283 32af2c3b djkim
            {
284 bae83c92 taeseongkim
                result = evt.DialogResult;
285
            };
286 264c9309 ljiyeon
287 bae83c92 taeseongkim
            DialogParameters parameters = new DialogParameters()
288
            {
289
                Content = new TextBlock()
290 32af2c3b djkim
                {
291 bae83c92 taeseongkim
                    MinWidth = 300,
292
                    FontSize = 11,
293
                    Text = "Found unsaved comments. Save now?",
294
                    TextWrapping = System.Windows.TextWrapping.Wrap
295
                },
296
297
                Header = "Confirm",
298
                Theme = new VisualStudio2013Theme(),
299
                ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style,
300
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
301
302
                Owner = Application.Current.MainWindow,
303
                Opened = (s, openedEvent) =>
304 32af2c3b djkim
                {
305 bae83c92 taeseongkim
                    RadWindow confirm = s as RadWindow;
306
                    //Button Cancel = confirm.ChildrenOfType<Button>()[5];
307
                    //FocusManager.SetIsFocusScope(confirm, true);
308
                    //FocusManager.SetFocusedElement(confirm, Cancel);
309
                },
310
311
                Closed = Closedhandler
312
            };
313
314
            RadWindow.Confirm(parameters);
315 75f6ff19 taeseongkim
316
            return result;
317 264c9309 ljiyeon
        }
318 75f6ff19 taeseongkim
319 bae83c92 taeseongkim
        private bool? FinalConfirm()
320 32af2c3b djkim
        {
321 bae83c92 taeseongkim
            bool? result = false;
322 75f6ff19 taeseongkim
323
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
324
325
            Closedhandler = (snd, evt) =>
326 32af2c3b djkim
            {
327 c362d2a5 taeseongkim
                result = evt.DialogResult;
328 75f6ff19 taeseongkim
            };
329
330
            DialogParameters parameters = new DialogParameters()
331
            {
332
                Content = new TextBlock()
333
                {
334 c362d2a5 taeseongkim
                    MinWidth = 300,
335 75f6ff19 taeseongkim
                    FontSize = 11,
336 bae83c92 taeseongkim
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
337 75f6ff19 taeseongkim
                    TextWrapping = System.Windows.TextWrapping.Wrap
338
                },
339 c362d2a5 taeseongkim
340 75f6ff19 taeseongkim
                Header = "Confirm",
341
                Theme = new VisualStudio2013Theme(),
342 bae83c92 taeseongkim
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
343 75f6ff19 taeseongkim
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
344 c362d2a5 taeseongkim
345
                Owner = Application.Current.MainWindow,
346
                Opened = (s, openedEvent) =>
347
                {
348
                    RadWindow confirm = s as RadWindow;
349
                },
350
351 75f6ff19 taeseongkim
                Closed = Closedhandler
352
            };
353
354
            RadWindow.Confirm(parameters);
355
356
            return result;
357 32af2c3b djkim
        }
358 d33ef543 taeseongkim
359 32af2c3b djkim
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
360
        {
361
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
362
            {
363
                double bytesIn = double.Parse(e.BytesReceived.ToString());
364
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
365
                double percentage = bytesIn / totalBytes * 100;
366
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
367 d33ef543 taeseongkim
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
368 32af2c3b djkim
            }));
369 310eff8b djkim
        }
370
371
        /// <summary>
372
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
373
        /// false : 업데이트 불필요.
374
        /// true : 업데이트 필요. url 을 같이 Return.
375
        /// </summary>
376
        /// <returns></returns>
377
        private KeyValuePair<bool, string> UpdateCheck()
378 264c9309 ljiyeon
        {
379 310eff8b djkim
            bool isUpdateCheck = false;
380
            string updateurl = string.Empty;
381 264c9309 ljiyeon
            try
382
            {
383 ffddbe4e djkim
                bool is64bit = Environment.Is64BitProcess;
384
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
385
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
386 d33ef543 taeseongkim
387 ffddbe4e djkim
                if (Check_Uri.isUri(updateurl))
388 d33ef543 taeseongkim
                {
389 32af2c3b djkim
                    DialogParameters parameters = new DialogParameters()
390 264c9309 ljiyeon
                    {
391 32af2c3b djkim
                        Owner = Application.Current.MainWindow,
392 97cde7e3 ljiyeon
                        Content = new TextBlock()
393
                        {
394
                            MinWidth = 400,
395
                            FontSize = 11,
396 eeb0a39c taeseongkim
                            Text = "Update is available. \n Update now?",
397 97cde7e3 ljiyeon
                            TextWrapping = System.Windows.TextWrapping.Wrap
398
                        },
399 32af2c3b djkim
                        Header = "Confirm",
400
                        Theme = new VisualStudio2013Theme(),
401 d33ef543 taeseongkim
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
402 32af2c3b djkim
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
403 264c9309 ljiyeon
                        {
404 32af2c3b djkim
                            if (e.DialogResult == true)
405 d33ef543 taeseongkim
                            {
406
                                isUpdateCheck = true;
407 97cde7e3 ljiyeon
                            }
408
                            else
409 32af2c3b djkim
                            {
410 310eff8b djkim
                                isUpdateCheck = false;
411 d33ef543 taeseongkim
                            }
412
                        }
413 32af2c3b djkim
                    };
414 d33ef543 taeseongkim
                    RadWindow.Confirm(parameters);
415
416 264c9309 ljiyeon
                }
417
                else
418
                {
419 310eff8b djkim
                    isUpdateCheck = false;
420 264c9309 ljiyeon
                }
421
            }
422 5a6493ad humkyung
            catch (Exception ex)
423 264c9309 ljiyeon
            {
424 5a6493ad humkyung
                throw ex;
425 310eff8b djkim
            }
426
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
427 264c9309 ljiyeon
        }
428
429 310eff8b djkim
        /// <summary>
430
        /// SmartUpdate 를 호출.
431
        /// </summary>
432
        /// <param name="updateurl">Download 할 설치파일 경로</param>
433
        private void CallUpdateProcess(string updateurl)
434
        {
435
            ProcessStartInfo proInfo = new ProcessStartInfo();
436
            string smartupdaterpath = string.Empty;
437
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
438
            Process.Start(smartupdaterpath, updateurl);
439
        }
440 d04e8ee9 taeseongkim
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
441 32af2c3b djkim
        {
442 264c9309 ljiyeon
            try
443
            {
444 d33ef543 taeseongkim
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
445 d04e8ee9 taeseongkim
446 d33ef543 taeseongkim
                if (progressControl != null)
447 32af2c3b djkim
                {
448
                    progressControl.Close();
449
                    progressControl = null;
450
                }
451 d33ef543 taeseongkim
                if (File.Exists(destfilepath))
452 32af2c3b djkim
                {
453
                    ProcessStartInfo update_msi = new ProcessStartInfo();
454
                    update_msi.FileName = destfilepath;
455
                    Process.Start(update_msi);
456 d33ef543 taeseongkim
                }
457 32af2c3b djkim
                this.Close();
458 264c9309 ljiyeon
            }
459 32af2c3b djkim
            catch (Exception)
460 69ef0800 KangIngu
            {
461 32af2c3b djkim
                throw;
462 69ef0800 KangIngu
            }
463 7e2d29a0 ljiyeon
464
        }
465 787a4489 KangIngu
    }
466
}
클립보드 이미지 추가 (최대 크기: 500 MB)