コード例 #1
0
        public static string TryAddPhoto(DBioPhotoContext dbContext, Photo tryPhoto)
        {
            // No photo selected
            if (tryPhoto.FileName == null || tryPhoto.FileName == "" || tryPhoto.FilePath == null || tryPhoto.FilePath == "")
            {
                return("Zvolte fotku");
            }

            // Photo already in db, update
            else if (dbContext.Photos.Any(p => p.FilePath == tryPhoto.FilePath))
            {
                Photo existingPhoto = dbContext.Photos.FirstOrDefault(p => p.FilePath == tryPhoto.FilePath);
                existingPhoto.Category = tryPhoto.Category;
                existingPhoto.Comment  = tryPhoto.Comment;
                existingPhoto.Location = tryPhoto.Location;
                dbContext.SaveChanges();
                return("Úspěšně aktualizováno!");
            }

            // Add to db
            else
            {
                dbContext.Photos.Add(tryPhoto);
                dbContext.SaveChanges();
                return("Úspěšně přidáno!");
            }
        }
コード例 #2
0
        public static bool TryAddOrganismToPhoto(DBioPhotoContext dbContext, string photoRelativePath, string organismFirstName, string organismSecondName)
        {
            Photo    photo    = dbContext.Photos.Where(p => p.FilePath == photoRelativePath).Include(p => p.Organisms).FirstOrDefault();
            Organism organism = dbContext.Organisms.Where(o => o.FirstName == organismFirstName && o.SecondName == organismSecondName).FirstOrDefault();

            // If the organism didn't have second name, then the SecondName is LatFirstName in fact
            if (organism == null)
            {
                organism = dbContext.Organisms.Where(o => o.FirstName == organismFirstName && o.LatFirstName == organismSecondName).FirstOrDefault();
            }
            if (photo == null || organism == null)
            {
                return(false);
            }
            else if (photo.Organisms.Contains(organism))
            {
                return(false);
            }
            else
            {
                photo.Organisms.Add(organism);
                dbContext.SaveChanges();
                return(true);
            }
        }
コード例 #3
0
        public SearchingForm()
        {
            InitializeComponent();

            untilDateTimePicker.Value = DateTime.Now;

            // Populate the basedOnComboBox
            basedOnComboBox.DataSource = new string[] { "Nic dalšího", "Český název organimu", "Latinský název organismu", "Jméno osoby", "Typ a barva organismu" };

            // Populate the combo boxes with data from enums
            categoryComboBox.DataSource       = Enum.GetValues(typeof(Category));
            organismTypeComboBox.DataSource   = Enum.GetValues(typeof(OrganismType));
            organismColourComboBox.DataSource = Enum.GetValues(typeof(Colour));

            // Create the DbContexts
            _searchingContext   = new DBioPhotoContext(Global.DbFilePath);
            _suggestionsContext = new DBioPhotoContext(Global.DbFilePath);

            // Create the BackgroundWorker for loading of images, bind tasks for him
            LoadingImagesBgWorker                     = new BackgroundWorker();
            LoadingImagesBgWorker.DoWork             += new DoWorkEventHandler(LoadingImagesBgWorker_DoWork);
            LoadingImagesBgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(LoadingImagesBgWorker_RunWorkerEventCompleted);

            // Set all textboxes to autocomplete
            _suggestions = new AutoCompleteStringCollection();
            locationTextBox.AutoCompleteCustomSource      = _suggestions;
            commentTextBox.AutoCompleteCustomSource       = _suggestions;
            czFirstNameTextBox.AutoCompleteCustomSource   = _suggestions;
            czSecondNameTextBox.AutoCompleteCustomSource  = _suggestions;
            latFirstNameTextBox.AutoCompleteCustomSource  = _suggestions;
            latSecondNameTextBox.AutoCompleteCustomSource = _suggestions;
            personNameTextBox.AutoCompleteCustomSource    = _suggestions;
            personSurnameTextBox.AutoCompleteCustomSource = _suggestions;
            personNickTextBox.AutoCompleteCustomSource    = _suggestions;
        }
コード例 #4
0
 public static string TryAddOrganism(DBioPhotoContext dbContext, Organism tryOrganism)
 {
     if (tryOrganism.FirstName == "" || tryOrganism.LatFirstName == "")
     {
         return("Vyplňte název");
     }
     else if (dbContext.Organisms
              .Any(o => o.FirstName == tryOrganism.FirstName &&
                   (o.SecondName == tryOrganism.SecondName)))
     {
         return("Organismus již existuje");
     }
     else if (dbContext.Organisms
              .Any(o => o.LatFirstName == tryOrganism.LatFirstName &&
                   (o.LatSecondName == tryOrganism.LatSecondName)))
     {
         return("Organismus již existuje");
     }
     else
     {
         dbContext.Organisms.Add(tryOrganism);
         dbContext.SaveChanges();
         return("Úspěšně přidáno!");
     }
 }
コード例 #5
0
ファイル: Suggestions.cs プロジェクト: b0r3k/DBioPhoto
        public static string[] GetOrganismNameSuggestions(DBioPhotoContext dbContext, string beginning, int textBoxNumber)
        {
            string[] suggestions;
            switch (textBoxNumber)
            {
            case 0:
                suggestions = dbContext.Organisms.Where(o => o.FirstName.StartsWith(beginning.ToLower())).Select(o => o.FirstName).Distinct().ToArray();
                break;

            case 1:
                suggestions = dbContext.Organisms.Where(o => o.SecondName.StartsWith(beginning.ToLower())).Select(o => o.SecondName).Distinct().ToArray();
                break;

            case 2:
                suggestions = dbContext.Organisms.Where(o => o.LatFirstName.StartsWith(beginning.ToLower())).Select(o => o.LatFirstName).Distinct().ToArray();
                break;

            case 3:
                suggestions = dbContext.Organisms.Where(o => o.LatSecondName.StartsWith(beginning.ToLower())).Select(o => o.LatSecondName).Distinct().ToArray();
                break;

            default:
                suggestions = new string[0];
                break;
            }
            return(suggestions);
        }
コード例 #6
0
ファイル: AddingForm.cs プロジェクト: b0r3k/DBioPhoto
        public AddingForm()
        {
            InitializeComponent();
            this.Location = new System.Drawing.Point(0, 0);

            // Populate the combo box with data from enum
            categoryComboBox.DataSource = Enum.GetValues(typeof(Category));

            // Create the DbContexts
            _photoAddingContext          = new DBioPhotoContext(Global.DbFilePath);
            _photoInfoSuggestionsContext = new DBioPhotoContext(Global.DbFilePath);
            _photoContentContext         = new DBioPhotoContext(Global.DbFilePath);

            // Create the BackgroundWorker for loading of images, bind tasks for him
            LoadingImagesBgWorker                     = new BackgroundWorker();
            LoadingImagesBgWorker.DoWork             += new DoWorkEventHandler(LoadingImagesBgWorker_DoWork);
            LoadingImagesBgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(LoadingImagesBgWorker_RunWorkerEventCompleted);

            // Set location and comment textboxes to autocomplete
            _photoInfoSuggestions = new AutoCompleteStringCollection();
            locationTextBox.AutoCompleteCustomSource = _photoInfoSuggestions;
            commentTextBox.AutoCompleteCustomSource  = _photoInfoSuggestions;

            // Set photo content textboxes to autocomplete
            _photoContentSuggestions = new AutoCompleteStringCollection();
            organismNameTextBox.AutoCompleteCustomSource     = _photoContentSuggestions;
            personNameOrNickTextBox.AutoCompleteCustomSource = _photoContentSuggestions;
        }
コード例 #7
0
        public static (List <Organism>, List <Person>) GetPhotoContent(DBioPhotoContext dbContext, string fileRelativePath)
        {
            var             photoQuery       = dbContext.Photos.Where(p => p.FilePath == fileRelativePath);
            List <Organism> organismsOnPhoto = photoQuery.Select(p => p.Organisms).ToList().FirstOrDefault();
            List <Person>   peopleOnPhoto    = photoQuery.Select(p => p.People).ToList().FirstOrDefault();

            return(organismsOnPhoto, peopleOnPhoto);
        }
コード例 #8
0
        public static void RemovePersonFromPhoto(DBioPhotoContext dbContext, string fileRelativePath, int indexInList)
        {
            Photo photo = dbContext.Photos.Where(p => p.FilePath == fileRelativePath).Include(p => p.People).FirstOrDefault();

            if (indexInList < photo.People.Count)
            {
                photo.People.RemoveAt(indexInList);
            }
            dbContext.SaveChanges();
        }
コード例 #9
0
 // Lock dbcontext and query the searched stuff from there
 private void SearchPhotoLocking(DBioPhotoContext dbContext, int basedOn, string[] names, ValueTuple <OrganismType, Colour> organismTypeColour,
                                 ValueTuple <Category, DateTime, DateTime, string, string> photoInfo)
 {
     string[] photosFound;
     lock (dbContext)
     {
         photosFound = SearchPhotos.SearchPhoto(dbContext, basedOn, names, organismTypeColour, photoInfo);
     }
     _imageRelativePaths = photosFound;
 }
コード例 #10
0
        public PersonAddForm()
        {
            InitializeComponent();

            // Set all the textboxes to autocomplete
            _nameSuggestions = new AutoCompleteStringCollection();
            nameTextBox.AutoCompleteCustomSource    = _nameSuggestions;
            surnameTextBox.AutoCompleteCustomSource = _nameSuggestions;
            nickTextBox.AutoCompleteCustomSource    = _nameSuggestions;

            // Initialize DbContexts
            _addingContext      = new DBioPhotoContext(Global.DbFilePath);
            _suggestionsContext = new DBioPhotoContext(Global.DbFilePath);
        }
コード例 #11
0
ファイル: OrganismAddForm.cs プロジェクト: b0r3k/DBioPhoto
        public OrganismAddForm()
        {
            InitializeComponent();

            // Populate the combo boxes with data from enums
            organismTypeComboBox.DataSource = Enum.GetValues(typeof(OrganismType));
            colourComboBox.DataSource       = Enum.GetValues(typeof(Colour));

            // Create the DbContexts
            _addingContext      = new DBioPhotoContext(Global.DbFilePath);
            _suggestionsContext = new DBioPhotoContext(Global.DbFilePath);

            // Set all the textboxes to autocomplete
            _nameSuggestions = new AutoCompleteStringCollection();
            firstNameTextBox.AutoCompleteCustomSource     = _nameSuggestions;
            secondNameTextBox.AutoCompleteCustomSource    = _nameSuggestions;
            latFirstNameTextBox.AutoCompleteCustomSource  = _nameSuggestions;
            latSecondNameTextBox.AutoCompleteCustomSource = _nameSuggestions;
        }
コード例 #12
0
ファイル: Suggestions.cs プロジェクト: b0r3k/DBioPhoto
        public static string[] GetPhotoInfoSuggestions(DBioPhotoContext dbContext, string beginning, int textBoxNumber)
        {
            string[] suggestions;
            switch (textBoxNumber)
            {
            case 0:
                suggestions = dbContext.Photos.Where(p => p.Location.StartsWith(beginning.ToLower())).Select(p => p.Location).Distinct().ToArray();
                break;

            case 1:
                suggestions = dbContext.Photos.Where(p => p.Comment.StartsWith(beginning.ToLower())).Select(p => p.Comment).Distinct().ToArray();
                break;

            default:
                suggestions = new string[0];
                break;
            }
            return(suggestions);
        }
コード例 #13
0
 public static string TryAddPerson(DBioPhotoContext dbContext, Person tryPerson)
 {
     if (tryPerson.Name == "" || tryPerson.Surname == "")
     {
         return("Vyplňte jméno");
     }
     else if (dbContext.People
              .Any(p => (p.Name == tryPerson.Name) &&
                   (p.Surname == tryPerson.Surname) &&
                   (p.Nickname == tryPerson.Nickname)))
     {
         return("Člověk již existuje");
     }
     else
     {
         dbContext.People.Add(tryPerson);
         dbContext.SaveChanges();
         return("Úspěšně přidáno!");
     }
 }
コード例 #14
0
        public static bool TryAddPersonToPhoto(DBioPhotoContext dbContext, string photoRelativePath, string personName, string personSurname)
        {
            Photo  photo  = dbContext.Photos.Where(p => p.FilePath == photoRelativePath).Include(p => p.People).FirstOrDefault();
            Person person = dbContext.People.Where(p => p.Name == personName && p.Surname == personSurname).FirstOrDefault();

            if (photo == null || person == null)
            {
                return(false);
            }
            else if (photo.People.Contains(person))
            {
                return(false);
            }
            else
            {
                photo.People.Add(person);
                dbContext.SaveChanges();
                return(true);
            }
        }
コード例 #15
0
ファイル: Suggestions.cs プロジェクト: b0r3k/DBioPhoto
        public static string[] GetPhotoContentSuggestions(DBioPhotoContext dbContext, string beginning, int textBoxNumber)
        {
            string[] suggestions;
            switch (textBoxNumber)
            {
            case 0:
                suggestions = dbContext.Organisms.Where(o => o.FirstName.StartsWith(beginning.ToLower()) || o.LatFirstName.StartsWith(beginning.ToLower()))
                              .Select(o => o.ToString()).Distinct().ToArray();
                break;

            case 1:
                suggestions = dbContext.People
                              .Where(p => p.Name.StartsWith(beginning.ToLower()) || p.Nickname.StartsWith(beginning.ToLower()) || p.Surname.StartsWith(beginning.ToLower()))
                              .Select(p => p.ToString()).Distinct().ToArray();
                break;

            default:
                suggestions = new string[0];
                break;
            }
            return(suggestions);
        }
コード例 #16
0
ファイル: Suggestions.cs プロジェクト: b0r3k/DBioPhoto
        public static string[] GetPersonNameSuggestions(DBioPhotoContext dbContext, string beginning, int textBoxNumber)
        {
            string[] suggestions;
            switch (textBoxNumber)
            {
            case 0:
                suggestions = dbContext.People.Where(p => p.Name.StartsWith(beginning.ToLower())).Select(p => p.Name).Distinct().ToArray();
                break;

            case 1:
                suggestions = dbContext.People.Where(p => p.Surname.StartsWith(beginning.ToLower())).Select(p => p.Surname).Distinct().ToArray();
                break;

            case 2:
                suggestions = dbContext.People.Where(p => p.Nickname.StartsWith(beginning.ToLower())).Select(p => p.Nickname).Distinct().ToArray();
                break;

            default:
                suggestions = new string[0];
                break;
            }
            return(suggestions);
        }
コード例 #17
0
ファイル: SearchPhotos.cs プロジェクト: b0r3k/DBioPhoto
        public static string[] SearchPhoto(DBioPhotoContext dbContext, int basedOn, string[] names, ValueTuple <OrganismType, Colour> organismTypeColour,
                                           ValueTuple <Category, DateTime, DateTime, string, string> photoInfo)
        {
            string[]           photosFound;
            IQueryable <Photo> photosQuery = dbContext.Photos.AsQueryable();

            switch (basedOn)
            {
            case 0:
                break;

            case 1:
                if (names[1] != "")
                {
                    photosQuery = dbContext.Organisms
                                  .Where(o => o.FirstName == names[0] && o.SecondName == names[1])
                                  .SelectMany(o => o.Photos);
                }
                else
                {
                    photosQuery = dbContext.Organisms.Where(o => o.FirstName == names[0]).SelectMany(o => o.Photos);
                }
                break;

            case 2:
                if (names[1] != "")
                {
                    photosQuery = dbContext.Organisms.Where(o => o.LatFirstName == names[0] && o.LatSecondName == names[1]).SelectMany(o => o.Photos);
                }
                else
                {
                    photosQuery = dbContext.Organisms.Where(o => o.LatFirstName == names[0]).SelectMany(o => o.Photos);
                }
                break;

            case 3:
                if (names[2] != "")
                {
                    photosQuery = dbContext.People.Where(p => p.Name == names[0] && p.Surname == names[1] && p.Nickname == names[2]).SelectMany(p => p.Photos);
                }
                else
                {
                    photosQuery = dbContext.People.Where(p => p.Name == names[0] && p.Surname == names[1]).SelectMany(p => p.Photos);
                }
                break;

            case 4:
                photosQuery = dbContext.Organisms.Where(o => o.OrganismType == organismTypeColour.Item1 && o.Colour == organismTypeColour.Item2).SelectMany(o => o.Photos);
                break;
            }
            (Category cat, DateTime frDate, DateTime untDate, string loc, string com) = photoInfo;
            if (cat != Category.Vše)
            {
                photosQuery = photosQuery.Where(p => p.Category == cat);
            }
            photosQuery = photosQuery.Where(p => p.TimeCreated.Date >= frDate.Date && p.TimeCreated.Date <= untDate.Date);
            if (loc != "")
            {
                photosQuery = photosQuery.Where(p => p.Location.Contains(loc.Trim().ToLower()));
            }
            if (com != "")
            {
                photosQuery = photosQuery.Where(p => p.Comment.Contains(com.Trim().ToLower()));
            }

            photosFound = photosQuery.OrderBy(p => p.TimeCreated).Select(p => p.FilePath).ToArray();
            return(photosFound);
        }