프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 315ae55e

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