프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 03960fa5

이력 | 보기 | 이력해설 | 다운로드 (15 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 787a4489 KangIngu
            this.Loaded += MainWindow_Loaded;
51 eeb0a39c taeseongkim
            this.Unloaded += MainWindow_Unloaded;
52 8e6884a5 taeseongkim
            //this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
53 d97dbc7f taeseongkim
            this.Activated += MainWindow_Activated;
54
        }
55
56 9d5b4bc2 taeseongkim
      
57 2007ecaa taeseongkim
58 d97dbc7f taeseongkim
        private void MainWindow_Activated(object sender, EventArgs e)
59
        {
60
            this.Topmost = true;
61 448c5399 taeseongkim
            this.Topmost = false;
62 787a4489 KangIngu
        }
63 ca16abb2 ljiyeon
64 eeb0a39c taeseongkim
        private void MainWindow_Unloaded(object sender, RoutedEventArgs e)
65
        {
66
            //ViewerDataModel.Instance.ImageViewPath.UriSource = null;
67
            //ViewerDataModel.Instance.ImageViewPath_C.UriSource = null;
68
        }
69
70 787a4489 KangIngu
        public void DialogMessage_Alert(string content, string header)
71
        {
72
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
73
            {
74 b9b01f8e ljiyeon
                Owner = Application.Current.MainWindow,
75 0d32593b ljiyeon
                Content = new TextBlock()
76 d33ef543 taeseongkim
                {
77 0d32593b ljiyeon
                    MinWidth = 400,
78
                    FontSize = 12,
79
                    Text = content,
80
                    TextWrapping = System.Windows.TextWrapping.Wrap
81
                },
82 787a4489 KangIngu
                Header = header,
83
                Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(),
84
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
85
            };
86
            Telerik.Windows.Controls.RadWindow.Alert(parameters);
87
        }
88 7e2d29a0 ljiyeon
89 787a4489 KangIngu
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
90
        {
91 0c997b99 ljiyeon
            InitializeComponent();
92 d33ef543 taeseongkim
93 ca16abb2 ljiyeon
            //cursor change  
94 902faaea taeseongkim
            this.Cursor = new Cursor(App.DefaultArrowCursorStream);
95 ca16abb2 ljiyeon
96 d33ef543 taeseongkim
            var point = GetScreenCenter();
97
98
            this.Left = point.X;
99
            this.Top = point.Y;
100 787a4489 KangIngu
101
            ViewerDataModel.Instance.SystemMain = this;
102
103
            if (!App.ParameterMode)
104
            {
105
                //App.ViewInfo = new IKCOM.ViewInfo
106
                //{
107
                //    DocumentItemID = "11111112",
108
                //    //DocumentItemID = "10001",
109
                //    bPartner = false,
110
                //    CreateFinalPDFPermission = true,
111
                //    NewCommentPermission = true,
112
                //    ProjectNO = "000000",
113
                //    UserID = "H2011357",
114
                //    //UserID = "H2009115",
115
                //    //Mode = 0 , 1 , 2
116
                //};
117
                //DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
118
119 7e2d29a0 ljiyeon
                //#if DEBUG
120
                //                App.ViewInfo = new IKCOM.ViewInfo
121
                //                {
122
                //                    DocumentItemID = "11111112",
123
                //                    //DocumentItemID = "10001",
124
                //                    bPartner = false,
125
                //                    CreateFinalPDFPermission = true,
126
                //                    NewCommentPermission = true,
127
                //                    ProjectNO = "000000",
128
                //                    UserID = "H2011357",
129
                //                    //UserID = "H2009115",
130
                //                    //Mode = 0 , 1 , 2
131
                //                };
132
                //                App.ParameterMode = true;
133
                //                this.dzMainMenu.ServiceOn();
134
                //                this.dzMainMenu.SetView(App.ViewInfo);
135
                //#else
136 787a4489 KangIngu
137
                DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내");
138
                this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed;
139
                this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed;
140
                this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed;
141
                this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed;
142
                this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed;
143 7e2d29a0 ljiyeon
                //#endif
144 787a4489 KangIngu
            }
145
            else
146
            {
147
                this.dzMainMenu.ServiceOn();
148 992a98b4 KangIngu
149
                if (!App.ViewInfo.CreateFinalPDFPermission && !App.ViewInfo.NewCommentPermission)
150
                {
151
                    this.dzTopMenu.radRibbonView.HelpButtonVisibility = Visibility.Collapsed;
152
                    var list = this.dzTopMenu.ChildrenOfType<RadRibbonTab>().ToList();
153
                    list.ForEach(item => item.Visibility = Visibility.Collapsed);
154
                    this.dzTopMenu.ribbontab_ReadOnly.Visibility = Visibility.Visible;
155
                    this.dzTopMenu.radRibbonView.SelectedItem = this.dzTopMenu.ribbontab_ReadOnly;
156 e0204db0 djkim
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
157
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
158
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
159 992a98b4 KangIngu
                }
160 3d31db34 송근호
161
                try
162
                {
163 ff01c725 humkyung
                    ///this.dzMainMenu.HubSet();
164 3d31db34 송근호
                    this.dzMainMenu.SetView(App.ViewInfo);
165
                }
166 5a6493ad humkyung
                catch (Exception ex)
167 3d31db34 송근호
                {
168 5a6493ad humkyung
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
169 3724d2a2 송근호
170
                    System.Environment.Exit(0);
171 3d31db34 송근호
                }
172 787a4489 KangIngu
            }
173 6707a5c7 ljiyeon
174 787a4489 KangIngu
            //App.ViewInfo = new IKCOM.ViewInfo
175
            //{
176
            //    DocumentItemID = "11111112",
177
            //    //DocumentItemID = "10001",
178
            //    bPartner = false,
179
            //    CreateFinalPDFPermission = true,
180
            //    NewCommentPermission = true,
181
            //    ProjectNO = "000000",
182
            //    UserID = "H2011357",
183
            //    //UserID = "H2009115",
184
            //    //Mode = 0 , 1 , 2
185 40a810fc taeseongkim
            //};0
186 787a4489 KangIngu
187
            //this.dzMainMenu.ServiceOn();
188
            //this.dzMainMenu.SetView(App.ViewInfo);
189
        }
190 6707a5c7 ljiyeon
191 d33ef543 taeseongkim
        private Point GetScreenCenter()
192 787a4489 KangIngu
        {
193 d33ef543 taeseongkim
            Point result = new Point();
194 3933072f ljiyeon
195 d33ef543 taeseongkim
            //first get all the screens 
196
            System.Drawing.Rectangle ret;
197
            int ScreenWidth = 0;
198 787a4489 KangIngu
199 d33ef543 taeseongkim
            var mousePosition = System.Windows.Forms.Cursor.Position;
200 71bfd53e ljiyeon
201 d33ef543 taeseongkim
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
202 71bfd53e ljiyeon
            {
203 d33ef543 taeseongkim
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
204 3933072f ljiyeon
205 d33ef543 taeseongkim
                if (ret.Contains(mousePosition))
206
                {
207
                    result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2);
208
                    result.Y = (ret.Height / 2 - this.Height / 2);
209 71bfd53e ljiyeon
210 d33ef543 taeseongkim
                    break;
211
                }
212
                else
213
                {
214
                    ScreenWidth += ret.Width;
215 71bfd53e ljiyeon
                }
216
217 d33ef543 taeseongkim
            }
218 71bfd53e ljiyeon
219
220 d33ef543 taeseongkim
            return result;
221 71bfd53e ljiyeon
        }
222
223 d33ef543 taeseongkim
        protected override void OnStateChanged(EventArgs e)
224 71bfd53e ljiyeon
        {
225 d33ef543 taeseongkim
            base.OnStateChanged(e);
226 71bfd53e ljiyeon
        }
227
228 d33ef543 taeseongkim
        protected override void OnClosing(CancelEventArgs e)
229 787a4489 KangIngu
        {
230 d33ef543 taeseongkim
            base.OnClosing(e);
231 787a4489 KangIngu
232 75f6ff19 taeseongkim
            if(!SaveCheck())
233
            {
234
                if(SaveConfirm())
235
                {
236
                    dzTopMenu.SaveEventCallback(null, null);
237
                }
238
                else
239
                {
240
                    e.Cancel = true;
241
                }
242
            }
243 787a4489 KangIngu
244 d33ef543 taeseongkim
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
245 9d5b4bc2 taeseongkim
            //KeyValuePair<bool, string> updatecheck = UpdateCheck();
246
            //if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
247
            //{
248
            //    CallUpdateProcess(updatecheck.Value);
249
            //}
250 787a4489 KangIngu
        }
251 d33ef543 taeseongkim
252 75f6ff19 taeseongkim
        private bool SaveCheck()
253 264c9309 ljiyeon
        {
254 75f6ff19 taeseongkim
            bool result = false;
255
256 32af2c3b djkim
            if (ViewerDataModel.Instance.UndoDataList.Count > 0)
257
            {
258
                DateTime undoTime = ViewerDataModel.Instance.UndoDataList.OrderByDescending(order => order.EventTime).FirstOrDefault().EventTime;
259
                DateTime updatetime = DateTime.Now.AddDays(-1);
260
                if (ViewerDataModel.Instance._markupInfoList.Count > 0)
261
                {
262
                    updatetime = ViewerDataModel.Instance._markupInfoList.OrderByDescending(order => order.UpdateTime).FirstOrDefault().UpdateTime;
263
                }
264 264c9309 ljiyeon
265 32af2c3b djkim
                if (undoTime > updatetime)
266
                {
267 75f6ff19 taeseongkim
                    result = false;
268 32af2c3b djkim
                }
269
                else
270
                {
271 75f6ff19 taeseongkim
                    result = true;
272 d33ef543 taeseongkim
                }
273
            }
274
            else
275 264c9309 ljiyeon
            {
276 75f6ff19 taeseongkim
                result = true;
277 264c9309 ljiyeon
            }
278 75f6ff19 taeseongkim
279
            return result;
280 264c9309 ljiyeon
        }
281 75f6ff19 taeseongkim
282
        private bool SaveConfirm()
283 32af2c3b djkim
        {
284 75f6ff19 taeseongkim
            bool result = false;
285
286
            EventHandler<WindowClosedEventArgs> Closedhandler = null;
287
288
            Closedhandler = (snd, evt) =>
289 32af2c3b djkim
            {
290 75f6ff19 taeseongkim
                result = evt.DialogResult.GetValueOrDefault();
291
            };
292
293
294
            DialogParameters parameters = new DialogParameters()
295
            {
296
                Owner = Application.Current.MainWindow,
297
                Content = new TextBlock()
298
                {
299
                    MinWidth = 400,
300
                    FontSize = 11,
301
                    Text = "Found unsaved comments. Save now?",
302
                    TextWrapping = System.Windows.TextWrapping.Wrap
303
                },
304
                Header = "Confirm",
305
                Theme = new VisualStudio2013Theme(),
306
                ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
307
                Closed = Closedhandler
308
            };
309
310
            RadWindow.Confirm(parameters);
311
312
            return result;
313 32af2c3b djkim
        }
314 d33ef543 taeseongkim
315 32af2c3b djkim
        private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
316
        {
317
            Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate
318
            {
319
                double bytesIn = double.Parse(e.BytesReceived.ToString());
320
                double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
321
                double percentage = bytesIn / totalBytes * 100;
322
                progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %";
323 d33ef543 taeseongkim
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
324 32af2c3b djkim
            }));
325 310eff8b djkim
        }
326
327
        /// <summary>
328
        /// KCOM_API 를 통해 업데이트 URL 을 가져옴.
329
        /// false : 업데이트 불필요.
330
        /// true : 업데이트 필요. url 을 같이 Return.
331
        /// </summary>
332
        /// <returns></returns>
333
        private KeyValuePair<bool, string> UpdateCheck()
334 264c9309 ljiyeon
        {
335 310eff8b djkim
            bool isUpdateCheck = false;
336
            string updateurl = string.Empty;
337 264c9309 ljiyeon
            try
338
            {
339 ffddbe4e djkim
                bool is64bit = Environment.Is64BitProcess;
340
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
341
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
342 d33ef543 taeseongkim
343 ffddbe4e djkim
                if (Check_Uri.isUri(updateurl))
344 d33ef543 taeseongkim
                {
345 32af2c3b djkim
                    DialogParameters parameters = new DialogParameters()
346 264c9309 ljiyeon
                    {
347 32af2c3b djkim
                        Owner = Application.Current.MainWindow,
348 97cde7e3 ljiyeon
                        Content = new TextBlock()
349
                        {
350
                            MinWidth = 400,
351
                            FontSize = 11,
352 eeb0a39c taeseongkim
                            Text = "Update is available. \n Update now?",
353 97cde7e3 ljiyeon
                            TextWrapping = System.Windows.TextWrapping.Wrap
354
                        },
355 32af2c3b djkim
                        Header = "Confirm",
356
                        Theme = new VisualStudio2013Theme(),
357 d33ef543 taeseongkim
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
358 32af2c3b djkim
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
359 264c9309 ljiyeon
                        {
360 32af2c3b djkim
                            if (e.DialogResult == true)
361 d33ef543 taeseongkim
                            {
362
                                isUpdateCheck = true;
363 97cde7e3 ljiyeon
                            }
364
                            else
365 32af2c3b djkim
                            {
366 310eff8b djkim
                                isUpdateCheck = false;
367 d33ef543 taeseongkim
                            }
368
                        }
369 32af2c3b djkim
                    };
370 d33ef543 taeseongkim
                    RadWindow.Confirm(parameters);
371
372 264c9309 ljiyeon
                }
373
                else
374
                {
375 310eff8b djkim
                    isUpdateCheck = false;
376 264c9309 ljiyeon
                }
377
            }
378 5a6493ad humkyung
            catch (Exception ex)
379 264c9309 ljiyeon
            {
380 5a6493ad humkyung
                throw ex;
381 310eff8b djkim
            }
382
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
383 264c9309 ljiyeon
        }
384
385 310eff8b djkim
        /// <summary>
386
        /// SmartUpdate 를 호출.
387
        /// </summary>
388
        /// <param name="updateurl">Download 할 설치파일 경로</param>
389
        private void CallUpdateProcess(string updateurl)
390
        {
391
            ProcessStartInfo proInfo = new ProcessStartInfo();
392
            string smartupdaterpath = string.Empty;
393
            smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe");
394
            Process.Start(smartupdaterpath, updateurl);
395
        }
396 d04e8ee9 taeseongkim
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
397 32af2c3b djkim
        {
398 264c9309 ljiyeon
            try
399
            {
400 d33ef543 taeseongkim
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
401 d04e8ee9 taeseongkim
402 d33ef543 taeseongkim
                if (progressControl != null)
403 32af2c3b djkim
                {
404
                    progressControl.Close();
405
                    progressControl = null;
406
                }
407 d33ef543 taeseongkim
                if (File.Exists(destfilepath))
408 32af2c3b djkim
                {
409
                    ProcessStartInfo update_msi = new ProcessStartInfo();
410
                    update_msi.FileName = destfilepath;
411
                    Process.Start(update_msi);
412 d33ef543 taeseongkim
                }
413 32af2c3b djkim
                this.Close();
414 264c9309 ljiyeon
            }
415 32af2c3b djkim
            catch (Exception)
416 69ef0800 KangIngu
            {
417 32af2c3b djkim
                throw;
418 69ef0800 KangIngu
            }
419 7e2d29a0 ljiyeon
420
        }
421 787a4489 KangIngu
    }
422
}
클립보드 이미지 추가 (최대 크기: 500 MB)