Created
November 21, 2012 21:31
-
-
Save cavebatsofware/4127914 to your computer and use it in GitHub Desktop.
Temporal Incursion Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Transactions | |
Class TemporalIncursionGenerator | |
Public Property ClientID As String | |
Public Property TransactionID As String | |
Public Property UserID As String | |
Private transaction_table As New DataTable | |
Private query_command As New System.Text.StringBuilder("") | |
Private command As New MySqlCommand() | |
Public Sub New(ByVal user_id As String, ByVal client_id As String, ByVal transaction_id As String) | |
UserID = user_id | |
ClientID = client_id | |
TransactionID = transaction_id | |
With transaction_table.Columns | |
.Add("ProductID", GetType(Integer)) | |
.Add("ContainerID", GetType(Integer)) | |
.Add("LocationID", GetType(Integer)) | |
.Add("Reference") | |
.Add("Available", GetType(Integer)) | |
.Add("Allocated", GetType(Integer)) | |
End With | |
With query_command | |
.Append("SELECT ih.product_id, ") | |
.Append("ih.container_id, ") | |
.Append("ih.location_id, ") | |
.Append("it.reference, ") | |
.Append("ih.available, ") | |
.Append("ih.allocated ") | |
.Append("FROM inventory_transaction it ") | |
.Append("INNER JOIN inventory_history ih ON ih.transaction_id = it.transaction_id ") | |
.Append("WHERE it.transaction_id = @Transaction_ID") | |
End With | |
command.CommandText = query_command.ToString() | |
End Sub | |
Public Function InitiateIncursion() As Boolean | |
command.Parameters.AddWithValue("Transaction_ID", TransactionID) | |
BuildDatatable(command, transaction_table, transaction_table.Columns.Count) | |
If transaction_table.Rows.Count = 0 Then | |
Return False | |
End If | |
Dim reference As String = transaction_table.Rows(0)("Reference") | |
Dim tso As New TransactionOptions() | |
tso.IsolationLevel = IsolationLevel.RepeatableRead | |
Using Scope As New TransactionScope(TransactionScopeOption.Required, tso) | |
Dim inv As New Inventory(UserID, ClientID, reference, Inventory.TransactionType.Adjust, "ROLLBACK TRANSACTION") | |
For Each row As DataRow In transaction_table.Rows | |
inv.Deallocate(row("ProductID"), row("ContainerID"), row("Allocated")) | |
Console.WriteLine(row("ProductID").ToString() & " " & row("ContainerID").ToString() & " " & row("Allocated").ToString()) | |
Next | |
Dim commit As New TransactionReceiptDialog(inv.TransactionID, True) | |
commit.ShowDialog() | |
If commit.DialogResult = DialogResult.OK Then | |
Scope.Complete() | |
End If | |
End Using | |
Return True | |
End Function | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment