/// <summary> /// Совершает SQL-транзакцию для двух таблиц /// </summary> /// <param name="info">Экземпляр TableInfo</param> /// <param name="control">Экземпляр TableControl</param> public bool ExecuteSqlTransaction(TableInfo info, TableControl control) { using (SQLiteCommand commandDB = new SQLiteCommand(connectionDB)) { SQLiteTransaction transaction; OpenConnection(); transaction = connectionDB.BeginTransaction(); commandDB.Connection = connectionDB; commandDB.Transaction = transaction; try { InsertIntoTableInfo(info); InsertIntoTableControl(control); transaction.Commit(); return(true); } catch (Exception ex) { transaction.Rollback(); return(false); throw new Exception(ex.Message); } finally { CloseConnection(); } } }
/// <summary> /// INSERT таблицу Control /// </summary> /// <param name="control">Экземпляр TableControl</param> private bool InsertIntoTableControl(TableControl control) { using (SQLiteCommand commandDB = new SQLiteCommand(connectionDB)) { commandDB.CommandText = "INSERT INTO control (" + "dataFile, " + "tableDefects, " + "controlConfig, " + "usFiles" + ")" + " VALUES(?,?,?,?)"; SQLiteParameter dataFileParam = new SQLiteParameter { Value = control.DataFile, DbType = DbType.Binary }; commandDB.Parameters.Add(dataFileParam); SQLiteParameter defectsTableParam = new SQLiteParameter { Value = control.TableDefects, DbType = DbType.String }; commandDB.Parameters.Add(defectsTableParam); SQLiteParameter controlConfigParam = new SQLiteParameter { Value = control.ControlConfig, DbType = DbType.Binary }; commandDB.Parameters.Add(controlConfigParam); SQLiteParameter usFilesParam = new SQLiteParameter { Value = control.UsFiles, DbType = DbType.Binary }; commandDB.Parameters.Add(usFilesParam); try { commandDB.CommandType = CommandType.Text; commandDB.ExecuteNonQuery(); return(true); } catch (Exception ex) { return(false); throw new Exception(ex.Message); } } }