//Return: // 0 -- Abort/Cancel // 1 -- Retry // 2 -- Ignore private static int CheckNodePath(string nodePath) { if (!GoodiesPath.IsDwgPath(nodePath)) { string msg = string.Format("P_NOTES file ({0}) is not a .dwg file", nodePath); MessageBox.Show(msg, "Not a DWG file", MessageBoxButtons.OK); return(0); } else if (!GoodiesPath.IsNotePath(nodePath)) { string msg = string.Format("Note file {0} does not look like a P_NOTES file.", nodePath); DialogResult result = MessageBox.Show(msg, "Does not look like P_NOTES file", MessageBoxButtons.AbortRetryIgnore); if (result == DialogResult.Ignore) { return(2); } else if (result == DialogResult.Retry) { return(1); } else { return(0); } } return(2); }
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(); }
//At this point, the projectPath MUST HAVE BEEN INITIATED //Add/Remove a file in ChoosenDwgFiles; //Function GetData() should be called after this. public static void CheckedTreeNode(TreeNode tn, string currentNotePath) { if (string.IsNullOrEmpty(ProjectFolder)) { return; } string relativeDwgPath = GetTreeNotePath(tn); if (GoodiesPath.IsDwgPath(relativeDwgPath)) { DwgFileModel fe = new DwgFileModel(); //fe.modifieddate = GoodiesPath.GetModifiedOfFile(ProjectFolder + relativeDwgPath).Ticks; // this is to make sure later file is going to be updated. fe.modifieddate = 0; fe.isP_Notes = 0; fe.relativePath = relativeDwgPath; //string fullDwgPath = Root + relativeDwgPath; if (tn.Checked) { PlumbingDatabaseManager.projectElement.Dwgs.Add(fe); } else { PlumbingDatabaseManager.projectElement.Dwgs.Remove(fe); } } }
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); }
private static NODEDWG ReadFromDatabase(SQLiteConnection connection) { NODEDWG note = new NODEDWG(); string path = Application.DocumentManager.MdiActiveDocument.Name; string notePath = GoodiesPath.GetNotePathFromADwgPath(path, connection); note.ReadFromDatabase(connection, notePath); return(note); }
/// <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); }
public static void CreateDatabaseFolder(out string dbFolder) { dbFolder = ""; if (string.IsNullOrEmpty(Model.ProjectFolder)) { return; } if (GoodiesPath.IsDirectoryWritable(Model.ProjectFolder)) { string dataBaseFolder = "\\" + ConstantName.centerFolder; dbFolder = Model.ProjectFolder + dataBaseFolder; Directory.CreateDirectory(dbFolder); } }
private void ProgramManagerForm_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { string[] fileList = (string[])e.Data.GetData(DataFormats.FileDrop, false); foreach (string path in fileList) { if (System.IO.Path.GetFileName(path) == (ConstantName.databasePostFix)) { string relativePNotePath = Model.ReadDatabase(path); P_NODE_PATH_BOX.Text = Model.ProjectFolder + relativePNotePath; SetUpFolderTreeView.Nodes.Clear(); setupGridView.Rows.Clear(); Model.UpdateTheForm(SetUpFolderTreeView, setupGridView, P_NODE_PATH_BOX.Text); break; } else if (System.IO.Path.GetFileName(path) == ConstantName.centerFolder && Directory.Exists(path)) { string databasePath = path + "/" + ConstantName.databasePostFix; if (System.IO.File.Exists(databasePath)) { string relativePNotePath = Model.ReadDatabase(databasePath); P_NODE_PATH_BOX.Text = Model.ProjectFolder + relativePNotePath; Model.UpdateTheForm(SetUpFolderTreeView, setupGridView, P_NODE_PATH_BOX.Text); break; } } { if (GoodiesPath.IsNotePath(path)) { P_NODE_PATH_BOX.Text = path; Model.ProjectFolder = System.IO.Path.GetDirectoryName(path); Model.GetFilesDrag(P_NODE_PATH_BOX, setupGridView, SetUpFolderTreeView); break; } } } } else { e.Effect = DragDropEffects.None; } }
private void SetupGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e) { DataGridView dView = sender as DataGridView; //IT's always on because the path is at index 1; RowIndex is important. DataGridViewCell dCell = dView[1, e.RowIndex]; string dataPath = (string)dCell.Value; string fullPath = Model.ProjectFolder + dataPath; fullPath = GoodiesPath.ConvertPathToXDrive(fullPath); string cadPath = GoodiesPath.GetAcadPath(); Process process = new Process(); ProcessStartInfo info = new ProcessStartInfo(cadPath, "/i " + "\"" + fullPath + "\""); process.StartInfo = info; process.Start(); }
private static void CheckNode(TreeNode tn) { if (GoodiesPath.IsDwgPath(tn.FullPath) && PlumbingDatabaseManager.projectElement.ContainsPath(tn.FullPath)) { tn.Checked = true; //This function start with parent folder of dwgs ExpandNode(tn.Parent); } else { if (tn.Nodes.Count >= 1) { foreach (TreeNode treeNode in tn.Nodes) { CheckNode(treeNode); } } } }
/// <summary> /// Read Node File From Database, Fill Out The NODEDWG /// Path must be FULL PATH of a DWG from the database /// </summary> /// <param name="connection"></param> /// <param name="path">Note PATH</param> public void ReadFromDatabase(SQLiteConnection connection, string pathDwg) { FixtureBoxSet.Clear(); InsertPointSet.Clear(); FixtureDetailSet.Clear(); TableDataSet.Clear(); string relPath = GoodiesPath.MakeRelativePath(pathDwg); file = DBDwgFile.SelectRow(connection, relPath); if (file == null || file.ID == ConstantName.invalidNum) { MessageBox.Show("NODEDWG -> ReadFromDatabase -> File Not Found"); return; } foreach (FixtureBeingUsedAreaModel fixtureBox in DBFixtureBeingUsedArea.SelectRows(connection, file.ID)) { FixtureBeingUsedArea fixtureArea = new FixtureBeingUsedArea(fixtureBox); //this line is very important. You have to make sure they have file model in each fixtureArea; //this won't complicate the program as we pass the pointer. FixtureBoxSet.Add(fixtureArea); } foreach (FixtureDetailsModel detailModel in DBFixtureDetails.SelectRows(connection, file.ID)) { FixtureDetails fd = new FixtureDetails(detailModel); FixtureDetailSet.Add(fd); } foreach (InsertPointModel insertPointModel in DBInsertPoint.SelectRows(connection, file.ID)) { InsertPoint ip = new InsertPoint(insertPointModel); InsertPointSet.Add(ip); } foreach (TableModel model in DBTable.SelectRows(connection, file.ID)) { TableData table = new TableData(model); TableDataSet.Add(table); } }
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(); }
private static NODEDWG GetData(Database db, SQLiteConnection connection) { NODEDWG note = new NODEDWG(); using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForRead); foreach (ObjectId id in btr) { DBObject obj = tr.GetObject(id, OpenMode.ForRead); if (obj is BlockReference) { BlockReference bref = (BlockReference)obj; if (Goodies.IsBlockInTheDrawing(bref)) { if (bref.IsDynamicBlock) { string brefName = Goodies.GetDynamicName(bref); if (brefName.Equals(ConstantName.FixtureInformationArea)) { FixtureBeingUsedArea dbA = new FixtureBeingUsedArea(bref); if (dbA.model != null) { note.FixtureBoxSet.Add(dbA); } } } else if (bref.Name == ConstantName.FixtureDetailsBox) { FixtureDetails FD = new FixtureDetails(bref, tr); if (FD.model != null) { note.FixtureDetailSet.Add(FD); } } else if (bref.Name == ConstantName.InsertPoint) { InsertPoint IP = new InsertPoint(bref, tr); if (IP.model != null) { note.InsertPointSet.Add(IP); } } else if (bref is Table) { TableData tb = new TableData(bref, tr, db); if (tb.model != null) { note.TableDataSet.Add(tb); } } } } } List <FixtureDetails> newFixs = new List <FixtureDetails>(); foreach (FixtureBeingUsedArea fba in note.FixtureBoxSet) { foreach (FixtureDetails fd in note.FixtureDetailSet) { if (fba.IsInsideTheBox(fd)) { newFixs.Add(fd); } } } note.FixtureDetailSet.Clear(); foreach (FixtureDetails fd in newFixs) { note.FixtureDetailSet.Add(fd); } } //Write to Database string currentdwgPath = db.Filename; string dbPath = GoodiesPath.GetDatabasePathFromDwgPath(currentdwgPath); if (string.IsNullOrEmpty(dbPath)) { MessageBox.Show("Could Not Find Database."); } note.file = DBDwgFile.GetPNote(connection); note.file.modifieddate = GoodiesPath.GetModifiedOfFile(GoodiesPath.GetFullPathFromRelativePath(note.file.relativePath, connection)).Ticks; if (note.file == null) { MessageBox.Show($"Can't find this {currentdwgPath} in databse."); return(null); } foreach (FixtureBeingUsedArea fixtureBox in note.FixtureBoxSet) { fixtureBox.model.file = note.file; } foreach (FixtureDetails fd in note.FixtureDetailSet) { fd.model.file = note.file; } foreach (InsertPoint ip in note.InsertPointSet) { ip.model.file = note.file; } foreach (TableData table in note.TableDataSet) { table.model.file = note.file; } DBDwgFile.DeleteRow(connection, note.file.relativePath); note.WriteToDataBase(connection); return(note); }
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(); } } }