Exemple #1
0
        /// <summary>
        /// ReadPNote is read Note in general, can be from database, can be from dwg depends on current situation.
        /// If dwgPNote is opened, is active or not, is modified or not (can't check whether or not it is modied), refer to read from DWG and updateDatabase.
        /// If dwgPNote is Not open check date, if if equals, read from database.
        /// Else: read from file + udpate todatabase.
        /// FK IT, JUST FOUND DOWN THE INTEROPT SHIT
        /// </summary>
        /// <param name="connection"></param>
        /// <returns></returns>
        public static NODEDWG ReadDataPNode(SQLiteConnection connection)
        {
            NODEDWG note = null;

            string notePath = GoodiesPath.GetNotePathFromADwgPath(Application.DocumentManager.MdiActiveDocument.Name, connection);

            if (!string.IsNullOrEmpty(notePath))
            {
                if (Goodies.GetListOfDocumentOpening().Contains(notePath))
                {
                    Document doc = Goodies.GetDocumentFromDwgpath(notePath);

                    if (doc == null)
                    {
                        Application.ShowAlertDialog("ReadDwgNoteFile -> There is no Document, weird!");
                        return(null);
                    }

                    AcadDocument acadDoct = (AcadDocument)doc.GetAcadDocument();
                    if (acadDoct.Saved && GoodiesPath.IsDateTheSame(notePath, connection))
                    {
                        note = ReadFromDatabase(connection);
                    }
                    else
                    {
                        using (Database db = doc.Database)
                        {
                            note = GetData(db, connection);
                        }
                    }
                }
                else
                {
                    Database db = new Database();
                    try
                    {
                        if (GoodiesPath.IsDateTheSame(notePath, connection))
                        {
                            note = ReadFromDatabase(connection);
                        }
                        else
                        {
                            db.ReadDwgFile(notePath, FileOpenMode.OpenForReadAndAllShare, false, "");
                            note = GetData(db, connection);
                        }
                    }catch (Exception e)
                    {
                        MessageBox.Show(e.Message);
                    }
                }
            }

            return(note);
        }
Exemple #2
0
        public static void WriteScheduleTableToNote(SQLiteConnection connection)
        {
            string dwgPath      = Application.DocumentManager.MdiActiveDocument.Name;
            string notePathFull = GoodiesPath.GetNotePathFromADwgPath(dwgPath, connection);
            string notePath     = GoodiesPath.MakeRelativePath(notePathFull);

            if (string.IsNullOrEmpty(notePath))
            {
                MessageBox.Show("WriteScheduleTableToNote -> Can't find P_Note file.");
                return;
            }

            FileStatus fileStatus = Goodies.CanOpenToWrite(notePathFull);

            //Document doc = Goodies.CanOpenToWrite1(notePathFull);
            if (fileStatus == null || fileStatus.db == null)
            {
                return;
            }
            //if (doc == null) return;

            DwgFileModel fileModel = PlumbingDatabaseManager.GetNotePath(connection);

            if (notePath == fileModel.relativePath)
            {
                if (GoodiesPath.IsDateTheSame(notePathFull, connection))
                {
                    NODEDWG note = ReadPNote.ReadDataPNode(connection);


                    InsertPoint ip    = note.InsertPointSet.Where(insertpoint => insertpoint.model.alias == "FS").FirstOrDefault();
                    Table       table = TableSchedule.CreateTable(note.FixtureDetailSet, ip);
                    Document    doc   = Application.DocumentManager.GetDocument(fileStatus.db);
                    using (doc.LockDocument())
                    {
                        using (fileStatus.db)
                        {
                            TableSchedule.DeleteTableSchedule(fileStatus.db, XDataHelperName.tableSchedule);

                            using (Transaction tr = fileStatus.db.TransactionManager.StartTransaction())
                            {
                                BlockTable       bt  = (BlockTable)tr.GetObject(fileStatus.db.BlockTableId, OpenMode.ForRead);
                                BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                                Goodies.InsertTable(table, tr, btr);

                                table.Layer = ConstantName.TABLE;
                                XDataHelper.AddTableXData(ref table, tr, fileStatus.db);
                                tr.Commit();
                                tr.Dispose();
                                TableData tableData = new TableData(table, tr, fileStatus.db);
                                tableData.model.file = fileModel;
                                tableData.model.WriteToDatabase(connection);
                            }
                            TableSchedule.AddBlockToTable(table, fileStatus.db, note.FixtureDetailSet);
                            fileStatus.Save();
                        }
                    }
                    fileStatus.ReturnPreviousDocument();
                }
            }
        }