public void getSelectedPhotos() { mainWindow._listbox.Items.Clear(); foreach (StackPanel sp in selectListBox.SelectedItems) { Image i = sp.Children[0] as Image; OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); connection.Open(); DataTable dt = new DataTable(); DataSet ds = new DataSet(); ds.Tables.Add(dt); string relativeImagePath = mainWindow.getFileName(i.Source.ToString()); OleDbDataAdapter da = new OleDbDataAdapter("SELECT ImagePath from Images WHERE ImagePath = '" + relativeImagePath + "' ORDER BY ImagePath ASC", connection); da.Fill(dt); if (dt.Rows.Count == 0) { connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); if (currentCollection == null) { String fileName = System.IO.Path.GetFileNameWithoutExtension(relativeImagePath); String fileExtension = System.IO.Path.GetExtension(relativeImagePath); DateTime insertedDate = DateTime.Now; connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); String sql = " INSERT INTO Images (ImagePath, ImageName, FileType, InsertedTime) VALUES ('" + relativeImagePath + "','" + fileName + "','" + fileExtension + "','" + insertedDate + "')"; OleDbCommand command = new OleDbCommand(sql, connection); connection.Open(); command.ExecuteNonQuery(); } else { String fileName = System.IO.Path.GetFileNameWithoutExtension(relativeImagePath); String fileExtension = System.IO.Path.GetExtension(relativeImagePath); DateTime insertedDate = DateTime.Now; connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); String sql = " INSERT INTO Images (ImagePath, Collection, ImageName, FileType, InsertedTime) VALUES ('" + relativeImagePath + "','" + currentCollection + "','" + fileName + "','" + fileExtension + "','" + insertedDate + "')"; OleDbCommand command = new OleDbCommand(sql, connection); connection.Open(); command.ExecuteNonQuery(); } } } System.Threading.Thread.Sleep(1000); mainWindow.totalImageCounter = 0; if (currentCollection == null) { currentCollection = "All Photos"; } mainWindow.currentCollectionName = currentCollection; mainWindow.refreshMainWindowImages(currentCollection, mainWindow.currentSort, mainWindow.currentSortType); foreach (RadioButton mwRb in mainWindow.collectionsList.Items) { if (mwRb.Content.ToString() == mainWindow.currentCollectionName) { mwRb.IsChecked = true; } } }
private void Button_Click_2(object sender, RoutedEventArgs e) { String messageBoxText; String caption; if (collectionList.SelectedItems.Count == 1) { ListViewItem item = collectionList.SelectedItem as ListViewItem; messageBoxText = "Are you sure you want to remove the collection " + item.Content + "? Your existing photos will remain under All Photos."; caption = "Remove Collections"; } else { messageBoxText = "Are you sure you want to remove the selected collections? Your existing photos will remain under All Photos."; caption = "Remove Collections"; } MessageBoxButton button = MessageBoxButton.YesNo; MessageBoxImage icon = MessageBoxImage.Question; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); switch (result) { case MessageBoxResult.Yes: using (new WaitCursor()) { foreach (ListViewItem item in collectionList.SelectedItems) { OleDbConnection connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); String sql = " DELETE FROM Collections WHERE Collection_Name =?"; OleDbCommand command = new OleDbCommand(sql, connection); connection.Open(); command.Parameters.AddWithValue("@p1", item.Content); command.ExecuteNonQuery(); connection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\\StarPix.accdb"); sql = " UPDATE Images SET Collection = ? WHERE Collection = ?"; command = new OleDbCommand(sql, connection); command.Parameters.AddWithValue("@p1", ""); command.Parameters.AddWithValue("@p2", item.Content); connection.Open(); int i = command.ExecuteNonQuery(); foreach (RadioButton rb in mainWindow.collectionsList.Items) { if (rb.Content.ToString() == item.Content.ToString()) { if (rb.IsChecked == true) { foreach (RadioButton rb2 in mainWindow.collectionsList.Items) { if (rb2.Content.ToString() == "All Photos") { rb2.IsChecked = true; mainWindow._listbox.Items.Clear(); mainWindow.totalImageCounter = 0; mainWindow.refreshMainWindowImages("All Photos", mainWindow.currentSort, mainWindow.currentSortType); } } } } } } var selected = collectionList.SelectedItems.Cast <Object>().ToArray(); foreach (var item in selected) { collectionList.Items.Remove(item); } break; } } }