/// <summary> /// Shows an OpenFileDialog for user to select image files and adds to the filenames List any /// filename it doesn't already contain. /// </summary> /// <returns>True if one or more files were added to filenames List, false otherwise.</returns> private bool SelectImages() { bool fileAdded = false; OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "Image files (*.bmp, *.gif, *.jpeg, *.jpg, *.png)|*.bmp;*.gif;*.jpeg;*.jpg;*.png"; Nullable <bool> result = ofd.ShowDialog(); if (result.HasValue && result.Value) { string[] files = ofd.FileNames; foreach (string name in files) { // Make a record in the database for the file DateTime now = DateTime.Now; FileTimestampModel timestamp = new FileTimestampModel(name, now.Ticks); SqliteDataAccess.SaveFileTimestamp(timestamp); // Add the file name to the filenames list if it doesn't already contain it if (!filenames.Contains(name)) { filenames.Add(name); fileAdded = true; } } // Notify listeners that the database has changed OnDatabaseChanged(); } return(fileAdded); }
private void lbTimestamps_CmDeleteClick(object sender, RoutedEventArgs e) { if (lbTimestamps.SelectedItems == null || lbTimestamps.SelectedItems.Count != 1) { return; } FileTimestampModel selectedTimestamp = (FileTimestampModel)lbTimestamps.SelectedItems[0]; // Delete the selected timestamp from the database SqliteDataAccess.DeleteFileTimestamp(selectedTimestamp); // Refresh list of timestamps timestamps = new ObservableCollection <FileTimestampModel>(SqliteDataAccess.GetAllTimestampsForFile(mFilePath)); lbTimestamps.ItemsSource = timestamps; // Notify listeners that the database has changed OnDatabaseChanged(); // Close this window if we deleted the last timestamp if (timestamps.Count == 0) { this.DialogResult = false; } }
/// <summary> /// Deletes the FileTimestamp record whose Id value matches @timestamp's Id property. /// </summary> /// <param name="timestamp"></param> public static void DeleteFileTimestamp(FileTimestampModel timestamp) { // Safely open a connection to our database using (IDbConnection dbConnection = new SQLiteConnection(LoadConnectionString())) { // Delete the FileTimestamp record whose Id value matches @timestamp's Id property string sql = "DELETE FROM FileTimestamp WHERE Id = @Id"; dbConnection.Execute(sql, timestamp); } }
public static void SaveFileTimestamp(FileTimestampModel timestamp) { // Safely open a connection to our database using (IDbConnection dbConnection = new SQLiteConnection(LoadConnectionString())) { // Create a record in FileTimestamp table to represent the given timestamp string sql = "INSERT INTO FileTimestamp (FileAbsolutePath, ParentDirAbsolutePath, Ticks) VALUES (@FileAbsolutePath, @ParentDirAbsolutePath, @Ticks)"; dbConnection.Execute(sql, timestamp); } }
/// <summary> /// Sets values for the record in FileTimestamp table whose Id matches @timestamp.Id /// to match @timestamp's properties. /// </summary> /// <param name="timestamp"></param> public static void UpdateFileTimestamp(FileTimestampModel timestamp) { // Safely open a connection to our database using (IDbConnection dbConnection = new SQLiteConnection(LoadConnectionString())) { // Update the record in FileTimestamp table whose Id matches @timestamp.Id with values of @timestamp's properties string sql = "UPDATE FileTimestamp " + "SET FileAbsolutePath = @FileAbsolutePath, ParentDirAbsolutePath = @ParentDirAbsolutePath, Ticks = @Ticks " + "WHERE Id = @Id"; dbConnection.Execute(sql, timestamp); } }
}//end MainCanvas_PreviewMouseLeftButtonDown() private void MainCanvas_PreviewDrop(object sender, DragEventArgs e) { string[] validImageExtensions = { ".BMP", ".GIF", ".JPEG", ".JPG", ".PNG" }; if (e.Data.GetDataPresent(DataFormats.FileDrop)) { bool fileAdded = false; string[] droppedFilenames = (string[])e.Data.GetData(DataFormats.FileDrop); // Check if dropped File is a single Arrangement file if (droppedFilenames.Length == 1) { string fileName = droppedFilenames[0]; string extension = System.IO.Path.GetExtension(fileName).ToUpperInvariant(); if (extension.Equals(FILE_EXTENSION_ARRANGEMENT.ToUpperInvariant())) { // Open the Arrangement OpenArrangement(fileName); return; } } // Handle non-Arrangement file dropped bool databaseUpdated = false; foreach (string s in droppedFilenames) { if (validImageExtensions.Contains(System.IO.Path.GetExtension(s).ToUpperInvariant())) { // Add a FileTimestamp record to the database DateTime now = DateTime.Now; FileTimestampModel timestamp = new FileTimestampModel(s, now.Ticks); SqliteDataAccess.SaveFileTimestamp(timestamp); databaseUpdated = true; // add s to filenames if it's not already there if (!filenames.Contains(s)) { filenames.Add(s); fileAdded = true; } } }//end foreach if (databaseUpdated) { // Notify listeners that the database has changed OnDatabaseChanged(); } if (fileAdded) { IndicateUnsavedChanges(true); ArrangeImages(); } } //end if } //end MainCanvas_PreviewDrop()
// Methods private void OpenArrangement(string filePath) { // Update non-image app data _arrangementPath = filePath; this.Title = System.IO.Path.GetFileName(filePath) + " - " + APP_NAME; IndicateUnsavedChanges(false); // Get data from File at filePath List <string> arrangementFilenames = File.ReadAllLines(filePath).ToList(); // Make a database record for the arrangement file DateTime now = DateTime.Now; FileTimestampModel timestamp = new FileTimestampModel(filePath, now.Ticks); SqliteDataAccess.SaveFileTimestamp(timestamp); // Make a database record for each file in the arrangement foreach (string s in arrangementFilenames) { timestamp = new FileTimestampModel(s, now.Ticks); SqliteDataAccess.SaveFileTimestamp(timestamp); } // Notify listeners that the database has changed OnDatabaseChanged(); // Re-initialize filenames list based on arrangement's files that exist (we'll show a MessageBox if any of the arrangement's files don't exist) bool fileNotFound = false; string fileNotFoundMsg = "Warning: The following file(s) were unable to be found. (They may have been renamed, moved, deleted, or stolen by data thieves):\n"; filenames = new List <string>(); foreach (string s in arrangementFilenames) { if (!File.Exists(s)) { fileNotFound = true; fileNotFoundMsg += "\n" + s; continue; } filenames.Add(s); } ArrangeImages(); // Notify user if any of the arrangement's files don't exist if (fileNotFound) { MessageBox.Show(this, fileNotFoundMsg, "File Not Found"); } }
// Constructor public FolderStatisticsModel(string dirPath, List <FileTimestampModel> allTimestamps) { // Set properties from parameters AbsolutePath = dirPath; // Set other properties NumViews = allTimestamps.Count; Name = Path.GetFileName(dirPath); long mostTicks = 0; foreach (FileTimestampModel timestamp in allTimestamps) { if (timestamp.Ticks > mostTicks) { MostRecentTimestamp = timestamp; mostTicks = timestamp.Ticks; } } }