Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PaperLess_Emeeting;
- 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.ViewModel;
- using PaperLess_Emeeting.App_Code.WS;
- using PaperLess_Emeeting.Properties;
- using PaperLess_ViewModel;
- using System;
- using System.CodeDom.Compiler;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Input;
- using System.Windows.Markup;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- public class LawRow : UserControl, IComponentConnector
- {
- private Storyboard sb;
- private LawListCT_HangTheDownloadEvent_Function LawListCT_HangTheDownloadEvent_Event;
- private LawListCT_IsAllLawRowFinished_AddInitUIFinished_Function LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event;
- private LawListCT_GetBookVMs_ByMeetingFileCate_Function LawListCT_GetBookVMs_ByMeetingFileCate_Event;
- public bool IsAllLawRowFinished = false;
- internal TextBlock txtDate;
- internal TextBlock txtLawName;
- internal Image btnUpdate;
- internal TextBlock txtIsNew;
- internal TextBlock txtUpdatePercent;
- internal TextBlock txtUpdateUnzip;
- internal ProgressBar pbUpdate;
- internal Image btnOpen;
- internal Image btnDownload;
- internal TextBlock txtPercent;
- internal TextBlock txtUnzip;
- internal ProgressBar pb;
- internal Image btnDelete;
- private bool _contentLoaded;
- public LawDataLaw lawDataLaw
- {
- get;
- set;
- }
- public Law_DownloadItemViewModel lawItem
- {
- get;
- set;
- }
- public string UserID
- {
- get;
- set;
- }
- public string UserName
- {
- get;
- set;
- }
- public string UserPWD
- {
- get;
- set;
- }
- public bool IsLastRow
- {
- get;
- set;
- }
- 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)
- {
- InitializeComponent();
- this.UserID = UserID;
- this.UserName = UserName;
- this.UserPWD = UserPWD;
- this.IsLastRow = IsLastRow;
- this.lawDataLaw = lawDataLaw;
- base.Loaded += LawRow_Loaded;
- LawListCT_HangTheDownloadEvent_Event = callback1;
- LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event = callback2;
- LawListCT_GetBookVMs_ByMeetingFileCate_Event = callback3;
- lawItem = new Law_DownloadItemViewModel();
- }
- private void LawRow_Loaded(object sender, RoutedEventArgs e)
- {
- txtDate.Text = lawDataLaw.UpDate.Split(' ')[0];
- txtLawName.Text = lawDataLaw.Name;
- Task.Factory.StartNew(delegate
- {
- InitSelectDB();
- base.Dispatcher.BeginInvoke((Action)delegate
- {
- InitUI();
- InitEvent();
- });
- });
- }
- private void InitSelectDB()
- {
- DataTable dataTable = new DataTable();
- LawDownloader instance = Singleton_LawDownloader.GetInstance();
- lawItem = instance.GetInList(lawDataLaw.ID);
- if (lawItem != null)
- {
- return;
- }
- string text = "";
- DateTime dateTime = DateTime.Parse("2010/01/01");
- string text2 = "";
- string text3 = "";
- long num = 0L;
- long num2 = 0L;
- dataTable = MSCE.GetDataTable("SELECT ID,AtDownloadFinished_XmlUpDate,Link,StorageFileName,DownloadBytes,TotalBytes FROM LawRow where ID=@1 and UserID=@2", lawDataLaw.ID, UserID);
- if (dataTable.Rows.Count > 0)
- {
- text = dataTable.Rows[0]["ID"].ToString();
- dateTime = (DateTime)dataTable.Rows[0]["AtDownloadFinished_XmlUpDate"];
- text2 = dataTable.Rows[0]["Link"].ToString();
- text3 = dataTable.Rows[0]["StorageFileName"].ToString();
- num = long.Parse(dataTable.Rows[0]["DownloadBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["DownloadBytes"].ToString());
- num2 = long.Parse(dataTable.Rows[0]["TotalBytes"].ToString().Equals("") ? "0" : dataTable.Rows[0]["TotalBytes"].ToString());
- }
- else
- {
- string text4 = "INSERT INTO LawRow(ID,AtDownloadFinished_XmlUpDate,DownloadBytes,TotalBytes,UserID) \r\n VALUES(@1,'2010/01/01',0,0,@2)";
- int num3 = MSCE.ExecuteNonQuery(text4, lawDataLaw.ID, UserID);
- if (num3 < 1)
- {
- LogTool.Debug(new Exception("DB失敗: " + text4));
- }
- }
- lawItem = new Law_DownloadItemViewModel();
- lawItem.ID = lawDataLaw.ID;
- lawItem.UserID = UserID;
- DateTime.TryParse(lawDataLaw.UpDate, out DateTime result);
- lawItem.UpDate = result;
- lawItem.Name = lawDataLaw.Name;
- lawItem.Link = lawDataLaw.Link;
- lawItem.Status = (LawDataStatus)Enum.Parse(typeof(LawDataStatus), lawDataLaw.Status);
- string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
- string law_StorageFileFolder = Settings.Default.Law_StorageFileFolder2;
- lawItem.StorageFileFolder = Path.Combine(baseDirectory, law_StorageFileFolder);
- string arg = DateTime.Now.ToFileTime().ToString();
- try
- {
- Uri uri = new Uri(lawItem.Link);
- string fileName = Path.GetFileName(uri.LocalPath);
- if (!fileName.Equals("/"))
- {
- arg = fileName;
- }
- }
- catch (Exception ex)
- {
- LogTool.Debug(ex);
- }
- lawItem.StorageFileName = $"{UserID}_{lawDataLaw.ID}_{arg}";
- lawItem.UnZipFileFolder = Path.Combine(ClickOnceTool.GetFilePath(), Settings.Default.Law_UnZipFileFolder);
- if (num == 0L || num < num2)
- {
- if (File.Exists(lawItem.StorageFilePath))
- {
- File.Delete(lawItem.StorageFilePath);
- }
- lawItem.DownloadBytes = 0L;
- lawItem.TotalBytes = 0L;
- lawItem.FileType = LawFileType.從未下載;
- }
- else if (TimeSpan.Compare(new TimeSpan(result.Ticks), new TimeSpan(dateTime.Ticks)) > 0)
- {
- lawItem.StorageFileName += ".update";
- lawItem.DownloadBytes = 0L;
- lawItem.TotalBytes = 0L;
- lawItem.FileType = LawFileType.更新檔未下載;
- }
- else
- {
- lawItem.FileType = LawFileType.已下載完成;
- }
- }
- private void InitEvent()
- {
- btnDownload.MouseEnter += delegate
- {
- MouseTool.ShowHand();
- };
- btnDownload.MouseLeave += delegate
- {
- MouseTool.ShowArrow();
- };
- btnDownload.MouseLeftButtonDown += btnDownload_MouseLeftButtonDown;
- btnDelete.MouseEnter += delegate
- {
- MouseTool.ShowHand();
- };
- btnDelete.MouseLeave += delegate
- {
- MouseTool.ShowArrow();
- };
- btnDelete.MouseLeftButtonDown += btnDelete_MouseLeftButtonDown;
- btnOpen.MouseEnter += delegate
- {
- MouseTool.ShowHand();
- };
- btnOpen.MouseLeave += delegate
- {
- MouseTool.ShowArrow();
- };
- btnOpen.MouseLeftButtonDown += btnOpen_MouseLeftButtonDown;
- btnUpdate.MouseEnter += delegate
- {
- MouseTool.ShowHand();
- };
- btnUpdate.MouseLeave += delegate
- {
- MouseTool.ShowArrow();
- };
- btnUpdate.MouseLeftButtonDown += btnDownload_MouseLeftButtonDown;
- if (IsAllLawRowFinished && LawListCT_HangTheDownloadEvent_Event != null)
- {
- LawListCT_HangTheDownloadEvent_Event(lawItem.ID);
- }
- }
- private void btnOpen_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- MouseTool.ShowLoading();
- try
- {
- string filePath = ClickOnceTool.GetFilePath();
- string _bookPath = lawItem.UnZipFilePath;
- string _bookId = "";
- string _account = "";
- string _userName = "";
- string _email = "";
- string _meetingId = "";
- string _watermark = "";
- string _dbPath = Path.Combine(ClickOnceTool.GetDataPath(), Settings.Default.bookInfo_Path);
- bool _isSync = false;
- bool _isSyncOwner = false;
- string _webServiceUrl = WsTool.GetUrl() + "/AnnotationUpload";
- string _socketMessage = "";
- Dictionary<string, BookVM> cbBooksData = null;
- Home Home_Window = Application.Current.Windows.OfType<Home>().FirstOrDefault();
- Home_Window.CloseAllWindow("", fromInit: true);
- Task.Factory.StartNew(delegate
- {
- base.Dispatcher.BeginInvoke((Action)delegate
- {
- ReadWindow readWindow = new ReadWindow(cbBooksData, Home_Window.OpenBookFromReader, _bookPath, _bookId, _account, _userName, _email, _meetingId, _watermark, _dbPath, _isSync, _isSyncOwner, _webServiceUrl, _socketMessage)
- {
- HideCollectFile = true,
- WindowStyle = WindowStyle.None,
- WindowStartupLocation = WindowStartupLocation.CenterScreen,
- WindowState = WindowState.Maximized
- };
- if (Settings.Default.AssemblyName.Contains("TPI4F"))
- {
- }
- readWindow.Show();
- });
- });
- }
- catch (Exception ex)
- {
- LogTool.Debug(ex);
- }
- MouseTool.ShowArrow();
- }
- private void btnDelete_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- MessageBoxResult messageBoxResult = MessageBox.Show("您確定要刪除檔案?", "系統訊息", MessageBoxButton.YesNo);
- if (messageBoxResult == MessageBoxResult.No)
- {
- return;
- }
- string text = "update LawRow set DownloadBytes=0,TotalBytes=0 where ID=@1 and UserID=@2";
- int num = MSCE.ExecuteNonQuery(text, lawDataLaw.ID, UserID);
- if (num < 1)
- {
- AutoClosingMessageBox.Show("刪除失敗");
- LogTool.Debug(new Exception("DB失敗: " + text));
- return;
- }
- if (File.Exists(lawItem.StorageFilePath))
- {
- File.Delete(lawItem.StorageFilePath);
- }
- ShowNeverDownload(fromBtnDelete: true);
- }
- private void btnDownload_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- if (lawItem != null)
- {
- btnDownload.Visibility = Visibility.Collapsed;
- txtPercent.Text = "等待中";
- txtPercent.Foreground = Brushes.Gray;
- txtPercent.Visibility = Visibility.Visible;
- pb.Foreground = Brushes.Wheat;
- pb.Background = Brushes.Gray;
- pb.Visibility = Visibility.Visible;
- if (lawItem.StorageFileName.EndsWith(".update"))
- {
- lawItem.FileType = LawFileType.更新檔排入下載中;
- }
- else
- {
- lawItem.FileType = LawFileType.排入下載中;
- }
- LawDownloader instance = Singleton_LawDownloader.GetInstance();
- instance.AddItem(lawItem);
- }
- }
- private void InitUI()
- {
- switch (lawItem.FileType)
- {
- case LawFileType.從未下載:
- ShowNeverDownload(fromBtnDelete: false);
- break;
- case LawFileType.正在下載中:
- ShowInDownload();
- txtPercent.Text = (int)lawItem.NowPercentage + " %";
- pb.Value = lawItem.NowPercentage;
- pb.Foreground = Brushes.Orange;
- pb.Background = Brushes.Black;
- txtPercent.Visibility = Visibility.Visible;
- pb.Visibility = Visibility.Visible;
- break;
- case LawFileType.已下載完成:
- ShowCanOpen();
- txtIsNew.Visibility = Visibility.Visible;
- break;
- case LawFileType.排入下載中:
- ShowInDownload();
- txtPercent.Text = "等待中";
- txtPercent.Foreground = Brushes.Gray;
- txtPercent.Visibility = Visibility.Visible;
- pb.Foreground = Brushes.Wheat;
- pb.Background = Brushes.Gray;
- pb.Visibility = Visibility.Visible;
- break;
- case LawFileType.解壓縮中:
- ((Storyboard)TryFindResource("sb"))?.Begin();
- break;
- case LawFileType.解壓縮失敗:
- ShowNeverDownload(fromBtnDelete: false);
- break;
- case LawFileType.更新檔未下載:
- ShowCanOpen();
- break;
- case LawFileType.更新檔暫停中:
- ShowCanOpen();
- break;
- case LawFileType.更新檔正在下載中:
- ShowCanOpen();
- break;
- case LawFileType.更新檔已下載完成:
- ShowCanOpen();
- break;
- case LawFileType.更新檔排入下載中:
- ShowCanOpen();
- txtUpdatePercent.Text = "等待中";
- txtIsNew.Foreground = Brushes.Gray;
- txtUpdatePercent.Visibility = Visibility.Visible;
- pb.Foreground = Brushes.Wheat;
- pb.Background = Brushes.Gray;
- pb.Visibility = Visibility.Visible;
- break;
- case LawFileType.更新檔解壓縮中:
- ((Storyboard)TryFindResource("sbUpdate"))?.Begin();
- break;
- case LawFileType.更新檔解壓縮失敗:
- ShowCanOpen();
- break;
- }
- if (LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event != null)
- {
- IsAllLawRowFinished = LawListCT_IsAllLawRowFinished_AddInitUIFinished_Event();
- }
- }
- private void HideAll()
- {
- btnDelete.Visibility = Visibility.Collapsed;
- btnOpen.Visibility = Visibility.Collapsed;
- btnUpdate.Visibility = Visibility.Collapsed;
- pb.Visibility = Visibility.Collapsed;
- txtIsNew.Visibility = Visibility.Collapsed;
- btnDownload.Visibility = Visibility.Visible;
- pbUpdate.Visibility = Visibility.Collapsed;
- txtUpdatePercent.Visibility = Visibility.Collapsed;
- }
- private void ShowNeverDownload(bool fromBtnDelete)
- {
- if (fromBtnDelete)
- {
- btnDelete.Visibility = Visibility.Collapsed;
- btnOpen.Visibility = Visibility.Collapsed;
- btnUpdate.Visibility = Visibility.Collapsed;
- pb.Visibility = Visibility.Collapsed;
- txtIsNew.Visibility = Visibility.Collapsed;
- pbUpdate.Visibility = Visibility.Collapsed;
- txtUpdatePercent.Visibility = Visibility.Collapsed;
- }
- btnDownload.Visibility = Visibility.Visible;
- }
- private void ShowInDownload()
- {
- }
- private void ShowCanOpen()
- {
- btnDelete.Visibility = Visibility.Visible;
- btnOpen.Visibility = Visibility.Visible;
- }
- [DebuggerNonUserCode]
- [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
- public void InitializeComponent()
- {
- if (!_contentLoaded)
- {
- _contentLoaded = true;
- Uri resourceLocator = new Uri("/PaperLess_Emeeting_Taichung;component/lawrow.xaml", UriKind.Relative);
- Application.LoadComponent(this, resourceLocator);
- }
- }
- [DebuggerNonUserCode]
- [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
- [EditorBrowsable(EditorBrowsableState.Never)]
- void IComponentConnector.Connect(int connectionId, object target)
- {
- switch (connectionId)
- {
- case 1:
- txtDate = (TextBlock)target;
- break;
- case 2:
- txtLawName = (TextBlock)target;
- break;
- case 3:
- btnUpdate = (Image)target;
- break;
- case 4:
- txtIsNew = (TextBlock)target;
- break;
- case 5:
- txtUpdatePercent = (TextBlock)target;
- break;
- case 6:
- txtUpdateUnzip = (TextBlock)target;
- break;
- case 7:
- pbUpdate = (ProgressBar)target;
- break;
- case 8:
- btnOpen = (Image)target;
- break;
- case 9:
- btnDownload = (Image)target;
- break;
- case 10:
- txtPercent = (TextBlock)target;
- break;
- case 11:
- txtUnzip = (TextBlock)target;
- break;
- case 12:
- pb = (ProgressBar)target;
- break;
- case 13:
- btnDelete = (Image)target;
- break;
- default:
- _contentLoaded = true;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment