프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (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 e0cfc73c ljiyeon
            App.splashString(ISplashMessage.MAINWINDOW);
50 c362d2a5 taeseongkim
51 787a4489 KangIngu
            this.Loaded += MainWindow_Loaded;
52 eeb0a39c taeseongkim
            this.Unloaded += MainWindow_Unloaded;
53 8e6884a5 taeseongkim
            //this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
54 d97dbc7f taeseongkim
            this.Activated += MainWindow_Activated;
55
        }
56
57 9d5b4bc2 taeseongkim
      
58 2007ecaa taeseongkim
59 d97dbc7f taeseongkim
        private void MainWindow_Activated(object sender, EventArgs e)
60
        {
61
            this.Topmost = true;
62 448c5399 taeseongkim
            this.Topmost = false;
63 787a4489 KangIngu
        }
64 ca16abb2 ljiyeon
65 eeb0a39c taeseongkim
        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 787a4489 KangIngu
        public void DialogMessage_Alert(string content, string header)
72
        {
73 c362d2a5 taeseongkim
            App.splashScreen.Close();
74
75 787a4489 KangIngu
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
76
            {
77 b9b01f8e ljiyeon
                Owner = Application.Current.MainWindow,
78 0d32593b ljiyeon
                Content = new TextBlock()
79 d33ef543 taeseongkim
                {
80 0d32593b ljiyeon
                    MinWidth = 400,
81
                    FontSize = 12,
82
                    Text = content,
83
                    TextWrapping = System.Windows.TextWrapping.Wrap
84
                },
85 787a4489 KangIngu
                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 7e2d29a0 ljiyeon
92 787a4489 KangIngu
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
93
        {
94 0c997b99 ljiyeon
            InitializeComponent();
95 d33ef543 taeseongkim
96 ca16abb2 ljiyeon
            //cursor change  
97 902faaea taeseongkim
            this.Cursor = new Cursor(App.DefaultArrowCursorStream);
98 ca16abb2 ljiyeon
99 d33ef543 taeseongkim
            var point = GetScreenCenter();
100
101 c362d2a5 taeseongkim
            //this.Left = point.X;
102
            //this.Top = point.Y;
103 787a4489 KangIngu
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 7e2d29a0 ljiyeon
                //#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 787a4489 KangIngu
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 7e2d29a0 ljiyeon
                //#endif
147 787a4489 KangIngu
            }
148
            else
149
            {
150
                this.dzMainMenu.ServiceOn();
151 992a98b4 KangIngu
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 e0204db0 djkim
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
160
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
161
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
162 992a98b4 KangIngu
                }
163 3d31db34 송근호
164
                try
165
                {
166 ff01c725 humkyung
                    ///this.dzMainMenu.HubSet();
167 3d31db34 송근호
                    this.dzMainMenu.SetView(App.ViewInfo);
168
                }
169 5a6493ad humkyung
                catch (Exception ex)
170 3d31db34 송근호
                {
171 5a6493ad humkyung
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
172 3724d2a2 송근호
173
                    System.Environment.Exit(0);
174 3d31db34 송근호
                }
175 787a4489 KangIngu
            }
176 6707a5c7 ljiyeon
177 787a4489 KangIngu
            //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 40a810fc taeseongkim
            //};0
189 787a4489 KangIngu
190
            //this.dzMainMenu.ServiceOn();
191
            //this.dzMainMenu.SetView(App.ViewInfo);
192
        }
193 6707a5c7 ljiyeon
194 d33ef543 taeseongkim
        private Point GetScreenCenter()
195 787a4489 KangIngu
        {
196 d33ef543 taeseongkim
            Point result = new Point();
197 3933072f ljiyeon
198 d33ef543 taeseongkim
            //first get all the screens 
199
            System.Drawing.Rectangle ret;
200
            int ScreenWidth = 0;
201 787a4489 KangIngu
202 d33ef543 taeseongkim
            var mousePosition = System.Windows.Forms.Cursor.Position;
203 71bfd53e ljiyeon
204 d33ef543 taeseongkim
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
205 71bfd53e ljiyeon
            {
206 d33ef543 taeseongkim
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
207 3933072f ljiyeon
208 d33ef543 taeseongkim
                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 71bfd53e ljiyeon
213 d33ef543 taeseongkim
                    break;
214
                }
215
                else
216
                {
217
                    ScreenWidth += ret.Width;
218 71bfd53e ljiyeon
                }
219
220 d33ef543 taeseongkim
            }
221 71bfd53e ljiyeon
222
223 d33ef543 taeseongkim
            return result;
224 71bfd53e ljiyeon
        }
225
226 d33ef543 taeseongkim
        protected override void OnStateChanged(EventArgs e)
227 71bfd53e ljiyeon
        {
228 d33ef543 taeseongkim
            base.OnStateChanged(e);
229 71bfd53e ljiyeon
        }
230
231 d33ef543 taeseongkim
        protected override void OnClosing(CancelEventArgs e)
232 787a4489 KangIngu
        {
233 d33ef543 taeseongkim
            base.OnClosing(e);
234 cf1cc862 taeseongkim
            
235 bae83c92 taeseongkim
            if(!ViewerDataModel.Instance.SaveCheck())
236 75f6ff19 taeseongkim
            {
237 c362d2a5 taeseongkim
                var IsConfirm = SaveConfirm();
238
239
                if (IsConfirm == null)
240 75f6ff19 taeseongkim
                {
241
                    e.Cancel = true;
242
                }
243 c362d2a5 taeseongkim
                else if(IsConfirm == true)
244
                { 
245
                    dzTopMenu.SaveEventCallback(null, null);
246
                }
247 75f6ff19 taeseongkim
            }
248 787a4489 KangIngu
249 bae83c92 taeseongkim
            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 d33ef543 taeseongkim
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
267 9d5b4bc2 taeseongkim
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
268
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
269
            //{
270
            //    CallUpdateProcess(updatecheck.Value);
271
            //}
272 787a4489 KangIngu
        }
273 d33ef543 taeseongkim
274 bae83c92 taeseongkim
275
        private bool? SaveConfirm()
276 264c9309 ljiyeon
        {
277 bae83c92 taeseongkim
            bool? result = null;
278
279
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
280 75f6ff19 taeseongkim
281 bae83c92 taeseongkim
            Closedhandler = (snd, evt) =>
282 32af2c3b djkim
            {
283 bae83c92 taeseongkim
                result = evt.DialogResult;
284
            };
285 264c9309 ljiyeon
286 bae83c92 taeseongkim
            DialogParameters parameters = new DialogParameters()
287
            {
288
                Content = new TextBlock()
289 32af2c3b djkim
                {
290 bae83c92 taeseongkim
                    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 32af2c3b djkim
                {
304 bae83c92 taeseongkim
                    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 75f6ff19 taeseongkim
315
            return result;
316 264c9309 ljiyeon
        }
317 75f6ff19 taeseongkim
318 bae83c92 taeseongkim
        private bool? FinalConfirm()
319 32af2c3b djkim
        {
320 bae83c92 taeseongkim
            bool? result = false;
321 75f6ff19 taeseongkim
322
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
323
324
            Closedhandler = (snd, evt) =>
325 32af2c3b djkim
            {
326 c362d2a5 taeseongkim
                result = evt.DialogResult;
327 75f6ff19 taeseongkim
            };
328
329
            DialogParameters parameters = new DialogParameters()
330
            {
331
                Content = new TextBlock()
332
                {
333 c362d2a5 taeseongkim
                    MinWidth = 300,
334 75f6ff19 taeseongkim
                    FontSize = 11,
335 bae83c92 taeseongkim
                    Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?",
336 75f6ff19 taeseongkim
                    TextWrapping = System.Windows.TextWrapping.Wrap
337
                },
338 c362d2a5 taeseongkim
339 75f6ff19 taeseongkim
                Header = "Confirm",
340
                Theme = new VisualStudio2013Theme(),
341 bae83c92 taeseongkim
                ContentStyle = Application.Current.Resources["RadConfirmYNStyle"] as Style,
342 75f6ff19 taeseongkim
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
343 c362d2a5 taeseongkim
344
                Owner = Application.Current.MainWindow,
345
                Opened = (s, openedEvent) =>
346
                {
347
                    RadWindow confirm = s as RadWindow;
348
                },
349
350 75f6ff19 taeseongkim
                Closed = Closedhandler
351
            };
352
353
            RadWindow.Confirm(parameters);
354
355
            return result;
356 32af2c3b djkim
        }
357 d33ef543 taeseongkim
358 32af2c3b djkim
        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 d33ef543 taeseongkim
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
367 32af2c3b djkim
            }));
368 310eff8b djkim
        }
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 264c9309 ljiyeon
        {
378 310eff8b djkim
            bool isUpdateCheck = false;
379
            string updateurl = string.Empty;
380 264c9309 ljiyeon
            try
381
            {
382 ffddbe4e djkim
                bool is64bit = Environment.Is64BitProcess;
383
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
384
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
385 d33ef543 taeseongkim
386 ffddbe4e djkim
                if (Check_Uri.isUri(updateurl))
387 d33ef543 taeseongkim
                {
388 32af2c3b djkim
                    DialogParameters parameters = new DialogParameters()
389 264c9309 ljiyeon
                    {
390 32af2c3b djkim
                        Owner = Application.Current.MainWindow,
391 97cde7e3 ljiyeon
                        Content = new TextBlock()
392
                        {
393
                            MinWidth = 400,
394
                            FontSize = 11,
395 eeb0a39c taeseongkim
                            Text = "Update is available. \n Update now?",
396 97cde7e3 ljiyeon
                            TextWrapping = System.Windows.TextWrapping.Wrap
397
                        },
398 32af2c3b djkim
                        Header = "Confirm",
399
                        Theme = new VisualStudio2013Theme(),
400 d33ef543 taeseongkim
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
401 32af2c3b djkim
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
402 264c9309 ljiyeon
                        {
403 32af2c3b djkim
                            if (e.DialogResult == true)
404 d33ef543 taeseongkim
                            {
405
                                isUpdateCheck = true;
406 97cde7e3 ljiyeon
                            }
407
                            else
408 32af2c3b djkim
                            {
409 310eff8b djkim
                                isUpdateCheck = false;
410 d33ef543 taeseongkim
                            }
411
                        }
412 32af2c3b djkim
                    };
413 d33ef543 taeseongkim
                    RadWindow.Confirm(parameters);
414
415 264c9309 ljiyeon
                }
416
                else
417
                {
418 310eff8b djkim
                    isUpdateCheck = false;
419 264c9309 ljiyeon
                }
420
            }
421 5a6493ad humkyung
            catch (Exception ex)
422 264c9309 ljiyeon
            {
423 5a6493ad humkyung
                throw ex;
424 310eff8b djkim
            }
425
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
426 264c9309 ljiyeon
        }
427
428 310eff8b djkim
        /// <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 d04e8ee9 taeseongkim
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
440 32af2c3b djkim
        {
441 264c9309 ljiyeon
            try
442
            {
443 d33ef543 taeseongkim
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
444 d04e8ee9 taeseongkim
445 d33ef543 taeseongkim
                if (progressControl != null)
446 32af2c3b djkim
                {
447
                    progressControl.Close();
448
                    progressControl = null;
449
                }
450 d33ef543 taeseongkim
                if (File.Exists(destfilepath))
451 32af2c3b djkim
                {
452
                    ProcessStartInfo update_msi = new ProcessStartInfo();
453
                    update_msi.FileName = destfilepath;
454
                    Process.Start(update_msi);
455 d33ef543 taeseongkim
                }
456 32af2c3b djkim
                this.Close();
457 264c9309 ljiyeon
            }
458 32af2c3b djkim
            catch (Exception)
459 69ef0800 KangIngu
            {
460 32af2c3b djkim
                throw;
461 69ef0800 KangIngu
            }
462 7e2d29a0 ljiyeon
463
        }
464 787a4489 KangIngu
    }
465
}
클립보드 이미지 추가 (최대 크기: 500 MB)