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