Exemple #1
0
        public static IEnumerable <WP.Paragraph> Calculate(ProjectTruss projectTrussToCalculate, ISteelRepository steelRepository)
        {
            var barsCalculationParagraph = new List <WP.Paragraph>();
            var trussToCalculate         = projectTrussToCalculate.Truss;
            var projectToCalculate       = projectTrussToCalculate.Project;

            barsCalculationParagraph.Add(FormulaCreator.CenterBigTextParagraph($"Расчет фермы"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Проект: {projectToCalculate.Code} - {projectToCalculate.Description}"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Ферма: {projectTrussToCalculate.TrussName}."));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Шаг ферм: {projectTrussToCalculate.TrussSpacing} мм, нагрузка на 1м2: {projectTrussToCalculate.Load} кгс/м2."));
            barsCalculationParagraph.Add(FormulaCreator.CenterBigTextParagraph($"Информация о ферме"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Пролет: {trussToCalculate.Span} мм"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Уклон: {trussToCalculate.Slope}"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Высота на опоре: {trussToCalculate.SupportDepth} мм"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Количество панелей: {trussToCalculate.PanelAmount}"));
            barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Тип нагрузки: {trussToCalculate.LoadType}"));



            var barsToCalc = trussToCalculate.Bar.OrderBy(bar => bar.BarNumber);

            foreach (var bar in barsToCalc)
            {
                barsCalculationParagraph.AddRange(FormulaCreator.GenerateParagraphWithBarText(bar));

                var Ry = steelRepository.GetStrength(bar.Steel, bar.Section.Thickness);
                barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Расчетное сопротивления стержня по пределу текучести: {Ry} кгс/м2"));
                if (bar.ActualForce < 0)
                {
                    var ecc = bar.ActualMoment / Math.Abs(bar.ActualForce) * 100;
                    var m   = ecc * bar.Section.Area / bar.Section.SectionModulusX;

                    if (Math.Abs(bar.Moment) < TOLERANCE || m <= 0.1)
                    {
                        barsCalculationParagraph.Add(bar.ActualMoment == 0
                            ? FormulaCreator.TextParagraph($"Стержень рассчитывается на сжатие")
                            : FormulaCreator.TextParagraph($"Влияние момента незначительно, стержень рассчитывается на сжатие"));
                        barsCalculationParagraph.AddRange(CalculateForce(bar, Ry));
                    }
                    else
                    {
                        barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Стержень рассчитывается на сжатие с изгибом"));
                        barsCalculationParagraph.AddRange(CalculateForceMoment(bar, Ry));
                    }
                }
                else
                {
                    barsCalculationParagraph.Add(FormulaCreator.TextParagraph($"Стержень рассчитывается на растяжение"));
                    bar.CalcType   = "расчет на растяжение";
                    bar.CalcResult = bar.ActualForce / bar.Section.Area / Ry * 100;
                    barsCalculationParagraph.Add(FormulaCreator.GenerateParagraphWithAxialTensionFormula(bar, Ry));
                }
            }

            return(barsCalculationParagraph);
        }
Exemple #2
0
        /// <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
        }