// 物件PDF編集メソッド(Listview内外のコマンドから呼ばれる)
        private void PdfEdit(RentLivingPdf rlpdf)
        {
            // PDF編集Windowへ渡す為のArgをセット
            OpenRentLivingPdfWindowEventArgs ag = new OpenRentLivingPdfWindowEventArgs();

            ag.Id = rlpdf.RentPdfId;
            ag.RentLivingPdfObject = rlpdf;
            ag.RentLivingPdfs      = RentLivingEdit.RentLivingPdfs;
            ag.IsEdit = true;

            // PDF編集Windowを開く
            OpenRentLivingPdfWindow?.Invoke(this, ag);
        }
Esempio n. 2
0
        // PDF編集画面の表示
        public void OpenRentLivingPdfWindow(OpenRentLivingPdfWindowEventArgs arg)
        {
            if (arg == null)
            {
                return;
            }

            if (String.IsNullOrEmpty(arg.Id))
            {
                return;
            }

            if (arg.RentLivingPdfs == 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 RentLivingPdfWindow();

            // VMをセット
            win.DataContext = new RentLivingPdfViewModel(id);

            var vm = (win.DataContext as RentLivingPdfViewModel);

            // VMにデータを渡す
            vm.RentLivingPdfEdit = arg.RentLivingPdfObject;
            vm.RentLivingPdfs    = arg.RentLivingPdfs;
            vm.IsDirty           = !arg.IsEdit;

            // 画像編集画面からの変更通知を受け取る
            vm.RentLivingIsDirty += () => OnRentLivingIsDirty();

            // Windowリストへ追加。
            app.WindowList.Add(win);

            // モーダルで編集画面を開く
            win.Owner = this;
            win.ShowDialog();
        }
        public async void PdfAddCommand_Execute()
        {
            if (RentLivingEdit == null)
            {
                return;
            }

            var files = _openDialogService.GetOpenZumenPdfFileDialog("図面の追加");

            if (files != null)
            {
                foreach (String filePath in files)
                {
                    string fileName = filePath.Trim();

                    if (!string.IsNullOrEmpty(fileName))
                    {
                        FileInfo fi = new FileInfo(fileName);
                        if (fi.Exists)
                        {
                            // 図面ファイルのPDFデータの読み込み
                            byte[]     PdfData;
                            FileStream fs  = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                            long       len = fs.Length;

                            // ByteArrayに変換
                            BinaryReader br = new BinaryReader(fs);
                            PdfData = br.ReadBytes((int)fs.Length);
                            br.Close();

                            // RentLivingPdfオブジェクトの作成
                            RentLivingPdf rlZumen = new RentLivingPdf(RentLivingEdit.RentId, RentLivingEdit.RentLivingId, Guid.NewGuid().ToString());
                            rlZumen.PdfData  = PdfData;
                            rlZumen.FileSize = len;

                            // 画像を作成。
                            BitmapImage bitimg = await Methods.BitmapImageFromPdf(PdfData);

                            rlZumen.Picture = bitimg;

                            // ByteArrayに変換
                            byte[] ImageData = Methods.BitmapImageToByteArray(bitimg);
                            rlZumen.PictureData = ImageData;

                            // TODO:
                            //rlZumen.DateTimeAdded = DateTime.Now;
                            rlZumen.DateTimePublished = DateTime.Now;
                            rlZumen.DateTimeVerified  = DateTime.Now;

                            // 画面閉じる際の確認用のフラグ。
                            rlZumen.IsNew = true;
                            // DBに保存する為のフラグ。
                            rlZumen.IsModified = true;

                            // 物件のPDFリストに追加。
                            //RentLivingEdit.RentLivingPdfs.Add(rlZumen);

                            fs.Close();

                            // PDF編集Windowへ渡す為のArgをセット
                            OpenRentLivingPdfWindowEventArgs ag = new OpenRentLivingPdfWindowEventArgs();
                            ag.Id = rlZumen.RentPdfId;
                            ag.RentLivingPdfObject = rlZumen;
                            ag.RentLivingPdfs      = RentLivingEdit.RentLivingPdfs;
                            ag.IsEdit = false;

                            // PDF編集Windowを開く
                            OpenRentLivingPdfWindow?.Invoke(this, ag);
                        }
                    }
                }
            }
        }