프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 40a810fc

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