프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (14.8 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
        }
54

    
55
        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
        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
        public void DialogMessage_Alert(string content, string header)
70
        {
71
            Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters()
72
            {
73
                Owner = Application.Current.MainWindow,
74
                Content = new TextBlock()
75
                {
76
                    MinWidth = 400,
77
                    FontSize = 12,
78
                    Text = content,
79
                    TextWrapping = System.Windows.TextWrapping.Wrap
80
                },
81
                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

    
88
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
89
        {
90
            InitializeComponent();
91

    
92
            //cursor change  
93
            this.Cursor = new Cursor(CursorChange().StreamSource);
94

    
95
            var point = GetScreenCenter();
96

    
97
            this.Left = point.X;
98
            this.Top = point.Y;
99

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

    
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
                //#endif
143
            }
144
            else
145
            {
146
                this.dzMainMenu.ServiceOn();
147

    
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
                    //this.dzMainMenu.SymbolPane.Visibility = Visibility.Collapsed;
156
                    //this.dzMainMenu.FavoritePane.Visibility = Visibility.Collapsed;
157
                    //this.dzMainMenu.drawingRotateCanvas.IsHitTestVisible = false;
158
                }
159

    
160
                try
161
                {
162
                    ///this.dzMainMenu.HubSet();
163
                    this.dzMainMenu.SetView(App.ViewInfo);
164
                }
165
                catch (Exception ex)
166
                {
167
                    MessageBox.Show(string.Format("웹 서비스 접속시 에러가 발생했습니다.\n{0}", ex.StackTrace));
168

    
169
                    System.Environment.Exit(0);
170
                }
171
            }
172

    
173
            //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
            //};0
185

    
186
            //this.dzMainMenu.ServiceOn();
187
            //this.dzMainMenu.SetView(App.ViewInfo);
188
        }
189

    
190
        private Point GetScreenCenter()
191
        {
192
            Point result = new Point();
193

    
194
            //first get all the screens 
195
            System.Drawing.Rectangle ret;
196
            int ScreenWidth = 0;
197

    
198
            var mousePosition = System.Windows.Forms.Cursor.Position;
199

    
200
            for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++)
201
            {
202
                ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds;
203

    
204
                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

    
209
                    break;
210
                }
211
                else
212
                {
213
                    ScreenWidth += ret.Width;
214
                }
215

    
216
            }
217

    
218

    
219
            return result;
220
        }
221

    
222
        protected override void OnStateChanged(EventArgs e)
223
        {
224
            base.OnStateChanged(e);
225
        }
226

    
227
        protected override void OnClosing(CancelEventArgs e)
228
        {
229
            base.OnClosing(e);
230

    
231
            SaveCheck();
232

    
233
            //Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행.
234
            KeyValuePair<bool, string> updatecheck = UpdateCheck();
235
            if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value))
236
            {
237
                CallUpdateProcess(updatecheck.Value);
238
            }
239
        }
240

    
241
        private void SaveCheck()
242
        {
243
            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

    
252
                if (undoTime > updatetime)
253
                {
254
                    DialogParameters parameters = new DialogParameters()
255
                    {
256
                        Owner = Application.Current.MainWindow,
257
                        Content = new TextBlock()
258
                        {
259
                            MinWidth = 400,
260
                            FontSize = 11,
261
                            Text = "Found unsaved comments. Save now?",
262
                            TextWrapping = System.Windows.TextWrapping.Wrap
263
                        },
264
                        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
                }
275
            }
276
            else
277
            {
278
                isSaveCheck = true;
279
            }
280
        }
281
        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

    
290
        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
                progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString());
299
            }));
300
        }
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
        {
310
            bool isUpdateCheck = false;
311
            string updateurl = string.Empty;
312
            try
313
            {
314
                bool is64bit = Environment.Is64BitProcess;
315
                string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
316
                updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion);
317

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

    
347
                }
348
                else
349
                {
350
                    isUpdateCheck = false;
351
                }
352
            }
353
            catch (Exception ex)
354
            {
355
                throw ex;
356
            }
357
            return new KeyValuePair<bool, string>(isUpdateCheck, updateurl);
358
        }
359

    
360
        /// <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
        private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
372
        {
373
            try
374
            {
375
                await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed");
376

    
377
                if (progressControl != null)
378
                {
379
                    progressControl.Close();
380
                    progressControl = null;
381
                }
382
                if (File.Exists(destfilepath))
383
                {
384
                    ProcessStartInfo update_msi = new ProcessStartInfo();
385
                    update_msi.FileName = destfilepath;
386
                    Process.Start(update_msi);
387
                }
388
                this.Close();
389
            }
390
            catch (Exception)
391
            {
392
                throw;
393
            }
394

    
395
        }
396
    }
397
}
클립보드 이미지 추가 (최대 크기: 500 MB)