프로젝트

일반

사용자정보

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

markus / KCOM / MainWindow.xaml.cs @ 27cf69cd

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

1
using KCOM.Common;
2
using KCOM.Controls;
3
using KCOM.Views;
4
using KCOMDataModel;
5
using KCOMDataModel.DataModel;
6
using MarkupToPDF.Common;
7
using MarkupToPDF.Controls.Parsing;
8
using MarkupToPDF.Serialize.Core;
9
using MarkupToPDF.Serialize.S_Control;
10
using System;
11
using System.Collections.Generic;
12
using System.ComponentModel;
13
using System.Diagnostics;
14
using System.IO;
15
using System.Linq;
16
using System.Net;
17
using System.Reflection;
18
using System.Runtime.InteropServices;
19
using System.Text;
20
using System.Threading;
21
using System.Threading.Tasks;
22
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
using System.Xml;
32
using Telerik.Windows.Controls;
33
using WinInterop = System.Windows.Interop;
34

    
35
namespace KCOM
36
{
37
    /// <summary>
38
    /// MainWindow.xaml에 대한 상호 작용 논리
39
    /// </summary>
40
    public partial class MainWindow : Window
41
    {
42
        bool isSaveCheck = false;
43

    
44
        ProgressControl progressControl = null;
45
        string destfilepath = string.Empty;
46

    
47
        public MainWindow()
48
        {
49
            App.splashString(ISplashMessage.MAINWINDOW);
50
            this.Loaded += MainWindow_Loaded;
51
            this.Unloaded += MainWindow_Unloaded;
52
            this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction);
53
            this.Activated += MainWindow_Activated;
54
        }
55

    
56
        private void MainWindow_Activated(object sender, EventArgs e)
57
        {
58
            this.Topmost = true;
59
            this.Topmost = false;
60
        }
61

    
62
        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
        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
        public void DialogMessage_Alert(string content, string header)
77
        {
78
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
79
            {
80
                Owner = Application.Current.MainWindow,
81
                Content = new TextBlock()
82
                {
83
                    MinWidth = 400,
84
                    FontSize = 12,
85
                    Text = content,
86
                    TextWrapping = System.Windows.TextWrapping.Wrap
87
                },
88
                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

    
95
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
96
        {
97
            InitializeComponent();
98

    
99
            //cursor change  
100
            this.Cursor = new Cursor(CursorChange().StreamSource);
101

    
102
            var point = GetScreenCenter();
103

    
104
            this.Left = point.X;
105
            this.Top = point.Y;
106

    
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
                //#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

    
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
                //#endif
150
            }
151
            else
152
            {
153
                this.dzMainMenu.ServiceOn();
154

    
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
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
163
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
164
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
165
                }
166

    
167
                try
168
                {
169
                    ///this.dzMainMenu.HubSet();
170
                    this.dzMainMenu.SetView(App.ViewInfo);
171
                }
172
                catch (Exception ex)
173
                {
174
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
175

    
176
                    System.Environment.Exit(0);
177
                }
178
            }
179

    
180
            //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
            //};0
192

    
193
            //this.dzMainMenu.ServiceOn();
194
            //this.dzMainMenu.SetView(App.ViewInfo);
195
        }
196

    
197
        private Point GetScreenCenter()
198
        {
199
            Point result = new Point();
200

    
201
            //first get all the screens 
202
            System.Drawing.Rectangle ret;
203
            int ScreenWidth = 0;
204

    
205
            var mousePosition = System.Windows.Forms.Cursor.Position;
206

    
207
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
208
            {
209
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
210

    
211
                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

    
216
                    break;
217
                }
218
                else
219
                {
220
                    ScreenWidth += ret.Width;
221
                }
222

    
223
            }
224

    
225

    
226
            return result;
227
        }
228

    
229
        protected override void OnStateChanged(EventArgs e)
230
        {
231
            base.OnStateChanged(e);
232
        }
233

    
234
        protected override void OnClosing(CancelEventArgs e)
235
        {
236
            base.OnClosing(e);
237

    
238
            SaveCheck();
239

    
240
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
241
            KeyValuePair<bool, string> updatecheck = UpdateCheck();
242
            if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
243
            {
244
                CallUpdateProcess(updatecheck.Value);
245
            }
246
        }
247

    
248
        private void SaveCheck()
249
        {
250
            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

    
259
                if (undoTime > updatetime)
260
                {
261
                    DialogParameters parameters = new DialogParameters()
262
                    {
263
                        Owner = Application.Current.MainWindow,
264
                        Content = new TextBlock()
265
                        {
266
                            MinWidth = 400,
267
                            FontSize = 11,
268
                            Text = "Found unsaved comments. Save now?",
269
                            TextWrapping = System.Windows.TextWrapping.Wrap
270
                        },
271
                        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
                }
282
            }
283
            else
284
            {
285
                isSaveCheck = true;
286
            }
287
        }
288
        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

    
297
        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
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
306
            }));
307
        }
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
        {
317
            bool isUpdateCheck = false;
318
            string updateurl = string.Empty;
319
            try
320
            {
321
                bool is64bit = Environment.Is64BitProcess;
322
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
323
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
324

    
325
                if (Check_Uri.isUri(updateurl))
326
                {
327
                    DialogParameters parameters = new DialogParameters()
328
                    {
329
                        Owner = Application.Current.MainWindow,
330
                        Content = new TextBlock()
331
                        {
332
                            MinWidth = 400,
333
                            FontSize = 11,
334
                            Text = "Update is available. \n Update now?",
335
                            TextWrapping = System.Windows.TextWrapping.Wrap
336
                        },
337
                        Header = "Confirm",
338
                        Theme = new VisualStudio2013Theme(),
339
                        ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 },
340
                        Closed = delegate (object windowSender, WindowClosedEventArgs e)
341
                        {
342
                            if (e.DialogResult == true)
343
                            {
344
                                isUpdateCheck = true;
345
                            }
346
                            else
347
                            {
348
                                isUpdateCheck = false;
349
                            }
350
                        }
351
                    };
352
                    RadWindow.Confirm(parameters);
353

    
354
                }
355
                else
356
                {
357
                    isUpdateCheck = false;
358
                }
359
            }
360
            catch (Exception ex)
361
            {
362
                throw ex;
363
            }
364
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
365
        }
366

    
367
        /// <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
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
379
        {
380
            try
381
            {
382
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
383

    
384
                if (progressControl != null)
385
                {
386
                    progressControl.Close();
387
                    progressControl = null;
388
                }
389
                if (File.Exists(destfilepath))
390
                {
391
                    ProcessStartInfo update_msi = new ProcessStartInfo();
392
                    update_msi.FileName = destfilepath;
393
                    Process.Start(update_msi);
394
                }
395
                this.Close();
396
            }
397
            catch (Exception)
398
            {
399
                throw;
400
            }
401

    
402
        }
403
    }
404
}
클립보드 이미지 추가 (최대 크기: 500 MB)