private void BtnAddImage_Click(object sender, RoutedEventArgs e) { System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "Obrázky|*.jpg;*.bmp;*.png;*.gif"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] paths = ofd.FileNames; Uri[] uris = new Uri[paths.Count()]; for (int i = 0; i <= paths.Count() - 1; i++) { uris[i] = new Uri(paths[i]); } List <ImageStruct> imagesAdded = new List <ImageStruct>(); for (int u = 0; u <= uris.Count() - 1; u++) { ImageStruct s = new ImageStruct() { imgName = System.IO.Path.GetFileNameWithoutExtension(paths[u]), image = new BitmapImage(uris[u]) }; imagesAdded.Add(s); } foreach (ImageStruct imageAdded in imagesAdded) { gallery.Images.Add(imageAdded); } gallery.Update(); } }
public static void AddImage(ImageStruct imageStruct) { LinqToSqlDataContext db = DatabaseSetup.Database; ImagesTable img = new ImagesTable(); byte[] array = ImageToByte(imageStruct.image); img.name = imageStruct.imgName; img.img = array; db.ImagesTables.InsertOnSubmit(img); db.SubmitChanges(); }
private void BtnAddImage_Click(object sender, RoutedEventArgs e) { // Nahrání obrázků do databáze System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog(); ofd.Multiselect = true; ofd.Filter = "Obrázky|*.jpg;*.bmp;*.png;*.gif"; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string[] paths = ofd.FileNames; Uri[] uris = new Uri[paths.Count()]; for (int i = 0; i <= paths.Count() - 1; i++) { uris[i] = new Uri(paths[i]); } List <ImageStruct> imagesAdded = new List <ImageStruct>(); for (int u = 0; u <= uris.Count() - 1; u++) { ImageStruct s = new ImageStruct() { imgName = System.IO.Path.GetFileNameWithoutExtension(paths[u]), image = new BitmapImage(uris[u]) }; imagesAdded.Add(s); } foreach (ImageStruct istr in imagesAdded) { // Práce s databází Images.AddImage(istr); Product p = StorageSetup.GetProductById(_id); ImagesTable imt = Images.FindLastAddedImage(); Images.AssignImageToProduct(p, imt); } // Získání obrázků z databáze - i s ID's gallery.Images = Images.GetImages(StorageSetup.GetProductById(_id)); gallery.Update(); } }