BasicContainer.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Diagnostics;
  11. namespace AVSORTER
  12. {
  13. public partial class BasicContainer : UserControl
  14. {
  15. public BasicContainer()
  16. {
  17. InitializeComponent();
  18. this.pictureBox1.Visible = false;
  19. }
  20. MovieBasic movie;
  21. public bool IsShowPic { get; set; }
  22. public MovieBasic MovieB
  23. {
  24. get
  25. {
  26. return movie;
  27. }
  28. set
  29. {
  30. this.movie = value;
  31. if (this.movie!=null)
  32. {
  33. RefreshUI();
  34. }
  35. }
  36. }
  37. private List<MovieBasic> _listmovieBasic;
  38. public List<MovieBasic> ListMovieBasic
  39. {
  40. get
  41. {
  42. return _listmovieBasic;
  43. }
  44. set
  45. {
  46. if (value!=null && value.Count>0)
  47. {
  48. _listmovieBasic = value;
  49. this.btn_next.Visible = true;
  50. this.btn_pre.Visible = true;
  51. }
  52. }
  53. }
  54. int index = -1;
  55. private void RefreshUI()
  56. {
  57. this.txt_actor.Text = Tools.ListToString(this.movie.Actor);
  58. IsShowPic = this.cb_ShowPic.Checked;
  59. this.txt_labl.Text = movie.Label;
  60. this.txt_title.Text = movie.Title;
  61. this.txt_URL.Text = movie.ItemURL;
  62. this.txt_Maker.Text = movie.Maker;
  63. if (IsShowPic && string.IsNullOrEmpty(MovieB.Img_s_file))
  64. {
  65. this.pictureBox1.Visible = false;
  66. Gets.MyWebClient wc = new Gets.MyWebClient();
  67. wc.ReferURL = this.movie.ItemURL;
  68. string fi = this.movie.Title + ".jpg";
  69. fi = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"SmallImage",Path.ChangeExtension(fi, "jpg"));
  70. try
  71. {
  72. if (!Directory.Exists(Path.GetDirectoryName(fi)))
  73. {
  74. Directory.CreateDirectory(Path.GetDirectoryName(fi));
  75. }
  76. //wc.DownloadFile(movie.Img_s, fi);
  77. wc.DownloadFileCompleted += wc_DownloadFileCompleted;
  78. wc.DownloadProgressChanged += wc_DownloadProgressChanged;
  79. wc.DownloadFileAsync(new Uri(movie.Img_s), fi,fi);
  80. }
  81. catch (Exception s)
  82. {
  83. throw new Exception("下载缩略图失败!");
  84. }
  85. }
  86. else if(IsShowPic)
  87. {
  88. this.pictureBox1.Image = Image.FromFile(MovieB.Img_s_file);
  89. }
  90. }
  91. void wc_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)
  92. {
  93. // e.ProgressPercentage
  94. this.progressBar1.Value = e.ProgressPercentage;
  95. }
  96. void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
  97. {
  98. try
  99. {
  100. if (this.MovieB.Title == Path.GetFileNameWithoutExtension(e.UserState as string))
  101. {
  102. this.MovieB.Img_s_file = e.UserState as string;
  103. this.pictureBox1.Image = Image.FromFile(e.UserState as string);
  104. this.pictureBox1.Visible = true;
  105. }
  106. }
  107. catch
  108. {
  109. }
  110. }
  111. private void btn_ShowDetail_Click(object sender, EventArgs e)
  112. {
  113. Process.Start(this.MovieB.ItemURL);
  114. }
  115. private void txt_title_TextChanged(object sender, EventArgs e)
  116. {
  117. }
  118. private void btn_pre_Click(object sender, EventArgs e)
  119. {
  120. if (this.ListMovieBasic.Count>1)
  121. {
  122. this.index = this.ListMovieBasic.IndexOf(MovieB);
  123. if (this.index>0)
  124. {
  125. this.MovieB = this.ListMovieBasic[--index];
  126. }
  127. }
  128. else
  129. {
  130. this.btn_pre.Visible = false;
  131. }
  132. }
  133. private void btn_next_Click(object sender, EventArgs e)
  134. {
  135. if (this.ListMovieBasic.Count > 1)
  136. {
  137. this.index = this.ListMovieBasic.IndexOf(MovieB);
  138. if (this.index < this.ListMovieBasic.Count - 1)
  139. {
  140. this.MovieB = this.ListMovieBasic[++index];
  141. }
  142. }
  143. else
  144. {
  145. this.btn_next.Visible = false;
  146. }
  147. }
  148. private void btn_select_Click(object sender, EventArgs e)
  149. {
  150. }
  151. }
  152. }