Exemple #1
0
        private void LoadCategories()
        {
            var categories = new List <ListViewItem>();

            CategoryList.Items.Clear();
            DBRequests.MakeRequest(DBRequests.LoadCategories(), (connection, sqlCommand) =>
            {
                using (var reader = sqlCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            categories.Add(new ListViewItem(reader.GetString(0)));
                        }
                    }

                    CategoryList.Alignment = ListViewAlignment.Left;
                    CategoryList.Dock      = DockStyle.Fill;
                    CategoryList.View      = View.List;

                    // Initialize the tile size.
                    CategoryList.TileSize = new Size(100, 25);
                    CategoryList.Items.AddRange(categories.ToArray());
                }
            });
        }
Exemple #2
0
 private void SelectCategoryBtn_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.ChangePhotoCategory(_activePhoto.ID, _categories[CategoryList.SelectedIndices[0]].ID), (connection, command) =>
     {
         using (var reader = command.ExecuteReader())
         {
             CategoryLabel.Text = _categories[CategoryList.SelectedIndices[0]].Name;
         }
     });
 }
Exemple #3
0
 private void RemovePhotoBtn_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.DeletePhoto(_activePhoto.ID), (connection, sqlCommand) =>
     {
         sqlCommand.ExecuteNonQuery();
         var view = new AlbumManager();
         view.Show();
         Hide();
     });
 }
Exemple #4
0
 private void ChangePhotoName_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.RenamePhoto(_activePhoto.ID, PhotoNameTextBox.Text), (connection, command) =>
     {
         using (var reader = command.ExecuteReader())
         {
             NameLabel.Text = PhotoNameTextBox.Text;
         }
     });
 }
Exemple #5
0
 private void ChangePhotoDesc_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.ChangePhotoDescription(_activePhoto.ID, PhotoDescTextBox.Text), (connection, command) =>
     {
         using (var reader = command.ExecuteReader())
         {
             PhotoDescriptionLabel.Text = PhotoDescTextBox.Text;
         }
     }
                            );
 }
Exemple #6
0
 private void ChangeCategoryNameBtn_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.RenameCategory(CategoryList.SelectedItems[0].Text, ChangeCategoryNameTextBox.Text), (connection, sqlCommand) =>
     {
         Console.WriteLine(connection);
         Console.WriteLine(sqlCommand);
         using (var reader = sqlCommand.ExecuteReader())
         {
             Console.WriteLine(reader);
             LoadCategories();
         }
     });
 }
Exemple #7
0
 private void AddCategoryBtn_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.CreateCategory(NewCategoryNameTextBox.Text), (connection, sqlCommand) =>
     {
         Console.WriteLine(connection);
         Console.WriteLine(sqlCommand);
         using (var reader = sqlCommand.ExecuteReader())
         {
             Console.WriteLine(reader);
             LoadCategories();
         }
     });
 }
Exemple #8
0
 private void RemoveAlbumBtn_Click(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.DeleteAlbum(AlbumList.SelectedItems[0].ToString()), (connection, sqlCommand) =>
     {
         Console.WriteLine(connection);
         Console.WriteLine(sqlCommand);
         using (var reader = sqlCommand.ExecuteReader())
         {
             Console.WriteLine(reader);
             LoadAlbums();
         }
     });
 }
Exemple #9
0
 private void Login(object sender, EventArgs e)
 {
     DBRequests.MakeRequest(DBRequests.Login(LoginTextBox.Text, PassTextBox.Text), (sqlConnetion, sqlCommand) =>
     {
         using (var reader = sqlCommand.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 reader.Read();
                 LoggedUser = (int)reader.GetValue(0);
                 IsAdmin    = (int)reader.GetValue(1) == 1;
                 Console.WriteLine("Logged as User:" + LoggedUser);
                 var mainMenu = new MainMenu();
                 mainMenu.Show();
                 Hide();
             }
         }
     });
 }
Exemple #10
0
 private void LoadAlbums()
 {
     DBRequests.MakeRequest(DBRequests.LoadAlbums(), (connection, sqlCommand) =>
     {
         using (var reader = sqlCommand.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     _albums.Add(new TextInstance {
                         Name = reader.GetString(0)
                     });
                 }
             }
             AlbumList.Refresh();
         }
     });
 }
Exemple #11
0
 public PhotoManager(Photo photo)
 {
     InitializeComponent();
     _activePhoto = photo;
     LoadCategories();
     PhotoPreview.SizeMode      = PictureBoxSizeMode.StretchImage;
     PhotoPreview.Image         = ImageFromByteArray(photo.PhotoData);
     PhotoDescTextBox.Text      = photo.Desc;
     PhotoDescriptionLabel.Text = photo.Desc;
     ResolutionLabel.Text      += photo.Resolution;
     DBRequests.MakeRequest(DBRequests.GetAlbumName(photo.Album), (connection, command) =>
     {
         using (var reader = command.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     AlbumLabel.Text += reader.GetString(0);
                 }
             }
         }
     });
     DBRequests.MakeRequest(DBRequests.GetCategoryName(photo.Category), (connection, command) =>
     {
         using (var reader = command.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     CategoryLabel.Text += reader.GetString(0);
                 }
             }
         }
     });
     FormatLabel.Text       += photo.Format;
     SizeLabel.Text         += GetBytesReadable(photo.Size);
     CreationDateLabel.Text += photo.CreationDate;
     NameLabel.Text         += photo.Name;
     TagsLabel.Text          = photo.Tags.Replace(",", ", ");
 }
Exemple #12
0
        private void LoadCategories()
        {
            DBRequests.MakeRequest(DBRequests.LoadCategories(), (connection, sqlCommand) =>
            {
                using (var reader = sqlCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            _categories.Add(new TextInstance {
                                Name = reader.GetString(0), ID = reader.GetInt32(1)
                            });
                        }
                    }

                    CategoryListBox.Refresh();
                }
            });
        }
Exemple #13
0
        private void AddPhotoClicked(object sender, EventArgs e)
        {
            if (_loadedImage == null)
            {
                return;
            }
            var imageData = ImageToByteArray(_loadedImage);


            var constring = DBRequests.AddPhoto(PhotoNameTextBox.Text, imageData, (AlbumListBox.SelectedItems[0] as TextInstance).ID, (CategoryListBox.SelectedItems[0] as TextInstance).ID, LoginPage.LoggedUser, PhotoDescTextBox.Text,
                                                _tags.Select((instance, i) => instance.Name).ToArray(), _loadedImageExtension, _loadedImage.Size, imageData.Length);

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["HMatuszewski.PhotoAlbum.Properties.Settings.BDFotoConnectionString"].ConnectionString))
            {
                using (var command = new SqlCommand(constring, connection))
                {
                    command.Parameters.Add("@image", SqlDbType.Binary).Value = imageData;
                    connection.Open();

                    command.ExecuteNonQuery();
                    connection.Close();
                }
            }
        }
Exemple #14
0
        private void LoadAlbums()
        {
            _albums.Clear();
            AlbumCombo.Items.Clear();
            DBRequests.MakeRequest(DBRequests.LoadAlbums(), (connection, sqlCommand) =>
            {
                using (var reader = sqlCommand.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            var textInstance = new TextInstance {
                                ID = reader.GetInt32(1), Name = reader.GetString(0)
                            };
                            _albums.Add(textInstance);
                        }
                    }


                    AlbumCombo.Items.AddRange(_albums.ToArray());
                }
            });
        }
Exemple #15
0
        public AlbumView(string album)
        {
            InitializeComponent();

            // Initialize myListView.
            PhotoList.Dock = DockStyle.Fill;
            PhotoList.View = View.Tile;

            // Initialize the tile size.
            PhotoList.TileSize = new Size(200, 100);

            // Initialize the item icons.
            ImageList = new ImageList();

            if (album == "PreImportedPhotos")
            {
                var root        = Application.StartupPath;
                var preImported = Path.Combine(root, "PreImportedPhotos");

                var images = Directory.EnumerateFiles(preImported).ToList();


                foreach (var image in images)
                {
                    var renFace = Image.FromFile(image);
                    ImageList.Images.Add(renFace);
                    PhotoList.Items.Add(new ListViewItem(new[] { Path.GetFileName(image) }, PhotoList.Items.Count));
                }


                ImageList.ImageSize      = new Size(100, 100);
                PhotoList.LargeImageList = ImageList;

                // Add column headers so the subitems will appear.
                PhotoList.Columns.AddRange(new[]
                                           { new ColumnHeader() });
            }

            var albumID = -1;

            DBRequests.MakeRequest(DBRequests.GetAlbumIndex(album), (connection, command) =>
            {
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            albumID = reader.GetInt32(0);
                        }
                    }
                }
            });
            DBRequests.MakeRequest(DBRequests.GetPhotos(albumID), (connection, command) =>
            {
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            _photos.Add(new Photo
                            {
                                ID           = reader.GetInt32(0),
                                Name         = reader.GetString(1),
                                Owner        = reader.GetInt32(2),
                                Desc         = reader.GetString(3),
                                Tags         = reader.GetString(4),
                                Category     = reader.GetInt32(5),
                                Album        = reader.GetInt32(6),
                                Format       = reader.GetString(7),
                                Resolution   = reader.GetString(8),
                                CreationDate = reader.GetDateTime(9).ToLongDateString(),
                                Size         = reader.GetInt32(10),
                                PhotoData    = reader.GetValue(11) as byte[]
                            });
                        }
                    }
                }
            });


            foreach (var image in _photos)
            {
                var renFace = ImageFromByteArray(image.PhotoData);
                ImageList.Images.Add(renFace);
                PhotoList.Items.Add(new ListViewItem(new[] { image.Name }, PhotoList.Items.Count));
            }


            ImageList.ImageSize      = new Size(100, 100);
            PhotoList.LargeImageList = ImageList;

            // Add column headers so the subitems will appear.
            PhotoList.Columns.AddRange(new[]
                                       { new ColumnHeader() });
        }
Exemple #16
0
        private void SearchBtn_Click(object sender, EventArgs e)
        {
            _photos.Clear();
            var query = DBRequests.FindPhoto();

            if (!string.IsNullOrWhiteSpace(NameTextBox.Text))
            {
                query = query.WithName(NameTextBox.Text);
            }
            if (!string.IsNullOrWhiteSpace(CategoryCombo.Text))
            {
                query = query.WithCategory(_categories[CategoryCombo.SelectedIndex].ID);
            }
            if (!string.IsNullOrWhiteSpace(AlbumCombo.Text))
            {
                query = query.WithAlbum(_albums[AlbumCombo.SelectedIndex].ID);
            }
            if (!string.IsNullOrWhiteSpace(TagTextBox.Text))
            {
                query = query.WithTag(TagTextBox.Text);
            }

            var queryString   = query.ToString();
            var wherePosition = queryString.IndexOf("WHERE", 0);
            var firstPart     = queryString.Substring(0, wherePosition + 5);
            var secondPart    = queryString.Substring(wherePosition + 5, queryString.Length - firstPart.Length);

            secondPart = secondPart.Replace("WHERE", "OR");
            var newQueryString = firstPart + secondPart;

            DBRequests.MakeRequest(newQueryString, (connection, command) =>
            {
                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Console.WriteLine();

                            _photos.Add(new Photo
                            {
                                ID           = reader.GetInt32(0),
                                Name         = reader.GetString(1),
                                Owner        = reader.GetInt32(2),
                                Desc         = reader.GetString(3),
                                Tags         = reader.GetString(4),
                                Category     = reader.GetInt32(5),
                                Album        = reader.GetInt32(6),
                                Format       = reader.GetString(7),
                                Resolution   = reader.GetString(8),
                                CreationDate = reader.GetDateTime(9).ToLongDateString(),
                                Size         = reader.GetInt32(10),
                                PhotoData    = reader.GetValue(11) as byte[]
                            });
                        }

                        // Initialize myListView.
                        PhotoList.View = View.Tile;

                        // Initialize the tile size.
                        PhotoList.TileSize = new Size(200, 100);

                        // Initialize the item icons.
                        var ImageList = new ImageList();

                        foreach (var image in _photos)
                        {
                            var renFace = ImageFromByteArray(image.PhotoData);
                            ImageList.Images.Add(renFace);
                            PhotoList.Items.Add(new ListViewItem(new[] { image.Name }, PhotoList.Items.Count));
                        }


                        ImageList.ImageSize      = new Size(100, 100);
                        PhotoList.LargeImageList = ImageList;

                        // Add column headers so the subitems will appear.
                        PhotoList.Columns.AddRange(new[]
                                                   { new ColumnHeader() });
                    }
                }
            });
        }