private void SaveDocument(Document doc, Stream stream) { // Copy the contents to a byte array int length = (int)stream.Length; byte[] buffer = new byte[length]; stream.Read(buffer, 0, length); using (IDbConnection connection = DataSettings.GetConnection()) using (IDbCommand command = connection.CreateCommand()) { command.CommandText = @"INSERT INTO Files (DocNum, Data, Thumbnail) VALUES (?DocNum, ?Data, NULL)"; IDataParameter docNumParameter = command.CreateParameter(); docNumParameter.ParameterName = "DocNum"; docNumParameter.Value = doc.DocNum; command.Parameters.Add(docNumParameter); IDataParameter dataParameter = command.CreateParameter(); dataParameter.ParameterName = "Data"; dataParameter.Value = buffer; command.Parameters.Add(dataParameter); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
protected override void DeleteThumbnailImageInternal(Document doc) { using (IDbConnection connection = DataSettings.GetConnection()) using (IDbCommand command = connection.CreateCommand()) { command.CommandText = @"UPDATE Files SET Thumbnail = NULL WHERE DocNum = ?DocNum"; IDataParameter docNumParameter = command.CreateParameter(); docNumParameter.ParameterName = "DocNum"; docNumParameter.Value = doc.DocNum; command.Parameters.Add(docNumParameter); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
protected override void DeleteDocument(Document doc) { using (IDbConnection connection = DataSettings.GetConnection()) using (IDbCommand command = connection.CreateCommand()) { command.CommandText = @"DELETE FROM files WHERE DocNum = ?DocNum"; IDataParameter docNumParameter = command.CreateParameter(); docNumParameter.ParameterName = "DocNum"; docNumParameter.Value = doc.DocNum; command.Parameters.Add(docNumParameter); connection.Open(); command.ExecuteNonQuery(); connection.Close(); } }
protected override byte[] GetBytes(Document doc) { byte[] buffer; using (IDbConnection connection = DataSettings.GetConnection()) using (IDbCommand command = connection.CreateCommand()) { command.CommandText = @"SELECT Data FROM Files WHERE DocNum = ?DocNum"; IDataParameter docNumParameter = command.CreateParameter(); docNumParameter.ParameterName = "DocNum"; docNumParameter.Value = doc.DocNum; command.Parameters.Add(docNumParameter); connection.Open(); buffer = (byte[])command.ExecuteScalar(); connection.Close(); } return(buffer); }
private static bool KeyInUse(string tablename, string field, int keynum) { string commandText = "SELECT COUNT(*) FROM " + tablename + " WHERE " + field + "=" + keynum.ToString(); string value; using (IDbConnection connection = DataSettings.GetConnection()) using (IDbCommand command = connection.CreateCommand()) { command.CommandText = commandText; connection.Open(); value = command.ExecuteScalar().ToString(); connection.Close(); } if (value == "0") { return(false); } return(true); //already in use }