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