Form1.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.Threading;
  11. namespace PicSo
  12. {
  13. public partial class Form1 : Form
  14. {
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. ListView.CheckForIllegalCrossThreadCalls = false;
  19. }
  20. private void Form1_Load(object sender, EventArgs e)
  21. {
  22. arzon = new Gets.Arzon(false);
  23. arzon.InitCompleted += arzon_InitCompleted;
  24. arzon.CookiesInit();
  25. var f = AVSORTER.FileProcessor.GetInstance();
  26. this.txt_Dest.Text = f.DestPath;
  27. this.txt_sub.Text = f.SubPath;
  28. }
  29. void arzon_InitCompleted(object sender, EventArgs e)
  30. {
  31. lbl_YouMaStatus.BackColor = Color.Green;
  32. }
  33. Gets.Arzon arzon;
  34. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  35. {
  36. }
  37. bool lastSort;
  38. private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
  39. {
  40. try
  41. {
  42. this.listView1.ListViewItemSorter = new ListViewColumnSorter(e.Column, !lastSort);
  43. lastSort = !lastSort;
  44. }
  45. catch (Exception)
  46. {
  47. }
  48. }
  49. //void Go()
  50. //{
  51. // try
  52. // {
  53. // for (int i = 0; i < this.listView1.Items.Count; i++)
  54. // {
  55. // this.listView1.Items[i].SubItems.Add("查询品番...");
  56. // var mbs = arzon.Query(this.listView1.Items[i].SubItems[1].Text);
  57. // if (mbs.Count == 1)
  58. // {
  59. // this.bc.MovieB = mbs[0];
  60. // this.listView1.Items[i].SubItems[2].Text = "下载封面...";
  61. // var mv = arzon.GetMovie(this.bc.MovieB);
  62. // arzon.GetCover(mv);
  63. // this.listView1.Items[i].SubItems[2].Text = "完成";
  64. // f.MakeMove(mv, listView1.Items[i].Text);
  65. // }
  66. // else
  67. // {
  68. // this.listView1.Items[i].SubItems[2].Text = "未找到";
  69. // }
  70. // }
  71. // }
  72. // finally
  73. // {
  74. // f.WriteLog();
  75. // }
  76. //}
  77. private void textBox2_TextChanged(object sender, EventArgs e)
  78. {
  79. }
  80. private void btn_Clear_Click(object sender, EventArgs e)
  81. {
  82. this.listView1.Items.Clear();
  83. this.listView1.ListViewItemSorter = null;
  84. AVSORTER.FileProcessor.GetInstance().Files.Clear();
  85. }
  86. private void btn_removeItem_Click(object sender, EventArgs e)
  87. {
  88. while (this.listView1.SelectedItems.Count > 0)
  89. {
  90. this.listView1.Items.Remove(this.listView1.SelectedItems[0]);
  91. }
  92. }
  93. private void btn_brower_Click(object sender, EventArgs e)
  94. {
  95. FolderBrowserDialog fbd = new FolderBrowserDialog();
  96. if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  97. {
  98. var f = AVSORTER.FileProcessor.GetInstance();
  99. f.AddDirectory(fbd.SelectedPath);
  100. List<ListViewItem> li = new List<ListViewItem>();
  101. for (int i = 0; i < f.Files.Count; i++)
  102. {
  103. li.Add(new ListViewItem(f.Files[i]));
  104. }
  105. this.listView1.Items.AddRange(li.ToArray());
  106. }
  107. for (int i = 0; i < this.listView1.Items.Count; i++)
  108. {
  109. this.listView1.Items[i].SubItems.Add(AVSORTER.Tools.Fcode(Path.GetFileNameWithoutExtension(this.listView1.Items[i].Text)));
  110. this.listView1.Items[i].SubItems.Add("");
  111. }
  112. }
  113. void initFileProcessor()
  114. {
  115. var f = AVSORTER.FileProcessor.GetInstance();
  116. if (f != null)
  117. {
  118. f.DestPath = txt_Dest.Text;
  119. f.SubPath = txt_sub.Text;
  120. f.ShowLog = cb_IsShowlog.Checked;
  121. new AVSORTER.DB.AVDB().SetDestPath(f.DestPath);
  122. new AVSORTER.DB.AVDB().SetSubPath(f.SubPath);
  123. }
  124. }
  125. private void btn_GO_Click(object sender, EventArgs e)
  126. {
  127. foreach (ListViewItem item in listView1.Items)
  128. {
  129. var fi = new AVSORTER.SearchItem(item.SubItems[1].Text, arzon.Clone() as AVSORTER.IGetable);
  130. item.Tag = fi;
  131. fi.OnStatusChange += fi_OnStatusChange;
  132. fi.Tag = item;
  133. fi.IsAutoSelect = cb_AutoSelect.Checked;
  134. fi.IsDownloadCover = cb_isCoverDownload.Checked;
  135. fi.StartQuery();
  136. }
  137. }
  138. void fi_OnStatusChange(object sender, AVSORTER.SearchItem.StatusChangeEventArgs e)
  139. {
  140. ((sender as AVSORTER.SearchItem).Tag as ListViewItem).SubItems[2].Text = e.After.ToString();
  141. }
  142. private void UIParamChange(object sender, EventArgs e)
  143. {
  144. }
  145. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  146. {
  147. if (listView1.SelectedItems.Count == 1)
  148. {
  149. if (listView1.SelectedItems[0].Tag != null)
  150. {
  151. var si = (listView1.SelectedItems[0].Tag as AVSORTER.SearchItem);
  152. this.bc.ListMovieBasic = si.MovieBasicList;
  153. if (si.IsSelected)
  154. {
  155. this.bc.MovieB = si.SelectedMovieBasic;
  156. }
  157. else if (si.MovieBasicList != null && si.MovieBasicList.Count != 0)
  158. {
  159. this.bc.MovieB = si.MovieBasicList[0];
  160. }
  161. }
  162. }
  163. }
  164. private void btn_select_Click(object sender, EventArgs e)
  165. {
  166. if (listView1.SelectedItems.Count == 1)
  167. {
  168. if (listView1.SelectedItems[0].Tag != null)
  169. {
  170. (listView1.SelectedItems[0].Tag as AVSORTER.SearchItem).Select(this.bc.MovieB);
  171. }
  172. }
  173. }
  174. private void btn_MoveFile_Click(object sender, EventArgs e)
  175. {
  176. this.btn_MoveFile.Enabled = false;
  177. initFileProcessor();
  178. foreach (ListViewItem item in listView1.Items)
  179. {
  180. if ((item.Tag as AVSORTER.SearchItem).IsSelected == true)
  181. {
  182. if (item.Text!="No File")
  183. {
  184. AVSORTER.FileProcessor.GetInstance().MakeMove((item.Tag as AVSORTER.SearchItem).MovieDetail, item.Text);
  185. item.SubItems[2].Text = "移动成功!";
  186. }
  187. else
  188. {
  189. item.SubItems[2].Text = "未移动";
  190. }
  191. }
  192. else
  193. {
  194. item.SubItems[2].Text = "未指定对应影片信息";
  195. }
  196. }
  197. AVSORTER.FileProcessor.GetInstance().WriteLog();
  198. this.btn_MoveFile.Enabled = true;
  199. }
  200. private void menu_BrowerFile_Click(object sender, EventArgs e)
  201. {
  202. if (listView1.SelectedItems.Count > 0)
  203. {
  204. System.Diagnostics.Process.Start("Explorer.exe", "/select, " + listView1.SelectedItems[0].Text);
  205. }
  206. }
  207. private void menu_ChangeFcode_Click(object sender, EventArgs e)
  208. {
  209. var inp = new InputBox();
  210. if (inp.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  211. {
  212. listView1.SelectedItems[0].SubItems[1].Text = inp.InputText;
  213. }
  214. }
  215. private void menu_remove_Click(object sender, EventArgs e)
  216. {
  217. while (this.listView1.SelectedItems.Count > 0)
  218. {
  219. this.listView1.Items.Remove(this.listView1.SelectedItems[0]);
  220. }
  221. }
  222. private void listView1_DragDrop(object sender, DragEventArgs e)
  223. {
  224. if (e.Data.GetDataPresent(DataFormats.FileDrop) && e.Effect == DragDropEffects.Link)
  225. {
  226. var dd = e.Data.GetData(DataFormats.FileDrop);
  227. var f = AVSORTER.FileProcessor.GetInstance();
  228. this.txt_Dest.Text = f.DestPath;
  229. this.txt_sub.Text = f.SubPath;
  230. var arr = dd as string[];
  231. foreach (var item in arr)
  232. {
  233. f.AddDirectory(item);
  234. }
  235. List<ListViewItem> li = new List<ListViewItem>();
  236. for (int i = 0; i < f.Files.Count; i++)
  237. {
  238. var lsvi = new ListViewItem(f.Files[i]);
  239. lsvi.SubItems.Add(AVSORTER.Tools.Fcode(Path.GetFileNameWithoutExtension(f.Files[i])));
  240. lsvi.SubItems.Add("");
  241. li.Add(lsvi);
  242. }
  243. this.listView1.Items.Clear();
  244. this.listView1.Items.AddRange(li.ToArray());
  245. }
  246. }
  247. private void listView1_DragEnter(object sender, DragEventArgs e)
  248. {
  249. e.Effect = DragDropEffects.Link;
  250. }
  251. private void bc_Load(object sender, EventArgs e)
  252. {
  253. }
  254. private void groupBox1_Enter(object sender, EventArgs e)
  255. {
  256. }
  257. private void menu_BigCover_Click(object sender, EventArgs e)
  258. {
  259. if (this.listView1.SelectedItems.Count > 0)
  260. {
  261. var d = (listView1.SelectedItems[0].Tag as AVSORTER.SearchItem).MovieDetail;
  262. if (d != null)
  263. {
  264. System.Diagnostics.Process.Start(d.CoverFile);
  265. }
  266. }
  267. }
  268. private void btn_AddNewEmptyItem_Click(object sender, EventArgs e)
  269. {
  270. var li = new ListViewItem("No File");
  271. li.SubItems.Add(AVSORTER.Tools.Fcode(this.txt_EmptyItemKeyWord.Text));
  272. li.SubItems.Add("");
  273. this.listView1.Items.Add(li);
  274. }
  275. private void listView1_DoubleClick(object sender, EventArgs e)
  276. {
  277. if (this.listView1.SelectedItems.Count > 0)
  278. {
  279. var d = (listView1.SelectedItems[0].Tag as AVSORTER.SearchItem);
  280. if (d.MovieDetail != null && !string.IsNullOrEmpty(d.MovieDetail.CoverFile))
  281. {
  282. System.Diagnostics.Process.Start(d.MovieDetail.CoverFile);
  283. }
  284. }
  285. }
  286. private void btn_rebuild_Click(object sender, EventArgs e)
  287. {
  288. this.btn_MoveFile.Enabled = false;
  289. initFileProcessor();
  290. foreach (ListViewItem item in listView1.Items)
  291. {
  292. if ((item.Tag as AVSORTER.SearchItem).IsSelected == true)
  293. {
  294. if (item.Text != "No File")
  295. {
  296. AVSORTER.FileProcessor.GetInstance().MakeDataBase((item.Tag as AVSORTER.SearchItem).MovieDetail, item.Text);
  297. item.SubItems[2].Text = "成功!";
  298. }
  299. else
  300. {
  301. item.SubItems[2].Text = "未动";
  302. }
  303. }
  304. else
  305. {
  306. item.SubItems[2].Text = "未指定对应影片信息";
  307. }
  308. }
  309. AVSORTER.FileProcessor.GetInstance().WriteLog();
  310. this.btn_MoveFile.Enabled = true;
  311. }
  312. #region Page2
  313. private void btn_LocalSearch_Click(object sender, EventArgs e)
  314. {
  315. string fc = txt_LocalSearchKeyWord.Text;
  316. if (cb_AutoCorrect.Checked)
  317. {
  318. fc = AVSORTER.Tools.Fcode(txt_LocalSearchKeyWord.Text);
  319. txt_LocalSearchKeyWord.Text = fc;
  320. }
  321. var db = new AVSORTER.DB.AVDB();
  322. var l = db.QueryAV(fc);
  323. this.movieContainer1.MovieList = l;
  324. this.listBox1.DataSource = l;
  325. //this.listBox1.DisplayMember = string.Format("{0}:{1}", "AVCode", "Title");
  326. if (l.Count > 0)
  327. {
  328. this.movieContainer1.Movie = l[0];
  329. }
  330. }
  331. private void txt_LocalSearchKeyWord_KeyPress(object sender, KeyPressEventArgs e)
  332. {
  333. if (e.KeyChar==13)
  334. {
  335. btn_LocalSearch_Click(sender, e);
  336. }
  337. }
  338. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  339. {
  340. if (this.listBox1.SelectedItems.Count>0)
  341. {
  342. this.movieContainer1.Movie = (this.listBox1.SelectedItem as AVSORTER.Movie);
  343. }
  344. }
  345. #endregion
  346. }
  347. }