Пример #1
0
        private void buttonAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                bool added     = false;
                var  viewNames = from view in rvtSheetData.Views select view.Name;
                for (int i = 1; i < 100; i++)
                {
                    string viewName = "New View " + i;
                    if (!viewNames.Contains(viewName))
                    {
                        RevitView rvtView = new RevitView(Guid.NewGuid(), viewName);
                        this.RvtSheetData.Views.Add(rvtView);
                        added = SheetDataWriter.ChangeViewItem(rvtView, CommandType.INSERT);

                        break;
                    }
                }

                if (!added)
                {
                    MessageBox.Show("Please assign view names before you add more view items.", "View Name", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to add view items.\n" + ex.Message, "Add Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Пример #2
0
        private void buttonDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != dataGridView.SelectedItems)
                {
                    List <RevitView> viewsToDelete = dataGridView.SelectedItems.Cast <RevitView>().ToList();

                    foreach (RevitView rvtView in viewsToDelete)
                    {
                        this.RvtSheetData.Views.Remove(rvtView);
                        bool dbUpdated = SheetDataWriter.ChangeViewItem(rvtView, CommandType.DELETE);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to delete view items.\n" + ex.Message, "Delete Views", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Пример #3
0
        private void dataGridView_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                DataGridRow row = e.Row;
                if (null != row)
                {
                    RevitView oldView      = row.Item as RevitView;
                    string    propertyName = e.Column.Header.ToString();

                    switch (propertyName)
                    {
                    case "View Name":
                        TextBox textBoxName = e.EditingElement as TextBox;
                        if (null != textBoxName)
                        {
                            bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, textBoxName.Text);
                        }
                        break;

                    case "Sheet Number":
                        ComboBox comboBoxSheet = e.EditingElement as ComboBox;
                        if (null != comboBoxSheet)
                        {
                            RevitSheet selectedSheet = comboBoxSheet.SelectedItem as RevitSheet;
                            if (null != selectedSheet)
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, selectedSheet.Id.ToString());
                            }
                        }
                        break;

                    case "View Type":
                        ComboBox comboBoxViewType = e.EditingElement as ComboBox;
                        if (null != comboBoxViewType)
                        {
                            RevitViewType selectedViewType = comboBoxViewType.SelectedItem as RevitViewType;
                            if (null != selectedViewType)
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, selectedViewType.Id.ToString());
                            }
                        }
                        break;

                    case "U":
                        TextBox textBoxU = e.EditingElement as TextBox;
                        if (null != textBoxU)
                        {
                            double uValue;
                            if (double.TryParse(textBoxU.Text, out uValue))
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, uValue);
                            }
                        }
                        break;

                    case "V":
                        TextBox textBoxV = e.EditingElement as TextBox;
                        if (null != textBoxV)
                        {
                            double vValue;
                            if (double.TryParse(textBoxV.Text, out vValue))
                            {
                                bool databaseUpdated = SheetDataWriter.ChangeViewItem(oldView.Id.ToString(), propertyName, vValue);
                            }
                        }
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }