DownLoadDetailWindow.xaml.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. using ivf_tl_Entity.Entity.DownLoad;
  2. using ivf_tl_Entity.Enums;
  3. using ivf_tl_Entity.Response;
  4. using ivf_tl_Manage.ViewModels;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. namespace ivf_tl_Manage.Win
  21. {
  22. /// <summary>
  23. /// DownLoadDetailWindow.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class DownLoadDetailWindow : Window
  26. {
  27. MainWindowViewModel vm;
  28. public DownLoadDetailWindow(MainWindowViewModel mainWindowViewModel)
  29. {
  30. InitializeComponent();
  31. vm = mainWindowViewModel;
  32. DataCount = vm.DownLoadFileList.Count;
  33. var aa = vm.DownLoadFileList.Take(pagesize);
  34. ShowDownLoadList.Clear();
  35. foreach (var item in aa)
  36. {
  37. ShowDownLoadList.Add(item);
  38. }
  39. this.Owner = AppData.Instance.MainWindow;
  40. Unloaded += (s, e) =>
  41. {
  42. this.Canvas_BigRoot.Children.Clear();
  43. AppData.Instance.MainWindow.Activate();
  44. };
  45. }
  46. private void Cancel_Click(object sender, RoutedEventArgs e)
  47. {
  48. this.DialogResult = true;
  49. return;
  50. }
  51. private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  52. {
  53. e.Handled = true;
  54. }
  55. private void ListBox_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e)
  56. {
  57. e.Handled = true;
  58. }
  59. private void Button_ClickEd(object sender, RoutedEventArgs e)
  60. {
  61. //if (vm.NewdownLoadFileList.TryDequeue(out DownLoadEntity result))
  62. //{
  63. // result.state = 4;
  64. //}
  65. //vm.ListdownLoadFileList.First().state = 4;
  66. //if (vm.NewdownLoadFileList.TryDequeue(out DownLoadEntity result))
  67. //{
  68. // result.state = 2;
  69. //}
  70. Task.Run(() =>
  71. {
  72. if (vm.DownLoadFileList.First().state == 2)
  73. {
  74. vm.DownLoadFileList.First().state = 3;
  75. }
  76. else
  77. {
  78. vm.DownLoadFileList.First().state = 2;
  79. }
  80. });
  81. }
  82. private void Button_Click(object sender, RoutedEventArgs e)
  83. {
  84. //vm.NewdownLoadFileList.Enqueue(new DownLoadEntity
  85. //{
  86. // DownLoadUrl = "123",
  87. // FileName = "filename",
  88. // NewFileFullName = "newfileName"
  89. //});
  90. //vm.ListdownLoadFileList.Add(new DownLoadEntity
  91. //{
  92. // DownLoadUrl = "123",
  93. // FileName = "filename",
  94. // NewFileFullName = "newfileName"
  95. //});
  96. vm.DownLoadFileList.First().state = 2;
  97. return;
  98. for (int i = 0; i < 100; i++)
  99. {
  100. vm.DownLoadFileList.Add(new DownLoadEntity
  101. {
  102. DownLoadUrl = "123",
  103. FileName = i.ToString(),
  104. NewFileFullName = "newfileName"
  105. });
  106. }
  107. return;
  108. Task.Run(() =>
  109. {
  110. vm.NewdownLoadFileList.Enqueue(new DownLoadEntity
  111. {
  112. DownLoadUrl = "123",
  113. FileName = "filename",
  114. NewFileFullName = "newfileName"
  115. });
  116. });
  117. //Task.Run(async () =>
  118. //{
  119. // while (true)
  120. // {
  121. // var a = vm.DownLoadQueue.Dequeue();
  122. // if (a != null)
  123. // {
  124. // a.state = (int)DownLoadEnum.DownLoad;
  125. // await Task.Delay(1000);
  126. // continue;
  127. // }
  128. // return;
  129. // }
  130. //});
  131. }
  132. private void Button_Click_1(object sender, RoutedEventArgs e)
  133. {
  134. if (!(sender is Button button)) return;
  135. if (!(button.Tag is DownLoadEntity downLoadEntity)) return;
  136. //string fileName = "C:\\PersonalSpace\\work\\1 VisualWorkSpace\\Personal\\Git\\ivf_tl_Manage_2.0\\ivf_tl_Manage\\Resources\\1.ico";
  137. string fileName = downLoadEntity.NewFileFullName;
  138. if (string.IsNullOrEmpty(fileName))
  139. {
  140. return;
  141. }
  142. if (File.Exists(fileName))
  143. {
  144. OpenFolderAndSelectFile(fileName);
  145. }
  146. else
  147. {
  148. System.Diagnostics.Process.Start("explorer.exe", Path.GetDirectoryName(fileName));
  149. }
  150. }
  151. private void ReDown_Click_1(object sender, RoutedEventArgs e)
  152. {
  153. if (!(sender is Button button)) return;
  154. if (!(button.Tag is DownLoadEntity downLoadEntity)) return;
  155. AppData.Instance.MainWindowViewModel.DownLoadStart(downLoadEntity);
  156. //AppData.Instance.MainWindowViewModel.DownLoadStart(new ivf_tl_Entity.Entity.DownLoad.DownLoadEntity
  157. //{
  158. // DownLoadUrl = downLoadEntity.DownLoadUrl,
  159. // NewFileFullName = downLoadEntity.NewFileFullName,
  160. // FileName = downLoadEntity.FileName,
  161. // Body = downLoadEntity.Body,
  162. //});
  163. }
  164. [DllImport("shell32.dll", ExactSpelling = true)]
  165. private static extern void ILFree(IntPtr pidlList);
  166. [DllImport("shell32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
  167. private static extern IntPtr ILCreateFromPathW(string pszPath);
  168. [DllImport("shell32.dll", ExactSpelling = true)]
  169. private static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cild, IntPtr children, uint dwFlags);
  170. public void OpenFolderAndSelectFile(string filePath)
  171. {
  172. IntPtr pidl = ILCreateFromPathW(filePath);
  173. SHOpenFolderAndSelectItems(pidl, 0, IntPtr.Zero, 0);
  174. ILFree(pidl);
  175. }
  176. private void PaginationUserControl_PageChangedEvent(UserControls.PaginationUserControl arg1, int arg2)
  177. {
  178. if (!this.IsLoaded || !arg1.IsLoaded) return;
  179. PageCurrent = arg2;
  180. var aa = vm.DownLoadFileList.Skip((PageCurrent - 1) * pagesize).Take(pagesize);
  181. ShowDownLoadList.Clear();
  182. foreach (var item in aa)
  183. {
  184. ShowDownLoadList.Add(item);
  185. }
  186. }
  187. public int pagesize = 10;
  188. public int PageCurrent
  189. {
  190. get { return (int)GetValue(PageCurrentProperty); }
  191. set { SetValue(PageCurrentProperty, value); }
  192. }
  193. // Using a DependencyProperty as the backing store for PageCurrent. This enables animation, styling, binding, etc...
  194. public static readonly DependencyProperty PageCurrentProperty =
  195. DependencyProperty.Register("PageCurrent", typeof(int), typeof(DownLoadDetailWindow), new PropertyMetadata(1));
  196. public int DataCount
  197. {
  198. get { return (int)GetValue(DataCountProperty); }
  199. set { SetValue(DataCountProperty, value); }
  200. }
  201. // Using a DependencyProperty as the backing store for DataCount. This enables animation, styling, binding, etc...
  202. public static readonly DependencyProperty DataCountProperty =
  203. DependencyProperty.Register("DataCount", typeof(int), typeof(DownLoadDetailWindow), new PropertyMetadata(-1));
  204. public ObservableCollection<DownLoadEntity> ShowDownLoadList
  205. {
  206. get { return (ObservableCollection<DownLoadEntity>)GetValue(ShowDownLoadListProperty); }
  207. set { SetValue(ShowDownLoadListProperty, value); }
  208. }
  209. // Using a DependencyProperty as the backing store for ShowDownLoadList. This enables animation, styling, binding, etc...
  210. public static readonly DependencyProperty ShowDownLoadListProperty =
  211. DependencyProperty.Register("ShowDownLoadList", typeof(ObservableCollection<DownLoadEntity>), typeof(DownLoadDetailWindow), new PropertyMetadata(new ObservableCollection<DownLoadEntity>()));
  212. }
  213. }