⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.cs

📁 这是一个小型的相片管理器
💻 CS
字号:


using System;
using VirtualPhotoOrganizer.Dialogs;
using VirtualPhotoOrganizer.Photo;

namespace VirtualPhotoOrganizer.Util
{
	/// <summary>
	/// handles the searching for photos
	/// </summary>
	internal class Search
	{
		public struct SearchResult
		{
			public Album Album;
			public Photo.Photo Photo;
		}

		public struct SearchType
		{
			public bool Title;
			public bool Description;
			public bool TimeTaken;
			public bool Path;
			public bool MatchCase;
		}

		private SearchDialog Sd;
		private string[] Patterns;
		private Albums TargetAlbums;
		private SearchType SType;
		private bool Abort = false;
		public delegate void SearchResultUpdate(SearchResult sr);
		public event SearchResultUpdate ResultUpdate;

		public Search(SearchDialog sd, string[] keywords, Albums searchAlbums, SearchType sType) {
			Sd = sd;
			if (!sType.MatchCase) {
				Patterns = new string[keywords.Length];
				for (int i = 0; i < Patterns.Length; i++) 
					Patterns[i] = keywords[i].ToLower();
			} else
				Patterns = keywords;
			TargetAlbums = searchAlbums;
			SType = sType;
			Sd.EndSearchNow += new SearchDialog.EndSearch(Sd_EndSearchNow);
		}

		void Sd_EndSearchNow() {
			Abort = true;
		}

		public void ExecuteSearch() {
			SearchResult sr = new SearchResult();
			foreach (Album a in TargetAlbums) {
				foreach (Photo.Photo p in a.Photos) {
					System.Windows.Forms.Application.DoEvents();
					if (Abort)
						return;
					if (SType.Title) {
						if (ContainsKeyword(p.Title))
							goto AddToResults;
					}
					if (SType.Description) {
						if (ContainsKeyword(p.Description))
							goto AddToResults;
					}
					if (SType.TimeTaken) {
						if (ContainsKeyword(p.TimeTaken))
							goto AddToResults;
					}
					if (SType.Path) {
						if (ContainsKeyword(p.Path))
							goto AddToResults;
					}
					continue;

				AddToResults:
					sr.Album = a;
					sr.Photo = p;
					ResultUpdate(sr);

				}
			}
		}

		private bool ContainsKeyword(string text) {
			if (!SType.MatchCase)
				text = text.ToLower();
			foreach (string s in Patterns) {
				if (text.IndexOf(s) == -1)
					return false;
			}
			return true;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -