-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeetingRoom.xaml.cs
946 lines (803 loc) · 42 KB
/
MeetingRoom.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
using Newtonsoft.Json;
using PaperLess_Emeeting.App_Code;
using PaperLess_Emeeting.App_Code.ClickOnce;
using PaperLess_Emeeting.App_Code.DownloadItem;
using PaperLess_Emeeting.App_Code.MessageBox;
using PaperLess_Emeeting.App_Code.WS;
using PaperLess_ViewModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Xml;
namespace PaperLess_Emeeting
{
/// <summary>
/// MeetingRoom.xaml 的互動邏輯
/// </summary>
public partial class MeetingRoom : UserControl
{
public event Home_Change2MeetingDataCT_Function Home_Change2MeetingDataCT_Event;
public UserMeeting userMeeting { get; set; }
MeetingRoomButtonType meetingRoomButtonType;
public string NewAddMeetingID = "";
public bool invisible = false;
MeetingRoom_DownloadFileStart_Function Start_callback;
MeetingRoom_DownloadProgressChanged_Function Progress_callback;
MeetingRoom_DownloadFileToErrorCompleted_Function ErrorFinish_callback;
int TotalFiles = 0;
int FinishedFiles = 0;
int FinishedPercent = 0;
public string UserID { get; set; }
public string UserPWD { get; set; }
public DispatcherTimer ajaxTimer = null;
public bool ForceStopAjaxLoader = false;
public bool HasReceiveStart_callback = false;
//預載會議資料
public MeetingData PreLoadMeetingData = null;
public int CacheMinuteTTL = 0;
public Thread CacheThread = null;
public MeetingRoom(string UserID, string UserPWD, UserMeeting userMeeting, Home_Change2MeetingDataCT_Function callback, string NewAddMeetingID = "", bool invisible = false)
{
//MouseTool.ShowLoading();
InitializeComponent();
this.UserID = UserID;
this.UserPWD = UserPWD;
this.userMeeting = userMeeting;
this.Home_Change2MeetingDataCT_Event += callback;
this.NewAddMeetingID = NewAddMeetingID;
this.invisible = invisible;
//先判斷是從系列會議到底是否隱藏(1)
if (this.invisible == true)
{
this.Visibility = Visibility.Collapsed;
}
this.Loaded +=MeetingRoom_Loaded;
this.Unloaded +=MeetingRoom_Unloaded;
this.CacheMinuteTTL = PaperLess_Emeeting.Properties.Settings.Default.CacheMinuteTTL;
//MouseTool.ShowArrow();
}
private void MeetingRoom_Loaded(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
InitSelectDB();
// 這裡為 日期列表畫面 下的 會議房間畫面,優先權設定為Background => 列舉值為 4。 所有其他非閒置作業都完成之後,就會處理作業。
//this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() =>
this.Dispatcher.BeginInvoke(new Action(() =>
{
InitUI();
// 有下載UI相關的把事件放到主線成
InitEvent();
}));
// 正在開會議的會議
//if (DateTime.Parse(userMeeting.BeginTime) <= DateTime.Now && DateTime.Now < DateTime.Parse(userMeeting.EndTime))
if (DateTool.IsSameDate(DateTime.Parse(userMeeting.BeginTime),DateTime.Now))
{
//預載會議資料
PreLoadMeeting();
}
});
}
//預載會議資料
private void PreLoadMeeting()
{
//小於0為沒有Cache
//等於0為Cache不會過期
//大於0為多少分鐘後清掉Cache
if (this.CacheMinuteTTL >= 0)
{
Task.Factory.StartNew(() =>
{
GetMeetingData.AsyncPOST(userMeeting.ID, UserID, UserPWD, (md) =>
{
try
{
PreLoadMeetingData = md;
//[過時]因為CacheMinuteTTL是以分鐘為計算,如果是以秒鐘為計算的話
//[過時]最好放在上面的AsyncPOST裡面
//已改為放在AsyncPOST裡
if (this.CacheMinuteTTL > 0)
{
if (CacheThread != null)
CacheThread.Abort();
CacheThread = new Thread(delegate()
{
Thread.Sleep(this.CacheMinuteTTL * 60 * 1000);
PreLoadMeetingData = null;
});
CacheThread.IsBackground = true;
CacheThread.Start();
}
}
catch (Exception ex)
{
LogTool.Debug(ex);
}
});
});
}
}
private void MeetingRoom_Unloaded(object sender, RoutedEventArgs e)
{
Singleton_FileDownloader.GetInstance(userMeeting.ID).ClearMeetingRoomEvent();
}
private void InitSelectDB()
{
DataTable dt = MSCE.GetDataTable(@"select count(ID) as TotalFiles from FileRow where UserID =@1 and MeetingID=@2;"
,UserID,userMeeting.ID);
if (dt.Rows.Count > 0)
int.TryParse(dt.Rows[0]["TotalFiles"].ToString(), out TotalFiles);
FinishedPercent=GetFinishedPercent();
if (userMeeting.isDownload != null && userMeeting.isBrowserd != null)
Enum.TryParse(userMeeting.isDownload + userMeeting.isBrowserd, out meetingRoomButtonType);
else
meetingRoomButtonType = MeetingRoomButtonType.YY;
//DataTable dt = MSCE.GetDataTable("select NewAddMeetingID from NowLogin");
//if (dt.Rows.Count > 0)
//{
// UserID = dt.Rows[0]["UserID"].ToString().Trim();
// UserName = dt.Rows[0]["UserName"].ToString().Trim();
// UserPWD = dt.Rows[0]["UserPWD"].ToString().Trim();
//}
}
private void InitEvent()
{
// 下載事件不能這麼快掛上去,要等全部FileRow產生完成,在掛上去
// 不然如果在下載中,會阻塞到UI的產生
FileDownloader fileDownloader = Singleton_FileDownloader.GetInstance(userMeeting.ID);
Start_callback = new MeetingRoom_DownloadFileStart_Function(MeetingRoom_DownloadFileStart_Callback);
Progress_callback = new MeetingRoom_DownloadProgressChanged_Function(MeetingRoom_DownloadProgressChanged_Callback);
ErrorFinish_callback = new MeetingRoom_DownloadFileToErrorCompleted_Function(MeetingRoom_DownloadFileToErrorCompleted_Callback);
fileDownloader.MeetingRoom_DownloadFileStart_Event += Start_callback;
fileDownloader.MeetingRoom_DownloadProgressChanged_Event += Progress_callback;
fileDownloader.MeetingRoom_DownloadFileToErrorCompleted_Event += ErrorFinish_callback;
this.MouseLeftButtonDown += MeetingRoom_MouseLeftButtonDown;
btnSeries.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnSeries.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnSeries.MouseLeftButtonDown += btnSeries_MouseLeftButtonDown;
btnDelete.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnDelete.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnDelete.MouseLeftButtonDown += btnDelete_MouseLeftButtonDown;
btnRefresh.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnRefresh.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnRefresh.MouseLeftButtonDown += btnDownload_btnPausing_MouseLeftButtonDown;
btnDownload.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnDownload.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnDownload.MouseLeftButtonDown += btnDownload_btnPausing_MouseLeftButtonDown;
// 要變成暫停下載
btnPause.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnPause.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnPause.MouseLeftButtonDown += btnPause_MouseLeftButtonDown;
// 要變成繼續下載
btnPausing.MouseEnter += (sender, e) => { MouseTool.ShowHand(); };
btnPausing.MouseLeave += (sender, e) => { MouseTool.ShowArrow(); };
btnPausing.MouseLeftButtonDown += btnDownload_btnPausing_MouseLeftButtonDown;
}
private void btnDownload_btnPausing_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
// 先撈一次MeetingData
MouseTool.ShowLoading();
//GetMeetingData.AsyncPOST(userMeeting.ID, UserID, UserPWD, (md) => { GetMeetingData_DoAction(md,(Image)sender); });
if (NetworkTool.CheckNetwork() > 0)
{
GetMeetingData.AsyncPOST(userMeeting.ID, UserID, UserPWD, (md) => { GetMeetingData_DoAction(md, (Image)sender); });
}
else
{
//DB查詢登入
DataTable dt = MSCE.GetDataTable("select MeetingJson from MeetingData where MeetingID=@1 and UserID =@2"
, userMeeting.ID
, UserID);
if (dt.Rows.Count > 0)
{
MeetingData md = JsonConvert.DeserializeObject<MeetingData>(dt.Rows[0]["MeetingJson"].ToString());
GetMeetingData_DoAction(md,(Image)sender);
}
else
{
AutoClosingMessageBox.Show("無法取得資料,請稍後再試");
MouseTool.ShowArrow();
}
}
}
private void GetMeetingData_DoAction(MeetingData md,Image btnImage)
{
//先判斷是否要invoke
if (this.Dispatcher.CheckAccess() == false)
{
// 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
this.Dispatcher.BeginInvoke(new Action<MeetingData, Image>(GetMeetingData_DoAction), md, btnImage);
}
else
{
if (md != null)
{
Task.Factory.StartNew(() =>
{
FileDownloader fileDownloader = Singleton_FileDownloader.GetInstance(md.ID);
fileDownloader.Stop();
List<MeetingDataDownloadFileFile> FileList = new List<MeetingDataDownloadFileFile>();
try
{
// <File ID="cAS66-P" Url="http://com-meeting.ntpc.hyweb.com.tw/Public/MeetingAttachFile/2/2-b167-P.phej" FileName="ae717047" version="1"/>
// 如果meetingData.MeetingsFile.FileList沒有子節點,就會轉型失敗
//XmlNode[] FileListXml = (XmlNode[])md.MeetingsFile.FileList;
//foreach (XmlNode item in FileListXml)
foreach (MeetingDataMeetingsFileFile item in md.MeetingsFile.FileList)
{
MeetingDataDownloadFileFile recordFile = new MeetingDataDownloadFileFile();
recordFile.AgendaID = "record";
//recordFile.FileName = item.Attributes["FileName"].Value;
//recordFile.ID = item.Attributes["ID"].Value;
//recordFile.Url = item.Attributes["Url"].Value;
//recordFile.version = byte.Parse(item.Attributes["version"].Value);
recordFile.FileName = item.FileName;
recordFile.ID = item.ID;
recordFile.Url = item.Url;
recordFile.version = item.version;
FileList.Add(recordFile);
}
}
catch (Exception ex)
{
LogTool.Debug(ex);
}
FileList.AddRange(md.DownloadFile.DownloadFileList.ToList());
TotalFiles = FileList.Count;
List<File_DownloadItemViewModel> fileItemList = new List<File_DownloadItemViewModel>();
foreach (MeetingDataDownloadFileFile meetingDataDownloadFileFile in FileList)
{
File_DownloadItemViewModel fileItem = FileItemTool.Gen(meetingDataDownloadFileFile, UserID, md.ID);
if (fileItem.DownloadBytes == 0 || fileItem.DownloadBytes < fileItem.TotalBytes)
fileItemList.Add(fileItem);
}
if (fileDownloader.HasMeetingRoom_DownloadFileStart_Event() == false)
{
fileDownloader.MeetingRoom_DownloadFileStart_Event += Start_callback;
}
if (fileDownloader.HasMeetingRoom_DownloadProgressChanged_Event() == false)
{
fileDownloader.MeetingRoom_DownloadProgressChanged_Event += Progress_callback;
}
if (fileDownloader.HasMeetingRoom_DownloadFileToErrorCompleted_Event() == false)
{
fileDownloader.MeetingRoom_DownloadFileToErrorCompleted_Event += ErrorFinish_callback;
}
fileDownloader.AddItem(fileItemList);
});
btnImage.Visibility = Visibility.Collapsed;
if (btnImage.Name.Equals(btnDownload.Name) == true)
{
txtPercent.Text = "0 %";
pb.Value = pb.Minimum;
}
txtPercent.Foreground = Brushes.Black;
pb.Foreground = Brushes.Orange;
pb.Background = Brushes.Black;
txtPercent.Visibility = Visibility.Visible;
pb.Visibility = Visibility.Visible;
btnPause.Visibility = Visibility.Visible;
}
else
{
AutoClosingMessageBox.Show("無法取得資料,請稍後再試");
}
MouseTool.ShowArrow();
}
}
private void btnDelete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
string QuestSring = "您確定要刪除檔案?";
// userMeeting.isDownload + userMeeting.isBrowserd
switch (meetingRoomButtonType)
{
case MeetingRoomButtonType.NN:
break;
case MeetingRoomButtonType.YY:
break;
case MeetingRoomButtonType.OY:
QuestSring = string.Format("{0}附件資料下載時間已過期,是否確認刪除?", PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String);
break;
case MeetingRoomButtonType.YO:
QuestSring = string.Format("{0}附件資料下載時間已過期,是否確認刪除?", PaperLess_Emeeting.Properties.Settings.Default.CourseOrMeeting_String);
break;
}
MessageBoxResult result = MessageBox.Show(QuestSring, "系統訊息", MessageBoxButton.YesNo);
if (result != MessageBoxResult.Yes)
return;
MouseTool.ShowLoading();
bool HasDelete = false;
try
{
//找出資料庫所有的檔案並且重置和刪除。
// 多少檔案完成
// 抓取檔案路徑
DataTable dt = MSCE.GetDataTable(@"select ID,StorageFileName from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes >= TotalBytes;"
, UserID, userMeeting.ID);
// 多少檔案要被刪除
foreach (DataRow dr in dt.Rows)
{
string filePath = ClickOnceTool.GetFilePath();
string StorageFileFolder = PaperLess_Emeeting.Properties.Settings.Default.File_StorageFileFolder;
string UnZipFileFolder = PaperLess_Emeeting.Properties.Settings.Default.File_UnZipFileFolder;
string StorageFilePath = filePath + "\\" + StorageFileFolder + "\\" + dr["StorageFileName"].ToString();
string UnZipFilePath = filePath + "\\" + UnZipFileFolder + "\\" + UserID + "\\" + userMeeting.ID + "\\" + dr["ID"].ToString();
if (File.Exists(StorageFilePath) == true)
File.Delete(StorageFilePath);
DirectoryTool.FullDeleteDirectories(UnZipFilePath);
}
string SQL = @"update FileRow set DownloadBytes=0,TotalBytes=0,FinishedFileVersion=0 where UserID =@1 and MeetingID=@2 ";
int success = MSCE.ExecuteNonQuery(SQL
, UserID, userMeeting.ID);
if (success < 1)
{
LogTool.Debug(new Exception(@"DB失敗: " + SQL));
}
else
{
HasDelete = true;
}
}
catch(Exception ex)
{
LogTool.Debug(ex);
}
MouseTool.ShowArrow();
if (HasDelete == false)
{
AutoClosingMessageBox.Show("刪除失敗");
}
else
{
// userMeeting.isDownload + userMeeting.isBrowserd
//switch (meetingRoomButtonType)
//{
// case MeetingRoomButtonType.NN:
// btnDelete.Visibility = Visibility.Collapsed;
// pb.Value = pb.Minimum;
// break;
// case MeetingRoomButtonType.YY:
// // 一般都會顯示這個,除非下載瀏覽過期之類的
// btnDelete.Visibility = Visibility.Collapsed;
// btnDownload.Visibility = Visibility.Visible;
// pb.Value = pb.Minimum;
// break;
// case MeetingRoomButtonType.OY:
// btnDelete.Visibility = Visibility.Collapsed;
// btnDownloadForbidden.Visibility = Visibility.Visible;
// pb.Value = pb.Minimum;
// break;
// case MeetingRoomButtonType.YO:
// btnDelete.Visibility = Visibility.Collapsed;
// btnRead2Forbidden.Visibility = Visibility.Visible;
// pb.Value = pb.Minimum;
// break;
//}
btnDelete.Visibility = Visibility.Collapsed;
btnRefresh.Visibility = Visibility.Visible;
pb.Value = pb.Minimum;
txtPercent.Text = "0 %";
}
}
private void btnPause_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
Task.Factory.StartNew(() =>
{
FileDownloader fileDownloader = Singleton_FileDownloader.GetInstance(userMeeting.ID);
fileDownloader.ClearMeetingRoomEvent();
fileDownloader.Stop();
});
this.btnPause.Visibility = Visibility.Collapsed;
this.txtPercent.Foreground = Brushes.Gray;
this.pb.Foreground = Brushes.Wheat;
this.pb.Background = Brushes.Gray;
this.txtPercent.Visibility = Visibility.Visible;
this.btnPausing.Visibility = Visibility.Visible;
}
private void MeetingRoom_DownloadFileToErrorCompleted_Callback(File_DownloadItemViewModel fileItem)
{
//先判斷是否要invoke
if (this.Dispatcher.CheckAccess() == false)
{
// 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<File_DownloadItemViewModel>(MeetingRoom_DownloadFileToErrorCompleted_Callback), fileItem);
}
else
{
ForceStopAjaxLoader = true;
double totalPercent = GetNowMeetingFilesTotalPercent(fileItem);
// 全部都已經下載完成或失敗,要變成暫停狀態,一定不會是100%
this.btnDownloadForbidden.Visibility = Visibility.Collapsed;
this.btnRead2Forbidden.Visibility = Visibility.Collapsed;
this.btnDelete.Visibility = Visibility.Collapsed;
this.btnDownload.Visibility = Visibility.Collapsed;
this.btnPause.Visibility = Visibility.Collapsed;
this.txtPercent.Text = ((int)totalPercent).ToString() + " %";
this.txtPercent.Foreground = Brushes.Black;
this.txtPercent.Visibility = Visibility.Visible;
this.pb.Value = totalPercent;
this.pb.Foreground = Brushes.Orange;
this.pb.Background = Brushes.Black;
this.pb.Visibility = Visibility.Visible;
this.btnPausing.Visibility = Visibility.Visible;
}
}
private void MeetingRoom_DownloadProgressChanged_Callback(File_DownloadItemViewModel fileItem,bool ForceUpdate)
{
//先判斷是否要invoke
if (this.Dispatcher.CheckAccess() == false)
{
// 這裡是下載事件處理,優先權設定為ContextIdle => 列舉值為 3。 幕後作業完成後,會處理作業。
//this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle, new Action<File_DownloadItemViewModel, bool>(MeetingRoom_DownloadProgressChanged_Callback), fileItem, ForceUpdate);
this.Dispatcher.BeginInvoke(new Action<File_DownloadItemViewModel, bool>(MeetingRoom_DownloadProgressChanged_Callback), fileItem, ForceUpdate);
}
else
{
ForceStopAjaxLoader = true;
double totalPercent = GetNowMeetingFilesTotalPercent(fileItem);
if (totalPercent>=100)
{
// 下載完了,顯示可以刪除的圖示
this.btnDownloadForbidden.Visibility = Visibility.Collapsed;
this.btnRead2Forbidden.Visibility = Visibility.Collapsed;
this.btnDownload.Visibility = Visibility.Collapsed;
this.btnPausing.Visibility = Visibility.Collapsed;
this.txtPercent.Visibility = Visibility.Collapsed;
this.pb.Visibility = Visibility.Collapsed;
this.btnPause.Visibility = Visibility.Collapsed;
this.btnDelete.Visibility = Visibility.Visible;
}
else if (totalPercent - pb.Value > 1 || ForceUpdate==true)
{
// 還沒下載完了,持續更新進度
this.btnDownloadForbidden.Visibility = Visibility.Collapsed;
this.btnRead2Forbidden.Visibility = Visibility.Collapsed;
this.btnDelete.Visibility = Visibility.Collapsed;
this.btnDownload.Visibility = Visibility.Collapsed;
this.btnPausing.Visibility = Visibility.Collapsed;
this.txtPercent.Text = ((int)totalPercent).ToString() + " %";
this.txtPercent.Foreground = Brushes.Black;
this.txtPercent.Visibility = Visibility.Visible;
this.pb.Value = totalPercent;
this.pb.Foreground = Brushes.Orange;
this.pb.Background = Brushes.Black;
this.pb.Visibility = Visibility.Visible;
this.btnPause.Visibility = Visibility.Visible;
}
}
}
private double GetNowMeetingFilesTotalPercent(File_DownloadItemViewModel fileItem)
{
double totalPercent = 0;
DataTable dt = MSCE.GetDataTable(@"select count(ID) as FinishedFiles from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes >= TotalBytes;"
, UserID, userMeeting.ID);
if (dt.Rows.Count > 0)
int.TryParse(dt.Rows[0]["FinishedFiles"].ToString(), out FinishedFiles);
if (TotalFiles > 0)
{
totalPercent = ((double)FinishedFiles / (double)TotalFiles) * 100.0;
if(fileItem.NowPercentage < 100)
{
//小於100趴才需要,後面這一段+ (fileItem.NowPercentage / 100.0) * (100.0 / (double)TotalFiles)
totalPercent += (fileItem.NowPercentage / 100.0) * (100.0 / (double)TotalFiles);
}
}
return totalPercent;
}
private void MeetingRoom_DownloadFileStart_Callback(File_DownloadItemViewModel fileItem)
{
if (HasReceiveStart_callback == false)
{
HasReceiveStart_callback = true;
MeetingRoom_DownloadProgressChanged_Callback(fileItem, true);
}
}
private void btnSeries_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
e.Handled = true;
Home Home_Window = Application.Current.Windows.OfType<Home>().FirstOrDefault();
Home_Window.ShowBtnSeriesCT(userMeeting.SeriesMeetingID);
}
private void MeetingRoom_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
string SQL = @"Update NowLogin set MeetingID=@1,AllowIpRange='' ";
int success = MSCE.ExecuteNonQuery(SQL, userMeeting.ID);
if (success < 1)
{
LogTool.Debug(new Exception(@"DB失敗: " + SQL));
return;
}
//20141203
//Home_Change2MeetingDataCT_Event(userMeeting.ID);
//20150422
Home_Change2MeetingDataCT_Event(userMeeting.ID,PreLoadMeetingData);
}
private void InitUI()
{
// (1)背景顏色處理好之後,就直接顯示
try
{
// 如果 parse 失敗 會維持白色
// 正在開會議的會議
if (DateTime.Parse(userMeeting.BeginTime) <= DateTime.Now && DateTime.Now < DateTime.Parse(userMeeting.EndTime))
{
txtMeetingName.Foreground = Brushes.White;
txtLocation.Foreground = Brushes.White;
txtTime.Foreground = Brushes.White;
RoomInnerBG.Visibility = Visibility.Visible;
// 新增的會議
if (NewAddMeetingID.Equals(userMeeting.ID) == true)
{
RoomBG.Background = Brushes.Yellow;
}
}
else
{
txtMeetingName.Foreground = Brushes.Black;
txtLocation.Foreground = Brushes.Black;
txtTime.Foreground = Brushes.Black;
// 新增的會議
if (NewAddMeetingID.Equals(userMeeting.ID) == true)
{
RoomBG.Background = Brushes.Yellow;
RoomInnerBG.Background = Brushes.White;
RoomInnerBG.Visibility = Visibility.Visible;
}
}
}
catch (Exception ex)
{
LogTool.Debug(ex);
}
txtMeetingName.Text = userMeeting.Name;
txtLocation.Text=userMeeting.Location;
txtTime.Text = DateTime.Parse(userMeeting.BeginTime).ToString("HH:mm");
//if (userMeeting.SeriesMeetingID!=null && userMeeting.SeriesMeetingID.Equals("") == false)
if (userMeeting.SeriesMeetingID != null && userMeeting.SeriesMeetingID.Length > 0)
btnSeries.Visibility = Visibility.Visible;
//如果不要隱形,就顯示出來
//if (invisible == false)
//{
// (2)背景顏色處理好之後,就直接顯示
this.Visibility = Visibility.Visible;
//}
//else
//{
// this.Visibility = Visibility.Collapsed;
//}
switch (meetingRoomButtonType)
{
case MeetingRoomButtonType.NN:
// 沒有圖示
break;
case MeetingRoomButtonType.YY:
// 未下載檔案: 下載圖示,包含續傳到一半的檔案
// 已下載檔案: 垃圾埇圖示
// 都要先檢查所有檔案的下載進度
// 下載完了
if (FinishedPercent >= 100)
{
btnDelete.Visibility = Visibility.Visible;
}
else //尚未下載完
{
// 沒有下載過
if (FinishedPercent < 1)
{
btnDownload.Visibility = Visibility.Visible;
}
else
{
// 這裡慢一點再顯示出來,沒關係
// 可以先給Ajax動畫
// 選擇(一),有動畫
ajaxTimer = new DispatcherTimer();
ajaxTimer.Interval = TimeSpan.FromMilliseconds(30);
ajaxTimer.Tick += new EventHandler(ajaxLoader_ChangeImage);
ajaxTimer.Start();
// 選擇(二),沒有動畫
//txtPercent.Text = FinishedPercent + " %";
//pb.Value = FinishedPercent;
//pb.Foreground = Brushes.Wheat;
//pb.Background = Brushes.Gray;
//txtPercent.Visibility = Visibility.Visible;
//pb.Visibility = Visibility.Visible;
//btnPausing.Visibility = Visibility.Visible;
}
}
break;
case MeetingRoomButtonType.OY:
// 未下載檔案: 不可下載圖示,直接顯示不可下載圖示
// 已下載檔案: 垃圾埇圖示
// 都要先檢查所有檔案的下載進度
// 下載完了
if (FinishedPercent >= 100)
{
btnDelete.Visibility = Visibility.Visible;
}
else //尚未下載完
{
btnDownloadForbidden.Visibility = Visibility.Visible;
}
break;
case MeetingRoomButtonType.YO:
//不可瀏覽圖示
btnRead2Forbidden.Visibility = Visibility.Visible;
break;
case MeetingRoomButtonType.OO:
// 未下載檔案: 不可下載圖示
// 已下載檔案: 不可瀏覽圖示
btnRead2Forbidden.Visibility = Visibility.Visible;
break;
}
//最後判斷是從系列會議到底是否隱藏(2)
if (this.invisible == true)
{
this.Visibility = Visibility.Collapsed;
}
//DispatcherTimer timer = new DispatcherTimer();
//timer.Interval = TimeSpan.FromSeconds(1);
//timer.Tick += (sender3, e3) =>
//{
// try
// {
// string url = WsTool.GetUrl();
// string xmlData = "<?xml version=\"1.0\"?><UserInfo><MeetingID>{0}</MeetingID><UserID><![CDATA[{1}]]></UserID><UserPW><![CDATA[{2}]]></UserPW></UserInfo>";
// xmlData = string.Format(xmlData, userMeeting.ID, UserID, UserPWD);
// Dictionary<string, string> postData = new Dictionary<string, string>();
// postData["XmlDoc"] = xmlData;
// string data = HttpTool.CreateRequest(url + "/MeetingData", "POST", postData);
// if (nowXML.Length == 0)
// nowXML = data;
// else
// {
// if(!data.Equals(nowXML))
// {
// if (refresh != null)
// refresh();
// }
// }
// }
// catch (Exception ex)
// {
// LogTool.Debug(ex);
// }
//};
//timer.Start();
}
public string nowXML = "";
public Action refresh;
private void ShowBtnPercent(int Percent)
{
btnDelete.Visibility = Visibility.Collapsed;
btnDownload.Visibility = Visibility.Collapsed;
btnPause.Visibility = Visibility.Collapsed;
txtPercent.Text = FinishedPercent + " %";
pb.Value = FinishedPercent;
pb.Foreground = Brushes.Wheat;
pb.Background = Brushes.Gray;
txtPercent.Visibility = Visibility.Visible;
pb.Visibility = Visibility.Visible;
btnPausing.Visibility = Visibility.Visible;
}
int i = 0;
//int ajaxTimes = 1;
private void ajaxLoader_ChangeImage(object sender, EventArgs e)
{
string fileName=string.Format("images/ajaxLoader/{0}.gif", i);
ajaxLoader.Source = new BitmapImage(new Uri(fileName,UriKind.Relative));
i++;
if (ForceStopAjaxLoader==true || i >= 11 )
{
//i = 0;
//if (ForceStopAjaxLoader==true || ajaxTimes > 1 )
//{
ajaxTimer.Stop();
ajaxLoader.Visibility = Visibility.Collapsed;
i = 1; // Display first image after the last image
FileDownloader fileItem = Singleton_FileDownloader.GetInstance(userMeeting.ID);
if (fileItem.downloaderType != DownloaderType.正在下載中)
ShowBtnPercent(this.FinishedPercent);
//}
//ajaxTimes++;
}
}
private int GetFinishedPercent()
{
int Rtn_FinishedPercent = 0;
try
{
// 多少檔案完成
DataTable dt = MSCE.GetDataTable(@"select count(ID) as FinishedFiles from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes >= TotalBytes;"
, UserID, userMeeting.ID);
if (dt.Rows.Count > 0)
{
int.TryParse(dt.Rows[0]["FinishedFiles"].ToString(), out FinishedFiles);
}
//// 抓取檔案路徑
//dt = MSCE.GetDataTable(@"select StorageFileName from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes >= TotalBytes;"
// , UserID, userMeeting.ID);
//// 多少檔案被刪除
//foreach (DataRow dr in dt.Rows)
//{
// string filePath = ClickOnceTool.GetFilePath();
// string StorageFileFolder = PaperLess_Emeeting.Properties.Settings.Default.File_StorageFileFolder;
// string StorageFilePath = filePath + "\\" + StorageFileFolder + "\\" + dr["StorageFileName"].ToString();
// if (File.Exists(StorageFilePath) == false)
// FinishedFiles--;
//}
// 全部完成。
if (FinishedFiles > 0 && FinishedFiles >= TotalFiles)
{
Rtn_FinishedPercent = 100;
}
else
{
// 檢查百分比
if (TotalFiles > 0)
Rtn_FinishedPercent = (int)(((double)FinishedFiles / (double)TotalFiles) * 100.0);
double SumDownloadBytes = 0;
double SumTotalBytes = 0;
dt = MSCE.GetDataTable(@"select sum(DownloadBytes) as sumDownloadBytes from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes < TotalBytes;"
, UserID, userMeeting.ID);
if (dt.Rows.Count > 0)
double.TryParse(dt.Rows[0]["SumDownloadBytes"].ToString(), out SumDownloadBytes);
dt = MSCE.GetDataTable(@"select sum(TotalBytes) as SumTotalBytes from FileRow where UserID =@1 and MeetingID=@2 and DownloadBytes!=0 and DownloadBytes < TotalBytes;"
, UserID, userMeeting.ID);
if (dt.Rows.Count > 0)
double.TryParse(dt.Rows[0]["SumTotalBytes"].ToString(), out SumTotalBytes);
if (SumTotalBytes > 0)
Rtn_FinishedPercent += (int)( (SumDownloadBytes / SumTotalBytes) / (TotalFiles - FinishedFiles) * (100.0 / (double)TotalFiles) );
//dt = MSCE.GetDataTable(@"select DownloadBytes from FileRow where UserID =@3 and MeetingID=@4;"
// , UserID, userMeeting.ID);
//foreach(DataRow dr in dt.Rows)
//{
// double DownloadBytes = 0;
// double.TryParse(dr["DownloadBytes"].ToString(), out DownloadBytes);
// SumDownloadBytes += DownloadBytes;
//}
////(10MB)
//int NotHasTotalBytes = 1024 * 1024 * 10;
//dt = MSCE.GetDataTable(@"select TotalBytes from FileRow where UserID =@3 and MeetingID=@4;"
// , UserID, userMeeting.ID);
//int.TryParse(dt.Compute("max(TotalBytes)", "").ToString(),out NotHasTotalBytes);
//foreach (DataRow dr in dt.Rows)
//{
// double TotalBytes = 0;
// double.TryParse(dr["TotalBytes"].ToString(), out TotalBytes);
// if (TotalBytes==0)
// SumTotalBytes += NotHasTotalBytes;
// else
// SumTotalBytes += TotalBytes;
//}
//if (SumTotalBytes > 0)
// Rtn_FinishedPercent += (int)(SumDownloadBytes / SumTotalBytes * 100.0) / (TotalFiles - FinishedFiles);
}
}
catch(Exception ex)
{
LogTool.Debug(ex);
}
return Rtn_FinishedPercent;
}
}
}