예제 #1
0
 public ErrorHandling RemoveDatabaseEntry(TrackedWindowStorage entryToDelete)
 {
     using (var connection = new SQLiteConnection(DatabaseSource))
     {
         // Create a database command
         using (var command = new SQLiteCommand(connection))
         {
             connection.Open();
             command.CommandText = "DELETE FROM AppTimeLogs WHERE Application=@name AND date(InsertedDate) = date(@date)";
             command.Parameters.Add(new SQLiteParameter("name", entryToDelete.Name));
             command.Parameters.Add(new SQLiteParameter("date", entryToDelete.Date));
             try
             {
                 command.ExecuteNonQuery();
                 connection.Close();
                 return(new ErrorHandling {
                     isError = false
                 });
             }
             catch (Exception e)
             {
                 connection.Close();
                 return(new ErrorHandling
                 {
                     Message = e.Message,
                     isError = true
                 });
             }
         }
     }
 }
        private void Delete_Entry_Click(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("Are you sure wou want to remove this item?", "Database", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No);

            if (result == MessageBoxResult.Yes)
            {
                TrackedWindowStorage rowEntity = ((Button)e.OriginalSource).DataContext as TrackedWindowStorage;
                allStoredData.Remove(rowEntity);
                var resultOfDelete = _storage.RemoveDatabaseEntry(rowEntity);
                if (!resultOfDelete.isError)
                {
                    MessageBox.Show("Item removed", "Database", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Error occured: " + resultOfDelete.Message, "Database", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }