Guest User

Untitled

a guest
Apr 1st, 2020
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.34 KB | None | 0 0
  1. using PaperLess_Emeeting;
  2. using PaperLess_Emeeting.App_Code;
  3. using PaperLess_Emeeting.App_Code.ClickOnce;
  4. using PaperLess_Emeeting.App_Code.DownloadItem;
  5. using PaperLess_Emeeting.App_Code.MessageBox;
  6. using PaperLess_Emeeting.App_Code.ViewModel;
  7. using PaperLess_Emeeting.App_Code.WS;
  8. using PaperLess_Emeeting.Properties;
  9. using PaperLess_ViewModel;
  10. using System;
  11. using System.CodeDom.Compiler;
  12. using System.Collections.Generic;
  13. using System.ComponentModel;
  14. using System.Data;
  15. using System.Diagnostics;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Threading.Tasks;
  19. using System.Windows;
  20. using System.Windows.Controls;
  21. using System.Windows.Input;
  22. using System.Windows.Markup;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Animation;
  25.  
  26. public class LawRow : UserControl, IComponentConnector
  27. {
  28. private Storyboard sb;
  29.  
  30. private LawListCT_HangTheDownloadEvent_Function LawListCT_HangTheDownloadEvent_Event;
  31.  
  32. private LawListCT_IsAllLawRowFinished_AddInitUIFinished_Function LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event;
  33.  
  34. private LawListCT_GetBookVMs_ByMeetingFileCate_Function LawListCT_GetBookVMs_ByMeetingFileCate_Event;
  35.  
  36. public bool IsAllLawRowFinished = false;
  37.  
  38. internal TextBlock txtDate;
  39.  
  40. internal TextBlock txtLawName;
  41.  
  42. internal Image btnUpdate;
  43.  
  44. internal TextBlock txtIsNew;
  45.  
  46. internal TextBlock txtUpdatePercent;
  47.  
  48. internal TextBlock txtUpdateUnzip;
  49.  
  50. internal ProgressBar pbUpdate;
  51.  
  52. internal Image btnOpen;
  53.  
  54. internal Image btnDownload;
  55.  
  56. internal TextBlock txtPercent;
  57.  
  58. internal TextBlock txtUnzip;
  59.  
  60. internal ProgressBar pb;
  61.  
  62. internal Image btnDelete;
  63.  
  64. private bool _contentLoaded;
  65.  
  66. public LawDataLaw lawDataLaw
  67. {
  68. get;
  69. set;
  70. }
  71.  
  72. public Law_DownloadItemViewModel lawItem
  73. {
  74. get;
  75. set;
  76. }
  77.  
  78. public string UserID
  79. {
  80. get;
  81. set;
  82. }
  83.  
  84. public string UserName
  85. {
  86. get;
  87. set;
  88. }
  89.  
  90. public string UserPWD
  91. {
  92. get;
  93. set;
  94. }
  95.  
  96. public bool IsLastRow
  97. {
  98. get;
  99. set;
  100. }
  101.  
  102. public LawRow(string UserID, string UserName, string UserPWD, bool IsLastRow, LawDataLaw lawDataLaw, LawListCT_HangTheDownloadEvent_Function callback1, LawListCT_IsAllLawRowFinished_AddInitUIFinished_Function callback2, LawListCT_GetBookVMs_ByMeetingFileCate_Function callback3)
  103. {
  104. InitializeComponent();
  105. this.UserID = UserID;
  106. this.UserName = UserName;
  107. this.UserPWD = UserPWD;
  108. this.IsLastRow = IsLastRow;
  109. this.lawDataLaw = lawDataLaw;
  110. base.Loaded += LawRow_Loaded;
  111. LawListCT_HangTheDownloadEvent_Event = callback1;
  112. LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event = callback2;
  113. LawListCT_GetBookVMs_ByMeetingFileCate_Event = callback3;
  114. lawItem = new Law_DownloadItemViewModel();
  115. }
  116.  
  117. private void LawRow_Loaded(object sender, RoutedEventArgs e)
  118. {
  119. txtDate.Text = lawDataLaw.UpDate.Split(' ')[0];
  120. txtLawName.Text = lawDataLaw.Name;
  121. Task.Factory.StartNew(delegate
  122. {
  123. InitSelectDB();
  124. base.Dispatcher.BeginInvoke((Action)delegate
  125. {
  126. InitUI();
  127. InitEvent();
  128. });
  129. });
  130. }
  131.  
  132. private void InitSelectDB()
  133. {
  134. DataTable dataTable = new DataTable();
  135. LawDownloader instance = Singleton_LawDownloader.GetInstance();
  136. lawItem = instance.GetInList(lawDataLaw.ID);
  137. if (lawItem != null)
  138. {
  139. return;
  140. }
  141. string text = "";
  142. DateTime dateTime = DateTime.Parse("2010/01/01");
  143. string text2 = "";
  144. string text3 = "";
  145. long num = 0L;
  146. long num2 = 0L;
  147. dataTable = MSCE.GetDataTable("SELECT ID,AtDownloadFinished_XmlUpDate,Link,StorageFileName,DownloadBytes,TotalBytes FROM LawRow where ID=@1 and UserID=@2", lawDataLaw.ID, UserID);
  148. if (dataTable.Rows.Count > 0)
  149. {
  150. text = dataTable.Rows[0]["ID"].ToString();
  151. dateTime = (DateTime)dataTable.Rows[0]["AtDownloadFinished_XmlUpDate"];
  152. text2 = dataTable.Rows[0]["Link"].ToString();
  153. text3 = dataTable.Rows[0]["StorageFileName"].ToString();
  154. num = long.Parse(dataTable.Rows[0]["DownloadBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["DownloadBytes"].ToString());
  155. num2 = long.Parse(dataTable.Rows[0]["TotalBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["TotalBytes"].ToString());
  156. }
  157. else
  158. {
  159. string text4 = "INSERT INTO LawRow(ID,AtDownloadFinished_XmlUpDate,DownloadBytes,TotalBytes,UserID) \r\n VALUES(@1,'2010/01/01',0,0,@2)";
  160. int num3 = MSCE.ExecuteNonQuery(text4, lawDataLaw.ID, UserID);
  161. if (num3 < 1)
  162. {
  163. LogTool.Debug(new Exception("DB失敗: " + text4));
  164. }
  165. }
  166. lawItem = new Law_DownloadItemViewModel();
  167. lawItem.ID = lawDataLaw.ID;
  168. lawItem.UserID = UserID;
  169. DateTime.TryParse(lawDataLaw.UpDate, out DateTime result);
  170. lawItem.UpDate = result;
  171. lawItem.Name = lawDataLaw.Name;
  172. lawItem.Link = lawDataLaw.Link;
  173. lawItem.Status = (LawDataStatus)Enum.Parse(typeof(LawDataStatus), lawDataLaw.Status);
  174. string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  175. string law_StorageFileFolder = Settings.Default.Law_StorageFileFolder2;
  176. lawItem.StorageFileFolder = Path.Combine(baseDirectory, law_StorageFileFolder);
  177. string arg = DateTime.Now.ToFileTime().ToString();
  178. try
  179. {
  180. Uri uri = new Uri(lawItem.Link);
  181. string fileName = Path.GetFileName(uri.LocalPath);
  182. if (!fileName.Equals("/"))
  183. {
  184. arg = fileName;
  185. }
  186. }
  187. catch (Exception ex)
  188. {
  189. LogTool.Debug(ex);
  190. }
  191. lawItem.StorageFileName = $"{UserID}_{lawDataLaw.ID}_{arg}";
  192. lawItem.UnZipFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.Law_UnZipFileFolder);
  193. if (num == 0L || num < num2)
  194. {
  195. if (File.Exists(lawItem.StorageFilePath))
  196. {
  197. File.Delete(lawItem.StorageFilePath);
  198. }
  199. lawItem.DownloadBytes = 0L;
  200. lawItem.TotalBytes = 0L;
  201. lawItem.FileType = LawFileType.從未下載;
  202. }
  203. else if (TimeSpan.Compare(new TimeSpan(result.Ticks), new TimeSpan(dateTime.Ticks)) > 0)
  204. {
  205. lawItem.StorageFileName += ".update";
  206. lawItem.DownloadBytes = 0L;
  207. lawItem.TotalBytes = 0L;
  208. lawItem.FileType = LawFileType.更新檔未下載;
  209. }
  210. else
  211. {
  212. lawItem.FileType = LawFileType.已下載完成;
  213. }
  214. }
  215.  
  216. private void InitEvent()
  217. {
  218. btnDownload.MouseEnter += delegate
  219. {
  220. MouseTool.ShowHand();
  221. };
  222. btnDownload.MouseLeave += delegate
  223. {
  224. MouseTool.ShowArrow();
  225. };
  226. btnDownload.MouseLeftButtonDown += btnDownload_MouseLeftButtonDown;
  227. btnDelete.MouseEnter += delegate
  228. {
  229. MouseTool.ShowHand();
  230. };
  231. btnDelete.MouseLeave += delegate
  232. {
  233. MouseTool.ShowArrow();
  234. };
  235. btnDelete.MouseLeftButtonDown += btnDelete_MouseLeftButtonDown;
  236. btnOpen.MouseEnter += delegate
  237. {
  238. MouseTool.ShowHand();
  239. };
  240. btnOpen.MouseLeave += delegate
  241. {
  242. MouseTool.ShowArrow();
  243. };
  244. btnOpen.MouseLeftButtonDown += btnOpen_MouseLeftButtonDown;
  245. btnUpdate.MouseEnter += delegate
  246. {
  247. MouseTool.ShowHand();
  248. };
  249. btnUpdate.MouseLeave += delegate
  250. {
  251. MouseTool.ShowArrow();
  252. };
  253. btnUpdate.MouseLeftButtonDown += btnDownload_MouseLeftButtonDown;
  254. if (IsAllLawRowFinished && LawListCT_HangTheDownloadEvent_Event != null)
  255. {
  256. LawListCT_HangTheDownloadEvent_Event(lawItem.ID);
  257. }
  258. }
  259.  
  260. private void btnOpen_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  261. {
  262. MouseTool.ShowLoading();
  263. try
  264. {
  265. string filePath = ClickOnceTool.GetFilePath();
  266. string _bookPath = lawItem.UnZipFilePath;
  267. string _bookId = "";
  268. string _account = "";
  269. string _userName = "";
  270. string _email = "";
  271. string _meetingId = "";
  272. string _watermark = "";
  273. string _dbPath = Path.Combine(ClickOnceTool.GetDataPath(), Settings.Default.bookInfo_Path);
  274. bool _isSync = false;
  275. bool _isSyncOwner = false;
  276. string _webServiceUrl = WsTool.GetUrl() + "/AnnotationUpload";
  277. string _socketMessage = "";
  278. Dictionary<string, BookVM> cbBooksData = null;
  279. Home Home_Window = Application.Current.Windows.OfType<Home>().FirstOrDefault();
  280. Home_Window.CloseAllWindow("", fromInit: true);
  281. Task.Factory.StartNew(delegate
  282. {
  283. base.Dispatcher.BeginInvoke((Action)delegate
  284. {
  285. ReadWindow readWindow = new ReadWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId, _account, _userName, _email, _meetingId, _watermark, _dbPath, _isSync, _isSyncOwner, _webServiceUrl, _socketMessage)
  286. {
  287. HideCollectFile = true,
  288. WindowStyle = WindowStyle.None,
  289. WindowStartupLocation = WindowStartupLocation.CenterScreen,
  290. WindowState = WindowState.Maximized
  291. };
  292. if (Settings.Default.AssemblyName.Contains("TPI4F"))
  293. {
  294. }
  295. readWindow.Show();
  296. });
  297. });
  298. }
  299. catch (Exception ex)
  300. {
  301. LogTool.Debug(ex);
  302. }
  303. MouseTool.ShowArrow();
  304. }
  305.  
  306. private void btnDelete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  307. {
  308. MessageBoxResult messageBoxResult = MessageBox.Show("您確定要刪除檔案?", "系統訊息", MessageBoxButton.YesNo);
  309. if (messageBoxResult == MessageBoxResult.No)
  310. {
  311. return;
  312. }
  313. string text = "update LawRow set DownloadBytes=0,TotalBytes=0 where ID=@1 and UserID=@2";
  314. int num = MSCE.ExecuteNonQuery(text, lawDataLaw.ID, UserID);
  315. if (num < 1)
  316. {
  317. AutoClosingMessageBox.Show("刪除失敗");
  318. LogTool.Debug(new Exception("DB失敗: " + text));
  319. return;
  320. }
  321. if (File.Exists(lawItem.StorageFilePath))
  322. {
  323. File.Delete(lawItem.StorageFilePath);
  324. }
  325. ShowNeverDownload(fromBtnDelete: true);
  326. }
  327.  
  328. private void btnDownload_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  329. {
  330. if (lawItem != null)
  331. {
  332. btnDownload.Visibility = Visibility.Collapsed;
  333. txtPercent.Text = "等待中";
  334. txtPercent.Foreground = Brushes.Gray;
  335. txtPercent.Visibility = Visibility.Visible;
  336. pb.Foreground = Brushes.Wheat;
  337. pb.Background = Brushes.Gray;
  338. pb.Visibility = Visibility.Visible;
  339. if (lawItem.StorageFileName.EndsWith(".update"))
  340. {
  341. lawItem.FileType = LawFileType.更新檔排入下載中;
  342. }
  343. else
  344. {
  345. lawItem.FileType = LawFileType.排入下載中;
  346. }
  347. LawDownloader instance = Singleton_LawDownloader.GetInstance();
  348. instance.AddItem(lawItem);
  349. }
  350. }
  351.  
  352. private void InitUI()
  353. {
  354. switch (lawItem.FileType)
  355. {
  356. case LawFileType.從未下載:
  357. ShowNeverDownload(fromBtnDelete: false);
  358. break;
  359. case LawFileType.正在下載中:
  360. ShowInDownload();
  361. txtPercent.Text = (int)lawItem.NowPercentage + " %";
  362. pb.Value = lawItem.NowPercentage;
  363. pb.Foreground = Brushes.Orange;
  364. pb.Background = Brushes.Black;
  365. txtPercent.Visibility = Visibility.Visible;
  366. pb.Visibility = Visibility.Visible;
  367. break;
  368. case LawFileType.已下載完成:
  369. ShowCanOpen();
  370. txtIsNew.Visibility = Visibility.Visible;
  371. break;
  372. case LawFileType.排入下載中:
  373. ShowInDownload();
  374. txtPercent.Text = "等待中";
  375. txtPercent.Foreground = Brushes.Gray;
  376. txtPercent.Visibility = Visibility.Visible;
  377. pb.Foreground = Brushes.Wheat;
  378. pb.Background = Brushes.Gray;
  379. pb.Visibility = Visibility.Visible;
  380. break;
  381. case LawFileType.解壓縮中:
  382. ((Storyboard)TryFindResource("sb"))?.Begin();
  383. break;
  384. case LawFileType.解壓縮失敗:
  385. ShowNeverDownload(fromBtnDelete: false);
  386. break;
  387. case LawFileType.更新檔未下載:
  388. ShowCanOpen();
  389. break;
  390. case LawFileType.更新檔暫停中:
  391. ShowCanOpen();
  392. break;
  393. case LawFileType.更新檔正在下載中:
  394. ShowCanOpen();
  395. break;
  396. case LawFileType.更新檔已下載完成:
  397. ShowCanOpen();
  398. break;
  399. case LawFileType.更新檔排入下載中:
  400. ShowCanOpen();
  401. txtUpdatePercent.Text = "等待中";
  402. txtIsNew.Foreground = Brushes.Gray;
  403. txtUpdatePercent.Visibility = Visibility.Visible;
  404. pb.Foreground = Brushes.Wheat;
  405. pb.Background = Brushes.Gray;
  406. pb.Visibility = Visibility.Visible;
  407. break;
  408. case LawFileType.更新檔解壓縮中:
  409. ((Storyboard)TryFindResource("sbUpdate"))?.Begin();
  410. break;
  411. case LawFileType.更新檔解壓縮失敗:
  412. ShowCanOpen();
  413. break;
  414. }
  415. if (LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event != null)
  416. {
  417. IsAllLawRowFinished = LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event();
  418. }
  419. }
  420.  
  421. private void HideAll()
  422. {
  423. btnDelete.Visibility = Visibility.Collapsed;
  424. btnOpen.Visibility = Visibility.Collapsed;
  425. btnUpdate.Visibility = Visibility.Collapsed;
  426. pb.Visibility = Visibility.Collapsed;
  427. txtIsNew.Visibility = Visibility.Collapsed;
  428. btnDownload.Visibility = Visibility.Visible;
  429. pbUpdate.Visibility = Visibility.Collapsed;
  430. txtUpdatePercent.Visibility = Visibility.Collapsed;
  431. }
  432.  
  433. private void ShowNeverDownload(bool fromBtnDelete)
  434. {
  435. if (fromBtnDelete)
  436. {
  437. btnDelete.Visibility = Visibility.Collapsed;
  438. btnOpen.Visibility = Visibility.Collapsed;
  439. btnUpdate.Visibility = Visibility.Collapsed;
  440. pb.Visibility = Visibility.Collapsed;
  441. txtIsNew.Visibility = Visibility.Collapsed;
  442. pbUpdate.Visibility = Visibility.Collapsed;
  443. txtUpdatePercent.Visibility = Visibility.Collapsed;
  444. }
  445. btnDownload.Visibility = Visibility.Visible;
  446. }
  447.  
  448. private void ShowInDownload()
  449. {
  450. }
  451.  
  452. private void ShowCanOpen()
  453. {
  454. btnDelete.Visibility = Visibility.Visible;
  455. btnOpen.Visibility = Visibility.Visible;
  456. }
  457.  
  458. [DebuggerNonUserCode]
  459. [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  460. public void InitializeComponent()
  461. {
  462. if (!_contentLoaded)
  463. {
  464. _contentLoaded = true;
  465. Uri resourceLocator = new Uri("/PaperLess_Emeeting_Taichung;component/lawrow.xaml", UriKind.Relative);
  466. Application.LoadComponent(this, resourceLocator);
  467. }
  468. }
  469.  
  470. [DebuggerNonUserCode]
  471. [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  472. [EditorBrowsable(EditorBrowsableState.Never)]
  473. void IComponentConnector.Connect(int connectionId, object target)
  474. {
  475. switch (connectionId)
  476. {
  477. case 1:
  478. txtDate = (TextBlock)target;
  479. break;
  480. case 2:
  481. txtLawName = (TextBlock)target;
  482. break;
  483. case 3:
  484. btnUpdate = (Image)target;
  485. break;
  486. case 4:
  487. txtIsNew = (TextBlock)target;
  488. break;
  489. case 5:
  490. txtUpdatePercent = (TextBlock)target;
  491. break;
  492. case 6:
  493. txtUpdateUnzip = (TextBlock)target;
  494. break;
  495. case 7:
  496. pbUpdate = (ProgressBar)target;
  497. break;
  498. case 8:
  499. btnOpen = (Image)target;
  500. break;
  501. case 9:
  502. btnDownload = (Image)target;
  503. break;
  504. case 10:
  505. txtPercent = (TextBlock)target;
  506. break;
  507. case 11:
  508. txtUnzip = (TextBlock)target;
  509. break;
  510. case 12:
  511. pb = (ProgressBar)target;
  512. break;
  513. case 13:
  514. btnDelete = (Image)target;
  515. break;
  516. default:
  517. _contentLoaded = true;
  518. break;
  519. }
  520. }
  521. }
Advertisement
Add Comment
Please, Sign In to add comment