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