private void SetCurrentPatientID(object sender, object data) { if (sender != null) { _fileNameOnly = sender as string; } CurrentDocument = new AdditionalInfoDocument(); try { // CurrentPatient = PtRep.Get((int)data);CurrentDocument Doctors = new ObservableCollection <Docs>(); //bool tester = true; foreach (var doc in Data.Doctor.GetAll) { if (doc.isEnabled.Value) { Doctors.Add(new Docs(doc)); } } if (data != null && int.Parse(data.ToString()) != 0) { CurrentDocument = Data.AdditionalInfoDocument.Get(int.Parse(data.ToString())); if (CurrentDocument.DoctorId != 0) { var doc = Data.Doctor.Get(CurrentDocument.DoctorId); foreach (var docs in Doctors) { if (docs.doc.Id == doc.Id) { DoctorSelectedId = Doctors.IndexOf(docs); } } } // DoctorSelectedId = CurrentDocument.DoctorId; IsDocAdded = Visibility.Visible; TextForDoWhat = ""; } else { DoctorSelectedId = 0; IsDocAdded = Visibility.Hidden; TextForDoWhat = "Сформируйте или загрузите документ"; } } catch { } // IsAnalizeLoadedVisibility = Visibility.Hidden; //TODO: LOAD FROM FILE }
public ViewModelCreateAdditionalInfoDocuments(NavigationController controller) : base(controller) { CurrentSelectDoctorPanelViewModel = new SclerozPanelViewModel(this); RevertSelectDoctorCommand = new DelegateCommand(() => { CurrentSelectDoctorPanelViewModel.PanelOpened = false; }); OpenSelectDoctorCommand = new DelegateCommand(() => { CurrentSelectDoctorPanelViewModel.ClearPanel(); CurrentSelectDoctorPanelViewModel.PanelOpened = true; }); MessageBus.Default.Subscribe("GetAdditionalInfoDocForHirurgOverview", SetCurrentPatientID); MessageBus.Default.Subscribe("SetCurrentPatientIDRealyThisTimeForAdditionalInfo", SetCurrentPatientIDRealyThisTime); // MessageBus.Default.Subscribe("GetAnalizeForAnalizeOverview", SetCurrentAnalizeID); HasNavigation = false; Controller = controller; ToCurrentObsledCommand = new DelegateCommand( () => { if (!string.IsNullOrWhiteSpace(FileName)) { MessageBoxResult dialogResult = MessageBox.Show("Вы сохранили изменения в документе?", "", MessageBoxButton.YesNo); if (dialogResult == MessageBoxResult.Yes) { // MessageBus.Default.Call("GetOperationForOverwiev", this, operationId); //GetObsForOverview Controller.NavigateTo <ViewModelAdditionalInfoPatient>(); FileName = ""; } } else { // MessageBus.Default.Call("GetOperationForOverwiev", this, operationId); //GetObsForOverview Controller.NavigateTo <ViewModelAdditionalInfoPatient>(); FileName = ""; } // Controller.NavigateTo<ViewModelAdditionalInfoPatient>(); } ); OpenWordDocument = new DelegateCommand( () => { int togle = 0; FileName = System.IO.Path.GetTempPath() + "Амбулаторная_карта.docx"; _fileNameOnly = "Амбулаторная_карта.docx"; byte[] bte = CurrentDocument.DocTemplate; for (; ;) { try { File.WriteAllBytes(FileName, bte); break; } catch { togle += 1; FileName = System.IO.Path.GetTempPath() + "Амбулаторная_карта" + togle + ".docx"; _fileNameOnly = "Амбулаторная_карта" + togle + ".docx"; } } TextForDoWhat = "Был открыт документ " + _fileNameOnly + ". Для сохранения изменений в документе сохраните данные в Word, закройте документ и нажмите кнопку \"Сохранить изменения\"."; Process.Start("WINWORD.EXE", FileName); } ); MessageBus.Default.Subscribe("GeAdditionalInfoDocFILENAME", GetStatementForStatementFILENAME); CurrentSavePanelViewModel = new SclerozPanelViewModel(this); OpenAddSaveCommand = new DelegateCommand(() => { if (!string.IsNullOrWhiteSpace(FileName)) { CurrentSavePanelViewModel.ClearPanel(); CurrentSavePanelViewModel.PanelOpened = true; } else { MessageBox.Show("Сначала откройте документ"); } }); RevertSaveCommand = new DelegateCommand(() => { CurrentSavePanelViewModel.PanelOpened = false; }); SetNewOverview = new DelegateCommand( () => { if (Doctors != null && Doctors.Count != 0) { if (DoctorSelectedId == -1) { MessageBus.Default.Call("CreateDocumentAdditionalInfo", "", null); } else { MessageBus.Default.Call("CreateDocumentAdditionalInfo", Doctors[DoctorSelectedId].ToString(), Doctors[DoctorSelectedId].doc.Id); } TextForDoWhat = "Вы создали новый документ " + _fileNameOnly; CurrentSavePanelViewModel.PanelOpened = false; } } ); SaveWordDocument = new DelegateCommand( () => { try { if (!string.IsNullOrWhiteSpace(FileName)) { byte[] bteToBD = File.ReadAllBytes(FileName); AdditionalInfoDocument Hv = new AdditionalInfoDocument(); //bool tester = true; if (CurrentDocument.Id != 0) { Hv = Data.AdditionalInfoDocument.Get(CurrentDocument.Id); CurrentDocument.DocTemplate = bteToBD; Hv.DocTemplate = bteToBD; Hv.DoctorId = Doctors[DoctorSelectedId].doc.Id; Data.Complete(); } else { Hv.DocTemplate = bteToBD; Hv.DoctorId = Doctors[DoctorSelectedId].doc.Id; CurrentDocument.DocTemplate = bteToBD; Data.AdditionalInfoDocument.Add(Hv); Data.Complete(); CurrentDocument.Id = Hv.Id; MessageBus.Default.Call("SetIdOfAdditionalInfoDoc", null, CurrentDocument.Id); } CurrentSavePanelViewModel.PanelOpened = false; TextForDoWhat = "Изменения в " + _fileNameOnly + " были сохранены"; } } catch { MessageBox.Show("Закройте документ"); } } ); OpenFile = new DelegateCommand( () => { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Word Documents (.docx)|*.docx|Word Template (.dotx)|*.dotx|All Files (*.*)|*.*"; openFileDialog.ValidateNames = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == true) { _fileNameOnly = openFileDialog.SafeFileName; FileName = openFileDialog.FileName; byte[] bteToBD = File.ReadAllBytes(FileName); AdditionalInfoDocument Hv = new AdditionalInfoDocument(); if (CurrentDocument.Id != 0) { Hv = Data.AdditionalInfoDocument.Get(CurrentDocument.Id); Hv.DocTemplate = bteToBD; Hv.DoctorId = Doctors[DoctorSelectedId].doc.Id; Data.Complete(); } else { Hv.DocTemplate = bteToBD; Hv.DoctorId = Doctors[DoctorSelectedId].doc.Id; Data.AdditionalInfoDocument.Add(Hv); Data.Complete(); CurrentDocument.Id = Hv.Id; MessageBus.Default.Call("SetIdOfAdditionalInfoDoc", null, CurrentDocument.Id); } MessageBus.Default.Call("GetAdditionalInfoDocForHirurgOverview", null, CurrentDocument.Id); TextForDoWhat = "Был загружен документ " + _fileNameOnly; } } ); ToCurrentPatientCommand = new DelegateCommand( () => { MessageBus.Default.Call("GetCurrentPatientId", this, CurrentPatient.Id); Controller.NavigateTo <ViewModelCurrentPatient>(); } ); }