private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { //On sélectionne l'item if (lstMaps.SelectedIndex != -1) { photo = (Photo)lstMaps.SelectedItem; BitmapImage tmp = new BitmapImage(); using (IsolatedStorageFile isoStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStorage.FileExists(photo.Background)) { using (IsolatedStorageFileStream fileStream = isoStorage.OpenFile(photo.Background, FileMode.Open, FileAccess.Read)) { tmp.SetSource(fileStream); fileStream.Close(); } } } img.Source = tmp; //On affiche les rectangles dbc = new DataBaseContext(DataBaseContext.DBConnectionString); var objects = from interactions in dbc.InteractionsPhotos where interactions.PhotoId == photo.Id select interactions; int cpt = 0; foreach (InteractionPhoto ip in objects) { Rectangle r = new Rectangle(); r.HorizontalAlignment = System.Windows.HorizontalAlignment.Left; r.VerticalAlignment = System.Windows.VerticalAlignment.Top; r.Fill = new SolidColorBrush(Color.FromArgb(150, 250, 0, 0)); r.Fill.Opacity = 0.5; r.Height = (ip.Hauteur * 235) / 307; r.Width = (ip.Longueur * 392) / 512; r.Margin = new Thickness(((ip.X * 392) / 512) + (776 - 392) / 2 , ((ip.Y * 235) / 307), 0, 0); ContentPhoto.Children.Add(r); } ContentPhoto.Visibility = Visibility.Visible; ContentLst.Visibility = Visibility.Collapsed; lstMaps.SelectedIndex = -1; } }
private void appBarSave_Click(object sender, EventArgs e) { //On regarde s'il y a des interaction if (lstInteractions.Count != 0) { //On sauvegarde l'image dans l'isolated storage string nom = "Victor " + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + ".jpg"; WriteableBitmap wb = new WriteableBitmap(img); using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { //On copie dans l'isolated storage IsolatedStorageFileStream fileStream = isf.CreateFile(nom); wb.SaveJpeg(fileStream, wb.PixelWidth, wb.PixelHeight, 0, 100); fileStream.Close(); } //On sauvegarde la photo dans la BDD dbc = new DataBaseContext(DataBaseContext.DBConnectionString); Photo photo = new Photo() { Background = nom }; dbc.Photos.InsertOnSubmit(photo); dbc.SubmitChanges(); //On sauvegarde le nom de la photo sur toutes les interactions foreach (var q in lstInteractions) { q.PhotoId = photo.Id; dbc.InteractionsPhotos.InsertOnSubmit(q); } dbc.SubmitChanges(); dbc.Dispose(); NavigationService.Navigate(new Uri("/Explorer/ExplorerMenu.xaml", UriKind.Relative)); } else { MessageBox.Show("You cannot save a photo without any danger", "Error", MessageBoxButton.OK); } }