private static FixtureUnitModel getItem(SQLiteDataReader reader, SQLiteConnection connection) { FixtureUnitModel model = new FixtureUnitModel(); long POSITION_ID = (long)reader[DBFixtureUnitName.POSITION_ID]; long TRANSFORM_ID = (long)reader[DBFixtureUnitName.MATRIX_ID]; model.handle = (string)reader[DBFixtureUnitName.HANDLE]; model.INDEX = (double)reader[DBFixtureUnitName.INDEX]; model.TAG = (string)reader[DBFixtureUnitName.TAG]; model.NUMBER = (string)reader[DBFixtureUnitName.NUMBER]; model.CW_DIA = (double)reader[DBFixtureUnitName.CW_DIA]; model.HW_DIA = (double)reader[DBFixtureUnitName.HW_DIA]; model.WASTE_DIA = (double)reader[DBFixtureUnitName.WASTE_DIA]; model.VENT_DIA = (double)reader[DBFixtureUnitName.VENT_DIA]; model.STORM_DIA = (double)reader[DBFixtureUnitName.STORM_DIA]; model.WSFU = (double)reader[DBFixtureUnitName.WSFU]; model.CWSFU = (double)reader[DBFixtureUnitName.CWSFU]; model.HWSFU = (double)reader[DBFixtureUnitName.HWSFU]; model.DFU = (double)reader[DBFixtureUnitName.DFU]; model.ID = (long)reader[DBFixtureUnitName.ID]; long FILE_ID = (long)reader[DBFixtureUnitName.FILE_ID]; model.A2 = (double)reader[DBFixtureUnitName.A2]; model.Y2 = (double)reader[DBFixtureUnitName.Y2]; model.X2 = (double)reader[DBFixtureUnitName.X2]; model.X2_2 = (double)reader[DBFixtureUnitName.X2_2]; model.A3 = (double)reader[DBFixtureUnitName.A3]; model.A1 = (double)reader[DBFixtureUnitName.A1]; model.D1 = (double)reader[DBFixtureUnitName.D1]; long tagID = (long)reader[DBFixtureUnitName.tagPos]; long ventID = (long)reader[DBFixtureUnitName.ventPos]; long hotStubID = (long)reader[DBFixtureUnitName.hotStub]; long coldStubID = (long)reader[DBFixtureUnitName.coldStub]; long drainPosID = (long)reader[DBFixtureUnitName.drainPos]; long M_ID = (long)reader[DBFixtureUnitName.M_ID]; long R1_ID = (long)reader[DBFixtureUnitName.R1_ID]; long V_ID = (long)reader[DBFixtureUnitName.V_ID]; model.matrixTransform = DBMatrix3d.SelectRow(connection, TRANSFORM_ID); model.position = DBPoint3D.SelectRow(connection, POSITION_ID); model.file = DBDwgFile.SelectRow(connection, FILE_ID); model.tagPos = DBPoint3D.SelectRow(connection, tagID); model.ventPos = DBPoint3D.SelectRow(connection, ventID); model.hotStub = DBPoint3D.SelectRow(connection, hotStubID); model.coldStub = DBPoint3D.SelectRow(connection, coldStubID); model.drainPos = DBPoint3D.SelectRow(connection, drainPosID); model.M = DBPoint3D.SelectRow(connection, M_ID); model.R1 = DBPoint3D.SelectRow(connection, R1_ID); model.V = DBPoint3D.SelectRow(connection, V_ID); return(model); }
/// <summary> /// Check whether or not file and database has different date. /// This is used to decide whether or not to read from database or file Dwg. /// </summary> /// <param name="dwgPath">Full Dwg Path</param> /// <returns></returns> public static bool IsDateTheSame(string dwgPath, SQLiteConnection connection) { if (!IsPathInDatabase(dwgPath, connection)) { return(false); } string relPath = MakeRelativePath(dwgPath); DwgFileModel file = DBDwgFile.SelectRow(connection, relPath); return(file.modifieddate == GetModifiedOfFile(dwgPath).Ticks); }
public void WriteToDatabase(SQLiteConnection connection) { //File must be inserted to Database first (meaning it must have ID). if (!DBDwgFile.HasRowPath(connection, relativePath)) { var temp = this; ID = DBDwgFile.InsertRow(connection, ref temp); } else { DBDwgFile.UpdateRow(connection, this); } }
private static TableModel CreateModel(SQLiteDataReader reader, SQLiteConnection connection) { TableModel model = new TableModel(); model.ID = Convert.ToInt64(reader[DBTableName.ID]); model.handle = Convert.ToString(reader[DBTableName.HANDLE]); model.matrixTransform = DBMatrix3d.SelectRow(connection, Convert.ToInt64(reader[DBTableName.MATRIX_ID])); model.position = DBPoint3D.SelectRow(connection, Convert.ToInt64(reader[DBTableName.POSITION_ID])); model.ALIAS = Convert.ToString(reader[DBTableName.ALIAS]); model.A_VALUE = Convert.ToString(reader[DBTableName.A_VALUE]); model.file = DBDwgFile.SelectRow(connection, Convert.ToInt64(reader[DBTableName.FILE_ID])); return(model); }
/// <summary> /// Check Whether or Not dwg path is in database. /// </summary> /// <param name="dwgPath">full Path</param> /// <returns></returns> public static bool IsPathInDatabase(string dwgPath, SQLiteConnection connection) { string relPath = MakeRelativePath(dwgPath); if (string.IsNullOrEmpty(relPath)) { return(false); } if (DBDwgFile.HasRowPath(connection, relPath)) { return(true); } return(false); }
/// <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); } }
private static AreaBorderModel GetModelFromReader(SQLiteDataReader reader, SQLiteConnection connection) { AreaBorderModel model = new AreaBorderModel(); model.ID = (long)reader[DBAreaBorderNames.ID]; model.handle = (string)reader[DBAreaBorderNames.HANDLE]; model.position = DBPoint3D.SelectRow(connection, (long)reader[DBAreaBorderNames.POSITION_ID]); model.pointTop = DBPoint3D.SelectRow(connection, (long)reader[DBAreaBorderNames.POINT_TOP_ID]); model.pointBottom = DBPoint3D.SelectRow(connection, (long)reader[DBAreaBorderNames.POINT_BOTTOM_ID]); model.origin = DBPoint3D.SelectRow(connection, (long)reader[DBAreaBorderNames.ORIGIN_ID]); model.matrixTransform = DBMatrix3d.SelectRow(connection, (long)reader[DBAreaBorderNames.MATRIX_ID]); model.X = (double)reader[DBAreaBorderNames.X]; model.Y = (double)reader[DBAreaBorderNames.Y]; model.file = DBDwgFile.SelectRow(connection, (long)reader[DBAreaBorderNames.FILE_ID]); if (model.ID == ConstantName.invalidNum) { model = null; } return(model); }
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); }