public static bool UpdateRevisionDocument(RevitRevision rvtRevision, RevisionDocument revisionDoc) { bool updated = false; try { if (null != connection && null != command) { if (null != revisionDoc) { command.CommandText = @"UPDATE Revisions SET Revision_Document_Id = '" + revisionDoc.Id.ToString() + "' WHERE Revision_Id = '" + rvtRevision.Id.ToString() + "'"; if (command.ExecuteNonQuery() > 0) { updated = true; } command.CommandText = @"INSERT OR REPLACE INTO RevisionDocuments (Document_Id, Document_Title, Document_Path) " + "VALUES ('" + revisionDoc.Id.ToString() + "', '" + revisionDoc.Title + "', '" + revisionDoc.Path + "')"; if (command.ExecuteNonQuery() > 0) { updated = true; } } } } catch (Exception ex) { string message = ex.Message; } return(updated); }
private void buttonAdd_Click(object sender, RoutedEventArgs e) { try { bool added = false; var revisionDescriptions = from revision in rvtSheetData.Revisions select revision.Description; for (int i = 1; i < 100; i++) { string revisionDescription = "New Revision " + i; if (!revisionDescriptions.Contains(revisionDescription)) { RevitRevision rvtRevision = new RevitRevision(Guid.NewGuid(), revisionDescription, "", "", ""); this.RvtSheetData.Revisions.Add(rvtRevision); bool sheetDBUpdated = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.INSERT); //update Revision On Sheet if (rvtSheetData.Sheets.Count > 0) { List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); for (int sheetIndex = 0; sheetIndex < rvtSheetData.Sheets.Count; sheetIndex++) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), rvtSheetData.Sheets[sheetIndex].Id, rvtRevision, false); if (!rvtSheetData.Sheets[sheetIndex].SheetRevisions.ContainsKey(ros.RvtRevision.Id)) { this.RvtSheetData.Sheets[sheetIndex].SheetRevisions.Add(ros.RvtRevision.Id, ros); rosList.Add(ros); } } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); added = rosDBUpdated; } else { added = true; } break; } } if (!added) { MessageBox.Show("Please assign descriptions of revision items before you add more revisions.", "Revision Description", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { string message = ex.Message; } }
private void buttonDelete_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridRevision.SelectedItems) { StringBuilder strBuilder = new StringBuilder(); strBuilder.AppendLine("Would you like to delete following revision items and related information?\n"); List <RevitRevision> revisions = new List <RevitRevision>(); foreach (object selectedItem in dataGridRevision.SelectedItems) { RevitRevision rvtRevision = selectedItem as RevitRevision; strBuilder.AppendLine("\"" + rvtRevision.Description + "\""); revisions.Add(rvtRevision); } if (revisions.Count > 0) { MessageBoxResult msgResult = MessageBox.Show(strBuilder.ToString(), "Delete Revisions", MessageBoxButton.YesNo, MessageBoxImage.Question); if (msgResult == MessageBoxResult.Yes) { foreach (RevitRevision rvtRevision in revisions) { this.RvtSheetData.Revisions.Remove(rvtRevision); bool revisionDeleted = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.DELETE); bool rosDeleted = SheetDataWriter.DeleteRevisionOnSheet("RevisionsOnSheet_Revision_Id", rvtRevision.Id.ToString()); bool linkedDeleted = SheetDataWriter.ChangeLinkedRevision(rvtRevision.Id, "LinkedRevision_Revision_Id", rvtRevision.Id.ToString(), CommandType.DELETE); } for (int sheetIndex = 0; sheetIndex < rvtSheetData.Sheets.Count; sheetIndex++) { foreach (RevitRevision rvtRevision in revisions) { if (rvtSheetData.Sheets[sheetIndex].SheetRevisions.ContainsKey(rvtRevision.Id)) { this.RvtSheetData.Sheets[sheetIndex].SheetRevisions.Remove(rvtRevision.Id); } } } } } } } catch (Exception ex) { string message = ex.Message; } }
private void dataGridRevision_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { try { DataGridRow row = e.Row; string columnName = e.Column.Header.ToString(); if (null != row && !string.IsNullOrEmpty(columnName)) { RevitRevision oldRevision = row.Item as RevitRevision; if (columnName != "Document") { TextBox textBox = e.EditingElement as TextBox; string propertyValue = textBox.Text; string propertyName = ""; switch (columnName) { case "Description": propertyName = "Revision_Description"; break; case "Issued By": propertyName = "Revision_IssuedBy"; break; case "Issued To": propertyName = "Revision_IssuedTo"; break; case "Date": propertyName = "Revision_Date"; break; } bool databaseUpdated = SheetDataWriter.ChangeRevisionItem(oldRevision.Id.ToString(), propertyName, propertyValue); } } } catch (Exception ex) { string message = ex.Message; } }
private bool DeleteRevision(ElementId revisionId) { bool deleted = false; try { if (idMaps.ContainsKey(revisionId)) { string uniqueId = idMaps[revisionId]; LinkedRevision linkedRevision = dataManager.GetLinkedRevision(uniqueId, linkedProjectId); if (null != linkedRevision) { if (linkedRevision.IsSource) { MessageBoxResult msgResult = MessageBox.Show("Would you like to delete the revision item in the linked database?", "Delete Revision Source Item", MessageBoxButton.YesNo, MessageBoxImage.Question); if (msgResult == MessageBoxResult.Yes) { RevitRevision rvtRevision = new RevitRevision(); rvtRevision.Id = linkedRevision.RevisionId; bool revisionDeleted = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.DELETE); bool rosDeleted = SheetDataWriter.DeleteRevisionOnSheet("RevisionsOnSheet_Revision_Id", rvtRevision.Id.ToString()); bool linkDeleted = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.DELETE); deleted = (revisionDeleted && rosDeleted && linkDeleted) ? true : false; } else { deleted = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.DELETE); } } else { deleted = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.DELETE); } } } } catch (Exception ex) { string message = ex.Message; } return(deleted); }
public void RemoveRevisionExecuted(object param) { try { if (null != param && null != selectedSheet) { RevitRevision selectedRevision = param as RevitRevision; int sheetIndex = rvtSheetData.Sheets.IndexOf(selectedSheet); this.RvtSheetData.Sheets[sheetIndex].SheetRevisions[selectedRevision.Id].Include = false; bool dbUpdated = SheetDataWriter.ChangeRevisionOnSheet(rvtSheetData.Sheets[sheetIndex].SheetRevisions[selectedRevision.Id], CommandType.UPDATE); RefreshSelectedSheet(); } } catch (Exception ex) { string message = ex.Message; } }
private void buttonDocument_Click(object sender, RoutedEventArgs e) { try { DataGridRow row = DataGridUtils.FindVisualParent <DataGridRow>(e.OriginalSource as UIElement); if (null != row) { RevitRevision revision = row.Item as RevitRevision; if (null != revision) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Open a Revision Document"; openFileDialog.Filter = "All files (*.*)|*.*"; if ((bool)openFileDialog.ShowDialog()) { string fileName = openFileDialog.FileName; if (File.Exists(fileName)) { int index = rvtSheetData.Revisions.IndexOf(revision); RevisionDocument revisionDoc = revision.Document; revisionDoc.Path = fileName; revisionDoc.Title = System.IO.Path.GetFileName(fileName); if (revisionDoc.Id == Guid.Empty) { revisionDoc.Id = Guid.NewGuid(); this.RvtSheetData.Revisions[index].Document.Id = revisionDoc.Id; } this.RvtSheetData.Revisions[index].Document.Path = revisionDoc.Path; this.RvtSheetData.Revisions[index].Document.Title = revisionDoc.Title; bool databaseUpdated = SheetDataWriter.UpdateRevisionDocument(revision, revisionDoc); } } } } } catch (Exception ex) { string message = ex.Message; } }
private static void CheckRevisionLinks(Document doc, Guid projectId, ref RevitSheetData sheetData) { try { for (int i = 0; i < sheetData.Revisions.Count; i++) { RevitRevision rvtRevision = sheetData.Revisions[i]; var linkedRevisionFound = from lrevision in sheetData.Revisions[i].LinkedRevisions where lrevision.LinkProject.Id == projectId select lrevision; if (linkedRevisionFound.Count() > 0) { LinkedRevision linkedRevision = linkedRevisionFound.First(); Revision revision = doc.GetElement(linkedRevision.LinkedElementId) as Revision; if (null != revision) { sheetData.Revisions[i].LinkStatus.IsLinked = true; sheetData.Revisions[i].LinkStatus.CurrentLinkedId = linkedRevision.LinkedElementId; sheetData.Revisions[i].LinkStatus.LinkedElementId = revision.Id.IntegerValue; sheetData.Revisions[i].LinkStatus.ToolTip = "Linked Revision ElementId: " + revision.Id.IntegerValue; if (revision.Description != rvtRevision.Description || revision.IssuedBy != rvtRevision.IssuedBy || revision.IssuedTo != rvtRevision.IssuedTo || revision.RevisionDate != rvtRevision.Date) { sheetData.Revisions[i].LinkStatus.Modified = true; sheetData.Revisions[i].LinkStatus.ToolTip = "Revision parameter values are different from the linked element."; } } else { //item deleted sheetData.Revisions[i].LinkStatus.Modified = true; sheetData.Revisions[i].LinkStatus.ToolTip = "Linked Revision Not Found."; sheetData.Revisions[i].LinkedRevisions.Remove(linkedRevision); //bool revisionDBUpdated = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.DELETE); } } } } catch (Exception ex) { MessageBox.Show("Failed to check link status of revisions.\n" + ex.Message, "Sheet Manager Updater - Check Revision Links", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void dataGridRevision_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) { try { if (dataGridRevision.SelectedCells.Count > 0) { DataGridCellInfo cellInfo = dataGridRevision.SelectedCells.First(); RevitRevision selectedRevision = cellInfo.Item as RevitRevision; if (null != selectedRevision) { dataGridLinks.ItemsSource = null; dataGridLinks.ItemsSource = selectedRevision.LinkedRevisions; } } } catch (Exception ex) { string message = ex.Message; } }
public static bool InsertNewRevision(Revision revision, Guid projectId, ref RevitSheetData sheetData) { bool inserted = false; try { RevitRevision rvtRevision = new RevitRevision(Guid.NewGuid(), revision.Description, revision.IssuedBy, revision.IssuedTo, revision.RevisionDate); NumberType revNumType = (NumberType)Enum.Parse(typeof(NumberType), revision.NumberType.ToString()); LinkedRevision linkedRevision = new LinkedRevision(Guid.NewGuid(), rvtRevision.Id, revision.SequenceNumber, revision.RevisionNumber, revNumType, projectId, revision.UniqueId, true); rvtRevision.LinkedRevisions.Add(linkedRevision); RevitLinkStatus linkStatus = new RevitLinkStatus(); linkStatus.IsLinked = true; linkStatus.CurrentLinkedId = revision.UniqueId; linkStatus.LinkedElementId = revision.Id.IntegerValue; linkStatus.ToolTip = "Linked Revision ElementId: " + revision.Id.IntegerValue; rvtRevision.LinkStatus = linkStatus; sheetData.Revisions.Add(rvtRevision); bool revisionDBUpdated = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.INSERT); bool linkedRevisionDBUpdated = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.INSERT); List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); for (int sheetIndex = 0; sheetIndex < sheetData.Sheets.Count; sheetIndex++) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), sheetData.Sheets[sheetIndex].Id, rvtRevision, false); sheetData.Sheets[sheetIndex].SheetRevisions.Add(rvtRevision.Id, ros); rosList.Add(ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); inserted = (revisionDBUpdated && linkedRevisionDBUpdated && rosDBUpdated) ? true : false; } catch (Exception ex) { MessageBox.Show("Failed to insert a new revision element.\n" + ex.Message, "Insert New Revision", MessageBoxButton.OK, MessageBoxImage.Warning); } return(inserted); }
private void SearchByText(string fieldName, string searchText) { try { ICollectionView cv = CollectionViewSource.GetDefaultView(dataGridRevision.ItemsSource); if (!string.IsNullOrEmpty(searchText)) { switch (fieldName) { case "Description": cv.Filter = o => { RevitRevision revision = o as RevitRevision; return(revision.Description.ToUpper().Contains(searchText.ToUpper())); }; break; case "Issued By": cv.Filter = o => { RevitRevision revision = o as RevitRevision; return(revision.IssuedBy.ToUpper().Contains(searchText.ToUpper())); }; break; case "Issued To": cv.Filter = o => { RevitRevision revision = o as RevitRevision; return(revision.IssuedTo.ToUpper().Contains(searchText.ToUpper())); }; break; case "Date": cv.Filter = o => { RevitRevision revision = o as RevitRevision; return(revision.Date.ToUpper().Contains(searchText.ToUpper())); }; break; case "Document": cv.Filter = o => { RevitRevision revision = o as RevitRevision; return(revision.Document.Path.ToUpper().Contains(searchText.ToUpper())); }; break; } } else { cv.Filter = null; } } catch (Exception ex) { string message = ex.Message; } }
private bool InsertRevisionToDB(Revision revision, List <Guid> sheetIds) { bool inserted = false; try { RevitRevision rvtRevision = new RevitRevision(Guid.NewGuid(), revision.Description, revision.IssuedBy, revision.IssuedTo, revision.RevisionDate); NumberType revNumType = (NumberType)Enum.Parse(typeof(NumberType), revision.NumberType.ToString()); LinkedRevision linkedRevision = new LinkedRevision(Guid.NewGuid(), rvtRevision.Id, revision.SequenceNumber, revision.RevisionNumber, revNumType, linkedProjectId, revision.UniqueId, true); rvtRevision.LinkStatus.IsLinked = true; rvtRevision.LinkStatus.IsSelected = false; rvtRevision.LinkStatus.Modified = false; rvtRevision.LinkStatus.CurrentLinkedId = revision.UniqueId; rvtRevision.LinkStatus.LinkedElementId = revision.Id.IntegerValue; rvtRevision.LinkStatus.ToolTip = "Linked Revision ElementId: " + revision.Id.IntegerValue; rvtRevision.LinkedRevisions.Add(linkedRevision); rvtSheetData.Revisions.Add(rvtRevision); bool revisionDBUpdated = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.INSERT); bool linkedRevisionDBUpdated = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.INSERT); List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); foreach (Guid sheetId in sheetIds) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), sheetId, rvtRevision, false); rosList.Add(ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); inserted = (revisionDBUpdated && linkedRevisionDBUpdated && rosDBUpdated) ? true : false; } catch (Exception ex) { string message = ex.Message; } return(inserted); }
private void buttonDbToRevit_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridRevisionDB.SelectedItems) { List <RevitRevision> selectedRevisions = dataGridRevisionDB.SelectedItems.OfType <RevitRevision>().ToList(); var selectedIds = from revision in selectedRevisions select revision.Id; if (selectedIds.Count() > 0) { for (int i = 0; i < rvtSheetData.Revisions.Count; i++) { RevitRevision rvtRevision = rvtSheetData.Revisions[i]; if (selectedIds.Contains(rvtRevision.Id)) { rvtSheetData.Revisions[i].LinkStatus.IsSelected = true; } else { rvtSheetData.Revisions[i].LinkStatus.IsSelected = false; } } } selectionMode = true; //insert or update m_handler.Request.Make(RequestId.UpdateRevision); m_event.Raise(); selectionMode = false; } } catch (Exception ex) { string message = ex.Message; } }
private bool InsertRevision(Revision revision) { bool revisionInserted = false; try { RevitRevision rvtRevision = new RevitRevision(Guid.NewGuid(), revision.Description, revision.IssuedBy, revision.IssuedTo, revision.RevisionDate); NumberType revNumType = (NumberType)Enum.Parse(typeof(NumberType), revision.NumberType.ToString()); LinkedRevision linkedRevision = new LinkedRevision(Guid.NewGuid(), rvtRevision.Id, revision.SequenceNumber, revision.RevisionNumber, revNumType, linkedProjectId, revision.UniqueId, true); rvtRevision.LinkedRevisions.Add(linkedRevision); bool revisionDBUpdated = SheetDataWriter.ChangeRevisionItem(rvtRevision, CommandType.INSERT); bool linkedRevisionDBUpdated = SheetDataWriter.ChangeLinkedRevision(linkedRevision, CommandType.INSERT); List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); List <Guid> sheetIds = dataManager.GetSheetIds(); foreach (Guid sheetId in sheetIds) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), sheetId, rvtRevision, false); rosList.Add(ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); revisionInserted = (revisionDBUpdated && linkedRevisionDBUpdated && rosDBUpdated) ? true : false; if (!idMaps.ContainsKey(revision.Id)) { idMaps.Add(revision.Id, revision.UniqueId); } } catch (Exception ex) { string message = ex.Message; } return(revisionInserted); }
private bool InsertSheet(ViewSheet sheet) { bool sheetInserted = false; try { // insert into the database connected RevitSheet rvtSheet = new RevitSheet(Guid.NewGuid(), sheet.SheetNumber, sheet.ViewName); LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(linkedProjectId), sheet.UniqueId, true); rvtSheet.LinkedSheets.Add(linkedSheet); bool sheetDBUpdated = SheetDataWriter.ChangeSheetItem(rvtSheet, CommandType.INSERT); bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT); List <SheetParameterValue> paramValues = new List <SheetParameterValue>(); foreach (SheetParameter sheetParam in rvtSheetParameters) { SheetParameterValue paramValue = new SheetParameterValue(); paramValue.ParameterValueId = Guid.NewGuid(); paramValue.Parameter = sheetParam; paramValue.SheetId = rvtSheet.Id; Parameter param = sheet.LookupParameter(sheetParam.ParameterName); if (null != param) { switch (param.StorageType) { case StorageType.Double: paramValue.ParameterValue = param.AsDouble().ToString(); break; case StorageType.ElementId: paramValue.ParameterValue = param.AsElementId().IntegerValue.ToString(); break; case StorageType.Integer: paramValue.ParameterValue = param.AsInteger().ToString(); break; case StorageType.String: paramValue.ParameterValue = param.AsString(); break; } } paramValues.Add(paramValue); } bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(paramValues); List <Guid> revisionIds = dataManager.GetRevisionIds(); List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); foreach (Guid revisionId in revisionIds) { RevitRevision rvtRevision = new RevitRevision(); rvtRevision.Id = revisionId; RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), rvtSheet.Id, rvtRevision, false); rvtSheet.SheetRevisions.Add(rvtRevision.Id, ros); rosList.Add(ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); sheetInserted = (sheetDBUpdated && linkedSheetDBUpdated && rosDBUpdated) ? true : false; if (sheetInserted && !idMaps.ContainsKey(sheet.Id)) { idMaps.Add(sheet.Id, sheet.UniqueId); } } catch (Exception ex) { string message = ex.Message; } return(sheetInserted); }
private static void ReadRevisions(ref RevitSheetData sheetData) { try { ObservableCollection <LinkedRevision> linkedRevisions = new ObservableCollection <LinkedRevision>(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM LinkedRevisions"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { LinkedRevision lRevision = new LinkedRevision(); lRevision.Id = reader.GetGuid(reader.GetOrdinal("LinkedRevision_Id")); lRevision.RevisionId = reader.GetGuid(reader.GetOrdinal("LinkedRevision_Revision_Id")); lRevision.Sequence = reader.GetInt32(reader.GetOrdinal("LinkedRevision_Sequence")); lRevision.Number = reader.GetString(reader.GetOrdinal("LinkedRevision_Number")); lRevision.NumberType = (NumberType)Enum.Parse(typeof(NumberType), reader.GetString(reader.GetOrdinal("LinkedRevision_NumberType"))); Guid projectId = reader.GetGuid(reader.GetOrdinal("LinkedRevision_Project_Id")); var projectFound = from project in sheetData.LinkedProjects where project.Id == projectId select project; if (projectFound.Count() > 0) { LinkedProject project = projectFound.First(); lRevision.LinkProject = project; } lRevision.LinkedElementId = reader.GetString(reader.GetOrdinal("LinkedRevision_Element_Id")); lRevision.IsSource = reader.GetBoolean(reader.GetOrdinal("LinkedRevision_IsSource")); linkedRevisions.Add(lRevision); } } } ObservableCollection <RevisionDocument> revisionDocuments = new ObservableCollection <RevisionDocument>(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM RevisionDocuments"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { RevisionDocument document = new RevisionDocument(); document.Id = reader.GetGuid(reader.GetOrdinal("Document_Id")); document.Title = reader.GetString(reader.GetOrdinal("Document_Title")); document.Path = reader.GetString(reader.GetOrdinal("Document_Path")); if (reader["Document_Contents"] != System.DBNull.Value) { document.Contents = (byte[])reader["Document_Contents"]; } revisionDocuments.Add(document); } } } sheetData.Revisions.Clear(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM Revisions"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { RevitRevision revision = new RevitRevision(); revision.Id = reader.GetGuid(reader.GetOrdinal("Revision_Id")); revision.Description = reader.GetString(reader.GetOrdinal("Revision_Description")); revision.IssuedBy = reader.GetString(reader.GetOrdinal("Revision_IssuedBy")); revision.IssuedTo = reader.GetString(reader.GetOrdinal("Revision_IssuedTo")); revision.Date = reader.GetString(reader.GetOrdinal("Revision_Date")); Guid documentId = reader.GetGuid(reader.GetOrdinal("Revision_Document_Id")); var documentFound = from document in revisionDocuments where document.Id == documentId select document; if (documentFound.Count() > 0) { revision.Document = documentFound.First(); } var linkedRevisionFound = from link in linkedRevisions where link.RevisionId == revision.Id select link; if (linkedRevisionFound.Count() > 0) { revision.LinkedRevisions = new ObservableCollection <LinkedRevision>(linkedRevisionFound.ToList()); } sheetData.Revisions.Add(revision); } } } } catch (Exception ex) { string message = ex.Message; } }
public static bool ChangeRevisionItem(RevitRevision item, CommandType cmdType) { bool result = false; try { if (null != connection && null != command) { switch (cmdType) { case CommandType.INSERT: command.CommandText = @"INSERT INTO Revisions (Revision_Id, Revision_Description, Revision_IssuedBy, Revision_IssuedTo, Revision_Date, Revision_Document_Id) " + "VALUES ('" + item.Id.ToString() + "', '" + item.Description + "', '" + item.IssuedBy + "', '" + item.IssuedTo + "', '" + item.Date + "', '" + item.Document.Id.ToString() + "' )"; if (command.ExecuteNonQuery() > 0) { result = true; } if (item.Document.Id != Guid.Empty) { command.CommandText = @"INSERT OR REPLACE INTO RevisionDocuments (Document_Id, Document_Title, Document_Path) " + "VALUES ('" + item.Document.Id.ToString() + "', '" + item.Document.Title + "', '" + item.Document.Path + "')"; if (command.ExecuteNonQuery() > 0) { result = true; } } break; case CommandType.UPDATE: command.CommandText = @"UPDATE Revisions SET Revision_Description = '" + item.Description + "', Revision_IssuedBy ='" + item.IssuedBy + "', Revision_IssuedTo = '" + item.IssuedTo + "', Revision_Date = '" + item.Date + "', " + "Revision_Document_Id ='" + item.Document.Id.ToString() + "' WHERE Revision_Id = '" + item.Id.ToString() + "'"; if (command.ExecuteNonQuery() > 0) { result = true; } if (item.Document.Id != Guid.Empty) { command.CommandText = @"INSERT OR REPLACE INTO RevisionDocuments (Document_Id, Document_Title, Document_Path) " + "VALUES ('" + item.Document.Id.ToString() + "', '" + item.Document.Title + "', '" + item.Document.Path + "')"; if (command.ExecuteNonQuery() > 0) { result = true; } } break; case CommandType.DELETE: command.CommandText = "DELETE FROM Revisions WHERE Revision_Id = '" + item.Id.ToString() + "'"; if (command.ExecuteNonQuery() > 0) { result = true; } if (item.Document.Id != Guid.Empty) { command.CommandText = @"DELETE FROM RevisionDocuments WHERE Document_Id = '" + item.Document.Id.ToString() + "'"; if (command.ExecuteNonQuery() > 0) { result = true; } } break; } } } catch (Exception ex) { string message = ex.Message; } return(result); }
private static void CheckSheetLinks(Document doc, Guid projectId, ref RevitSheetData sheetData) { try { Dictionary <Guid /*revisionId*/, int /*elementId*/> revDictionary = new Dictionary <Guid, int>(); var linkedRevisions = from revision in sheetData.Revisions where revision.LinkStatus.IsLinked select revision; if (linkedRevisions.Count() > 0) { revDictionary = linkedRevisions.ToDictionary(o => o.Id, o => o.LinkStatus.LinkedElementId); } for (int i = 0; i < sheetData.Sheets.Count; i++) { RevitSheet rvtSheet = sheetData.Sheets[i]; var linkedSheetFound = from lsheet in sheetData.Sheets[i].LinkedSheets where lsheet.LinkProject.Id == projectId select lsheet; if (linkedSheetFound.Count() > 0) { LinkedSheet linkedSheet = linkedSheetFound.First(); ViewSheet viewSheet = doc.GetElement(linkedSheet.LinkedElementId) as ViewSheet; if (null != viewSheet) { sheetData.Sheets[i].LinkStatus.IsLinked = true; sheetData.Sheets[i].LinkStatus.CurrentLinkedId = linkedSheet.LinkedElementId; sheetData.Sheets[i].LinkStatus.LinkedElementId = viewSheet.Id.IntegerValue; sheetData.Sheets[i].LinkStatus.ToolTip = "Linked Sheet ElementId: " + viewSheet.Id.IntegerValue; //parameter check string toolTip = ""; if (CompareSheetParameters(viewSheet, sheetData.Sheets[i], sheetData, out toolTip)) { sheetData.Sheets[i].LinkStatus.Modified = true; sheetData.Sheets[i].LinkStatus.ToolTip = toolTip; } var viewRevisionIds = from elementId in viewSheet.GetAllRevisionIds() select elementId.IntegerValue; //revision check foreach (Guid revisionId in rvtSheet.SheetRevisions.Keys) { RevisionOnSheet ros = rvtSheet.SheetRevisions[revisionId]; var revisionFound = from revision in sheetData.Revisions where revision.Id == revisionId select revision; if (revisionFound.Count() > 0) { RevitRevision rvtRevision = revisionFound.First(); sheetData.Sheets[i].SheetRevisions[revisionId].RvtRevision = rvtRevision; if (rvtRevision.LinkStatus.IsLinked) { if (ros.Include && viewRevisionIds.Contains(rvtRevision.LinkStatus.LinkedElementId)) { sheetData.Sheets[i].SheetRevisions[revisionId].LinkStatus.IsLinked = true; } } } } } else { //item deleted sheetData.Sheets[i].LinkedSheets.Remove(linkedSheet); bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.DELETE); } } } } catch (Exception ex) { MessageBox.Show("Failed to check link status of sheets.\n" + ex.Message, "Sheet Manager Updater - Check Sheet Links", MessageBoxButton.OK, MessageBoxImage.Warning); } }