예제 #1
0
 private static void ClearUp(TreeView SetUpFolderTreeView, DataGridView setupGridView)
 {
     Model.ProjectFolder = "";
     SetUpFolderTreeView.Nodes.Clear();
     PlumbingDatabaseManager.clear();
     setupGridView.Rows.Clear();
 }
예제 #2
0
        public void ReadData()
        {
            string dwgPath = Application.DocumentManager.MdiActiveDocument.Name;

            string dbPath = GoodiesPath.GetDatabasePathFromDwgPath(dwgPath);

            if (string.IsNullOrEmpty(dbPath))
            {
                MessageBox.Show("Couldn't find the database!");
                return;
            }

            SQLiteConnection connection = PlumbingDatabaseManager.OpenSqliteConnection(dbPath);

            connection.Open();
            using (SQLiteTransaction sqlTr = connection.BeginTransaction())
            {
                //P_NODE_EDIT.TestingFunction.testing1(ConstantName.TEMPPATH);
                ReadPNote.ReadDataPNode(connection);
                sqlTr.Commit();
                connection.Close();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
예제 #3
0
        public static NODEDWG SetUp(string currentDWGPath)
        {
            string  databasePath = GoodiesPath.GetDatabasePathFromDwgPath(currentDWGPath);
            NODEDWG node;

            if (string.IsNullOrEmpty(databasePath))
            {
                SQLiteConnection connection = PlumbingDatabaseManager.OpenSqliteConnection(databasePath);
                node = ReadPNote.ReadDataPNode(connection);
            }
            else
            {
                while (string.IsNullOrEmpty(databasePath))
                {
                    databasePath = GoodiesPath.GetDatabasePathFromDwgPath(currentDWGPath);
                    MessageBox.Show("This file is not path of any project.", "Project Not Found", MessageBoxButtons.OK);

                    ProgramManagerForm form = new ProgramManagerForm("");
                    form.Show();
                }

                SQLiteConnection connection = PlumbingDatabaseManager.OpenSqliteConnection(databasePath);
                node = ReadPNote.ReadDataPNode(connection);
            }
            return(node);
        }
예제 #4
0
        //READ DATABASE -- IMPORTANCE --

        //RETURN RELATIVE PATH OF OF PNOTE (to put on text file)
        public static string ReadDatabase(string databasePath)
        {
            if (File.Exists(databasePath))
            {
                ProjectFolder = Directory.GetParent(Directory.GetParent(databasePath).FullName).FullName;
                PlumbingDatabaseManager.ReadDataAtBeginning(databasePath);
                //DatabaseManager.GuessProjectNumber();
                return(PlumbingDatabaseManager.projectElement.P_NOTE.relativePath);
            }
            return("");
        }
예제 #5
0
        public static string GetNotePathFromADwgPath(string path, SQLiteConnection sqlConn)
        {
            string dataPath = GetDatabasePathFromDwgPath(path);

            if (!string.IsNullOrEmpty(dataPath))
            {
                string directoryPath = Directory.GetParent(Path.GetDirectoryName(dataPath)).FullName;

                DwgFileModel fe = PlumbingDatabaseManager.GetNotePath(sqlConn);

                string pNotePath = directoryPath + fe.relativePath;
                if (File.Exists(pNotePath))
                {
                    return(pNotePath);
                }
            }
            return("");
        }
예제 #6
0
        public static void UpdateInitDatabase()
        {
            if (PlumbingDatabaseManager.projectElement == null)
            {
                return;
            }
            if (PlumbingDatabaseManager.projectElement.P_NOTE == null)
            {
                return;
            }
            if (PlumbingDatabaseManager.projectElement.Dwgs == null)
            {
                return;
            }
            if (Model.ProjectFolder == null)
            {
                return;
            }

            //Trying to Get ProjectNumber

            string dbFolder = "";

            if (!HasDataBaseFolder(out dbFolder))
            {
                CreateDatabaseFolder(out dbFolder);
                PlumbingDatabaseManager.CreateDatabase(dbFolder);
            }
            else
            {
                if (!PlumbingDatabaseManager.DoesDatabaseExist(dbFolder))
                {
                    PlumbingDatabaseManager.CreateDatabase(dbFolder);
                }
            }
            string batFilePath = Directory.GetParent(dbFolder).FullName + "\\" + ConstantName.batFileName;

            File.WriteAllText(batFilePath, ConstantName.batchCommand);
        }
예제 #7
0
        public static bool DeleteDatabaseFolder()
        {
            bool result = false;

            if (Directory.Exists(Model.ProjectFolder))
            {
                string[] directories = Directory.GetDirectories(Model.ProjectFolder);

                Regex rex = new Regex(ConstantName.databaseFolderPattern, RegexOptions.IgnoreCase);


                foreach (string dir in directories)
                {
                    Match m = rex.Match(dir);
                    if (m.Success)
                    {
                        try
                        {
                            string[] files = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);
                            foreach (string file in files)
                            {
                                File.Delete(file);
                            }

                            Directory.Delete(dir, true);
                            result = true;
                        }
                        catch (Exception e)
                        {
                            string msg = string.Format("Can't delete database folder: {0}, Exception: {1}", dir, e.Message);
                            PlumbingDatabaseManager.DebugMessage(msg);
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }
예제 #8
0
        public void RunTest3()
        {
            string dwgPath = Application.DocumentManager.MdiActiveDocument.Name;
            string dbPath  = GoodiesPath.GetDatabasePathFromDwgPath(dwgPath);

            if (string.IsNullOrEmpty(dbPath))
            {
                MessageBox.Show("Couldn't find the database!");
                return;
            }

            SQLiteConnection connection = PlumbingDatabaseManager.OpenSqliteConnection(dbPath);

            connection.Open();
            using (SQLiteTransaction sqlTr = connection.BeginTransaction())
            {
                WritePNote.WriteScheduleTableToNote(connection);
                sqlTr.Commit();
                connection.Close();
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
예제 #9
0
        public static bool HasDwgPathInDatabase(string path, SQLiteConnection sqlConn)
        {
            string dataPath = GetDatabasePathFromDwgPath(path);

            if (!string.IsNullOrEmpty(dataPath))
            {
                string directoryPath         = Directory.GetParent(Path.GetDirectoryName(path)).FullName;
                HashSet <DwgFileModel> feSet = PlumbingDatabaseManager.GetDwgsPath(sqlConn);
                foreach (DwgFileModel fe in feSet)
                {
                    string dwgPath = directoryPath + fe.relativePath;
                    if (dwgPath == path)
                    {
                        return(true);
                    }
                }
                Console.WriteLine(string.Format("HasDwgPathInDatabase Func -> Database found, but file from file: {0}", path));
            }
            else
            {
                Console.WriteLine(string.Format("HasDwgPathInDatabase Func -> Could not find database from file: {0}", path));
            }
            return(false);
        }
예제 #10
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();
                }
            }
        }