PageRenderTime 42ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 1ms

/JMMClient/JMMClient/Forms/GroupFilterConditionForm.xaml.cs

https://bitbucket.org/gibwar/jmm-test
C# | 839 lines | 651 code | 169 blank | 19 comment | 104 complexity | 8432be5196e0f051c514a507110be9f9 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. using JMMClient.ViewModel;
  14. using System.ComponentModel;
  15. using System.Collections.ObjectModel;
  16. using System.Globalization;
  17. namespace JMMClient.Forms
  18. {
  19. /// <summary>
  20. /// Interaction logic for GroupFilterConditionForm.xaml
  21. /// </summary>
  22. public partial class GroupFilterConditionForm : Window
  23. {
  24. public GroupFilterVM groupFilter = null;
  25. public GroupFilterConditionVM groupFilterCondition = null;
  26. public ICollectionView ViewGroups { get; set; }
  27. public ObservableCollection<AnimeGroupVM> AllGroups { get; set; }
  28. public ICollectionView ViewCategoryNames { get; set; }
  29. public ObservableCollection<string> AllCategoryNames { get; set; }
  30. public ObservableCollection<string> AllVideoQuality { get; set; }
  31. public ObservableCollection<string> AllAnimeTypes { get; set; }
  32. public ObservableCollection<string> AllAudioLanguages { get; set; }
  33. public ObservableCollection<string> AllSubtitleLanguages { get; set; }
  34. public static readonly DependencyProperty IsParameterDateProperty = DependencyProperty.Register("IsParameterDate",
  35. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  36. public bool IsParameterDate
  37. {
  38. get { return (bool)GetValue(IsParameterDateProperty); }
  39. set { SetValue(IsParameterDateProperty, value); }
  40. }
  41. public static readonly DependencyProperty IsParameterAnimeGroupProperty = DependencyProperty.Register("IsParameterAnimeGroup",
  42. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  43. public bool IsParameterAnimeGroup
  44. {
  45. get { return (bool)GetValue(IsParameterAnimeGroupProperty); }
  46. set { SetValue(IsParameterAnimeGroupProperty, value); }
  47. }
  48. public static readonly DependencyProperty IsParameterAnimeTypeProperty = DependencyProperty.Register("IsParameterAnimeType",
  49. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  50. public bool IsParameterAnimeType
  51. {
  52. get { return (bool)GetValue(IsParameterAnimeTypeProperty); }
  53. set { SetValue(IsParameterAnimeTypeProperty, value); }
  54. }
  55. public static readonly DependencyProperty IsParameterTextProperty = DependencyProperty.Register("IsParameterText",
  56. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  57. public bool IsParameterText
  58. {
  59. get { return (bool)GetValue(IsParameterTextProperty); }
  60. set { SetValue(IsParameterTextProperty, value); }
  61. }
  62. public static readonly DependencyProperty IsParameterInNotInProperty = DependencyProperty.Register("IsParameterInNotIn",
  63. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  64. public bool IsParameterInNotIn
  65. {
  66. get { return (bool)GetValue(IsParameterInNotInProperty); }
  67. set { SetValue(IsParameterInNotInProperty, value); }
  68. }
  69. public static readonly DependencyProperty IsParameterCategoryProperty = DependencyProperty.Register("IsParameterCategory",
  70. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  71. public bool IsParameterCategory
  72. {
  73. get { return (bool)GetValue(IsParameterCategoryProperty); }
  74. set { SetValue(IsParameterCategoryProperty, value); }
  75. }
  76. public static readonly DependencyProperty IsParameterVideoQualityProperty = DependencyProperty.Register("IsParameterVideoQuality",
  77. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  78. public bool IsParameterVideoQuality
  79. {
  80. get { return (bool)GetValue(IsParameterVideoQualityProperty); }
  81. set { SetValue(IsParameterVideoQualityProperty, value); }
  82. }
  83. public static readonly DependencyProperty IsParameterAudioLanguageProperty = DependencyProperty.Register("IsParameterAudioLanguage",
  84. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  85. public bool IsParameterAudioLanguage
  86. {
  87. get { return (bool)GetValue(IsParameterAudioLanguageProperty); }
  88. set { SetValue(IsParameterAudioLanguageProperty, value); }
  89. }
  90. public static readonly DependencyProperty IsParameterSubtitleLanguageProperty = DependencyProperty.Register("IsParameterSubtitleLanguage",
  91. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  92. public bool IsParameterSubtitleLanguage
  93. {
  94. get { return (bool)GetValue(IsParameterSubtitleLanguageProperty); }
  95. set { SetValue(IsParameterSubtitleLanguageProperty, value); }
  96. }
  97. public static readonly DependencyProperty IsParameterRatingProperty = DependencyProperty.Register("IsParameterRating",
  98. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  99. public bool IsParameterRating
  100. {
  101. get { return (bool)GetValue(IsParameterRatingProperty); }
  102. set { SetValue(IsParameterRatingProperty, value); }
  103. }
  104. public static readonly DependencyProperty IsParameterIntegerProperty = DependencyProperty.Register("IsParameterInteger",
  105. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  106. public bool IsParameterInteger
  107. {
  108. get { return (bool)GetValue(IsParameterIntegerProperty); }
  109. set { SetValue(IsParameterIntegerProperty, value); }
  110. }
  111. public static readonly DependencyProperty IsParameterLastXDaysProperty = DependencyProperty.Register("IsParameterLastXDays",
  112. typeof(bool), typeof(GroupFilterConditionForm), new UIPropertyMetadata(false, null));
  113. public bool IsParameterLastXDays
  114. {
  115. get { return (bool)GetValue(IsParameterLastXDaysProperty); }
  116. set { SetValue(IsParameterLastXDaysProperty, value); }
  117. }
  118. public GroupFilterConditionForm()
  119. {
  120. InitializeComponent();
  121. txtGroupSearch.TextChanged += new TextChangedEventHandler(txtGroupSearch_TextChanged);
  122. btnClearGroupSearch.Click += new RoutedEventHandler(btnClearGroupSearch_Click);
  123. txtCategorySearch.TextChanged += new TextChangedEventHandler(txtCategorySearch_TextChanged);
  124. btnClearCategorySearch.Click += new RoutedEventHandler(btnClearCategorySearch_Click);
  125. btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
  126. btnConfirm.Click += new RoutedEventHandler(btnConfirm_Click);
  127. lbCategories.MouseDoubleClick += new MouseButtonEventHandler(lbCategories_MouseDoubleClick);
  128. lbVideoQuality.MouseDoubleClick += new MouseButtonEventHandler(lbVideoQuality_MouseDoubleClick);
  129. lbAnimeTypes.MouseDoubleClick += new MouseButtonEventHandler(lbAnimeTypes_MouseDoubleClick);
  130. lbAudioLanguages.MouseDoubleClick += new MouseButtonEventHandler(lbAudioLanguages_MouseDoubleClick);
  131. lbSubtitleLanguages.MouseDoubleClick += new MouseButtonEventHandler(lbSubtitleLanguages_MouseDoubleClick);
  132. }
  133. void btnConfirm_Click(object sender, RoutedEventArgs e)
  134. {
  135. // get the details from the form
  136. groupFilterCondition.ConditionType = (int)GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
  137. groupFilterCondition.ConditionOperator = (int)GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.SelectedItem.ToString());
  138. NumberStyles style = NumberStyles.Number;
  139. CultureInfo culture = CultureInfo.CreateSpecificCulture("en-GB");
  140. // get the parameter details
  141. if (IsParameterDate)
  142. {
  143. if (dpDate.SelectedDate == null)
  144. {
  145. MessageBox.Show(Properties.Resources.MSG_ERR_SelectDate, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  146. dpDate.Focus();
  147. return;
  148. }
  149. else
  150. {
  151. groupFilterCondition.ConditionParameter = GroupFilterHelper.GetDateAsString(dpDate.SelectedDate.Value);
  152. }
  153. }
  154. if (IsParameterRating)
  155. {
  156. if (txtParameter.Text.Trim().Length == 0)
  157. {
  158. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  159. txtParameter.Focus();
  160. return;
  161. }
  162. else
  163. {
  164. decimal dRating = -1;
  165. decimal.TryParse(txtParameter.Text, style, culture, out dRating);
  166. if (dRating <= 0 || dRating > 10)
  167. {
  168. MessageBox.Show(Properties.Resources.MSG_ERR_RatingValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  169. txtParameter.Focus();
  170. return;
  171. }
  172. groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
  173. }
  174. }
  175. if (IsParameterInteger)
  176. {
  177. if (txtParameter.Text.Trim().Length == 0)
  178. {
  179. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  180. txtParameter.Focus();
  181. return;
  182. }
  183. else
  184. {
  185. int parmInt = -1;
  186. if (!int.TryParse(txtParameter.Text, out parmInt))
  187. {
  188. MessageBox.Show("Please enter an integer value only", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  189. txtParameter.Focus();
  190. return;
  191. }
  192. groupFilterCondition.ConditionParameter = parmInt.ToString();
  193. }
  194. }
  195. if (IsParameterLastXDays)
  196. {
  197. if (txtParameter.Text.Trim().Length == 0)
  198. {
  199. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  200. txtParameter.Focus();
  201. return;
  202. }
  203. else
  204. {
  205. int days = -1;
  206. int.TryParse(txtParameter.Text, out days);
  207. if (days < 1 || days > int.MaxValue)
  208. {
  209. MessageBox.Show(Properties.Resources.MSG_ERR_DaysValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  210. txtParameter.Focus();
  211. return;
  212. }
  213. groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
  214. }
  215. }
  216. if (IsParameterCategory)
  217. {
  218. if (txtSelectedCategories.Text.Trim().Length == 0)
  219. {
  220. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  221. txtParameter.Focus();
  222. return;
  223. }
  224. else
  225. {
  226. // validate
  227. string[] cats = txtSelectedCategories.Text.Trim().Split(',');
  228. groupFilterCondition.ConditionParameter = "";
  229. foreach (string cat in cats)
  230. {
  231. if (cat.Trim().Length == 0) continue;
  232. if (cat.Trim() == ",") continue;
  233. if (groupFilterCondition.ConditionParameter.Length > 0) groupFilterCondition.ConditionParameter += ",";
  234. groupFilterCondition.ConditionParameter += cat;
  235. }
  236. }
  237. }
  238. if (IsParameterVideoQuality)
  239. {
  240. if (txtSelectedVideoQuality.Text.Trim().Length == 0)
  241. {
  242. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  243. txtParameter.Focus();
  244. return;
  245. }
  246. else
  247. {
  248. // validate
  249. string[] vidQuals = txtSelectedVideoQuality.Text.Trim().Split(',');
  250. groupFilterCondition.ConditionParameter = "";
  251. foreach (string vidq in vidQuals)
  252. {
  253. if (vidq.Trim().Length == 0) continue;
  254. if (vidq.Trim() == ",") continue;
  255. if (groupFilterCondition.ConditionParameter.Length > 0) groupFilterCondition.ConditionParameter += ",";
  256. groupFilterCondition.ConditionParameter += vidq;
  257. }
  258. }
  259. }
  260. if (IsParameterAudioLanguage)
  261. {
  262. if (txtSelectedAudioLanguages.Text.Trim().Length == 0)
  263. {
  264. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  265. txtParameter.Focus();
  266. return;
  267. }
  268. else
  269. {
  270. // validate
  271. string[] languages = txtSelectedAudioLanguages.Text.Trim().Split(',');
  272. groupFilterCondition.ConditionParameter = "";
  273. foreach (string lanName in languages)
  274. {
  275. if (lanName.Trim().Length == 0) continue;
  276. if (lanName.Trim() == ",") continue;
  277. if (groupFilterCondition.ConditionParameter.Length > 0) groupFilterCondition.ConditionParameter += ",";
  278. groupFilterCondition.ConditionParameter += lanName;
  279. }
  280. }
  281. }
  282. if (IsParameterSubtitleLanguage)
  283. {
  284. if (txtSelectedSubtitleLanguages.Text.Trim().Length == 0)
  285. {
  286. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  287. txtParameter.Focus();
  288. return;
  289. }
  290. else
  291. {
  292. // validate
  293. string[] languages = txtSelectedSubtitleLanguages.Text.Trim().Split(',');
  294. groupFilterCondition.ConditionParameter = "";
  295. foreach (string lanName in languages)
  296. {
  297. if (lanName.Trim().Length == 0) continue;
  298. if (lanName.Trim() == ",") continue;
  299. if (groupFilterCondition.ConditionParameter.Length > 0) groupFilterCondition.ConditionParameter += ",";
  300. groupFilterCondition.ConditionParameter += lanName;
  301. }
  302. }
  303. }
  304. if (IsParameterAnimeType)
  305. {
  306. if (txtSelectedAnimeTypes.Text.Trim().Length == 0)
  307. {
  308. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  309. txtParameter.Focus();
  310. return;
  311. }
  312. else
  313. {
  314. // validate
  315. string[] aTypes = txtSelectedAnimeTypes.Text.Trim().Split(',');
  316. groupFilterCondition.ConditionParameter = "";
  317. foreach (string aType in aTypes)
  318. {
  319. if (aType.Trim().Length == 0) continue;
  320. if (aType.Trim() == ",") continue;
  321. if (groupFilterCondition.ConditionParameter.Length > 0) groupFilterCondition.ConditionParameter += ",";
  322. groupFilterCondition.ConditionParameter += aType;
  323. }
  324. }
  325. }
  326. if (IsParameterAnimeGroup)
  327. {
  328. if (lbGroups.SelectedItem == null)
  329. {
  330. MessageBox.Show(Properties.Resources.MSG_ERR_GroupSelectionRequired, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  331. lbGroups.Focus();
  332. return;
  333. }
  334. else
  335. {
  336. AnimeGroupVM grp = lbGroups.SelectedItem as AnimeGroupVM;
  337. groupFilterCondition.ConditionParameter = grp.AnimeGroupID.Value.ToString();
  338. }
  339. }
  340. if (IsParameterText)
  341. {
  342. if (txtParameter.Text.Trim().Length == 0)
  343. {
  344. MessageBox.Show(Properties.Resources.MSG_ERR_EnterValue, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
  345. txtParameter.Focus();
  346. return;
  347. }
  348. else
  349. {
  350. groupFilterCondition.ConditionParameter = txtParameter.Text.Trim();
  351. }
  352. }
  353. this.DialogResult = true;
  354. this.Close();
  355. }
  356. void btnCancel_Click(object sender, RoutedEventArgs e)
  357. {
  358. this.DialogResult = false;
  359. this.Close();
  360. }
  361. private void EvaluateConditionsAndOperators()
  362. {
  363. if (cboConditionType.SelectedItem == null || cboConditionOperator.SelectedItem == null) return;
  364. GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
  365. GroupFilterOperator opType = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.SelectedItem.ToString());
  366. IsParameterDate = false;
  367. IsParameterAnimeGroup = false;
  368. IsParameterAnimeType = false;
  369. IsParameterText = false;
  370. IsParameterInNotIn = false;
  371. IsParameterCategory = false;
  372. IsParameterRating = false;
  373. IsParameterLastXDays = false;
  374. IsParameterVideoQuality = false;
  375. IsParameterAudioLanguage = false;
  376. IsParameterSubtitleLanguage = false;
  377. IsParameterInteger = false;
  378. switch (conditionType)
  379. {
  380. case GroupFilterConditionType.AirDate:
  381. case GroupFilterConditionType.SeriesCreatedDate:
  382. case GroupFilterConditionType.EpisodeAddedDate:
  383. case GroupFilterConditionType.EpisodeWatchedDate:
  384. if (opType == GroupFilterOperator.LastXDays)
  385. {
  386. IsParameterLastXDays = true;
  387. IsParameterText = true;
  388. }
  389. else
  390. IsParameterDate = true;
  391. break;
  392. case GroupFilterConditionType.AnimeGroup:
  393. IsParameterAnimeGroup = true;
  394. break;
  395. case GroupFilterConditionType.AnimeType:
  396. IsParameterAnimeType = true; break;
  397. case GroupFilterConditionType.ReleaseGroup:
  398. case GroupFilterConditionType.Studio:
  399. IsParameterInNotIn = true; break;
  400. case GroupFilterConditionType.Category:
  401. IsParameterInNotIn = true;
  402. IsParameterCategory = true;
  403. break;
  404. case GroupFilterConditionType.AudioLanguage:
  405. IsParameterInNotIn = true;
  406. IsParameterAudioLanguage = true;
  407. break;
  408. case GroupFilterConditionType.SubtitleLanguage:
  409. IsParameterInNotIn = true;
  410. IsParameterSubtitleLanguage = true;
  411. break;
  412. case GroupFilterConditionType.VideoQuality:
  413. IsParameterInNotIn = true;
  414. IsParameterVideoQuality = true;
  415. break;
  416. case GroupFilterConditionType.AniDBRating:
  417. case GroupFilterConditionType.UserRating:
  418. IsParameterText = true;
  419. IsParameterRating = true;
  420. break;
  421. case GroupFilterConditionType.EpisodeCount:
  422. IsParameterText = true;
  423. IsParameterInteger = true;
  424. break;
  425. }
  426. }
  427. void cboConditionOperator_SelectionChanged(object sender, SelectionChangedEventArgs e)
  428. {
  429. EvaluateConditionsAndOperators();
  430. }
  431. void cboConditionType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  432. {
  433. GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
  434. cboConditionOperator.Items.Clear();
  435. foreach (string op in GroupFilterHelper.GetAllowedOperators(conditionType))
  436. cboConditionOperator.Items.Add(op);
  437. cboConditionOperator.SelectedIndex = 0;
  438. EvaluateConditionsAndOperators();
  439. }
  440. private void PopulateCategories()
  441. {
  442. AllCategoryNames = new ObservableCollection<string>();
  443. ViewCategoryNames = CollectionViewSource.GetDefaultView(AllCategoryNames);
  444. List<string> catsRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllCategoryNames();
  445. foreach (string cat in catsRaw)
  446. AllCategoryNames.Add(cat);
  447. ViewCategoryNames.Filter = CategoryFilter;
  448. }
  449. private void PopulateVideoQuality()
  450. {
  451. AllVideoQuality = new ObservableCollection<string>();
  452. List<string> vidsRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllUniqueVideoQuality();
  453. vidsRaw.Sort();
  454. foreach (string vidq in vidsRaw)
  455. AllVideoQuality.Add(vidq);
  456. }
  457. private void PopulateLanguages()
  458. {
  459. AllAudioLanguages = new ObservableCollection<string>();
  460. List<string> audioRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllUniqueAudioLanguages();
  461. audioRaw.Sort();
  462. foreach (string aud in audioRaw)
  463. AllAudioLanguages.Add(aud);
  464. AllSubtitleLanguages = new ObservableCollection<string>();
  465. List<string> subRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllUniqueSubtitleLanguages();
  466. subRaw.Sort();
  467. foreach (string sub in subRaw)
  468. AllSubtitleLanguages.Add(sub);
  469. }
  470. private void PopulateAnimeTypes()
  471. {
  472. AllAnimeTypes = new ObservableCollection<string>();
  473. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_Movie);
  474. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_Other);
  475. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_OVA);
  476. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_TVSeries);
  477. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_TVSpecial);
  478. AllAnimeTypes.Add(JMMClient.Properties.Resources.AnimeType_Web);
  479. }
  480. private void PopulateAnimeGroups()
  481. {
  482. AllGroups = new ObservableCollection<AnimeGroupVM>();
  483. ViewGroups = CollectionViewSource.GetDefaultView(AllGroups);
  484. ViewGroups.SortDescriptions.Add(new SortDescription("SortName", ListSortDirection.Ascending));
  485. List<JMMServerBinary.Contract_AnimeGroup> grpsRaw = JMMServerVM.Instance.clientBinaryHTTP.GetAllGroups(JMMServerVM.Instance.CurrentUser.JMMUserID.Value);
  486. foreach (JMMServerBinary.Contract_AnimeGroup grp in grpsRaw)
  487. {
  488. AnimeGroupVM grpNew = new AnimeGroupVM(grp);
  489. AllGroups.Add(grpNew);
  490. }
  491. ViewGroups.Filter = GroupSearchFilter;
  492. }
  493. public void Init(GroupFilterVM gf, GroupFilterConditionVM gfc)
  494. {
  495. groupFilter = gf;
  496. groupFilterCondition = gfc;
  497. try
  498. {
  499. cboConditionType.Items.Clear();
  500. foreach (string cond in GroupFilterHelper.GetAllConditionTypes())
  501. cboConditionType.Items.Add(cond);
  502. PopulateAnimeGroups();
  503. PopulateCategories();
  504. PopulateVideoQuality();
  505. PopulateAnimeTypes();
  506. PopulateLanguages();
  507. // find the right condition
  508. int idx = 0;
  509. for (int i = 0; i < cboConditionType.Items.Count; i++ )
  510. {
  511. GroupFilterConditionType conditionTypeTemp = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.Items[i].ToString());
  512. if (conditionTypeTemp == gfc.ConditionTypeEnum)
  513. {
  514. idx = i;
  515. break;
  516. }
  517. }
  518. cboConditionType.SelectedIndex = idx;
  519. GroupFilterConditionType conditionType = GroupFilterHelper.GetEnumForText_ConditionType(cboConditionType.SelectedItem.ToString());
  520. cboConditionOperator.Items.Clear();
  521. foreach (string op in GroupFilterHelper.GetAllowedOperators(conditionType))
  522. cboConditionOperator.Items.Add(op);
  523. cboConditionType.SelectionChanged += new SelectionChangedEventHandler(cboConditionType_SelectionChanged);
  524. cboConditionOperator.SelectionChanged += new SelectionChangedEventHandler(cboConditionOperator_SelectionChanged);
  525. // find the right operator
  526. idx = 0;
  527. for (int i = 0; i < cboConditionOperator.Items.Count; i++)
  528. {
  529. GroupFilterOperator opTypeTemp = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.Items[i].ToString());
  530. if (opTypeTemp == gfc.ConditionOperatorEnum)
  531. {
  532. idx = i;
  533. break;
  534. }
  535. }
  536. cboConditionOperator.SelectedIndex = idx;
  537. GroupFilterOperator opType = GroupFilterHelper.GetEnumForText_Operator(cboConditionOperator.Items[idx].ToString());
  538. // display the selected filter value
  539. switch (conditionType)
  540. {
  541. case GroupFilterConditionType.AirDate:
  542. case GroupFilterConditionType.SeriesCreatedDate:
  543. case GroupFilterConditionType.EpisodeAddedDate:
  544. case GroupFilterConditionType.EpisodeWatchedDate:
  545. if (opType == GroupFilterOperator.LastXDays)
  546. txtParameter.Text = gfc.ConditionParameter;
  547. else
  548. {
  549. DateTime airDate = GroupFilterHelper.GetDateFromString(gfc.ConditionParameter);
  550. dpDate.SelectedDate = airDate;
  551. }
  552. break;
  553. case GroupFilterConditionType.AnimeGroup:
  554. // don't display anything
  555. break;
  556. case GroupFilterConditionType.AnimeType:
  557. case GroupFilterConditionType.Category:
  558. case GroupFilterConditionType.ReleaseGroup:
  559. case GroupFilterConditionType.Studio:
  560. case GroupFilterConditionType.VideoQuality:
  561. case GroupFilterConditionType.AniDBRating:
  562. case GroupFilterConditionType.UserRating:
  563. case GroupFilterConditionType.AudioLanguage:
  564. case GroupFilterConditionType.SubtitleLanguage:
  565. txtParameter.Text = gfc.ConditionParameter;
  566. break;
  567. }
  568. }
  569. catch (Exception ex)
  570. {
  571. Utils.ShowErrorMessage(ex);
  572. }
  573. }
  574. private bool GroupSearchFilter(object obj)
  575. {
  576. AnimeGroupVM grpvm = obj as AnimeGroupVM;
  577. if (grpvm == null) return true;
  578. return GroupSearchFilterHelper.EvaluateGroupTextSearch(grpvm, txtGroupSearch.Text);
  579. }
  580. private bool CategoryFilter(object obj)
  581. {
  582. string catName = obj as string;
  583. if (catName == null) return true;
  584. int index = catName.IndexOf(txtCategorySearch.Text.Trim(), 0, StringComparison.InvariantCultureIgnoreCase);
  585. if (index > -1) return true;
  586. return false;
  587. }
  588. void txtGroupSearch_TextChanged(object sender, TextChangedEventArgs e)
  589. {
  590. ViewGroups.Refresh();
  591. }
  592. void btnClearGroupSearch_Click(object sender, RoutedEventArgs e)
  593. {
  594. txtGroupSearch.Text = "";
  595. }
  596. void btnClearCategorySearch_Click(object sender, RoutedEventArgs e)
  597. {
  598. txtCategorySearch.Text = "";
  599. }
  600. void txtCategorySearch_TextChanged(object sender, TextChangedEventArgs e)
  601. {
  602. ViewCategoryNames.Refresh();
  603. }
  604. void lbSubtitleLanguages_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  605. {
  606. object obj = lbSubtitleLanguages.SelectedItem;
  607. if (obj == null) return;
  608. string lanName = obj.ToString();
  609. string currentList = txtSelectedSubtitleLanguages.Text.Trim();
  610. // add to the selected list
  611. int index = currentList.IndexOf(lanName, 0, StringComparison.InvariantCultureIgnoreCase);
  612. if (index > -1) return;
  613. if (currentList.Length > 0) currentList += ",";
  614. currentList += lanName;
  615. txtSelectedSubtitleLanguages.Text = currentList;
  616. }
  617. void lbAudioLanguages_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  618. {
  619. object obj = lbAudioLanguages.SelectedItem;
  620. if (obj == null) return;
  621. string lanName = obj.ToString();
  622. string currentList = txtSelectedAudioLanguages.Text.Trim();
  623. // add to the selected list
  624. int index = currentList.IndexOf(lanName, 0, StringComparison.InvariantCultureIgnoreCase);
  625. if (index > -1) return;
  626. if (currentList.Length > 0) currentList += ",";
  627. currentList += lanName;
  628. txtSelectedAudioLanguages.Text = currentList;
  629. }
  630. void lbVideoQuality_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  631. {
  632. object obj = lbVideoQuality.SelectedItem;
  633. if (obj == null) return;
  634. string vidQual = obj.ToString();
  635. string currentList = txtSelectedVideoQuality.Text.Trim();
  636. // add to the selected list
  637. int index = currentList.IndexOf(vidQual, 0, StringComparison.InvariantCultureIgnoreCase);
  638. if (index > -1) return;
  639. if (currentList.Length > 0) currentList += ",";
  640. currentList += vidQual;
  641. txtSelectedVideoQuality.Text = currentList;
  642. }
  643. void lbAnimeTypes_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  644. {
  645. object obj = lbAnimeTypes.SelectedItem;
  646. if (obj == null) return;
  647. string aType = obj.ToString();
  648. string currentList = txtSelectedAnimeTypes.Text.Trim();
  649. // add to the selected list
  650. int index = currentList.IndexOf(aType, 0, StringComparison.InvariantCultureIgnoreCase);
  651. if (index > -1) return;
  652. if (currentList.Length > 0) currentList += ",";
  653. currentList += aType;
  654. txtSelectedAnimeTypes.Text = currentList;
  655. }
  656. void lbCategories_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  657. {
  658. object obj = lbCategories.SelectedItem;
  659. if (obj == null) return;
  660. string catName = obj.ToString();
  661. string currentList = txtSelectedCategories.Text.Trim();
  662. // add to the selected list
  663. int index = currentList.IndexOf(catName, 0, StringComparison.InvariantCultureIgnoreCase);
  664. if (index > -1) return;
  665. if (currentList.Length > 0) currentList += ",";
  666. currentList += catName;
  667. txtSelectedCategories.Text = currentList;
  668. }
  669. }
  670. }