private static void DeleteOthers(DwgFileModel model, SQLiteConnection connection) { if (model != null) { using (SQLiteCommand command = connection.CreateCommand()) { //MUST DELETE CHILD FIRST. List <FixtureDetailsModel> fixtures = DBFixtureDetails.SelectRows(connection, model.relativePath); List <FixtureBeingUsedAreaModel> areas = DBFixtureBeingUsedArea.SelectRows(connection, model.relativePath); List <InsertPointModel> insertPoints = DBInsertPoint.SelectRows(connection, model.relativePath); List <TableModel> tables = DBTable.SelectRows(connection, model.relativePath); List <AreaBorderModel> areaU = DBAreaBorder.SelectRows(connection, model.relativePath); List <FixtureUnitModel> units = DBFixture_Unit.SelectRows(connection, model.relativePath); foreach (FixtureDetailsModel fixture in fixtures) { DBFixtureDetails.DeleteRow(connection, fixture.ID); } foreach (FixtureBeingUsedAreaModel area in areas) { DBFixtureBeingUsedArea.DeleteRow(connection, area.ID); } foreach (InsertPointModel insertPoint in insertPoints) { DBInsertPoint.DeleteRow(connection, insertPoint.ID); } foreach (TableModel table in tables) { DBTable.DeleteRow(connection, table.ID); } foreach (AreaBorderModel m in areaU) { DBTable.DeleteRow(connection, m.ID); } foreach (FixtureUnitModel m in units) { DBTable.DeleteRow(connection, m.ID); } DBCommand.DeleteRow(DBDwgFileName.name, model.ID, command); long check = command.ExecuteNonQuery(); } } }
public static void InitTable(string databasePath) { SQLiteConnection sqliteConn = new SQLiteConnection(DBCommand.GetConnectionString(databasePath)); try { sqliteConn.Open(); SQLiteTransaction sqliteTrans = sqliteConn.BeginTransaction(); DBMatrix3d.CreateTable(sqliteConn); DBPoint3D.CreateTable(sqliteConn); DBInsertPoint.CreateTable(sqliteConn); DBFixtureDetails.CreateTable(sqliteConn); DBFixtureBeingUsedArea.CreateTable(sqliteConn); DBDwgFile.CreateTable(sqliteConn); DBTable.CreateTable(sqliteConn); DBFixture_Unit.CreateTable(sqliteConn); DBAreaBorder.CreateTable(sqliteConn); if (projectElement.P_NOTE != null) { projectElement.P_NOTE.WriteToDatabase(sqliteConn); } if (projectElement.Dwgs != null) { foreach (DwgFileModel model in projectElement.Dwgs) { model.WriteToDatabase(sqliteConn); } } sqliteTrans.Commit(); sqliteTrans.Dispose(); sqliteConn.Close(); GC.Collect(); GC.WaitForPendingFinalizers(); } catch (Exception e) { DebugMessage(string.Format(@"Error opening Database: {0}, Error:{1}", databasePath, e.Message)); } }