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