markus / KCOM / MainWindow.xaml.cs @ 41e3c8ac
이력 | 보기 | 이력해설 | 다운로드 (18.5 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 : KCOM.Controls.CustomizedWindow.CustomWindow |
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 |
|
51 |
this.Loaded += MainWindow_Loaded; |
52 |
this.Unloaded += MainWindow_Unloaded; |
53 |
//this.PreviewKeyDown += new KeyEventHandler(KeyEventDownAction); |
54 |
this.Activated += MainWindow_Activated; |
55 |
} |
56 |
|
57 |
|
58 |
|
59 |
private void MainWindow_Activated(object sender, EventArgs e) |
60 |
{ |
61 |
this.Topmost = true; |
62 |
this.Topmost = false; |
63 |
} |
64 |
|
65 |
private void MainWindow_Unloaded(object sender, RoutedEventArgs e) |
66 |
{ |
67 |
} |
68 |
|
69 |
public void DialogMessage_Alert(string content, string header) |
70 |
{ |
71 |
App.splashScreen.Close(); |
72 |
|
73 |
Telerik.Windows.Controls.DialogParameters parameters = new Telerik.Windows.Controls.DialogParameters() |
74 |
{ |
75 |
Owner = Application.Current.MainWindow, |
76 |
Content = new TextBlock() |
77 |
{ |
78 |
MinWidth = 400, |
79 |
FontSize = 12, |
80 |
Text = content, |
81 |
TextWrapping = System.Windows.TextWrapping.Wrap |
82 |
}, |
83 |
Header = header, |
84 |
Theme = new Telerik.Windows.Controls.VisualStudio2013Theme(), |
85 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
86 |
}; |
87 |
Telerik.Windows.Controls.RadWindow.Alert(parameters); |
88 |
} |
89 |
|
90 |
private void MainWindow_Loaded(object sender, RoutedEventArgs e) |
91 |
{ |
92 |
InitializeComponent(); |
93 |
//Loaded 이벤트에서 MaxHeight를 설정 모니터가 1개일때만 |
94 |
//MaxHeight = SystemParameters.WorkArea.Height; |
95 |
//LocationChanged : 모니터가 2개 이상이고, 모니터의 해상도가 다를 때에 설정 |
96 |
//20240610 LJY 화면 넘어갈때 이슈로 주석 |
97 |
//this.LocationChanged += Window_LocationChanged; |
98 |
//cursor change |
99 |
this.Cursor = new Cursor(App.DefaultArrowCursorStream); |
100 |
|
101 |
var point = GetScreenCenter(); |
102 |
|
103 |
//this.Left = point.X; |
104 |
//this.Top = point.Y; |
105 |
|
106 |
ViewerDataModel.Instance.SystemMain = this; |
107 |
|
108 |
if (!App.ParameterMode) |
109 |
{ |
110 |
//App.ViewInfo = new IKCOM.ViewInfo |
111 |
//{ |
112 |
// DocumentItemID = "11111112", |
113 |
// //DocumentItemID = "10001", |
114 |
// bPartner = false, |
115 |
// CreateFinalPDFPermission = true, |
116 |
// NewCommentPermission = true, |
117 |
// ProjectNO = "000000", |
118 |
// UserID = "H2011357", |
119 |
// //UserID = "H2009115", |
120 |
// //Mode = 0 , 1 , 2 |
121 |
//}; |
122 |
//DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
123 |
|
124 |
//#if DEBUG |
125 |
// App.ViewInfo = new IKCOM.ViewInfo |
126 |
// { |
127 |
// DocumentItemID = "11111112", |
128 |
// //DocumentItemID = "10001", |
129 |
// bPartner = false, |
130 |
// CreateFinalPDFPermission = true, |
131 |
// NewCommentPermission = true, |
132 |
// ProjectNO = "000000", |
133 |
// UserID = "H2011357", |
134 |
// //UserID = "H2009115", |
135 |
// //Mode = 0 , 1 , 2 |
136 |
// }; |
137 |
// App.ParameterMode = true; |
138 |
// this.dzMainMenu.ServiceOn(); |
139 |
// this.dzMainMenu.SetView(App.ViewInfo); |
140 |
//#else |
141 |
|
142 |
DialogMessage_Alert("데모버전은 단독 실행모드를 지원하지 않습니다", "안내"); |
143 |
this.dzMainMenu.pageNavigator.Visibility = Visibility.Collapsed; |
144 |
this.dzMainMenu.historyPane.Visibility = Visibility.Collapsed; |
145 |
this.dzMainMenu.infoListPane.Visibility = Visibility.Collapsed; |
146 |
this.dzMainMenu.searchPane.Visibility = Visibility.Collapsed; |
147 |
this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed; |
148 |
//#endif |
149 |
} |
150 |
else |
151 |
{ |
152 |
this.dzMainMenu.talkPane.Visibility = Visibility.Collapsed; |
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 |
/// <summary> |
181 |
/// 멤버 변수로 현 사용자의 모든 모니터들의 상태를 가져온다. |
182 |
/// Window의 LocationChanged Event를 통해 Window가 이동할 때마다 어떤 모니터에 있는지를 확인 |
183 |
/// Window가 어떤 모니터에 있는지의 기준은 각 Window의 중앙 부분 |
184 |
/// Sum 은 모니터들의 왼쪽 끝 부터 오른쪽 끝까지의 합 |
185 |
/// 현재 Window의 중앙은 Left 값 + Width의 반 |
186 |
/// um보다 작다면 현재 더하게 된 Screen 안에 있다는 뜻이므로 현재 더한 item의 WorkingArea의 Height를MaxHeight로 설정 |
187 |
/// </summary> |
188 |
System.Windows.Forms.Screen[] screens = System.Windows.Forms.Screen.AllScreens; |
189 |
private void Window_LocationChanged(object sender, EventArgs e) |
190 |
{ |
191 |
int sum = 0; |
192 |
foreach (var item in screens) |
193 |
{ |
194 |
sum += item.WorkingArea.Width; |
195 |
if (sum >= this.Left + this.Width / 2) |
196 |
{ |
197 |
this.MaxHeight = item.WorkingArea.Height; |
198 |
this.MaxWidth = item.WorkingArea.Width; |
199 |
if (this.Left < 0) |
200 |
{ |
201 |
this.Left = 0; |
202 |
} |
203 |
|
204 |
if (this.Top < 0) |
205 |
{ |
206 |
this.Top = 0; |
207 |
} |
208 |
// if(this.Tag.Equals("Normal")) |
209 |
//{ |
210 |
// this.WindowState = WindowState.Normal; |
211 |
// this.CustomState = WindowState.Maximized; |
212 |
//} |
213 |
//if (this.CustomState == WindowState.Maximized) |
214 |
//{ |
215 |
// this.WindowState = WindowState.Normal; |
216 |
// this.CustomState = WindowState.Normal; |
217 |
|
218 |
|
219 |
//} |
220 |
//else |
221 |
//{ |
222 |
// this.WindowState = WindowState.Normal; |
223 |
// this.CustomState = WindowState.Maximized; |
224 |
// this.NomalWindowArea = new Rect(this.Left, this.Top, this.Width, this.Height); |
225 |
|
226 |
//} |
227 |
break; |
228 |
} |
229 |
} |
230 |
} |
231 |
|
232 |
private Point GetScreenCenter() |
233 |
{ |
234 |
Point result = new Point(); |
235 |
|
236 |
//first get all the screens |
237 |
System.Drawing.Rectangle ret; |
238 |
int ScreenWidth = 0; |
239 |
|
240 |
var mousePosition = System.Windows.Forms.Cursor.Position; |
241 |
|
242 |
for (int i = 1; i <= System.Windows.Forms.Screen.AllScreens.Count(); i++) |
243 |
{ |
244 |
ret = System.Windows.Forms.Screen.AllScreens[i - 1].Bounds; |
245 |
|
246 |
if (ret.Contains(mousePosition)) |
247 |
{ |
248 |
result.X = ScreenWidth + (ret.Width / 2 - this.Width / 2); |
249 |
result.Y = (ret.Height / 2 - this.Height / 2); |
250 |
|
251 |
break; |
252 |
} |
253 |
else |
254 |
{ |
255 |
ScreenWidth += ret.Width; |
256 |
} |
257 |
|
258 |
} |
259 |
|
260 |
|
261 |
return result; |
262 |
} |
263 |
|
264 |
protected override void OnStateChanged(EventArgs e) |
265 |
{ |
266 |
base.OnStateChanged(e); |
267 |
} |
268 |
|
269 |
protected override void OnClosing(CancelEventArgs e) |
270 |
{ |
271 |
base.OnClosing(e); |
272 |
|
273 |
if(!ViewerDataModel.Instance.SaveCheck()) |
274 |
{ |
275 |
var IsConfirm = SaveConfirm(); |
276 |
|
277 |
if (IsConfirm == null) |
278 |
{ |
279 |
e.Cancel = true; |
280 |
} |
281 |
else if(IsConfirm == true) |
282 |
{ |
283 |
dzTopMenu.SaveEventCallback(null, null); |
284 |
} |
285 |
} |
286 |
|
287 |
if (App.ViewInfo.CreateFinalPDFPermission) |
288 |
{ |
289 |
if (!ViewerDataModel.Instance.FinalPDFCheck()) |
290 |
{ |
291 |
var result = FinalConfirm(); |
292 |
|
293 |
if(result == null) |
294 |
e.Cancel = true; |
295 |
|
296 |
if (result == false) |
297 |
{ |
298 |
e.Cancel = true; |
299 |
} |
300 |
else |
301 |
{ |
302 |
//Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.SaveLog(App.ViewInfo.ProjectNO, App.ViewInfo.DocumentItemID, "최종 Merged PDF 안됨."); |
303 |
} |
304 |
} |
305 |
} |
306 |
|
307 |
//Update Check 를 통해 update url 을 Get 하고 결과값이 있을 경우에는 SmartUpdater 실행. |
308 |
//KeyValuePair<bool, string> updatecheck = UpdateCheck(); |
309 |
//if (updatecheck.Key && !string.IsNullOrEmpty(updatecheck.Value)) |
310 |
//{ |
311 |
// CallUpdateProcess(updatecheck.Value); |
312 |
//} |
313 |
} |
314 |
|
315 |
|
316 |
private bool? SaveConfirm() |
317 |
{ |
318 |
bool? result = null; |
319 |
|
320 |
EventHandler<WindowClosedEventArgs> Closedhandler = null; |
321 |
|
322 |
Closedhandler = (snd, evt) => |
323 |
{ |
324 |
result = evt.DialogResult; |
325 |
}; |
326 |
|
327 |
DialogParameters parameters = new DialogParameters() |
328 |
{ |
329 |
Content = new TextBlock() |
330 |
{ |
331 |
MinWidth = 300, |
332 |
FontSize = 11, |
333 |
Text = "Found unsaved comments. Save now?", |
334 |
TextWrapping = System.Windows.TextWrapping.Wrap |
335 |
}, |
336 |
|
337 |
Header = "Confirm", |
338 |
Theme = new VisualStudio2013Theme(), |
339 |
ContentStyle = Application.Current.Resources["RadConfirmYNCStyle"] as Style, |
340 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
341 |
|
342 |
Owner = Application.Current.MainWindow, |
343 |
Opened = (s, openedEvent) => |
344 |
{ |
345 |
RadWindow confirm = s as RadWindow; |
346 |
//Button Cancel = confirm.ChildrenOfType<Button>()[5]; |
347 |
//FocusManager.SetIsFocusScope(confirm, true); |
348 |
//FocusManager.SetFocusedElement(confirm, Cancel); |
349 |
}, |
350 |
|
351 |
Closed = Closedhandler |
352 |
}; |
353 |
|
354 |
RadWindow.Confirm(parameters); |
355 |
|
356 |
return result; |
357 |
} |
358 |
|
359 |
private bool? FinalConfirm() |
360 |
{ |
361 |
bool? result = false; |
362 |
|
363 |
EventHandler<WindowClosedEventArgs> Closedhandler = null; |
364 |
|
365 |
Closedhandler = (snd, evt) => |
366 |
{ |
367 |
result = evt.DialogResult; |
368 |
}; |
369 |
|
370 |
DialogParameters parameters = new DialogParameters() |
371 |
{ |
372 |
Content = new TextBlock() |
373 |
{ |
374 |
MinWidth = 300, |
375 |
FontSize = 11, |
376 |
Text = "Merged PDF가 수행되지 않았습니다. 창을 닫으시겠습니까?", |
377 |
TextWrapping = System.Windows.TextWrapping.Wrap |
378 |
}, |
379 |
|
380 |
Header = "Confirm", |
381 |
Theme = new VisualStudio2013Theme(), |
382 |
ContentStyle = Application.Current.Resources["RadConfirmYCStyle"] as Style, |
383 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
384 |
|
385 |
Owner = Application.Current.MainWindow, |
386 |
Opened = (s, openedEvent) => |
387 |
{ |
388 |
RadWindow confirm = s as RadWindow; |
389 |
}, |
390 |
|
391 |
Closed = Closedhandler |
392 |
}; |
393 |
|
394 |
RadWindow.Confirm(parameters); |
395 |
|
396 |
return result; |
397 |
} |
398 |
|
399 |
private void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) |
400 |
{ |
401 |
Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate |
402 |
{ |
403 |
double bytesIn = double.Parse(e.BytesReceived.ToString()); |
404 |
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); |
405 |
double percentage = bytesIn / totalBytes * 100; |
406 |
progressControl.splashText.Text = "Download : " + Math.Truncate(percentage).ToString() + " %"; |
407 |
progressControl.progressBar.Value = int.Parse(Math.Truncate(percentage).ToString()); |
408 |
})); |
409 |
} |
410 |
|
411 |
/// <summary> |
412 |
/// KCOM_API 를 통해 업데이트 URL 을 가져옴. |
413 |
/// false : 업데이트 불필요. |
414 |
/// true : 업데이트 필요. url 을 같이 Return. |
415 |
/// </summary> |
416 |
/// <returns></returns> |
417 |
private KeyValuePair<bool, string> UpdateCheck() |
418 |
{ |
419 |
bool isUpdateCheck = false; |
420 |
string updateurl = string.Empty; |
421 |
try |
422 |
{ |
423 |
bool is64bit = Environment.Is64BitProcess; |
424 |
string clientversion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); |
425 |
updateurl = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.BaseClient.GetVersionData(is64bit, clientversion); |
426 |
|
427 |
if (Check_Uri.isUri(updateurl)) |
428 |
{ |
429 |
DialogParameters parameters = new DialogParameters() |
430 |
{ |
431 |
Owner = Application.Current.MainWindow, |
432 |
Content = new TextBlock() |
433 |
{ |
434 |
MinWidth = 400, |
435 |
FontSize = 11, |
436 |
Text = "Update is available. \n Update now?", |
437 |
TextWrapping = System.Windows.TextWrapping.Wrap |
438 |
}, |
439 |
Header = "Confirm", |
440 |
Theme = new VisualStudio2013Theme(), |
441 |
ModalBackground = new SolidColorBrush { Color = Colors.Black, Opacity = 0.6 }, |
442 |
Closed = delegate (object windowSender, WindowClosedEventArgs e) |
443 |
{ |
444 |
if (e.DialogResult == true) |
445 |
{ |
446 |
isUpdateCheck = true; |
447 |
} |
448 |
else |
449 |
{ |
450 |
isUpdateCheck = false; |
451 |
} |
452 |
} |
453 |
}; |
454 |
RadWindow.Confirm(parameters); |
455 |
|
456 |
} |
457 |
else |
458 |
{ |
459 |
isUpdateCheck = false; |
460 |
} |
461 |
} |
462 |
catch (Exception ex) |
463 |
{ |
464 |
throw ex; |
465 |
} |
466 |
return new KeyValuePair<bool, string>(isUpdateCheck, updateurl); |
467 |
} |
468 |
|
469 |
/// <summary> |
470 |
/// SmartUpdate 를 호출. |
471 |
/// </summary> |
472 |
/// <param name="updateurl">Download 할 설치파일 경로</param> |
473 |
private void CallUpdateProcess(string updateurl) |
474 |
{ |
475 |
ProcessStartInfo proInfo = new ProcessStartInfo(); |
476 |
string smartupdaterpath = string.Empty; |
477 |
smartupdaterpath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SmartUpdate.exe"); |
478 |
Process.Start(smartupdaterpath, updateurl); |
479 |
} |
480 |
private async void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) |
481 |
{ |
482 |
try |
483 |
{ |
484 |
await Dispatcher.InvokeAsync(() => progressControl.splashText.Text = "Download Completed"); |
485 |
|
486 |
if (progressControl != null) |
487 |
{ |
488 |
progressControl.Close(); |
489 |
progressControl = null; |
490 |
} |
491 |
if (File.Exists(destfilepath)) |
492 |
{ |
493 |
ProcessStartInfo update_msi = new ProcessStartInfo(); |
494 |
update_msi.FileName = destfilepath; |
495 |
Process.Start(update_msi); |
496 |
} |
497 |
this.Close(); |
498 |
} |
499 |
catch (Exception) |
500 |
{ |
501 |
throw; |
502 |
} |
503 |
|
504 |
} |
505 |
} |
506 |
} |