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 OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { try { if (e.NewItems != null && e.Action == NotifyCollectionChangedAction.Add) { foreach (RevitSheet sheet in e.NewItems) { int index = rvtSheetData.Sheets.IndexOf(sheet); Guid sheetId = Guid.NewGuid(); this.RvtSheetData.Sheets[index].Id = sheetId; bool sheetDBUpdated = SheetDataWriter.ChangeSheetItem(rvtSheetData.Sheets[index], CommandType.INSERT); foreach (SheetParameter sheetParam in rvtSheetData.SheetParameters) { SheetParameterValue paramValue = new SheetParameterValue(); paramValue.ParameterValueId = Guid.NewGuid(); paramValue.Parameter = sheetParam; paramValue.SheetId = sheetId; this.RvtSheetData.Sheets[index].SheetParameters.Add(sheetParam.ParameterId, paramValue); } bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(RvtSheetData.Sheets[index].SheetParameters.Values.ToList()); foreach (RevitRevision revision in rvtSheetData.Revisions) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), sheetId, revision, false); this.RvtSheetData.Sheets[index].SheetRevisions.Add(revision.Id, ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(RvtSheetData.Sheets[index].SheetRevisions.Values.ToList()); } } if (e.OldItems != null && e.Action == NotifyCollectionChangedAction.Remove) { foreach (RevitSheet sheet in e.OldItems) { bool sheetDBUpdated = SheetDataWriter.ChangeSheetItem(sheet, CommandType.DELETE); bool sheetParamDBUpdated = SheetDataWriter.DeleteSheetParameterValue(sheet.Id.ToString()); bool rosDBUpdated = SheetDataWriter.DeleteRevisionOnSheet("RevisionsOnSheet_Sheet_Id", sheet.Id.ToString()); } } } catch (Exception ex) { string message = ex.Message; } }
public static bool ChangeRevisionOnSheet(RevisionOnSheet ros, CommandType cmdType) { bool result = false; try { if (null != connection && null != command) { switch (cmdType) { case CommandType.INSERT: command.CommandText = @"INSERT INTO RevisionsOnSheet(RevisionsOnSheet_Id, RevisionsOnSheet_Sheet_Id, RevisionsOnSheet_Revision_Id, RevisionsOnSheet_Include) " + "VALUES ('" + ros.MapId.ToString() + "', '" + ros.SheetId.ToString() + "', '" + ros.RvtRevision.Id.ToString() + "', @include)"; command.Parameters["@include"].Value = ros.Include; if (command.ExecuteNonQuery() > 0) { result = true; } break; case CommandType.UPDATE: command.CommandText = @"UPDATE RevisionsOnSheet SET RevisionsOnSheet_Include = @include WHERE RevisionsOnSheet_Id ='" + ros.MapId.ToString() + "'"; command.Parameters["@include"].Value = ros.Include; if (command.ExecuteNonQuery() > 0) { result = true; } break; case CommandType.DELETE: command.CommandText = "DELETE FROM RevisionsOnSheet WHERE RevisionsOnSheet_Id = '" + ros.MapId.ToString() + "'"; if (command.ExecuteNonQuery() > 0) { result = true; } break; } } } catch (Exception ex) { string message = ex.Message; } return(result); }
private void OnUnchecked(object sender, RoutedEventArgs e) { try { if (userMode && null != sender) { CheckBox checkBox = sender as CheckBox; RevisionOnSheet ros = GetRevisionOnSheet(checkBox); if (null != ros) { bool dbUpdated = SheetDataWriter.ChangeRevisionOnSheet(ros, CommandType.UPDATE); } } } catch (Exception ex) { MessageBox.Show("Failed to fire checkbox event.\n" + ex.Message, "Checkbox Unchecked", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private RevisionOnSheet GetRevisionOnSheet(CheckBox checkBox) { RevisionOnSheet ros = null; Guid revisionId = Guid.Empty; try { Binding binding = BindingOperations.GetBinding(checkBox, ToggleButton.IsCheckedProperty); string sortMemberPath = binding.Path.Path; var mg = Regex.Match(sortMemberPath, @"\[(.*?)\]"); if (mg.Success) { string value = mg.Groups[1].Value; revisionId = new Guid(value); } var parent = VisualTreeHelper.GetParent(checkBox); while (parent != null && parent.GetType() != typeof(DataGridRow)) { parent = VisualTreeHelper.GetParent(parent); } DataGridRow datarow = parent as DataGridRow; if (null != datarow) { RevitSheet sheet = datarow.Item as RevitSheet; if (null != sheet) { if (sheet.SheetRevisions.ContainsKey(revisionId)) { ros = sheet.SheetRevisions[revisionId]; } } } } catch (Exception ex) { MessageBox.Show("Failed to checked Ids.\n" + ex.Message, "Get Checked Ids", MessageBoxButton.OK, MessageBoxImage.Warning); } return(ros); }
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 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 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 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); } }
public static bool InsertNewSheet(ViewSheet sheet, Guid projectId, ref RevitSheetData sheetData) { bool inserted = false; try { var sheetNumberExisting = from rvtSheet in sheetData.Sheets where rvtSheet.Number == sheet.SheetNumber select rvtSheet; if (sheetNumberExisting.Count() > 0) { RevitSheet rvtSheet = sheetNumberExisting.First(); int sheetIndex = sheetData.Sheets.IndexOf(rvtSheet); LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(projectId), sheet.UniqueId, false); sheetData.Sheets[sheetIndex].LinkedSheets.Add(linkedSheet); bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT); RevitLinkStatus linkStatus = new RevitLinkStatus(); linkStatus.IsLinked = true; linkStatus.CurrentLinkedId = sheet.UniqueId; linkStatus.LinkedElementId = sheet.Id.IntegerValue; linkStatus.ToolTip = "Linked Sheet ElementId: " + sheet.Id.IntegerValue; string toolTip = ""; if (CompareSheetParameters(sheet, rvtSheet, sheetData, out toolTip)) { linkStatus.Modified = true; linkStatus.ToolTip = toolTip; } sheetData.Sheets[sheetIndex].LinkStatus = linkStatus; inserted = true; } else { RevitSheet rvtSheet = new RevitSheet(Guid.NewGuid(), sheet.SheetNumber, sheet.ViewName); LinkedSheet linkedSheet = new LinkedSheet(Guid.NewGuid(), rvtSheet.Id, new LinkedProject(projectId), sheet.UniqueId, true); rvtSheet.LinkedSheets.Add(linkedSheet); bool sheetDBUpdated = SheetDataWriter.ChangeSheetItem(rvtSheet, CommandType.INSERT); bool linkedSheetDBUpdated = SheetDataWriter.ChangeLinkedSheet(linkedSheet, CommandType.INSERT); RevitLinkStatus linkStatus = new RevitLinkStatus(); linkStatus.IsLinked = true; linkStatus.CurrentLinkedId = sheet.UniqueId; linkStatus.LinkedElementId = sheet.Id.IntegerValue; linkStatus.ToolTip = "Linked Sheet ElementId: " + sheet.Id.IntegerValue; rvtSheet.LinkStatus = linkStatus; foreach (SheetParameter sheetParam in sheetData.SheetParameters) { 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; } } rvtSheet.SheetParameters.Add(sheetParam.ParameterId, paramValue); } bool sheetParamDBUpdated = SheetDataWriter.InsertMultipleParameterValue(rvtSheet.SheetParameters.Values.ToList()); List <RevisionOnSheet> rosList = new List <RevisionOnSheet>(); foreach (RevitRevision revision in sheetData.Revisions) { RevisionOnSheet ros = new RevisionOnSheet(Guid.NewGuid(), rvtSheet.Id, revision, false); rvtSheet.SheetRevisions.Add(revision.Id, ros); rosList.Add(ros); } bool rosDBUpdated = SheetDataWriter.InsertMultipleRevisionOnSheet(rosList); sheetData.Sheets.Add(rvtSheet); inserted = (sheetDBUpdated && linkedSheetDBUpdated && rosDBUpdated) ? true : false; } } catch (Exception ex) { MessageBox.Show("Failed to add a new sheet element.\n" + ex.Message, "New Sheet", MessageBoxButton.OK, MessageBoxImage.Warning); } return(inserted); }
private static void ReadRevitSheets(ref RevitSheetData sheetData) { try { ObservableCollection <LinkedSheet> linkedSheets = new ObservableCollection <LinkedSheet>(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM LinkedSheets"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { LinkedSheet lSheet = new LinkedSheet(); lSheet.Id = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Id")); lSheet.SheetId = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Sheet_Id")); Guid projectId = reader.GetGuid(reader.GetOrdinal("LinkedSheet_Project_Id")); var projectFound = from project in sheetData.LinkedProjects where project.Id == projectId select project; if (projectFound.Count() > 0) { lSheet.LinkProject = projectFound.First(); } lSheet.LinkedElementId = reader.GetString(reader.GetOrdinal("LinkedSheet_Element_Id")); lSheet.IsSource = reader.GetBoolean(reader.GetOrdinal("LinkedSheet_IsSource")); linkedSheets.Add(lSheet); } } } ObservableCollection <SheetParameterValue> sheetParameterValues = new ObservableCollection <SheetParameterValue>(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM SheetParameterValues"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { SheetParameterValue paramValue = new SheetParameterValue(); paramValue.ParameterValueId = reader.GetGuid(reader.GetOrdinal("ParameterValue_Id")); paramValue.SheetId = reader.GetGuid(reader.GetOrdinal("ParameterValue_Sheet_Id")); Guid parameterId = reader.GetGuid(reader.GetOrdinal("ParameterValue_Parameter_Id")); var paramFound = from param in sheetData.SheetParameters where param.ParameterId == parameterId select param; if (paramFound.Count() > 0) { paramValue.Parameter = paramFound.First(); } paramValue.ParameterValue = reader.GetString(reader.GetOrdinal("ParameterValue_Parameter_Value")); sheetParameterValues.Add(paramValue); } } } ObservableCollection <RevisionOnSheet> revisionOnSheets = new ObservableCollection <RevisionOnSheet>(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM RevisionsOnSheet"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { RevisionOnSheet ros = new RevisionOnSheet(); ros.MapId = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Id")); ros.SheetId = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Sheet_Id")); Guid revisionId = reader.GetGuid(reader.GetOrdinal("RevisionsOnSheet_Revision_Id")); var revisionFound = from rev in sheetData.Revisions where rev.Id == revisionId select rev; if (revisionFound.Count() > 0) { ros.RvtRevision = revisionFound.First(); } ros.Include = reader.GetBoolean(reader.GetOrdinal("RevisionsOnSheet_Include")); revisionOnSheets.Add(ros); } } } sheetData.Sheets.Clear(); using (SQLiteCommand cmd = new SQLiteCommand(connection)) { cmd.CommandText = "SELECT * FROM Sheets"; using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { RevitSheet sheet = new RevitSheet(); sheet.Id = reader.GetGuid(reader.GetOrdinal("Sheet_Id")); sheet.Number = reader.GetString(reader.GetOrdinal("Sheet_Number")); sheet.Name = reader.GetString(reader.GetOrdinal("Sheet_Name")); Guid disciplineId = reader.GetGuid(reader.GetOrdinal("Sheet_Discipline_Id")); var disciplineFound = from discipline in sheetData.Disciplines where discipline.Id == disciplineId select discipline; if (disciplineFound.Count() > 0) { sheet.DisciplineObj = disciplineFound.First(); } var linkedSheetFound = from linkedSheet in linkedSheets where linkedSheet.SheetId == sheet.Id select linkedSheet; if (linkedSheetFound.Count() > 0) { sheet.LinkedSheets = new ObservableCollection <LinkedSheet>(linkedSheetFound.ToList()); } foreach (SheetParameter param in sheetData.SheetParameters) { var parameterValueFound = from paramValue in sheetParameterValues where paramValue.SheetId == sheet.Id && paramValue.Parameter.ParameterId == param.ParameterId select paramValue; if (parameterValueFound.Count() > 0) { SheetParameterValue value = parameterValueFound.First(); sheet.SheetParameters.Add(param.ParameterId, value); } } var revisionOnSheetFound = from ros in revisionOnSheets where ros.SheetId == sheet.Id select ros; if (revisionOnSheetFound.Count() > 0) { foreach (RevisionOnSheet ros in revisionOnSheetFound) { if (!sheet.SheetRevisions.ContainsKey(ros.RvtRevision.Id)) { sheet.SheetRevisions.Add(ros.RvtRevision.Id, ros); } } } sheetData.Sheets.Add(sheet); } } } sheetData.Sheets = new ObservableCollection <RevitSheet>(sheetData.Sheets.OrderBy(o => o.Number)); } catch (Exception ex) { string message = ex.Message; } }