private void UpdateProjectButton_Click(object sender, RoutedEventArgs e) { if (ProjectmanagementListView.SelectedItem == null) { return; } string projectName = ((Projects)ProjectmanagementListView.SelectedItem).szName; DateTime startDate = ((Projects)ProjectmanagementListView.SelectedItem).StartDate; DateTime endDate = ((Projects)ProjectmanagementListView.SelectedItem).EndDate; long projectSizeID = ((Projects)ProjectmanagementListView.SelectedItem).lProjectSizeID; long ID = ((Projects)ProjectmanagementListView.SelectedItem).lID; long updateCounter = ((Projects)ProjectmanagementListView.SelectedItem).lUpdateCounter; Projects project = new Projects((int)ID, (int)updateCounter, projectName, (int)App.userCompanyID, (int)projectSizeID, startDate, endDate); UpdateProjectDialog updateProjectDialog = new UpdateProjectDialog(project); updateProjectDialog.ShowAsync(); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel( IProjectRepository projectRepository, IProjectTrussRepository projectTrussRepository, ITrussRepository trussRepository, ISectionRepository sectionRepository, ISteelRepository steelRepository ) { this._projectRepository = projectRepository; this._projectTrussRepository = projectTrussRepository; this._trussRepository = trussRepository; this._sectionRepository = sectionRepository; this._steelRepository = steelRepository; ProjectsCollection = new ObservableCollection <Project>(this._projectRepository.GetAll()); #region openProject Action openProjectAction = () => { ActiveUserControl = new SelectProjectControl(); }; this._actions.Add(openProjectAction); OpenProjectMenuCommand = new RelayCommand(openProjectAction); #endregion #region addProject this.AddProjectCommand = new RelayCommand(() => { AddProjectDialog addNewProj = new AddProjectDialog(); if (addNewProj.ShowDialog() == true) { Project tempProj = addNewProj.NewProject; try { this._projectRepository.Add(tempProj); ProjectsCollection.Add(tempProj); } catch (DbUpdateException e) { MessageBox.Show("Проект с данным кодом уже существует!"); } catch (Exception e) { MessageBox.Show(e.Message, "Ошибка при добавлении проекта"); } } }); #endregion #region UpdateProject UpdateProjectCommand = new RelayCommand( () => { var updateProjectDialog = new UpdateProjectDialog(SelectedProject); if (updateProjectDialog.ShowDialog() == true) { try { this._projectRepository.Update(SelectedProject); } catch (DbUpdateException e) { MessageBox.Show(e.Message); } } }, () => SelectedProject != null); #endregion #region RemoveProject this.RemoveProjectCommand = new RelayCommand(() => { if (MessageBox.Show("Вы уверены, что хотите удалить проект?", "Удаление проекта", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { try { this._projectRepository.Remove(SelectedProject); ProjectsCollection.Remove(SelectedProject); } catch (Exception e) { MessageBox.Show(e.Message, "Ошибка при удалении проекта"); } } }, () => SelectedProject != null); #endregion #region openTruss Action openTrussMenuAction = () => { var x = this._projectRepository.GetProjectTruss(SelectedProject); //Получить список ферм! ProjectsTrussesCollection = new ObservableCollection <ProjectTruss>(x); ActiveUserControl = new SelectProjectTrussControl(); //MessageBox.Show(SelectedProject.Code); }; this._actions.Add(openTrussMenuAction); OpenTrussMenuCommand = new RelayCommand(openTrussMenuAction, () => SelectedProject != null); #endregion #region addTruss AddTrussCommand = new RelayCommand(() => { var newTrussDialog = new AddTrussDialog(this._trussRepository.GetTypeOfLoads()); if (newTrussDialog.ShowDialog() == true) { var newProjectTruss = newTrussDialog.NewProjectTruss; var newTruss = newProjectTruss.Truss; this._trussRepository.Add(newTruss); newProjectTruss.Truss = null; newProjectTruss.TrussId = newTruss.TrussId; newProjectTruss.ProjectId = SelectedProject.ProjectId; this._projectTrussRepository.Add(newProjectTruss); ProjectsTrussesCollection.Add(newProjectTruss); } }, () => SelectedProject != null); #endregion #region EditTruss EditTrussCommand = new RelayCommand(() => { var editTussDialog = new AddTrussDialog(SelectedProjectTruss, this._trussRepository.GetTypeOfLoads()); if (editTussDialog.ShowDialog() == true) { this._projectTrussRepository.Update(editTussDialog.NewProjectTruss); editTussDialog.NewProjectTruss.Truss.TrussId = editTussDialog.NewProjectTruss.TrussId; this._trussRepository.Update(editTussDialog.NewProjectTruss.Truss); //SelectedTruss = editTussDialog.NewProjectTruss.Truss; } }, () => SelectedProjectTruss != null); #endregion #region RemoveTruss RemoveTrussCommand = new RelayCommand(() => { if (MessageBox.Show("Вы уверены, что хотите удалить ферму?", "Удаление фермы", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { try { this._projectTrussRepository.Remove(SelectedProjectTruss); ProjectsTrussesCollection.Remove(SelectedProjectTruss); } catch (Exception e) { MessageBox.Show(e.Message, "Ошибка при удалении фермы"); } } }, () => SelectedProjectTruss != null ); #endregion #region DetailTruss DetailTrussMenuCommand = new RelayCommand(() => { SelectedTruss = SelectedProjectTruss.Truss; BarTemplateList = new List <BarTemplate>(this._trussRepository.GetBarTypes()); SectionCollection = new ObservableCollection <Section>(this._sectionRepository.GetAll().Where(sec => ShortListOfSections? sec.ShortList == ShortListOfSections:true)); SteelCollection = new ObservableCollection <Steel>(this._steelRepository.GetAll()); BarCollection = new ObservableCollection <Bar>(SelectedTruss.Bar.OrderBy(bar => bar.BarNumber)); if (SelectedTruss.UnitForce) { BarCollection.AsParallel().ForAll(bar => { if (bar.SteelId != null) { bar.SteelId = bar.SteelId; bar.Steel = SteelCollection.First(steel => steel.SteelId == bar.SteelId); } if (bar.SectionId != null) { bar.SectionId = bar.SectionId; bar.Section = SectionCollection.First(sec => sec.SectionId == bar.SectionId); } }); } else { BarCollection.AsParallel().ForAll(bar => { if (bar.SteelId != null) { bar.SteelId = bar.SteelId; bar.Steel = SteelCollection.First(steel => steel.SteelId == bar.SteelId); } if (bar.SectionId != null) { bar.SectionId = bar.SectionId; bar.Section = SectionCollection.First(sec => sec.SectionId == bar.SectionId); } bar.ActualForce = bar.Force; bar.ActualMoment = bar.Moment; }); } LoadChangedCommand.Execute(null); ActiveUserControl = new TrussDetailControl(SelectedTruss); }, () => SelectedProjectTruss != null); #endregion #region SaveProjectChangesCmd SaveChangesCommand = new RelayCommand(() => { this._projectTrussRepository.SaveChanges(SelectedProjectTruss); }, () => SelectedProjectTruss != null); #endregion #region LoadChangedCmd LoadChangedCommand = new RelayCommand(() => { var coeff = SelectedTruss.UnitForce ? SelectedProjectTruss.Load * SelectedProjectTruss.TrussSpacing / 100000 : 1; foreach (var item in BarCollection) { item.ActualForce = item.Force * coeff; item.ActualMoment = item.Moment * coeff; } }, () => /*ActiveUserControl is TrussDetailControl && */ SelectedTruss.UnitForce && SelectedProjectTruss != null); #endregion #region BarTemplateSelectionChangedCmd BarTemplateSelectionChangedCommand = new RelayCommand(() => { BarCollection .Where(bar => bar.ElementType == SelectedBarTemplate.ShortName) .AsParallel() .ForAll(bar => { if (SelectedBarTemplate.Steel != null) { bar.Steel = SelectedBarTemplate.Steel; bar.SteelId = SelectedBarTemplate.Steel.SteelId; } if (SelectedBarTemplate.Section != null) { bar.Section = SelectedBarTemplate.Section; bar.SectionId = SelectedBarTemplate.Section.SectionId; } }); }, () => SelectedBarTemplate != null); #endregion #region CalculateTruss CalculateTrussCommand = new RelayCommand(() => { TrussWeight = 0; var f = true; foreach (var bar in BarCollection) { TrussWeight += bar.Length / 1000F * bar.Section.Mass / 1000F; if (bar.Length == 0 || bar.ActualForce == 0 || bar.Section == null || bar.Steel == null) { f = false; //break; } } if (f) { try { this._report = TrussCalculate.Calculate(SelectedProjectTruss, this._steelRepository); Calculated = true; ResultVisibility = Visibility.Visible; } catch (ArgumentException e) { MessageBox.Show(e.Message); } } else { TrussWeight = 0; MessageBox.Show("Заполните данные о сечениях фермы"); } }, () => SelectedProjectTruss != null); #endregion #region CreateReport CreateReportCommand = new RelayCommand(() => { SaveFileDialog saveFileDialog = new SaveFileDialog { Filter = "Word File (*.docx)|*.docx" }; if (saveFileDialog.ShowDialog() == true) { var filename = saveFileDialog.FileName.Replace(".docx", "") + ".png"; if (ActiveUserControl is TrussDetailControl tdc) { tdc.GetTrussPicture(filename); using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Create(saveFileDialog.FileName, WordprocessingDocumentType.Document)) { var mainPart = wordprocessingDocument.AddMainDocumentPart(); var doc = new Document(); mainPart.Document = doc; var body = doc.AppendChild(new Body()); ImagePart x = wordprocessingDocument.MainDocumentPart.AddImagePart(ImagePartType.Jpeg); using (FileStream stream = new FileStream(filename, FileMode.Open)) { x.FeedData(stream); } AddImageToBody(doc, mainPart.GetIdOfPart(x), tdc.TrussWidthToHeight); CalculateTrussCommand.Execute(null); wordprocessingDocument.MainDocumentPart.Document.Body.Append(this._report); wordprocessingDocument.MainDocumentPart.Document.Save(); } System.Diagnostics.Process.Start(saveFileDialog.FileName); } } }, () => this._report != null); #endregion #region Settings SettingsMenuCommand = new RelayCommand(() => { this.ActiveUserControl = new SettingsControl(); }); #endregion }