// 物件画像編集メソッド(Listview内外のコマンドから呼ばれる) private void PictureEdit(RentLivingPicture rlpic) { // 画像編集Windowへ渡す為のArgをセット OpenRentLivingImageWindowEventArgs ag = new OpenRentLivingImageWindowEventArgs(); ag.Id = rlpic.RentPictureId; ag.RentLivingPictureObject = rlpic; ag.RentLivingPictures = RentLivingEdit.RentLivingPictures; ag.IsEdit = true; // 画像編集Windowを開く OpenRentLivingImageWindow?.Invoke(this, ag); }
// 画像編集画面の表示 public void OpenRentLivingImageWindow(OpenRentLivingImageWindowEventArgs arg) { if (arg == null) { return; } if (String.IsNullOrEmpty(arg.Id)) { return; } if (arg.RentLivingPictures == null) { return; } string id = arg.Id; App app = App.Current as App; foreach (var w in app.WindowList) { if (!(w is RentLivingImageWindow)) { continue; } if ((w as RentLivingImageWindow).DataContext == null) { continue; } if (!((w as RentLivingImageWindow).DataContext is RentLivingImageViewModel)) { continue; } if (id == ((w as RentLivingImageWindow).DataContext as RentLivingImageViewModel).Id) { //w.Activate(); if ((w as RentLivingImageWindow).WindowState == WindowState.Minimized || (w as Window).Visibility == Visibility.Hidden) { //w.Show(); (w as RentLivingImageWindow).Visibility = Visibility.Visible; (w as RentLivingImageWindow).WindowState = WindowState.Normal; } (w as RentLivingImageWindow).Activate(); //(w as EditorWindow).Topmost = true; //(w as EditorWindow).Topmost = false; (w as RentLivingImageWindow).Focus(); return; } } // Create a new window. var win = new RentLivingImageWindow(); // VMをセット win.DataContext = new RentLivingImageViewModel(id); var vm = (win.DataContext as RentLivingImageViewModel); // VMにデータを渡す vm.RentLivingPictureEdit = arg.RentLivingPictureObject; vm.RentLivingPictures = arg.RentLivingPictures; vm.IsDirty = !arg.IsEdit; // 画像編集画面からの変更通知を受け取る vm.RentLivingIsDirty += () => OnRentLivingIsDirty(); // Windowリストへ追加。 app.WindowList.Add(win); // モーダルで編集画面を開く win.Owner = this; win.ShowDialog(); }
public void PictureAddCommand_Execute() { if (RentLivingEdit == null) { return; } var files = _openDialogService.GetOpenPictureFileDialog("物件写真の追加"); if (files != null) { foreach (String filePath in files) { string fileName = filePath.Trim(); if (!string.IsNullOrEmpty(fileName)) { FileInfo fi = new FileInfo(fileName); if (fi.Exists) { // 画像データの読み込み FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); // Imageオブジェクトに読み込み。 System.Drawing.Image img = System.Drawing.Image.FromStream(fs, false, false); // 検証なしが早い。https://www.atmarkit.co.jp/ait/articles/0706/07/news139.html // ByteArrayに変換 byte[] ImageData = Methods.ImageToByteArray(img); // サムネイル画像の作成 System.Drawing.Image thumbImg = Methods.FixedSize(img, 130, 87); // ByteArrayに変換 byte[] ImageThumbData = Methods.ImageToByteArray(thumbImg); // RentLivingPictureオブジェクトを用意 RentLivingPicture rlpic = new RentLivingPicture(RentLivingEdit.RentId, RentLivingEdit.RentLivingId, Guid.NewGuid().ToString()); rlpic.PictureData = ImageData; rlpic.PictureThumbData = ImageThumbData; rlpic.PictureFileExt = fi.Extension; // 画面閉じる際の確認用のフラグ。 rlpic.IsNew = true; // DBに保存する為のフラグ。 rlpic.IsModified = true; // ビットマップImageに変換(表示用) rlpic.Picture = Methods.BitmapImageFromImage(img, Methods.FileExtToImageFormat(rlpic.PictureFileExt)); rlpic.PictureThumb = Methods.BitmapImageFromImage(thumbImg, Methods.FileExtToImageFormat(rlpic.PictureFileExt)); // 物件の画像リストに追加。 //RentLivingEdit.RentLivingPictures.Add(rlpic); fs.Close(); // 画像編集Windowへ渡す為のArgをセット OpenRentLivingImageWindowEventArgs ag = new OpenRentLivingImageWindowEventArgs(); ag.Id = rlpic.RentPictureId; ag.RentLivingPictureObject = rlpic; ag.RentLivingPictures = RentLivingEdit.RentLivingPictures; ag.IsEdit = false; // 画像編集Windowを開く OpenRentLivingImageWindow?.Invoke(this, ag); } } } } }