Esempio n. 1
0
        private void buttonBack_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int        index   = pageNum - 1;
                PreviewMap preview = previewMapList[index];
                if ((bool)checkBoxSkip.IsChecked)
                {
                    preview.IsEnabled = false;
                }
                else
                {
                    preview.IsEnabled = true;
                }

                previewMapList.RemoveAt(index);
                previewMapList.Insert(index, preview);

                pageNum--;
                preview = previewMapList[pageNum - 1];
                DisplayPreviews(preview);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to move the page backward.\n" + ex.Message, "Move page Backward", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 2
0
        private void buttonRefresh_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //export image
                ImageExportOptions option = new ImageExportOptions();
                option.HLRandWFViewsFileType = ImageFileType.PNG;
                option.ImageResolution       = ImageResolution.DPI_300;
                option.ShouldCreateWebSite   = false;
                option.ExportRange           = ExportRange.SetOfViews;

                List <ElementId> viewIds = new List <ElementId>();
                int        index         = pageNum - 1;
                PreviewMap preview       = previewMapList[index];
                if (null != preview.RecipientViewProperties)
                {
                    if (preview.RecipientViewProperties.ViewId > 0)
                    {
                        string tempFileName  = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), "png");
                        string tempImageFile = System.IO.Path.Combine(tempFolder, tempFileName);

                        viewIds.Add(new ElementId(preview.RecipientViewProperties.ViewId));
                        option.FilePath = tempImageFile;
                        option.SetViewsAndSheets(viewIds);
                        if (ImageExportOptions.IsValidFileName(tempImageFile))
                        {
                            string imageFileName = ExportDraftingView(preview.RecipientModelInfo.Doc, option);
                            if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath1))
                            {
                                if (File.Exists(preview.ViewLinkInfo.DestImagePath1))
                                {
                                    File.Delete(preview.ViewLinkInfo.DestImagePath1);
                                }
                            }
                            if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath2))
                            {
                                preview.ViewLinkInfo.DestImagePath1 = preview.ViewLinkInfo.DestImagePath2;
                            }
                            preview.ViewLinkInfo.DestImagePath2 = imageFileName;
                            imageRecipient.Source = new BitmapImage(new Uri(preview.ViewLinkInfo.DestImagePath2));
                        }
                    }
                    previewMapList.RemoveAt(index);
                    previewMapList.Insert(index, preview);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to refresh the preview image.\n" + ex.Message, "Refresh Preview Image", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 3
0
        public bool UpdateDraftingViews(ModelInfo sourceInfo, ModelInfo recipientInfo, TreeView treeViewSource, TreeView treeViewRecipient, bool createSheet, bool createLinks, TextBlock statusLable, ProgressBar progressBar)
        {
            bool result = false;

            try
            {
                List <int>        sourceViewIds  = new List <int>();
                List <PreviewMap> previewMapList = new List <PreviewMap>();

                ViewMapClass vmc = new ViewMapClass(sourceInfo, recipientInfo, createLinks);
                Dictionary <int, ViewProperties> sourceViews    = vmc.SourceViews;
                Dictionary <int, ViewProperties> recipientViews = vmc.RecipientViews;

                List <TreeViewModel> treeviewModels = treeViewSource.ItemsSource as List <TreeViewModel>;
                foreach (TreeViewModel rootNode in treeviewModels)
                {
                    foreach (TreeViewModel secondNode in rootNode.Children)
                    {
                        foreach (TreeViewModel viewNode in secondNode.Children)
                        {
                            if (viewNode.IsChecked == true)
                            {
                                int viewId = 0;
                                if (int.TryParse(viewNode.Tag.ToString(), out viewId))
                                {
                                    if (sourceViews.ContainsKey(viewId) && !sourceViewIds.Contains(viewId))
                                    {
                                        ViewProperties viewSource = sourceViews[viewId];
                                        if (viewSource.DependantViews.Count > 0)
                                        {
                                            foreach (int dependentId in viewSource.DependantViews.Keys)
                                            {
                                                if (!sourceViewIds.Contains(dependentId))
                                                {
                                                    ViewProperties dependentSource    = viewSource.DependantViews[dependentId];
                                                    ViewProperties dependentRecipient = null;
                                                    LinkInfo       dependantlinkInfo  = new LinkInfo();
                                                    if (null != dependentSource.LinkedView)
                                                    {
                                                        dependentRecipient = dependentSource.LinkedView;
                                                        var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == dependentId && info.DestItemId == dependentRecipient.ViewId select info;
                                                        if (linkInfoList.Count() > 0)
                                                        {
                                                            dependantlinkInfo = linkInfoList.First();
                                                        }
                                                    }

                                                    PreviewMap dependantView = new PreviewMap();
                                                    dependantView.SourceModelInfo         = sourceInfo;
                                                    dependantView.RecipientModelInfo      = recipientInfo;
                                                    dependantView.SourceViewProperties    = dependentSource;
                                                    dependantView.RecipientViewProperties = dependentRecipient;
                                                    dependantView.ViewLinkInfo            = dependantlinkInfo;
                                                    dependantView.IsEnabled = true;

                                                    sourceViewIds.Add(dependentId);
                                                    previewMapList.Add(dependantView);
                                                }
                                            }
                                        }

                                        ViewProperties viewRecipient = null;
                                        LinkInfo       linkInfo      = new LinkInfo();
                                        if (null != viewSource.LinkedView)
                                        {
                                            viewRecipient = viewSource.LinkedView;
                                            var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == viewId && info.DestItemId == viewRecipient.ViewId && info.ItemStatus != LinkItemStatus.Deleted select info;
                                            if (linkInfoList.Count() > 0)
                                            {
                                                linkInfo = linkInfoList.First();
                                            }
                                        }

                                        PreviewMap preview = new PreviewMap();
                                        preview.SourceModelInfo         = sourceInfo;
                                        preview.RecipientModelInfo      = recipientInfo;
                                        preview.SourceViewProperties    = viewSource;
                                        preview.RecipientViewProperties = viewRecipient;
                                        preview.ViewLinkInfo            = linkInfo;
                                        preview.IsEnabled = true;

                                        sourceViewIds.Add(viewId);
                                        previewMapList.Add(preview);
                                    }
                                }
                            }
                        }
                    }
                }

                if (previewMapList.Count > 0)
                {
                    PreviewWindow pWindow = new PreviewWindow(previewMapList, createSheet);
                    if (true == pWindow.ShowDialog())
                    {
                        previewMapList = pWindow.PreviewMapList;

                        progressBar.Visibility = System.Windows.Visibility.Visible;
                        statusLable.Visibility = System.Windows.Visibility.Visible;

                        bool updatedDictionary  = UpdateRecipientViewDictionary(recipientInfo, previewMapList);
                        bool updatedGoogleSheet = GoogleSheetUtil.WriteLinkIfo(recipientInfo.GoogleSheetID, recipientInfo.LinkInfoCollection);
                        bool updatedLinkStatus  = UpdateLinkStatus(recipientInfo);

                        progressBar.Visibility = System.Windows.Visibility.Hidden;
                        statusLable.Visibility = System.Windows.Visibility.Hidden;
                    }
                }
                else
                {
                    MessageBox.Show("Please select at least one source item to duplicate views.", "Select a Source Item", MessageBoxButton.OK, MessageBoxImage.Information);
                    result = false;
                }
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update drafting views.\n" + ex.Message, "Update Drafting Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }
Esempio n. 4
0
        private void DisplayPreviews(PreviewMap preview)
        {
            try
            {
                textBoxPage.Text       = pageNum + " of " + totalPage;
                checkBoxSkip.IsChecked = false;
                if (!preview.IsEnabled)
                {
                    checkBoxSkip.IsChecked = true;
                }
                buttonNext.IsEnabled = true;
                buttonBack.IsEnabled = true;
                if (pageNum == previewMapList.Count)
                {
                    buttonNext.IsEnabled        = false;
                    buttonUpdateViews.IsEnabled = true;
                }
                if (pageNum == 1)
                {
                    buttonBack.IsEnabled = false;
                }

                imageRecipient.Source = null;
                if (null != preview.RecipientModelInfo && null != preview.RecipientViewProperties)
                {
                    RecipientModelName.Content = preview.RecipientModelInfo.DocTitle;
                    RecipientView.Content      = preview.RecipientViewProperties.ViewName;
                    RecipientSheetName.Content = (!string.IsNullOrEmpty(preview.RecipientViewProperties.SheetName)) ? preview.RecipientViewProperties.SheetName : "None";

                    if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath2))
                    {
                        imageRecipient.Source = new BitmapImage(new Uri(preview.ViewLinkInfo.DestImagePath2));
                    }
                }
                else if (null == preview.RecipientViewProperties)
                {
                    RecipientModelName.Content = preview.RecipientModelInfo.DocTitle;
                    RecipientView.Content      = "To Be Created";
                    if (createSheet && !string.IsNullOrEmpty(preview.SourceViewProperties.SheetName))
                    {
                        RecipientSheetName.Content = "To Be Created";
                    }
                    else
                    {
                        RecipientSheetName.Content = "None";
                    }
                }

                if (null != preview.SourceModelInfo && null != preview.SourceViewProperties)
                {
                    SourceModelName.Content = preview.SourceModelInfo.DocTitle;
                    SourceView.Content      = preview.SourceViewProperties.ViewName;
                    SourceSheetName.Content = (!string.IsNullOrEmpty(preview.SourceViewProperties.SheetName)) ? preview.SourceViewProperties.SheetName : "None";

                    if (null != viewControl)
                    {
                        viewControl.Dispose();
                    }
                    viewControl           = new PreviewControl(preview.SourceModelInfo.Doc, new ElementId(preview.SourceViewProperties.ViewId));
                    contentSource.Content = viewControl;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to display preview Images.\n" + ex.Message, "Display Previews", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Esempio n. 5
0
        private bool UpdateViews()
        {
            bool result = false;

            try
            {
                progressBar.Visibility = System.Windows.Visibility.Visible;
                statusLable.Visibility = System.Windows.Visibility.Visible;
                statusLable.Text       = "Duplicating Views . . .";

                progressBar.Minimum = 0;
                progressBar.Maximum = previewMapList.Count;
                progressBar.Value   = 0;

                double value = 0;

                UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue);
                DuplicateUtils.errorMessage = new StringBuilder();
                List <PreviewMap> updatedList = new List <PreviewMap>();
                for (int i = 0; i < previewMapList.Count; i++)
                {
                    value += 1;
                    if (previewMapList[i].IsEnabled)
                    {
                        PreviewMap previewMap = DuplicateUtils.DuplicateView(previewMapList[i], createSheet);
                        updatedList.Add(previewMap);
                    }
                    Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, value });
                }

                if (DuplicateUtils.errorMessage.Length > 0)
                {
                    MessageBox.Show("Following drafting views contains problems.\n\n" + DuplicateUtils.errorMessage.ToString(), "Errors in Duplicating Views", MessageBoxButton.OK, MessageBoxImage.Information);
                }

                previewMapList = new List <PreviewMap>();
                previewMapList = updatedList;
                //exportView one by one
                ImageExportOptions option = new ImageExportOptions();
                option.HLRandWFViewsFileType = ImageFileType.PNG;
                option.ImageResolution       = ImageResolution.DPI_300;
                option.ShouldCreateWebSite   = false;
                option.ExportRange           = ExportRange.SetOfViews;

                List <ElementId> viewIds = new List <ElementId>();
                foreach (PreviewMap preview in previewMapList)
                {
                    viewIds.Clear();
                    if (null != preview.RecipientViewProperties)
                    {
                        if (preview.RecipientViewProperties.ViewId > 0)
                        {
                            string tempFileName  = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), "png");
                            string tempImageFile = System.IO.Path.Combine(tempFolder, tempFileName);

                            viewIds.Add(new ElementId(preview.RecipientViewProperties.ViewId));
                            option.FilePath = tempImageFile;
                            option.SetViewsAndSheets(viewIds);
                            if (ImageExportOptions.IsValidFileName(tempImageFile))
                            {
                                string imageFileName = ExportDraftingView(preview.RecipientModelInfo.Doc, option);

                                if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath1))
                                {
                                    if (File.Exists(preview.ViewLinkInfo.DestImagePath1))
                                    {
                                        File.Delete(preview.ViewLinkInfo.DestImagePath1);
                                    }
                                }
                                if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath2))
                                {
                                    preview.ViewLinkInfo.DestImagePath1 = preview.ViewLinkInfo.DestImagePath2;
                                }
                                preview.ViewLinkInfo.DestImagePath2 = imageFileName;
                            }
                        }
                    }
                }

                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to update drafting views.\n" + ex.Message, "Update Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(result);
        }