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