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);
        }
Exemple #2
0
        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 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;
            }
        }